• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #define CK_NOFORK 0
15 #define CK_FORK   1
16 
17 #define CK_SILENT  0
18 #define CK_NORMAL  1
19 #define CK_VERBOSE 2
20 
21 #define START_TEST(testname) static void testname(void) { \
22     _check_set_test_info(__func__, __FILE__, __LINE__);   \
23     {
24 #define END_TEST } }
25 
26 #define fail(msg)  _fail_unless(0, __FILE__, __LINE__, msg)
27 
28 typedef void (*tcase_setup_function)(void);
29 typedef void (*tcase_teardown_function)(void);
30 typedef void (*tcase_test_function)(void);
31 
32 typedef struct SRunner SRunner;
33 typedef struct Suite Suite;
34 typedef struct TCase TCase;
35 
36 struct SRunner {
37     Suite *suite;
38     int forking;
39     int nchecks;
40     int nfailures;
41 };
42 
43 struct Suite {
44     char *name;
45     TCase *tests;
46 };
47 
48 struct TCase {
49     char *name;
50     tcase_setup_function setup;
51     tcase_teardown_function teardown;
52     tcase_test_function *tests;
53     int ntests;
54     int allocated;
55     TCase *next_tcase;
56 };
57 
58 
59 /* Internal helper. */
60 void _check_set_test_info(char const *function,
61                           char const *filename, int lineno);
62 
63 
64 /*
65  * Prototypes for the actual implementation.
66  */
67 
68 void _fail_unless(int condition, const char *file, int line, char *msg);
69 Suite *suite_create(char *name);
70 TCase *tcase_create(char *name);
71 void suite_add_tcase(Suite *suite, TCase *tc);
72 void tcase_add_checked_fixture(TCase *,
73                                tcase_setup_function,
74                                tcase_teardown_function);
75 void tcase_add_test(TCase *tc, tcase_test_function test);
76 SRunner *srunner_create(Suite *suite);
77 void srunner_set_fork_status(SRunner *runner, int forking);
78 void srunner_run_all(SRunner *runner, int verbosity);
79 int srunner_ntests_failed(SRunner *runner);
80 void srunner_free(SRunner *runner);
81 
82 #ifdef __cplusplus
83 }
84 #endif
85