42 extern int clTestLogLevel;
44 extern int clTestPrintIndent;
48 ClTestCaseMaxNameLen = 512,
49 ClTestMaxNameLen = 512
54 CL_TEST_PRINT_ALL = 0xffffff,
55 CL_TEST_PRINT_TEST_OK = 1,
56 CL_TEST_PRINT_TEST_FAILED = 2,
59 extern ClTestVerbosity clTestVerbosity;
67 unsigned int malfunction;
68 unsigned int malfPops;
69 char name[ClTestCaseMaxNameLen];
73 extern void clPushTestCase(
const ClTestCaseData* tcd);
74 extern void clPopTestCase(ClTestCaseData* tcd);
75 extern int clTestGroupFinalizeImpl();
76 extern void clTestPrintImpl(
const char* file,
int line,
const char* fn,
const char* c);
77 extern void clTestImpl(
const char* file,
int line,
const char*
function,
const char *
id,
const char * error,
int ok);
79 extern ClTestCaseData clCurTc;
83 #define this_error_indicates_missing_parens_around_string(...) __VA_ARGS__
85 #define clTestStripParens(...) __VA_ARGS__
111 #define clTestGroupInitialize(name) clTestPrint(name)
127 #define clTestGroupFinalize() clTestGroupFinalizeImpl()
149 #define clTestGroupMalfunction(reason, predicate, execOnFailure) \
151 if (!(predicate)) { \
152 clTestPrint(reason); \
153 clTestPrint(("Test Malfunction.")); \
154 (void) clTestGroupFinalize(); \
176 #define clTestCase(name, test) \
178 clTestCaseStart(name); \
179 clCurTc.malfPops = 0; \
181 clTestCaseEnd((" ")); \
199 #define clTestCaseStart(testname) \
201 clTestPrintIndent+=2; \
202 clPushTestCase(&clCurTc); \
205 clCurTc.malfunction=0; \
206 clCurTc.malfPops = 1; \
207 snprintf(clCurTc.name, ClTestCaseMaxNameLen, \
208 this_error_indicates_missing_parens_around_string testname); \
209 clTestPrint(("Test case started [%s]:\n", clCurTc.name)); \
221 #define clTestCaseNumErrors() clCurTc.failed
232 #define clTestCaseNumMalfunctions() clCurTc.malfunction
243 #define clTestCaseNumPasses() clCurTc.passed
260 #define clTestCaseEnd(synopsis) \
262 clTestPrint(("Test case completed [%s]. " \
263 "Subcases: [%d] passed, [%d] failed, [%d] malfunction.\n" \
265 clCurTc.name, clCurTc.passed, \
266 clCurTc.failed, clCurTc.malfunction)); \
267 clTestPrint(synopsis); \
268 clTestPrintIndent-=2; \
269 int malf=clCurTc.malfunction; \
270 int fail = clCurTc.failed; \
271 clPopTestCase(&clCurTc); \
275 clCurTc.malfunction++; \
297 #define clTestCaseMalfunction(reason, predicate, execOnFailure) \
299 if (!(predicate)) { \
300 clTestPrint(("Test case malfunction [%s]. " \
301 "Subtests: [%d] Passed, [%d] Failed.\n" \
302 "Malfunction reason:\n", \
303 clCurTc.name, clCurTc.passed, clCurTc.failed)); \
304 clTestPrint(reason); \
305 if (clCurTc.malfPops) clPopTestCase(&clCurTc); \
306 clCurTc.malfunction++; \
330 #define clTest(string, predicate, errorPrintf)\
332 char __id[ClTestMaxNameLen]; \
333 char __error[ClTestMaxNameLen]=""; \
334 int __ok = predicate; \
335 snprintf(__id, ClTestMaxNameLen, \
336 this_error_indicates_missing_parens_around_string string); \
338 snprintf(__error, ClTestMaxNameLen, \
339 this_error_indicates_missing_parens_around_string errorPrintf); \
340 clTestImpl(__FILE__, __LINE__, __FUNCTION__, __id, __error, __ok); \
365 #define clTestExecOnFailure(string, predicate, errorPrintf, execOnFailure) \
367 clTestPrint(string); \
369 int result = (predicate); \
372 clTestPrint((": Ok\n")); \
375 clTestPrint((": %s:%d: Test (" #predicate ") failed. ", \
376 __FILE__, __LINE__)); \
377 clTestPrint(errorPrintf); \
378 clTestPrint(("\n")); \
402 #define clTestFailed(__string) clTestFailedAt(__FILE__, __LINE__,__string)
413 #define clTestFailedAt(__file, __line, __string) \
416 clTestPrint((": %s:%d: Test failed. ", __file, __line)); \
417 clTestPrint(__string); \
418 clTestPrint(("\n")); \
441 #define clTestSuccess(__string) clTestSuccessAt(__FILE__, __LINE__, __string)
452 #define clTestSuccessAt(__file, __line, __string) \
455 clTestPrintAt(__file,__line, __FUNCTION__, __string); \
456 clTestPrintAt(__file,__line, __FUNCTION__, (": Ok\n")); \
474 #define clTestPrint(x) clTestPrintAt(__FILE__, __LINE__, __FUNCTION__, x)
485 #define clTestPrintAt(__file, __line, __function, x) \
487 char __tempstr[2048]; \
488 snprintf(__tempstr,2048, \
489 this_error_indicates_missing_parens_around_string x); \
490 clTestPrintImpl(__file, __line, __function,__tempstr); \
491 CL_DEBUG_PRINT(clTestLogLevel, x); \
497 #define clTestGroupInitialize(name) do{ } while(0)
498 #define clTestGroupFinalize() do{ } while(0)
499 #define clTestGroupMalfunction(reason, predicate, execOnFailure) do{ } while(0)
500 #define clTestCase(name, test) do{ } while(0)
501 #define clTestCaseStart(testname) do{ } while(0)
502 #define clTestCaseNumErrors() 0
503 #define clTestCaseNumMalfunctions() 0
504 #define clTestCaseNumPasses() 0
505 #define clTestCaseEnd(synopsis) do{ } while(0)
506 #define clTestCaseMalfunction(reason, predicate, execOnFailure) do{ } while(0)
507 #define clTest(string, predicate, errorPrintf) do{ } while(0)
508 #define clTestExecOnFailure(string, predicate, errorPrintf, execOnFailure) do{ } while(0)
509 #define clTestFailed(string) do{ } while(0)
510 #define clTestSuccess(string) do{ } while(0)
511 #define clTestPrint(x) do{ } while(0)
513 #define clTestPrintAt(__file, __line, __function, x) do{ } while(0)
514 #define clTestSuccessAt(__file, __line, __string) do{ } while(0)
515 #define clTestFailedAt(__file, __line, __string) do{ } while(0)