From 4682deeb62247d34de87f8e777f99e2d337fd377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Sun, 20 Oct 2024 15:21:43 +0200 Subject: New upstream version 1.3 --- tests/unistdio/test-u16-vasnprintf3.c | 65 ++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'tests/unistdio/test-u16-vasnprintf3.c') diff --git a/tests/unistdio/test-u16-vasnprintf3.c b/tests/unistdio/test-u16-vasnprintf3.c index 0efe1984..d5924f8b 100644 --- a/tests/unistdio/test-u16-vasnprintf3.c +++ b/tests/unistdio/test-u16-vasnprintf3.c @@ -87,6 +87,69 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, . free (result); } } + + /* Test the support of the 'ls' conversion specifier for wide strings. */ + + { + const char *locale_string = "h\303\251t\303\251rog\303\251n\303\251it\303\251"; /* hétérogénéité */ + wchar_t wide_string[20]; + ASSERT (mbstowcs (wide_string, locale_string, SIZEOF (wide_string)) == 13); + { + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55); + static const uint16_t expected[] = + { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, + 'i', 't', 0x00e9, ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* Width. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'h', 0x00e9, 't', + 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, 'i', 't', 0x00e9, + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* FLAG_LEFT. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55); + static const uint16_t expected[] = + { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, + 'i', 't', 0x00e9, ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + { /* FLAG_ZERO: no effect. */ + size_t length; + uint16_t *result = + my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'h', 0x00e9, 't', + 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, 'i', 't', 0x00e9, + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + ASSERT (length == u16_strlen (result)); + free (result); + } + } } static uint16_t * @@ -115,5 +178,5 @@ main (int argc, char *argv[]) return 1; test_vasnprintf (); - return 0; + return test_exit_status; } -- cgit v1.2.3