test-framework-sh: Don't leave temporary directories on NetBSD.
[gnulib.git] / tests / test-c32ispunct.c
blobee21852601e59df9f78a21122978865cd6b85d69
1 /* Test of c32ispunct() 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 (c32ispunct, 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 c32ispunct 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 c32ispunct (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 = c32ispunct (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 no explicit list of punctuation or symbol characters. */
66 int c;
68 for (c = 0; c < 0x100; c++)
69 switch (c)
71 case '\t': case '\v': case '\f':
72 case ' ': case '!': case '"': case '#': case '%':
73 case '&': case '\'': case '(': case ')': case '*':
74 case '+': case ',': case '-': case '.': case '/':
75 case '0': case '1': case '2': case '3': case '4':
76 case '5': case '6': case '7': case '8': case '9':
77 case ':': case ';': case '<': case '=': case '>':
78 case '?':
79 case 'A': case 'B': case 'C': case 'D': case 'E':
80 case 'F': case 'G': case 'H': case 'I': case 'J':
81 case 'K': case 'L': case 'M': case 'N': case 'O':
82 case 'P': case 'Q': case 'R': case 'S': case 'T':
83 case 'U': case 'V': case 'W': case 'X': case 'Y':
84 case 'Z':
85 case '[': case '\\': case ']': case '^': case '_':
86 case 'a': case 'b': case 'c': case 'd': case 'e':
87 case 'f': case 'g': case 'h': case 'i': case 'j':
88 case 'k': case 'l': case 'm': case 'n': case 'o':
89 case 'p': case 'q': case 'r': case 's': case 't':
90 case 'u': case 'v': case 'w': case 'x': case 'y':
91 case 'z': case '{': case '|': case '}': case '~':
92 /* c is in the ISO C "basic character set". */
93 buf[0] = (unsigned char) c;
94 is = for_character (buf, 1);
95 switch (c)
97 case ' ':
98 case '0': case '1': case '2': case '3': case '4':
99 case '5': case '6': case '7': case '8': case '9':
100 case 'A': case 'B': case 'C': case 'D': case 'E':
101 case 'F': case 'G': case 'H': case 'I': case 'J':
102 case 'K': case 'L': case 'M': case 'N': case 'O':
103 case 'P': case 'Q': case 'R': case 'S': case 'T':
104 case 'U': case 'V': case 'W': case 'X': case 'Y':
105 case 'Z':
106 case 'a': case 'b': case 'c': case 'd': case 'e':
107 case 'f': case 'g': case 'h': case 'i': case 'j':
108 case 'k': case 'l': case 'm': case 'n': case 'o':
109 case 'p': case 'q': case 'r': case 's': case 't':
110 case 'u': case 'v': case 'w': case 'x': case 'y':
111 case 'z':
112 /* c is an alphanumeric or space character. */
113 ASSERT (is == 0);
114 break;
115 case '!': case '"': case '#': case '%':
116 case '&': case '\'': case '(': case ')': case '*':
117 case '+': case ',': case '-': case '.': case '/':
118 case ':': case ';': case '<': case '=': case '>':
119 case '?':
120 case '[': case '\\': case ']': case '^': case '_':
121 case '{': case '|': case '}': case '~':
122 /* These characters are usually expected to be punctuation or
123 symbol characters. */
124 ASSERT (is != 0);
125 break;
126 default:
127 ASSERT (is == 0);
128 break;
130 break;
134 if (argc > 1)
135 switch (argv[1][0])
137 case '0':
138 /* C locale; tested above. */
139 /* These characters are not in the ISO C "basic character set", but
140 are nevertheless usually expected to be punctuation or symbol
141 characters. */
142 is = for_character ("$", 1);
143 ASSERT (is != 0);
144 is = for_character ("@", 1);
145 ASSERT (is != 0);
146 is = for_character ("`", 1);
147 ASSERT (is != 0);
148 return test_exit_status;
150 case '1':
151 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
153 #if !(defined __FreeBSD__ || defined __DragonFly__)
154 /* U+00BF INVERTED QUESTION MARK */
155 is = for_character ("\277", 1);
156 ASSERT (is != 0);
157 #endif
158 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
159 /* U+00D7 MULTIPLICATION SIGN */
160 is = for_character ("\327", 1);
161 ASSERT (is != 0);
162 #endif
163 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
164 is = for_character ("\330", 1);
165 ASSERT (is == 0);
166 /* U+00DF LATIN SMALL LETTER SHARP S */
167 is = for_character ("\337", 1);
168 ASSERT (is == 0);
170 return test_exit_status;
172 case '2':
173 /* Locale encoding is EUC-JP. */
175 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__)
176 /* U+00BF INVERTED QUESTION MARK */
177 is = for_character ("\217\242\304", 3);
178 ASSERT (is != 0);
179 #endif
180 #if !(defined __FreeBSD__ || defined __DragonFly__)
181 /* U+00D7 MULTIPLICATION SIGN */
182 is = for_character ("\241\337", 2);
183 ASSERT (is != 0);
184 #endif
185 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
186 is = for_character ("\217\251\254", 3);
187 ASSERT (is == 0);
188 /* U+00DF LATIN SMALL LETTER SHARP S */
189 is = for_character ("\217\251\316", 3);
190 ASSERT (is == 0);
191 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
192 is = for_character ("\217\251\250", 3);
193 ASSERT (is == 0);
194 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__)
195 /* U+2192 RIGHTWARDS ARROW */
196 is = for_character ("\242\252", 2);
197 ASSERT (is != 0);
198 #endif
199 #if !(defined __FreeBSD__ || defined __DragonFly__)
200 /* U+3001 IDEOGRAPHIC COMMA */
201 is = for_character ("\241\242", 2);
202 ASSERT (is != 0);
203 #endif
204 /* U+FF11 FULLWIDTH DIGIT ONE */
205 is = for_character ("\243\261", 2);
206 ASSERT (is == 0);
207 /* U+FF4D FULLWIDTH LATIN SMALL LETTER M */
208 is = for_character ("\243\355", 2);
209 ASSERT (is == 0);
211 return test_exit_status;
213 case '3':
214 /* Locale encoding is UTF-8. */
216 /* U+00BF INVERTED QUESTION MARK */
217 is = for_character ("\302\277", 2);
218 ASSERT (is != 0);
219 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
220 /* U+00D7 MULTIPLICATION SIGN */
221 is = for_character ("\303\227", 2);
222 ASSERT (is != 0);
223 #endif
224 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
225 is = for_character ("\303\230", 2);
226 ASSERT (is == 0);
227 /* U+00DF LATIN SMALL LETTER SHARP S */
228 is = for_character ("\303\237", 2);
229 ASSERT (is == 0);
230 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
231 is = for_character ("\305\201", 2);
232 ASSERT (is == 0);
233 /* U+05F3 HEBREW PUNCTUATION GERESH */
234 is = for_character ("\327\263", 2);
235 ASSERT (is != 0);
236 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun || (defined _WIN32 && !defined __CYGWIN__))
237 /* U+2192 RIGHTWARDS ARROW */
238 is = for_character ("\342\206\222", 3);
239 ASSERT (is != 0);
240 #endif
241 /* U+3001 IDEOGRAPHIC COMMA */
242 is = for_character ("\343\200\201", 3);
243 ASSERT (is != 0);
244 /* U+FF11 FULLWIDTH DIGIT ONE */
245 is = for_character ("\357\274\221", 3);
246 ASSERT (is == 0);
247 /* U+FF4D FULLWIDTH LATIN SMALL LETTER M */
248 is = for_character ("\357\275\215", 3);
249 ASSERT (is == 0);
250 /* U+10330 GOTHIC LETTER AHSA */
251 is = for_character ("\360\220\214\260", 4);
252 ASSERT (is == 0);
253 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
254 /* U+1D100 MUSICAL SYMBOL SINGLE BARLINE */
255 is = for_character ("\360\235\204\200", 4);
256 ASSERT (is != 0);
257 #endif
258 #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ || defined _AIX || defined __sun || defined __CYGWIN__ || (defined _WIN32 && !defined __CYGWIN__))
259 /* U+E003A TAG COLON */
260 is = for_character ("\363\240\200\272", 4);
261 ASSERT (is == 0);
262 #endif
264 return test_exit_status;
266 case '4':
267 /* Locale encoding is GB18030. */
268 #if (defined __GLIBC__ && __GLIBC__ == 2 && __GLIBC_MINOR__ >= 13 && __GLIBC_MINOR__ <= 15) || (GL_CHAR32_T_IS_UNICODE && (defined __FreeBSD__ || defined __NetBSD__ || defined __sun))
269 if (test_exit_status != EXIT_SUCCESS)
270 return test_exit_status;
271 fputs ("Skipping test: The GB18030 converter in this system's iconv is broken.\n", stderr);
272 return 77;
273 #endif
275 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
276 /* U+00BF INVERTED QUESTION MARK */
277 is = for_character ("\201\060\206\067", 4);
278 ASSERT (is != 0);
279 #endif
280 #if !(defined __FreeBSD__ || defined __DragonFly__)
281 /* U+00D7 MULTIPLICATION SIGN */
282 is = for_character ("\241\301", 2);
283 ASSERT (is != 0);
284 #endif
285 /* U+00D8 LATIN CAPITAL LETTER O WITH STROKE */
286 is = for_character ("\201\060\211\061", 4);
287 ASSERT (is == 0);
288 /* U+00DF LATIN SMALL LETTER SHARP S */
289 is = for_character ("\201\060\211\070", 4);
290 ASSERT (is == 0);
291 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
292 is = for_character ("\201\060\221\071", 4);
293 ASSERT (is == 0);
294 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
295 /* U+05F3 HEBREW PUNCTUATION GERESH */
296 is = for_character ("\201\060\374\067", 4);
297 ASSERT (is != 0);
298 #endif
299 #if !(defined __FreeBSD__ || defined __DragonFly__)
300 /* U+2192 RIGHTWARDS ARROW */
301 is = for_character ("\241\372", 2);
302 ASSERT (is != 0);
303 /* U+3001 IDEOGRAPHIC COMMA */
304 is = for_character ("\241\242", 2);
305 ASSERT (is != 0);
306 #endif
307 /* U+FF11 FULLWIDTH DIGIT ONE */
308 is = for_character ("\243\261", 2);
309 ASSERT (is == 0);
310 /* U+FF4D FULLWIDTH LATIN SMALL LETTER M */
311 is = for_character ("\243\355", 2);
312 ASSERT (is == 0);
313 /* U+10330 GOTHIC LETTER AHSA */
314 is = for_character ("\220\060\322\066", 4);
315 ASSERT (is == 0);
316 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sun)
317 /* U+1D100 MUSICAL SYMBOL SINGLE BARLINE */
318 is = for_character ("\224\062\273\064", 4);
319 ASSERT (is != 0);
320 #endif
321 #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __CYGWIN__)
322 /* U+E003A TAG COLON */
323 is = for_character ("\323\066\233\066", 4);
324 ASSERT (is == 0);
325 #endif
327 return test_exit_status;
331 return 1;