aboutsummaryrefslogtreecommitdiff
path: root/test/test_framework.h
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-08-07 22:47:46 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-08-07 22:47:46 +0200
commit8f17684810718973c8ea0f1150e46d6c1b8c0ef1 (patch)
treed03b30c0a14e75e6c3374af3744cf7d7b1789f39 /test/test_framework.h
parenta260f02eac411171a827c9e0aeb31b8de397a5b5 (diff)
server: Add basic unit test framework
Diffstat (limited to 'test/test_framework.h')
-rw-r--r--test/test_framework.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test_framework.h b/test/test_framework.h
new file mode 100644
index 0000000..7ab4816
--- /dev/null
+++ b/test/test_framework.h
@@ -0,0 +1,25 @@
+#pragma once
+
+
+#define TEST(name) testfn__ ## name
+
+// Test function should return 0 on success, nonzero value on error
+#ifdef TEST_HEADER_GENERATION
+#define DEFINE_TEST(name) XXTEST_DECLARATION(TEST(name))
+#else
+#define DEFINE_TEST(name) int TEST(name)(void)
+#endif
+
+void test_report_error(
+ const char *type, const char *condition, const char *fname, int lineno);
+
+#define EXPECT(cond_) do { \
+ if (!(cond_)) test_report_error("EXPECT", #cond_, __FILE__, __LINE__); \
+ } while (0)
+
+#define EXPECTRET(cond_, ret_) do { \
+ if (!(cond_)) { \
+ test_report_error("EXPECT", #cond_, __FILE__, __LINE__); \
+ return (ret_); \
+ } \
+ }