1 #ifndef __COMMON_TEST_BASIC_H
2 #define __COMMON_TEST_BASIC_H
25 int total_countings[2];
30 #define fmt_passed "[\x1b[32;49mPASS\x1b[0m]"
31 #define fmt_failed "[\x1b[31;49mFAIL\x1b[0m]"
33 #define active_context \
34 ({ extern struct test_context* __test_ctx; __test_ctx; })
36 #define _expect(expr, act, exp, type_fmt) \
38 int failed = !(expr); \
39 printf(" @%s:%03d ....... ", __FILE__, __LINE__); \
41 printf(fmt_failed " (expect: " type_fmt ", got: " type_fmt ")\n",\
44 printf(fmt_passed "\n"); \
45 active_context->stats.countings[failed]++; \
48 #define new_aspect(expr, exp, act, typefmt) expr, exp, act, typefmt
50 #define expect(aspect) _expect(aspect)
52 #define expect_int(a, b) \
53 _expect(a == b, a, b, "%d")
55 #define expect_uint(a, b) \
56 _expect(a == b, a, b, "%u")
58 #define expect_long(a, b) \
59 _expect(a == b, a, b, "%ld")
61 #define expect_ulong(a, b) \
62 _expect(a == b, a, b, "%lu")
64 #define expect_str(str_a, str_b) \
65 _expect(!strcmp(str_a, str_b), str_a, str_b, "'%s'")
67 #define expect_notnull(ptr) \
68 _expect(ptr != NULL, "null", "not null", "<%s>")
70 #define expect_null(ptr) \
71 _expect(ptr == NULL, "not null", "null", "<%s>")
73 #define expect_true(val) \
74 _expect(val, "false", "true", "<%s>")
76 #define expect_false(val) \
77 _expect(!val, "true", "false", "<%s>")
79 #define testcase(name, body) \
80 do { begin_testcase(name); body; end_testcase(); } while(0)
83 begin_testcase(const char* name);
89 run_test(int argc, const char* argv[]);
91 #endif /* __COMMON_TEST_BASIC_H */