From: Tobias Brunner Date: Mon, 27 Jan 2014 12:50:06 +0000 (+0100) Subject: tests: Fix test for printing NULL on FreeBSD X-Git-Tag: 5.1.2rc1~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8c9c03de0849a9c6f2bde633afd95c7c0632ebf;p=thirdparty%2Fstrongswan.git tests: Fix test for printing NULL on FreeBSD --- diff --git a/src/libstrongswan/tests/suites/test_printf.c b/src/libstrongswan/tests/suites/test_printf.c index 7d38c60df9..9e40d1fc07 100644 --- a/src/libstrongswan/tests/suites/test_printf.c +++ b/src/libstrongswan/tests/suites/test_printf.c @@ -43,13 +43,23 @@ static void verify(char *expected, char *format, ...) #endif /* HAVE_FMEMOPEN */ } +START_TEST(test_printf_null) +{ + char buf[16]; + + /* on FreeBSD "(null)" gets printed even when a precision of 0 is used. + * because printing of "(null)" for NULL is not standardized we don't verify + * the output and just make sure there is no crash */ + snprintf(buf, sizeof(buf), "%s", NULL); +} +END_TEST + START_TEST(test_printf_strings) { verify("a bc def", "%s %s %s", "a", "bc", "def"); + verify("", "%.0s", "asdfg"); verify("asd", "%.3s", "asdfg"); verify("asdf", "%.*s", (int)4, "asdfg"); - verify("", "%.0s", NULL); - verify("", "%.*s", (int)0, NULL); verify(" asdf", "%6s", "asdf"); verify(" asdf", "%+6s", "asdf"); verify("asdf ", "%-6s", "asdf"); @@ -186,6 +196,7 @@ Suite *printf_suite_create() s = suite_create("printf"); tc = tcase_create("strings"); + tcase_add_test(tc, test_printf_null); tcase_add_test(tc, test_printf_strings); suite_add_tcase(s, tc);