su  1.13.17
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 {
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
159 #define END() (void) tstdef_dummy; } END_(TSTFLAGS)
163 #define TEST0(suite) TEST_1_(TSTFLAGS, suite)
165 #define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
167 #define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
169 #define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
171 #define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
173 #define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
175 #define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
177 #define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
179 #define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
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) ? abort() : (void)0; return 1
192 
194 #define TEST_1_(flags, suite) do { \
195  if (flags & tst_verbatim) { \
196  printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
197  fflush(stdout); } \
198  if ((suite)) { \
199  if (flags & tst_verbatim) \
200  printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); \
201  break; } \
202  fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
203  __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
204  TEST_FAILED(flags); } \
205  while(0)
206 
208 #define TEST_VOID_(flags, suite) do { \
209  if (flags & tst_verbatim) { \
210  printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
211  fflush(stdout); } \
212  (suite); } while(0)
213 
215 #define TEST_(flags, suite, expect) do { \
216  uintptr_t _value, _expect; \
217  if (flags & tst_verbatim) { \
218  printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
219  fflush(stdout); } \
220  _value = (uintptr_t)(suite); \
221  _expect = (uintptr_t)(expect); \
222  if (_value == _expect) { \
223  if (flags & tst_verbatim) \
224  printf("%s: %s%sok: %s == %s \n", \
225  TSTNAME, #suite, #expect); \
226  break; \
227  } \
228  fprintf(stderr, "%s:%u: %s %s%sFAILED: " \
229  "%s != %s or "MOD_ZU" != "MOD_ZU"\n", \
230  __FILE__, __LINE__, TSTNAME, \
231  #suite, #expect, (size_t)_value, (size_t)_expect); \
232  fflush(stderr); \
233  TEST_FAILED(flags); \
234  } while(0)
235 
237 #define TEST_P_(flags, suite, expect) do { \
238  void const * _value, * _expect; \
239  if (flags & tst_verbatim) { \
240  printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
241  fflush(stdout); } \
242  if ((_value = (suite)) == (_expect = (expect))) { \
243  if (flags & tst_verbatim) \
244  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
245  break; \
246  } \
247  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n", \
248  __FILE__, __LINE__, TSTNAME, \
249  #suite, #expect, _value, _expect); fflush(stderr); \
250  TEST_FAILED(flags); \
251  } while(0)
252 
254 #define TEST_SIZE_(flags, suite, expect) do { \
255  size_t _value, _expect; \
256  if (flags & tst_verbatim) { \
257  printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
258  fflush(stdout); } \
259  if ((_value = (size_t)(suite)) == \
260  (_expect = (size_t)(expect))) { \
261  if (flags & tst_verbatim) \
262  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
263  break; } \
264  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
265  __FILE__, __LINE__, TSTNAME, \
266  #suite, #expect, _value, _expect); fflush(stderr); \
267  TEST_FAILED(flags); \
268  } while(0)
269 
270 
272 #define TEST64_(flags, suite, expect) do { \
273  uint64_t _value, _expect; \
274  if (flags & tst_verbatim) { \
275  printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
276  fflush(stdout); } \
277  if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) { \
278  if (flags & tst_verbatim) \
279  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
280  break; } \
281  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
282  __FILE__, __LINE__, TSTNAME, \
283  #suite, #expect, (unsigned longlong)_value, \
284  (unsigned longlong)_expect); fflush(stderr); \
285  TEST_FAILED(flags); \
286  } while(0)
287 
289 #define TEST_D_(flags, suite, expect) do { \
290  double _value, _expect; \
291  if (flags & tst_verbatim) { \
292  printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
293  fflush(stdout); } \
294  if ((_value = (double)(suite)) == (_expect = (double)(expect))) { \
295  if (flags & tst_verbatim) \
296  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
297  break; } \
298  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
299  __FILE__, __LINE__, TSTNAME, \
300  #suite, #expect, _value, _expect); fflush(stderr); \
301  TEST_FAILED(flags); \
302  } while(0)
303 
305 #define TEST_S_(flags, suite, expect) do { \
306  char const * _value, * _expect; \
307  if (flags & tst_verbatim) { \
308  printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
309  fflush(stdout); } \
310  _value = (suite); \
311  _expect = (expect); \
312  if (((_value == NULL || _expect == NULL) && _value == _expect) || \
313  (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) { \
314  if (flags & tst_verbatim) \
315  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
316  break; } \
317  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
318  __FILE__, __LINE__, TSTNAME, \
319  #suite, #expect, \
320  _value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
321  _expect); fflush(stderr); \
322  TEST_FAILED(flags); \
323  } while(0)
324 
326 #define TEST_M_(flags, suite, expect, len) do { \
327  void const * _value, * _expect; \
328  size_t _len; \
329  if (flags & tst_verbatim) { \
330  printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
331  fflush(stdout); } \
332  _value = (suite); \
333  _expect = (expect); \
334  _len = (size_t)(len); \
335  if (((_value == NULL || _expect == NULL) && _value == _expect) || \
336  memcmp(_value, _expect, _len) == 0) { \
337  if (flags & tst_verbatim) \
338  printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
339  break; } \
340  fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
341  "or \"%.*s\" != \"%.*s\"\n", \
342  __FILE__, __LINE__, TSTNAME, \
343  #suite, #expect, (int)_len, \
344  (char *)_value, (int)_len, (char *)_expect); \
345  fflush(stderr); \
346  TEST_FAILED(flags); \
347  } while(0)
348 
350 #define BEGIN_(flags) \
351  if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
352 
354 #define END_(flags) \
355  if (flags & tst_verbatim) \
356  printf("%s: %s%sfinished fully successful\n", TSTNAME); \
357  return 0
358 
359 SOFIA_END_DECLS
Basic integer types for su library.
@ tst_log
If (TSTFLAGS & tst_log) is non-zero, log intermediate results.
Definition: tstdef.h:149
@ tst_abort
If (TSTFLAGS & tst_abort) is non-zero, abort() when failed.
Definition: tstdef.h:147
@ tst_verbatim
If (TSTFLAGS & tst_verbatim) is non-zero, be verbatim.
Definition: tstdef.h:145

Sofia-SIP 1.13.17 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.