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) {
171 #if defined(G_RANGE_CHECK)
172 if (index < 0 || index >=
size()) {
192 #if defined(G_RANGE_CHECK)
193 if (index < 0 || index >=
size()) {
273 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;
369 const std::string& name,
370 const std::string& message)
386 std::cout << testcase->
print();
408 const std::string& name,
409 const std::string& message)
413 std::string formated_name;
427 if (value != expected) {
433 std::string formated_message;
435 formated_message = message;
438 formated_message =
"Value "+
gammalib::str(value)+
" equals not the "+
443 testcase->
message(formated_message);
446 std::cout << testcase->
print();
468 const double& expected,
469 const std::string& name,
470 const std::string& message)
473 double eps = (expected != 0.0) ? 1.0e-7 * std::abs(expected) : 1.0e-7;
496 const double& expected,
498 const std::string& name,
499 const std::string& message)
503 std::string formated_name;
509 " is comprised within "+
519 if (value > expected + eps || value < expected - eps) {
525 std::string formated_message;
527 formated_message = message;
530 formated_message =
"Value "+
gammalib::str(value)+
" not within "+
537 testcase->
message(formated_message);
540 std::cout << testcase->
print();
562 const std::complex<double>& expected,
563 const std::string& name,
564 const std::string& message)
567 double eps = (expected != 0.0) ? 1.0e-7 * std::abs(expected) : 1.0e-7;
590 const std::complex<double>& expected,
592 const std::string& name,
593 const std::string& message)
597 std::string formated_name;
603 " is comprised within "+
613 if ((value.real() > expected.real() + eps) ||
614 (value.real() < expected.real() - eps) ||
615 (value.imag() > expected.imag() + eps) ||
616 (value.imag() < expected.imag() - eps)) {
622 std::string formated_message;
624 formated_message = message;
627 formated_message =
"Value "+
gammalib::str(value)+
" not within "+
634 testcase->
message(formated_message);
637 std::cout << testcase->
print();
658 const std::string& expected,
659 const std::string& name,
660 const std::string& message)
664 std::string formated_name;
669 formated_name =
format_name(
"Test if \""+value+
"\" is \""+expected+
"\"");
677 if (value != expected) {
683 std::string formated_message;
685 formated_message = message;
688 formated_message =
"String \""+value+
"\" is not equal to the "+
689 "expected string \""+expected+
"\".";
693 testcase->
message(formated_message);
696 std::cout << testcase->
print();
767 "Called \"G_TRY_SUCCESS\" without a previous call to test_try()");
777 std::cout <<
m_tests.back()->print();
810 const std::string& type)
840 std::cout <<
m_tests.back()->print();
956 for (
int i = 0; i <
m_tests.size(); ++i) {
980 result.append(
"=== GTestSuite ===");
1012 m_name =
"Unnamed Test Suite";
1051 for (
int i = 0; i < suite.
m_tests.size(); ++i) {
1056 for (
int i = 0; i < suite.
m_stack_try.size(); ++i) {
1071 for (
int i = 0; i <
m_tests.size(); ++i) {
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.
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< GTestCase * > m_tests
List of test results.
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.
std::vector< GTestCase * > m_stack_try
Stack for nested try blocks.
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.
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.