aboutsummaryrefslogtreecommitdiff
path: root/test/test_framework.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_framework.c')
-rw-r--r--test/test_framework.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/test_framework.c b/test/test_framework.c
index 8cd53ac..d566944 100644
--- a/test/test_framework.c
+++ b/test/test_framework.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdatomic.h>
+#include <stdint.h>
#include "test_framework.h"
@@ -12,3 +13,22 @@ void test_report_error(
fname, lineno, type, condition);
atomic_flag_test_and_set(&test_framework_assertion_failed);
}
+
+void print_buffer(FILE *stream, const void *buffer_, size_t length) {
+ const uint8_t *buffer = (const uint8_t*)buffer_;
+ fputc('"', stream);
+
+ for (size_t i = 0; i < length; i++) {
+ const uint8_t b = buffer[i];
+ if (b == '"') fprintf(stream, "\\\"");
+ else if (b == '\\') fprintf(stream, "\\\\");
+ else if (32 <= b && b < 127) fputc(b, stream);
+ else {
+ fprintf(stream, "\\x%c%c",
+ "0123456789abcdef"[b >> 4],
+ "0123456789abcdef"[b & 0xf]);
+ }
+ }
+
+ fprintf(stream, "\"[%zu]", length);
+}