Update copyright notices with scripts/update-copyrights
[glibc.git] / localedata / tst-digits.c
blob9b3ebcdaa16fc8413d69a459f72b5ab6b64f4a44
1 /* Copyright (C) 2000-2014 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, see
17 <http://www.gnu.org/licenses/>. */
19 #include <ctype.h>
20 #include <langinfo.h>
21 #include <locale.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <wchar.h>
27 #include <wctype.h>
28 #include <sys/types.h>
31 #define ZERO "\xe2\x82\x80"
32 #define ONE "\xe2\x82\x81"
33 #define TWO "\xe2\x82\x82"
34 #define THREE "\xe2\x82\x83"
35 #define FOUR "\xe2\x82\x84"
36 #define FIVE "\xe2\x82\x85"
37 #define SIX "\xe2\x82\x86"
38 #define SEVEN "\xe2\x82\x87"
39 #define EIGHT "\xe2\x82\x88"
40 #define NINE "\xe2\x82\x89"
42 static struct printf_int_test
44 int n;
45 const char *format;
46 const char *expected;
47 } printf_int_tests[] =
49 { 0, "%I'10d", " " ZERO },
50 { 1, "%I'10d", " " ONE },
51 { 2, "%I'10d", " " TWO },
52 { 3, "%I'10d", " " THREE },
53 { 4, "%I'10d", " " FOUR },
54 { 5, "%I'10d", " " FIVE },
55 { 6, "%I'10d", " " SIX },
56 { 7, "%I'10d", " " SEVEN },
57 { 8, "%I'10d", " " EIGHT },
58 { 9, "%I'10d", " " NINE },
59 { 11, "%I'10d", " " ONE ONE },
60 { 12, "%I'10d", " " ONE TWO },
61 { 123, "%I10d", " " ONE TWO THREE },
62 { 123, "%I'10d", " " ONE TWO THREE },
63 { 1234, "%I10d", ONE TWO THREE FOUR },
64 { 1234, "%I'10d", ONE "," TWO THREE FOUR },
65 { 12345, "%I'10d", ONE TWO "," THREE FOUR FIVE },
66 { 123456, "%I'10d", ONE TWO THREE "," FOUR FIVE SIX },
67 { 1234567, "%I'10d", ONE "," TWO THREE FOUR "," FIVE SIX SEVEN }
69 #define nprintf_int_tests \
70 (sizeof (printf_int_tests) / sizeof (printf_int_tests[0]))
72 #define WZERO L"\x2080"
73 #define WONE L"\x2081"
74 #define WTWO L"\x2082"
75 #define WTHREE L"\x2083"
76 #define WFOUR L"\x2084"
77 #define WFIVE L"\x2085"
78 #define WSIX L"\x2086"
79 #define WSEVEN L"\x2087"
80 #define WEIGHT L"\x2088"
81 #define WNINE L"\x2089"
83 static struct wprintf_int_test
85 int n;
86 const wchar_t *format;
87 const wchar_t *expected;
88 } wprintf_int_tests[] =
90 { 0, L"%I'10d", L" " WZERO },
91 { 1, L"%I'10d", L" " WONE },
92 { 2, L"%I'10d", L" " WTWO },
93 { 3, L"%I'10d", L" " WTHREE },
94 { 4, L"%I'10d", L" " WFOUR },
95 { 5, L"%I'10d", L" " WFIVE },
96 { 6, L"%I'10d", L" " WSIX },
97 { 7, L"%I'10d", L" " WSEVEN },
98 { 8, L"%I'10d", L" " WEIGHT },
99 { 9, L"%I'10d", L" " WNINE },
100 { 11, L"%I'10d", L" " WONE WONE },
101 { 12, L"%I'10d", L" " WONE WTWO },
102 { 123, L"%I10d", L" " WONE WTWO WTHREE },
103 { 123, L"%I'10d", L" " WONE WTWO WTHREE },
104 { 1234, L"%I10d", L" " WONE WTWO WTHREE WFOUR },
105 { 1234, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR },
106 { 12345, L"%I'10d", L" " WONE WTWO L"," WTHREE WFOUR WFIVE },
107 { 123456, L"%I'10d", L" " WONE WTWO WTHREE L"," WFOUR WFIVE WSIX },
108 { 1234567, L"%I'10d", L" " WONE L"," WTWO WTHREE WFOUR L"," WFIVE WSIX WSEVEN }
110 #define nwprintf_int_tests \
111 (sizeof (wprintf_int_tests) / sizeof (wprintf_int_tests[0]))
115 main (void)
117 int cnt;
118 int failures;
119 int status;
121 if (setlocale (LC_ALL, "test7") == NULL)
123 puts ("cannot set locale `test7'");
124 exit (1);
126 printf ("CODESET = \"%s\"\n", nl_langinfo (CODESET));
128 /* First: printf tests. */
129 failures = 0;
130 for (cnt = 0; cnt < (int) nprintf_int_tests; ++cnt)
132 char buf[100];
133 ssize_t n;
135 n = snprintf (buf, sizeof buf, printf_int_tests[cnt].format,
136 printf_int_tests[cnt].n);
138 printf ("%3d: got \"%s\", expected \"%s\"",
139 cnt, buf, printf_int_tests[cnt].expected);
141 if (n != (ssize_t) strlen (printf_int_tests[cnt].expected)
142 || strcmp (buf, printf_int_tests[cnt].expected) != 0)
144 puts (" -> FAILED");
145 ++failures;
147 else
148 puts (" -> OK");
151 printf ("%d failures in printf tests\n", failures);
152 status = failures != 0;
154 /* wprintf tests. */
155 failures = 0;
156 for (cnt = 0; cnt < (int) nwprintf_int_tests; ++cnt)
158 wchar_t buf[100];
159 ssize_t n;
161 n = swprintf (buf, sizeof buf / sizeof (buf[0]),
162 wprintf_int_tests[cnt].format,
163 wprintf_int_tests[cnt].n);
165 printf ("%3d: got \"%ls\", expected \"%ls\"",
166 cnt, buf, wprintf_int_tests[cnt].expected);
168 if (n != (ssize_t) wcslen (wprintf_int_tests[cnt].expected)
169 || wcscmp (buf, wprintf_int_tests[cnt].expected) != 0)
171 puts (" -> FAILED");
172 ++failures;
174 else
175 puts (" -> OK");
178 printf ("%d failures in wprintf tests\n", failures);
179 status = failures != 0;
181 /* ctype tests. This makes sure that the multibyte character digit
182 representations are not handle in this table. */
183 failures = 0;
184 for (cnt = 0; cnt < 256; ++cnt)
185 if (cnt >= '0' && cnt <= '9')
187 if (! isdigit (cnt))
189 printf ("isdigit ('%c') == 0\n", cnt);
190 ++failures;
193 else
195 if (isdigit (cnt))
197 printf ("isdigit (%d) != 0\n", cnt);
198 ++failures;
202 printf ("%d failures in ctype tests\n", failures);
203 status = failures != 0;
205 /* wctype tests. This makes sure the second set of digits is also
206 recorded. */
207 failures = 0;
208 for (cnt = 0; cnt < 256; ++cnt)
209 if (cnt >= '0' && cnt <= '9')
211 if (! iswdigit (cnt))
213 printf ("iswdigit (L'%c') == 0\n", cnt);
214 ++failures;
217 else
219 if (iswdigit (cnt))
221 printf ("iswdigit (%d) != 0\n", cnt);
222 ++failures;
226 for (cnt = 0x2070; cnt < 0x2090; ++cnt)
227 if (cnt >= 0x2080 && cnt <= 0x2089)
229 if (! iswdigit (cnt))
231 printf ("iswdigit (U%04X) == 0\n", cnt);
232 ++failures;
235 else
237 if (iswdigit (cnt))
239 printf ("iswdigit (U%04X) != 0\n", cnt);
240 ++failures;
244 printf ("%d failures in wctype tests\n", failures);
245 status = failures != 0;
247 return status;