TestSuite manages a set of tests. More...
#include <TestSuite/TestSuite.H>
Classes | |
struct | Impl |
Public Types | |
enum | Op { EQ, NEQ, LT, LTE, GT, GTE } |
Different types of arithmetic conditions that can be required. More... | |
Public Member Functions | |
TestSuite () | |
Default constructor builds an empty test suite. | |
~TestSuite () | |
Destructor. | |
void | addTest (const char *name, TestFunc func) |
Add a test to the test suite. | |
void | printAvailableTests () const |
Print all the available tests to stdout. | |
void | printAvailableTestsForPerl () const |
Print all the available tests to stdout. | |
void | runTest (int test_n, int repeat_n=1) |
Run a single test, optionally repeating it multiple times. | |
void | parseAndRun (int argc, const char **argv) |
Parse command-line args and take appropriate action. | |
bool | require (bool expr, const char *srcfile, int line, const char *expr_str) |
Require that the expression evaluates to true. | |
bool | requireEq (int expr, int expected, const char *srcfile, int line, const char *expr_str) |
Check that the given "int" expressions compare equal. | |
bool | requireEq (uint expr, uint expected, const char *srcfile, int line, const char *expr_str) |
Check that the given "unsigned int" expressions compare equal. | |
bool | requireEq (long expr, long expected, const char *srcfile, int line, const char *expr_str) |
Check that the given "long" expressions compare equal. | |
bool | requireEq (unsigned long expr, unsigned long expected, const char *srcfile, int line, const char *expr_str) |
Check that the given "unsigned long" expressions compare equal. | |
bool | requireEq (const std::string &expr, const std::string &expected, const char *srcfile, int line, const char *expr_str) |
Check that the given std::string expressions compare equal (as strings). | |
bool | requireEq (double expr, double expected, const char *srcfile, int line, const char *expr_str) |
Check that the given "double" expressions compare equal. | |
bool | require (int lhs, Op op, int rhs, const char *srcfile, int line, const char *lhs_str, const char *rhs_str) |
Check that the expression "lhs OP rhs" is true. | |
bool | require (long lhs, Op op, long rhs, const char *srcfile, int line, const char *lhs_str, const char *rhs_str) |
Check that the expression "lhs OP rhs" is true. | |
bool | require (double lhs, Op op, double rhs, const char *srcfile, int line, const char *lhs_str, const char *rhs_str) |
Check that the expression "lhs OP rhs" is true. | |
template<class T_or_RGB > | |
bool | requireEq (const Image< T_or_RGB > &expr, const Image< T_or_RGB > &expected, const char *srcfile, int line, const char *expr_str) |
Check that the given Image objects compare equal. | |
bool | requireEq (const Image< float > &expr, const Image< float > &expected, const float prec, const char *srcfile, int line, const char *expr_str) |
Check that the given Image objects compare equal to given precision. | |
template<class T > | |
bool | requireEqUserType (const T &expr, const T &expected, const char *srcfile, int line, const char *expr_str) |
Check that the given user-defined objects compare equal to given precision. | |
template<class T > | |
bool | requireEq (const Image< T > &expr, const Image< T > &expected, const char *srcfile, int line, const char *expr_str) |
TestSuite manages a set of tests.
The tests can be run one at a time or all at once. Each "test" is a function whose signature matches the TestFunc typedef. Such functions receive a TestSuite as a reference parameter. This allows the TestFunc's to use TestSuite's diagnostic functions (such as require() and requireEq()) to verify whatever the test is testing.
Definition at line 58 of file TestSuite.H.
enum TestSuite::Op |
Different types of arithmetic conditions that can be required.
Definition at line 101 of file TestSuite.H.
TestSuite::TestSuite | ( | ) |
Default constructor builds an empty test suite.
Definition at line 245 of file TestSuite.C.
TestSuite::~TestSuite | ( | ) |
Destructor.
Definition at line 250 of file TestSuite.C.
void TestSuite::addTest | ( | const char * | name, | |
TestFunc | func | |||
) |
Add a test to the test suite.
(Note that the ADD_TEST macro below makes it easier to have the string name of the function be the same as the C++ function name, without having to type it twice.)
Definition at line 256 of file TestSuite.C.
void TestSuite::parseAndRun | ( | int | argc, | |
const char ** | argv | |||
) |
Parse command-line args and take appropriate action.
This may involve either printing a list of available tests, or running a specific test.
Definition at line 305 of file TestSuite.C.
References rutz::prof::print_all_prof_data(), printAvailableTests(), printAvailableTestsForPerl(), and runTest().
void TestSuite::printAvailableTests | ( | ) | const |
Print all the available tests to stdout.
Definition at line 262 of file TestSuite.C.
Referenced by parseAndRun().
void TestSuite::printAvailableTestsForPerl | ( | ) | const |
Print all the available tests to stdout.
Definition at line 269 of file TestSuite.C.
Referenced by parseAndRun().
bool TestSuite::require | ( | double | lhs, | |
Op | op, | |||
double | rhs, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | lhs_str, | |||
const char * | rhs_str | |||
) |
Check that the expression "lhs OP rhs" is true.
Return the truth value of the comparison.
Definition at line 425 of file TestSuite.C.
bool TestSuite::require | ( | long | lhs, | |
Op | op, | |||
long | rhs, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | lhs_str, | |||
const char * | rhs_str | |||
) |
Check that the expression "lhs OP rhs" is true.
Return the truth value of the comparison.
Definition at line 419 of file TestSuite.C.
bool TestSuite::require | ( | int | lhs, | |
Op | op, | |||
int | rhs, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | lhs_str, | |||
const char * | rhs_str | |||
) |
Check that the expression "lhs OP rhs" is true.
Return the truth value of the comparison.
Definition at line 413 of file TestSuite.C.
bool TestSuite::require | ( | bool | expr, | |
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Require that the expression evaluates to true.
Return the truth value of the expression.
Definition at line 358 of file TestSuite.C.
bool TestSuite::requireEq | ( | const Image< float > & | expr, | |
const Image< float > & | expected, | |||
const float | prec, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given Image objects compare equal to given precision.
Return the truth value of the comparison.
Definition at line 406 of file TestSuite.C.
bool TestSuite::requireEq | ( | const Image< T_or_RGB > & | expr, | |
const Image< T_or_RGB > & | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) | [inline] |
Check that the given Image objects compare equal.
Return the truth value of the comparison.
bool TestSuite::requireEq | ( | double | expr, | |
double | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given "double" expressions compare equal.
Return the truth value of the comparison.
Definition at line 390 of file TestSuite.C.
bool TestSuite::requireEq | ( | const std::string & | expr, | |
const std::string & | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given std::string expressions compare equal (as strings).
Return the truth value of the comparison.
Definition at line 395 of file TestSuite.C.
bool TestSuite::requireEq | ( | unsigned long | expr, | |
unsigned long | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given "unsigned long" expressions compare equal.
Return the truth value of the comparison.
Definition at line 385 of file TestSuite.C.
bool TestSuite::requireEq | ( | long | expr, | |
long | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given "long" expressions compare equal.
Return the truth value of the comparison.
Definition at line 380 of file TestSuite.C.
bool TestSuite::requireEq | ( | uint | expr, | |
uint | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given "unsigned int" expressions compare equal.
Return the truth value of the comparison.
Definition at line 375 of file TestSuite.C.
bool TestSuite::requireEq | ( | int | expr, | |
int | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) |
Check that the given "int" expressions compare equal.
Return the truth value of the comparison.
Definition at line 370 of file TestSuite.C.
bool TestSuite::requireEqUserType | ( | const T & | expr, | |
const T & | expected, | |||
const char * | srcfile, | |||
int | line, | |||
const char * | expr_str | |||
) | [inline] |
Check that the given user-defined objects compare equal to given precision.
Return the truth value of the comparison.
Definition at line 174 of file TestSuite.H.
void TestSuite::runTest | ( | int | test_n, | |
int | repeat_n = 1 | |||
) |
Run a single test, optionally repeating it multiple times.
(Multiple repeats may be useful for profiling.) The output of the test is printed to standard output: on the first line is a boolean code indicating whether the test succeeded (code==1) or failed (code==0), and on subsequent lines are any diagnostic messages that may relate to the success or failure of the test (e.g., require() and requireEq() will generate a diagnostic message on failure).
Definition at line 276 of file TestSuite.C.
Referenced by parseAndRun().