javascript: support using nodejs as jsshell interpreter.
[wvtest.git] / c / wvtest.h
blob42b5ce1e79392a19f35c56e33437fd9c7ff6bfbc
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
11 #ifndef WVTEST_CONFIGURED
12 # error "Missing settings: HAVE_VALGRIND_MEMCHECK_H HAVE_WVCRASH WVTEST_CONFIGURED"
13 #endif
15 #include <time.h>
16 #include <string.h>
17 #include <stdbool.h>
19 typedef void wvtest_mainfunc();
21 struct WvTest {
22 const char *descr, *idstr;
23 wvtest_mainfunc *main;
24 int slowness;
25 struct WvTest *next;
28 void wvtest_register(struct WvTest *ptr);
29 int wvtest_run_all(char * const *prefixes);
30 void wvtest_start(const char *file, int line, const char *condstr);
31 void wvtest_check(bool cond, const char *reason);
32 static inline bool wvtest_start_check(const char *file, int line,
33 const char *condstr, bool cond)
34 { wvtest_start(file, line, condstr); wvtest_check(cond, NULL); return cond; }
35 void wvtest_check_xfail(bool cond);
36 void wvtest_skip(const char *file, int line, const char *condstr);
37 bool wvtest_start_check_eq(const char *file, int line,
38 int a, int b, bool expect_pass);
39 bool wvtest_start_check_eq_double(const char *file, int line,
40 double a, double b, double c, bool expect_pass);
41 bool wvtest_start_check_lt(const char *file, int line,
42 int a, int b);
43 bool wvtest_start_check_eq_str(const char *file, int line,
44 const char *a, const char *b, bool expect_pass);
45 bool wvtest_start_check_lt_str(const char *file, int line,
46 const char *a, const char *b);
49 #define WVPASS(cond) \
50 wvtest_start_check(__FILE__, __LINE__, #cond, (cond))
51 #define WVPASSEQ(a, b) \
52 wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), true)
53 #define WVPASSEQ_DOUBLE(a, b, c) \
54 wvtest_start_check_eq_double(__FILE__, __LINE__, (a), (b), (c), true)
55 #define WVPASSLT(a, b) \
56 wvtest_start_check_lt(__FILE__, __LINE__, (a), (b))
57 #define WVPASSEQSTR(a, b) \
58 wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), true)
59 #define WVPASSLTSTR(a, b) \
60 wvtest_start_check_lt_str(__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 WVFAILEQSTR(a, b) \
66 wvtest_start_check_eq_str(__FILE__, __LINE__, (a), (b), false)
67 #define WVPASSNE(a, b) WVFAILEQ(a, b)
68 #define WVPASSNESTR(a, b) WVFAILEQSTR(a, b)
69 #define WVFAILNE(a, b) WVPASSEQ(a, b)
70 #define WVFAILNESTR(a, b) WVPASSEQSTR(a, b)
71 #define WVFAILEQ_DOUBLE(a, b, c) \
72 wvtest_start_check_eq_double(__FILE__, __LINE__, (a), (b), (c), false)
73 #define WVPASSNE_DOUBLE(a, b, c) WVFAILEQ_DOUBLE(a, b, c)
74 #define WVABS(x) ((x)<0 ? -(x) : (x))
76 #define WVXFAIL(cond) do { \
77 wvtest_start(__FILE__, __LINE__, #cond); \
78 wvtest_check_xfail(cond); \
79 } while (0)
81 #define WVSKIP(cond) \
82 wvtest_skip(__FILE__, __LINE__, #cond)
85 #define WVTEST_MAIN3(_descr, ff, ll, _slowness) \
86 static void _wvtest_main_##ll(); \
87 struct WvTest _wvtest_##ll = \
88 { .descr = _descr, .idstr = ff ":" #ll, .main = _wvtest_main_##ll, .slowness = _slowness }; \
89 static void _wvtest_register_##ll() __attribute__ ((constructor)); \
90 static void _wvtest_register_##ll() { wvtest_register(&_wvtest_##ll); } \
91 static void _wvtest_main_##ll()
92 #define WVTEST_MAIN2(descr, ff, ll, slowness) \
93 WVTEST_MAIN3(descr, ff, ll, slowness)
94 #define WVTEST_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 0)
95 #define WVTEST_SLOW_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 1)
98 #endif // __WVTEST_H