Loading...
Searching...
No Matches
tstdef.h
Go to the documentation of this file.
/*
* This file is part of the Sofia-SIP package
*
* Copyright (C) 2005 Nokia Corporation.
*
* Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef SU_TYPES_H
#include <sofia-sip/su_types.h>
#endif
SOFIA_BEGIN_DECLS
#if HAVE_FUNC
#define TSTNAME name, __func__, "() "
#elif HAVE_FUNCTION
#define TSTNAME name, __FUNCTION__, "() "
#else
#define TSTNAME name, "", ""
#endif
enum {
tst_verbatim = 1,
tst_abort = 2,
tst_log = 4
};
#ifndef TSTFLAGS
#error <TSTFLAGS is not defined>
#endif
#define BEGIN() BEGIN_(TSTFLAGS); { extern int tstdef_dummy
#define END() (void) tstdef_dummy; } END_(TSTFLAGS)
#define TEST0(suite) TEST_1_(TSTFLAGS, suite)
#define TEST_1(suite) TEST_1_(TSTFLAGS, suite)
#define TEST_VOID(suite) TEST_VOID_(TSTFLAGS, suite)
#define TEST(suite, expected) TEST_(TSTFLAGS, suite, expected)
#define TEST_P(suite, expected) TEST_P_(TSTFLAGS, suite, expected)
#define TEST64(suite, expected) TEST64_(TSTFLAGS, suite, expected)
#define TEST_D(suite, expected) TEST_D_(TSTFLAGS, suite, expected)
#define TEST_S(suite, expected) TEST_S_(TSTFLAGS, suite, expected)
#define TEST_M(suite, expected, len) TEST_M_(TSTFLAGS, suite, expected, len)
#define TEST_SIZE(suite, expected) TEST_SIZE_(TSTFLAGS, suite, expected)
#define TEST_LOG(x) \
do { \
if (tstflags & tst_log) \
printf x; \
} while(0)
#define TEST_FAILED(flags) \
(((flags) & tst_abort) || getenv("SOFIA_SIP_TEST_ABORT")) \
? abort() : (void)0; return 1
#define TEST_1_(flags, suite) do { \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
fflush(stdout); } \
if ((suite)) { if (flags & tst_verbatim) \
printf("%s: %s%sok: (%s)\n", TSTNAME, #suite); break ; } \
fprintf(stderr, "%s:%u: %s %s%sFAILED: (%s)\n", \
__FILE__, __LINE__, TSTNAME, #suite); fflush(stderr); \
TEST_FAILED(flags); } \
while(0)
#define TEST_VOID_(flags, suite) do { \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s\n", TSTNAME, #suite); \
fflush(stdout); } \
(suite); } while(0)
#define TEST_(flags, suite, expect) do { \
uintptr_t _value, _expect; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
_value = (uintptr_t)(suite); \
_expect = (uintptr_t)(expect); \
if (_value == _expect) { \
if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", \
TSTNAME, #suite, #expect); \
break; \
} \
fprintf(stderr, "%s:%u: %s %s%sFAILED: " \
"%s != %s or "MOD_ZU" != "MOD_ZU"\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, (size_t)_value, (size_t)_expect); \
fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define TEST_P_(flags, suite, expect) do { \
void const * _value, * _expect; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
if ((_value = (suite)) == (_expect = (expect))) { \
if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); \
break; \
} \
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %p != %p\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, _value, _expect); fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define TEST_SIZE_(flags, suite, expect) do { \
size_t _value, _expect; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
if ((_value = (size_t)(suite)) == \
(_expect = (size_t)(expect))) \
{ if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "MOD_ZU" != "MOD_ZU"\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, _value, _expect); fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define TEST64_(flags, suite, expect) do { \
uint64_t _value, _expect; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
if ((_value = (uint64_t)(suite)) == (_expect = (uint64_t)(expect))) \
{ if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or "LLU" != "LLU"\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, (unsigned longlong)_value, \
(unsigned longlong)_expect); fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define TEST_D_(flags, suite, expect) do { \
double _value, _expect; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s == %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
if ((_value = (double)(suite)) == (_expect = (double)(expect))) \
{ if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect); break; } \
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %g != %g\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, _value, _expect); fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define TEST_S_(flags, suite, expect) do { \
char const * _value, * _expect; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
_value = (suite); \
_expect = (expect); \
if (((_value == NULL || _expect == NULL) && _value == _expect) || \
(_value != NULL && _expect != NULL && strcmp(_value, _expect) == 0)) \
{ if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s or %s%s%s != \"%s\"\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, \
_value ? "\"" : "", _value ? _value : "NULL", _value ? "\"" : "", \
_expect); fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define TEST_M_(flags, suite, expect, len) do { \
void const * _value, * _expect; \
size_t _len; \
if (flags & tst_verbatim) { \
printf("%s: %s%stesting %s is %s\n", TSTNAME, #suite, #expect); \
fflush(stdout); } \
_value = (suite); \
_expect = (expect); \
_len = (size_t)(len); \
if (((_value == NULL || _expect == NULL) && _value == _expect) || \
memcmp(_value, _expect, _len) == 0) \
{ if (flags & tst_verbatim) \
printf("%s: %s%sok: %s == %s \n", TSTNAME, #suite, #expect);break;}\
fprintf(stderr, "%s:%u: %s %s%sFAILED: %s != %s "\
"or \"%.*s\" != \"%.*s\"\n", \
__FILE__, __LINE__, TSTNAME, \
#suite, #expect, (int)_len, \
(char *)_value, (int)_len, (char *)_expect); \
fflush(stderr); \
TEST_FAILED(flags); \
} while(0)
#define BEGIN_(flags) \
if (flags & tst_verbatim) printf("%s: %s%sstarting\n", TSTNAME)
#define END_(flags) \
if (flags & tst_verbatim) \
printf("%s: %s%sfinished fully successful\n", TSTNAME); \
return 0
SOFIA_END_DECLS
su_types.h
Basic integer types for su library.
tst_log
@ tst_log
If (TSTFLAGS & tst_log) is non-zero, log intermediate results.
Definition tstdef.h:149
tst_abort
@ tst_abort
If (TSTFLAGS & tst_abort) is non-zero, abort() when failed.
Definition tstdef.h:147
tst_verbatim
@ tst_verbatim
If (TSTFLAGS & tst_verbatim) is non-zero, be verbatim.
Definition tstdef.h:145

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