aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2003-04-17 01:55:13 +0000
committerNick Mathewson <nickm@torproject.org>2003-04-17 01:55:13 +0000
commitd3c0e5ab344235b6fdc471b60c1978f0ac590318 (patch)
treeb5e9d001bc6b4a663c2a6c7b5d302297c5c6ff73 /src/common
parentfe1aba7f15405193e2359e4364b221c157f11a43 (diff)
downloadtor-d3c0e5ab344235b6fdc471b60c1978f0ac590318.tar
tor-d3c0e5ab344235b6fdc471b60c1978f0ac590318.tar.gz
Fix test.h to have once-only evalutation of arguments
svn:r243
Diffstat (limited to 'src/common')
-rw-r--r--src/common/test.h34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/common/test.h b/src/common/test.h
index 8be3afd77..3a1215fe0 100644
--- a/src/common/test.h
+++ b/src/common/test.h
@@ -20,7 +20,7 @@
STMT_END
#define test_assert(expr) \
- STMT_BEGIN \
+ STMT_BEGIN \
if(expr) { printf("."); } else { \
printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \
__FILE__, \
@@ -31,55 +31,65 @@
} STMT_END
#define test_eq(expr1, expr2) \
- STMT_BEGIN if(expr1==expr2) { printf("."); } else { \
+ STMT_BEGIN \
+ long v1=(long)(expr1), v2=(long)(expr2); \
+ if(v1==v2) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
" (%ld != %ld)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
- (long)expr1, (long)expr2); \
+ v1, v2); \
return; \
} STMT_END
#define test_neq(expr1, expr2) \
- STMT_BEGIN if(expr1!=expr2) { printf("."); } else { \
+ STMT_BEGIN \
+ long v1=(long)(expr1), v2=(long)(expr2); \
+ if(v1!=v2) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
" (%ld == %ld)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
- (long)expr1, (long)expr2); \
+ v1, v2); \
return; \
} STMT_END
#define test_streq(expr1, expr2) \
- STMT_BEGIN if(!strcmp(expr1,expr2)) { printf("."); } else { \
+ STMT_BEGIN \
+ char *v1=(expr1), *v2=(expr2); \
+ if(!strcmp(v1,v2)) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\
" (%s != %s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
- expr1, expr2); \
+ v1, v2); \
return; \
} STMT_END
#define test_strneq(expr1, expr2) \
- STMT_BEGIN if(strcmp(expr1,expr2)) { printf("."); } else { \
+ STMT_BEGIN \
+ char *v1=(expr1), *v2=(expr2); \
+ if(strcmp(v1,v2)) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\
" (%s == %s)\n", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#expr1, #expr2, \
- expr1, expr2); \
+ v1, v2); \
return; \
} STMT_END
#define test_memeq(expr1, expr2, len) \
- STMT_BEGIN if(!memcmp(expr1,expr2,len)) { printf("."); } else { \
+ STMT_BEGIN \
+ void *v1=(expr1), *v2=(expr2); \
+ if(!memcmp(v1,v2,(len))) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n", \
__FILE__, \
__LINE__, \
@@ -89,7 +99,9 @@
} STMT_END
#define test_memneq(expr1, expr2, len) \
- STMT_BEGIN if(memcmp(expr1,expr2,len)) { printf("."); } else { \
+ STMT_BEGIN \
+ void *v1=(expr1), *v2=(expr2); \
+ if(memcmp(v1,v2,(len))) { printf("."); } else { \
printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n", \
__FILE__, \
__LINE__, \