1178848Scokane/* Miniature re-implementation of the "check" library. 2178848Scokane * 3178848Scokane * This is intended to support just enough of check to run the Expat 4178848Scokane * tests. This interface is based entirely on the portion of the 5178848Scokane * check library being used. 6178848Scokane * 7178848Scokane * This is *source* compatible, but not necessary *link* compatible. 8178848Scokane */ 9178848Scokane 10178848Scokane#ifdef __cplusplus 11178848Scokaneextern "C" { 12178848Scokane#endif 13178848Scokane 14178848Scokane#define CK_NOFORK 0 15178848Scokane#define CK_FORK 1 16178848Scokane 17178848Scokane#define CK_SILENT 0 18178848Scokane#define CK_NORMAL 1 19178848Scokane#define CK_VERBOSE 2 20178848Scokane 21247513Sdelphij/* Workaround for Microsoft's compiler and Tru64 Unix systems where the 22247513Sdelphij C compiler has a working __func__, but the C++ compiler only has a 23247513Sdelphij working __FUNCTION__. This could be fixed in configure.in, but it's 24247513Sdelphij not worth it right now. */ 25247513Sdelphij#if defined (_MSC_VER) || (defined(__osf__) && defined(__cplusplus)) 26178848Scokane#define __func__ __FUNCTION__ 27178848Scokane#endif 28178848Scokane 29178848Scokane#define START_TEST(testname) static void testname(void) { \ 30178848Scokane _check_set_test_info(__func__, __FILE__, __LINE__); \ 31178848Scokane { 32178848Scokane#define END_TEST } } 33178848Scokane 34178848Scokane#define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg) 35178848Scokane 36178848Scokanetypedef void (*tcase_setup_function)(void); 37178848Scokanetypedef void (*tcase_teardown_function)(void); 38178848Scokanetypedef void (*tcase_test_function)(void); 39178848Scokane 40178848Scokanetypedef struct SRunner SRunner; 41178848Scokanetypedef struct Suite Suite; 42178848Scokanetypedef struct TCase TCase; 43178848Scokane 44178848Scokanestruct SRunner { 45178848Scokane Suite *suite; 46178848Scokane int nchecks; 47178848Scokane int nfailures; 48178848Scokane}; 49178848Scokane 50178848Scokanestruct Suite { 51178848Scokane char *name; 52178848Scokane TCase *tests; 53178848Scokane}; 54178848Scokane 55178848Scokanestruct TCase { 56178848Scokane char *name; 57178848Scokane tcase_setup_function setup; 58178848Scokane tcase_teardown_function teardown; 59178848Scokane tcase_test_function *tests; 60178848Scokane int ntests; 61178848Scokane int allocated; 62178848Scokane TCase *next_tcase; 63178848Scokane}; 64178848Scokane 65178848Scokane 66178848Scokane/* Internal helper. */ 67178848Scokanevoid _check_set_test_info(char const *function, 68178848Scokane char const *filename, int lineno); 69178848Scokane 70178848Scokane 71178848Scokane/* 72178848Scokane * Prototypes for the actual implementation. 73178848Scokane */ 74178848Scokane 75178848Scokanevoid _fail_unless(int condition, const char *file, int line, char *msg); 76178848ScokaneSuite *suite_create(char *name); 77178848ScokaneTCase *tcase_create(char *name); 78178848Scokanevoid suite_add_tcase(Suite *suite, TCase *tc); 79178848Scokanevoid tcase_add_checked_fixture(TCase *, 80178848Scokane tcase_setup_function, 81178848Scokane tcase_teardown_function); 82178848Scokanevoid tcase_add_test(TCase *tc, tcase_test_function test); 83178848ScokaneSRunner *srunner_create(Suite *suite); 84178848Scokanevoid srunner_run_all(SRunner *runner, int verbosity); 85178848Scokaneint srunner_ntests_failed(SRunner *runner); 86178848Scokanevoid srunner_free(SRunner *runner); 87178848Scokane 88178848Scokane#ifdef __cplusplus 89178848Scokane} 90178848Scokane#endif 91