sofia-sip/tstdef.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00123 #ifndef SU_TYPES_H
00124 #include <sofia-sip/su_types.h>
00125 #endif
00126 
00127 SOFIA_BEGIN_DECLS
00128 
00129 #if HAVE_FUNC
00130 #define TSTNAME name, __func__, "() "
00131 #elif HAVE_FUNCTION
00132 #define TSTNAME name, __FUNCTION__, "() "
00133 #else
00134 #define TSTNAME name, "", ""
00135 #endif
00136 
00137 enum {
00139   tst_verbatim = 1,
00141   tst_abort = 2,
00142 };
00143 
00144 #ifndef TSTFLAGS
00145 #error <TSTFLAGS is not defined>
00146 #endif
00147 
00148 #ifdef TSTFLAGS
00149 
00150 #define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
00151 
00152 #define END() (void) tstdef_dummy; } END_(TSTFLAGS)
00153 
00156 #define TEST0(suite) TEST_1_(TSTFLAGS, suite)
00157 
00158 #define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
00159 
00160 #define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
00161 
00162 #define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
00163 
00164 #define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
00165 
00166 #define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
00167 
00168 #define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
00169 
00170 #define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
00171 
00172 #define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
00173 
00174 #define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)
00175 
00176 #else
00177 /* Deprecated */
00178 #define TEST0(flags, suite) TEST_1_(flags, suite)
00179 #define TEST_1(flags, suite) TEST_1_(flags, suite)
00180 #define TEST_VOID(flags, suite) TEST_VOID_(flags, suite)
00181 #define TEST(flags, suite, expect) TEST_(flags, suite, expect)
00182 #define TEST64(flags, suite, expect) TEST64_(flags, suite, expect)
00183 #define TEST_S(flags, suite, expect) TEST_S_(flags, suite, expect)
00184 #define BEGIN(flags) BEGIN_(flags) { extern int tstdef_dummy
00185 #define END(flags) (void) tstdef_dummy;  } END_(flags) 
00186 #endif
00187 
00188 #define TEST_FAILED(flags) \
00189   ((flags) & tst_abort) ? abort() : (void)0; return 1
00190 
00192 #define TEST_1_(flags, suite) do { \
00193   if (flags & tst_verbatim) { \
00194     printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00195     fflush(stdout); } \
00196   if ((suite)) { if (flags & tst_verbatim) \
00197   printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
00198   fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
00199           __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
00200   TEST_FAILED(flags); }                                         \
00201   while(0)
00202 
00204 #define TEST_VOID_(flags, suite) do { \
00205   if (flags & tst_verbatim) { \
00206     printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00207     fflush(stdout); } \
00208   (suite); } while(0)
00209 
00211 #define TEST_(flags, suite, expect) do {                                \
00212     uintptr_t _value, _expect;                                          \
00213     if (flags & tst_verbatim) {                                         \
00214       printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect);   \
00215       fflush(stdout); }                                                 \
00216     _value = (uintptr_t)(suite);                                        \
00217     _expect = (uintptr_t)(expect);                                      \
00218     if (_value == _expect) {                                            \
00219       if (flags & tst_verbatim)                                         \
00220         printf("%s: %s%sok: %s == %s \n",                               \
00221                TSTNAME, #suite, #expect);                               \
00222       break;                                                            \
00223     }                                                                   \
00224     fprintf(stderr, "%s:%u: %s %s%sFAILED: "                            \
00225             "%s != %s or "MOD_ZU" != "MOD_ZU"\n",                       \
00226             __FILE__, __LINE__, TSTNAME,                                \
00227             #suite, #expect, (size_t)_value, (size_t)_expect);          \
00228     fflush(stderr);                                                     \
00229     TEST_FAILED(flags);                                                 \
00230   } while(0)
00231 
00233 #define TEST_P_(flags, suite, expect) do {                              \
00234     void const * _value, * _expect;                                     \
00235   if (flags & tst_verbatim) {                                           \
00236     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect);     \
00237     fflush(stdout); }                                                   \
00238   if ((_value = (suite)) == (_expect = (expect))) {                     \
00239     if (flags & tst_verbatim)                                           \
00240       printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);      \
00241     break;                                                              \
00242   }                                                                     \
00243   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n",       \
00244           __FILE__, __LINE__, TSTNAME,                                  \
00245           #suite, #expect, _value, _expect); fflush(stderr);            \
00246   TEST_FAILED(flags);                                                   \
00247   } while(0)
00248 
00250 #define TEST_SIZE_(flags, suite, expect) do {   \
00251   size_t _value, _expect; \
00252   if (flags & tst_verbatim) { \
00253     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00254     fflush(stdout); } \
00255   if ((_value = (size_t)(suite)) == \
00256       (_expect = (size_t)(expect))) \
00257   { if (flags & tst_verbatim) \
00258   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00259   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
00260          __FILE__, __LINE__, TSTNAME, \
00261           #suite, #expect, _value, _expect); fflush(stderr);            \
00262   TEST_FAILED(flags);                                                   \
00263   } while(0)
00264 
00265 
00267 #define TEST64_(flags, suite, expect) do { \
00268   uint64_t _value, _expect; \
00269   if (flags & tst_verbatim) { \
00270     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00271     fflush(stdout); } \
00272   if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
00273   { if (flags & tst_verbatim) \
00274   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00275   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
00276          __FILE__, __LINE__, TSTNAME, \
00277           #suite, #expect, (unsigned longlong)_value,   \
00278          (unsigned longlong)_expect); fflush(stderr);   \
00279   TEST_FAILED(flags);                                   \
00280   } while(0)
00281 
00283 #define TEST_D_(flags, suite, expect) do { \
00284   double _value, _expect; \
00285   if (flags & tst_verbatim) { \
00286     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00287     fflush(stdout); } \
00288   if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
00289   { if (flags & tst_verbatim) \
00290   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00291   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
00292          __FILE__, __LINE__, TSTNAME, \
00293          #suite, #expect, _value, _expect); fflush(stderr); \
00294   TEST_FAILED(flags);                                       \
00295   } while(0)
00296 
00298 #define TEST_S_(flags, suite, expect) do { \
00299   char const * _value, * _expect; \
00300   if (flags & tst_verbatim) { \
00301     printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00302     fflush(stdout); } \
00303   _value = (suite); \
00304   _expect = (expect); \
00305   if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00306       (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
00307   { if (flags & tst_verbatim) \
00308   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00309   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
00310          __FILE__, __LINE__, TSTNAME, \
00311           #suite, #expect, \
00312           _value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
00313           _expect); fflush(stderr);                                     \
00314   TEST_FAILED(flags);                                                   \
00315   } while(0)
00316 
00318 #define TEST_M_(flags, suite, expect, len) do { \
00319   void const * _value, * _expect; \
00320   int _len; \
00321   if (flags & tst_verbatim) { \
00322     printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00323     fflush(stdout); } \
00324   _value = (suite); \
00325   _expect = (expect); \
00326   _len = (len); \
00327   if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00328       memcmp(_value, _expect, _len) == 0) \
00329   { if (flags & tst_verbatim) \
00330   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00331   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
00332                   "or \"%.*s\" != \"%.*s\"\n", \
00333          __FILE__, __LINE__, TSTNAME, \
00334           #suite, #expect, _len, (char *)_value, _len, (char *)_expect); \
00335   fflush(stderr);                                                       \
00336   TEST_FAILED(flags);                                                   \
00337   } while(0)
00338 
00340 #define BEGIN_(flags) \
00341   if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
00342 
00344 #define END_(flags) \
00345   if (flags & tst_verbatim) \
00346     printf("%s: %s%sfinished fully successful\n", TSTNAME); \
00347   return 0
00348 
00349 SOFIA_END_DECLS

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