Begin a functionality test

SS_CHECKING is a macro defined in sserr.h.

Synopsis:

SS_CHECKING(_what_)

Description: This family of macros can be used in the SSlib test suite to perform a test of some functionality. The SS_CHECKING and SS_END_CHECKING macros should be paired with curly braces. Inside the body of that construct may be zero or more calls to SS_FAILED or SS_FAILED_WHEN. If either of the failure macros is executed flow control branches to the SS_END_CHECKING macro.

The SS_END_CHECKING_WITH macro can be used in place of SS_END_CHECKING. It takes a single argument which is arbitrary code to execute if an error was detected in the body of the SS_CHECKING construct. Typically the argument will be something alone the lines of return ``FAILURE`’ or `goto error’.

The argument for SS_CHECKING should be a string that will be printed to stderr after the word “checking”. The string is printed only if _print is non-zero (similarly for the output from related macros).

1
2
3
4
5
6
7
8
 FILE *_print = 0==self ? stderr : NULL;
 int nerrors=0;
 SS_CHECKING("file opening operations") {
     file1 = ss_file_create(....);
     if (!file1) SS_FAILED_WHEN("creating");
     file2 = ss_file_open(....);
     if (!file2) SS_FAILED_WHEN("opening");
 } SS_END_CHECKING_WITH(nerrors++);
1
2
3
 SS_CHECKING("file close") {
     if (ss_file_close(....)<0) SS_FAILED;
 } SS_END_CHECKING;

See Also: