00001
00002 #ifndef testlib_test_h_
00003 #define testlib_test_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <vcl_string.h>
00016 #include <vcl_complex.h>
00017
00018
00019 void testlib_test_start(const char* name = 0);
00020
00021 void testlib_test_begin(const char* msg);
00022
00023 void testlib_test_perform(bool success);
00024
00025 int testlib_test_summary();
00026
00027
00028 void testlib_test_assert(const vcl_string& msg, bool expr);
00029
00030 void testlib_test_assert_near(const vcl_string& msg, double expr,
00031 double target = 0, double tol = 1e-12);
00032
00033 void testlib_test_assert_near(const vcl_string& msg, vcl_complex<double> expr,
00034 vcl_complex<double> target, double tol = 1e-12);
00035
00036 void testlib_test_assert_near_relative(const vcl_string& msg, double expr,
00037 double target = 0, double tol = 1e-12);
00038
00039 void testlib_test_assert_near_relative(const vcl_string& msg,
00040 vcl_complex<double> expr,
00041 vcl_complex<double> target,
00042 double tol = 1e-12);
00043
00044 void testlib_test_assert_far(const vcl_string& msg, double expr,
00045 double target = 0, double tol = 1e-12);
00046
00047 void testlib_test_assert_far(const vcl_string& msg, vcl_complex<double> expr,
00048 vcl_complex<double> target, double tol = 1e-12);
00049
00050 void testlib_test_assert_equal(const vcl_string& msg, long expr, long target);
00051
00052 #define Assert testlib_test_assert
00053 #define AssertNear testlib_test_assert_near
00054 #define AssertFar testlib_test_assert_far
00055
00056
00057 #define START(s) testlib_test_start(s)
00058
00059
00060 #define TEST(s,p,v) \
00061 do { \
00062 testlib_test_begin(s); \
00063 testlib_test_perform((p)==(v)); \
00064 } while (false)
00065
00066
00067 #define TEST_EQUAL(s,p,v) \
00068 do { \
00069 testlib_test_begin(s); \
00070 testlib_test_assert_equal("",p,v); \
00071 } while (false)
00072
00073
00074 #define TEST_NEAR(s,p,v,t) \
00075 do { \
00076 testlib_test_begin(s); \
00077 testlib_test_assert_near("",p,v,t); \
00078 } while (false)
00079
00080
00081 #define TEST_NEAR_REL(s,p,v,t) \
00082 do { \
00083 testlib_test_begin(s); \
00084 testlib_test_assert_near_relative("",p,v,t); \
00085 } while (false)
00086
00087
00088 #define TEST_FAR(s,p,v,t) \
00089 do { \
00090 testlib_test_begin(s); \
00091 testlib_test_assert_far("",p,v,t); \
00092 } while (false)
00093
00094
00095 #define TEST_RUN(s,x,p,v) \
00096 do { \
00097 testlib_test_begin(s); \
00098 x; \
00099 testlib_test_perform((p)==(v)); \
00100 } while (false)
00101
00102
00103 #define SUMMARY() return testlib_test_summary()
00104
00105
00106 #define RUN_TEST_FUNC(x) \
00107 testlib_test_start(#x); x(); return testlib_test_summary()
00108
00109
00110 #define MAIN( testname ) \
00111 int testname ## _main(int,char*[])
00112
00113
00114 #define MAIN_ARGS( testname ) \
00115 int testname ## _main(int argc, char* argv[])
00116
00117
00118
00119 #define TESTMAIN( testname ) \
00120 int testname ## _main(int,char*[]) { START(#testname); testname(); SUMMARY(); }
00121
00122
00123
00124 #define TEST_MAIN( testname ) \
00125 int testname(int,char*[]) { START(#testname); testname(); SUMMARY(); }
00126
00127
00128 #define TESTMAIN_ARGS( testname ) \
00129 int testname ## _main(int argc, char*argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }
00130
00131
00132
00133 #define TEST_MAIN_ARGS( testname ) \
00134 int testname(int argc, char*argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }
00135
00136
00137 #undef TESTLIB_DEFINE_MAIN
00138 #define TESTLIB_DEFINE_MAIN(testname) \
00139 int main() { START(#testname); testname(); return testlib_test_summary(); }
00140
00141
00142 #undef TESTLIB_DEFINE_MAIN_ARGS
00143 #define TESTLIB_DEFINE_MAIN_ARGS(testname) \
00144 int main(int argc, char * argv[]) { START(#testname); testname(argc,argv); SUMMARY(); }
00145
00146 #endif // testlib_test_h_