[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Introduce a few unit tests (from older code), refactor comp...



Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv17073/src/common

Modified Files:
	test.h 
Log Message:
Introduce a few unit tests (from older code), refactor compression setup/teardown

Index: test.h
===================================================================
RCS file: /home/or/cvsroot/src/common/test.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- test.h	7 Apr 2003 13:25:43 -0000	1.1
+++ test.h	15 Apr 2003 19:10:18 -0000	1.2
@@ -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:
+*/