summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2023-03-21 17:47:04 +0100
committerBruno Haible <bruno@clisp.org>2023-03-21 17:53:44 +0100
commitff3f33eea46cd58b490a88bc90e9e572bff70d0f (patch)
tree0fea8b231c362425ac6789b5e92d18552d3ce6a9 /tests
parent4d76e28ab57ee53871cda1c3e158bdc380441855 (diff)
downloadgnulib-ff3f33eea46cd58b490a88bc90e9e572bff70d0f.tar.gz
vasnwprintf: Fix for older platforms without swprintf.
* lib/vasnprintf.c (VASNPRINTF): In the %lc handling, ignore the precision. Convert the snprintf result to a wchar_t[] not by mbsrtowcs, but by a loop that does not stop at NUL characters. * tests/test-vasnwprintf-posix.c (test_function): Add more tests for the %c and %lc directives. * modules/vasnwprintf (Depends-on): Add mbrtowc. Remove mbsrtowcs.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-vasnwprintf-posix.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test-vasnwprintf-posix.c b/tests/test-vasnwprintf-posix.c
index c609a104ff..e53c6a33f3 100644
--- a/tests/test-vasnwprintf-posix.c
+++ b/tests/test-vasnwprintf-posix.c
@@ -3940,6 +3940,26 @@ test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *,
free (result);
}
+ { /* Precision is ignored. */
+ size_t length;
+ wchar_t *result =
+ my_asnwprintf (NULL, &length,
+ L"%.0c %d", (unsigned char) 'x', 33, 44, 55);
+ ASSERT (wcscmp (result, L"x 33") == 0);
+ ASSERT (length == wcslen (result));
+ free (result);
+ }
+
+ { /* NUL character. */
+ size_t length;
+ wchar_t *result =
+ my_asnwprintf (NULL, &length,
+ L"a%cz %d", '\0', 33, 44, 55);
+ ASSERT (wmemcmp (result, L"a\0z 33\0", 6 + 1) == 0);
+ ASSERT (length == 6);
+ free (result);
+ }
+
#if HAVE_WCHAR_T
static wint_t L_x = (wchar_t) 'x';
@@ -3982,6 +4002,24 @@ test_function (wchar_t * (*my_asnwprintf) (wchar_t *, size_t *, const wchar_t *,
ASSERT (length == wcslen (result));
free (result);
}
+
+ { /* Precision is ignored. */
+ size_t length;
+ wchar_t *result =
+ my_asnwprintf (NULL, &length, L"%.0lc %d", L_x, 33, 44, 55);
+ ASSERT (wcscmp (result, L"x 33") == 0);
+ ASSERT (length == wcslen (result));
+ free (result);
+ }
+
+ { /* NUL character. */
+ size_t length;
+ wchar_t *result =
+ my_asnwprintf (NULL, &length, L"a%lcz %d", (wint_t) L'\0', 33, 44, 55);
+ ASSERT (wmemcmp (result, L"a\0z 33\0", 6 + 1) == 0);
+ ASSERT (length == 6);
+ free (result);
+ }
#endif
/* Test the support of the 'b' conversion specifier for binary output of