2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * Part of an automated testing framework. You can declare a "test function"
6 * using WVTEST_MAIN, and call WVPASS and WVFAIL from there. These produce
7 * formatted data on stdout that can be read by external testrunner scripts.
9 * More than one WVTEST_MAIN is allowed in a single program, and they all
19 typedef void MainFunc();
20 const char *descr, *idstr;
24 static WvTest *first, *last;
25 static int fails, runs;
26 static time_t start_time;
27 static bool run_twice;
29 static void alarm_handler(int sig);
31 static void print_result(bool start, const char *file, int line,
32 const char *condstr, bool result);
34 WvTest(const char *_descr, const char *_idstr, MainFunc *_main, int _slow);
35 static int run_all(const char * const *prefixes = NULL);
36 static void start(const char *file, int line, const char *condstr);
37 static void check(bool cond);
38 static inline bool start_check(const char *file, int line,
39 const char *condstr, bool cond)
40 { start(file, line, condstr); check(cond); return cond; }
41 static bool start_check_eq(const char *file, int line,
42 const char *a, const char *b, bool expect_pass);
43 static bool start_check_eq(const char *file, int line, int a, int b,
45 static bool start_check_lt(const char *file, int line,
46 const char *a, const char *b);
47 static bool start_check_lt(const char *file, int line, int a, int b);
51 #define WVPASS(cond) \
52 WvTest::start_check(__FILE__, __LINE__, #cond, (cond))
53 #define WVPASSEQ(a, b) \
54 WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), true)
55 #define WVPASSLT(a, b) \
56 WvTest::start_check_lt(__FILE__, __LINE__, (a), (b))
57 #define WVFAIL(cond) \
58 WvTest::start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond))
59 #define WVFAILEQ(a, b) \
60 WvTest::start_check_eq(__FILE__, __LINE__, (a), (b), false)
62 #define WVTEST_MAIN3(descr, ff, ll, slowness) \
63 static void _wvtest_main_##ll(); \
64 static WvTest _wvtest_##ll(descr, ff, _wvtest_main_##ll, slowness); \
65 static void _wvtest_main_##ll()
66 #define WVTEST_MAIN2(descr, ff, ll, slowness) \
67 WVTEST_MAIN3(descr, ff, ll, slowness)
68 #define WVTEST_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 0)
69 #define WVTEST_SLOW_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 1)