diff options
author | Tom Smeding <tom@tomsmeding.com> | 2021-05-16 19:13:05 +0200 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2021-05-16 19:13:05 +0200 |
commit | 831af1d49c9bb7d17794d259c99f92b2513496c5 (patch) | |
tree | 1a7674bb6d4fbcecf1e6b83ff1834b238b06f2a5 /test/test_framework.c | |
parent | 6aebd10ba045085ed1d0ca7c0ffbf69196c3308c (diff) |
server: WIP utf8 validation implementation
Diffstat (limited to 'test/test_framework.c')
-rw-r--r-- | test/test_framework.c | 20 |
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); +} |