sigprocmask: Fix configuration failure on Solaris 10 (regr. 2020-07-25).
[gnulib.git] / tests / test-c32isupper.c
bloba773466f432674d0d682855a3996878a5484f790
1 /* Test of c32isupper() function.
2 Copyright (C) 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 #include <config.h>
19 #include <uchar.h>
21 #include "signature.h"
22 SIGNATURE_CHECK (c32isupper, 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 c32isupper 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 c32isupper (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 = c32isupper (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 uppercase characters include the A ... Z
66 characters,
67 - in the "POSIX" locale (which is usually the same as the "C" locale),
68 the uppercase characters include only the ASCII A ... Z characters.
71 int c;
73 for (c = 0; c < 0x100; c++)
74 switch (c)
76 case '\t': case '\v': case '\f':
77 case ' ': case '!': case '"': case '#': case '%':
78 case '&': case '\'': case '(': case ')': case '*':
79 case '+': case ',': case '-': case '.': case '/':
80 case '0': case '1': case '2': case '3': case '4':
81 case '5': case '6': case '7': case '8': case '9':
82 case ':': case ';': case '<': case '=': case '>':
83 case '?':
84 case 'A': case 'B': case 'C': case 'D': case 'E':
85 case 'F': case 'G': case 'H': case 'I': case 'J':
86 case 'K': case 'L': case 'M': case 'N': case 'O':
87 case 'P': case 'Q': case 'R': case 'S': case 'T':
88 case 'U': case 'V': case 'W': case 'X': case 'Y':
89 case 'Z':
90 case '[': case '\\': case ']': case '^': case '_':
91 case 'a': case 'b': case 'c': case 'd': case 'e':
92 case 'f': case 'g': case 'h': case 'i': case 'j':
93 case 'k': case 'l': case 'm': case 'n': case 'o':
94 case 'p': case 'q': case 'r': case 's': case 't':
95 case 'u': case 'v': case 'w': case 'x': case 'y':
96 case 'z': case '{': case '|': case '}': case '~':
97 /* c is in the ISO C "basic character set". */
98 buf[0] = (unsigned char) c;
99 is = for_character (buf, 1);
100 switch (c)
102 case 'A': case 'B': case 'C': case 'D': case 'E':
103 case 'F': case 'G': case 'H': case 'I': case 'J':
104 case 'K': case 'L': case 'M': case 'N': case 'O':
105 case 'P': case 'Q': case 'R': case 'S': case 'T':
106 case 'U': case 'V': case 'W': case 'X': case 'Y':
107 case 'Z':
108 ASSERT (is != 0);
109 break;
110 default:
111 ASSERT (is == 0);
112 break;
114 break;
118 if (argc > 1)
119 switch (argv[1][0])
121 case '0':
122 /* C locale; tested above. */
123 return 0;
125 case '1':
126 /* Locale encoding is ISO-8859-1 or ISO-8859-15. */
128 /* U+00B2 SUPERSCRIPT TWO */
129 is = for_character ("\262", 1);
130 ASSERT (is == 0);
131 /* U+00B5 MICRO SIGN */
132 is = for_character ("\265", 1);
133 ASSERT (is == 0);
134 /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
135 is = for_character ("\311", 1);
136 ASSERT (is != 0);
137 #if !defined __hpux
138 /* U+00DF LATIN SMALL LETTER SHARP S */
139 is = for_character ("\337", 1);
140 ASSERT (is == 0);
141 #endif
142 /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
143 is = for_character ("\351", 1);
144 ASSERT (is == 0);
145 /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
146 is = for_character ("\377", 1);
147 ASSERT (is == 0);
149 return 0;
151 case '2':
152 /* Locale encoding is EUC-JP. */
154 #if !((defined __APPLE__ && defined __MACH__) || defined __NetBSD__)
155 /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
156 is = for_character ("\217\252\261", 3);
157 ASSERT (is != 0);
158 #endif
159 /* U+00DF LATIN SMALL LETTER SHARP S */
160 is = for_character ("\217\251\316", 3);
161 ASSERT (is == 0);
162 /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
163 is = for_character ("\217\253\261", 3);
164 ASSERT (is == 0);
165 /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
166 is = for_character ("\217\253\363", 3);
167 ASSERT (is == 0);
168 #if !((defined __APPLE__ && defined __MACH__) || defined __NetBSD__)
169 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
170 is = for_character ("\217\251\250", 3);
171 ASSERT (is != 0);
172 #endif
173 /* U+0142 LATIN SMALL LETTER L WITH STROKE */
174 is = for_character ("\217\251\310", 3);
175 ASSERT (is == 0);
176 #if !(defined __FreeBSD__ || defined __DragonFly__)
177 /* U+0429 CYRILLIC CAPITAL LETTER SHCHA */
178 is = for_character ("\247\273", 2);
179 ASSERT (is != 0);
180 #endif
181 /* U+0449 CYRILLIC SMALL LETTER SHCHA */
182 is = for_character ("\247\353", 2);
183 ASSERT (is == 0);
184 /* U+3073 HIRAGANA LETTER BI */
185 is = for_character ("\244\323", 2);
186 ASSERT (is == 0);
187 /* U+FF27 FULLWIDTH LATIN CAPITAL LETTER G */
188 is = for_character ("\243\307", 2);
189 ASSERT (is != 0);
191 return 0;
193 case '3':
194 /* Locale encoding is UTF-8. */
196 /* U+00B2 SUPERSCRIPT TWO */
197 is = for_character ("\302\262", 2);
198 ASSERT (is == 0);
199 /* U+00B5 MICRO SIGN */
200 is = for_character ("\302\265", 2);
201 ASSERT (is == 0);
202 /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
203 is = for_character ("\303\211", 2);
204 ASSERT (is != 0);
205 /* U+00DF LATIN SMALL LETTER SHARP S */
206 is = for_character ("\303\237", 2);
207 ASSERT (is == 0);
208 /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
209 is = for_character ("\303\251", 2);
210 ASSERT (is == 0);
211 /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
212 is = for_character ("\303\277", 2);
213 ASSERT (is == 0);
214 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
215 is = for_character ("\305\201", 2);
216 ASSERT (is != 0);
217 /* U+0142 LATIN SMALL LETTER L WITH STROKE */
218 is = for_character ("\305\202", 2);
219 ASSERT (is == 0);
220 /* U+0429 CYRILLIC CAPITAL LETTER SHCHA */
221 is = for_character ("\320\251", 2);
222 ASSERT (is != 0);
223 /* U+0449 CYRILLIC SMALL LETTER SHCHA */
224 is = for_character ("\321\211", 2);
225 ASSERT (is == 0);
226 /* U+05D5 HEBREW LETTER VAV */
227 is = for_character ("\327\225", 2);
228 ASSERT (is == 0);
229 /* U+3073 HIRAGANA LETTER BI */
230 is = for_character ("\343\201\263", 3);
231 ASSERT (is == 0);
232 /* U+3162 HANGUL LETTER YI */
233 is = for_character ("\343\205\242", 3);
234 ASSERT (is == 0);
235 /* U+FF27 FULLWIDTH LATIN CAPITAL LETTER G */
236 is = for_character ("\357\274\247", 3);
237 ASSERT (is != 0);
238 /* U+FFDB HALFWIDTH HANGUL LETTER YI */
239 is = for_character ("\357\277\233", 3);
240 ASSERT (is == 0);
241 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
242 /* U+10419 DESERET CAPITAL LETTER EF */
243 is = for_character ("\360\220\220\231", 4);
244 ASSERT (is != 0);
245 #endif
246 /* U+10441 DESERET SMALL LETTER EF */
247 is = for_character ("\360\220\221\201", 4);
248 ASSERT (is == 0);
249 /* U+E0041 TAG LATIN CAPITAL LETTER A */
250 is = for_character ("\363\240\201\201", 4);
251 ASSERT (is == 0);
252 /* U+E0061 TAG LATIN SMALL LETTER A */
253 is = for_character ("\363\240\201\241", 4);
254 ASSERT (is == 0);
256 return 0;
258 case '4':
259 /* Locale encoding is GB18030. */
261 /* U+00B2 SUPERSCRIPT TWO */
262 is = for_character ("\201\060\205\065", 4);
263 ASSERT (is == 0);
264 /* U+00B5 MICRO SIGN */
265 is = for_character ("\201\060\205\070", 4);
266 ASSERT (is == 0);
267 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
268 /* U+00C9 LATIN CAPITAL LETTER E WITH ACUTE */
269 is = for_character ("\201\060\207\067", 4);
270 ASSERT (is != 0);
271 #endif
272 /* U+00DF LATIN SMALL LETTER SHARP S */
273 is = for_character ("\201\060\211\070", 4);
274 ASSERT (is == 0);
275 /* U+00E9 LATIN SMALL LETTER E WITH ACUTE */
276 is = for_character ("\250\246", 2);
277 ASSERT (is == 0);
278 /* U+00FF LATIN SMALL LETTER Y WITH DIAERESIS */
279 is = for_character ("\201\060\213\067", 4);
280 ASSERT (is == 0);
281 #if !(defined __FreeBSD__ || defined __DragonFly__ || defined __sun)
282 /* U+0141 LATIN CAPITAL LETTER L WITH STROKE */
283 is = for_character ("\201\060\221\071", 4);
284 ASSERT (is != 0);
285 #endif
286 /* U+0142 LATIN SMALL LETTER L WITH STROKE */
287 is = for_character ("\201\060\222\060", 4);
288 ASSERT (is == 0);
289 #if !(defined __FreeBSD__ || defined __DragonFly__)
290 /* U+0429 CYRILLIC CAPITAL LETTER SHCHA */
291 is = for_character ("\247\273", 2);
292 ASSERT (is != 0);
293 #endif
294 /* U+0449 CYRILLIC SMALL LETTER SHCHA */
295 is = for_character ("\247\353", 2);
296 ASSERT (is == 0);
297 /* U+05D5 HEBREW LETTER VAV */
298 is = for_character ("\201\060\371\067", 4);
299 ASSERT (is == 0);
300 /* U+3073 HIRAGANA LETTER BI */
301 is = for_character ("\244\323", 2);
302 ASSERT (is == 0);
303 /* U+3162 HANGUL LETTER YI */
304 is = for_character ("\201\071\256\062", 4);
305 ASSERT (is == 0);
306 /* U+FF27 FULLWIDTH LATIN CAPITAL LETTER G */
307 is = for_character ("\243\307", 2);
308 ASSERT (is != 0);
309 /* U+FFDB HALFWIDTH HANGUL LETTER YI */
310 is = for_character ("\204\061\241\071", 4);
311 ASSERT (is == 0);
312 #if !((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sun)
313 /* U+10419 DESERET CAPITAL LETTER EF */
314 is = for_character ("\220\060\351\071", 4);
315 ASSERT (is != 0);
316 #endif
317 /* U+10441 DESERET SMALL LETTER EF */
318 is = for_character ("\220\060\355\071", 4);
319 ASSERT (is == 0);
320 /* U+E0041 TAG LATIN CAPITAL LETTER A */
321 is = for_character ("\323\066\234\063", 4);
322 ASSERT (is == 0);
323 /* U+E0061 TAG LATIN SMALL LETTER A */
324 is = for_character ("\323\066\237\065", 4);
325 ASSERT (is == 0);
327 return 0;
331 return 1;