2003-12-13 23:53:17 +01:00
|
|
|
/* Copyright 2001,2002,2003 Roger Dingledine. */
|
2003-04-07 15:25:44 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef __TEST_H
|
|
|
|
#define __TEST_H
|
|
|
|
|
2003-04-15 21:10:18 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define STMT_BEGIN do {
|
|
|
|
#define STMT_END } while (0)
|
|
|
|
|
2003-08-12 05:08:41 +02:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRETTY_FUNCTION __PRETTY_FUNCTION__
|
|
|
|
#else
|
|
|
|
#define PRETTY_FUNCTION ""
|
|
|
|
#endif
|
|
|
|
|
2004-03-01 07:45:32 +01:00
|
|
|
extern int have_failed;
|
|
|
|
|
2003-04-07 15:25:44 +02:00
|
|
|
#define test_fail() \
|
2003-04-15 21:10:18 +02:00
|
|
|
STMT_BEGIN \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-07 15:25:44 +02:00
|
|
|
printf("\nFile %s: line %d (%s): assertion failed.", \
|
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION); \
|
2003-04-07 15:25:44 +02:00
|
|
|
return; \
|
2003-04-15 21:10:18 +02:00
|
|
|
STMT_END
|
2003-04-07 15:25:44 +02:00
|
|
|
|
|
|
|
#define test_assert(expr) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
2003-04-07 15:25:44 +02:00
|
|
|
if(expr) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-07 15:25:44 +02:00
|
|
|
printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
|
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-07 15:25:44 +02:00
|
|
|
#expr); \
|
|
|
|
return; \
|
2003-04-15 21:10:18 +02:00
|
|
|
} STMT_END
|
2003-04-07 15:25:44 +02:00
|
|
|
|
|
|
|
#define test_eq(expr1, expr2) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
|
|
|
long v1=(long)(expr1), v2=(long)(expr2); \
|
|
|
|
if(v1==v2) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-07 15:25:44 +02:00
|
|
|
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
|
|
|
|
" (%ld != %ld)\n", \
|
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-07 15:25:44 +02:00
|
|
|
#expr1, #expr2, \
|
2003-04-17 03:55:13 +02:00
|
|
|
v1, v2); \
|
2003-04-07 15:25:44 +02:00
|
|
|
return; \
|
2003-04-15 21:10:18 +02:00
|
|
|
} STMT_END
|
2003-04-07 15:25:44 +02:00
|
|
|
|
|
|
|
#define test_neq(expr1, expr2) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
|
|
|
long v1=(long)(expr1), v2=(long)(expr2); \
|
|
|
|
if(v1!=v2) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-07 15:25:44 +02:00
|
|
|
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
|
|
|
|
" (%ld == %ld)\n", \
|
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-07 15:25:44 +02:00
|
|
|
#expr1, #expr2, \
|
2003-04-17 03:55:13 +02:00
|
|
|
v1, v2); \
|
2003-04-07 15:25:44 +02:00
|
|
|
return; \
|
2003-04-15 21:10:18 +02:00
|
|
|
} STMT_END
|
2003-04-07 15:25:44 +02:00
|
|
|
|
|
|
|
#define test_streq(expr1, expr2) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
|
|
|
char *v1=(expr1), *v2=(expr2); \
|
|
|
|
if(!strcmp(v1,v2)) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-07 15:25:44 +02:00
|
|
|
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
|
2003-05-06 19:38:16 +02:00
|
|
|
" (\"%s\" != \"%s\")\n", \
|
2003-04-07 15:25:44 +02:00
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-07 15:25:44 +02:00
|
|
|
#expr1, #expr2, \
|
2003-04-17 03:55:13 +02:00
|
|
|
v1, v2); \
|
2003-04-07 15:25:44 +02:00
|
|
|
return; \
|
2003-04-15 21:10:18 +02:00
|
|
|
} STMT_END
|
2003-04-07 15:25:44 +02:00
|
|
|
|
|
|
|
#define test_strneq(expr1, expr2) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
|
|
|
char *v1=(expr1), *v2=(expr2); \
|
|
|
|
if(strcmp(v1,v2)) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-07 15:25:44 +02:00
|
|
|
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
|
2003-05-06 19:38:16 +02:00
|
|
|
" (\"%s\" == \"%s\")\n", \
|
2003-04-07 15:25:44 +02:00
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-07 15:25:44 +02:00
|
|
|
#expr1, #expr2, \
|
2003-04-17 03:55:13 +02:00
|
|
|
v1, v2); \
|
2003-04-07 15:25:44 +02:00
|
|
|
return; \
|
2003-04-15 21:10:18 +02:00
|
|
|
} STMT_END
|
|
|
|
|
|
|
|
#define test_memeq(expr1, expr2, len) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
|
|
|
void *v1=(expr1), *v2=(expr2); \
|
|
|
|
if(!memcmp(v1,v2,(len))) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-15 21:10:18 +02:00
|
|
|
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
|
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-15 21:10:18 +02:00
|
|
|
#expr1, #expr2); \
|
|
|
|
return; \
|
|
|
|
} STMT_END
|
2003-04-07 15:25:44 +02:00
|
|
|
|
2003-04-16 17:24:09 +02:00
|
|
|
#define test_memneq(expr1, expr2, len) \
|
2003-04-17 03:55:13 +02:00
|
|
|
STMT_BEGIN \
|
|
|
|
void *v1=(expr1), *v2=(expr2); \
|
|
|
|
if(memcmp(v1,v2,(len))) { printf("."); } else { \
|
2004-03-01 07:45:32 +01:00
|
|
|
have_failed = 1; \
|
2003-04-16 17:24:09 +02:00
|
|
|
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
|
|
|
|
__FILE__, \
|
|
|
|
__LINE__, \
|
2003-08-12 05:08:41 +02:00
|
|
|
PRETTY_FUNCTION, \
|
2003-04-16 17:24:09 +02:00
|
|
|
#expr1, #expr2); \
|
|
|
|
return; \
|
|
|
|
} STMT_END
|
|
|
|
|
2003-04-07 15:25:44 +02:00
|
|
|
#endif
|
2003-04-15 21:10:18 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Local Variables:
|
|
|
|
mode:c
|
|
|
|
indent-tabs-mode:nil
|
|
|
|
c-basic-offset:2
|
|
|
|
End:
|
|
|
|
*/
|