1 1.1 tron /* Miniature re-implementation of the "check" library. 2 1.1.1.5 maya 3 1.1.1.5 maya This is intended to support just enough of check to run the Expat 4 1.1.1.5 maya tests. This interface is based entirely on the portion of the 5 1.1.1.5 maya check library being used. 6 1.1.1.5 maya 7 1.1.1.5 maya This is *source* compatible, but not necessary *link* compatible. 8 1.1.1.5 maya __ __ _ 9 1.1.1.5 maya ___\ \/ /_ __ __ _| |_ 10 1.1.1.5 maya / _ \\ /| '_ \ / _` | __| 11 1.1.1.5 maya | __// \| |_) | (_| | |_ 12 1.1.1.5 maya \___/_/\_\ .__/ \__,_|\__| 13 1.1.1.5 maya |_| XML parser 14 1.1.1.5 maya 15 1.1.1.6 christos Copyright (c) 2004-2006 Fred L. Drake, Jr. <fdrake (at) users.sourceforge.net> 16 1.1.1.6 christos Copyright (c) 2006-2012 Karl Waclawek <karl (at) waclawek.net> 17 1.1.1.7 wiz Copyright (c) 2016-2025 Sebastian Pipping <sebastian (at) pipping.org> 18 1.1.1.7 wiz Copyright (c) 2022 Rhodri James <rhodri (at) wildebeest.org.uk> 19 1.1.1.7 wiz Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild (at) sony.com> 20 1.1.1.5 maya Licensed under the MIT license: 21 1.1.1.5 maya 22 1.1.1.5 maya Permission is hereby granted, free of charge, to any person obtaining 23 1.1.1.5 maya a copy of this software and associated documentation files (the 24 1.1.1.5 maya "Software"), to deal in the Software without restriction, including 25 1.1.1.5 maya without limitation the rights to use, copy, modify, merge, publish, 26 1.1.1.5 maya distribute, sublicense, and/or sell copies of the Software, and to permit 27 1.1.1.5 maya persons to whom the Software is furnished to do so, subject to the 28 1.1.1.5 maya following conditions: 29 1.1.1.5 maya 30 1.1.1.5 maya The above copyright notice and this permission notice shall be included 31 1.1.1.5 maya in all copies or substantial portions of the Software. 32 1.1.1.5 maya 33 1.1.1.5 maya THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 34 1.1.1.5 maya EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 35 1.1.1.5 maya MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 36 1.1.1.5 maya NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 37 1.1.1.5 maya DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 38 1.1.1.5 maya OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 39 1.1.1.5 maya USE OR OTHER DEALINGS IN THE SOFTWARE. 40 1.1.1.5 maya */ 41 1.1 tron 42 1.1 tron #ifdef __cplusplus 43 1.1 tron extern "C" { 44 1.1 tron #endif 45 1.1 tron 46 1.1.1.7 wiz #ifndef XML_MINICHECK_H 47 1.1.1.7 wiz # define XML_MINICHECK_H 48 1.1 tron 49 1.1.1.7 wiz # define CK_NOFORK 0 50 1.1.1.7 wiz # define CK_FORK 1 51 1.1.1.7 wiz 52 1.1.1.7 wiz # define CK_SILENT 0 53 1.1.1.7 wiz # define CK_NORMAL 1 54 1.1.1.7 wiz # define CK_VERBOSE 2 55 1.1 tron 56 1.1.1.2 spz /* Workaround for Microsoft's compiler and Tru64 Unix systems where the 57 1.1.1.5 maya C compiler has a working __func__, but the C++ compiler only has a 58 1.1.1.2 spz working __FUNCTION__. This could be fixed in configure.in, but it's 59 1.1.1.2 spz not worth it right now. */ 60 1.1.1.7 wiz # if defined(_MSC_VER) || (defined(__osf__) && defined(__cplusplus)) 61 1.1.1.7 wiz # define __func__ __FUNCTION__ 62 1.1.1.7 wiz # endif 63 1.1.1.7 wiz 64 1.1.1.7 wiz /* PRINTF_LIKE has two effects: 65 1.1.1.7 wiz 1. Make clang's -Wformat-nonliteral stop warning about non-literal format 66 1.1.1.7 wiz strings in annotated functions' code. 67 1.1.1.7 wiz 2. Make both clang and gcc's -Wformat-nonliteral warn about *callers* of 68 1.1.1.7 wiz the annotated function that use a non-literal format string. 69 1.1.1.7 wiz */ 70 1.1.1.7 wiz # if defined(__GNUC__) 71 1.1.1.7 wiz # define PRINTF_LIKE(fmtpos, argspos) \ 72 1.1.1.7 wiz __attribute__((format(printf, fmtpos, argspos))) 73 1.1.1.7 wiz # else 74 1.1.1.7 wiz # define PRINTF_LIKE(fmtpos, argspos) 75 1.1.1.7 wiz # endif 76 1.1.1.7 wiz 77 1.1.1.7 wiz # define START_TEST(testname) \ 78 1.1.1.7 wiz static void testname(void) { \ 79 1.1.1.7 wiz _check_set_test_info(__func__, __FILE__, __LINE__); \ 80 1.1.1.7 wiz { 81 1.1.1.7 wiz # define END_TEST \ 82 1.1.1.7 wiz } \ 83 1.1.1.7 wiz } 84 1.1.1.7 wiz 85 1.1.1.7 wiz void PRINTF_LIKE(1, 2) set_subtest(char const *fmt, ...); 86 1.1.1.7 wiz 87 1.1.1.7 wiz # define fail(msg) _fail(__FILE__, __LINE__, msg) 88 1.1.1.7 wiz # define assert_true(cond) \ 89 1.1.1.7 wiz do { \ 90 1.1.1.7 wiz if (! (cond)) { \ 91 1.1.1.7 wiz _fail(__FILE__, __LINE__, "check failed: " #cond); \ 92 1.1.1.7 wiz } \ 93 1.1.1.7 wiz } while (0) 94 1.1 tron 95 1.1 tron typedef void (*tcase_setup_function)(void); 96 1.1 tron typedef void (*tcase_teardown_function)(void); 97 1.1 tron typedef void (*tcase_test_function)(void); 98 1.1 tron 99 1.1 tron typedef struct SRunner SRunner; 100 1.1 tron typedef struct Suite Suite; 101 1.1 tron typedef struct TCase TCase; 102 1.1 tron 103 1.1 tron struct SRunner { 104 1.1.1.5 maya Suite *suite; 105 1.1.1.5 maya int nchecks; 106 1.1.1.5 maya int nfailures; 107 1.1 tron }; 108 1.1 tron 109 1.1 tron struct Suite { 110 1.1.1.5 maya const char *name; 111 1.1.1.5 maya TCase *tests; 112 1.1 tron }; 113 1.1 tron 114 1.1 tron struct TCase { 115 1.1.1.5 maya const char *name; 116 1.1.1.5 maya tcase_setup_function setup; 117 1.1.1.5 maya tcase_teardown_function teardown; 118 1.1.1.5 maya tcase_test_function *tests; 119 1.1.1.5 maya int ntests; 120 1.1.1.5 maya int allocated; 121 1.1.1.5 maya TCase *next_tcase; 122 1.1 tron }; 123 1.1 tron 124 1.1 tron /* Internal helper. */ 125 1.1.1.5 maya void _check_set_test_info(char const *function, char const *filename, 126 1.1.1.5 maya int lineno); 127 1.1 tron 128 1.1 tron /* 129 1.1 tron * Prototypes for the actual implementation. 130 1.1 tron */ 131 1.1 tron 132 1.1.1.7 wiz # if defined(__has_attribute) 133 1.1.1.7 wiz # if __has_attribute(noreturn) 134 1.1.1.7 wiz __attribute__((noreturn)) 135 1.1.1.7 wiz # endif 136 1.1.1.7 wiz # endif 137 1.1.1.8 jdc void _fail(const char *file, int line, const char *msg); 138 1.1.1.3 spz Suite *suite_create(const char *name); 139 1.1.1.3 spz TCase *tcase_create(const char *name); 140 1.1 tron void suite_add_tcase(Suite *suite, TCase *tc); 141 1.1.1.7 wiz void tcase_add_checked_fixture(TCase *tc, tcase_setup_function setup, 142 1.1.1.7 wiz tcase_teardown_function teardown); 143 1.1 tron void tcase_add_test(TCase *tc, tcase_test_function test); 144 1.1 tron SRunner *srunner_create(Suite *suite); 145 1.1.1.7 wiz void srunner_run_all(SRunner *runner, const char *context, int verbosity); 146 1.1.1.7 wiz void srunner_summarize(SRunner *runner, int verbosity); 147 1.1 tron int srunner_ntests_failed(SRunner *runner); 148 1.1 tron void srunner_free(SRunner *runner); 149 1.1 tron 150 1.1.1.7 wiz #endif /* XML_MINICHECK_H */ 151 1.1.1.7 wiz 152 1.1 tron #ifdef __cplusplus 153 1.1 tron } 154 1.1 tron #endif 155