minicheck.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #define CK_NOFORK 0
  13. #define CK_FORK 1
  14. #define CK_SILENT 0
  15. #define CK_NORMAL 1
  16. #define CK_VERBOSE 2
  17. /* Workaround for Tru64 Unix systems where the C compiler has a working
  18. __func__, but the C++ compiler only has a working __FUNCTION__. This
  19. could be fixed in configure.in, but it's not worth it right now. */
  20. #if defined(__osf__) && defined(__cplusplus)
  21. #define __func__ __FUNCTION__
  22. #endif
  23. #define START_TEST(testname) static void testname(void) { \
  24. _check_set_test_info(__func__, __FILE__, __LINE__); \
  25. {
  26. #define END_TEST } }
  27. #define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg)
  28. typedef void (*tcase_setup_function)(void);
  29. typedef void (*tcase_teardown_function)(void);
  30. typedef void (*tcase_test_function)(void);
  31. typedef struct SRunner SRunner;
  32. typedef struct Suite Suite;
  33. typedef struct TCase TCase;
  34. struct SRunner {
  35. Suite *suite;
  36. int nchecks;
  37. int nfailures;
  38. };
  39. struct Suite {
  40. char *name;
  41. TCase *tests;
  42. };
  43. struct TCase {
  44. char *name;
  45. tcase_setup_function setup;
  46. tcase_teardown_function teardown;
  47. tcase_test_function *tests;
  48. int ntests;
  49. int allocated;
  50. TCase *next_tcase;
  51. };
  52. /* Internal helper. */
  53. void _check_set_test_info(char const *function,
  54. char const *filename, int lineno);
  55. /*
  56. * Prototypes for the actual implementation.
  57. */
  58. void _fail_unless(int condition, const char *file, int line, char *msg);
  59. Suite *suite_create(char *name);
  60. TCase *tcase_create(char *name);
  61. void suite_add_tcase(Suite *suite, TCase *tc);
  62. void tcase_add_checked_fixture(TCase *,
  63. tcase_setup_function,
  64. tcase_teardown_function);
  65. void tcase_add_test(TCase *tc, tcase_test_function test);
  66. SRunner *srunner_create(Suite *suite);
  67. void srunner_run_all(SRunner *runner, int verbosity);
  68. int srunner_ntests_failed(SRunner *runner);
  69. void srunner_free(SRunner *runner);
  70. #ifdef __cplusplus
  71. }
  72. #endif