]> git.ipfire.org Git - thirdparty/glibc.git/blame - localedata/tst-digits.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / localedata / tst-digits.c
CommitLineData
f7a9f785 1/* Copyright (C) 2000-2016 Free Software Foundation, Inc.
c1d835ce
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
c1d835ce
UD
9
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
41bdb6e2 13 Lesser General Public License for more details.
c1d835ce 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
c1d835ce
UD
18
19#include <ctype.h>
2da34564 20#include <langinfo.h>
69c69fe1
UD
21#include <locale.h>
22#include <stdio.h>
03ae3c1e
AJ
23#include <stdlib.h>
24#include <string.h>
2da34564
UD
25#include <unistd.h>
26#include <wchar.h>
c1d835ce 27#include <wctype.h>
69c69fe1
UD
28#include <sys/types.h>
29
30
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"
41
42static struct printf_int_test
43{
44 int n;
45 const char *format;
46 const char *expected;
47} printf_int_tests[] =
48{
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 }
68};
d64a397a
UD
69#define nprintf_int_tests \
70 (sizeof (printf_int_tests) / sizeof (printf_int_tests[0]))
69c69fe1 71
2da34564
UD
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"
82
83static struct wprintf_int_test
84{
85 int n;
86 const wchar_t *format;
87 const wchar_t *expected;
88} wprintf_int_tests[] =
89{
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 }
109};
d64a397a
UD
110#define nwprintf_int_tests \
111 (sizeof (wprintf_int_tests) / sizeof (wprintf_int_tests[0]))
69c69fe1
UD
112
113
29955b5d
AS
114static int
115do_test (void)
69c69fe1
UD
116{
117 int cnt;
2da34564 118 int failures;
c1d835ce 119 int status;
69c69fe1
UD
120
121 if (setlocale (LC_ALL, "test7") == NULL)
122 {
123 puts ("cannot set locale `test7'");
124 exit (1);
125 }
2da34564 126 printf ("CODESET = \"%s\"\n", nl_langinfo (CODESET));
69c69fe1
UD
127
128 /* First: printf tests. */
2da34564 129 failures = 0;
d64a397a 130 for (cnt = 0; cnt < (int) nprintf_int_tests; ++cnt)
69c69fe1
UD
131 {
132 char buf[100];
133 ssize_t n;
134
135 n = snprintf (buf, sizeof buf, printf_int_tests[cnt].format,
136 printf_int_tests[cnt].n);
137
2da34564
UD
138 printf ("%3d: got \"%s\", expected \"%s\"",
139 cnt, buf, printf_int_tests[cnt].expected);
140
d64a397a 141 if (n != (ssize_t) strlen (printf_int_tests[cnt].expected)
69c69fe1
UD
142 || strcmp (buf, printf_int_tests[cnt].expected) != 0)
143 {
2da34564
UD
144 puts (" -> FAILED");
145 ++failures;
146 }
147 else
148 puts (" -> OK");
149 }
150
151 printf ("%d failures in printf tests\n", failures);
152 status = failures != 0;
153
154 /* wprintf tests. */
155 failures = 0;
d64a397a 156 for (cnt = 0; cnt < (int) nwprintf_int_tests; ++cnt)
2da34564
UD
157 {
158 wchar_t buf[100];
159 ssize_t n;
160
161 n = swprintf (buf, sizeof buf / sizeof (buf[0]),
162 wprintf_int_tests[cnt].format,
163 wprintf_int_tests[cnt].n);
164
165 printf ("%3d: got \"%ls\", expected \"%ls\"",
166 cnt, buf, wprintf_int_tests[cnt].expected);
167
d64a397a 168 if (n != (ssize_t) wcslen (wprintf_int_tests[cnt].expected)
2da34564
UD
169 || wcscmp (buf, wprintf_int_tests[cnt].expected) != 0)
170 {
171 puts (" -> FAILED");
c1d835ce 172 ++failures;
69c69fe1 173 }
2da34564
UD
174 else
175 puts (" -> OK");
69c69fe1
UD
176 }
177
2da34564 178 printf ("%d failures in wprintf tests\n", failures);
c1d835ce
UD
179 status = failures != 0;
180
382466e0 181 /* ctype tests. This makes sure that the multibyte character digit
c1d835ce 182 representations are not handle in this table. */
2da34564 183 failures = 0;
c1d835ce
UD
184 for (cnt = 0; cnt < 256; ++cnt)
185 if (cnt >= '0' && cnt <= '9')
186 {
187 if (! isdigit (cnt))
188 {
189 printf ("isdigit ('%c') == 0\n", cnt);
190 ++failures;
191 }
192 }
193 else
194 {
195 if (isdigit (cnt))
196 {
197 printf ("isdigit (%d) != 0\n", cnt);
198 ++failures;
199 }
200 }
201
2da34564 202 printf ("%d failures in ctype tests\n", failures);
c1d835ce
UD
203 status = failures != 0;
204
205 /* wctype tests. This makes sure the second set of digits is also
206 recorded. */
2da34564 207 failures = 0;
c1d835ce
UD
208 for (cnt = 0; cnt < 256; ++cnt)
209 if (cnt >= '0' && cnt <= '9')
210 {
211 if (! iswdigit (cnt))
212 {
213 printf ("iswdigit (L'%c') == 0\n", cnt);
214 ++failures;
215 }
216 }
217 else
218 {
219 if (iswdigit (cnt))
220 {
221 printf ("iswdigit (%d) != 0\n", cnt);
222 ++failures;
223 }
224 }
225
226 for (cnt = 0x2070; cnt < 0x2090; ++cnt)
227 if (cnt >= 0x2080 && cnt <= 0x2089)
228 {
229 if (! iswdigit (cnt))
230 {
231 printf ("iswdigit (U%04X) == 0\n", cnt);
232 ++failures;
233 }
234 }
235 else
236 {
237 if (iswdigit (cnt))
238 {
239 printf ("iswdigit (U%04X) != 0\n", cnt);
240 ++failures;
241 }
242 }
243
2da34564 244 printf ("%d failures in wctype tests\n", failures);
c1d835ce 245 status = failures != 0;
69c69fe1 246
c1d835ce 247 return status;
69c69fe1 248}
29955b5d
AS
249
250#define TEST_FUNCTION do_test ()
251#include "../test-skeleton.c"