usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-c32isalnum.c
blobd5f8dcf5d209ae0c54870e40e680427872ae6fc2
1 /* Test of c32isalnum() function.
2 Copyright (C) 2020-2024 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 #include <config.h>
19 #include <uchar.h>
21 #include "signature.h"
22 SIGNATURE_CHECK (c32isalnum, int, (wint_t));
24 #include <locale.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <wchar.h>
29 #include "macros.h"
31 /* Returns the value of c32isalnum for the multibyte character s[0..n-1]. */
32 static int
33 for_character (const char *s, size_t n)
35 mbstate_t state;
36 char32_t wc;
37 size_t ret;
39 memset (&state, '\0', sizeof (mbstate_t));
40 wc = (char32_t) 0xBADFACE;
41 ret = mbrtoc32 (&wc, s, n, &state);
42 ASSERT (ret == n);
44 return c32isalnum (wc);
47 int
48 main (int argc, char *argv[])
50 int is;
51 char buf[4];
53 /* configure should already have checked that the locale is supported. */
54 if (setlocale (LC_ALL, "") == NULL)
55 return 1;
57 /* Test WEOF. */
58 is = c32isalnum (WEOF);
59 ASSERT (is == 0);
61 /* Test single-byte characters.
62 POSIX specifies in
63 <https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html>
64 that
65 - in all locales, the alphanumeric characters include the uppercase and
66 lowercase characters and digits and, consequently, include the A ... Z
67 and a ... z and 0 ... 9 characters.
68 - in the "POSIX" locale (which is usually the same as the "C" locale),
69 the alphanumeric characters include only the ASCII A ... Z and a ... z
70 and 0 ... 9 characters. */
72 int c;
74 for (c = 0; c < 0x100; c++)
75 switch (c)
77 case '\t': case '\v': case '\f':
78 case ' ': case '!': case '"': case '#': case '%':
79 case '&': case '\'': case '(': case ')': case '*':
80 case '+': case ',': case '-': case '.': case '/':
81 case '0': case '1': case '2': case '3': case '4':
82 case '5': case '6': case '7': case '8': case '9':
83 case ':': case ';': case '<': case '=': case '>':
84 case '?':
85 case 'A': case 'B': case 'C': case 'D': case 'E':
86 case 'F': case 'G': case 'H': case 'I': case 'J':
87 case 'K': case 'L': case 'M': case 'N': case 'O':
88 case 'P': case 'Q': case 'R': case 'S': case 'T':
89 case 'U': case 'V': case 'W': case 'X': case 'Y':
90 case 'Z':
91 case '[': case '\\': case ']': case '^': case '_':
92 case 'a': case 'b': case 'c': case 'd': case 'e':
93 case 'f': case 'g': case 'h': case 'i': case 'j':
94 case 'k': case 'l': case 'm': case 'n': case 'o':
95 case 'p': case 'q': case 'r': case 's': case 't':
96 case 'u': case 'v': case 'w': case 'x': case 'y':
97 case 'z': case '{': case '|': case '}': case '~':
98 /* c is in the ISO C "basic character set". */
99 buf[0] = (unsigned char) c;
100 is = for_character (buf, 1);
101 switch (c)
103 case '0': case '1': case '2': case '3': case '4':
104 case '5': case '6': case '7': case '8': case '9':
105 case 'A': case 'B': case 'C': case 'D': case 'E':
106 case 'F': case 'G': case 'H': case 'I': case 'J':
107 case 'K': case 'L': case 'M': case 'N': case 'O':
108 case 'P': case 'Q': case 'R': case 'S': case 'T':
109 case 'U': case 'V': case 'W': case 'X': case 'Y':
110 case 'Z':
111 case 'a': case 'b': case 'c': case 'd': case 'e':
112 case 'f': case 'g': case 'h': case 'i': case 'j':
113 case 'k': case 'l': case 'm': case 'n': case 'o':
114 case 'p': case 'q': case 'r': case 's': case 't':
115 case 'u': case 'v': case 'w': case 'x': case 'y':
116 case 'z':
117 ASSERT (is != 0);
118 break;
119 default:
120 ASSERT (is == 0);
121 break;
123 break;
127 if (argc > 1)
128 switch (argv[1][0])
130 case '0':
131 /* C locale; tested above. */
132 return test_exit_status;
134 case '1':
135 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
137 /* U+00D7 MULTIPLICATION SIGN */
138 is = for_character ("\327", 1);
139 ASSERT (is == 0);
140 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
141 is = for_character ("\330", 1);
142 ASSERT (is != 0);
144 return test_exit_status;
146 case '2':
147 /* Locale encoding is EUC-JP. */
149 /* U+00D7 MULTIPLICATION SIGN */
150 is = for_character ("\241\337", 2);
151 ASSERT (is == 0);
152 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__)
153 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
154 is = for_character ("\217\251\254", 3);
155 ASSERT (is != 0);
156 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
157 is = for_character ("\217\251\250", 3);
158 ASSERT (is != 0);
159 #endif
160 /* U+3001 IDEOGRAPHIC COMMA */
161 is = for_character ("\241\242", 2);
162 ASSERT (is == 0);
163 #if defined __GLIBC__
164 /* U+FF11 FULLWIDTH DIGIT ONE */
165 is = for_character ("\243\261", 2);
166 ASSERT (is != 0);
167 #endif
168 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__)
169 /* U+FF4D FULLWIDTH LATIN SMALL LETTER M */
170 is = for_character ("\243\355", 2);
171 ASSERT (is != 0);
172 #endif
174 return test_exit_status;
176 case '3':
177 /* Locale encoding is UTF-8. */
179 /* U+00D7 MULTIPLICATION SIGN */
180 is = for_character ("\303\227", 2);
181 ASSERT (is == 0);
182 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
183 is = for_character ("\303\230", 2);
184 ASSERT (is != 0);
185 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
186 is = for_character ("\305\201", 2);
187 ASSERT (is != 0);
188 /* U+3001 IDEOGRAPHIC COMMA */
189 is = for_character ("\343\200\201", 3);
190 ASSERT (is == 0);
191 #if defined __GLIBC__
192 /* U+FF11 FULLWIDTH DIGIT ONE */
193 is = for_character ("\357\274\221", 3);
194 ASSERT (is != 0);
195 #endif
196 /* U+FF4D FULLWIDTH LATIN SMALL LETTER M */
197 is = for_character ("\357\275\215", 3);
198 ASSERT (is != 0);
199 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sun)
200 /* U+10330 GOTHIC LETTER AHSA */
201 is = for_character ("\360\220\214\260", 4);
202 ASSERT (is != 0);
203 #endif
204 /* U+1D100 MUSICAL SYMBOL SINGLE BARLINE */
205 is = for_character ("\360\235\204\200", 4);
206 ASSERT (is == 0);
207 /* U+E0061 TAG LATIN SMALL LETTER A */
208 is = for_character ("\363\240\201\241", 4);
209 ASSERT (is == 0);
211 return test_exit_status;
213 case '4':
214 /* Locale encoding is GB18030. */
215 #if (defined __GLIBC__ && __GLIBC__ == 2 && __GLIBC_MINOR__ >= 13 && __GLIBC_MINOR__ <= 15) || (GL_CHAR32_T_IS_UNICODE && (defined __FreeBSD__ || defined __NetBSD__ || defined __sun))
216 if (test_exit_status != EXIT_SUCCESS)
217 return test_exit_status;
218 fputs ("Skipping test: The GB18030 converter in this system's iconv is broken.\n", stderr);
219 return 77;
220 #endif
222 /* U+00D7 MULTIPLICATION SIGN */
223 is = for_character ("\241\301", 2);
224 ASSERT (is == 0);
225 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
226 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
227 is = for_character ("\201\060\211\061", 4);
228 ASSERT (is != 0);
229 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
230 is = for_character ("\201\060\221\071", 4);
231 ASSERT (is != 0);
232 #endif
233 /* U+3001 IDEOGRAPHIC COMMA */
234 is = for_character ("\241\242", 2);
235 ASSERT (is == 0);
236 #if defined __GLIBC__
237 /* U+FF11 FULLWIDTH DIGIT ONE */
238 is = for_character ("\243\261", 2);
239 ASSERT (is != 0);
240 #endif
241 #if !defined __DragonFly__
242 /* U+FF4D FULLWIDTH LATIN SMALL LETTER M */
243 is = for_character ("\243\355", 2);
244 ASSERT (is != 0);
245 #endif
246 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sun)
247 /* U+10330 GOTHIC LETTER AHSA */
248 is = for_character ("\220\060\322\066", 4);
249 ASSERT (is != 0);
250 #endif
251 /* U+1D100 MUSICAL SYMBOL SINGLE BARLINE */
252 is = for_character ("\224\062\273\064", 4);
253 ASSERT (is == 0);
254 /* U+E0061 TAG LATIN SMALL LETTER A */
255 is = for_character ("\323\066\237\065", 4);
256 ASSERT (is == 0);
258 return test_exit_status;
262 return 1;