• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                         / _ \\  /| '_ \ / _` | __|
11                        |  __//  \| |_) | (_| | |_
12                         \___/_/\_\ .__/ \__,_|\__|
13                                  |_| XML parser
14 
15    Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
16    Copyright (c) 2000-2017 Expat development team
17    Licensed under the MIT license:
18 
19    Permission is  hereby granted,  free of charge,  to any  person obtaining
20    a  copy  of  this  software   and  associated  documentation  files  (the
21    "Software"),  to  deal in  the  Software  without restriction,  including
22    without  limitation the  rights  to use,  copy,  modify, merge,  publish,
23    distribute, sublicense, and/or sell copies of the Software, and to permit
24    persons  to whom  the Software  is  furnished to  do so,  subject to  the
25    following conditions:
26 
27    The above copyright  notice and this permission notice  shall be included
28    in all copies or substantial portions of the Software.
29 
30    THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
31    EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
32    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33    NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34    DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
35    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
36    USE OR OTHER DEALINGS IN THE SOFTWARE.
37 */
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
43 #define CK_NOFORK 0
44 #define CK_FORK   1
45 
46 #define CK_SILENT  0
47 #define CK_NORMAL  1
48 #define CK_VERBOSE 2
49 
50 /* Workaround for Microsoft's compiler and Tru64 Unix systems where the
51    C compiler has a working __func__, but the C++ compiler only has a
52    working __FUNCTION__.  This could be fixed in configure.in, but it's
53    not worth it right now. */
54 #if defined (_MSC_VER) || (defined(__osf__) && defined(__cplusplus))
55 #define __func__ __FUNCTION__
56 #endif
57 
58 #define START_TEST(testname) static void testname(void) { \
59     _check_set_test_info(__func__, __FILE__, __LINE__);   \
60     {
61 #define END_TEST } }
62 
63 #define fail(msg)  _fail_unless(0, __FILE__, __LINE__, msg)
64 
65 typedef void (*tcase_setup_function)(void);
66 typedef void (*tcase_teardown_function)(void);
67 typedef void (*tcase_test_function)(void);
68 
69 typedef struct SRunner SRunner;
70 typedef struct Suite Suite;
71 typedef struct TCase TCase;
72 
73 struct SRunner {
74     Suite *suite;
75     int nchecks;
76     int nfailures;
77 };
78 
79 struct Suite {
80     const char *name;
81     TCase *tests;
82 };
83 
84 struct TCase {
85     const char *name;
86     tcase_setup_function setup;
87     tcase_teardown_function teardown;
88     tcase_test_function *tests;
89     int ntests;
90     int allocated;
91     TCase *next_tcase;
92 };
93 
94 
95 /* Internal helper. */
96 void _check_set_test_info(char const *function,
97                           char const *filename, int lineno);
98 
99 
100 /*
101  * Prototypes for the actual implementation.
102  */
103 
104 void _fail_unless(int condition, const char *file, int line, const char *msg);
105 Suite *suite_create(const char *name);
106 TCase *tcase_create(const char *name);
107 void suite_add_tcase(Suite *suite, TCase *tc);
108 void tcase_add_checked_fixture(TCase *,
109                                tcase_setup_function,
110                                tcase_teardown_function);
111 void tcase_add_test(TCase *tc, tcase_test_function test);
112 SRunner *srunner_create(Suite *suite);
113 void srunner_run_all(SRunner *runner, int verbosity);
114 int srunner_ntests_failed(SRunner *runner);
115 void srunner_free(SRunner *runner);
116 
117 #ifdef __cplusplus
118 }
119 #endif
120