reduced verbosity and better debugging.
[gnutls.git] / gl / tests / test-c-ctype.c
bloba9cb655266d1c25660ce57d34d18639e08341df9
1 /* Test of character handling in C locale.
2 Copyright (C) 2005, 2007-2012 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005. */
19 #include <config.h>
21 #include "c-ctype.h"
23 #include <locale.h>
25 #include "macros.h"
27 static void
28 test_all (void)
30 int c;
32 for (c = -0x80; c < 0x100; c++)
34 ASSERT (c_isascii (c) == (c >= 0 && c < 0x80));
36 switch (c)
38 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
39 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
40 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
41 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
42 case 'Y': case 'Z':
43 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
44 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
45 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
46 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
47 case 'y': case 'z':
48 case '0': case '1': case '2': case '3': case '4': case '5':
49 case '6': case '7': case '8': case '9':
50 ASSERT (c_isalnum (c) == 1);
51 break;
52 default:
53 ASSERT (c_isalnum (c) == 0);
54 break;
57 switch (c)
59 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
60 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
61 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
62 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
63 case 'Y': case 'Z':
64 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
65 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
66 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
67 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
68 case 'y': case 'z':
69 ASSERT (c_isalpha (c) == 1);
70 break;
71 default:
72 ASSERT (c_isalpha (c) == 0);
73 break;
76 switch (c)
78 case '\t': case ' ':
79 ASSERT (c_isblank (c) == 1);
80 break;
81 default:
82 ASSERT (c_isblank (c) == 0);
83 break;
86 ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f));
88 switch (c)
90 case '0': case '1': case '2': case '3': case '4': case '5':
91 case '6': case '7': case '8': case '9':
92 ASSERT (c_isdigit (c) == 1);
93 break;
94 default:
95 ASSERT (c_isdigit (c) == 0);
96 break;
99 switch (c)
101 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
102 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
103 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
104 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
105 case 'y': case 'z':
106 ASSERT (c_islower (c) == 1);
107 break;
108 default:
109 ASSERT (c_islower (c) == 0);
110 break;
113 ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' '));
115 ASSERT (c_isprint (c) == (c >= 0x20 && c < 0x7f));
117 ASSERT (c_ispunct (c) == (c_isgraph (c) && !c_isalnum (c)));
119 switch (c)
121 case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
122 ASSERT (c_isspace (c) == 1);
123 break;
124 default:
125 ASSERT (c_isspace (c) == 0);
126 break;
129 switch (c)
131 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
132 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
133 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
134 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
135 case 'Y': case 'Z':
136 ASSERT (c_isupper (c) == 1);
137 break;
138 default:
139 ASSERT (c_isupper (c) == 0);
140 break;
143 switch (c)
145 case '0': case '1': case '2': case '3': case '4': case '5':
146 case '6': case '7': case '8': case '9':
147 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
148 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
149 ASSERT (c_isxdigit (c) == 1);
150 break;
151 default:
152 ASSERT (c_isxdigit (c) == 0);
153 break;
156 switch (c)
158 case 'A':
159 ASSERT (c_tolower (c) == 'a');
160 ASSERT (c_toupper (c) == c);
161 break;
162 case 'B':
163 ASSERT (c_tolower (c) == 'b');
164 ASSERT (c_toupper (c) == c);
165 break;
166 case 'C':
167 ASSERT (c_tolower (c) == 'c');
168 ASSERT (c_toupper (c) == c);
169 break;
170 case 'D':
171 ASSERT (c_tolower (c) == 'd');
172 ASSERT (c_toupper (c) == c);
173 break;
174 case 'E':
175 ASSERT (c_tolower (c) == 'e');
176 ASSERT (c_toupper (c) == c);
177 break;
178 case 'F':
179 ASSERT (c_tolower (c) == 'f');
180 ASSERT (c_toupper (c) == c);
181 break;
182 case 'G':
183 ASSERT (c_tolower (c) == 'g');
184 ASSERT (c_toupper (c) == c);
185 break;
186 case 'H':
187 ASSERT (c_tolower (c) == 'h');
188 ASSERT (c_toupper (c) == c);
189 break;
190 case 'I':
191 ASSERT (c_tolower (c) == 'i');
192 ASSERT (c_toupper (c) == c);
193 break;
194 case 'J':
195 ASSERT (c_tolower (c) == 'j');
196 ASSERT (c_toupper (c) == c);
197 break;
198 case 'K':
199 ASSERT (c_tolower (c) == 'k');
200 ASSERT (c_toupper (c) == c);
201 break;
202 case 'L':
203 ASSERT (c_tolower (c) == 'l');
204 ASSERT (c_toupper (c) == c);
205 break;
206 case 'M':
207 ASSERT (c_tolower (c) == 'm');
208 ASSERT (c_toupper (c) == c);
209 break;
210 case 'N':
211 ASSERT (c_tolower (c) == 'n');
212 ASSERT (c_toupper (c) == c);
213 break;
214 case 'O':
215 ASSERT (c_tolower (c) == 'o');
216 ASSERT (c_toupper (c) == c);
217 break;
218 case 'P':
219 ASSERT (c_tolower (c) == 'p');
220 ASSERT (c_toupper (c) == c);
221 break;
222 case 'Q':
223 ASSERT (c_tolower (c) == 'q');
224 ASSERT (c_toupper (c) == c);
225 break;
226 case 'R':
227 ASSERT (c_tolower (c) == 'r');
228 ASSERT (c_toupper (c) == c);
229 break;
230 case 'S':
231 ASSERT (c_tolower (c) == 's');
232 ASSERT (c_toupper (c) == c);
233 break;
234 case 'T':
235 ASSERT (c_tolower (c) == 't');
236 ASSERT (c_toupper (c) == c);
237 break;
238 case 'U':
239 ASSERT (c_tolower (c) == 'u');
240 ASSERT (c_toupper (c) == c);
241 break;
242 case 'V':
243 ASSERT (c_tolower (c) == 'v');
244 ASSERT (c_toupper (c) == c);
245 break;
246 case 'W':
247 ASSERT (c_tolower (c) == 'w');
248 ASSERT (c_toupper (c) == c);
249 break;
250 case 'X':
251 ASSERT (c_tolower (c) == 'x');
252 ASSERT (c_toupper (c) == c);
253 break;
254 case 'Y':
255 ASSERT (c_tolower (c) == 'y');
256 ASSERT (c_toupper (c) == c);
257 break;
258 case 'Z':
259 ASSERT (c_tolower (c) == 'z');
260 ASSERT (c_toupper (c) == c);
261 break;
262 case 'a':
263 ASSERT (c_tolower (c) == c);
264 ASSERT (c_toupper (c) == 'A');
265 break;
266 case 'b':
267 ASSERT (c_tolower (c) == c);
268 ASSERT (c_toupper (c) == 'B');
269 break;
270 case 'c':
271 ASSERT (c_tolower (c) == c);
272 ASSERT (c_toupper (c) == 'C');
273 break;
274 case 'd':
275 ASSERT (c_tolower (c) == c);
276 ASSERT (c_toupper (c) == 'D');
277 break;
278 case 'e':
279 ASSERT (c_tolower (c) == c);
280 ASSERT (c_toupper (c) == 'E');
281 break;
282 case 'f':
283 ASSERT (c_tolower (c) == c);
284 ASSERT (c_toupper (c) == 'F');
285 break;
286 case 'g':
287 ASSERT (c_tolower (c) == c);
288 ASSERT (c_toupper (c) == 'G');
289 break;
290 case 'h':
291 ASSERT (c_tolower (c) == c);
292 ASSERT (c_toupper (c) == 'H');
293 break;
294 case 'i':
295 ASSERT (c_tolower (c) == c);
296 ASSERT (c_toupper (c) == 'I');
297 break;
298 case 'j':
299 ASSERT (c_tolower (c) == c);
300 ASSERT (c_toupper (c) == 'J');
301 break;
302 case 'k':
303 ASSERT (c_tolower (c) == c);
304 ASSERT (c_toupper (c) == 'K');
305 break;
306 case 'l':
307 ASSERT (c_tolower (c) == c);
308 ASSERT (c_toupper (c) == 'L');
309 break;
310 case 'm':
311 ASSERT (c_tolower (c) == c);
312 ASSERT (c_toupper (c) == 'M');
313 break;
314 case 'n':
315 ASSERT (c_tolower (c) == c);
316 ASSERT (c_toupper (c) == 'N');
317 break;
318 case 'o':
319 ASSERT (c_tolower (c) == c);
320 ASSERT (c_toupper (c) == 'O');
321 break;
322 case 'p':
323 ASSERT (c_tolower (c) == c);
324 ASSERT (c_toupper (c) == 'P');
325 break;
326 case 'q':
327 ASSERT (c_tolower (c) == c);
328 ASSERT (c_toupper (c) == 'Q');
329 break;
330 case 'r':
331 ASSERT (c_tolower (c) == c);
332 ASSERT (c_toupper (c) == 'R');
333 break;
334 case 's':
335 ASSERT (c_tolower (c) == c);
336 ASSERT (c_toupper (c) == 'S');
337 break;
338 case 't':
339 ASSERT (c_tolower (c) == c);
340 ASSERT (c_toupper (c) == 'T');
341 break;
342 case 'u':
343 ASSERT (c_tolower (c) == c);
344 ASSERT (c_toupper (c) == 'U');
345 break;
346 case 'v':
347 ASSERT (c_tolower (c) == c);
348 ASSERT (c_toupper (c) == 'V');
349 break;
350 case 'w':
351 ASSERT (c_tolower (c) == c);
352 ASSERT (c_toupper (c) == 'W');
353 break;
354 case 'x':
355 ASSERT (c_tolower (c) == c);
356 ASSERT (c_toupper (c) == 'X');
357 break;
358 case 'y':
359 ASSERT (c_tolower (c) == c);
360 ASSERT (c_toupper (c) == 'Y');
361 break;
362 case 'z':
363 ASSERT (c_tolower (c) == c);
364 ASSERT (c_toupper (c) == 'Z');
365 break;
366 default:
367 ASSERT (c_tolower (c) == c);
368 ASSERT (c_toupper (c) == c);
369 break;
375 main ()
377 test_all ();
379 setlocale (LC_ALL, "de_DE");
380 test_all ();
382 setlocale (LC_ALL, "ja_JP.EUC-JP");
383 test_all ();
385 return 0;