00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef __TF_TEST_H__
00031 #define __TF_TEST_H__
00032
00033 #include <time.h>
00034
00035 #include <string>
00036
00037 #include "ut_types.h"
00038
00039 class TF_Test
00040 {
00041 typedef void MainFunc();
00042 const char *m_suite;
00043 const char *descr, *idstr;
00044 MainFunc *main;
00045 TF_Test *next;
00046 static TF_Test *first, *last;
00047 static int fails, runs;
00048 static time_t start_time;
00049
00050 static void alarm_handler(int sig) ABI_NORETURN;
00051 public:
00052 TF_Test(const char *_suite, const char *_descr,
00053 const char *_idstr, MainFunc *_main);
00054 static int run(const char * const *prefixes, const char * suite);
00055 static int run_all(const char * const *prefixes = NULL);
00056 static int run_suite(const char * suite);
00057 static void start(const char *file, int line, const char *condstr);
00058 static void check(bool cond);
00059 static inline bool start_check(const char *file, int line,
00060 const char *condstr, bool cond)
00061 { start(file, line, condstr); check(cond); return cond; }
00062 static bool start_check_eq(const char *file, int line,
00063 const char *a, const char *b);
00064 static bool start_check_eq(const char *file, int line, int a, int b);
00066 static void pulse();
00070 static const char* get_test_src_dir();
00071 static bool ensure_test_data(const char* file, std::string & path);
00072 };
00073
00074
00075
00076 #define TFPASS(cond) \
00077 TF_Test::start_check(__FILE__, __LINE__, #cond, (cond))
00078 #define TFPASSEQ(a, b) \
00079 TF_Test::start_check_eq(__FILE__, __LINE__, (a), (b))
00080
00081 #define TFFAIL(cond) \
00082 TF_Test::start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond))
00083
00084 #define TFTEST_MAIN3(suite, descr, ff, ll) \
00085 static void _tftest_main_##ll(); \
00086 static TF_Test _tftest_##ll(suite, descr, ff, _tftest_main_##ll); \
00087 static void _tftest_main_##ll()
00088 #define TFTEST_MAIN2(suite, descr, ff, ll) \
00089 TFTEST_MAIN3(suite, descr, ff, ll)
00090 #define TFTEST_MAIN(descr) \
00091 TFTEST_MAIN2(TFSUITE, descr, __FILE__, __COUNTER__)
00092
00093 #endif