1 /* Copyright (C) 2000,02, 05 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/>. */
26 static const char lower
[] = "abcdefghijklmnopqrstuvwxyz";
27 static const char upper
[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
28 static const char digits
[] = "0123456789";
29 static const char cntrl
[] = "\
30 \x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\
31 \x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f ";
40 #define ENTRY(name) { #name, _IS##name }
54 #define nclasses (sizeof (classes) / sizeof (classes[0]))
57 #define FAIL(str, args...) \
59 printf (" " str "\n", ##args); \
71 size_t inplinelen
= 0;
73 size_t reslinelen
= 0;
76 setlocale (LC_ALL
, "");
78 printf ("Testing the ctype data of the `%s' locale\n",
79 setlocale (LC_CTYPE
, NULL
));
82 /* Just for debugging. */
84 /* Contents of the class array. */
86 upper = %04x lower = %04x alpha = %04x digit = %04x xdigit = %04x\n\
87 space = %04x print = %04x graph = %04x blank = %04x cntrl = %04x\n\
88 punct = %04x alnum = %04x\n",
89 _ISupper
, _ISlower
, _ISalpha
, _ISdigit
, _ISxdigit
,
90 _ISspace
, _ISprint
, _ISgraph
, _ISblank
, _IScntrl
,
97 printf ("%04x%s", __ctype_b
[n
], (n
+ 1) % 8 == 0 ? "\n" : " ");
102 puts (" Test of ASCII character range\n special NUL byte handling");
104 FAIL ("isupper ('\\0') is true");
106 FAIL ("islower ('\\0') is true");
108 FAIL ("isalpha ('\\0') is true");
110 FAIL ("isdigit ('\\0') is true");
112 FAIL ("isxdigit ('\\0') is true");
114 FAIL ("isspace ('\\0') is true");
116 FAIL ("isprint ('\\0') is true");
118 FAIL ("isgraph ('\\0') is true");
120 FAIL ("isblank ('\\0') is true");
121 if (! iscntrl ('\0'))
122 FAIL ("iscntrl ('\\0') not true");
124 FAIL ("ispunct ('\\0') is true");
126 FAIL ("isalnum ('\\0') is true");
129 for (cp
= lower
; *cp
!= '\0'; ++cp
)
131 FAIL ("islower ('%c') not true", *cp
);
132 for (cp
= upper
; *cp
!= '\0'; ++cp
)
134 FAIL ("islower ('%c') is true", *cp
);
135 for (cp
= digits
; *cp
!= '\0'; ++cp
)
137 FAIL ("islower ('%c') is true", *cp
);
138 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
140 FAIL ("islower ('\\x%02x') is true", *cp
);
143 for (cp
= lower
; *cp
!= '\0'; ++cp
)
145 FAIL ("isupper ('%c') is true", *cp
);
146 for (cp
= upper
; *cp
!= '\0'; ++cp
)
148 FAIL ("isupper ('%c') not true", *cp
);
149 for (cp
= digits
; *cp
!= '\0'; ++cp
)
151 FAIL ("isupper ('%c') is true", *cp
);
152 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
154 FAIL ("isupper ('\\x%02x') is true", *cp
);
157 for (cp
= lower
; *cp
!= '\0'; ++cp
)
159 FAIL ("isalpha ('%c') not true", *cp
);
160 for (cp
= upper
; *cp
!= '\0'; ++cp
)
162 FAIL ("isalpha ('%c') not true", *cp
);
163 for (cp
= digits
; *cp
!= '\0'; ++cp
)
165 FAIL ("isalpha ('%c') is true", *cp
);
166 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
168 FAIL ("isalpha ('\\x%02x') is true", *cp
);
171 for (cp
= lower
; *cp
!= '\0'; ++cp
)
173 FAIL ("isdigit ('%c') is true", *cp
);
174 for (cp
= upper
; *cp
!= '\0'; ++cp
)
176 FAIL ("isdigit ('%c') is true", *cp
);
177 for (cp
= digits
; *cp
!= '\0'; ++cp
)
179 FAIL ("isdigit ('%c') not true", *cp
);
180 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
182 FAIL ("isdigit ('\\x%02x') is true", *cp
);
184 puts (" isxdigit()");
185 for (cp
= lower
; *cp
!= '\0'; ++cp
)
186 if ((! isxdigit (*cp
) && cp
- lower
< 6)
187 || (isxdigit (*cp
) && cp
- lower
>= 6))
188 FAIL ("isxdigit ('%c') %s true", *cp
, cp
- upper
< 6 ? "not" : "is");
189 for (cp
= upper
; *cp
!= '\0'; ++cp
)
190 if ((! isxdigit (*cp
) && cp
- upper
< 6)
191 || (isxdigit (*cp
) && cp
- upper
>= 6))
192 FAIL ("isxdigit ('%c') %s true", *cp
, cp
- upper
< 6 ? "not" : "is");
193 for (cp
= digits
; *cp
!= '\0'; ++cp
)
194 if (! isxdigit (*cp
))
195 FAIL ("isxdigit ('%c') not true", *cp
);
196 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
198 FAIL ("isxdigit ('\\x%02x') is true", *cp
);
201 for (cp
= lower
; *cp
!= '\0'; ++cp
)
203 FAIL ("isspace ('%c') is true", *cp
);
204 for (cp
= upper
; *cp
!= '\0'; ++cp
)
206 FAIL ("isspace ('%c') is true", *cp
);
207 for (cp
= digits
; *cp
!= '\0'; ++cp
)
209 FAIL ("isspace ('%c') is true", *cp
);
210 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
211 if ((isspace (*cp
) && ((*cp
< '\x09' || *cp
> '\x0d') && *cp
!= ' '))
213 && ((*cp
>= '\x09' && *cp
<= '\x0d') || *cp
== ' ')))
214 FAIL ("isspace ('\\x%02x') %s true", *cp
,
215 (*cp
< '\x09' || *cp
> '\x0d') ? "is" : "not");
218 for (cp
= lower
; *cp
!= '\0'; ++cp
)
220 FAIL ("isprint ('%c') not true", *cp
);
221 for (cp
= upper
; *cp
!= '\0'; ++cp
)
223 FAIL ("isprint ('%c') not true", *cp
);
224 for (cp
= digits
; *cp
!= '\0'; ++cp
)
226 FAIL ("isprint ('%c') not true", *cp
);
227 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
228 if ((isprint (*cp
) && *cp
!= ' ')
229 || (! isprint (*cp
) && *cp
== ' '))
230 FAIL ("isprint ('\\x%02x') is true", *cp
);
233 for (cp
= lower
; *cp
!= '\0'; ++cp
)
235 FAIL ("isgraph ('%c') not true", *cp
);
236 for (cp
= upper
; *cp
!= '\0'; ++cp
)
238 FAIL ("isgraph ('%c') not true", *cp
);
239 for (cp
= digits
; *cp
!= '\0'; ++cp
)
241 FAIL ("isgraph ('%c') not true", *cp
);
242 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
244 FAIL ("isgraph ('\\x%02x') is true", *cp
);
247 for (cp
= lower
; *cp
!= '\0'; ++cp
)
249 FAIL ("isblank ('%c') is true", *cp
);
250 for (cp
= upper
; *cp
!= '\0'; ++cp
)
252 FAIL ("isblank ('%c') is true", *cp
);
253 for (cp
= digits
; *cp
!= '\0'; ++cp
)
255 FAIL ("isblank ('%c') is true", *cp
);
256 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
257 if ((isblank (*cp
) && *cp
!= '\x09' && *cp
!= ' ')
258 || (! isblank (*cp
) && (*cp
== '\x09' || *cp
== ' ')))
259 FAIL ("isblank ('\\x%02x') %s true", *cp
, *cp
!= '\x09' ? "is" : "not");
262 for (cp
= lower
; *cp
!= '\0'; ++cp
)
264 FAIL ("iscntrl ('%c') is true", *cp
);
265 for (cp
= upper
; *cp
!= '\0'; ++cp
)
267 FAIL ("iscntrl ('%c') is true", *cp
);
268 for (cp
= digits
; *cp
!= '\0'; ++cp
)
270 FAIL ("iscntrl ('%c') is true", *cp
);
271 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
272 if ((iscntrl (*cp
) && *cp
== ' ')
273 || (! iscntrl (*cp
) && *cp
!= ' '))
274 FAIL ("iscntrl ('\\x%02x') not true", *cp
);
277 for (cp
= lower
; *cp
!= '\0'; ++cp
)
279 FAIL ("ispunct ('%c') is true", *cp
);
280 for (cp
= upper
; *cp
!= '\0'; ++cp
)
282 FAIL ("ispunct ('%c') is true", *cp
);
283 for (cp
= digits
; *cp
!= '\0'; ++cp
)
285 FAIL ("ispunct ('%c') is true", *cp
);
286 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
288 FAIL ("ispunct ('\\x%02x') is true", *cp
);
291 for (cp
= lower
; *cp
!= '\0'; ++cp
)
293 FAIL ("isalnum ('%c') not true", *cp
);
294 for (cp
= upper
; *cp
!= '\0'; ++cp
)
296 FAIL ("isalnum ('%c') not true", *cp
);
297 for (cp
= digits
; *cp
!= '\0'; ++cp
)
299 FAIL ("isalnum ('%c') not true", *cp
);
300 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
302 FAIL ("isalnum ('\\x%02x') is true", *cp
);
306 for (cp
= lower
; *cp
!= '\0'; ++cp
)
307 if (tolower (*cp
) != *cp
)
308 FAIL ("tolower ('%c') != '%c'", *cp
, *cp
);
309 for (cp
= upper
, cp2
= lower
; *cp
!= '\0'; ++cp
, ++cp2
)
310 if (tolower (*cp
) != *cp2
)
311 FAIL ("tolower ('%c') != '%c'", *cp
, *cp2
);
312 for (cp
= digits
; *cp
!= '\0'; ++cp
)
313 if (tolower (*cp
) != *cp
)
314 FAIL ("tolower ('%c') != '%c'", *cp
, *cp
);
315 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
316 if (tolower (*cp
) != *cp
)
317 FAIL ("tolower ('\\x%02x') != '\\x%02x'", *cp
, *cp
);
320 for (cp
= lower
, cp2
= upper
; *cp
!= '\0'; ++cp
, ++cp2
)
321 if (toupper (*cp
) != *cp2
)
322 FAIL ("toupper ('%c') != '%c'", *cp
, *cp2
);
323 for (cp
= upper
; *cp
!= '\0'; ++cp
)
324 if (toupper (*cp
) != *cp
)
325 FAIL ("toupper ('%c') != '%c'", *cp
, *cp
);
326 for (cp
= digits
; *cp
!= '\0'; ++cp
)
327 if (toupper (*cp
) != *cp
)
328 FAIL ("toupper ('%c') != '%c'", *cp
, *cp
);
329 for (cp
= cntrl
; *cp
!= '\0'; ++cp
)
330 if (toupper (*cp
) != *cp
)
331 FAIL ("toupper ('\\x%02x') != '\\x%02x'", *cp
, *cp
);
334 /* Now some locale specific tests. */
335 while (! feof (stdin
))
340 if (getline (&inpline
, &inplinelen
, stdin
) <= 0
341 || getline (&resline
, &reslinelen
, stdin
) <= 0)
344 inp
= (unsigned char *) strchr (inpline
, '\n');
347 resp
= (unsigned char *) strchr (resline
, '\n');
351 inp
= (unsigned char *) inpline
;
352 while (*inp
!= ' ' && *inp
!= '\t' && *inp
&& *inp
!= '\n'
358 printf ("line \"%s\" is without content\n", inpline
);
362 while (*inp
== ' ' || *inp
== '\t')
365 /* Try all classes. */
366 for (n
= 0; n
< nclasses
; ++n
)
367 if (strcmp (inpline
, classes
[n
].name
) == 0)
370 resp
= (unsigned char *) resline
;
371 while (*resp
== ' ' || *resp
== '\t')
374 if (strlen ((char *) inp
) != strlen ((char *) resp
))
376 printf ("lines \"%.20s\"... and \"%.20s\" have not the same length\n",
383 if (strspn ((char *) resp
, "01") != strlen ((char *) resp
))
385 printf ("result string \"%s\" malformed\n", resp
);
389 printf (" Locale-specific tests for `%s'\n", inpline
);
391 while (*inp
!= '\0' && *inp
!= '\n')
393 if (((__ctype_b
[(unsigned int) *inp
] & classes
[n
].mask
) != 0)
396 printf (" is%s('%c' = '\\x%02x') %s true\n", inpline
,
397 *inp
, *inp
, *resp
== '1' ? "not" : "is");
404 else if (strcmp (inpline
, "tolower") == 0)
408 if (tolower (*inp
) != *resp
)
410 printf (" tolower('%c' = '\\x%02x') != '%c'\n",
418 else if (strcmp (inpline
, "toupper") == 0)
422 if (toupper (*inp
) != *resp
)
424 printf (" toupper('%c' = '\\x%02x') != '%c'\n",
433 printf ("\"%s\": unknown class or map\n", inpline
);
439 printf (" %d error%s for `%s' locale\n\n\n", errors
,
440 errors
== 1 ? "" : "s", setlocale (LC_ALL
, NULL
));
444 printf (" No errors for `%s' locale\n\n\n", setlocale (LC_ALL
, NULL
));