Debian Codegraph @

check/stf/fcml_stf.h

raw
1 /*
2 * FCML - Free Code Manipulation Library.
3 * Copyright (C) 2010-2021 Slawomir Wojtasiak
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef FCML_STF_H_
21 #define FCML_STF_H_
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #if _WIN32 || __CYGWIN__
28 #define LIB_CALL_STF __stdcall
29 #ifdef DLL_EXPORT
30 #define LIB_EXPORT_STF __declspec(dllexport)
31 #else
32 #ifdef LIBSTF_DLL_IMPORT
33 #define LIB_EXPORT_STF __declspec(dllimport)
34 #endif
35 #endif
36 #endif
37
38 #ifndef LIB_EXPORT_STF
39 #define LIB_EXPORT_STF
40 #endif
41
42 #ifndef LIB_CALL_STF
43 #define LIB_CALL_STF
44 #endif
45
46 #define FCML_STF_NULL_SUITE NULL
47 #define FCML_STF_NULL_TEST { NULL, NULL }
48
49 #include <fcml_types.h>
50 #include <string.h>
51
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55
56 typedef fcml_bool (*fcml_stf_test_init_function)(void);
57 typedef void (*fcml_stf_test_case_function)(void);
58
59 typedef struct fcml_stf_test_case {
60 const fcml_string name;
61 fcml_stf_test_case_function test_function;
62 } fcml_stf_test_case;
63
64 typedef struct fcml_stf_test_suite {
65 const fcml_string name;
66 fcml_stf_test_init_function init_function;
67 fcml_stf_test_init_function cleanup_function;
68 fcml_stf_test_case *test_cases;
69 } fcml_stf_test_suite;
70
71 typedef struct fcml_stf_result_element {
72 struct fcml_stf_result_element *next;
73 fcml_int line;
74 const fcml_string file;
75 const fcml_string message;
76 fcml_stf_test_case *test_case;
77 fcml_stf_test_suite *suite;
78 } fcml_stf_result_element;
79
80 typedef struct fcml_stf_test_counter {
81 fcml_int passed;
82 fcml_int failed;
83 } fcml_stf_test_counter;
84
85 typedef struct fcml_stf_test_result {
86 fcml_stf_result_element *first;
87 fcml_stf_result_element *last;
88 /* Counters.*/
89 fcml_stf_test_counter suites;
90 fcml_stf_test_counter tests;
91 fcml_stf_test_counter asserts;
92 } fcml_stf_test_result;
93
94 extern fcml_stf_test_result fcml_gl_stf_test_result;
95
96 /* Asserts */
97
98 fcml_bool LIB_CALL_STF LIB_EXPORT_STF fcml_str_run_assert(fcml_bool condition,
99 const fcml_string file, fcml_int line, const fcml_string message);
100
101 /* Equals.*/
102 #define STF_ASSERT_EQUAL(actual, expected) \
103 (fcml_str_run_assert((actual) == (expected), __FILE__, __LINE__, \
104 ("STF_ASSERT_EQUAL(" #actual "," #expected ")")))
105
106 /* Not equal.*/
107 #define STF_ASSERT_NOT_EQUAL(actual, expected) \
108 (fcml_str_run_assert((actual) != (expected), __FILE__, __LINE__, \
109 ("STF_ASSERT_NOT_EQUAL(" #actual "," #expected ")")))
110
111 /* Boolean.*/
112 #define STF_ASSERT(condition) \
113 fcml_str_run_assert((condition), __FILE__, __LINE__, \
114 ("STF_ASSERT(" #condition ")"))
115
116 /* Not NULL.*/
117 #define STF_ASSERT_PTR_NOT_NULL(value) \
118 fcml_str_run_assert((value) != NULL, __FILE__, __LINE__, \
119 ("STF_ASSERT_PTR_NOT_NULL(" #value ")") )
120
121 /* Not NULL.*/
122 #define STF_ASSERT_PTR_NULL(value) \
123 fcml_str_run_assert((value) == NULL, __FILE__, __LINE__, \
124 ("STF_ASSERT_PTR_NULL(" #value ")"))
125
126 /* Fail immediately. */
127 #define STF_FAIL(value) \
128 fcml_str_run_assert( FCML_FALSE, __FILE__, __LINE__, \
129 ("STF_FAIL(" #value ")"))
130
131 /* String equal.*/
132 #define STF_ASSERT_STRING_EQUAL(actual, expected) \
133 fcml_str_run_assert( (strcmp(actual,expected)==0), __FILE__, __LINE__, \
134 ("STF_ASSERT_STRING_EQUAL(" #actual "," #expected ")"))
135
136 fcml_bool LIB_CALL_STF LIB_EXPORT_STF fcml_stf_run_tests(
137 const fcml_string test_name, fcml_stf_test_suite **suite);
138
139 #ifdef __cplusplus
140 }
141 #endif
142
143 #endif /* FCML_STF_H_ */