39#ifdef HAVE_OPENMP_DARWIN_KLUGE
41pthread_attr_t gomp_thread_attr;
46#define G_OP_ACCESS "GTestSuite::operator[](int&)"
47#define G_TRY_SUCCESS "GTestSuite::test_try_success()"
48#define G_TRY_FAILURE1 "GTestSuite::test_try_failure(std::string&,"\
50#define G_TRY_FAILURE2 "GTestSuite::test_try_failure(std::exception&)"
142 if (
this != &suite) {
172 #if defined(G_RANGE_CHECK)
173 if (index < 0 || index >=
size()) {
195 #if defined(G_RANGE_CHECK)
196 if (index < 0 || index >=
size()) {
276 int old_errors =
errors();
287 double t_start = omp_get_wtime();
289 clock_t t_start = clock();
296 catch (std::exception& e) {
305 test.
type(
typeid(e).name());
312 test.
message(
"Non-standard C++ exception thrown");
317 double t_elapse = omp_get_wtime()-t_start;
319 double t_elapse = (double)(clock() - t_start) / (
double)CLOCKS_PER_SEC;
331 std::cout << test.
print();
335 std::cout <<
" ok" << std::endl;
338 std::cout <<
" NOK" << std::endl;
372 const std::string& name,
373 const std::string& message)
389 std::cout << testcase.
print();
411 const std::string& name,
412 const std::string& message)
416 std::string formated_name;
430 if (value != expected) {
436 std::string formated_message;
438 formated_message = message;
441 formated_message =
"Value "+
gammalib::str(value)+
" equals not the "+
446 testcase.
message(formated_message);
449 std::cout << testcase.
print();
471 const double& expected,
472 const std::string& name,
473 const std::string& message)
476 double eps = (expected != 0.0) ? 1.0e-7 * std::abs(expected) : 1.0e-7;
499 const double& expected,
501 const std::string& name,
502 const std::string& message)
506 std::string formated_name;
512 " is comprised within "+
522 if (value > expected + eps || value < expected - eps) {
528 std::string formated_message;
530 formated_message = message;
533 formated_message =
"Value "+
gammalib::str(value)+
" not within "+
540 testcase.
message(formated_message);
543 std::cout << testcase.
print();
565 const std::complex<double>& expected,
566 const std::string& name,
567 const std::string& message)
570 double eps = (expected != 0.0) ? 1.0e-7 * std::abs(expected) : 1.0e-7;
593 const std::complex<double>& expected,
595 const std::string& name,
596 const std::string& message)
600 std::string formated_name;
606 " is comprised within "+
616 if ((value.real() > expected.real() + eps) ||
617 (value.real() < expected.real() - eps) ||
618 (value.imag() > expected.imag() + eps) ||
619 (value.imag() < expected.imag() - eps)) {
625 std::string formated_message;
627 formated_message = message;
630 formated_message =
"Value "+
gammalib::str(value)+
" not within "+
637 testcase.
message(formated_message);
640 std::cout << testcase.
print();
661 const std::string& expected,
662 const std::string& name,
663 const std::string& message)
667 std::string formated_name;
672 formated_name =
format_name(
"Test if \""+value+
"\" is \""+expected+
"\"");
680 if (value != expected) {
686 std::string formated_message;
688 formated_message = message;
691 formated_message =
"String \""+value+
"\" is not equal to the "+
692 "expected string \""+expected+
"\".";
696 testcase.
message(formated_message);
699 std::cout << testcase.
print();
770 "Called \"G_TRY_SUCCESS\" without a previous call to test_try()");
780 std::cout <<
m_tests.back().print();
813 const std::string& type)
843 std::cout <<
m_tests.back().print();
959 for (
int i = 0; i <
m_tests.size(); ++i) {
983 result.append(
"=== GTestSuite ===");
1015 m_name =
"Unnamed Test Suite";
Information logger class definition.
Abstract test suite base class definition.
void(GTestSuite::* pfunction)(void)
void buffer_size(const int &size)
Set the buffer size.
void close(void)
Close log file.
void clear(void)
Clear object.
const double & duration(void) const
Return test case duration.
const bool & has_passed(void) const
Return whether the test passed.
std::string print(const GChatter &chatter=NORMAL) const
Print test case result.
const std::string & type(void) const
Return test case type.
const std::string & message(void) const
Return test case message.
Abstract test suite class for unit testing on GammaLib fixtures.
void test_try_failure(const std::string &message="", const std::string &type="")
Notice when a try block failed.
bool run(void)
Run all tests in test suite.
void test_try_success(void)
Notice when a try block succeeded.
void clear(void)
Clear test suite.
GException::test_failure & exception_failure(const std::string &message)
Return a failure exception.
std::vector< GTestCase > m_tests
List of test results.
int m_errors
Number of errors.
const int & failures(void) const
Return the number of failures.
void test_value(const int &value, const int &expected, const std::string &name="", const std::string &message="")
Test an integer value.
void copy_members(const GTestSuite &testsuite)
Copy class members.
std::vector< pfunction > m_functions
Test functions of this suite.
void test_assert(const bool &result, const std::string &name, const std::string &message="")
Test an assert.
int m_failures
Number of failures.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
void append(pfunction function, const std::string &name)
Append test functions to test suite.
GTestCase & operator[](const int &index)
Returns reference to test case.
time_t m_timestamp
Timestamp.
int size(void) const
Return number of tests in test suite.
std::string print(const GChatter &chatter=NORMAL) const
Print test suite information.
GTestSuite(void)
Void constructor.
GTestSuite & operator=(const GTestSuite &testsuite)
Assignment operator.
const int & errors(void) const
Return the number of errors.
std::string m_name
Name of the test suite.
void cout(const bool &flag)
Enables/disables logging into standard output stream.
virtual ~GTestSuite(void)
Destructor.
GException::test_error & exception_error(const std::string &message)
Return an error exception.
void test_try(const std::string &name)
Test an try block.
int success(void) const
Return the number of successful tests.
int m_index
Index of actual test function.
std::string format_name(const std::string &name)
Format Name.
const std::string & name(void) const
Return test suite name.
std::vector< GTestCase > m_stack_try
Stack for nested try blocks.
double duration(void) const
Return the total duration of all tests.
std::vector< std::string > m_names
Names of test functions.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.