changeset 603:be957142ab37

Add TEST_ASSERT() and test sizes of some types before doing anything else.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 16 Jan 2020 00:49:26 +0200
parents aec713767482
children e789accfca87
files tests.c
diffstat 1 files changed, 13 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tests.c	Thu Jan 16 00:48:51 2020 +0200
+++ b/tests.c	Thu Jan 16 00:49:26 2020 +0200
@@ -307,6 +307,14 @@
 }
 
 
+#define TEST_ASSERT(xcond) do { \
+        if (!(xcond)) \
+        { \
+            THERR("Assertion '" # xcond "' failed.\n"); \
+            return -1; \
+        } \
+    } while (0)
+
 #define TEST1(fun) do { \
         test_ctx ctx; \
         test_start(&ctx, # fun ); \
@@ -561,11 +569,11 @@
     th_init("th-test", "th-libs unit tests", "0.2", NULL, NULL);
     th_verbosity = 0;
 
-    if (sizeof(char) != sizeof(unsigned char))
-    {
-        THERR("sizeof(char) != sizeof(unsigned char)???\n");
-        return -1;
-    }
+    TEST_ASSERT(sizeof(char) == sizeof(unsigned char));
+    TEST_ASSERT(sizeof(char) == 1);
+    TEST_ASSERT(sizeof(uint16_t) == 2);
+    TEST_ASSERT(sizeof(uint32_t) == 4);
+    TEST_ASSERT(sizeof(uint64_t) == 8);
 
     tests_failed = tests_passed = tests_total =
         sets_total = sets_nenabled = 0;