getusershell: Work around musl bugs.
[gnulib.git] / tests / test-c32isprint.c
blobdfc9e59cd44a5b977b8e1646a2e07ccaeb1fd527
1 /* Test of c32isprint() 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 (c32isprint, 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 c32isprint 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 c32isprint (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 = c32isprint (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 printable 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 '\t': case '\v': case '\f':
98 ASSERT (is == 0);
99 break;
100 default:
101 ASSERT (is != 0);
102 break;
104 break;
108 if (argc > 1)
109 switch (argv[1][0])
111 case '0':
112 /* C locale; tested above. */
113 return test_exit_status;
115 case '1':
116 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
118 /* U+007F <control> */
119 is = for_character ("\177", 1);
120 ASSERT (is == 0);
121 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sgi || (defined _WIN32 && !defined __CYGWIN__))
122 /* U+00A0 NO-BREAK SPACE */
123 is = for_character ("\240", 1);
124 ASSERT (is != 0);
125 #endif
126 #if !(defined __FreeBSD__ || defined __DragonFly__)
127 /* U+00B8 CEDILLA */
128 is = for_character ("\270", 1);
129 ASSERT (is != 0);
130 #endif
132 return test_exit_status;
134 case '2':
135 /* Locale encoding is EUC-JP. */
137 /* U+007F <control> */
138 is = for_character ("\177", 1);
139 ASSERT (is == 0);
140 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__)
141 /* U+00B8 CEDILLA */
142 is = for_character ("\217\242\261", 3);
143 ASSERT (is != 0);
144 /* U+3000 IDEOGRAPHIC SPACE */
145 is = for_character ("\241\241", 2);
146 ASSERT (is != 0);
147 #endif
149 return test_exit_status;
151 case '3':
152 /* Locale encoding is UTF-8. */
154 /* U+007F <control> */
155 is = for_character ("\177", 1);
156 ASSERT (is == 0);
157 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun || (defined _WIN32 && !defined __CYGWIN__))
158 /* U+00A0 NO-BREAK SPACE */
159 is = for_character ("\302\240", 2);
160 ASSERT (is != 0);
161 #endif
162 /* U+00B8 CEDILLA */
163 is = for_character ("\302\270", 2);
164 ASSERT (is != 0);
165 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun || (defined _WIN32 && !defined __CYGWIN__))
166 /* U+2002 EN SPACE */
167 is = for_character ("\342\200\202", 3);
168 ASSERT (is != 0);
169 #endif
170 #if !(defined __GLIBC__ || defined MUSL_LIBC || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ || defined _AIX || defined __sun || defined __CYGWIN__)
171 /* U+202E RIGHT-TO-LEFT OVERRIDE */
172 is = for_character ("\342\200\256", 3);
173 ASSERT (is == 0);
174 #endif
175 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
176 /* U+3000 IDEOGRAPHIC SPACE */
177 is = for_character ("\343\200\200", 3);
178 ASSERT (is != 0);
179 #endif
180 #if !(defined __GLIBC__ || defined MUSL_LIBC || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ || defined _AIX || defined __sun || defined __CYGWIN__ || (defined _WIN32 && !defined __CYGWIN__))
181 /* U+FEFF ZERO WIDTH NO-BREAK SPACE */
182 is = for_character ("\357\273\277", 3);
183 ASSERT (is == 0);
184 #endif
185 #if !defined __sun
186 /* U+20000 <CJK Ideograph> */
187 is = for_character ("\360\240\200\200", 4);
188 ASSERT (is != 0);
189 #endif
190 #if !(defined __GLIBC__ || defined MUSL_LIBC || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __NetBSD__ || defined _AIX || defined __sun || defined __CYGWIN__ || (defined _WIN32 && !defined __CYGWIN__))
191 /* U+E0001 LANGUAGE TAG */
192 is = for_character ("\363\240\200\201", 4);
193 ASSERT (is == 0);
194 #endif
196 return test_exit_status;
198 case '4':
199 /* Locale encoding is GB18030. */
200 #if (defined __GLIBC__ && __GLIBC__ == 2 && __GLIBC_MINOR__ >= 13 && __GLIBC_MINOR__ <= 15) || (GL_CHAR32_T_IS_UNICODE && (defined __NetBSD__ || defined __sun))
201 fputs ("Skipping test: The GB18030 converter in this system's iconv is broken.\n", stderr);
202 return 77;
203 #endif
205 /* U+007F <control> */
206 is = for_character ("\177", 1);
207 ASSERT (is == 0);
208 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
209 /* U+00A0 NO-BREAK SPACE */
210 is = for_character ("\201\060\204\062", 4);
211 ASSERT (is != 0);
212 /* U+00B8 CEDILLA */
213 is = for_character ("\201\060\206\060", 4);
214 ASSERT (is != 0);
215 /* U+2002 EN SPACE */
216 is = for_character ("\201\066\243\070", 4);
217 ASSERT (is != 0);
218 #endif
219 #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__)
220 /* U+202E RIGHT-TO-LEFT OVERRIDE */
221 is = for_character ("\201\066\247\061", 4);
222 ASSERT (is == 0);
223 #endif
224 #if !(defined __FreeBSD__ || defined __DragonFly__)
225 /* U+3000 IDEOGRAPHIC SPACE */
226 is = for_character ("\241\241", 2);
227 ASSERT (is != 0);
228 #endif
229 #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__)
230 /* U+FEFF ZERO WIDTH NO-BREAK SPACE */
231 is = for_character ("\204\061\225\063", 4);
232 ASSERT (is == 0);
233 #endif
234 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sun)
235 /* U+20000 <CJK Ideograph> */
236 is = for_character ("\225\062\202\066", 4);
237 ASSERT (is != 0);
238 #endif
239 #if !(defined __GLIBC__ || (defined __APPLE__ && defined __MACH__) || defined __FreeBSD__)
240 /* U+E0001 LANGUAGE TAG */
241 is = for_character ("\323\066\225\071", 4);
242 ASSERT (is == 0);
243 #endif
245 return test_exit_status;
249 return 1;