1 /* Test of u8_vasnprintf() function in an ISO-8859-1 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 (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...))
48 /* Test the support of the 's' conversion specifier for strings. */
51 const char *locale_string = "\304rger"; /* Ärger */
55 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
56 static const uint8_t expected[] = "\303\204rger 33";
57 ASSERT (result != NULL);
58 ASSERT (u8_strcmp (result, expected) == 0);
59 ASSERT (length == u8_strlen (result));
65 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
66 static const uint8_t expected[] = " \303\204rger 33";
67 ASSERT (result != NULL);
68 ASSERT (u8_strcmp (result, expected) == 0);
69 ASSERT (length == u8_strlen (result));
75 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
76 static const uint8_t expected[] = "\303\204rger 33";
77 ASSERT (result != NULL);
78 ASSERT (u8_strcmp (result, expected) == 0);
79 ASSERT (length == u8_strlen (result));
82 { /* FLAG_ZERO: no effect. */
85 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
86 static const uint8_t expected[] = " \303\204rger 33";
87 ASSERT (result != NULL);
88 ASSERT (u8_strcmp (result, expected) == 0);
89 ASSERT (length == u8_strlen (result));
96 my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...)
101 va_start (args, format);
102 ret = u8_vasnprintf (resultbuf, lengthp, format, args);
110 test_function (my_asnprintf);
114 main (int argc, char *argv[])
116 /* configure should already have checked that the locale is supported. */
117 if (setlocale (LC_ALL, "") == NULL)