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 Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 #include <sys/types.h>
32 #define ZERO "\xe2\x82\x80"
33 #define ONE "\xe2\x82\x81"
34 #define TWO "\xe2\x82\x82"
35 #define THREE "\xe2\x82\x83"
36 #define FOUR "\xe2\x82\x84"
37 #define FIVE "\xe2\x82\x85"
38 #define SIX "\xe2\x82\x86"
39 #define SEVEN "\xe2\x82\x87"
40 #define EIGHT "\xe2\x82\x88"
41 #define NINE "\xe2\x82\x89"
43 static struct printf_int_test
48 } printf_int_tests[] =
50 { 0, "%I'10d", " " ZERO },
51 { 1, "%I'10d", " " ONE },
52 { 2, "%I'10d", " " TWO },
53 { 3, "%I'10d", " " THREE },
54 { 4, "%I'10d", " " FOUR },
55 { 5, "%I'10d", " " FIVE },
56 { 6, "%I'10d", " " SIX },
57 { 7, "%I'10d", " " SEVEN },
58 { 8, "%I'10d", " " EIGHT },
59 { 9, "%I'10d", " " NINE },
60 { 11, "%I'10d", " " ONE ONE },
61 { 12, "%I'10d", " " ONE TWO },
62 { 123, "%I10d", " " ONE TWO THREE },
63 { 123, "%I'10d", " " ONE TWO THREE },
64 { 1234, "%I10d", ONE TWO THREE FOUR },
65 { 1234, "%I'10d", ONE "," TWO THREE FOUR },
66 { 12345, "%I'10d", ONE TWO "," THREE FOUR FIVE },
67 { 123456, "%I'10d", ONE TWO THREE "," FOUR FIVE SIX },
68 { 1234567, "%I'10d", ONE "," TWO THREE FOUR "," FIVE SIX SEVEN }
70 #define nprintf_int_tests \
71 (sizeof (printf_int_tests) / sizeof (printf_int_tests[0]))
73 #define WZERO L"\x2080"
74 #define WONE L"\x2081"
75 #define WTWO L"\x2082"
76 #define WTHREE L"\x2083"
77 #define WFOUR L"\x2084"
78 #define WFIVE L"\x2085"
79 #define WSIX L"\x2086"
80 #define WSEVEN L"\x2087"
81 #define WEIGHT L"\x2088"
82 #define WNINE L"\x2089"
84 static struct wprintf_int_test
87 const wchar_t *format;
88 const wchar_t *expected;
89 } wprintf_int_tests[] =
91 { 0, L"%I'10d", L" " WZERO },
92 { 1, L"%I'10d", L" " WONE },
93 { 2, L"%I'10d", L" " WTWO },
94 { 3, L"%I'10d", L" " WTHREE },
95 { 4, L"%I'10d", L" " WFOUR },
96 { 5, L"%I'10d", L" " WFIVE },
97 { 6, L"%I'10d", L" " WSIX },
98 { 7, L"%I'10d", L" " WSEVEN },
99 { 8, L"%I'10d", L" " WEIGHT },
100 { 9, L"%I'10d", L" " WNINE },
101 { 11, L"%I'10d", L" " WONE WONE },
102 { 12, L"%I'10d", L" " WONE WTWO },
103 { 123, L"%I10d", L" " WONE WTWO WTHREE },
104 { 123, L"%I'10d", L" " WONE WTWO WTHREE },
105 { 1234, L"%I10d", L" " WONE WTWO WTHREE WFOUR },
106 { 1234, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR },
107 { 12345, L"%I'10d", L" " WONE WTWO L"," WTHREE WFOUR WFIVE },
108 { 123456, L"%I'10d", L" " WONE WTWO WTHREE L"," WFOUR WFIVE WSIX },
109 { 1234567, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR L"," WFIVE WSIX WSEVEN }
111 #define nwprintf_int_tests \
112 (sizeof (wprintf_int_tests) / sizeof (wprintf_int_tests[0]))
122 if (setlocale (LC_ALL, "test7") == NULL)
124 puts ("cannot set locale `test7'");
127 printf ("CODESET = \"%s\"\n", nl_langinfo (CODESET));
129 /* First: printf tests. */
131 for (cnt = 0; cnt < (int) nprintf_int_tests; ++cnt)
136 n = snprintf (buf, sizeof buf, printf_int_tests[cnt].format,
137 printf_int_tests[cnt].n);
139 printf ("%3d: got \"%s\", expected \"%s\"",
140 cnt, buf, printf_int_tests[cnt].expected);
142 if (n != (ssize_t) strlen (printf_int_tests[cnt].expected)
143 || strcmp (buf, printf_int_tests[cnt].expected) != 0)
152 printf ("%d failures in printf tests\n", failures);
153 status = failures != 0;
157 for (cnt = 0; cnt < (int) nwprintf_int_tests; ++cnt)
162 n = swprintf (buf, sizeof buf / sizeof (buf[0]),
163 wprintf_int_tests[cnt].format,
164 wprintf_int_tests[cnt].n);
166 printf ("%3d: got \"%ls\", expected \"%ls\"",
167 cnt, buf, wprintf_int_tests[cnt].expected);
169 if (n != (ssize_t) wcslen (wprintf_int_tests[cnt].expected)
170 || wcscmp (buf, wprintf_int_tests[cnt].expected) != 0)
179 printf ("%d failures in wprintf tests\n", failures);
180 status = failures != 0;
182 /* ctype tests. This makes sure that the multibyte chracter digit
183 representations are not handle in this table. */
185 for (cnt = 0; cnt < 256; ++cnt)
186 if (cnt >= '0' && cnt <= '9')
190 printf ("isdigit ('%c') == 0\n", cnt);
198 printf ("isdigit (%d) != 0\n", cnt);
203 printf ("%d failures in ctype tests\n", failures);
204 status = failures != 0;
206 /* wctype tests. This makes sure the second set of digits is also
209 for (cnt = 0; cnt < 256; ++cnt)
210 if (cnt >= '0' && cnt <= '9')
212 if (! iswdigit (cnt))
214 printf ("iswdigit (L'%c') == 0\n", cnt);
222 printf ("iswdigit (%d) != 0\n", cnt);
227 for (cnt = 0x2070; cnt < 0x2090; ++cnt)
228 if (cnt >= 0x2080 && cnt <= 0x2089)
230 if (! iswdigit (cnt))
232 printf ("iswdigit (U%04X) == 0\n", cnt);
240 printf ("iswdigit (U%04X) != 0\n", cnt);
245 printf ("%d failures in wctype tests\n", failures);
246 status = failures != 0;