1 /* Test of u8_vasnprintf() function in an UTF-8 locale.
2 Copyright (C) 2007 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__); \
45 test_function (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...))
47 /* Test the support of the 's' conversion specifier for strings. */
50 const char *locale_string = "\303\204rger"; /* Ärger */
54 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
55 static const uint8_t expected[] = "\303\204rger 33";
56 ASSERT (result != NULL);
57 ASSERT (u8_strcmp (result, expected) == 0);
58 ASSERT (length == u8_strlen (result));
64 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
65 static const uint8_t expected[] = " \303\204rger 33";
66 ASSERT (result != NULL);
67 ASSERT (u8_strcmp (result, expected) == 0);
68 ASSERT (length == u8_strlen (result));
74 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
75 static const uint8_t expected[] = "\303\204rger 33";
76 ASSERT (result != NULL);
77 ASSERT (u8_strcmp (result, expected) == 0);
78 ASSERT (length == u8_strlen (result));
81 { /* FLAG_ZERO: no effect. */
84 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
85 static const uint8_t expected[] = " \303\204rger 33";
86 ASSERT (result != NULL);
87 ASSERT (u8_strcmp (result, expected) == 0);
88 ASSERT (length == u8_strlen (result));
95 my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...)
100 va_start (args, format);
101 ret = u8_vasnprintf (resultbuf, lengthp, format, args);
109 test_function (my_asnprintf);
113 main (int argc, char *argv[])
115 /* configure should already have checked that the locale is supported. */
116 if (setlocale (LC_ALL, "") == NULL)