1 /* Copyright (C) 2000 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25 /* Currently selected locale. */
26 static const char *current_locale
;
29 /* Test which should succeed. */
31 ok_test (int c
, wint_t expwc
)
33 wint_t wc
= btowc (c
);
37 printf ("%s: btowc('%c') failed, returned L'\\x%x' instead of L'\\x%x'\n",
38 current_locale
, c
, wc
, expwc
);
45 /* Test which should fail. */
49 wint_t wc
= btowc (c
);
53 printf ("%s: btowc('%c') succeded, returned L'\\x%x' instead of WEOF\n",
54 current_locale
, c
, wc
);
62 /* Test EOF handling. */
66 wint_t wc
= btowc (EOF
);
69 printf ("%s: btowc(EOF) returned L'\\x%x', not WEOF\n",
77 /* Test the btowc() function for a few locales with known character sets. */
83 current_locale
= setlocale (LC_ALL
, "en_US.ANSI_X3.4-1968");
84 if (current_locale
== NULL
)
86 puts ("cannot set locale \"en_US.ANSI_X3.4-1968\"");
93 for (c
= 0; c
< 128; ++c
)
94 result
|= ok_test (c
, c
);
96 for (c
= 128; c
< 256; ++c
)
97 result
|= fail_test (c
);
99 result
|= eof_test ();
102 current_locale
= setlocale (LC_ALL
, "de_DE.ISO-8859-1");
103 if (current_locale
== NULL
)
105 puts ("cannot set locale \"de_DE.ISO-8859-1\"");
112 for (c
= 0; c
< 256; ++c
)
113 result
|= ok_test (c
, c
);
115 result
|= eof_test ();
118 current_locale
= setlocale (LC_ALL
, "de_DE.UTF-8");
119 if (current_locale
== NULL
)
121 puts ("cannot set locale \"de_DE.UTF-8\"");
128 for (c
= 0; c
< 128; ++c
)
129 result
|= ok_test (c
, c
);
131 for (c
= 128; c
< 256; ++c
)
132 result
|= fail_test (c
);
134 result
|= eof_test ();
137 current_locale
= setlocale (LC_ALL
, "hr_HR.ISO-8859-2");
138 if (current_locale
== NULL
)
140 puts ("cannot set locale \"hr_HR.ISO-8859-2\"");
145 static const wint_t upper_half
[] =
147 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7, 0x00A8,
148 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B, 0x00B0,
149 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7, 0x00B8,
150 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C, 0x0154,
151 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7, 0x010C,
152 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E, 0x0110,
153 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7, 0x0158,
154 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF, 0x0155,
155 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7, 0x010D,
156 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F, 0x0111,
157 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7, 0x0159,
158 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
162 for (c
= 0; c
< 161; ++c
)
163 result
|= ok_test (c
, c
);
165 for (c
= 161; c
< 256; ++c
)
166 result
|= ok_test (c
, upper_half
[c
- 161]);
168 result
|= eof_test ();