From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type
Date: Thu, 17 Mar 2022 20:28:26 +0100 [thread overview]
Message-ID: <f251e498ed050e37063b3cdd2dae82d9a430b8fc.1647544751.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1647544751.git.fweimer@redhat.com>
And use TEST_COMPARE_STRING for the narrow tests.
---
stdio-common/tst-vfprintf-user-type.c | 128 ++++++++++++--------------
1 file changed, 61 insertions(+), 67 deletions(-)
diff --git a/stdio-common/tst-vfprintf-user-type.c b/stdio-common/tst-vfprintf-user-type.c
index f2650ac018..4aa78a6b60 100644
--- a/stdio-common/tst-vfprintf-user-type.c
+++ b/stdio-common/tst-vfprintf-user-type.c
@@ -21,6 +21,7 @@
this indicates the number of such pairs which constitute the
argument. */
+#include <array_length.h>
#include <locale.h>
#include <printf.h>
#include <stdio.h>
@@ -60,13 +61,23 @@ my_printf_function (FILE *fp, const struct printf_info *info,
__func__, fp, info, args[0], args, (wint_t) info->spec,
info->prec);
+ TEST_COMPARE (info->wide, fwide (fp, 0) > 0);
+
TEST_VERIFY (info->spec == 'P');
size_t nargs;
int printed;
if (info->prec >= 0)
{
- if (fputc ('{', fp) < 0)
- return -1;
+ if (info->wide)
+ {
+ if (fputwc (L'{', fp) < 0)
+ return -1;
+ }
+ else
+ {
+ if (fputc ('{', fp) < 0)
+ return -1;
+ }
nargs = info->prec;
printed = 1;
}
@@ -80,8 +91,16 @@ my_printf_function (FILE *fp, const struct printf_info *info,
{
if (i != 0)
{
- if (fputc (',', fp) < 0)
- return -1;
+ if (info->wide)
+ {
+ if (fputwc (L',', fp) < 0)
+ return -1;
+ }
+ else
+ {
+ if (fputc (',', fp) < 0)
+ return -1;
+ }
++printed;
}
@@ -89,15 +108,27 @@ my_printf_function (FILE *fp, const struct printf_info *info,
and those pointers point to a pointer to the memory area
supplied to my_va_arg_function. */
struct two_argument *pair = *(void **) args[i];
- int ret = fprintf (fp, "(%ld, %f)", pair->i, pair->d);
+ int ret;
+ if (info->wide)
+ ret = fwprintf (fp, L"(%ld, %f)", pair->i, pair->d);
+ else
+ ret = fprintf (fp, "(%ld, %f)", pair->i, pair->d);
if (ret < 0)
return -1;
printed += ret;
}
if (info->prec >= 0)
{
- if (fputc ('}', fp) < 0)
- return -1;
+ if (info->wide)
+ {
+ if (fputwc (L'}', fp) < 0)
+ return -1;
+ }
+ else
+ {
+ if (fputc ('}', fp) < 0)
+ return -1;
+ }
++printed;
}
return printed;
@@ -145,77 +176,40 @@ do_test (void)
TEST_VERIFY_EXIT (register_printf_specifier
('P', my_printf_function, my_arginfo_function) >= 0);
- /* Alias declaration for asprintf, to avoid the format string
- attribute and the associated warning. */
-#if __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
- extern int asprintf_alias (char **, const char *, ...) __asm__ ("__asprintfieee128");
-#else
- extern int asprintf_alias (char **, const char *, ...) __asm__ ("asprintf");
-#endif
- TEST_VERIFY (asprintf_alias == asprintf);
- char *str = NULL;
- TEST_VERIFY (asprintf_alias (&str, "[[%P]]", 123L, 456.0) >= 0);
- if (test_verbose > 0)
- printf ("info: %s\n", str);
- TEST_VERIFY (strcmp (str, "[[(123, 456.000000)]]") == 0);
- free (str);
-
- str = NULL;
- TEST_VERIFY (asprintf_alias (&str, "[[%1$P %1$P]]", 123L, 457.0) >= 0);
- if (test_verbose > 0)
- printf ("info: %s\n", str);
- TEST_VERIFY (strcmp (str, "[[(123, 457.000000) (123, 457.000000)]]") == 0);
- free (str);
-
- str = NULL;
- TEST_VERIFY (asprintf_alias (&str, "[[%.1P]]", 1L, 2.0) >= 0);
- if (test_verbose > 0)
- printf ("info: %s\n", str);
- TEST_VERIFY (strcmp (str, "[[{(1, 2.000000)}]]") == 0);
- free (str);
+ /* Wide variants of the tests above. */
- str = NULL;
- TEST_VERIFY (asprintf_alias (&str, "[[%.2P]]", 1L, 2.0, 3L, 4.0) >= 0);
- if (test_verbose > 0)
- printf ("info: %s\n", str);
- TEST_VERIFY (strcmp (str, "[[{(1, 2.000000),(3, 4.000000)}]]") == 0);
- free (str);
+ wchar_t buf[200];
+ TEST_VERIFY (swprintf (buf, array_length (buf), L"[[%.2P]]",
+ 1L, 2.0, 3L, 4.0) >= 0);
+ TEST_COMPARE_STRING_WIDE (buf, L"[[{(1, 2.000000),(3, 4.000000)}]]");
- str = NULL;
- TEST_VERIFY (asprintf_alias
- (&str, "[[%.2P | %.3P]]",
+ TEST_VERIFY (swprintf
+ (buf, array_length (buf), L"[[%.2P | %.3P]]",
/* argument 1: */ 1L, 2.0, 3L, 4.0,
/* argument 2: */ 5L, 6.0, 7L, 8.0, 9L, 10.0)
>= 0);
- if (test_verbose > 0)
- printf ("info: %s\n", str);
- TEST_VERIFY (strcmp (str,
- "[["
- "{(1, 2.000000),(3, 4.000000)}"
- " | "
- "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}"
- "]]") == 0);
- free (str);
+ TEST_COMPARE_STRING_WIDE (buf,
+ L"[["
+ "{(1, 2.000000),(3, 4.000000)}"
+ " | "
+ "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}"
+ "]]");
/* The following subtest fails due to bug 21534. */
#if 0
- str = NULL;
- TEST_VERIFY (asprintf_alias
- (&str, "[[%1$.2P | %2$.3P | %1$.2P]]",
+ TEST_VERIFY (swprintf
+ (&buf, array_length (buf), L"[[%1$.2P | %2$.3P | %1$.2P]]",
/* argument 1: */ 1L, 2.0, 3L, 4.0,
/* argument 2: */ 5L, 6.0, 7L, 8.0, 9L, 10.0)
>= 0);
- if (test_verbose > 0)
- printf ("info: %s\n", str);
- TEST_VERIFY (strcmp (str,
- "[["
- "{(1, 2.000000),(3, 4.000000)}"
- " | "
- "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}"
- " | "
- "{(1, 2.000000),(3, 4.000000)}"
- "]]") == 0);
- free (str);
+ TEST_COMPARE_STRING_WIDE (buf,
+ L"[["
+ "{(1, 2.000000),(3, 4.000000)}"
+ " | "
+ "{(5, 6.000000),(7, 8.000000),(9, 10.000000)}"
+ " | "
+ "{(1, 2.000000),(3, 4.000000)}"
+ "]]");
#endif
return 0;
--
2.35.1
next prev parent reply other threads:[~2022-03-17 19:28 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
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 ` Florian Weimer [this message]
2022-03-18 18:30 ` [PATCH 03/26] stdio-common: Add wide stream coverage to tst-vfprintf-user-type 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=f251e498ed050e37063b3cdd2dae82d9a430b8fc.1647544751.git.fweimer@redhat.com \
--to=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).