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