86 #include "tb_linklist.h"
94 #define TB_TEST_VERBOSE 1
96 #ifdef TB_UNIT_TESTING
99 int TBRunTests(uint32_t settings = TB_TEST_VERBOSE);
102 #define TB_VERIFY(expr) { fail_line_nr = __LINE__; fail_file = __FILE__; if (!(expr)) { fail_text = (#expr); return; } }
105 #define TB_VERIFY_FLOAT(val, ref_val) { TB_VERIFY(fabs(ref_val - val) < 1.0E-5); }
108 #define TB_VERIFY_STR(str1, str2) do { \
109 if (strcmp((const char *)(str1), (const char *)(str2))) { \
110 std::cerr << "S1:" << (const char *)(str1) << "\n"; \
111 std::cerr << "S2:" << (const char *)(str2) << "\n"; \
113 TB_VERIFY(strcmp((const char *)(str1), (const char *)(str2)) == 0); \
117 #define TB_PASS() return;
120 #define TB_FAIL(error) { fail_line_nr = __LINE__; fail_file = __FILE__; fail_text = error; return; }
123 #define TB_TEST_FILE(filename) tb_get_test_file_name(__FILE__, filename)
126 class TBCall :
public TBLinkOf<TBCall>
130 virtual const char *name() = 0;
132 virtual void exec() = 0;
139 TBTestGroup(
const char *name);
140 bool IsSpecialTest(TBCall *call)
const {
return !call->linklist; }
147 TBLinkListOf<TBCall> calls;
148 TBTestGroup *next_test_group;
155 TBRegisterCall(TBTestGroup *test, TBCall *call);
161 #define TB_TEST_GROUP(name) \
162 namespace testgroup_##name \
164 class TheGroup : public TBTestGroup \
167 TheGroup() : TBTestGroup(#name) {} \
169 TheGroup the_group_obj; \
170 int force_link = 0; \
172 namespace testgroup_##name \
174 #define TB_TEST(callname) \
175 class CallObj##callname : public TBCall \
178 virtual const char *name(); \
179 virtual void exec(); \
181 CallObj##callname callname; \
182 TBRegisterCall callname##reg(&the_group_obj, &callname); \
183 const char *CallObj##callname::name() { return #callname; } \
184 void CallObj##callname::exec()
190 #define TB_FORCE_LINK_TEST_GROUP(name) \
191 namespace testgroup_##name { void force_link_call() { extern int force_link; force_link = 1; }}
193 TBStr tb_get_test_file_name(
const char *testpath,
const char *filename);
196 extern uint32_t test_settings;
197 extern int fail_line_nr;
198 extern const char *fail_file;
199 extern const char *fail_text;
203 inline int TBRunTests(uint32_t settings = TB_TEST_VERBOSE) {
return 0; }