]> rtime.felk.cvut.cz Git - frescor/demo.git/blobdiff - src/wvtest/c/wvtest.h
Add wvtest from frsh-forb repository
[frescor/demo.git] / src / wvtest / c / wvtest.h
diff --git a/src/wvtest/c/wvtest.h b/src/wvtest/c/wvtest.h
new file mode 100644 (file)
index 0000000..79c8da6
--- /dev/null
@@ -0,0 +1,69 @@
+/* -*- Mode: C -*-
+ * WvTest:
+ *   Copyright (C) 1997-2009 Net Integration Technologies, Inc.
+ *       Licensed under the GNU Library General Public License, version 2.
+ *       See the included file named LICENSE for license information.
+ */ 
+#ifndef __WVTEST_H
+#define __WVTEST_H
+
+#ifndef WVTEST_CONFIGURED
+# error "Missing settings: HAVE_VALGRIND_MEMCHECK_H HAVE_WVCRASH WVTEST_CONFIGURED"
+#endif
+
+#include <time.h>
+#include <string.h>
+#include <stdbool.h>
+
+typedef void wvtest_mainfunc();
+
+struct WvTest {
+       const char *descr, *idstr;
+       wvtest_mainfunc *main;
+       int slowness;
+       struct WvTest *next;
+};
+
+int wvtest_run_all(char * const *prefixes);
+void wvtest_start(const char *file, int line, const char *condstr);
+void wvtest_check(bool cond, const char *reason);
+static inline bool wvtest_start_check(const char *file, int line,
+                                     const char *condstr, bool cond)
+{ wvtest_start(file, line, condstr); wvtest_check(cond, NULL); return cond; }
+bool wvtest_start_check_eq(const char *file, int line,
+                          const char *a, const char *b, bool expect_pass);
+bool wvtest_start_check_lt(const char *file, int line,
+                          const char *a, const char *b);
+int wvtest_start_check_frsh(const char *file, int line,
+                           const char *condstr, int frsh_retval);
+
+
+#define WVPASS(cond) \
+    wvtest_start_check(__FILE__, __LINE__, #cond, (cond))
+#define WVPASSEQ(a, b) \
+    wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), true)
+#define WVPASSLT(a, b) \
+    wvtest_start_check_lt(__FILE__, __LINE__, (a), (b))
+#define WVFAIL(cond) \
+    wvtest_start_check(__FILE__, __LINE__, "NOT(" #cond ")", !(cond))
+#define WVFAILEQ(a, b) \
+    wvtest_start_check_eq(__FILE__, __LINE__, (a), (b), false)
+#define WVPASSNE(a, b) WVFAILEQ(a, b)
+#define WVFAILNE(a, b) WVPASSEQ(a, b)
+#define WVFRSH(frshretval) \
+       wvtest_start_check_frsh(__FILE__, __LINE__, #frshretval, (frshretval))
+
+
+#define WVTEST_MAIN3(_descr, ff, ll, _slowness)                                \
+       static void _wvtest_main_##ll();                                \
+       struct WvTest _wvtest_##ll = \
+       { .descr = _descr, .idstr = ff ":" #ll, .main = _wvtest_main_##ll, .slowness = _slowness }, \
+               *_wvtest_ptr_##ll __attribute__ ((section ("wvtest"))) = &_wvtest_##ll; \
+       static void _wvtest_main_##ll()
+#define WVTEST_MAIN2(descr, ff, ll, slowness)  \
+       WVTEST_MAIN3(descr, ff, ll, slowness)
+#define WVTEST_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 0)
+#define WVTEST_SLOW_MAIN(descr) WVTEST_MAIN2(descr, __FILE__, __LINE__, 1)
+
+
+#endif // __WVTEST_H