|
|
A helper class for test programs.
This class is used to parse the command line arguments, enable the xlog_ framework and return the exit status from the test functions/methods. An example of how to use this class can be found in test_test_main.cc.
enum { SUCCESS = 0, FAILURE = 1} |
A test function/method should return one of these values.
TestMain (int argc, char **argv)
| TestMain |
Start the parsing of command line arguments and enable xlog_*.
string
get_optional_args (const string &short_form, const string &long_form,
const string &description)
| get_optional_args |
Get an optional argument from the command line.
Parameters:
short_form | The short form of the argument e.g. "-t". |
long_form | The long form of the argument e.g. "--testing". |
description | The description of this argument that will be used in the usage message. |
Returns: the argument or "" if not found or an error occured in previous parsing of the arguments.
bool
get_optional_flag (const string &short_form, const string &long_form,
const string &description)
| get_optional_flag |
Get an optional flag from the command line.
Parameters:
short_form | The short form of the argument e.g. "-t". |
long_form | The long form of the argument e.g. "--testing". |
description | The description of this argument that will be used in the usage message. |
Returns: true if the flag is present or false found or an error occured in previous parsing of the arguments.
void
complete_args_parsing ()
| complete_args_parsing |
Complete parsing the arguments.
Process generic arguments and verify that there are no arguments left unprocessed.
void
run (string test_name, XorpCallback1<int, TestInfo&>::RefPtr cb)
| run |
Run a test function/method. The test function/method is passed a TestInfo. The test function/method should return "TestMain::SUCCESS" for sucess and "TestMain::FAILURE" for failure.
To run a function call "test": run("test", callback(test));
Parameters:
test_name | The name of the test. |
cb | Callback object. |
const string
usage ()
| usage |
Returns: The usage string.
void
failed (string error)
| failed |
Mark the tests as having failed. Used for setting an error condition from outside a test.
Parameters:
error | Error string. |
int
exit ()
| exit |
Must be called at the end of the tests.
Returns: The status of the tests. Should be passed to exit().
Generated by: pavlin on possum.icir.org on Mon Jun 9 13:23:43 2003, using kdoc 2.0a54+XORP. |