From 831af1d49c9bb7d17794d259c99f92b2513496c5 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 16 May 2021 19:13:05 +0200 Subject: server: WIP utf8 validation implementation --- test/test_framework.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/test_framework.c') 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 #include +#include #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); +} -- cgit v1.2.3-54-g00ecf