A helper class for test programs.
More...
#include <test_main.hh>
List of all members.
Classes |
| class | Arg |
Public Member Functions |
|
| TestMain (int argc, char *const argv[]) |
| | Start the parsing of command line arguments.
|
| string | get_optional_args (const string &short_form, const string &long_form, const string &description) |
| | Get an optional argument from the command line.
|
| bool | get_optional_flag (const string &short_form, const string &long_form, const string &description) |
| | Get an optional flag from the command line.
|
| void | complete_args_parsing () |
| | Complete parsing the arguments.
|
| bool | get_verbose () const |
| | Get the state of the verbose flag.
|
| int | get_verbose_level () const |
| | Get the the verbose level, should only be used if get_verbose() is true.
|
| void | run (string test_name, XorpCallback1< bool, TestInfo & >::RefPtr cb) |
| | Run a test function/method.
|
| const string | usage () |
| void | failed (string error) |
| | Mark the tests as having failed.
|
| int | exit () |
| | Must be called at the end of the tests.
|
Private Attributes |
|
string | _progname |
|
list< Arg > | _args |
|
bool | _verbose |
|
int | _verbose_level |
|
bool | _exit_status |
|
string | _error_string |
|
string | _usage |
Detailed Description
A helper class for test programs.
This class is used to parse the command line arguments 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.
Member Function Documentation
| void TestMain::complete_args_parsing |
( |
| ) |
[inline] |
Complete parsing the arguments.
Process generic arguments and verify that there are no arguments left unprocessed.
| int TestMain::exit |
( |
| ) |
[inline] |
Must be called at the end of the tests.
- Returns:
- The status of the tests. Should be passed to exit().
| void TestMain::failed |
( |
string |
error | ) |
[inline] |
Mark the tests as having failed.
Used for setting an error condition from outside a test.
- Parameters:
-
| string TestMain::get_optional_args |
( |
const string & |
short_form, |
|
|
const string & |
long_form, |
|
|
const string & |
description |
|
) |
| [inline] |
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 TestMain::get_optional_flag |
( |
const string & |
short_form, |
|
|
const string & |
long_form, |
|
|
const string & |
description |
|
) |
| [inline] |
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.
| bool TestMain::get_verbose |
( |
| ) |
const [inline] |
Get the state of the verbose flag.
Used by test programs that don't use the run method to run tests.
| int TestMain::get_verbose_level |
( |
| ) |
const [inline] |
Get the the verbose level, should only be used if get_verbose() is true.
Used by test programs that don't use the run method to run the tests.
| void TestMain::run |
( |
string |
test_name, |
|
|
XorpCallback1< bool, TestInfo & >::RefPtr |
cb |
|
) |
| [inline] |
Run a test function/method.
The test function/method is passed a TestInfo. The test function/method should return true for success and "false 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 TestMain::usage |
( |
| ) |
[inline] |
- Returns:
- The usage string.
The documentation for this class was generated from the following file: