3 * Copyright (C)1997-2012 Net Integration Technologies and contributors.
4 * Licensed under the GNU Library General Public License, version 2.
5 * See the included file named LICENSE for license information.
6 * You can get wvtest from: http://github.com/apenwarr/wvtest
11 #ifndef WVTEST_CONFIGURED
12 # error "Missing settings: HAVE_VALGRIND_MEMCHECK_H HAVE_WVCRASH WVTEST_CONFIGURED"
20 typedef void MainFunc();
21 const char *descr, *idstr;
25 static WvTest *first, *last;
26 static int fails, runs;
27 static time_t start_time;
28 static bool run_twice;
30 static void alarm_handler(int sig);
32 static void print_result(bool start, const char *file, int line,
33 const char *condstr, bool result);
35 WvTest(const char *_descr, const char *_idstr, MainFunc *_main, int _slow);
36 static int run_all(const char * const *prefixes = NULL);
37 static void start(const char *file, int line, const char *condstr);
38 static void check(bool cond);
39 static inline bool start_check(const char *file, int line,
40 const char *condstr, bool cond)
41 { start(file, line, condstr); check(cond); return cond; }
42 static bool start_check_eq(const char *file, int line,
43 const char *a, const char *b, bool expect_pass);
44 static bool start_check_eq(const char *file, int line,
45 const std::string &a, const std::string &b,
47 static bool start_check_eq(const char *file, int line, int a, int b,
49 static bool start_check_lt(const char *file, int line,
50 const char *a, const char *b);
51 static bool start_check_lt(const char *file, int line, int a, int b);
55 #define WVPASS(cond) \
56 WvTest::start_check(__FILE__, __LINE__, #cond, (cond))
57 #define WVPASSEQ(a, b) \
58 WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), true)
59 #define WVPASSLT(a, b) \
60 WvTest::start_check_lt(__FILE__, __LINE__, (a), (b))
61 #define WVFAIL(cond) \
62 WvTest::start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond))
63 #define WVFAILEQ(a, b) \
64 WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), false)
65 #define WVPASSNE(a, b) WVFAILEQ(a, b)
66 #define WVFAILNE(a, b) WVPASSEQ(a, b)
68 #define WVTEST_MAIN3(descr, ff, ll, slowness) \
69 static void _wvtest_main_##ll(); \
70 static WvTest _wvtest_##ll(descr, ff, _wvtest_main_##ll, slowness); \
71 static void _wvtest_main_##ll()
72 #define WVTEST_MAIN2(descr, ff, ll, slowness) \
73 WVTEST_MAIN3(descr, ff, ll, slowness)
74 #define WVTEST_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 0)
75 #define WVTEST_SLOW_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 1)