1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
27 #include <sys/types.h>
30 #define ZERO "\xe2\x82\x80"
31 #define ONE "\xe2\x82\x81"
32 #define TWO "\xe2\x82\x82"
33 #define THREE "\xe2\x82\x83"
34 #define FOUR "\xe2\x82\x84"
35 #define FIVE "\xe2\x82\x85"
36 #define SIX "\xe2\x82\x86"
37 #define SEVEN "\xe2\x82\x87"
38 #define EIGHT "\xe2\x82\x88"
39 #define NINE "\xe2\x82\x89"
41 static struct printf_int_test
46 } printf_int_tests[] =
48 { 0, "%I'10d", " " ZERO },
49 { 1, "%I'10d", " " ONE },
50 { 2, "%I'10d", " " TWO },
51 { 3, "%I'10d", " " THREE },
52 { 4, "%I'10d", " " FOUR },
53 { 5, "%I'10d", " " FIVE },
54 { 6, "%I'10d", " " SIX },
55 { 7, "%I'10d", " " SEVEN },
56 { 8, "%I'10d", " " EIGHT },
57 { 9, "%I'10d", " " NINE },
58 { 11, "%I'10d", " " ONE ONE },
59 { 12, "%I'10d", " " ONE TWO },
60 { 123, "%I10d", " " ONE TWO THREE },
61 { 123, "%I'10d", " " ONE TWO THREE },
62 { 1234, "%I10d", ONE TWO THREE FOUR },
63 { 1234, "%I'10d", ONE "," TWO THREE FOUR },
64 { 12345, "%I'10d", ONE TWO "," THREE FOUR FIVE },
65 { 123456, "%I'10d", ONE TWO THREE "," FOUR FIVE SIX },
66 { 1234567, "%I'10d", ONE "," TWO THREE FOUR "," FIVE SIX SEVEN }
69 #define WZERO L"\x2080"
70 #define WONE L"\x2081"
71 #define WTWO L"\x2082"
72 #define WTHREE L"\x2083"
73 #define WFOUR L"\x2084"
74 #define WFIVE L"\x2085"
75 #define WSIX L"\x2086"
76 #define WSEVEN L"\x2087"
77 #define WEIGHT L"\x2088"
78 #define WNINE L"\x2089"
80 static struct wprintf_int_test
83 const wchar_t *format;
84 const wchar_t *expected;
85 } wprintf_int_tests[] =
87 { 0, L"%I'10d", L" " WZERO },
88 { 1, L"%I'10d", L" " WONE },
89 { 2, L"%I'10d", L" " WTWO },
90 { 3, L"%I'10d", L" " WTHREE },
91 { 4, L"%I'10d", L" " WFOUR },
92 { 5, L"%I'10d", L" " WFIVE },
93 { 6, L"%I'10d", L" " WSIX },
94 { 7, L"%I'10d", L" " WSEVEN },
95 { 8, L"%I'10d", L" " WEIGHT },
96 { 9, L"%I'10d", L" " WNINE },
97 { 11, L"%I'10d", L" " WONE WONE },
98 { 12, L"%I'10d", L" " WONE WTWO },
99 { 123, L"%I10d", L" " WONE WTWO WTHREE },
100 { 123, L"%I'10d", L" " WONE WTWO WTHREE },
101 { 1234, L"%I10d", L" " WONE WTWO WTHREE WFOUR },
102 { 1234, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR },
103 { 12345, L"%I'10d", L" " WONE WTWO L"," WTHREE WFOUR WFIVE },
104 { 123456, L"%I'10d", L" " WONE WTWO WTHREE L"," WFOUR WFIVE WSIX },
105 { 1234567, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR L"," WFIVE WSIX WSEVEN }
117 if (setlocale (LC_ALL, "test7") == NULL)
119 puts ("cannot set locale `test7'");
122 printf ("CODESET = \"%s\"\n", nl_langinfo (CODESET));
124 /* First: printf tests. */
126 for (cnt = 0; cnt < sizeof (printf_int_tests) / sizeof (printf_int_tests[0]);
132 n = snprintf (buf, sizeof buf, printf_int_tests[cnt].format,
133 printf_int_tests[cnt].n);
135 printf ("%3d: got \"%s\", expected \"%s\"",
136 cnt, buf, printf_int_tests[cnt].expected);
138 if (n != strlen (printf_int_tests[cnt].expected)
139 || strcmp (buf, printf_int_tests[cnt].expected) != 0)
148 printf ("%d failures in printf tests\n", failures);
149 status = failures != 0;
154 cnt < sizeof (wprintf_int_tests) / sizeof (wprintf_int_tests[0]);
160 n = swprintf (buf, sizeof buf / sizeof (buf[0]),
161 wprintf_int_tests[cnt].format,
162 wprintf_int_tests[cnt].n);
164 printf ("%3d: got \"%ls\", expected \"%ls\"",
165 cnt, buf, wprintf_int_tests[cnt].expected);
167 if (n != wcslen (wprintf_int_tests[cnt].expected)
168 || wcscmp (buf, wprintf_int_tests[cnt].expected) != 0)
177 printf ("%d failures in wprintf tests\n", failures);
178 status = failures != 0;
180 /* ctype tests. This makes sure that the multibyte chracter digit
181 representations are not handle in this table. */
183 for (cnt = 0; cnt < 256; ++cnt)
184 if (cnt >= '0' && cnt <= '9')
188 printf ("isdigit ('%c') == 0\n", cnt);
196 printf ("isdigit (%d) != 0\n", cnt);
201 printf ("%d failures in ctype tests\n", failures);
202 status = failures != 0;
204 /* wctype tests. This makes sure the second set of digits is also
207 for (cnt = 0; cnt < 256; ++cnt)
208 if (cnt >= '0' && cnt <= '9')
210 if (! iswdigit (cnt))
212 printf ("iswdigit (L'%c') == 0\n", cnt);
220 printf ("iswdigit (%d) != 0\n", cnt);
225 for (cnt = 0x2070; cnt < 0x2090; ++cnt)
226 if (cnt >= 0x2080 && cnt <= 0x2089)
228 if (! iswdigit (cnt))
230 printf ("iswdigit (U%04X) == 0\n", cnt);
238 printf ("iswdigit (U%04X) != 0\n", cnt);
243 printf ("%d failures in wctype tests\n", failures);
244 status = failures != 0;