diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2021-09-21 21:12:03 +0100 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2021-09-21 21:12:03 +0100 |
commit | 69c8b1fe3f9c065b0e2f06bf62bda70cc4a5eba7 (patch) | |
tree | e2b67fa485e7c06ff36e66a9f18f356069aef833 | |
parent | 4bdbc45d66587384698813d6743d84c255e87235 (diff) | |
download | pack-69c8b1fe3f9c065b0e2f06bf62bda70cc4a5eba7.tar.gz pack-69c8b1fe3f9c065b0e2f06bf62bda70cc4a5eba7.tar.xz pack-69c8b1fe3f9c065b0e2f06bf62bda70cc4a5eba7.zip |
test.c: clean up macros
-rw-r--r-- | test.c | 29 |
1 files changed, 14 insertions, 15 deletions
@@ -27,24 +27,23 @@ struct test { #define DATA(...) ((unsigned char []){ __VA_ARGS__ }) #define CHECK(test) if (!(test)) { puts("! " #test); return false; } -#define CHECK_UNPACK(data, fmt, ...) do { \ - enum pack_status CHECK_UNPACK_s = unpack(data, sizeof (data), fmt, __VA_ARGS__); \ - if (CHECK_UNPACK_s != PACK_OK) { \ - printf(__FILE__ ":%d unpack(" #data ", " #fmt ", ...) -> %s (%d)\n", __LINE__, pack_strerror(CHECK_UNPACK_s), CHECK_UNPACK_s); \ - return false; \ - } \ -} while (0) - -#define CHECK_UNPACK_STRUCT(data, args, dest) do { \ - enum pack_status CHECK_UNPACK_STRUCT_s = \ - unpack_struct(data, sizeof (data), args, dest); \ - if (CHECK_UNPACK_STRUCT_s != PACK_OK) { \ - printf(__FILE__ ":%d unpack_struct(" #data ", " #args ", " #dest ") -> %s (%d)\n", \ - __LINE__, pack_strerror(CHECK_UNPACK_STRUCT_s), \ - CHECK_UNPACK_STRUCT_s); \ +#define DIAGNOSTIC(func, status, ...) \ + if (pack_trace == PACK_TRACE_OFF) \ + printf("# " __FILE__ ":%d " #func "(" #__VA_ARGS__ ") -> %s (%d)\n", \ + __LINE__, pack_strerror(status), status); + +#define CHECK_UNPACK_(func, data, ...) do { \ + enum pack_status PACK_STATUS = \ + func(data, sizeof (data), __VA_ARGS__); \ + if (PACK_STATUS != PACK_OK) { \ + DIAGNOSTIC(func, PACK_STATUS, data, s, __VA_ARGS__); \ return false; \ } \ } while (0) +#define CHECK_UNPACK(data, fmt, ...) \ + CHECK_UNPACK_(unpack, data, fmt, __VA_ARGS__) +#define CHECK_UNPACK_STRUCT(data, args, dest) \ + CHECK_UNPACK_(unpack_struct, data, args, dest) #define CHECK_EQUAL(f, a, b) if (a != b) { printf(__FILE__ ":%d %"f" != %"f"\n", __LINE__, a, b); return false; } |