Next: Macros, Previous: Introduction, Up: Top
The first macro invoked should be START
, which initiates a
testing session. The test program than calls the TEST...
macros, and at the end of the session calls SUMMARY
.
Generally, the result of FAILURE
should be used to return an
appropriate exit value at the conclusion of the test program.
For example, here's a snippet of the test code for the test library itself:
START("Testing Test"); { int a = 3; int b = 2; int c = 1; TEST("TEST, PASSED", 1, 1); TEST("TEST, PASSED", a, a); TEST("TEST, **FAILED**", 1, 0); TEST("TEST, **FAILED**", a, b); TEST_RUN("TEST_RUN, PASSED", a = 4, a, 4 ); TEST_RUN("TEST_RUN, **FAILED**", a = 3, a, 4 ); } { double d = 22.2; double e = 22.3; TEST_RUN_FP_TOL( "TEST_RUN_FP_TOL, **FAILED**", double g = d + 200 * DBL_EPSILON, g, d, 20 * DBL_EPSILON ); } SUMMARY();
The test output includes the line number where the test was called,
which in some cases is inappropriate. Each of the
TEST
macros exists in an additional form with a suffix of
__LINE
. These forms take an additional leading parameter, the
line number to output. For example
TEST_LINE(33, "TEST, PASSED", 1, 1);