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. */
26 static const char lower[] = "abcdefghijklmnopqrstuvwxyz";
27 static const char upper[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
28 static const char digits[] = "0123456789";
37 #define ENTRY(name) { #name, _IS##name }
51 #define nclasses (sizeof (classes) / sizeof (classes[0]))
54 #define FAIL(str, args...) \
56 printf (" " str "\n", ##args); \
68 size_t inplinelen = 0;
70 size_t reslinelen = 0;
73 setlocale (LC_ALL, "");
75 printf ("Testing the ctype data of the `%s' locale\n",
76 setlocale (LC_CTYPE, NULL));
79 /* Just for debugging. */
81 /* Contents of the class array. */
83 upper = %04x lower = %04x alpha = %04x digit = %04x xdigit = %04x\n\
84 space = %04x print = %04x graph = %04x blank = %04x cntrl = %04x\n\
85 punct = %04x alnum = %04x\n",
86 _ISupper, _ISlower, _ISalpha, _ISdigit, _ISxdigit,
87 _ISspace, _ISprint, _ISgraph, _ISblank, _IScntrl,
94 printf ("%04x%s", __ctype_b[n], (n + 1) % 8 == 0 ? "\n" : " ");
99 puts (" Test of ASCII character range\n special NUL byte handling");
101 FAIL ("isupper ('\\0') is true");
103 FAIL ("islower ('\\0') is true");
105 FAIL ("isalpha ('\\0') is true");
107 FAIL ("isdigit ('\\0') is true");
109 FAIL ("isxdigit ('\\0') is true");
111 FAIL ("isspace ('\\0') is true");
113 FAIL ("isprint ('\\0') is true");
115 FAIL ("isgraph ('\\0') is true");
117 FAIL ("isblank ('\\0') is true");
119 FAIL ("iscntrl ('\\0') is true");
121 FAIL ("ispunct ('\\0') is true");
123 FAIL ("isalnum ('\\0') is true");
126 for (cp = lower; *cp != '\0'; ++cp)
128 FAIL ("islower ('%c') not true", *cp);
129 for (cp = upper; *cp != '\0'; ++cp)
131 FAIL ("islower ('%c') is true", *cp);
132 for (cp = digits; *cp != '\0'; ++cp)
134 FAIL ("islower ('%c') is true", *cp);
137 for (cp = lower; *cp != '\0'; ++cp)
139 FAIL ("isupper ('%c') is true", *cp);
140 for (cp = upper; *cp != '\0'; ++cp)
142 FAIL ("isupper ('%c') not true", *cp);
143 for (cp = digits; *cp != '\0'; ++cp)
145 FAIL ("isupper ('%c') is true", *cp);
148 for (cp = lower; *cp != '\0'; ++cp)
150 FAIL ("isalpha ('%c') not true", *cp);
151 for (cp = upper; *cp != '\0'; ++cp)
153 FAIL ("isalpha ('%c') not true", *cp);
154 for (cp = digits; *cp != '\0'; ++cp)
156 FAIL ("isalpha ('%c') is true", *cp);
159 for (cp = lower; *cp != '\0'; ++cp)
161 FAIL ("isdigit ('%c') is true", *cp);
162 for (cp = upper; *cp != '\0'; ++cp)
164 FAIL ("isdigit ('%c') is true", *cp);
165 for (cp = digits; *cp != '\0'; ++cp)
167 FAIL ("isdigit ('%c') not true", *cp);
169 puts (" isxdigit()");
170 for (cp = lower; *cp != '\0'; ++cp)
171 if ((! isxdigit (*cp) && cp - lower < 6)
172 || (isxdigit (*cp) && cp - lower >= 6))
173 FAIL ("isxdigit ('%c') %s true", *cp, cp - upper < 6 ? "not" : "is");
174 for (cp = upper; *cp != '\0'; ++cp)
175 if ((! isxdigit (*cp) && cp - upper < 6)
176 || (isxdigit (*cp) && cp - upper >= 6))
177 FAIL ("isxdigit ('%c') %s true", *cp, cp - upper < 6 ? "not" : "is");
178 for (cp = digits; *cp != '\0'; ++cp)
179 if (! isxdigit (*cp))
180 FAIL ("isxdigit ('%c') not true", *cp);
183 for (cp = lower; *cp != '\0'; ++cp)
185 FAIL ("isspace ('%c') is true", *cp);
186 for (cp = upper; *cp != '\0'; ++cp)
188 FAIL ("isspace ('%c') is true", *cp);
189 for (cp = digits; *cp != '\0'; ++cp)
191 FAIL ("isspace ('%c') is true", *cp);
194 for (cp = lower; *cp != '\0'; ++cp)
196 FAIL ("isprint ('%c') not true", *cp);
197 for (cp = upper; *cp != '\0'; ++cp)
199 FAIL ("isprint ('%c') not true", *cp);
200 for (cp = digits; *cp != '\0'; ++cp)
202 FAIL ("isprint ('%c') not true", *cp);
205 for (cp = lower; *cp != '\0'; ++cp)
207 FAIL ("isgraph ('%c') not true", *cp);
208 for (cp = upper; *cp != '\0'; ++cp)
210 FAIL ("isgraph ('%c') not true", *cp);
211 for (cp = digits; *cp != '\0'; ++cp)
213 FAIL ("isgraph ('%c') not true", *cp);
216 for (cp = lower; *cp != '\0'; ++cp)
218 FAIL ("isblank ('%c') is true", *cp);
219 for (cp = upper; *cp != '\0'; ++cp)
221 FAIL ("isblank ('%c') is true", *cp);
222 for (cp = digits; *cp != '\0'; ++cp)
224 FAIL ("isblank ('%c') is true", *cp);
227 for (cp = lower; *cp != '\0'; ++cp)
229 FAIL ("iscntrl ('%c') is true", *cp);
230 for (cp = upper; *cp != '\0'; ++cp)
232 FAIL ("iscntrl ('%c') is true", *cp);
233 for (cp = digits; *cp != '\0'; ++cp)
235 FAIL ("iscntrl ('%c') is true", *cp);
238 for (cp = lower; *cp != '\0'; ++cp)
240 FAIL ("ispunct ('%c') is true", *cp);
241 for (cp = upper; *cp != '\0'; ++cp)
243 FAIL ("ispunct ('%c') is true", *cp);
244 for (cp = digits; *cp != '\0'; ++cp)
246 FAIL ("ispunct ('%c') is true", *cp);
249 for (cp = lower; *cp != '\0'; ++cp)
251 FAIL ("isalnum ('%c') not true", *cp);
252 for (cp = upper; *cp != '\0'; ++cp)
254 FAIL ("isalnum ('%c') not true", *cp);
255 for (cp = digits; *cp != '\0'; ++cp)
257 FAIL ("isalnum ('%c') not true", *cp);
261 for (cp = lower; *cp != '\0'; ++cp)
262 if (tolower (*cp) != *cp)
263 FAIL ("tolower ('%c') != '%c'", *cp, *cp);
264 for (cp = upper, cp2 = lower; *cp != '\0'; ++cp, ++cp2)
265 if (tolower (*cp) != *cp2)
266 FAIL ("tolower ('%c') != '%c'", *cp, *cp2);
267 for (cp = digits; *cp != '\0'; ++cp)
268 if (tolower (*cp) != *cp)
269 FAIL ("tolower ('%c') != '%c'", *cp, *cp);
272 for (cp = lower, cp2 = upper; *cp != '\0'; ++cp, ++cp2)
273 if (toupper (*cp) != *cp2)
274 FAIL ("toupper ('%c') != '%c'", *cp, *cp2);
275 for (cp = upper; *cp != '\0'; ++cp)
276 if (toupper (*cp) != *cp)
277 FAIL ("toupper ('%c') != '%c'", *cp, *cp);
278 for (cp = digits; *cp != '\0'; ++cp)
279 if (toupper (*cp) != *cp)
280 FAIL ("toupper ('%c') != '%c'", *cp, *cp);
283 /* Now some locale specific tests. */
284 while (! feof (stdin))
289 if (getline (&inpline, &inplinelen, stdin) <= 0
290 || getline (&resline, &reslinelen, stdin) <= 0)
293 inp = strchr (inpline, '\n');
296 resp = strchr (resline, '\n');
301 while (*inp != ' ' && *inp != '\t' && *inp && *inp != '\n'
307 printf ("line \"%s\" is without content\n", inpline);
311 while (*inp == ' ' || *inp == '\t')
314 /* Try all classes. */
315 for (n = 0; n < nclasses; ++n)
316 if (strcmp (inpline, classes[n].name) == 0)
320 while (*resp == ' ' || *resp == '\t')
323 if (strlen (inp) != strlen (resp))
325 printf ("lines \"%.20s\"... and \"%.20s\" have not the same length\n",
332 if (strspn (resp, "01") != strlen (resp))
334 printf ("result string \"%s\" malformed\n", resp);
338 printf (" Locale-specific tests for `%s'\n", inpline);
340 while (*inp != '\0' && *inp != '\n')
342 if (((__ctype_b[(unsigned int) *inp] & classes[n].mask) != 0)
345 printf (" is%s('%c' = '\\x%02x') %s true\n", inpline,
346 *inp, *inp, *resp == '1' ? "not" : "is");
353 else if (strcmp (inpline, "tolower") == 0)
357 if (tolower (*inp) != *resp)
359 printf (" tolower('%c' = '\\x%02x') != '%c'\n",
367 else if (strcmp (inpline, "toupper") == 0)
371 if (toupper (*inp) != *resp)
373 printf (" toupper('%c' = '\\x%02x') != '%c'\n",
382 printf ("\"%s\": unknown class or map\n", inpline);
388 printf (" %d error%s for `%s' locale\n\n\n", errors,
389 errors == 1 ? "" : "s", setlocale (LC_ALL, NULL));
393 printf (" No errors for `%s' locale\n\n\n", setlocale (LC_ALL, NULL));