diff options
Diffstat (limited to 'tests/support')
| -rw-r--r-- | tests/support/test.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/support/test.h b/tests/support/test.h new file mode 100644 index 0000000..5de3864 --- /dev/null +++ b/tests/support/test.h @@ -0,0 +1,48 @@ +#ifndef TINY_CONVMEM_TEST_SUPPORT_H +#define TINY_CONVMEM_TEST_SUPPORT_H + +#include <stdio.h> +#include <string.h> + +typedef struct tiny_test_state +{ + const char *case_name; + unsigned checks; + unsigned failures; +} tiny_test_state_t; + +#define TINY_TEST_CASE(state, name) ((state)->case_name = (name)) +#define TINY_EXPECT(state, expression) \ + do \ + { \ + (state)->checks++; \ + if (!(expression)) \ + { \ + fprintf(stderr, \ + "%s:%d [%s] expected %s\n", \ + __FILE__, \ + __LINE__, \ + (state)->case_name, \ + #expression); \ + (state)->failures++; \ + } \ + } \ + while (0) +#define TINY_EXPECT_EQ_U64(state, expected, actual) \ + TINY_EXPECT((state), (unsigned long long)(expected) == (unsigned long long)(actual)) +#define TINY_EXPECT_BYTES(state, expected, actual, length) \ + TINY_EXPECT((state), memcmp((expected), (actual), (length)) == 0) + +static inline int +tiny_test_finish(const tiny_test_state_t *state) +{ + if (state->failures == 0) + { + printf("%u checks passed\n", state->checks); + return 0; + } + fprintf(stderr, "%u of %u checks failed\n", state->failures, state->checks); + return 1; +} + +#endif |
