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