diff options
Diffstat (limited to '02-usart/test_harness/test_harness.h')
-rw-r--r-- | 02-usart/test_harness/test_harness.h | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/02-usart/test_harness/test_harness.h b/02-usart/test_harness/test_harness.h index 74f3faa..b236cba 100644 --- a/02-usart/test_harness/test_harness.h +++ b/02-usart/test_harness/test_harness.h @@ -19,19 +19,31 @@ typedef struct { #define GENPR(fmt, v1, v2) \ fprintf(stderr, fmt "\n", v1, v2) +void test_printll(size_t sz, long long v1, long long v2); +void test_printul(size_t sz, unsigned long v1, unsigned long v2); +void test_printd(size_t sz, int v1, int v2); +void test_printl(size_t sz, long v1, long v2); +void test_printui(size_t sz, unsigned int v1, unsigned int v2); +void test_prints(size_t sz, short v1, short v2); +void test_printus(size_t sz, unsigned short v1, unsigned short v2); +void test_printc(size_t sz, char v1, char v2); +void test_printf(size_t sz, double v1, double v2); +void test_printp(size_t sz, void* v1, void* v2); +void test_printuc(size_t sz, unsigned char v1, unsigned char v2); + #define FORMAT_STRING(v1, v2) \ - fprintf( \ - stderr, \ - _Generic((v1), long: "%ld == %ld\n", \ - unsigned long: "%lu == %lu\n", \ - int: "%d == %d\n", \ - unsigned int: "%u == %u\n", \ - short: "%hu == %hu\n", \ - unsigned short: "%hu == %hu\n", \ - char: "%c == %c\n", \ - double: "%f == %f\n", \ - default: "%p == %p\n"), \ - (v1), (v2)); \ + _Generic((v1), \ + long long: test_printll, \ + unsigned long: test_printul, \ + int: test_printd, \ + long: test_printl, \ + unsigned int: test_printui, \ + short: test_prints, \ + unsigned short: test_printus, \ + char: test_printc, \ + unsigned char: test_printuc, \ + double: test_printf, \ + default: test_printp)(sizeof(v1), v1, v2) \ #define TRY_PRINT_TYPE(v1, v2, type, fmt) \ else if (__builtin_types_compatible_p(typeof (v1), type)) { \ @@ -54,7 +66,7 @@ typedef struct { do { \ if ((x) != (y)) { \ fprintf(stderr, RED "ASSERT_EQ FAILED! " RESET "Not true that "); \ - FORMAT_STRING(x, y); \ + FORMAT_STRING((x), (y)); \ fprintf(stderr, " - " YELLOW "In expression ASSERT_EQ(" #x ", " #y ")\n"); \ fprintf(stderr, RESET " - " YELLOW "At " __FILE__ ":%d\n" RESET, __LINE__); \ test_harness_abort(1); \ |