1 /* Test of POSIX compatible vasnwprintf() and asnwprintf() functions.
2 Copyright (C) 2010-2024 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 <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2010. */
21 #include "vasnwprintf.h"
30 /* glibc >= 2.2 supports the 'I' flag, and in glibc >= 2.2.3 the fa_IR
31 locale defines the 'outdigits' to be U+06F0..U+06F9.
32 So we test for glibc >= 2.3. */
33 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__
36 test_function (wchar_t * (*my_asnwprintf
) (wchar_t *, size_t *, const wchar_t *, ...))
38 /* Test that the 'I' flag is supported. */
42 my_asnwprintf (NULL
, &length
, L
"%Id %d", 1234567, 99);
43 static const wchar_t expected
[] = /* "۱۲۳۴۵۶۷ 99" */
45 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7, L
' ',
48 ASSERT (result
!= NULL
);
49 ASSERT (wcscmp (result
, expected
) == 0);
50 ASSERT (length
== wcslen (result
));
56 my_asnwprintf (wchar_t *resultbuf
, size_t *lengthp
, const wchar_t *format
, ...)
61 va_start (args
, format
);
62 ret
= vasnwprintf (resultbuf
, lengthp
, format
, args
);
70 test_function (my_asnwprintf
);
76 test_function (asnwprintf
);
82 main (int argc
, char *argv
[])
84 #if (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) && !defined __UCLIBC__
85 /* Select a locale with Arabic 'outdigits'. */
86 if (setlocale (LC_ALL
, "fa_IR.UTF-8") == NULL
87 && setlocale (LC_ALL
, "fa_IR") == NULL
)
89 fprintf (stderr
, "Skipping test: no Iranian locale is installed\n");
96 return test_exit_status
;
98 fprintf (stderr
, "Skipping test: not a glibc >= 2.3 system\n");