summaryrefslogtreecommitdiff
path: root/tests/unistdio/test-u8-printf1.h
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unistdio/test-u8-printf1.h')
-rw-r--r--tests/unistdio/test-u8-printf1.h292
1 files changed, 291 insertions, 1 deletions
diff --git a/tests/unistdio/test-u8-printf1.h b/tests/unistdio/test-u8-printf1.h
index 5a820148..3e8999b6 100644
--- a/tests/unistdio/test-u8-printf1.h
+++ b/tests/unistdio/test-u8-printf1.h
@@ -1,5 +1,5 @@
/* Test of u8_v[a]s[n]printf() function.
- Copyright (C) 2007, 2009-2022 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2009-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -77,6 +77,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55);
@@ -113,6 +129,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55);
@@ -149,6 +181,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Hello 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55);
@@ -187,6 +235,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55);
+ static const uint8_t expected[] = "Mr. Ronald Reagan 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55);
+ static const uint8_t expected[] = "Mr. Ronald Reagan 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55);
@@ -238,6 +304,36 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = " 0x1.cp+0 33";
+ static const uint8_t expected2[] = " 0x3.8p-1 33";
+ static const uint8_t expected3[] = " 0x7p-2 33";
+ static const uint8_t expected4[] = " 0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = "0x1.cp+0 33";
+ static const uint8_t expected2[] = "0x3.8p-1 33";
+ static const uint8_t expected3[] = "0x7p-2 33";
+ static const uint8_t expected4[] = "0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint8_t *result =
my_xasprintf ("%.10a %d", 1.75, 33, 44, 55);
@@ -298,6 +394,36 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55);
+ static const uint8_t expected1[] = " 0x1.cp+0 33";
+ static const uint8_t expected2[] = " 0x3.8p-1 33";
+ static const uint8_t expected3[] = " 0x7p-2 33";
+ static const uint8_t expected4[] = " 0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55);
+ static const uint8_t expected1[] = "0x1.cp+0 33";
+ static const uint8_t expected2[] = "0x3.8p-1 33";
+ static const uint8_t expected3[] = "0x7p-2 33";
+ static const uint8_t expected4[] = "0xep-3 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0
+ || u8_strcmp (result, expected3) == 0
+ || u8_strcmp (result, expected4) == 0);
+ free (result);
+ }
+
{ /* Small precision. */
uint8_t *result =
my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55);
@@ -348,6 +474,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = " 1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = "1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.f %d", 1234.0, 33, 44, 55);
@@ -375,6 +519,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = " 1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = "1.750000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55);
@@ -446,6 +608,28 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = " 1.750000e+00 33";
+ static const uint8_t expected2[] = " 1.750000e+000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55);
+ static const uint8_t expected1[] = "1.750000e+00 33";
+ static const uint8_t expected2[] = "1.750000e+000 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected1) == 0
+ || u8_strcmp (result, expected2) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.e %d", 1234.0, 33, 44, 55);
@@ -475,6 +659,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = " 1.750000e+00 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = "1.750000e+00 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55);
@@ -504,6 +706,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = " 1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55);
+ static const uint8_t expected[] = "1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.g %d", 1234.0, 33, 44, 55);
@@ -533,6 +753,24 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = " 1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55);
+ static const uint8_t expected[] = "1.75 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+
{ /* Precision. */
uint8_t *result =
my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55);
@@ -548,11 +786,15 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
int count = -1;
uint8_t *result =
my_xasprintf ("%d %n", 123, &count, 33, 44, 55);
+#if NEED_PRINTF_WITH_N_DIRECTIVE
static const uint8_t expected[] = "123 ";
ASSERT (result != NULL);
ASSERT (u8_strcmp (result, expected) == 0);
ASSERT (count == 4);
free (result);
+#else
+ ASSERT (result == NULL);
+#endif
}
/* Test the support of the POSIX/XSI format strings with positions. */
@@ -596,6 +838,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55);
@@ -636,6 +894,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55);
@@ -676,6 +950,22 @@ test_xfunction (uint8_t * (*my_xasprintf) (const char *, ...))
ASSERT (u8_strcmp (result, expected) == 0);
free (result);
}
+ { /* Width given as argument. */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = " Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
+ { /* Negative width given as argument (cf. FLAG_LEFT below). */
+ uint8_t *result =
+ my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55);
+ static const uint8_t expected[] = "Rafa\305\202 Maszkowski 33";
+ ASSERT (result != NULL);
+ ASSERT (u8_strcmp (result, expected) == 0);
+ free (result);
+ }
{ /* FLAG_LEFT. */
uint8_t *result =
my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55);