test.h (847B)
1 #ifndef TEST_H 2 #define TEST_H 3 4 #include "common.h" 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif /* __cplusplus */ 9 10 #define TEST_PASS() return 1; 11 #define TEST_FAIL() return 0; 12 13 #define TESTS_BEGIN() s32 __test_suite_result = 0; 14 #define TESTS_END() return __test_suite_result; 15 16 #define TEST_RUN(name) \ 17 do { \ 18 errlog("%s:%s:", __FILE__, #name); \ 19 if (name()) { \ 20 errlog("%s:%s: OK", __FILE__, #name); \ 21 } else { \ 22 errlog("%s:%s: FAILED", __FILE__, #name); \ 23 __test_suite_result = 1; \ 24 } \ 25 } while (0); 26 27 #define _TEST_ASSERT_IMPL(cond, msg) \ 28 errlog("[%s:%d] %s: %s\n", __func__, __LINE__, #cond, msg) 29 30 #define TEST_ASSERT(cond, msg) \ 31 if (!(cond)) { _TEST_ASSERT_IMPL(cond, msg); TEST_FAIL() } 32 33 #define TEST_EXPECT(cond, msg) \ 34 if (!(cond)) { _TEST_ASSERT_IMPL(cond, msg); } 35 36 #ifdef __cplusplus 37 }; 38 #endif /* __cplusplus */ 39 40 #endif /* TEST_H */