PowerPC: ifunc improvement for internal calls
[glibc.git] / wcsmbs / tst-btowc.c
blobd793622771d0165bc43fb2ddb4629c9df272cd8e
1 /* Copyright (C) 2000-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <locale.h>
20 #include <stdio.h>
21 #include <wchar.h>
24 /* Currently selected locale. */
25 static const char *current_locale;
28 /* Test which should succeed. */
29 static int
30 ok_test (int c, wint_t expwc)
32 wint_t wc = btowc (c);
34 if (wc != expwc)
36 printf ("%s: btowc('%c') failed, returned L'\\x%x' instead of L'\\x%x'\n",
37 current_locale, c, wc, expwc);
38 return 1;
41 return 0;
44 /* Test which should fail. */
45 static int
46 fail_test (int c)
48 wint_t wc = btowc (c);
50 if (wc != WEOF)
52 printf ("%s: btowc('%c') succeded, returned L'\\x%x' instead of WEOF\n",
53 current_locale, c, wc);
54 return 1;
57 return 0;
61 /* Test EOF handling. */
62 static int
63 eof_test (void)
65 wint_t wc = btowc (EOF);
66 if (wc != WEOF)
68 printf ("%s: btowc(EOF) returned L'\\x%x', not WEOF\n",
69 current_locale, wc);
72 return 0;
76 /* Test the btowc() function for a few locales with known character sets. */
77 int
78 main (void)
80 int result = 0;
82 current_locale = setlocale (LC_ALL, "en_US.ANSI_X3.4-1968");
83 if (current_locale == NULL)
85 puts ("cannot set locale \"en_US.ANSI_X3.4-1968\"");
86 result = 1;
88 else
90 int c;
92 for (c = 0; c < 128; ++c)
93 result |= ok_test (c, c);
95 for (c = 128; c < 256; ++c)
96 result |= fail_test (c);
98 result |= eof_test ();
101 current_locale = setlocale (LC_ALL, "de_DE.ISO-8859-1");
102 if (current_locale == NULL)
104 puts ("cannot set locale \"de_DE.ISO-8859-1\"");
105 result = 1;
107 else
109 int c;
111 for (c = 0; c < 256; ++c)
112 result |= ok_test (c, c);
114 result |= eof_test ();
117 current_locale = setlocale (LC_ALL, "de_DE.UTF-8");
118 if (current_locale == NULL)
120 puts ("cannot set locale \"de_DE.UTF-8\"");
121 result = 1;
123 else
125 int c;
127 for (c = 0; c < 128; ++c)
128 result |= ok_test (c, c);
130 for (c = 128; c < 256; ++c)
131 result |= fail_test (c);
133 result |= eof_test ();
136 current_locale = setlocale (LC_ALL, "hr_HR.ISO-8859-2");
137 if (current_locale == NULL)
139 puts ("cannot set locale \"hr_HR.ISO-8859-2\"");
140 result = 1;
142 else
144 static const wint_t upper_half[] =
146 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8,
147 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0,
148 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8,
149 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154,
150 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C,
151 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, 0x0110,
152 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, 0x0158,
153 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, 0x0155,
154 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, 0x010D,
155 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111,
156 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159,
157 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
159 int c;
161 for (c = 0; c < 161; ++c)
162 result |= ok_test (c, c);
164 for (c = 161; c < 256; ++c)
165 result |= ok_test (c, upper_half[c - 161]);
167 result |= eof_test ();
170 if (result == 0)
171 puts ("all OK");
173 return result;