1 /* Test of character handling in C locale.
2 Copyright (C) 2005, 2007-2020 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 <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2005. */
30 test_agree_with_C_locale (void)
34 for (c
= 0; c
<= UCHAR_MAX
; c
++)
36 ASSERT (c_isascii (c
) == (isascii (c
) != 0));
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
));
63 for (c
= CHAR_MIN
; c
<= UCHAR_MAX
; c
++)
65 if (! (0 <= c
&& c
<= CHAR_MAX
))
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
);
84 n_isascii
+= c_isascii (c
);
87 ASSERT (c_isascii (c
) == (0 <= c
&& c
<= 0x7f));
90 ASSERT (c_isascii (c
) == (c_isprint (c
) || c_iscntrl (c
)));
92 ASSERT (c_isalnum (c
) == (c_isalpha (c
) || c_isdigit (c
)));
94 ASSERT (c_isalpha (c
) == (c_islower (c
) || c_isupper (c
)));
99 ASSERT (c_isblank (c
) == 1);
102 ASSERT (c_isblank (c
) == 0);
107 ASSERT (c_iscntrl (c
) == ((c
>= 0 && c
< 0x20) || c
== 0x7f));
112 case '\a': case '\b': case '\f': case '\n':
113 case '\r': case '\t': case '\v':
114 ASSERT (c_iscntrl (c
));
118 ASSERT (! (c_iscntrl (c
) && c_isprint (c
)));
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);
127 ASSERT (c_isdigit (c
) == 0);
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':
138 ASSERT (c_islower (c
) == 1);
139 ASSERT (c_toupper (c
) == c
- 'a' + 'A');
142 ASSERT (c_islower (c
) == 0);
143 ASSERT (c_toupper (c
) == c
);
148 ASSERT (c_isgraph (c
) == ((c
>= 0x20 && c
< 0x7f) && c
!= ' '));
150 ASSERT (c_isprint (c
) == (c
>= 0x20 && c
< 0x7f));
153 ASSERT (c_isgraph (c
) == (c_isalnum (c
) || c_ispunct (c
)));
155 ASSERT (c_isprint (c
) == (c_isgraph (c
) || c
== ' '));
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);
167 ASSERT (c_ispunct (c
) == 0);
173 case ' ': case '\t': case '\n': case '\v': case '\f': case '\r':
174 ASSERT (c_isspace (c
) == 1);
177 ASSERT (c_isspace (c
) == 0);
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':
188 ASSERT (c_isupper (c
) == 1);
189 ASSERT (c_tolower (c
) == c
- 'A' + 'a');
192 ASSERT (c_isupper (c
) == 0);
193 ASSERT (c_tolower (c
) == c
);
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);
206 ASSERT (c_isxdigit (c
) == 0);
211 ASSERT (n_isascii
== 128);
217 test_agree_with_C_locale ();
221 setlocale (LC_ALL
, "de_DE");
224 setlocale (LC_ALL
, "ja_JP.EUC-JP");