From d0b085fd7a9fb39acc517f2d9ae13ea68a2f2037 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Tue, 13 Mar 2018 15:18:54 -0500 Subject: [PATCH] Add test for hexdump --- tests/vm_segment.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/vm_segment.c b/tests/vm_segment.c index 59f8a10..db16c1d 100644 --- a/tests/vm_segment.c +++ b/tests/vm_segment.c @@ -194,3 +194,27 @@ Test(vm_segment, fwrite) fclose(stream); } + +Test(vm_segment, hexdump) +{ + vm_segment_set(segment, 0, 'H'); + vm_segment_set(segment, 1, 'e'); + vm_segment_set(segment, 2, 'l'); + vm_segment_set(segment, 3, 'l'); + vm_segment_set(segment, 4, 'o'); + vm_segment_set(segment, 5, ' '); + vm_segment_set(segment, 6, 'N'); + vm_segment_set(segment, 7, 'e'); + vm_segment_set(segment, 8, 'r'); + vm_segment_set(segment, 9, 'd'); + vm_segment_set(segment, 10, 's'); + + FILE *stream = fopen("/dev/null", "w"); + char buf[512]; + + setvbuf(stream, buf, _IOFBF, BUFSIZ); + vm_segment_hexdump(segment, stream, 0, 16); + + cr_assert_str_eq(buf, + "00000000 48 65 6C 6C 6F 20 4E 65 72 64 73 00 00 00 00 00 [Hello Nerds.....]\n"); +}