1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 #ifndef UCX_TEST_H
72 #define UCX_TEST_H
73
74 #include "ucx.h"
75 #include <stdio.h>
76 #include <string.h>
77 #include <setjmp.h>
78
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82
83 #ifndef __FUNCTION__
84
85
86
87
88
89
90
91 #define __FUNCTION__ __func__
92 #endif
93
94
95 typedef struct UcxTestSuite UcxTestSuite;
96
97
98 typedef void(*UcxTest)(UcxTestSuite*,
FILE*);
99
100
101 typedef struct UcxTestList UcxTestList;
102
103
104 struct UcxTestList {
105
106
107 UcxTest test;
108
109
110 UcxTestList *next;
111 };
112
113
114
115
116 struct UcxTestSuite {
117
118
119 unsigned int success;
120
121
122 unsigned int failure;
123
124
125
126
127
128 UcxTestList *tests;
129 };
130
131
132
133
134
135 UcxTestSuite* ucx_test_suite_new();
136
137
138
139
140
141 void ucx_test_suite_free(UcxTestSuite* suite);
142
143
144
145
146
147
148
149
150
151 int ucx_test_register(UcxTestSuite* suite, UcxTest test);
152
153
154
155
156
157
158 void ucx_test_run(UcxTestSuite* suite,
FILE* outstream);
159
160
161
162
163
164
165
166
167 #define UCX_TEST(name)
void name(UcxTestSuite* _suite_,
FILE *_output_)
168
169
170
171
172
173
174
175
176 #define UCX_TEST_BEGIN fwrite(
"Running ",
1,
8, _output_);\
177 fwrite(
__FUNCTION__,
1, strlen(
__FUNCTION__), _output_);\
178 fwrite(
"... ",
1,
4, _output_);\
179 jmp_buf _env_; \
180 if (!setjmp(_env_)) {
181
182
183
184
185
186
187
188
189
190 #define UCX_TEST_ASSERT(condition,message)
if (!(condition)) { \
191 fwrite(
".\n"message,
1,
2+strlen(message), _output_); \
192 _suite_->failure++; \
193 longjmp(_env_,
1);\
194 }
195
196
197
198
199
200
201
202
203
204
205
206
207 #define UCX_TEST_SUBROUTINE(name,...)
void name(UcxTestSuite* _suite_,\
208 FILE *_output_, jmp_buf _env_,
__VA_ARGS__)
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224 #define UCX_TEST_CALL_SUBROUTINE(name,...) \
225 name(_suite_,_output_,_env_,
__VA_ARGS__);
226
227
228
229
230
231
232
233
234 #define UCX_TEST_END fwrite(
"success.\n",
1,
9, _output_); _suite_->success++;}
235
236 #ifdef __cplusplus
237 }
238 #endif
239
240 #endif
241
242