1 /* Miniature re-implementation of the "check" library.
2  *
3  * This is intended to support just enough of check to run the Expat
4  * tests.  This interface is based entirely on the portion of the
5  * check library being used.
6  *
7  * This is *source* compatible, but not necessary *link* compatible.
8  */
9 
10 #define CK_NOFORK 0
11 #define CK_FORK   1
12 
13 #define CK_SILENT  0
14 #define CK_NORMAL  1
15 #define CK_VERBOSE 2
16 
17 #define START_TEST(testname) static void testname(void) {
18 #define END_TEST }
19 
20 #define fail(msg)  _fail_unless(0, __FILE__, __LINE__, msg)
21 
22 typedef void (*tcase_setup_function)(void);
23 typedef void (*tcase_teardown_function)(void);
24 typedef void (*tcase_test_function)(void);
25 
26 typedef struct SRunner SRunner;
27 typedef struct Suite Suite;
28 typedef struct TCase TCase;
29 
30 struct SRunner {
31     Suite *suite;
32     int forking;
33     int nchecks;
34     int nfailures;
35 };
36 
37 struct Suite {
38     char *name;
39     TCase *tests;
40 };
41 
42 struct TCase {
43     char *name;
44     tcase_setup_function setup;
45     tcase_teardown_function teardown;
46     tcase_test_function *tests;
47     int ntests;
48     int allocated;
49     TCase *next_tcase;
50 };
51 
52 
53 /*
54  * Prototypes for the actual implementation.
55  */
56 
57 void _fail_unless(int condition, const char *file, int line, char *msg);
58 Suite *suite_create(char *name);
59 TCase *tcase_create(char *name);
60 void suite_add_tcase(Suite *suite, TCase *tc);
61 void tcase_add_checked_fixture(TCase *,
62                                tcase_setup_function,
63                                tcase_teardown_function);
64 void tcase_add_test(TCase *tc, tcase_test_function test);
65 SRunner *srunner_create(Suite *suite);
66 void srunner_set_fork_status(SRunner *runner, int forking);
67 void srunner_run_all(SRunner *runner, int verbosity);
68 int srunner_ntests_failed(SRunner *runner);
69 void srunner_free(SRunner *runner);
70