TfRegTest
is a singleton class, which is used to register functions with either type bool
(*)(int, char*[]), or functions returning type bool
and taking no arguments.
Here is how TfRegTest
is used to create tests in separate files, which are then compiled into a single standalone executable (and not part of any library):
// file: main.cpp
// file: hammer.cpp
static bool
Test_PtHammer()
{
bool success;
...
return success;
}
#define TF_ADD_REGTEST(name)
Adds the function Test_name, under name name, as a runnable regression test.
Support for simple regression tests.
static bool
Test_PtDrill(int argc, char *argv[])
{
bool success;
...
return success;
}
When main.cpp
, drill.cpp
and hammer.cpp
are compiled into an executable, then a test can be run by invoking the executable with a first argument of either PtHammer
or PtDrill
. Since PtHammer
is a function without arguments, supplying additional arguments is an error; but PtDrill
takes arguments, so additional command-line arguments specified are passed to the function. (Most library test functions shouldn't need any arguments.)
Definition at line 89 of file regTest.h.
static int Main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
|
inlinestatic |
Run a single regression test function, returning 0 if the function succeeded and 1 otherwise.
This function is intended to be called as follows:
int main(int argc, char *argv[]) {
}
static int Main(int argc, char *argv[])
Run a single regression test function, returning 0 if the function succeeded and 1 otherwise.
The first argument is the name of the test to be run. If the registered test function run takes no arguments, then no arguments other than the test name should be supplied. Otherwise, the Main()
passes argc-1
and argv+1
to the test function, and the test function is responsible for argument checking.
Definition at line 106 of file regTest.h.