public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Florian Weimer <fw@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc] libio: Convert tst_swprintf to the test framework Date: Fri, 18 Mar 2022 20:42:17 +0000 (GMT) [thread overview] Message-ID: <20220318204217.7E3FA3888825@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6fece2968a11719e8559098d29b4b9519d8cf57a commit 6fece2968a11719e8559098d29b4b9519d8cf57a Author: Florian Weimer <fweimer@redhat.com> Date: Fri Mar 18 21:27:54 2022 +0100 libio: Convert tst_swprintf to the test framework And increase test coverage slightly. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> Diff: --- libio/tst_swprintf.c | 79 +++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/libio/tst_swprintf.c b/libio/tst_swprintf.c index e4bd7f022a..8a2ffe60ec 100644 --- a/libio/tst_swprintf.c +++ b/libio/tst_swprintf.c @@ -1,10 +1,11 @@ +#include <array_length.h> #include <stdio.h> -#include <wchar.h> +#include <support/check.h> #include <sys/types.h> +#include <wchar.h> static wchar_t buf[100]; -#define nbuf (sizeof (buf) / sizeof (buf[0])) static const struct { size_t n; @@ -12,81 +13,57 @@ static const struct ssize_t exp; } tests[] = { - { nbuf, "hello world", 11 }, + { array_length (buf), "hello world", 11 }, { 0, "hello world", -1 }, + { 1, "hello world", -1 }, + { 2, "hello world", -1 }, + { 11, "hello world", -1 }, + { 12, "hello world", 11 }, { 0, "", -1 }, - { nbuf, "", 0 } + { array_length (buf), "", 0 } }; -int -main (int argc, char *argv[]) +static int +do_test (void) { size_t n; - int result = 0; - puts ("test 1"); - n = swprintf (buf, nbuf, L"Hello %s", "world"); - if (n != 11) - { - printf ("incorrect return value: %zd instead of 11\n", n); - result = 1; - } - else if (wcscmp (buf, L"Hello world") != 0) - { - printf ("incorrect string: L\"%ls\" instead of L\"Hello world\"\n", buf); - result = 1; - } + TEST_COMPARE (swprintf (buf, array_length (buf), L"Hello %s", "world"), 11); + TEST_COMPARE_STRING_WIDE (buf, L"Hello world"); - puts ("test 2"); - n = swprintf (buf, nbuf, L"Is this >%g< 3.1?", 3.1); - if (n != 18) - { - printf ("incorrect return value: %zd instead of 18\n", n); - result = 1; - } - else if (wcscmp (buf, L"Is this >3.1< 3.1?") != 0) - { - printf ("incorrect string: L\"%ls\" instead of L\"Is this >3.1< 3.1?\"\n", - buf); - result = 1; - } + TEST_COMPARE (swprintf (buf, array_length (buf), L"Is this >%g< 3.1?", 3.1), + 18); + TEST_COMPARE_STRING_WIDE (buf, L"Is this >3.1< 3.1?"); - for (n = 0; n < sizeof (tests) / sizeof (tests[0]); ++n) + for (n = 0; n < array_length (tests); ++n) { ssize_t res = swprintf (buf, tests[n].n, L"%s", tests[n].str); if (tests[n].exp < 0 && res >= 0) { + support_record_failure (); printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to fail\n", tests[n].n, tests[n].str); - result = 1; } else if (tests[n].exp >= 0 && tests[n].exp != res) { - printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n", + support_record_failure (); + printf ("\ +swprintf (buf, %Zu, L\"%%s\", \"%s\") expected to return %Zd, but got %Zd\n", tests[n].n, tests[n].str, tests[n].exp, res); - result = 1; } else printf ("swprintf (buf, %Zu, L\"%%s\", \"%s\") OK\n", tests[n].n, tests[n].str); } - if (swprintf (buf, nbuf, L"%.0s", "foo") != 0 - || wcslen (buf) != 0) - { - printf ("swprintf (buf, %Zu, L\"%%.0s\", \"foo\") create some output\n", - nbuf); - result = 1; - } + TEST_COMPARE (swprintf (buf, array_length (buf), L"%.0s", "foo"), 0); + TEST_COMPARE_STRING_WIDE (buf, L""); - if (swprintf (buf, nbuf, L"%.0ls", L"foo") != 0 - || wcslen (buf) != 0) - { - printf ("swprintf (buf, %Zu, L\"%%.0ls\", L\"foo\") create some output\n", - nbuf); - result = 1; - } + TEST_COMPARE (swprintf (buf, array_length (buf), L"%.0ls", L"foo"), 0); + TEST_COMPARE_STRING_WIDE (buf, L""); - return result; + return 0; } + +#include <support/test-driver.c>
reply other threads:[~2022-03-18 20:42 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220318204217.7E3FA3888825@sourceware.org \ --to=fw@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).