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