testlib_register.h
Go to the documentation of this file.
1 #ifndef TESTLIB_REGISTER_H_
2 #define TESTLIB_REGISTER_H_
3 //:
4 // \file
5 // \author Amitha Perera
6 // \brief Macros for registering the tests with the driver.
7 //
8 // A test driver program would simply look like
9 // \code
10 // #include <testlib/testlib_register.h>
11 // DECLARE( some_test_name );
12 // void register_tests()
13 // {
14 // REGISTER( some_test_name );
15 // }
16 // DEFINE_MAIN;
17 // \endcode
18 // The DEFINE_MAIN macro will define the main() function for the driver.
19 // You will also have to link in a file defining a function
20 // \code
21 // int some_test_name_main(int,char*[])
22 // \endcode
23 // See the vxl tests for further examples (such as vil/tests).
24 
25 #include <string>
26 #ifdef _MSC_VER
27 # include <vcl_msvc_warnings.h>
28 #endif
29 
30 typedef int (*TestMainFunction)( int, char*[] );
31 
32 //: Declare the existence of the test.
33 // If you DECLARE( x ), then you will need to define a function int x_main(int,char*[]).
34 #ifdef _MSC_VER
35 #define DECLARE( testname ) int _cdecl testname ## _main ( int argc, char* argv[] )
36 #else
37 #define DECLARE( testname ) int testname ## _main ( int argc, char* argv[] )
38 #endif
39 
40 void testlib_register_test(const std::string &, TestMainFunction);
41 
42 //: Register the test with the driver.
43 // \param testname should be the same as one of the tests declared with DECLARE.
44 #define REGISTER( testname ) \
45  testlib_register_test(#testname, & testname ## _main );
46 
47 //: Define the main() routine for this test driver.
48 // This allows the main function to be defined in the driver code
49 // itself--instead of in the testlib library--thus avoiding
50 // "awf-weirdness". This also means that functionality from the test
51 // library, such as testlib_root_dir, can be used even if it is not
52 // used to create a test driver.
53 #define DEFINE_MAIN \
54  int testlib_main(int,char*[]); \
55  void testlib_cleanup(); \
56  int main( int argc, char* argv[] ) { \
57  register_tests(); \
58  int retval = testlib_main( argc, argv ); \
59  testlib_cleanup(); \
60  return retval; \
61  }
62 
63 #endif // TESTLIB_REGISTER_H_
void testlib_register_test(const std::string &, TestMainFunction)
int(* TestMainFunction)(int, char *[])