From fa6926e5d4ff7fc7efde46222ff70f2a75298ac4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 23 Aug 2010 00:37:37 -0400 Subject: [PATCH] Improve printf test coverage --- glib/tests/printf.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/glib/tests/printf.c b/glib/tests/printf.c index 55fa483..42f3f7c 100644 --- a/glib/tests/printf.c +++ b/glib/tests/printf.c @@ -642,6 +642,25 @@ test_positional_params2 (void) } static void +test_positional_params3 (void) +{ + gchar buf[128]; + gint res; + + res = g_sprintf (buf, "%2$c %1$c", 'b', 'a'); + g_assert_cmpint (res, ==, 3); + g_assert_cmpstr (buf, ==, "a b"); + + res = g_sprintf (buf, "%1$*2$.*3$s", "abc", 5, 2); + g_assert_cmpint (res, ==, 5); + g_assert_cmpstr (buf, ==, " ab"); + + res = g_sprintf (buf, "%1$s%1$s", "abc"); + g_assert_cmpint (res, ==, 6); + g_assert_cmpstr (buf, ==, "abcabc"); +} + +static void test_percent2 (void) { gint res; @@ -920,5 +939,7 @@ main (int argc, g_test_add_func ("/printf/test-positional-params", test_positional_params2); g_test_add_func ("/printf/test-64bit", test_64bit2); + g_test_add_func ("/sprintf/test-positional-params", test_positional_params3); + return g_test_run(); } -- 2.7.4