1178848Scokane/* Miniature re-implementation of the "check" library.
2178848Scokane
3355604Sdelphij   This is intended to support just enough of check to run the Expat
4355604Sdelphij   tests.  This interface is based entirely on the portion of the
5355604Sdelphij   check library being used.
6355604Sdelphij
7355604Sdelphij   This is *source* compatible, but not necessary *link* compatible.
8355604Sdelphij                            __  __            _
9355604Sdelphij                         ___\ \/ /_ __   __ _| |_
10355604Sdelphij                        / _ \\  /| '_ \ / _` | __|
11355604Sdelphij                       |  __//  \| |_) | (_| | |_
12355604Sdelphij                        \___/_/\_\ .__/ \__,_|\__|
13355604Sdelphij                                 |_| XML parser
14355604Sdelphij
15355604Sdelphij   Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
16355604Sdelphij   Copyright (c) 2000-2017 Expat development team
17355604Sdelphij   Licensed under the MIT license:
18355604Sdelphij
19355604Sdelphij   Permission is  hereby granted,  free of charge,  to any  person obtaining
20355604Sdelphij   a  copy  of  this  software   and  associated  documentation  files  (the
21355604Sdelphij   "Software"),  to  deal in  the  Software  without restriction,  including
22355604Sdelphij   without  limitation the  rights  to use,  copy,  modify, merge,  publish,
23355604Sdelphij   distribute, sublicense, and/or sell copies of the Software, and to permit
24355604Sdelphij   persons  to whom  the Software  is  furnished to  do so,  subject to  the
25355604Sdelphij   following conditions:
26355604Sdelphij
27355604Sdelphij   The above copyright  notice and this permission notice  shall be included
28355604Sdelphij   in all copies or substantial portions of the Software.
29355604Sdelphij
30355604Sdelphij   THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
31355604Sdelphij   EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
32355604Sdelphij   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
33355604Sdelphij   NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34355604Sdelphij   DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
35355604Sdelphij   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
36355604Sdelphij   USE OR OTHER DEALINGS IN THE SOFTWARE.
37355604Sdelphij*/
38355604Sdelphij
39178848Scokane#ifdef __cplusplus
40178848Scokaneextern "C" {
41178848Scokane#endif
42178848Scokane
43178848Scokane#define CK_NOFORK 0
44355604Sdelphij#define CK_FORK 1
45178848Scokane
46355604Sdelphij#define CK_SILENT 0
47355604Sdelphij#define CK_NORMAL 1
48178848Scokane#define CK_VERBOSE 2
49178848Scokane
50247296Sdelphij/* Workaround for Microsoft's compiler and Tru64 Unix systems where the
51355604Sdelphij   C compiler has a working __func__, but the C++ compiler only has a
52247296Sdelphij   working __FUNCTION__.  This could be fixed in configure.in, but it's
53247296Sdelphij   not worth it right now. */
54355604Sdelphij#if defined(_MSC_VER) || (defined(__osf__) && defined(__cplusplus))
55355604Sdelphij#  define __func__ __FUNCTION__
56178848Scokane#endif
57178848Scokane
58355604Sdelphij#define START_TEST(testname)                                                   \
59355604Sdelphij  static void testname(void) {                                                 \
60355604Sdelphij    _check_set_test_info(__func__, __FILE__, __LINE__);                        \
61178848Scokane    {
62355604Sdelphij#define END_TEST                                                               \
63355604Sdelphij  }                                                                            \
64355604Sdelphij  }
65178848Scokane
66355604Sdelphij#define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg)
67178848Scokane
68178848Scokanetypedef void (*tcase_setup_function)(void);
69178848Scokanetypedef void (*tcase_teardown_function)(void);
70178848Scokanetypedef void (*tcase_test_function)(void);
71178848Scokane
72178848Scokanetypedef struct SRunner SRunner;
73178848Scokanetypedef struct Suite Suite;
74178848Scokanetypedef struct TCase TCase;
75178848Scokane
76178848Scokanestruct SRunner {
77355604Sdelphij  Suite *suite;
78355604Sdelphij  int nchecks;
79355604Sdelphij  int nfailures;
80178848Scokane};
81178848Scokane
82178848Scokanestruct Suite {
83355604Sdelphij  const char *name;
84355604Sdelphij  TCase *tests;
85178848Scokane};
86178848Scokane
87178848Scokanestruct TCase {
88355604Sdelphij  const char *name;
89355604Sdelphij  tcase_setup_function setup;
90355604Sdelphij  tcase_teardown_function teardown;
91355604Sdelphij  tcase_test_function *tests;
92355604Sdelphij  int ntests;
93355604Sdelphij  int allocated;
94355604Sdelphij  TCase *next_tcase;
95178848Scokane};
96178848Scokane
97178848Scokane/* Internal helper. */
98355604Sdelphijvoid _check_set_test_info(char const *function, char const *filename,
99355604Sdelphij                          int lineno);
100178848Scokane
101178848Scokane/*
102178848Scokane * Prototypes for the actual implementation.
103178848Scokane */
104178848Scokane
105302305Sdelphijvoid _fail_unless(int condition, const char *file, int line, const char *msg);
106302305SdelphijSuite *suite_create(const char *name);
107302305SdelphijTCase *tcase_create(const char *name);
108178848Scokanevoid suite_add_tcase(Suite *suite, TCase *tc);
109355604Sdelphijvoid tcase_add_checked_fixture(TCase *, tcase_setup_function,
110178848Scokane                               tcase_teardown_function);
111178848Scokanevoid tcase_add_test(TCase *tc, tcase_test_function test);
112178848ScokaneSRunner *srunner_create(Suite *suite);
113178848Scokanevoid srunner_run_all(SRunner *runner, int verbosity);
114178848Scokaneint srunner_ntests_failed(SRunner *runner);
115178848Scokanevoid srunner_free(SRunner *runner);
116178848Scokane
117178848Scokane#ifdef __cplusplus
118178848Scokane}
119178848Scokane#endif
120