1 /* Test of u16_vasnprintf() function in an UTF-8 locale.
2 Copyright (C) 2007-2008 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 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
33 #define ASSERT(expr) \
38 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
46 test_function (uint16_t * (*my_asnprintf) (uint16_t *, size_t *, const char *, ...))
48 /* Test the support of the 's' conversion specifier for strings. */
51 const char *locale_string = "\303\204rger"; /* Ärger */
55 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
56 static const uint16_t expected[] =
57 { 0x00c4, 'r', 'g', 'e', 'r', ' ', '3', '3', 0 };
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));
79 my_asnprintf (NULL, &length, "%-10s %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));
89 { /* FLAG_ZERO: no effect. */
92 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
93 static const uint16_t expected[] =
94 { ' ', ' ', ' ', ' ', ' ', 0x00c4, 'r', 'g', 'e', 'r',
97 ASSERT (result != NULL);
98 ASSERT (u16_strcmp (result, expected) == 0);
99 ASSERT (length == u16_strlen (result));
106 my_asnprintf (uint16_t *resultbuf, size_t *lengthp, const char *format, ...)
111 va_start (args, format);
112 ret = u16_vasnprintf (resultbuf, lengthp, format, args);
120 test_function (my_asnprintf);
124 main (int argc, char *argv[])
126 /* configure should already have checked that the locale is supported. */
127 if (setlocale (LC_ALL, "") == NULL)