su  1.12.11
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 
00129 #ifndef SU_TYPES_H
00130 #include <sofia-sip/su_types.h>
00131 #endif
00132 
00133 SOFIA_BEGIN_DECLS
00134 
00135 #if HAVE_FUNC
00136 #define TSTNAME name, __func__, "() "
00137 #elif HAVE_FUNCTION
00138 #define TSTNAME name, __FUNCTION__, "() "
00139 #else
00140 #define TSTNAME name, "", ""
00141 #endif
00142 
00143 enum {
00145   tst_verbatim = 1,
00147   tst_abort = 2,
00149   tst_log = 4
00150 };
00151 
00152 #ifndef TSTFLAGS
00153 #error <TSTFLAGS is not defined>
00154 #endif
00155 
00157 #define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
00158 
00159 #define END() (void) tstdef_dummy; } END_(TSTFLAGS)
00160 
00163 #define TEST0(suite) TEST_1_(TSTFLAGS, suite)
00164 
00165 #define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
00166 
00167 #define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
00168 
00169 #define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
00170 
00171 #define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
00172 
00173 #define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
00174 
00175 #define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
00176 
00177 #define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
00178 
00179 #define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
00180 
00181 #define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)
00182 
00184 #define TEST_LOG(x)                    \
00185   do {                                 \
00186     if (tstflags & tst_log)            \
00187       printf x;                        \
00188   } while(0)
00189 
00190 #define TEST_FAILED(flags) \
00191   (((flags) & tst_abort) || getenv("SOFIA_SIP_TEST_ABORT"))     \
00192   ? abort() : (void)0; return 1
00193 
00195 #define TEST_1_(flags, suite) do { \
00196   if (flags & tst_verbatim) { \
00197     printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00198     fflush(stdout); } \
00199   if ((suite)) { if (flags & tst_verbatim) \
00200   printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
00201   fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
00202           __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
00203   TEST_FAILED(flags); }                                         \
00204   while(0)
00205 
00207 #define TEST_VOID_(flags, suite) do { \
00208   if (flags & tst_verbatim) { \
00209     printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00210     fflush(stdout); } \
00211   (suite); } while(0)
00212 
00214 #define TEST_(flags, suite, expect) do {                                \
00215     uintptr_t _value, _expect;                                          \
00216     if (flags & tst_verbatim) {                                         \
00217       printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect);   \
00218       fflush(stdout); }                                                 \
00219     _value = (uintptr_t)(suite);                                        \
00220     _expect = (uintptr_t)(expect);                                      \
00221     if (_value == _expect) {                                            \
00222       if (flags & tst_verbatim)                                         \
00223         printf("%s: %s%sok: %s == %s \n",                               \
00224                TSTNAME, #suite, #expect);                               \
00225       break;                                                            \
00226     }                                                                   \
00227     fprintf(stderr, "%s:%u: %s %s%sFAILED: "                            \
00228             "%s != %s or "MOD_ZU" != "MOD_ZU"\n",                       \
00229             __FILE__, __LINE__, TSTNAME,                                \
00230             #suite, #expect, (size_t)_value, (size_t)_expect);          \
00231     fflush(stderr);                                                     \
00232     TEST_FAILED(flags);                                                 \
00233   } while(0)
00234 
00236 #define TEST_P_(flags, suite, expect) do {                              \
00237     void const * _value, * _expect;                                     \
00238   if (flags & tst_verbatim) {                                           \
00239     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect);     \
00240     fflush(stdout); }                                                   \
00241   if ((_value = (suite)) == (_expect = (expect))) {                     \
00242     if (flags & tst_verbatim)                                           \
00243       printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);      \
00244     break;                                                              \
00245   }                                                                     \
00246   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n",       \
00247           __FILE__, __LINE__, TSTNAME,                                  \
00248           #suite, #expect, _value, _expect); fflush(stderr);            \
00249   TEST_FAILED(flags);                                                   \
00250   } while(0)
00251 
00253 #define TEST_SIZE_(flags, suite, expect) do {   \
00254   size_t _value, _expect; \
00255   if (flags & tst_verbatim) { \
00256     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00257     fflush(stdout); } \
00258   if ((_value = (size_t)(suite)) == \
00259       (_expect = (size_t)(expect))) \
00260   { if (flags & tst_verbatim) \
00261   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00262   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
00263          __FILE__, __LINE__, TSTNAME, \
00264           #suite, #expect, _value, _expect); fflush(stderr);            \
00265   TEST_FAILED(flags);                                                   \
00266   } while(0)
00267 
00268 
00270 #define TEST64_(flags, suite, expect) do { \
00271   uint64_t _value, _expect; \
00272   if (flags & tst_verbatim) { \
00273     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00274     fflush(stdout); } \
00275   if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
00276   { if (flags & tst_verbatim) \
00277   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00278   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
00279          __FILE__, __LINE__, TSTNAME, \
00280           #suite, #expect, (unsigned longlong)_value,   \
00281          (unsigned longlong)_expect); fflush(stderr);   \
00282   TEST_FAILED(flags);                                   \
00283   } while(0)
00284 
00286 #define TEST_D_(flags, suite, expect) do { \
00287   double _value, _expect; \
00288   if (flags & tst_verbatim) { \
00289     printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00290     fflush(stdout); } \
00291   if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
00292   { if (flags & tst_verbatim) \
00293   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00294   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
00295          __FILE__, __LINE__, TSTNAME, \
00296          #suite, #expect, _value, _expect); fflush(stderr); \
00297   TEST_FAILED(flags);                                       \
00298   } while(0)
00299 
00301 #define TEST_S_(flags, suite, expect) do { \
00302   char const * _value, * _expect; \
00303   if (flags & tst_verbatim) { \
00304     printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00305     fflush(stdout); } \
00306   _value = (suite); \
00307   _expect = (expect); \
00308   if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00309       (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
00310   { if (flags & tst_verbatim) \
00311   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00312   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
00313          __FILE__, __LINE__, TSTNAME, \
00314           #suite, #expect, \
00315           _value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
00316           _expect); fflush(stderr);                                     \
00317   TEST_FAILED(flags);                                                   \
00318   } while(0)
00319 
00321 #define TEST_M_(flags, suite, expect, len) do { \
00322   void const * _value, * _expect; \
00323   size_t _len; \
00324   if (flags & tst_verbatim) { \
00325     printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00326     fflush(stdout); } \
00327   _value = (suite); \
00328   _expect = (expect); \
00329   _len = (size_t)(len); \
00330   if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00331       memcmp(_value, _expect, _len) == 0) \
00332   { if (flags & tst_verbatim) \
00333   printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00334   fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
00335                   "or \"%.*s\" != \"%.*s\"\n", \
00336          __FILE__, __LINE__, TSTNAME, \
00337           #suite, #expect, (int)_len, \
00338           (char *)_value, (int)_len, (char *)_expect); \
00339   fflush(stderr);                                                       \
00340   TEST_FAILED(flags);                                                   \
00341   } while(0)
00342 
00344 #define BEGIN_(flags) \
00345   if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
00346 
00348 #define END_(flags) \
00349   if (flags & tst_verbatim) \
00350     printf("%s: %s%sfinished fully successful\n", TSTNAME); \
00351   return 0
00352 
00353 SOFIA_END_DECLS
 All Data Structures Files Functions Variables Typedefs Enumerator Defines

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