2024-06-18 Bruno Haible <bruno@clisp.org>
+ u*-vasnprintf tests: Add tests of %ls directive.
+ * tests/unistdio/test-u8-vasnprintf2.c (test_function): Add tests of
+ the %ls directive with non-ASCII argument.
+ * tests/unistdio/test-u8-vasnprintf3.c (test_function): Likewise.
+ * tests/unistdio/test-u16-vasnprintf2.c (test_function): Likewise.
+ * tests/unistdio/test-u16-vasnprintf3.c (test_function): Likewise.
+ * tests/unistdio/test-u32-vasnprintf2.c (test_function): Likewise.
+ * tests/unistdio/test-u32-vasnprintf3.c (test_function): Likewise.
+ * tests/unistdio/test-ulc-vasnprintf2.c (test_function): Likewise.
+ * tests/unistdio/test-ulc-vasnprintf3.c (test_function): Likewise.
+
u*-vasnprintf: Fix handling of %ls, %lc directives on Solaris, MSVC.
* lib/vasnprintf.c (VASNPRINTF): When implementing the %ls, %lc
directives ourselves: Rename variable 'characters' to 'bytes'. Also
free (result);
}
}
+
+ /* Test the support of the 'ls' conversion specifier for wide strings. */
+
+ {
+ const char *locale_string = "h\351t\351rog\351n\351it\351"; /* 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 *
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 *
free (result);
}
}
+
+ /* Test the support of the 'ls' conversion specifier for wide strings. */
+
+ {
+ const char *locale_string = "h\351t\351rog\351n\351it\351"; /* hétérogénéité */
+ wchar_t wide_string[20];
+ ASSERT (mbstowcs (wide_string, locale_string, SIZEOF (wide_string)) == 13);
+ {
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ { /* Width. */
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'h', 0x00e9, 't',
+ 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, 'i', 't', 0x00e9,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ { /* FLAG_LEFT. */
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ { /* FLAG_ZERO: no effect. */
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'h', 0x00e9, 't',
+ 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, 'i', 't', 0x00e9,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ }
}
static uint32_t *
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;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ { /* Width. */
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'h', 0x00e9, 't',
+ 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, 'i', 't', 0x00e9,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ { /* FLAG_LEFT. */
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, ' ', ' ', ' ', ' ', ' ', ' ', ' ',
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ { /* FLAG_ZERO: no effect. */
+ size_t length;
+ uint32_t *result =
+ my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'h', 0x00e9, 't',
+ 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9, 'i', 't', 0x00e9,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ ASSERT (length == u32_strlen (result));
+ free (result);
+ }
+ }
}
static uint32_t *
free (result);
}
}
+
+ /* Test the support of the 'ls' conversion specifier for wide strings. */
+
+ {
+ const char *locale_string = "h\351t\351rog\351n\351it\351"; /* hétérogénéité */
+ wchar_t wide_string[20];
+ ASSERT (mbstowcs (wide_string, locale_string, SIZEOF (wide_string)) == 13);
+ {
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = "h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ { /* Width. */
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = " h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ { /* FLAG_LEFT. */
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = "h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ { /* FLAG_ZERO: no effect. */
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = " h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ }
}
static uint8_t *
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;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = "h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ { /* Width. */
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = " h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ { /* FLAG_LEFT. */
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = "h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ { /* FLAG_ZERO: no effect. */
+ size_t length;
+ uint8_t *result =
+ my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55);
+ static const uint8_t expected[] = " h\303\251t\303\251rog\303\251n\303\251it\303\251 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ ASSERT (length == u8_strlen (result));
+ free (result);
+ }
+ }
}
static uint8_t *
free (result);
}
}
+
+ /* Test the support of the 'ls' conversion specifier for wide strings. */
+
+ {
+ const char *locale_string = "h\351t\351rog\351n\351it\351"; /* hétérogénéité */
+ wchar_t wide_string[20];
+ ASSERT (mbstowcs (wide_string, locale_string, SIZEOF (wide_string)) == 13);
+ {
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "h\351t\351rog\351n\351it\351 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ { /* Width. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " h\351t\351rog\351n\351it\351 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ { /* FLAG_LEFT. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "h\351t\351rog\351n\351it\351 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ { /* FLAG_ZERO: no effect. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " h\351t\351rog\351n\351it\351 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ }
}
static 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;
+ char *result =
+ my_asnprintf (NULL, &length, "%ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "h\303\251t\303\251rog\303\251n\303\251it\303\251 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ { /* Width. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%20ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " h\303\251t\303\251rog\303\251n\303\251it\303\251 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ { /* FLAG_LEFT. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%-20ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, "h\303\251t\303\251rog\303\251n\303\251it\303\251 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ { /* FLAG_ZERO: no effect. */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%020ls %d", wide_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " h\303\251t\303\251rog\303\251n\303\251it\303\251 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
+ }
}
static char *