File: testlib_register.h

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (65 lines) | stat: -rw-r--r-- 2,093 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef TESTLIB_REGISTER_H_
#define TESTLIB_REGISTER_H_
//:
// \file
// \author Amitha Perera
// \brief  Macros for registering the tests with the driver.
//
// A test driver program would simply look like
// \code
//   #include <testlib/testlib_register.h>
//   DECLARE( some_test_name );
//   void register_tests()
//   {
//     REGISTER( some_test_name );
//   }
//   DEFINE_MAIN;
// \endcode
// The DEFINE_MAIN macro will define the main() function for the driver.
// You will also have to link in a file defining a function
// \code
//   int some_test_name_main(int,char*[])
// \endcode
// See the vxl tests for further examples (such as vil/tests).

#include <vcl_string.h>

#if 0 // ifdef VCL_VC - gives compiler errors - PVr
typedef int ( (__cdecl *const) TestMainFunction)( int, char*[] );
#else
typedef int (*TestMainFunction)( int, char*[] );
#endif


//: Declare the existence of the test.
// If you DECLARE( x ), then you will need to define a function int x_main(int,char*[]).
#ifdef VCL_VC
#define DECLARE( testname ) int _cdecl testname ## _main ( int argc, char* argv[] )
#else
#define DECLARE( testname )  int testname ## _main ( int argc, char* argv[] )
#endif

void testlib_register_test(const vcl_string &, TestMainFunction);

//: Register the test with the driver.
// \param testname should be the same as one of the tests declared with DECLARE.
#define REGISTER( testname ) \
   testlib_register_test(#testname, & testname ## _main );

//: Define the main() routine for this test driver.
// This allows the main function to be defined in the driver code
// itself--instead of in the testlib library--thus avoiding
// "awf-weirdness". This also means that functionality from the test
// library, such as testlib_root_dir, can be used even if it is not
// used to create a test driver.
#define DEFINE_MAIN \
   int testlib_main(int,char*[]); \
   void testlib_cleanup(); \
   int main( int argc, char* argv[] ) { \
     register_tests(); \
     int retval = testlib_main( argc, argv ); \
     testlib_cleanup(); \
     return retval; \
   }

#endif // TESTLIB_REGISTER_H_