su
1.12.11devel
libsofia-sip-ua
su
sofia-sip
tstdef.h
Go to the documentation of this file.
1
/*
2
* This file is part of the Sofia-SIP package
3
*
4
* Copyright (C) 2005 Nokia Corporation.
5
*
6
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* as published by the Free Software Foundation; either version 2.1 of
11
* the License, or (at your option) any later version.
12
*
13
* This library is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21
* 02110-1301 USA
22
*
23
*/
24
129
#ifndef SU_TYPES_H
130
#include <
sofia-sip/su_types.h
>
131
#endif
132
133
SOFIA_BEGIN_DECLS
134
135
#if HAVE_FUNC
136
#define TSTNAME name, __func__, "() "
137
#elif HAVE_FUNCTION
138
#define TSTNAME name, __FUNCTION__, "() "
139
#else
140
#define TSTNAME name, "", ""
141
#endif
142
143
enum
{
145
tst_verbatim
= 1,
147
tst_abort
= 2,
149
tst_log
= 4
150
};
151
152
#ifndef TSTFLAGS
153
#error <TSTFLAGS is not defined>
154
#endif
155
157
#define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
158
159
#define END() (void) tstdef_dummy; } END_(TSTFLAGS)
160
163
#define TEST0(suite) TEST_1_(TSTFLAGS, suite)
164
165
#define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
166
167
#define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
168
169
#define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
170
171
#define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
172
173
#define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
174
175
#define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
176
177
#define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
178
179
#define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
180
181
#define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)
182
184
#define TEST_LOG(x) \
185
do { \
186
if (tstflags & tst_log) \
187
printf x; \
188
} while(0)
189
190
#define TEST_FAILED(flags) \
191
(((flags) & tst_abort) || getenv("SOFIA_SIP_TEST_ABORT")) \
192
? abort() : (void)0; return 1
193
195
#define TEST_1_(flags, suite) do { \
196
if (flags & tst_verbatim) { \
197
printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
198
fflush(stdout); } \
199
if ((suite)) { if (flags & tst_verbatim) \
200
printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
201
fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
202
__FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
203
TEST_FAILED(flags); } \
204
while(0)
205
207
#define TEST_VOID_(flags, suite) do { \
208
if (flags & tst_verbatim) { \
209
printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
210
fflush(stdout); } \
211
(suite); } while(0)
212
214
#define TEST_(flags, suite, expect) do { \
215
uintptr_t _value, _expect; \
216
if (flags & tst_verbatim) { \
217
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
218
fflush(stdout); } \
219
_value = (uintptr_t)(suite); \
220
_expect = (uintptr_t)(expect); \
221
if (_value == _expect) { \
222
if (flags & tst_verbatim) \
223
printf("%s: %s%sok: %s == %s \n", \
224
TSTNAME, #suite, #expect); \
225
break; \
226
} \
227
fprintf(stderr, "%s:%u: %s %s%sFAILED: " \
228
"%s != %s or "MOD_ZU" != "MOD_ZU"\n", \
229
__FILE__, __LINE__, TSTNAME, \
230
#suite, #expect, (size_t)_value, (size_t)_expect); \
231
fflush(stderr); \
232
TEST_FAILED(flags); \
233
} while(0)
234
236
#define TEST_P_(flags, suite, expect) do { \
237
void const * _value, * _expect; \
238
if (flags & tst_verbatim) { \
239
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
240
fflush(stdout); } \
241
if ((_value = (suite)) == (_expect = (expect))) { \
242
if (flags & tst_verbatim) \
243
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
244
break; \
245
} \
246
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n", \
247
__FILE__, __LINE__, TSTNAME, \
248
#suite, #expect, _value, _expect); fflush(stderr); \
249
TEST_FAILED(flags); \
250
} while(0)
251
253
#define TEST_SIZE_(flags, suite, expect) do { \
254
size_t _value, _expect; \
255
if (flags & tst_verbatim) { \
256
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
257
fflush(stdout); } \
258
if ((_value = (size_t)(suite)) == \
259
(_expect = (size_t)(expect))) \
260
{ if (flags & tst_verbatim) \
261
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
262
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
263
__FILE__, __LINE__, TSTNAME, \
264
#suite, #expect, _value, _expect); fflush(stderr); \
265
TEST_FAILED(flags); \
266
} while(0)
267
268
270
#define TEST64_(flags, suite, expect) do { \
271
uint64_t _value, _expect; \
272
if (flags & tst_verbatim) { \
273
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
274
fflush(stdout); } \
275
if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
276
{ if (flags & tst_verbatim) \
277
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
278
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
279
__FILE__, __LINE__, TSTNAME, \
280
#suite, #expect, (unsigned longlong)_value, \
281
(unsigned longlong)_expect); fflush(stderr); \
282
TEST_FAILED(flags); \
283
} while(0)
284
286
#define TEST_D_(flags, suite, expect) do { \
287
double _value, _expect; \
288
if (flags & tst_verbatim) { \
289
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
290
fflush(stdout); } \
291
if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
292
{ if (flags & tst_verbatim) \
293
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
294
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
295
__FILE__, __LINE__, TSTNAME, \
296
#suite, #expect, _value, _expect); fflush(stderr); \
297
TEST_FAILED(flags); \
298
} while(0)
299
301
#define TEST_S_(flags, suite, expect) do { \
302
char const * _value, * _expect; \
303
if (flags & tst_verbatim) { \
304
printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
305
fflush(stdout); } \
306
_value = (suite); \
307
_expect = (expect); \
308
if (((_value == NULL || _expect == NULL) && _value == _expect) || \
309
(_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
310
{ if (flags & tst_verbatim) \
311
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
312
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
313
__FILE__, __LINE__, TSTNAME, \
314
#suite, #expect, \
315
_value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
316
_expect); fflush(stderr); \
317
TEST_FAILED(flags); \
318
} while(0)
319
321
#define TEST_M_(flags, suite, expect, len) do { \
322
void const * _value, * _expect; \
323
size_t _len; \
324
if (flags & tst_verbatim) { \
325
printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
326
fflush(stdout); } \
327
_value = (suite); \
328
_expect = (expect); \
329
_len = (size_t)(len); \
330
if (((_value == NULL || _expect == NULL) && _value == _expect) || \
331
memcmp(_value, _expect, _len) == 0) \
332
{ if (flags & tst_verbatim) \
333
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
334
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
335
"or \"%.*s\" != \"%.*s\"\n", \
336
__FILE__, __LINE__, TSTNAME, \
337
#suite, #expect, (int)_len, \
338
(char *)_value, (int)_len, (char *)_expect); \
339
fflush(stderr); \
340
TEST_FAILED(flags); \
341
} while(0)
342
344
#define BEGIN_(flags) \
345
if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
346
348
#define END_(flags) \
349
if (flags & tst_verbatim) \
350
printf("%s: %s%sfinished fully successful\n", TSTNAME); \
351
return 0
352
353
SOFIA_END_DECLS
su_types.h
tst_abort
@ tst_abort
If (TSTFLAGS & tst_abort) is non-zero, abort() when failed.
Definition:
tstdef.h:147
tst_log
@ tst_log
If (TSTFLAGS & tst_log) is non-zero, log intermediate results.
Definition:
tstdef.h:149
tst_verbatim
@ tst_verbatim
If (TSTFLAGS & tst_verbatim) is non-zero, be verbatim.
Definition:
tstdef.h:145
Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.