1 /* Test of u16_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. */
33 test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, ...))
35 /* Test the support of the 's' conversion specifier for strings. */
38 const char *locale_string = "\304rger"; /* Ärger */
42 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
43 static const uint16_t expected[] =
44 { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 };
45 ASSERT (result != NULL);
46 ASSERT (u16_strcmp (result, expected) == 0);
47 ASSERT (length == u16_strlen (result));
53 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
54 static const uint16_t expected[] =
55 { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r',
58 ASSERT (result != NULL);
59 ASSERT (u16_strcmp (result, expected) == 0);
60 ASSERT (length == u16_strlen (result));
66 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
67 static const uint16_t expected[] =
68 { 0x00c4, 'r', 'g', 'e', 'r', ' ', ' ', ' ', ' ', ' ',
71 ASSERT (result != NULL);
72 ASSERT (u16_strcmp (result, expected) == 0);
73 ASSERT (length == u16_strlen (result));
76 { /* FLAG_ZERO: no effect. */
79 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
80 static const uint16_t expected[] =
81 { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r',
84 ASSERT (result != NULL);
85 ASSERT (u16_strcmp (result, expected) == 0);
86 ASSERT (length == u16_strlen (result));
93 my_asnprintf (uint16_t *resultbuf, size_t *lengthp, const char *format, ...)
98 va_start (args, format);
99 ret = u16_vasnprintf (resultbuf, lengthp, format, args);
107 test_function (my_asnprintf);
111 main (int argc, char *argv[])
113 /* configure should already have checked that the locale is supported. */
114 if (setlocale (LC_ALL, "") == NULL)