diff options
author | Nick Mathewson <nickm@torproject.org> | 2003-04-15 19:10:18 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2003-04-15 19:10:18 +0000 |
commit | 1fa0fc14876357b7f5d36696166d33dc1159b294 (patch) | |
tree | 00553f761f24242c4660b5079ee7025863ee8d08 /src/common | |
parent | 7df5caad0df1644770316d98a289be734029f4c5 (diff) | |
download | tor-1fa0fc14876357b7f5d36696166d33dc1159b294.tar tor-1fa0fc14876357b7f5d36696166d33dc1159b294.tar.gz |
Introduce a few unit tests (from older code), refactor compression setup/teardown
svn:r232
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/test.h | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/src/common/test.h b/src/common/test.h index 187828e92..fe3710094 100644 --- a/src/common/test.h +++ b/src/common/test.h @@ -5,16 +5,22 @@ #ifndef __TEST_H #define __TEST_H +#include <string.h> + +#define STMT_BEGIN do { +#define STMT_END } while (0) + #define test_fail() \ - if (1) { \ + STMT_BEGIN \ printf("\nFile %s: line %d (%s): assertion failed.", \ __FILE__, \ __LINE__, \ __PRETTY_FUNCTION__); \ return; \ - } + STMT_END #define test_assert(expr) \ + STMT_BEGIN \ if(expr) { printf("."); } else { \ printf("\nFile %s: line %d (%s): assertion failed: (%s)\n", \ __FILE__, \ @@ -22,10 +28,10 @@ __PRETTY_FUNCTION__, \ #expr); \ return; \ - } + } STMT_END #define test_eq(expr1, expr2) \ - if(expr1==expr2) { printf("."); } else { \ + STMT_BEGIN if(expr1==expr2) { printf("."); } else { \ printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\ " (%ld != %ld)\n", \ __FILE__, \ @@ -34,10 +40,10 @@ #expr1, #expr2, \ (long)expr1, (long)expr2); \ return; \ - } + } STMT_END #define test_neq(expr1, expr2) \ - if(expr1!=expr2) { printf("."); } else { \ + STMT_BEGIN if(expr1!=expr2) { printf("."); } else { \ printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\ " (%ld == %ld)\n", \ __FILE__, \ @@ -46,22 +52,22 @@ #expr1, #expr2, \ (long)expr1, (long)expr2); \ return; \ - } + } STMT_END #define test_streq(expr1, expr2) \ - if(!strcmp(expr1,expr2)) { printf("."); } else { \ + STMT_BEGIN if(!strcmp(expr1,expr2)) { printf("."); } else { \ printf("\nFile %s: line %d (%s): Assertion failed: (%s==%s)\n"\ " (%s != %s)\n", \ __FILE__, \ __LINE__, \ __PRETTY_FUNCTION__, \ #expr1, #expr2, \ - (long)expr1, (long)expr2); \ + expr1, expr2); \ return; \ - } + } STMT_END #define test_strneq(expr1, expr2) \ - if(strcmp(expr1,expr2)) { printf("."); } else { \ + STMT_BEGIN if(strcmp(expr1,expr2)) { printf("."); } else { \ printf("\nFile %s: line %d (%s): Assertion failed: (%s!=%s)\n"\ " (%s == %s)\n", \ __FILE__, \ @@ -70,6 +76,24 @@ #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 #endif + +/* + Local Variables: + mode:c + indent-tabs-mode:nil + c-basic-offset:2 + End: +*/ |