00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00140 };
00141
00142 #ifndef TSTFLAGS
00143 #error <TSTFLAGS is not defined>
00144 #endif
00145
00146 #ifdef TSTFLAGS
00147
00148 #define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
00149
00150 #define END() (void) tstdef_dummy; } END_(TSTFLAGS)
00151
00154 #define TEST0(suite) TEST_1_(TSTFLAGS, suite)
00155
00156 #define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
00157
00158 #define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
00159
00160 #define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
00161
00162 #define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
00163
00164 #define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
00165
00166 #define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
00167
00168 #define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
00169 #else
00170
00171 #define TEST0(flags, suite) TEST_1_(flags, suite)
00172 #define TEST_1(flags, suite) TEST_1_(flags, suite)
00173 #define TEST_VOID(flags, suite) TEST_VOID_(flags, suite)
00174 #define TEST(flags, suite, expect) TEST_(flags, suite, expect)
00175 #define TEST64(flags, suite, expect) TEST64_(flags, suite, expect)
00176 #define TEST_S(flags, suite, expect) TEST_S_(flags, suite, expect)
00177 #define BEGIN(flags) BEGIN_(flags) { extern int tstdef_dummy
00178 #define END(flags) (void) tstdef_dummy; } END_(flags)
00179 #endif
00180
00181 typedef unsigned longlong ull;
00182
00184 #define TEST_1_(flags, suite) do { \
00185 if (flags & tst_verbatim) { \
00186 printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00187 fflush(stdout); } \
00188 if ((suite)) { if (flags & tst_verbatim) \
00189 printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
00190 fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
00191 __FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); return 1; } \
00192 while(0)
00193
00195 #define TEST_VOID_(flags, suite) do { \
00196 if (flags & tst_verbatim) { \
00197 printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
00198 fflush(stdout); } \
00199 (suite); } while(0)
00200
00202 #define TEST_(flags, suite, expect) do { \
00203 unsigned long _value, _expect; \
00204 if (flags & tst_verbatim) { \
00205 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00206 fflush(stdout); } \
00207 if ((_value = (unsigned long)(suite)) == \
00208 (_expect = (unsigned long)(expect))) \
00209 { if (flags & tst_verbatim) \
00210 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00211 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %lu != %lu\n", \
00212 __FILE__, __LINE__, TSTNAME, \
00213 #suite, #expect, _value, _expect); fflush(stderr); return 1; } \
00214 while(0)
00215
00217 #define TEST64_(flags, suite, expect) do { \
00218 uint64_t _value, _expect; \
00219 if (flags & tst_verbatim) { \
00220 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00221 fflush(stdout); } \
00222 if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
00223 { if (flags & tst_verbatim) \
00224 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00225 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
00226 __FILE__, __LINE__, TSTNAME, \
00227 #suite, #expect, (ull)_value, (ull)_expect); fflush(stderr); \
00228 return 1; \
00229 } while(0)
00230
00232 #define TEST_D_(flags, suite, expect) do { \
00233 double _value, _expect; \
00234 if (flags & tst_verbatim) { \
00235 printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
00236 fflush(stdout); } \
00237 if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
00238 { if (flags & tst_verbatim) \
00239 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
00240 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
00241 __FILE__, __LINE__, TSTNAME, \
00242 #suite, #expect, _value, _expect); fflush(stderr); \
00243 return 1; \
00244 } while(0)
00245
00247 #define TEST_S_(flags, suite, expect) do { \
00248 char const * _value, * _expect; \
00249 if (flags & tst_verbatim) { \
00250 printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00251 fflush(stdout); } \
00252 _value = (suite); \
00253 _expect = (expect); \
00254 if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00255 (_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
00256 { if (flags & tst_verbatim) \
00257 printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
00258 fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or \"%s\" != \"%s\"\n", \
00259 __FILE__, __LINE__, TSTNAME, \
00260 #suite, #expect, _value, _expect); fflush(stderr); return 1; } \
00261 while(0)
00262
00264 #define TEST_M_(flags, suite, expect, len) do { \
00265 void const * _value, * _expect; \
00266 int _len; \
00267 if (flags & tst_verbatim) { \
00268 printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
00269 fflush(stdout); } \
00270 _value = (suite); \
00271 _expect = (expect); \
00272 _len = (len); \
00273 if (((_value == NULL || _expect == NULL) && _value == _expect) || \
00274 memcmp(_value, _expect, _len) == 0) \
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 "\
00278 "or \"%.*s\" != \"%.*s\"\n", \
00279 __FILE__, __LINE__, TSTNAME, \
00280 #suite, #expect, _len, (char *)_value, _len, (char *)_expect); \
00281 fflush(stderr); return 1; } \
00282 while(0)
00283
00285 #define BEGIN_(flags) \
00286 if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
00287
00289 #define END_(flags) \
00290 if (flags & tst_verbatim) \
00291 printf("%s: %s%sfinished fully successful\n", TSTNAME); \
00292 return 0
00293
00294 SOFIA_END_DECLS