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