00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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) ? abort() : (void)0; return 1
00192
00194 #define TEST_1_(flags, suite) do { \
00195 if (flags & tst_verbatim) { \
00196 printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00197 fflush(stdout); } \
00198 if ((suite)) { if (flags & tst_verbatim) \
00199 printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
00200 fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
00201 __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
00202 TEST_FAILED(flags); } \
00203 while(0)
00204
00206 #define TEST_VOID_(flags, suite) do { \
00207 if (flags & tst_verbatim) { \
00208 printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00209 fflush(stdout); } \
00210 (suite); } while(0)
00211
00213 #define TEST_(flags, suite, expect) do { \
00214 uintptr_t _value, _expect; \
00215 if (flags & tst_verbatim) { \
00216 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00217 fflush(stdout); } \
00218 _value = (uintptr_t)(suite); \
00219 _expect = (uintptr_t)(expect); \
00220 if (_value == _expect) { \
00221 if (flags & tst_verbatim) \
00222 printf("%s: %s%sok: %s == %s \n", \
00223 TSTNAME, #suite, #expect); \
00224 break; \
00225 } \
00226 fprintf(stderr, "%s:%u: %s %s%sFAILED: " \
00227 "%s != %s or "MOD_ZU" != "MOD_ZU"\n", \
00228 __FILE__, __LINE__, TSTNAME, \
00229 #suite, #expect, (size_t)_value, (size_t)_expect); \
00230 fflush(stderr); \
00231 TEST_FAILED(flags); \
00232 } while(0)
00233
00235 #define TEST_P_(flags, suite, expect) do { \
00236 void const * _value, * _expect; \
00237 if (flags & tst_verbatim) { \
00238 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00239 fflush(stdout); } \
00240 if ((_value = (suite)) == (_expect = (expect))) { \
00241 if (flags & tst_verbatim) \
00242 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
00243 break; \
00244 } \
00245 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n", \
00246 __FILE__, __LINE__, TSTNAME, \
00247 #suite, #expect, _value, _expect); fflush(stderr); \
00248 TEST_FAILED(flags); \
00249 } while(0)
00250
00252 #define TEST_SIZE_(flags, suite, expect) do { \
00253 size_t _value, _expect; \
00254 if (flags & tst_verbatim) { \
00255 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00256 fflush(stdout); } \
00257 if ((_value = (size_t)(suite)) == \
00258 (_expect = (size_t)(expect))) \
00259 { if (flags & tst_verbatim) \
00260 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00261 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
00262 __FILE__, __LINE__, TSTNAME, \
00263 #suite, #expect, _value, _expect); fflush(stderr); \
00264 TEST_FAILED(flags); \
00265 } while(0)
00266
00267
00269 #define TEST64_(flags, suite, expect) do { \
00270 uint64_t _value, _expect; \
00271 if (flags & tst_verbatim) { \
00272 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00273 fflush(stdout); } \
00274 if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
00275 { if (flags & tst_verbatim) \
00276 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00277 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
00278 __FILE__, __LINE__, TSTNAME, \
00279 #suite, #expect, (unsigned longlong)_value, \
00280 (unsigned longlong)_expect); fflush(stderr); \
00281 TEST_FAILED(flags); \
00282 } while(0)
00283
00285 #define TEST_D_(flags, suite, expect) do { \
00286 double _value, _expect; \
00287 if (flags & tst_verbatim) { \
00288 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00289 fflush(stdout); } \
00290 if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
00291 { if (flags & tst_verbatim) \
00292 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00293 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
00294 __FILE__, __LINE__, TSTNAME, \
00295 #suite, #expect, _value, _expect); fflush(stderr); \
00296 TEST_FAILED(flags); \
00297 } while(0)
00298
00300 #define TEST_S_(flags, suite, expect) do { \
00301 char const * _value, * _expect; \
00302 if (flags & tst_verbatim) { \
00303 printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00304 fflush(stdout); } \
00305 _value = (suite); \
00306 _expect = (expect); \
00307 if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00308 (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
00309 { if (flags & tst_verbatim) \
00310 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00311 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
00312 __FILE__, __LINE__, TSTNAME, \
00313 #suite, #expect, \
00314 _value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
00315 _expect); fflush(stderr); \
00316 TEST_FAILED(flags); \
00317 } while(0)
00318
00320 #define TEST_M_(flags, suite, expect, len) do { \
00321 void const * _value, * _expect; \
00322 int _len; \
00323 if (flags & tst_verbatim) { \
00324 printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00325 fflush(stdout); } \
00326 _value = (suite); \
00327 _expect = (expect); \
00328 _len = (len); \
00329 if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00330 memcmp(_value, _expect, _len) == 0) \
00331 { if (flags & tst_verbatim) \
00332 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00333 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
00334 "or \"%.*s\" != \"%.*s\"\n", \
00335 __FILE__, __LINE__, TSTNAME, \
00336 #suite, #expect, _len, (char *)_value, _len, (char *)_expect); \
00337 fflush(stderr); \
00338 TEST_FAILED(flags); \
00339 } while(0)
00340
00342 #define BEGIN_(flags) \
00343 if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
00344
00346 #define END_(flags) \
00347 if (flags & tst_verbatim) \
00348 printf("%s: %s%sfinished fully successful\n", TSTNAME); \
00349 return 0
00350
00351 SOFIA_END_DECLS