diff options
Diffstat (limited to 'tests/unistdio/test-u16-printf1.h')
-rw-r--r-- | tests/unistdio/test-u16-printf1.h | 372 |
1 files changed, 371 insertions, 1 deletions
diff --git a/tests/unistdio/test-u16-printf1.h b/tests/unistdio/test-u16-printf1.h index 7690978d..e501c9e4 100644 --- a/tests/unistdio/test-u16-printf1.h +++ b/tests/unistdio/test-u16-printf1.h @@ -1,5 +1,5 @@ /* Test of u16_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 @@ -83,6 +83,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*U %d", 10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*U %d", -10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-10U %d", unicode_string, 33, 44, 55); @@ -123,6 +141,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*lU %d", 10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*lU %d", -10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-10lU %d", unicode_string, 33, 44, 55); @@ -163,6 +199,24 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*llU %d", 10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', 'H', 'e', 'l', 'l', 'o', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*llU %d", -10, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'H', 'e', 'l', 'l', 'o', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-10llU %d", unicode_string, 33, 44, 55); @@ -211,6 +265,32 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("Mr. %*s %d", 20, "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', ' ', ' ', ' ', ' ', ' ', ' ', + ' ', 'R', 'o', 'n', 'a', 'l', 'd', ' ', 'R', 'e', + 'a', 'g', 'a', 'n', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("Mr. %*s %d", -20, "Ronald Reagan", 33, 44, 55); + static const uint16_t expected[] = + { 'M', 'r', '.', ' ', 'R', 'o', 'n', 'a', 'l', 'd', + ' ', 'R', 'e', 'a', 'g', 'a', 'n', ' ', ' ', ' ', + ' ', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("Mr. %-20s %d", "Ronald Reagan", 33, 44, 55); @@ -278,6 +358,44 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*a %d", 10, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*a %d", -10, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint16_t *result = my_xasprintf ("%.10a %d", 1.75, 33, 44, 55); @@ -402,6 +520,44 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*La %d", 10, 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { ' ', ' ', '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { ' ', ' ', ' ', ' ', '0', 'x', '7', 'p', '-', '2', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { ' ', ' ', ' ', ' ', '0', 'x', 'e', 'p', '-', '3', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*La %d", -10, 1.75L, 33, 44, 55); + static const uint16_t expected1[] = + { '0', 'x', '1', '.', 'c', 'p', '+', '0', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected2[] = + { '0', 'x', '3', '.', '8', 'p', '-', '1', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected3[] = + { '0', 'x', '7', 'p', '-', '2', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + static const uint16_t expected4[] = + { '0', 'x', 'e', 'p', '-', '3', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0 + || u16_strcmp (result, expected3) == 0 + || u16_strcmp (result, expected4) == 0); + free (result); + } + { /* Small precision. */ uint16_t *result = my_xasprintf ("%.10La %d", 1.75L, 33, 44, 55); @@ -502,6 +658,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*f %d", 10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*f %d", -10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.f %d", 1234.0, 33, 44, 55); @@ -532,6 +708,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*Lf %d", 10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*Lf %d", -10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.Lf %d", 1234.0L, 33, 44, 55); @@ -620,6 +816,40 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*e %d", 15, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { ' ', ' ', '1', '.', '7', '5', '0', '0', '0', '0', + 'e', '+', '0', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*e %d", -15, 1.75, 33, 44, 55); + static const uint16_t expected1[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + static const uint16_t expected2[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', '0', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected1) == 0 + || u16_strcmp (result, expected2) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.e %d", 1234.0, 33, 44, 55); @@ -657,6 +887,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*Le %d", 15, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', '1', '.', '7', '5', '0', '0', '0', + '0', 'e', '+', '0', '0', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*Le %d", -15, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', '0', '0', '0', '0', 'e', '+', + '0', '0', ' ', ' ', ' ', ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.Le %d", 1234.0L, 33, 44, 55); @@ -689,6 +943,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*g %d", 10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*g %d", -10, 1.75, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.g %d", 1234.0, 33, 44, 55); @@ -722,6 +996,26 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*Lg %d", 10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', ' ', ' ', '1', '.', '7', '5', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*Lg %d", -10, 1.75L, 33, 44, 55); + static const uint16_t expected[] = + { '1', '.', '7', '5', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '3', '3', 0 }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Precision. */ uint16_t *result = my_xasprintf ("%.Lg %d", 1234.0L, 33, 44, 55); @@ -738,12 +1032,16 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) int count = -1; uint16_t *result = my_xasprintf ("%d %n", 123, &count, 33, 44, 55); +#if NEED_PRINTF_WITH_N_DIRECTIVE static const uint16_t expected[] = { '1', '2', '3', ' ', 0 }; ASSERT (result != NULL); ASSERT (u16_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. */ @@ -795,6 +1093,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*U %d", 20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*U %d", -20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-20U %d", unicode_string, 33, 44, 55); @@ -850,6 +1172,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*lU %d", 20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*lU %d", -20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-20lU %d", unicode_string, 33, 44, 55); @@ -905,6 +1251,30 @@ test_xfunction (uint16_t * (*my_xasprintf) (const char *, ...)) ASSERT (u16_strcmp (result, expected) == 0); free (result); } + { /* Width given as argument. */ + uint16_t *result = + my_xasprintf ("%*llU %d", 20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { ' ', ' ', ' ', ' ', 'R', 'a', 'f', 'a', 0x0142, ' ', + 'M', 'a', 's', 'z', 'k', 'o', 'w', 's', 'k', 'i', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } + { /* Negative width given as argument (cf. FLAG_LEFT below). */ + uint16_t *result = + my_xasprintf ("%*llU %d", -20, unicode_string, 33, 44, 55); + static const uint16_t expected[] = + { 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', + 'k', 'o', 'w', 's', 'k', 'i', ' ', ' ', ' ', ' ', + ' ', '3', '3', 0 + }; + ASSERT (result != NULL); + ASSERT (u16_strcmp (result, expected) == 0); + free (result); + } { /* FLAG_LEFT. */ uint16_t *result = my_xasprintf ("%-20llU %d", unicode_string, 33, 44, 55); |