]>
Commit | Line | Data |
---|---|---|
11a3e7b6 VZ |
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 | /* Workaround for Microsoft's compiler and Tru64 Unix systems where the | |
22 | C compiler has a working __func__, but the C++ compiler only has a | |
23 | working __FUNCTION__. This could be fixed in configure.in, but it's | |
24 | not worth it right now. */ | |
25 | #if defined (_MSC_VER) || (defined(__osf__) && defined(__cplusplus)) | |
26 | #define __func__ __FUNCTION__ | |
27 | #endif | |
28 | ||
29 | #define START_TEST(testname) static void testname(void) { \ | |
30 | _check_set_test_info(__func__, __FILE__, __LINE__); \ | |
31 | { | |
32 | #define END_TEST } } | |
33 | ||
34 | #define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg) | |
35 | ||
36 | typedef void (*tcase_setup_function)(void); | |
37 | typedef void (*tcase_teardown_function)(void); | |
38 | typedef void (*tcase_test_function)(void); | |
39 | ||
40 | typedef struct SRunner SRunner; | |
41 | typedef struct Suite Suite; | |
42 | typedef struct TCase TCase; | |
43 | ||
44 | struct SRunner { | |
45 | Suite *suite; | |
46 | int nchecks; | |
47 | int nfailures; | |
48 | }; | |
49 | ||
50 | struct Suite { | |
51 | char *name; | |
52 | TCase *tests; | |
53 | }; | |
54 | ||
55 | struct TCase { | |
56 | char *name; | |
57 | tcase_setup_function setup; | |
58 | tcase_teardown_function teardown; | |
59 | tcase_test_function *tests; | |
60 | int ntests; | |
61 | int allocated; | |
62 | TCase *next_tcase; | |
63 | }; | |
64 | ||
65 | ||
66 | /* Internal helper. */ | |
67 | void _check_set_test_info(char const *function, | |
68 | char const *filename, int lineno); | |
69 | ||
70 | ||
71 | /* | |
72 | * Prototypes for the actual implementation. | |
73 | */ | |
74 | ||
75 | void _fail_unless(int condition, const char *file, int line, char *msg); | |
76 | Suite *suite_create(char *name); | |
77 | TCase *tcase_create(char *name); | |
78 | void suite_add_tcase(Suite *suite, TCase *tc); | |
79 | void tcase_add_checked_fixture(TCase *, | |
80 | tcase_setup_function, | |
81 | tcase_teardown_function); | |
82 | void tcase_add_test(TCase *tc, tcase_test_function test); | |
83 | SRunner *srunner_create(Suite *suite); | |
84 | void srunner_run_all(SRunner *runner, int verbosity); | |
85 | int srunner_ntests_failed(SRunner *runner); | |
86 | void srunner_free(SRunner *runner); | |
87 | ||
88 | #ifdef __cplusplus | |
89 | } | |
90 | #endif |