minicheck.h revision 1.1 1 1.1 tron /* Miniature re-implementation of the "check" library.
2 1.1 tron *
3 1.1 tron * This is intended to support just enough of check to run the Expat
4 1.1 tron * tests. This interface is based entirely on the portion of the
5 1.1 tron * check library being used.
6 1.1 tron *
7 1.1 tron * This is *source* compatible, but not necessary *link* compatible.
8 1.1 tron */
9 1.1 tron
10 1.1 tron #ifdef __cplusplus
11 1.1 tron extern "C" {
12 1.1 tron #endif
13 1.1 tron
14 1.1 tron #define CK_NOFORK 0
15 1.1 tron #define CK_FORK 1
16 1.1 tron
17 1.1 tron #define CK_SILENT 0
18 1.1 tron #define CK_NORMAL 1
19 1.1 tron #define CK_VERBOSE 2
20 1.1 tron
21 1.1 tron /* Workaround for Tru64 Unix systems where the C compiler has a working
22 1.1 tron __func__, but the C++ compiler only has a working __FUNCTION__. This
23 1.1 tron could be fixed in configure.in, but it's not worth it right now. */
24 1.1 tron #if defined(__osf__) && defined(__cplusplus)
25 1.1 tron #define __func__ __FUNCTION__
26 1.1 tron #endif
27 1.1 tron
28 1.1 tron #define START_TEST(testname) static void testname(void) { \
29 1.1 tron _check_set_test_info(__func__, __FILE__, __LINE__); \
30 1.1 tron {
31 1.1 tron #define END_TEST } }
32 1.1 tron
33 1.1 tron #define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg)
34 1.1 tron
35 1.1 tron typedef void (*tcase_setup_function)(void);
36 1.1 tron typedef void (*tcase_teardown_function)(void);
37 1.1 tron typedef void (*tcase_test_function)(void);
38 1.1 tron
39 1.1 tron typedef struct SRunner SRunner;
40 1.1 tron typedef struct Suite Suite;
41 1.1 tron typedef struct TCase TCase;
42 1.1 tron
43 1.1 tron struct SRunner {
44 1.1 tron Suite *suite;
45 1.1 tron int nchecks;
46 1.1 tron int nfailures;
47 1.1 tron };
48 1.1 tron
49 1.1 tron struct Suite {
50 1.1 tron char *name;
51 1.1 tron TCase *tests;
52 1.1 tron };
53 1.1 tron
54 1.1 tron struct TCase {
55 1.1 tron char *name;
56 1.1 tron tcase_setup_function setup;
57 1.1 tron tcase_teardown_function teardown;
58 1.1 tron tcase_test_function *tests;
59 1.1 tron int ntests;
60 1.1 tron int allocated;
61 1.1 tron TCase *next_tcase;
62 1.1 tron };
63 1.1 tron
64 1.1 tron
65 1.1 tron /* Internal helper. */
66 1.1 tron void _check_set_test_info(char const *function,
67 1.1 tron char const *filename, int lineno);
68 1.1 tron
69 1.1 tron
70 1.1 tron /*
71 1.1 tron * Prototypes for the actual implementation.
72 1.1 tron */
73 1.1 tron
74 1.1 tron void _fail_unless(int condition, const char *file, int line, char *msg);
75 1.1 tron Suite *suite_create(char *name);
76 1.1 tron TCase *tcase_create(char *name);
77 1.1 tron void suite_add_tcase(Suite *suite, TCase *tc);
78 1.1 tron void tcase_add_checked_fixture(TCase *,
79 1.1 tron tcase_setup_function,
80 1.1 tron tcase_teardown_function);
81 1.1 tron void tcase_add_test(TCase *tc, tcase_test_function test);
82 1.1 tron SRunner *srunner_create(Suite *suite);
83 1.1 tron void srunner_run_all(SRunner *runner, int verbosity);
84 1.1 tron int srunner_ntests_failed(SRunner *runner);
85 1.1 tron void srunner_free(SRunner *runner);
86 1.1 tron
87 1.1 tron #ifdef __cplusplus
88 1.1 tron }
89 1.1 tron #endif
90