From ff34cebaa50ebac63643a5e58989e416e09de4b9 Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Thu, 15 Sep 2022 19:35:27 +0300 Subject: Initial commit --- tests/test.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/test.h (limited to 'tests/test.h') diff --git a/tests/test.h b/tests/test.h new file mode 100644 index 0000000..38f5d6e --- /dev/null +++ b/tests/test.h @@ -0,0 +1,77 @@ +#ifndef TEST_H +#define TEST_H + +#include +#include +#include +#include + +#define ASSERT_INT_EQ(X, Y) \ + do { \ + int xxx = (X); \ + int yyy = (Y); \ + if (xxx != yyy) { \ + fprintf(stderr, \ + "*** %s ***\n%s is not equal to %s\nwhere\n%s is %d\nand\n%s " \ + "is %d\n", \ + __FUNCTION__, \ + #X, \ + #Y, \ + #X, \ + xxx, \ + #Y, \ + yyy); \ + exit(1); \ + } \ + } while (0) + +#define ASSERT_STR_EQ(X, Y) \ + do { \ + const char* xxx = (X); \ + const char* yyy = (Y); \ + if (strcmp(xxx, yyy) != 0) { \ + fprintf(stderr, \ + "*** %s ***\n%s is not equal to %s\nwhere\n%s is %s\nand\n%s " \ + "is %s\n", \ + __FUNCTION__, \ + #X, \ + #Y, \ + #X, \ + xxx, \ + #Y, \ + yyy); \ + exit(1); \ + } \ + } while (0) + +#define ASSERT_MEM_EQ(X, Y, SIZE) \ + do { \ + const char* xxx = (X); \ + const char* yyy = (Y); \ + if (memcmp(xxx, yyy, SIZE) != 0) { \ + fprintf(stderr, \ + "*** %s ***\n%s is not equal to %s\nwhere\n%s is %.*s\nand\n%s " \ + "is %.*s\n", \ + __FUNCTION__, \ + #X, \ + #Y, \ + #X, \ + SIZE, \ + xxx, \ + #Y, \ + SIZE, \ + yyy); \ + exit(1); \ + } \ + } while (0) + +#define ASSERT_NULL(X) \ + do { \ + const void* xxx = (X); \ + if (xxx != NULL) { \ + fprintf(stderr, "*** %s ***\n%s is not NULL (was %p)\n", __FUNCTION__, #X, xxx); \ + exit(1); \ + } \ + } while (0) + +#endif -- cgit v1.2.3