1 /* Test of u8_vasnprintf() function in an UTF-8 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 (uint8_t * (*my_asnprintf) (uint8_t *, size_t *, const char *, ...))
35 /* Test the support of the 's' conversion specifier for strings. */
38 const char *locale_string = "\303\204rger"; /* Ärger */
42 my_asnprintf (NULL, &length, "%s %d", locale_string, 33, 44, 55);
43 static const uint8_t expected[] = "\303\204rger 33";
44 ASSERT (result != NULL);
45 ASSERT (u8_strcmp (result, expected) == 0);
46 ASSERT (length == u8_strlen (result));
52 my_asnprintf (NULL, &length, "%10s %d", locale_string, 33, 44, 55);
53 static const uint8_t expected[] = " \303\204rger 33";
54 ASSERT (result != NULL);
55 ASSERT (u8_strcmp (result, expected) == 0);
56 ASSERT (length == u8_strlen (result));
62 my_asnprintf (NULL, &length, "%-10s %d", locale_string, 33, 44, 55);
63 static const uint8_t expected[] = "\303\204rger 33";
64 ASSERT (result != NULL);
65 ASSERT (u8_strcmp (result, expected) == 0);
66 ASSERT (length == u8_strlen (result));
69 { /* FLAG_ZERO: no effect. */
72 my_asnprintf (NULL, &length, "%010s %d", locale_string, 33, 44, 55);
73 static const uint8_t expected[] = " \303\204rger 33";
74 ASSERT (result != NULL);
75 ASSERT (u8_strcmp (result, expected) == 0);
76 ASSERT (length == u8_strlen (result));
83 my_asnprintf (uint8_t *resultbuf, size_t *lengthp, const char *format, ...)
88 va_start (args, format);
89 ret = u8_vasnprintf (resultbuf, lengthp, format, args);
97 test_function (my_asnprintf);
101 main (int argc, char *argv[])
103 /* configure should already have checked that the locale is supported. */
104 if (setlocale (LC_ALL, "") == NULL)