# HG changeset patch # User Matti Hamalainen # Date 1579128566 -7200 # Node ID be957142ab37e55bd1f1dc834ff88e9afb966cc5 # Parent aec7137674828b7d8b126738bbea81de1a31ec77 Add TEST_ASSERT() and test sizes of some types before doing anything else. diff -r aec713767482 -r be957142ab37 tests.c --- 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;