HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfRegTest Class Reference

#include <regTest.h>

Public Types

typedef bool(* RegFunc )()
 Type of a function with no arguments. More...
 
typedef bool(* RegFuncWithArgs )(int argc, char *argv[])
 

Public Member Functions

TF_API bool Register (const char *name, RegFunc)
 
TF_API bool Register (const char *name, RegFuncWithArgs)
 

Static Public Member Functions

static int Main (int argc, char *argv[])
 
static TF_API TfRegTestGetInstance ()
 

Friends

class TfSingleton< TfRegTest >
 

Detailed Description

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;
}
TF_ADD_REGTEST(PtHammer);
// file: drill.cpp
static bool
Test_PtDrill(int argc, char *argv[])
{
bool success;
...
return success;
}
TF_ADD_REGTEST(PtDrill);

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.

Member Typedef Documentation

typedef bool(* TfRegTest::RegFunc)()

Type of a function with no arguments.

Definition at line 114 of file regTest.h.

typedef bool(* TfRegTest::RegFuncWithArgs)(int argc, char *argv[])

Type of a function with arguments.

When Main(argc,argv) is requested to run a function of type RegFuncWithArgs, it invokes the function with arguments argc-1 and argv+1.

Definition at line 121 of file regTest.h.

Member Function Documentation

static TF_API TfRegTest& TfRegTest::GetInstance ( )
static
static int TfRegTest::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[]) {
return TfRegTest::Main(argc, argv);
}

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.

TF_API bool TfRegTest::Register ( const char *  name,
RegFunc   
)
TF_API bool TfRegTest::Register ( const char *  name,
RegFuncWithArgs   
)

Friends And Related Function Documentation

friend class TfSingleton< TfRegTest >
friend

Definition at line 129 of file regTest.h.


The documentation for this class was generated from the following file: