]> rtime.felk.cvut.cz Git - hubacji1/iamcar2.git/blob - bcar/wvtest/cpp/wvtest.h
Merge bcar
[hubacji1/iamcar2.git] / bcar / wvtest / cpp / wvtest.h
1 /* -*- Mode: C++ -*-
2  * WvTest:
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
7  */
8 #ifndef __WVTEST_H
9 #define __WVTEST_H
10
11 #ifndef WVTEST_CONFIGURED
12 # error "Missing settings: HAVE_VALGRIND_MEMCHECK_H HAVE_WVCRASH WVTEST_CONFIGURED"
13 #endif
14
15 #include <time.h>
16 #include <string>
17
18 class WvTest
19 {
20     typedef void MainFunc();
21     const char *descr, *idstr;
22     MainFunc *main;
23     int slowness;
24     WvTest *next;
25     static WvTest *first, *last;
26     static int fails, runs, xpasses, xfails, skips;
27     static time_t start_time;
28     static bool run_twice;
29
30     static void alarm_handler(int sig);
31
32     static void print_result(bool start, const char *file, int line,
33             const char *condstr, const char *result);
34
35     static void check_prologue();
36 public:
37     WvTest(const char *_descr, const char *_idstr, MainFunc *_main, int _slow);
38     static int run_all(const char * const *prefixes = NULL);
39     static void start(const char *file, int line, const char *condstr);
40     static void check(bool cond);
41     static void check_xfail(bool cond);
42     static void skip(const char *file, int line, const char *condstr);
43     static inline bool start_check(const char *file, int line,
44                                    const char *condstr, bool cond)
45         { start(file, line, condstr); check(cond); return cond; }
46     static bool start_check_eq(const char *file, int line,
47                                const char *a, const char *b, bool expect_pass);
48     static bool start_check_eq(const char *file, int line,
49                                const std::string &a, const std::string &b,
50                                bool expect_pass);
51     static bool start_check_eq(const char *file, int line, int a, int b,
52                                bool expect_pass);
53     static bool start_check_eq(const char *file, int line, double a, double b, double c,
54                                bool expect_pass);
55     static bool start_check_lt(const char *file, int line,
56                                const char *a, const char *b);
57     static bool start_check_lt(const char *file, int line, int a, int b);
58 };
59
60
61 #define WVPASS(cond) \
62     WvTest::start_check(__FILE__, __LINE__, #cond, (cond))
63 #define WVPASSEQ(a, b) \
64     WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), true)
65 #define WVPASSEQ_DOUBLE(a, b, c) \
66     WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), (c), true)
67 #define WVPASSLT(a, b) \
68     WvTest::start_check_lt(__FILE__, __LINE__, (a), (b))
69 #define WVFAIL(cond) \
70     WvTest::start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond))
71 #define WVFAILEQ(a, b) \
72     WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), false)
73 #define WVFAILEQ_DOUBLE(a, b, c) \
74     WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), (c), false)
75 #define WVPASSNE(a, b) WVFAILEQ(a, b)
76 #define WVPASSNE_DOUBLE(a, b, c) WVFAILEQ_DOUBLE(a, b, c)
77 #define WVFAILNE(a, b) WVPASSEQ(a, b)
78 #define WVABS(x) ((x)<0 ? -(x) : (x))
79
80 #define WVXFAIL(cond) do { \
81     WvTest::start(__FILE__, __LINE__, #cond); \
82     WvTest::check_xfail(cond); \
83 } while (0)
84
85 #define WVSKIP(cond) \
86     WvTest::skip(__FILE__, __LINE__, #cond)
87
88
89
90 #define WVTEST_MAIN3(descr, ff, ll, slowness) \
91     static void _wvtest_main_##ll(); \
92     static WvTest _wvtest_##ll(descr, ff, _wvtest_main_##ll, slowness); \
93     static void _wvtest_main_##ll()
94 #define WVTEST_MAIN2(descr, ff, ll, slowness) \
95     WVTEST_MAIN3(descr, ff, ll, slowness)
96 #define WVTEST_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 0)
97 #define WVTEST_SLOW_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 1)
98
99
100 #endif // __WVTEST_H