public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>, libc-alpha@sourceware.org
Subject: Re: [PATCH 01/26] libio: Convert tst_swprintf to the test framework
Date: Fri, 18 Mar 2022 14:40:27 -0300	[thread overview]
Message-ID: <ff48f873-0453-63a5-f92f-7aa731bee7ff@linaro.org> (raw)
In-Reply-To: <f4a970a0f55f12b3d90869336154a52293e48662.1647544751.git.fweimer@redhat.com>



On 17/03/2022 16:28, Florian Weimer via Libc-alpha wrote:
> And increase test coverage slightly.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  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..5ede402fff 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)

Missing space before '('?

>      {
>        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 17:40 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17 19:28 [PATCH 00/26] vfprintf rework to remove vtables Florian Weimer
2022-03-17 19:28 ` [PATCH 01/26] libio: Convert tst_swprintf to the test framework Florian Weimer
2022-03-18 17:40   ` Adhemerval Zanella [this message]
2022-03-17 19:28 ` [PATCH 02/26] libio: Flush-only _IO_str_overflow must not return EOF (bug 28949) Florian Weimer
2022-03-18 18:11   ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type Florian Weimer
2022-03-18 18:30   ` Adhemerval Zanella
2022-03-18 19:19     ` Florian Weimer
2022-03-17 19:28 ` [PATCH 04/26] stdio-common: Add tst-printf-width-i18n to cover numeric field width Florian Weimer
2022-05-20 13:22   ` Adhemerval Zanella
2022-05-20 13:33     ` Adhemerval Zanella
2022-05-23  6:39       ` Florian Weimer
2022-03-17 19:28 ` [PATCH 05/26] vfprintf: Move argument processing into vfprintf-process-arg.c Florian Weimer
2022-05-20 13:28   ` Adhemerval Zanella
2022-03-17 19:28 ` [PATCH 06/26] vfprintf: Consolidate some multibyte/wide character processing Florian Weimer
2022-05-20 14:16   ` Adhemerval Zanella
2022-03-17 19:29 ` [PATCH 07/26] __printf_fphex always uses LC_NUMERIC Florian Weimer
2022-05-20 14:21   ` Adhemerval Zanella
2022-05-23  6:55     ` Florian Weimer
2022-03-17 19:29 ` [PATCH 08/26] stdio-common: Add tst-memstream-string for open_memstream overflow Florian Weimer
2022-05-20 17:44   ` Adhemerval Zanella
2022-05-23  7:03     ` Florian Weimer
2022-03-17 19:29 ` [PATCH 09/26] stdio-common: Add printf specifier registry to <printf.h> Florian Weimer
2022-05-20 17:49   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 10/26] stdio-common: Move union printf_arg int <printf.h> Florian Weimer
2022-05-20 17:51   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 11/26] stdio-common: Simplify printf_unknown interface in vfprintf-internal.c Florian Weimer
2022-05-20 18:07   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 12/26] locale: Call _nl_unload_locale from _nl_archive_subfreeres Florian Weimer
2022-05-20 18:09   ` Adhemerval Zanella
2022-05-23  7:14     ` Florian Weimer
2022-03-17 19:30 ` [PATCH 13/26] locale: Remove cleanup function pointer from struct __localedata Florian Weimer
2022-05-20 18:16   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 14/26] locale: Remove private union from struct __locale_data Florian Weimer
2022-05-20 18:22   ` Adhemerval Zanella
2022-03-17 19:30 ` [PATCH 15/26] locale: Add more cached data to LC_CTYPE Florian Weimer
2022-05-20 18:29   ` Adhemerval Zanella
2022-05-23  7:20     ` Florian Weimer
2022-03-17 19:31 ` [PATCH 16/26] locale: Implement struct grouping_iterator Florian Weimer
2022-03-17 19:31 ` [PATCH 17/26] stdio-common: Introduce buffers for implementing printf Florian Weimer
2022-03-17 19:31 ` [PATCH 18/26] stdio-common: Add __printf_function_invoke Florian Weimer
2022-03-17 19:31 ` [PATCH 19/26] stdio-common: Add __translated_number_width Florian Weimer
2022-03-17 19:31 ` [PATCH 20/26] stdio-common: Convert vfprintf and related functions to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 21/26] stdio-common: Add lock optimization to vfprintf and vfwprintf Florian Weimer
2022-03-17 19:31 ` [PATCH 22/26] libio: Convert __vsprintf_internal to buffers Florian Weimer
2022-03-17 19:31 ` [PATCH 23/26] libio: Convert __vasprintf_internal " Florian Weimer
2022-03-17 19:31 ` [PATCH 24/26] libio: Convert __vdprintf_internal " Florian Weimer
2022-03-17 19:32 ` [PATCH 25/26] libio: Convert __obstack_vprintf_internal to buffers (bug 27124) Florian Weimer
2022-03-17 19:32 ` [PATCH 26/26] libio: Convert __vswprintf_internal to buffers (bug 27857) Florian Weimer

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=ff48f873-0453-63a5-f92f-7aa731bee7ff@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@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: link
Be 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).