tor/src/common/test.h

110 lines
5.1 KiB
C
Raw Normal View History

2003-04-07 15:25:44 +02:00
/* Copyright 2001,2002 Roger Dingledine, Matej Pfajfar. */
/* See LICENSE for licensing information */
/* $Id$ */
#ifndef __TEST_H
#define __TEST_H
#include <string.h>
#define STMT_BEGIN do {
#define STMT_END } while (0)
2003-04-07 15:25:44 +02:00
#define test_fail() \
STMT_BEGIN \
2003-04-07 15:25:44 +02:00
printf("\nFile %s: line %d (%s): assertion failed.", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__); \
return; \
STMT_END
2003-04-07 15:25:44 +02:00
#define test_assert(expr) \
STMT_BEGIN \
2003-04-07 15:25:44 +02:00
if(expr) { printf("."); } else { \
printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr); \
return; \
} STMT_END
2003-04-07 15:25:44 +02:00
#define test_eq(expr1, expr2) \
STMT_BEGIN if(expr1==expr2) { printf("."); } else { \
2003-04-07 15:25:44 +02:00
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
" (%ld != %ld)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
(long)expr1, (long)expr2); \
return; \
} STMT_END
2003-04-07 15:25:44 +02:00
#define test_neq(expr1, expr2) \
STMT_BEGIN if(expr1!=expr2) { printf("."); } else { \
2003-04-07 15:25:44 +02:00
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
" (%ld == %ld)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
(long)expr1, (long)expr2); \
return; \
} STMT_END
2003-04-07 15:25:44 +02:00
#define test_streq(expr1, expr2) \
STMT_BEGIN if(!strcmp(expr1,expr2)) { printf("."); } else { \
2003-04-07 15:25:44 +02:00
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
" (%s != %s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
expr1, expr2); \
2003-04-07 15:25:44 +02:00
return; \
} STMT_END
2003-04-07 15:25:44 +02:00
#define test_strneq(expr1, expr2) \
STMT_BEGIN if(strcmp(expr1,expr2)) { printf("."); } else { \
2003-04-07 15:25:44 +02:00
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
" (%s == %s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
expr1, expr2); \
return; \
} STMT_END
#define test_memeq(expr1, expr2, len) \
STMT_BEGIN if(!memcmp(expr1,expr2,len)) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2); \
return; \
} STMT_END
2003-04-07 15:25:44 +02:00
#define test_memneq(expr1, expr2, len) \
STMT_BEGIN if(memcmp(expr1,expr2,len)) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2); \
return; \
} STMT_END
2003-04-07 15:25:44 +02:00
#endif
/*
Local Variables:
mode:c
indent-tabs-mode:nil
c-basic-offset:2
End:
*/