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 /* ISO C90 does not support '__func__' predefined identifier */ 30 #if (defined(__STDC_VERSION__) && (__STDC_VERSION__ < 199901)) || \ 31 (defined(__GNUC__) && !defined(__STDC_VERSION__)) 32 # define __func__ "(unknown)" 33 #endif 34 35 #define START_TEST(testname) static void testname(void) { \ 36 _check_set_test_info(__func__, __FILE__, __LINE__); \ 37 { 38 #define END_TEST } } 39 40 #define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg) 41 42 typedef void (*tcase_setup_function)(void); 43 typedef void (*tcase_teardown_function)(void); 44 typedef void (*tcase_test_function)(void); 45 46 typedef struct SRunner SRunner; 47 typedef struct Suite Suite; 48 typedef struct TCase TCase; 49 50 struct SRunner { 51 Suite *suite; 52 int nchecks; 53 int nfailures; 54 }; 55 56 struct Suite { 57 const char *name; 58 TCase *tests; 59 }; 60 61 struct TCase { 62 const char *name; 63 tcase_setup_function setup; 64 tcase_teardown_function teardown; 65 tcase_test_function *tests; 66 int ntests; 67 int allocated; 68 TCase *next_tcase; 69 }; 70 71 72 /* Internal helper. */ 73 void _check_set_test_info(char const *function, 74 char const *filename, int lineno); 75 76 77 /* 78 * Prototypes for the actual implementation. 79 */ 80 81 void _fail_unless(int condition, const char *file, int line, const char *msg); 82 Suite *suite_create(const char *name); 83 TCase *tcase_create(const char *name); 84 void suite_add_tcase(Suite *suite, TCase *tc); 85 void tcase_add_checked_fixture(TCase *, 86 tcase_setup_function, 87 tcase_teardown_function); 88 void tcase_add_test(TCase *tc, tcase_test_function test); 89 SRunner *srunner_create(Suite *suite); 90 void srunner_run_all(SRunner *runner, int verbosity); 91 int srunner_ntests_failed(SRunner *runner); 92 void srunner_free(SRunner *runner); 93 94 #ifdef __cplusplus 95 } 96 #endif 97