From 8f17684810718973c8ea0f1150e46d6c1b8c0ef1 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Fri, 7 Aug 2020 22:47:46 +0200 Subject: server: Add basic unit test framework --- test/test_framework.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/test_framework.h (limited to 'test/test_framework.h') 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_); \ + } \ + } -- cgit v1.2.3-70-g09d2