]> git.lizzy.rs Git - nothing.git/blobdiff - test/test.h
(#815) Integrate Point Layer with Level and LevelEditor
[nothing.git] / test / test.h
index 732ef973fb547037b6200b7a7cb87284ed97ed2b..f39cc7a5758a8bf1e2a12ca5d9b602d1d71f9fa3 100644 (file)
@@ -1,11 +1,16 @@
 #ifndef TEST_H_
 #define TEST_H_
 
+#include "math.h"
+
 #define TEST_RUN(name)                          \
     if (name() < 0) {                           \
         return -1;                              \
     }
 
+#define TEST_IGNORE(name)                       \
+    (void)(name)                                \
+
 #define TEST(name)                              \
     static int name##_body(void);               \
     static int name(void) {                     \
@@ -20,6 +25,8 @@
     }                                           \
     static int name##_body(void)
 
+// TODO(#308): ASSERT_* macros evaluate expressions several times
+
 #define ASSERT_STREQN(expected, actual, n)                              \
     if (strncmp(expected, actual, n) != 0) {                            \
         fprintf(stderr, "\n%s:%d: ASSERT_STREQN: \n",                   \
         return -1;                                                      \
     }
 
+#define ASSERT_STREQ(expected, actual)                                  \
+    if (strcmp(expected, actual) != 0) {                                \
+        fprintf(stderr, "\n%s:%d: ASSERT_STREQ: \n",                    \
+                __FILE__, __LINE__);                                    \
+        fprintf(stderr, "  Expected: %s\n", expected);                  \
+        fprintf(stderr, "  Actual: %s\n", actual);                      \
+        return -1;                                                      \
+    }
+
+#define ASSERT_INTEQ(expected, actual)                                  \
+    if (expected != actual) {                                           \
+        fprintf(stderr, "\n%s:%d: ASSERT_INTEQ: \n",                    \
+                __FILE__, __LINE__);                                    \
+        fprintf(stderr, "  Expected: %d\n", expected);                  \
+        fprintf(stderr, "  Actual: %d\n", actual);                      \
+        return -1;                                                      \
+    }
+
+#define ASSERT_LONGINTEQ(expected, actual)                              \
+    if (expected != actual) {                                           \
+        fprintf(stderr, "\n%s:%d: ASSERT_LONGINTEQ: \n",                \
+                __FILE__, __LINE__);                                    \
+        fprintf(stderr, "  Expected: %ld\n", expected);                 \
+        fprintf(stderr, "  Actual: %ld\n", actual);                     \
+        return -1;                                                      \
+    }
+
+
+#define ASSERT_FLOATEQ(expected, actual, margin)                        \
+    if (fabsf(expected - actual) > margin) {                            \
+        fprintf(stderr, "\n%s:%d: ASSERT_FLOATEQ: \n",                  \
+                __FILE__, __LINE__);                                    \
+        fprintf(stderr, "  Expected: %f\n", expected);                  \
+        fprintf(stderr, "  Actual: %f\n", actual);                      \
+        fprintf(stderr, "  Margin: %f\n", margin);                      \
+        return -1;                                                      \
+    }
+
+#define ASSERT_EQ(type, expected, actual, handler)                      \
+    {                                                                   \
+        type _expected = (expected);                                    \
+        type _actual = (actual);                                        \
+        if (_expected != _actual) {                                     \
+            fprintf(stderr, "\n%s:%d: ASSERT_EQ: \n",                   \
+                    __FILE__, __LINE__);                                \
+            handler                                                     \
+            return -1;                                                  \
+        }                                                               \
+    }
+
+#define ASSERT_TRUE(condition, handler)                                 \
+    if (!(condition)) {                                                 \
+        fprintf(stderr, "\n%s:%d: ASSERT_TRUE: false\n",                \
+                __FILE__, __LINE__);                                    \
+        handler                                                         \
+        return -1;                                                      \
+    }
+
+#define ASSERT_FALSE(condition, handler)                                \
+    if (condition) {                                                    \
+        fprintf(stderr, "\n%s:%d: ASSERT_FALSE: false\n",               \
+                __FILE__, __LINE__);                                    \
+        handler                                                         \
+        return -1;                                                      \
+    }
+
 #define TEST_SUITE(name)                        \
     static int name##_body(void);               \
     static int name(void) {                     \