This source file includes following definitions.
- test_agree_with_C_locale
- test_all
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include "c-ctype.h"
22
23 #include <ctype.h>
24 #include <limits.h>
25 #include <locale.h>
26
27 #include "macros.h"
28
29 static void
30 test_agree_with_C_locale (void)
31 {
32 int c;
33
34 for (c = 0; c <= UCHAR_MAX; c++)
35 {
36 ASSERT (c_isascii (c) == (isascii (c) != 0));
37 if (c_isascii (c))
38 {
39 ASSERT (c_isalnum (c) == (isalnum (c) != 0));
40 ASSERT (c_isalpha (c) == (isalpha (c) != 0));
41 ASSERT (c_isblank (c) == (isblank (c) != 0));
42 ASSERT (c_iscntrl (c) == (iscntrl (c) != 0));
43 ASSERT (c_isdigit (c) == (isdigit (c) != 0));
44 ASSERT (c_islower (c) == (islower (c) != 0));
45 ASSERT (c_isgraph (c) == (isgraph (c) != 0));
46 ASSERT (c_isprint (c) == (isprint (c) != 0));
47 ASSERT (c_ispunct (c) == (ispunct (c) != 0));
48 ASSERT (c_isspace (c) == (isspace (c) != 0));
49 ASSERT (c_isupper (c) == (isupper (c) != 0));
50 ASSERT (c_isxdigit (c) == (isxdigit (c) != 0));
51 ASSERT (c_tolower (c) == tolower (c));
52 ASSERT (c_toupper (c) == toupper (c));
53 }
54 }
55 }
56
57 static void
58 test_all (void)
59 {
60 int c;
61 int n_isascii = 0;
62
63 for (c = CHAR_MIN; c <= UCHAR_MAX; c++)
64 {
65 if (! (0 <= c && c <= CHAR_MAX))
66 {
67 ASSERT (! c_isascii (c));
68 ASSERT (! c_isalnum (c));
69 ASSERT (! c_isalpha (c));
70 ASSERT (! c_isblank (c));
71 ASSERT (! c_iscntrl (c));
72 ASSERT (! c_isdigit (c));
73 ASSERT (! c_islower (c));
74 ASSERT (! c_isgraph (c));
75 ASSERT (! c_isprint (c));
76 ASSERT (! c_ispunct (c));
77 ASSERT (! c_isspace (c));
78 ASSERT (! c_isupper (c));
79 ASSERT (! c_isxdigit (c));
80 ASSERT (c_tolower (c) == c);
81 ASSERT (c_toupper (c) == c);
82 }
83
84 n_isascii += c_isascii (c);
85
86 #ifdef C_CTYPE_ASCII
87 ASSERT (c_isascii (c) == (0 <= c && c <= 0x7f));
88 #endif
89
90 ASSERT (c_isascii (c) == (c_isprint (c) || c_iscntrl (c)));
91
92 ASSERT (c_isalnum (c) == (c_isalpha (c) || c_isdigit (c)));
93
94 ASSERT (c_isalpha (c) == (c_islower (c) || c_isupper (c)));
95
96 switch (c)
97 {
98 case '\t': case ' ':
99 ASSERT (c_isblank (c) == 1);
100 break;
101 default:
102 ASSERT (c_isblank (c) == 0);
103 break;
104 }
105
106 #ifdef C_CTYPE_ASCII
107 ASSERT (c_iscntrl (c) == ((c >= 0 && c < 0x20) || c == 0x7f));
108 #endif
109
110 switch (c)
111 {
112 case '\a': case '\b': case '\f': case '\n':
113 case '\r': case '\t': case '\v':
114 ASSERT (c_iscntrl (c));
115 break;
116 }
117
118 ASSERT (! (c_iscntrl (c) && c_isprint (c)));
119
120 switch (c)
121 {
122 case '0': case '1': case '2': case '3': case '4': case '5':
123 case '6': case '7': case '8': case '9':
124 ASSERT (c_isdigit (c) == 1);
125 break;
126 default:
127 ASSERT (c_isdigit (c) == 0);
128 break;
129 }
130
131 switch (c)
132 {
133 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
134 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
135 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
136 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
137 case 'y': case 'z':
138 ASSERT (c_islower (c) == 1);
139 ASSERT (c_toupper (c) == c - 'a' + 'A');
140 break;
141 default:
142 ASSERT (c_islower (c) == 0);
143 ASSERT (c_toupper (c) == c);
144 break;
145 }
146
147 #ifdef C_CTYPE_ASCII
148 ASSERT (c_isgraph (c) == ((c >= 0x20 && c < 0x7f) && c != ' '));
149
150 ASSERT (c_isprint (c) == (c >= 0x20 && c < 0x7f));
151 #endif
152
153 ASSERT (c_isgraph (c) == (c_isalnum (c) || c_ispunct (c)));
154
155 ASSERT (c_isprint (c) == (c_isgraph (c) || c == ' '));
156
157 switch (c)
158 {
159 case '!': case '"': case '#': case '$': case '%': case '&': case '\'':
160 case '(': case ')': case '*': case '+': case ',': case '-': case '.':
161 case '/': case ':': case ';': case '<': case '=': case '>': case '?':
162 case '@': case '[': case'\\': case ']': case '^': case '_': case '`':
163 case '{': case '|': case '}': case '~':
164 ASSERT (c_ispunct (c) == 1);
165 break;
166 default:
167 ASSERT (c_ispunct (c) == 0);
168 break;
169 }
170
171 switch (c)
172 {
173 case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
174 ASSERT (c_isspace (c) == 1);
175 break;
176 default:
177 ASSERT (c_isspace (c) == 0);
178 break;
179 }
180
181 switch (c)
182 {
183 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
184 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
185 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
186 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
187 case 'Y': case 'Z':
188 ASSERT (c_isupper (c) == 1);
189 ASSERT (c_tolower (c) == c - 'A' + 'a');
190 break;
191 default:
192 ASSERT (c_isupper (c) == 0);
193 ASSERT (c_tolower (c) == c);
194 break;
195 }
196
197 switch (c)
198 {
199 case '0': case '1': case '2': case '3': case '4': case '5':
200 case '6': case '7': case '8': case '9':
201 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
202 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
203 ASSERT (c_isxdigit (c) == 1);
204 break;
205 default:
206 ASSERT (c_isxdigit (c) == 0);
207 break;
208 }
209 }
210
211 ASSERT (n_isascii == 128);
212 }
213
214 int
215 main ()
216 {
217 test_agree_with_C_locale ();
218
219 test_all ();
220
221 setlocale (LC_ALL, "de_DE");
222 test_all ();
223
224 setlocale (LC_ALL, "ja_JP.EUC-JP");
225 test_all ();
226
227 return 0;
228 }