1 /*
2 * file: test.h (originally minunit.h)
3 * Comment: No multi threading safety
4 * Copyright: http://www.jera.com/techinfo/jtns/jtn002.html
5 * See: http://www.eskimo.com/~scs/C-faq/q10.4.html
6 */
7 static char MU_ASSERT_TEXT[2048];
8 static int tests_run = 0;
9
10 #define mu_assertException(message, exceptionStr) \
11 do { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: Caught exception: '%.500s'", __FILE__, __LINE__, message, exceptionStr); return MU_ASSERT_TEXT; } while (0)
12
13 #define mu_assertEqualsBool(message, expected, was) \
14 do { if (expected != was) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: expected='%.500s' was='%.500s'", __FILE__, __LINE__, message, expected?"true":"false", was?"true":"false"); return MU_ASSERT_TEXT; }} while (0)
15
16 #define mu_assertEqualsInt(message, expected, was) \
17 do { if (expected != was) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: expected='%d' was='%d'", __FILE__, __LINE__, message, (int)expected, (int)was); return MU_ASSERT_TEXT; }} while (0)
18
19 #define mu_assertEqualsShort(message, expected, was) \
20 do { if (expected != was) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: expected='%hd' was='%hd'", __FILE__, __LINE__, message, expected, was); return MU_ASSERT_TEXT; }} while (0)
21
22 #define mu_assertEqualsLong(message, expected, was) \
23 do { if (expected != was) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: expected='%ld' was='%ld'", __FILE__, __LINE__, message, expected, was); return MU_ASSERT_TEXT; }} while (0)
24
25 #define mu_assertEqualsString(message, expected, was) \
26 do { if (strcmp(expected,was) != 0) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: expected='%.500s' was='%.500s'", __FILE__, __LINE__, message, expected, was); return MU_ASSERT_TEXT; }} while (0)
27
28 #define mu_assert2(message, expected, was, test) \
29 do { if (!(test)) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s: expected='%.500s' was='%.500s'", __FILE__, __LINE__, message, expected, was); return MU_ASSERT_TEXT; }} while (0)
30
31 #define mu_assert(message, test) \
32 do { if (!(test)) { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s", __FILE__, __LINE__, message); return MU_ASSERT_TEXT; }} while (0)
33
34 #define mu_fail(message) \
35 do { sprintf(MU_ASSERT_TEXT, "[TEST FAIL]%s:%d %.500s", __FILE__, __LINE__, message); return MU_ASSERT_TEXT; } while (0)
36
37 #define mu_run_test(test) \
38 do { const char *message = test(); tests_run++; \
39 if (message) return message; } while (0)
40 #define mu_run_test2(test, a, b) \
41 do { const char *message = test(a,b); tests_run++; \
42 if (message) return message; } while (0)
syntax highlighted by Code2HTML, v. 0.9.1