136 #define TSTNAME name, __func__, "() "
138 #define TSTNAME name, __FUNCTION__, "() "
140 #define TSTNAME name, "", ""
153 #error <TSTFLAGS is not defined>
157 #define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
159 #define END() (void) tstdef_dummy; } END_(TSTFLAGS)
163 #define TEST0(suite) TEST_1_(TSTFLAGS, suite)
165 #define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
167 #define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
169 #define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
171 #define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
173 #define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
175 #define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
177 #define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
179 #define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
181 #define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)
184 #define TEST_LOG(x) \
186 if (tstflags & tst_log) \
190 #define TEST_FAILED(flags) \
191 ((flags) & tst_abort) ? abort() : (void)0; return 1
194 #define TEST_1_(flags, suite) do { \
195 if (flags & tst_verbatim) { \
196 printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
199 if (flags & tst_verbatim) \
200 printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); \
202 fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
203 __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
204 TEST_FAILED(flags); } \
208 #define TEST_VOID_(flags, suite) do { \
209 if (flags & tst_verbatim) { \
210 printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
215 #define TEST_(flags, suite, expect) do { \
216 uintptr_t _value, _expect; \
217 if (flags & tst_verbatim) { \
218 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
220 _value = (uintptr_t)(suite); \
221 _expect = (uintptr_t)(expect); \
222 if (_value == _expect) { \
223 if (flags & tst_verbatim) \
224 printf("%s: %s%sok: %s == %s \n", \
225 TSTNAME, #suite, #expect); \
228 fprintf(stderr, "%s:%u: %s %s%sFAILED: " \
229 "%s != %s or "MOD_ZU" != "MOD_ZU"\n", \
230 __FILE__, __LINE__, TSTNAME, \
231 #suite, #expect, (size_t)_value, (size_t)_expect); \
233 TEST_FAILED(flags); \
237 #define TEST_P_(flags, suite, expect) do { \
238 void const * _value, * _expect; \
239 if (flags & tst_verbatim) { \
240 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
242 if ((_value = (suite)) == (_expect = (expect))) { \
243 if (flags & tst_verbatim) \
244 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
247 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n", \
248 __FILE__, __LINE__, TSTNAME, \
249 #suite, #expect, _value, _expect); fflush(stderr); \
250 TEST_FAILED(flags); \
254 #define TEST_SIZE_(flags, suite, expect) do { \
255 size_t _value, _expect; \
256 if (flags & tst_verbatim) { \
257 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
259 if ((_value = (size_t)(suite)) == \
260 (_expect = (size_t)(expect))) { \
261 if (flags & tst_verbatim) \
262 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
264 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
265 __FILE__, __LINE__, TSTNAME, \
266 #suite, #expect, _value, _expect); fflush(stderr); \
267 TEST_FAILED(flags); \
272 #define TEST64_(flags, suite, expect) do { \
273 uint64_t _value, _expect; \
274 if (flags & tst_verbatim) { \
275 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
277 if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) { \
278 if (flags & tst_verbatim) \
279 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
281 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
282 __FILE__, __LINE__, TSTNAME, \
283 #suite, #expect, (unsigned longlong)_value, \
284 (unsigned longlong)_expect); fflush(stderr); \
285 TEST_FAILED(flags); \
289 #define TEST_D_(flags, suite, expect) do { \
290 double _value, _expect; \
291 if (flags & tst_verbatim) { \
292 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
294 if ((_value = (double)(suite)) == (_expect = (double)(expect))) { \
295 if (flags & tst_verbatim) \
296 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
298 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
299 __FILE__, __LINE__, TSTNAME, \
300 #suite, #expect, _value, _expect); fflush(stderr); \
301 TEST_FAILED(flags); \
305 #define TEST_S_(flags, suite, expect) do { \
306 char const * _value, * _expect; \
307 if (flags & tst_verbatim) { \
308 printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
311 _expect = (expect); \
312 if (((_value == NULL || _expect == NULL) && _value == _expect) || \
313 (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) { \
314 if (flags & tst_verbatim) \
315 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
317 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
318 __FILE__, __LINE__, TSTNAME, \
320 _value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
321 _expect); fflush(stderr); \
322 TEST_FAILED(flags); \
326 #define TEST_M_(flags, suite, expect, len) do { \
327 void const * _value, * _expect; \
329 if (flags & tst_verbatim) { \
330 printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
333 _expect = (expect); \
334 _len = (size_t)(len); \
335 if (((_value == NULL || _expect == NULL) && _value == _expect) || \
336 memcmp(_value, _expect, _len) == 0) { \
337 if (flags & tst_verbatim) \
338 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
340 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
341 "or \"%.*s\" != \"%.*s\"\n", \
342 __FILE__, __LINE__, TSTNAME, \
343 #suite, #expect, (int)_len, \
344 (char *)_value, (int)_len, (char *)_expect); \
346 TEST_FAILED(flags); \
350 #define BEGIN_(flags) \
351 if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
354 #define END_(flags) \
355 if (flags & tst_verbatim) \
356 printf("%s: %s%sfinished fully successful\n", TSTNAME); \
Basic integer types for su library.
@ tst_log
If (TSTFLAGS & tst_log) is non-zero, log intermediate results.
Definition: tstdef.h:149
@ tst_abort
If (TSTFLAGS & tst_abort) is non-zero, abort() when failed.
Definition: tstdef.h:147
@ tst_verbatim
If (TSTFLAGS & tst_verbatim) is non-zero, be verbatim.
Definition: tstdef.h:145