core/testlib/testlib_register.h
Go to the documentation of this file.
00001 #ifndef TESTLIB_REGISTER_H_
00002 #define TESTLIB_REGISTER_H_
00003 //:
00004 // \file
00005 // \author Amitha Perera
00006 // \brief  Macros for registering the tests with the driver.
00007 //
00008 // A test driver program would simply look like
00009 // \code
00010 //   #include <testlib/testlib_register.h>
00011 //   DECLARE( some_test_name );
00012 //   void register_tests()
00013 //   {
00014 //     REGISTER( some_test_name );
00015 //   }
00016 //   DEFINE_MAIN;
00017 // \endcode
00018 // The DEFINE_MAIN macro will define the main() function for the driver.
00019 // You will also have to link in a file defining a function
00020 // \code
00021 //   int some_test_name_main(int,char*[])
00022 // \endcode
00023 // See the vxl tests for further examples (such as vil/tests).
00024 
00025 #include <vcl_string.h>
00026 
00027 #if 0 // ifdef VCL_VC - gives compiler errors - PVr
00028 typedef int ( (__cdecl *const) TestMainFunction)( int, char*[] );
00029 #else
00030 typedef int (*TestMainFunction)( int, char*[] );
00031 #endif
00032 
00033 
00034 //: Declare the existence of the test.
00035 // If you DECLARE( x ), then you will need to define a function int x_main(int,char*[]).
00036 #ifdef VCL_VC
00037 #define DECLARE( testname ) int _cdecl testname ## _main ( int argc, char* argv[] )
00038 #else
00039 #define DECLARE( testname )  int testname ## _main ( int argc, char* argv[] )
00040 #endif
00041 
00042 void testlib_register_test(const vcl_string &, TestMainFunction);
00043 
00044 //: Register the test with the driver.
00045 // \param testname should be the same as one of the tests declared with DECLARE.
00046 #define REGISTER( testname ) \
00047    testlib_register_test(#testname, & testname ## _main );
00048 
00049 //: Define the main() routine for this test driver.
00050 // This allows the main function to be defined in the driver code
00051 // itself--instead of in the testlib library--thus avoiding
00052 // "awf-weirdness". This also means that functionality from the test
00053 // library, such as testlib_root_dir, can be used even if it is not
00054 // used to create a test driver.
00055 #define DEFINE_MAIN \
00056    int testlib_main(int,char*[]); \
00057    void testlib_cleanup(); \
00058    int main( int argc, char* argv[] ) { \
00059      register_tests(); \
00060      int retval = testlib_main( argc, argv ); \
00061      testlib_cleanup(); \
00062      return retval; \
00063    }
00064 
00065 #endif // TESTLIB_REGISTER_H_