From 8c0cb0bd282dc7c9a74d7e39fcd7ad1d3899b5b6 Mon Sep 17 00:00:00 2001 From: chenguoping Date: Fri, 3 Jan 2020 14:34:35 +0800 Subject: [PATCH] Increased the test coverage of printbuf.c 82% to 92%. --- tests/test_printbuf.c | 6 ++++++ tests/test_printbuf.expected | 1 + 2 files changed, 7 insertions(+) diff --git a/tests/test_printbuf.c b/tests/test_printbuf.c index 06dd13d9..c74fe6b8 100644 --- a/tests/test_printbuf.c +++ b/tests/test_printbuf.c @@ -127,6 +127,10 @@ static void test_sprintbuf(int before_resize); static void test_sprintbuf(int before_resize) { struct printbuf *pb; + const char *max_char = "if string is greater than stack buffer, then use dynamic string" + " with vasprintf. Note: some implementation of vsnprintf return -1 " + " if output is truncated whereas some return the number of bytes that " + " would have been written - this code handles both cases."; printf("%s: starting test\n", __func__); pb = printbuf_new(); @@ -155,6 +159,8 @@ static void test_sprintbuf(int before_resize) sprintbuf(pb, "%s", "%s"); printf("%d, [%s]\n", printbuf_length(pb), pb->buf); + sprintbuf(pb, max_char); + printf("%d, [%s]\n", printbuf_length(pb), pb->buf); printbuf_free(pb); printf("%s: end test\n", __func__); } diff --git a/tests/test_printbuf.expected b/tests/test_printbuf.expected index 64644125..a4ebc2a6 100644 --- a/tests/test_printbuf.expected +++ b/tests/test_printbuf.expected @@ -29,5 +29,6 @@ sprintbuf to just after resize(31+1): 32, [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX], st 16, [plain12147483647] 27, [plain12147483647-2147483648] 29, [plain12147483647-2147483648%s] +284, [plain12147483647-2147483648%sif string is greater than stack buffer, then use dynamic string with vasprintf. Note: some implementation of vsnprintf return -1 if output is truncated whereas some return the number of bytes that would have been written - this code handles both cases.] test_sprintbuf: end test ======================================== -- 2.39.5