summaryrefslogtreecommitdiff
path: root/tests/unistdio
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unistdio')
-rw-r--r--tests/unistdio/test-u16-asnprintf1.c2
-rw-r--r--tests/unistdio/test-u16-asnprintf1.h55
-rw-r--r--tests/unistdio/test-u16-printf1.h82
-rw-r--r--tests/unistdio/test-u16-vasnprintf1.c2
-rw-r--r--tests/unistdio/test-u16-vasnprintf2.c65
-rw-r--r--tests/unistdio/test-u16-vasnprintf3.c65
-rw-r--r--tests/unistdio/test-u16-vasprintf1.c2
-rw-r--r--tests/unistdio/test-u16-vsnprintf1.c2
-rw-r--r--tests/unistdio/test-u16-vsprintf1.c2
-rw-r--r--tests/unistdio/test-u32-asnprintf1.c2
-rw-r--r--tests/unistdio/test-u32-asnprintf1.h55
-rw-r--r--tests/unistdio/test-u32-printf1.h82
-rw-r--r--tests/unistdio/test-u32-vasnprintf1.c2
-rw-r--r--tests/unistdio/test-u32-vasnprintf2.c65
-rw-r--r--tests/unistdio/test-u32-vasnprintf3.c65
-rw-r--r--tests/unistdio/test-u32-vasprintf1.c2
-rw-r--r--tests/unistdio/test-u32-vsnprintf1.c2
-rw-r--r--tests/unistdio/test-u32-vsprintf1.c2
-rw-r--r--tests/unistdio/test-u8-asnprintf1.c2
-rw-r--r--tests/unistdio/test-u8-asnprintf1.h55
-rw-r--r--tests/unistdio/test-u8-printf1.h64
-rw-r--r--tests/unistdio/test-u8-vasnprintf1.c2
-rw-r--r--tests/unistdio/test-u8-vasnprintf2.c50
-rw-r--r--tests/unistdio/test-u8-vasnprintf3.c50
-rw-r--r--tests/unistdio/test-u8-vasprintf1.c2
-rw-r--r--tests/unistdio/test-u8-vsnprintf1.c2
-rw-r--r--tests/unistdio/test-u8-vsprintf1.c2
-rw-r--r--tests/unistdio/test-ulc-asnprintf1.c3
-rw-r--r--tests/unistdio/test-ulc-asnprintf1.h55
-rw-r--r--tests/unistdio/test-ulc-vasnprintf1.c3
-rw-r--r--tests/unistdio/test-ulc-vasnprintf2.c76
-rw-r--r--tests/unistdio/test-ulc-vasnprintf3.c76
-rw-r--r--tests/unistdio/test-ulc-vasprintf1.c2
-rw-r--r--tests/unistdio/test-ulc-vsnprintf1.c2
-rw-r--r--tests/unistdio/test-ulc-vsprintf1.c2
35 files changed, 974 insertions, 28 deletions
diff --git a/tests/unistdio/test-u16-asnprintf1.c b/tests/unistdio/test-u16-asnprintf1.c
index 67ce490a..6eac3a3b 100644
--- a/tests/unistdio/test-u16-asnprintf1.c
+++ b/tests/unistdio/test-u16-asnprintf1.c
@@ -42,5 +42,5 @@ int
main (int argc, char *argv[])
{
test_asnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u16-asnprintf1.h b/tests/unistdio/test-u16-asnprintf1.h
index 4ec31a43..2b1a9ab3 100644
--- a/tests/unistdio/test-u16-asnprintf1.h
+++ b/tests/unistdio/test-u16-asnprintf1.h
@@ -57,4 +57,59 @@ test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, .
if (result != buf)
free (result);
}
+
+ /* Verify that u16_[v]asnprintf() rejects a width > 2 GiB, < 4 GiB. */
+ {
+ size_t length;
+ uint16_t *s = my_asnprintf (NULL, &length, "x%03000000000dy\n", -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint16_t arg[] = { '@', 0 };
+ size_t length;
+ uint16_t *s = my_asnprintf (NULL, &length, "x%03000000000lUy\n", arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+
+ /* Verify that u16_[v]asnprintf() rejects a width > 4 GiB. */
+ {
+ size_t length;
+ uint16_t *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306dy\n", /* 2^32 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint16_t arg[] = { '@', 0 };
+ size_t length;
+ uint16_t *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306lUy\n", /* 2^32 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ size_t length;
+ uint16_t *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626dy\n", /* 2^64 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint16_t arg[] = { '@', 0 };
+ size_t length;
+ uint16_t *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626lUy\n", /* 2^64 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
}
diff --git a/tests/unistdio/test-u16-printf1.h b/tests/unistdio/test-u16-printf1.h
index e501c9e4..d2a71153 100644
--- a/tests/unistdio/test-u16-printf1.h
+++ b/tests/unistdio/test-u16-printf1.h
@@ -120,6 +120,32 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint8_t unicode_string[] = /* hétérogénéité */
+ "h\303\251t\303\251rog\303\251n\303\251it\303\251";
+ uint16_t *result =
+ my_xasprintf ("%20U %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint8_t unicode_string[] = "\360\237\220\203"; /* 🐃 */
+ uint16_t *result =
+ my_xasprintf ("%10U %d", unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0xd83d,
+ 0xdc03, ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{
static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
@@ -178,6 +204,34 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint16_t unicode_string[] = /* hétérogénéité */
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, 0
+ };
+ uint16_t *result =
+ my_xasprintf ("%20lU %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint16_t unicode_string[] = { 0xd83d, 0xdc03, 0 }; /* 🐃 */
+ uint16_t *result =
+ my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0xd83d,
+ 0xdc03, ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
{
static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
@@ -236,6 +290,34 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint32_t unicode_string[] = /* hétérogénéité */
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, 0
+ };
+ uint16_t *result =
+ my_xasprintf ("%20llU %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint32_t unicode_string[] = { 0x1f403, 0 }; /* 🐃 */
+ uint16_t *result =
+ my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55);
+ static const uint16_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0xd83d,
+ 0xdc03, ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u16_strcmp (result, expected) == 0);
+ free (result);
+ }
/* Test the support of the 's' conversion specifier for strings. */
diff --git a/tests/unistdio/test-u16-vasnprintf1.c b/tests/unistdio/test-u16-vasnprintf1.c
index e39495c9..b9965683 100644
--- a/tests/unistdio/test-u16-vasnprintf1.c
+++ b/tests/unistdio/test-u16-vasnprintf1.c
@@ -71,5 +71,5 @@ int
main (int argc, char *argv[])
{
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u16-vasnprintf2.c b/tests/unistdio/test-u16-vasnprintf2.c
index aee67584..4c061c66 100644
--- a/tests/unistdio/test-u16-vasnprintf2.c
+++ b/tests/unistdio/test-u16-vasnprintf2.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\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 *
@@ -115,5 +178,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
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;
}
diff --git a/tests/unistdio/test-u16-vasprintf1.c b/tests/unistdio/test-u16-vasprintf1.c
index 203d2edf..43cc6e22 100644
--- a/tests/unistdio/test-u16-vasprintf1.c
+++ b/tests/unistdio/test-u16-vasprintf1.c
@@ -58,5 +58,5 @@ int
main (int argc, char *argv[])
{
test_vasprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u16-vsnprintf1.c b/tests/unistdio/test-u16-vsnprintf1.c
index 6859468a..9cf40eac 100644
--- a/tests/unistdio/test-u16-vsnprintf1.c
+++ b/tests/unistdio/test-u16-vsnprintf1.c
@@ -64,5 +64,5 @@ main (int argc, char *argv[])
{
test_vsnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u16-vsprintf1.c b/tests/unistdio/test-u16-vsprintf1.c
index b39a3056..63f68a79 100644
--- a/tests/unistdio/test-u16-vsprintf1.c
+++ b/tests/unistdio/test-u16-vsprintf1.c
@@ -64,5 +64,5 @@ main (int argc, char *argv[])
{
test_vsprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-asnprintf1.c b/tests/unistdio/test-u32-asnprintf1.c
index 5a16094b..428460fe 100644
--- a/tests/unistdio/test-u32-asnprintf1.c
+++ b/tests/unistdio/test-u32-asnprintf1.c
@@ -42,5 +42,5 @@ int
main (int argc, char *argv[])
{
test_asnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-asnprintf1.h b/tests/unistdio/test-u32-asnprintf1.h
index 85fa2cf0..af786848 100644
--- a/tests/unistdio/test-u32-asnprintf1.h
+++ b/tests/unistdio/test-u32-asnprintf1.h
@@ -57,4 +57,59 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, .
if (result != buf)
free (result);
}
+
+ /* Verify that u32_[v]asnprintf() rejects a width > 2 GiB, < 4 GiB. */
+ {
+ size_t length;
+ uint32_t *s = my_asnprintf (NULL, &length, "x%03000000000dy\n", -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint32_t arg[] = { '@', 0 };
+ size_t length;
+ uint32_t *s = my_asnprintf (NULL, &length, "x%03000000000llUy\n", arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+
+ /* Verify that u32_[v]asnprintf() rejects a width > 4 GiB. */
+ {
+ size_t length;
+ uint32_t *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306dy\n", /* 2^32 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint32_t arg[] = { '@', 0 };
+ size_t length;
+ uint32_t *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306llUy\n", /* 2^32 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ size_t length;
+ uint32_t *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626dy\n", /* 2^64 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint32_t arg[] = { '@', 0 };
+ size_t length;
+ uint32_t *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626llUy\n", /* 2^64 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
}
diff --git a/tests/unistdio/test-u32-printf1.h b/tests/unistdio/test-u32-printf1.h
index ae0edc6a..d7ba2e09 100644
--- a/tests/unistdio/test-u32-printf1.h
+++ b/tests/unistdio/test-u32-printf1.h
@@ -120,6 +120,32 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint8_t unicode_string[] = /* hétérogénéité */
+ "h\303\251t\303\251rog\303\251n\303\251it\303\251";
+ uint32_t *result =
+ my_xasprintf ("%20U %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint8_t unicode_string[] = "\360\237\220\203"; /* 🐃 */
+ uint32_t *result =
+ my_xasprintf ("%10U %d", unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x1f403,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{
static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
@@ -178,6 +204,34 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint16_t unicode_string[] = /* hétérogénéité */
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, 0
+ };
+ uint32_t *result =
+ my_xasprintf ("%20lU %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint16_t unicode_string[] = { 0xd83d, 0xdc03, 0 }; /* 🐃 */
+ uint32_t *result =
+ my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x1f403,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
{
static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
@@ -236,6 +290,34 @@ test_xfunction (uint32_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint32_t unicode_string[] = /* hétérogénéité */
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, 0
+ };
+ uint32_t *result =
+ my_xasprintf ("%20llU %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint32_t unicode_string[] = { 0x1f403, 0 }; /* 🐃 */
+ uint32_t *result =
+ my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55);
+ static const uint32_t expected[] =
+ { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x1f403,
+ ' ', '3', '3', 0
+ };
+ ASSERT (result != NULL);
+ ASSERT (u32_strcmp (result, expected) == 0);
+ free (result);
+ }
/* Test the support of the 's' conversion specifier for strings. */
diff --git a/tests/unistdio/test-u32-vasnprintf1.c b/tests/unistdio/test-u32-vasnprintf1.c
index 43c115cf..7392294a 100644
--- a/tests/unistdio/test-u32-vasnprintf1.c
+++ b/tests/unistdio/test-u32-vasnprintf1.c
@@ -71,5 +71,5 @@ int
main (int argc, char *argv[])
{
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-vasnprintf2.c b/tests/unistdio/test-u32-vasnprintf2.c
index 1ddab53f..70336c7c 100644
--- a/tests/unistdio/test-u32-vasnprintf2.c
+++ b/tests/unistdio/test-u32-vasnprintf2.c
@@ -87,6 +87,69 @@ test_function (uint32_t * (*my_asnprintf) (uint32_t *, size_t *, const char *, .
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 *
@@ -115,5 +178,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-vasnprintf3.c b/tests/unistdio/test-u32-vasnprintf3.c
index cfc4674c..816eb9fd 100644
--- a/tests/unistdio/test-u32-vasnprintf3.c
+++ b/tests/unistdio/test-u32-vasnprintf3.c
@@ -87,6 +87,69 @@ test_function (uint32_t * (*my_asnprintf) (uint32_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;
+ 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 *
@@ -115,5 +178,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-vasprintf1.c b/tests/unistdio/test-u32-vasprintf1.c
index 3ab5e89c..d4624725 100644
--- a/tests/unistdio/test-u32-vasprintf1.c
+++ b/tests/unistdio/test-u32-vasprintf1.c
@@ -58,5 +58,5 @@ int
main (int argc, char *argv[])
{
test_vasprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-vsnprintf1.c b/tests/unistdio/test-u32-vsnprintf1.c
index fa38f8db..bb73ca80 100644
--- a/tests/unistdio/test-u32-vsnprintf1.c
+++ b/tests/unistdio/test-u32-vsnprintf1.c
@@ -64,5 +64,5 @@ main (int argc, char *argv[])
{
test_vsnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u32-vsprintf1.c b/tests/unistdio/test-u32-vsprintf1.c
index c857ca71..ae2ff722 100644
--- a/tests/unistdio/test-u32-vsprintf1.c
+++ b/tests/unistdio/test-u32-vsprintf1.c
@@ -64,5 +64,5 @@ main (int argc, char *argv[])
{
test_vsprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-asnprintf1.c b/tests/unistdio/test-u8-asnprintf1.c
index d5d256aa..2a8c9ce4 100644
--- a/tests/unistdio/test-u8-asnprintf1.c
+++ b/tests/unistdio/test-u8-asnprintf1.c
@@ -42,5 +42,5 @@ int
main (int argc, char *argv[])
{
test_asnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-asnprintf1.h b/tests/unistdio/test-u8-asnprintf1.h
index f48e2365..7c2c3622 100644
--- a/tests/unistdio/test-u8-asnprintf1.h
+++ b/tests/unistdio/test-u8-asnprintf1.h
@@ -54,4 +54,59 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...
if (result != buf)
free (result);
}
+
+ /* Verify that u8_[v]asnprintf() rejects a width > 2 GiB, < 4 GiB. */
+ {
+ size_t length;
+ uint8_t *s = my_asnprintf (NULL, &length, "x%03000000000dy\n", -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint8_t arg[] = { '@', 0 };
+ size_t length;
+ uint8_t *s = my_asnprintf (NULL, &length, "x%03000000000Uy\n", arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+
+ /* Verify that u8_[v]asnprintf() rejects a width > 4 GiB. */
+ {
+ size_t length;
+ uint8_t *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306dy\n", /* 2^32 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint8_t arg[] = { '@', 0 };
+ size_t length;
+ uint8_t *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306Uy\n", /* 2^32 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ size_t length;
+ uint8_t *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626dy\n", /* 2^64 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint8_t arg[] = { '@', 0 };
+ size_t length;
+ uint8_t *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626Uy\n", /* 2^64 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
}
diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h
index 3e8999b6..3963adb6 100644
--- a/tests/unistdio/test-u8-printf1.h
+++ b/tests/unistdio/test-u8-printf1.h
@@ -110,6 +110,26 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint8_t unicode_string[] = /* hétérogénéité */
+ "h\303\251t\303\251rog\303\251n\303\251it\303\251";
+ uint8_t *result =
+ my_xasprintf ("%20U %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint8_t unicode_string[] = "\360\237\220\203"; /* 🐃 */
+ uint8_t *result =
+ my_xasprintf ("%10U %d", unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " \360\237\220\203 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{
static const uint16_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
@@ -162,6 +182,28 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint16_t unicode_string[] = /* hétérogénéité */
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, 0
+ };
+ uint8_t *result =
+ my_xasprintf ("%20lU %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint16_t unicode_string[] = { 0xd83d, 0xdc03, 0 }; /* 🐃 */
+ uint8_t *result =
+ my_xasprintf ("%10lU %d", unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " \360\237\220\203 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{
static const uint32_t unicode_string[] = { 'H', 'e', 'l', 'l', 'o', 0 };
@@ -214,6 +256,28 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
}
+ { /* Width with a non-ASCII argument. */
+ static const uint32_t unicode_string[] = /* hétérogénéité */
+ { 'h', 0x00e9, 't', 0x00e9, 'r', 'o', 'g', 0x00e9, 'n', 0x00e9,
+ 'i', 't', 0x00e9, 0
+ };
+ uint8_t *result =
+ my_xasprintf ("%20llU %d", unicode_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);
+ free (result);
+ }
+ { /* Width with a non-BMP argument. */
+ static const uint32_t unicode_string[] = { 0x1f403, 0 }; /* 🐃 */
+ uint8_t *result =
+ my_xasprintf ("%10llU %d", unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " \360\237\220\203 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
/* Test the support of the 's' conversion specifier for strings. */
diff --git a/tests/unistdio/test-u8-vasnprintf1.c b/tests/unistdio/test-u8-vasnprintf1.c
index 895faa93..b808b186 100644
--- a/tests/unistdio/test-u8-vasnprintf1.c
+++ b/tests/unistdio/test-u8-vasnprintf1.c
@@ -71,5 +71,5 @@ int
main (int argc, char *argv[])
{
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-vasnprintf2.c b/tests/unistdio/test-u8-vasnprintf2.c
index 30289688..3c0a00f1 100644
--- a/tests/unistdio/test-u8-vasnprintf2.c
+++ b/tests/unistdio/test-u8-vasnprintf2.c
@@ -77,6 +77,54 @@ test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...
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 *
@@ -105,5 +153,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-vasnprintf3.c b/tests/unistdio/test-u8-vasnprintf3.c
index b5dc9ab6..72efa60a 100644
--- a/tests/unistdio/test-u8-vasnprintf3.c
+++ b/tests/unistdio/test-u8-vasnprintf3.c
@@ -77,6 +77,54 @@ test_function (uint8_t * (*my_asnprintf) (uint8_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;
+ 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 *
@@ -105,5 +153,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-vasprintf1.c b/tests/unistdio/test-u8-vasprintf1.c
index 611f1395..24512276 100644
--- a/tests/unistdio/test-u8-vasprintf1.c
+++ b/tests/unistdio/test-u8-vasprintf1.c
@@ -58,5 +58,5 @@ int
main (int argc, char *argv[])
{
test_vasprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-vsnprintf1.c b/tests/unistdio/test-u8-vsnprintf1.c
index 5de57fb1..7cd55288 100644
--- a/tests/unistdio/test-u8-vsnprintf1.c
+++ b/tests/unistdio/test-u8-vsnprintf1.c
@@ -64,5 +64,5 @@ main (int argc, char *argv[])
{
test_vsnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-u8-vsprintf1.c b/tests/unistdio/test-u8-vsprintf1.c
index 542cce32..3300677f 100644
--- a/tests/unistdio/test-u8-vsprintf1.c
+++ b/tests/unistdio/test-u8-vsprintf1.c
@@ -64,5 +64,5 @@ main (int argc, char *argv[])
{
test_vsprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-asnprintf1.c b/tests/unistdio/test-ulc-asnprintf1.c
index 236cd3b2..8fb91da0 100644
--- a/tests/unistdio/test-ulc-asnprintf1.c
+++ b/tests/unistdio/test-ulc-asnprintf1.c
@@ -20,6 +20,7 @@
#include "unistdio.h"
+#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
@@ -40,5 +41,5 @@ int
main (int argc, char *argv[])
{
test_asnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-asnprintf1.h b/tests/unistdio/test-ulc-asnprintf1.h
index 9e11f314..8ede282f 100644
--- a/tests/unistdio/test-ulc-asnprintf1.h
+++ b/tests/unistdio/test-ulc-asnprintf1.h
@@ -51,4 +51,59 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
if (result != buf)
free (result);
}
+
+ /* Verify that ulc_[v]asnprintf() rejects a width > 2 GiB, < 4 GiB. */
+ {
+ size_t length;
+ char *s = my_asnprintf (NULL, &length, "x%03000000000dy\n", -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint8_t arg[] = { '@', 0 };
+ size_t length;
+ char *s = my_asnprintf (NULL, &length, "x%03000000000Uy\n", arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+
+ /* Verify that ulc_[v]asnprintf() rejects a width > 4 GiB. */
+ {
+ size_t length;
+ char *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306dy\n", /* 2^32 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint8_t arg[] = { '@', 0 };
+ size_t length;
+ char *s =
+ my_asnprintf (NULL, &length,
+ "x%04294967306Uy\n", /* 2^32 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ size_t length;
+ char *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626dy\n", /* 2^64 + 10 */
+ -17);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
+ {
+ static const uint8_t arg[] = { '@', 0 };
+ size_t length;
+ char *s =
+ my_asnprintf (NULL, &length,
+ "x%018446744073709551626Uy\n", /* 2^64 + 10 */
+ arg);
+ ASSERT (s == NULL);
+ ASSERT (errno == EOVERFLOW);
+ }
}
diff --git a/tests/unistdio/test-ulc-vasnprintf1.c b/tests/unistdio/test-ulc-vasnprintf1.c
index d0d6f858..4352ff03 100644
--- a/tests/unistdio/test-ulc-vasnprintf1.c
+++ b/tests/unistdio/test-ulc-vasnprintf1.c
@@ -20,6 +20,7 @@
#include "unistdio.h"
+#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
@@ -69,5 +70,5 @@ int
main (int argc, char *argv[])
{
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-vasnprintf2.c b/tests/unistdio/test-ulc-vasnprintf2.c
index 458ce4aa..ba14e612 100644
--- a/tests/unistdio/test-ulc-vasnprintf2.c
+++ b/tests/unistdio/test-ulc-vasnprintf2.c
@@ -76,6 +76,16 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
}
+ { /* Width with a non-BMP argument. */
+ static const uint8_t unicode_string[] = "\360\237\220\203"; /* 🐃 */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%10U %d", unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " ? 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
{
static const uint16_t unicode_string[] = /* Rafał Maszkowski */
@@ -124,6 +134,16 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
}
+ { /* Width with a non-BMP argument. */
+ static const uint16_t unicode_string[] = { 0xd83d, 0xdc03, 0 }; /* 🐃 */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%10lU %d", unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " ? 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
{
static const uint32_t unicode_string[] = /* Rafał Maszkowski */
@@ -172,6 +192,16 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
}
+ { /* Width with a non-BMP argument. */
+ static const uint32_t unicode_string[] = { 0x1f403, 0 }; /* 🐃 */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%10llU %d", unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " ? 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
/* Test the support of the 's' conversion specifier for strings. */
@@ -214,6 +244,50 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
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 *
@@ -242,5 +316,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-vasnprintf3.c b/tests/unistdio/test-ulc-vasnprintf3.c
index 717e9850..f73b4539 100644
--- a/tests/unistdio/test-ulc-vasnprintf3.c
+++ b/tests/unistdio/test-ulc-vasnprintf3.c
@@ -72,6 +72,16 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
}
+ { /* Width with a non-BMP argument. */
+ static const uint8_t unicode_string[] = "\360\237\220\203"; /* 🐃 */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%10U %d", unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " \360\237\220\203 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
{
static const uint16_t unicode_string[] = /* Rafał Maszkowski */
@@ -116,6 +126,16 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
}
+ { /* Width with a non-BMP argument. */
+ static const uint16_t unicode_string[] = { 0xd83d, 0xdc03, 0 }; /* 🐃 */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%10lU %d", unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " \360\237\220\203 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
{
static const uint32_t unicode_string[] = /* Rafał Maszkowski */
@@ -160,6 +180,16 @@ test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
free (result);
}
}
+ { /* Width with a non-BMP argument. */
+ static const uint32_t unicode_string[] = { 0x1f403, 0 }; /* 🐃 */
+ size_t length;
+ char *result =
+ my_asnprintf (NULL, &length, "%10llU %d", unicode_string, 33, 44, 55);
+ ASSERT (result != NULL);
+ ASSERT (strcmp (result, " \360\237\220\203 33") == 0);
+ ASSERT (length == strlen (result));
+ free (result);
+ }
/* Test the support of the 's' conversion specifier for strings. */
@@ -202,6 +232,50 @@ test_function (char * (*my_asnprintf) (char *, 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;
+ 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 *
@@ -230,5 +304,5 @@ main (int argc, char *argv[])
return 1;
test_vasnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-vasprintf1.c b/tests/unistdio/test-ulc-vasprintf1.c
index c97909cc..b91376ca 100644
--- a/tests/unistdio/test-ulc-vasprintf1.c
+++ b/tests/unistdio/test-ulc-vasprintf1.c
@@ -56,5 +56,5 @@ int
main (int argc, char *argv[])
{
test_vasprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-vsnprintf1.c b/tests/unistdio/test-ulc-vsnprintf1.c
index 899ad10b..2c1e38d7 100644
--- a/tests/unistdio/test-ulc-vsnprintf1.c
+++ b/tests/unistdio/test-ulc-vsnprintf1.c
@@ -57,5 +57,5 @@ main (int argc, char *argv[])
{
test_vsnprintf ();
- return 0;
+ return test_exit_status;
}
diff --git a/tests/unistdio/test-ulc-vsprintf1.c b/tests/unistdio/test-ulc-vsprintf1.c
index 123397d7..1e3633a5 100644
--- a/tests/unistdio/test-ulc-vsprintf1.c
+++ b/tests/unistdio/test-ulc-vsprintf1.c
@@ -57,5 +57,5 @@ main (int argc, char *argv[])
{
test_vsprintf ();
- return 0;
+ return test_exit_status;
}