Linux: Assume and consolidate socket wire-up syscall
[glibc.git] / wcsmbs / tst-btowc.c
blob0325a841af62e2a5ac47c1cf0c277c18b0df792a
1 /* Copyright (C) 2000-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <locale.h>
19 #include <stdio.h>
20 #include <wchar.h>
23 /* Currently selected locale. */
24 static const char *current_locale;
27 /* Test which should succeed. */
28 static int
29 ok_test (int c, wint_t expwc)
31 wint_t wc = btowc (c);
33 if (wc != expwc)
35 printf ("%s: btowc('%c') failed, returned L'\\x%x' instead of L'\\x%x'\n",
36 current_locale, c, wc, expwc);
37 return 1;
40 return 0;
43 /* Test which should fail. */
44 static int
45 fail_test (int c)
47 wint_t wc = btowc (c);
49 if (wc != WEOF)
51 printf ("%s: btowc('%c') succeded, returned L'\\x%x' instead of WEOF\n",
52 current_locale, c, wc);
53 return 1;
56 return 0;
60 /* Test EOF handling. */
61 static int
62 eof_test (void)
64 wint_t wc = btowc (EOF);
65 if (wc != WEOF)
67 printf ("%s: btowc(EOF) returned L'\\x%x', not WEOF\n",
68 current_locale, wc);
71 return 0;
75 /* Test the btowc() function for a few locales with known character sets. */
76 static int
77 do_test (void)
79 int result = 0;
81 current_locale = setlocale (LC_ALL, "en_US.ANSI_X3.4-1968");
82 if (current_locale == NULL)
84 puts ("cannot set locale \"en_US.ANSI_X3.4-1968\"");
85 result = 1;
87 else
89 int c;
91 for (c = 0; c < 128; ++c)
92 result |= ok_test (c, c);
94 for (c = 128; c < 256; ++c)
95 result |= fail_test (c);
97 result |= eof_test ();
100 current_locale = setlocale (LC_ALL, "de_DE.ISO-8859-1");
101 if (current_locale == NULL)
103 puts ("cannot set locale \"de_DE.ISO-8859-1\"");
104 result = 1;
106 else
108 int c;
110 for (c = 0; c < 256; ++c)
111 result |= ok_test (c, c);
113 result |= eof_test ();
116 current_locale = setlocale (LC_ALL, "de_DE.UTF-8");
117 if (current_locale == NULL)
119 puts ("cannot set locale \"de_DE.UTF-8\"");
120 result = 1;
122 else
124 int c;
126 for (c = 0; c < 128; ++c)
127 result |= ok_test (c, c);
129 for (c = 128; c < 256; ++c)
130 result |= fail_test (c);
132 result |= eof_test ();
135 current_locale = setlocale (LC_ALL, "hr_HR.ISO-8859-2");
136 if (current_locale == NULL)
138 puts ("cannot set locale \"hr_HR.ISO-8859-2\"");
139 result = 1;
141 else
143 static const wint_t upper_half[] =
145 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8,
146 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0,
147 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8,
148 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154,
149 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C,
150 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, 0x0110,
151 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, 0x0158,
152 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, 0x0155,
153 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, 0x010D,
154 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111,
155 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159,
156 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
158 int c;
160 for (c = 0; c < 161; ++c)
161 result |= ok_test (c, c);
163 for (c = 161; c < 256; ++c)
164 result |= ok_test (c, upper_half[c - 161]);
166 result |= eof_test ();
169 if (result == 0)
170 puts ("all OK");
172 return result;
175 #include <support/test-driver.c>