1 /* Test of ulc_vasnprintf() function in an ISO-8859-1 locale.
2 Copyright (C) 2007-2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
32 test_function (char * (*my_asnprintf) (char *, size_t *, const char *, ...))
34 /* Test the support of the 'U' conversion specifier for Unicode strings. */
37 static const uint8_t unicode_string[] = "Rafa\305\202 Maszkowski"; /* Rafał Maszkowski */
41 my_asnprintf (NULL, &length, "%U %d", unicode_string, 33, 44, 55);
42 ASSERT (result != NULL);
43 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
44 || strcmp (result, "Rafal Maszkowski 33") == 0);
45 ASSERT (length == strlen (result));
51 my_asnprintf (NULL, &length, "%20U %d", unicode_string, 33, 44, 55);
52 ASSERT (result != NULL);
53 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
54 || strcmp (result, " Rafal Maszkowski 33") == 0);
55 ASSERT (length == strlen (result));
61 my_asnprintf (NULL, &length, "%-20U %d", unicode_string, 33, 44, 55);
62 ASSERT (result != NULL);
63 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
64 || strcmp (result, "Rafal Maszkowski 33") == 0);
65 ASSERT (length == strlen (result));
68 { /* FLAG_ZERO: no effect. */
71 my_asnprintf (NULL, &length, "%020U %d", unicode_string, 33, 44, 55);
72 ASSERT (result != NULL);
73 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
74 || strcmp (result, " Rafal Maszkowski 33") == 0);
75 ASSERT (length == strlen (result));
81 static const uint16_t unicode_string[] = /* Rafał Maszkowski */
83 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
89 my_asnprintf (NULL, &length, "%lU %d", unicode_string, 33, 44, 55);
90 ASSERT (result != NULL);
91 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
92 || strcmp (result, "Rafal Maszkowski 33") == 0);
93 ASSERT (length == strlen (result));
99 my_asnprintf (NULL, &length, "%20lU %d", unicode_string, 33, 44, 55);
100 ASSERT (result != NULL);
101 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
102 || strcmp (result, " Rafal Maszkowski 33") == 0);
103 ASSERT (length == strlen (result));
109 my_asnprintf (NULL, &length, "%-20lU %d", unicode_string, 33, 44, 55);
110 ASSERT (result != NULL);
111 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
112 || strcmp (result, "Rafal Maszkowski 33") == 0);
113 ASSERT (length == strlen (result));
116 { /* FLAG_ZERO: no effect. */
119 my_asnprintf (NULL, &length, "%020lU %d", unicode_string, 33, 44, 55);
120 ASSERT (result != NULL);
121 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
122 || strcmp (result, " Rafal Maszkowski 33") == 0);
123 ASSERT (length == strlen (result));
129 static const uint32_t unicode_string[] = /* Rafał Maszkowski */
131 'R', 'a', 'f', 'a', 0x0142, ' ', 'M', 'a', 's', 'z', 'k', 'o', 'w',
137 my_asnprintf (NULL, &length, "%llU %d", unicode_string, 33, 44, 55);
138 ASSERT (result != NULL);
139 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
140 || strcmp (result, "Rafal Maszkowski 33") == 0);
141 ASSERT (length == strlen (result));
147 my_asnprintf (NULL, &length, "%20llU %d", unicode_string, 33, 44, 55);
148 ASSERT (result != NULL);
149 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
150 || strcmp (result, " Rafal Maszkowski 33") == 0);
151 ASSERT (length == strlen (result));
157 my_asnprintf (NULL, &length, "%-20llU %d", unicode_string, 33, 44, 55);
158 ASSERT (result != NULL);
159 ASSERT (strcmp (result, "Rafa? Maszkowski 33") == 0
160 || strcmp (result, "Rafal Maszkowski 33") == 0);
161 ASSERT (length == strlen (result));
164 { /* FLAG_ZERO: no effect. */
167 my_asnprintf (NULL, &length, "%020llU %d", unicode_string, 33, 44, 55);
168 ASSERT (result != NULL);
169 ASSERT (strcmp (result, " Rafa? Maszkowski 33") == 0
170 || strcmp (result, " Rafal Maszkowski 33") == 0);
171 ASSERT (length == strlen (result));
176 /* Test the support of the 's' conversion specifier for strings. */
179 const char *locale_string = "\304rger"; /* Ärger */
183 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
184 ASSERT (result != NULL);
185 ASSERT (strcmp (result, "\304rger 33") == 0);
186 ASSERT (length == strlen (result));
192 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
193 ASSERT (result != NULL);
194 ASSERT (strcmp (result, " \304rger 33") == 0);
195 ASSERT (length == strlen (result));
201 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
202 ASSERT (result != NULL);
203 ASSERT (strcmp (result, "\304rger 33") == 0);
204 ASSERT (length == strlen (result));
207 { /* FLAG_ZERO: no effect. */
210 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
211 ASSERT (result != NULL);
212 ASSERT (strcmp (result, " \304rger 33") == 0);
213 ASSERT (length == strlen (result));
220 my_asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
225 va_start (args, format);
226 ret = ulc_vasnprintf (resultbuf, lengthp, format, args);
234 test_function (my_asnprintf);
238 main (int argc, char *argv[])
240 /* configure should already have checked that the locale is supported. */
241 if (setlocale (LC_ALL, "") == NULL)