aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/test.c b/test.c
index ce37818..0a30e33 100644
--- a/test.c
+++ b/test.c
@@ -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; }