Remove some math_private.h libc_feholdexcept_setround overrides.
[glibc.git] / localedata / tst-langinfo.c
blob0d33e75215627d5948e620106a7dad77bffc5eca
1 /* Test program for nl_langinfo() function.
2 Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <langinfo.h>
21 #include <locale.h>
22 #include <stdio.h>
23 #include <string.h>
26 struct map
28 const char *str;
29 int val;
30 } map[] =
32 #define VAL(name) { #name, name }
33 VAL (ABDAY_1),
34 VAL (ABDAY_2),
35 VAL (ABDAY_3),
36 VAL (ABDAY_4),
37 VAL (ABDAY_5),
38 VAL (ABDAY_6),
39 VAL (ABDAY_7),
40 VAL (ABMON_1),
41 VAL (ABMON_10),
42 VAL (ABMON_11),
43 VAL (ABMON_12),
44 VAL (ABMON_2),
45 VAL (ABMON_3),
46 VAL (ABMON_4),
47 VAL (ABMON_5),
48 VAL (ABMON_6),
49 VAL (ABMON_7),
50 VAL (ABMON_8),
51 VAL (ABMON_9),
52 VAL (ALT_DIGITS),
53 VAL (ALTMON_1),
54 VAL (ALTMON_10),
55 VAL (ALTMON_11),
56 VAL (ALTMON_12),
57 VAL (ALTMON_2),
58 VAL (ALTMON_3),
59 VAL (ALTMON_4),
60 VAL (ALTMON_5),
61 VAL (ALTMON_6),
62 VAL (ALTMON_7),
63 VAL (ALTMON_8),
64 VAL (ALTMON_9),
65 VAL (AM_STR),
66 VAL (CRNCYSTR),
67 VAL (CURRENCY_SYMBOL),
68 VAL (DAY_1),
69 VAL (DAY_2),
70 VAL (DAY_3),
71 VAL (DAY_4),
72 VAL (DAY_5),
73 VAL (DAY_6),
74 VAL (DAY_7),
75 VAL (DECIMAL_POINT),
76 VAL (D_FMT),
77 VAL (D_T_FMT),
78 VAL (ERA),
79 VAL (ERA_D_FMT),
80 VAL (ERA_D_T_FMT),
81 VAL (ERA_T_FMT),
82 VAL (ERA_YEAR),
83 VAL (FRAC_DIGITS),
84 VAL (GROUPING),
85 VAL (INT_CURR_SYMBOL),
86 VAL (INT_FRAC_DIGITS),
87 VAL (MON_1),
88 VAL (MON_10),
89 VAL (MON_11),
90 VAL (MON_12),
91 VAL (MON_2),
92 VAL (MON_3),
93 VAL (MON_4),
94 VAL (MON_5),
95 VAL (MON_6),
96 VAL (MON_7),
97 VAL (MON_8),
98 VAL (MON_9),
99 VAL (MON_DECIMAL_POINT),
100 VAL (MON_GROUPING),
101 VAL (MON_THOUSANDS_SEP),
102 VAL (NEGATIVE_SIGN),
103 VAL (NOEXPR),
104 VAL (NOSTR),
105 VAL (N_CS_PRECEDES),
106 VAL (N_SEP_BY_SPACE),
107 VAL (N_SIGN_POSN),
108 VAL (PM_STR),
109 VAL (POSITIVE_SIGN),
110 VAL (P_CS_PRECEDES),
111 VAL (P_SEP_BY_SPACE),
112 VAL (P_SIGN_POSN),
113 VAL (RADIXCHAR),
114 VAL (THOUSANDS_SEP),
115 VAL (THOUSEP),
116 VAL (T_FMT),
117 VAL (T_FMT_AMPM),
118 VAL (YESEXPR),
119 VAL (YESSTR)
123 static int
124 map_paramstr (const char *str)
126 int low = 0;
127 int high = sizeof (map) / sizeof (map[0]);
129 while (low < high)
131 int med = (low + high) / 2;
132 int cmpres;
134 cmpres = strcmp (str, map[med].str);
135 if (cmpres == 0)
136 return map[med].val;
137 else if (cmpres > 0)
138 low = med + 1;
139 else
140 high = med;
143 return -1;
147 #ifdef DEBUG
148 # define REASON(str) printf ("\"%s\" ignored: %s\n", buf, str)
149 #else
150 # define REASON(str)
151 #endif
153 static int
154 do_test (void)
156 int result = 0;
158 while (! feof (stdin))
160 char buf[1000];
161 char *rp;
162 char *locale;
163 char *paramstr;
164 char *expected;
165 char *actual;
166 int param;
168 if (fgets (buf, sizeof (buf), stdin) == NULL)
169 break;
171 /* Split the fields. There are three is them:
172 1. locale
173 2. langinfo() parameter
174 3. expected result; this can be a string with white space etc.
176 rp = buf;
177 while (*rp == ' ' || *rp == '\t')
178 ++rp;
180 if (*rp == '#')
182 /* It's a comment line. Ignore it. */
183 REASON ("comment");
184 continue;
186 locale = rp;
188 while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
189 ++rp;
190 if (*rp == '\0' || *rp == '\n')
192 /* Incomplete line. */
193 REASON ("incomplete line");
194 continue;
196 *rp++ = '\0';
198 while (*rp == ' ' || *rp == '\t')
199 ++rp;
200 paramstr = rp;
202 while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
203 ++rp;
204 if (*rp == '\0' || *rp == '\n')
206 /* Incomplete line. */
207 REASON ("incomplete line");
208 continue;
210 *rp++ = '\0';
212 while (*rp == ' ' || *rp == '\t')
213 ++rp;
215 if (*rp == '"')
217 char *wp;
219 expected = wp = ++rp;
220 while (*rp != '"' && *rp != '\n' && *rp != '\0')
222 if (*rp == '\\')
224 ++rp;
225 if (*rp == '\0')
226 break;
227 if (*rp >= '0' && *rp <= '9')
229 int val = *rp - '0';
230 if (rp[1] >= '0' && rp[1] <= '9')
232 ++rp;
233 val *= 10;
234 val += *rp - '0';
235 if (rp[1] >= '0' && rp[1] <= '9')
237 ++rp;
238 val *= 10;
239 val += *rp - '0';
242 *rp = val;
245 *wp++ = *rp++;
248 if (*rp != '"')
250 REASON ("missing '\"'");
251 continue;
254 *wp = '\0';
256 else
258 expected = rp;
259 while (*rp != '\0' && *rp != '\n')
260 ++rp;
261 *rp = '\0';
264 param = map_paramstr (paramstr);
265 if (param == -1)
267 /* Invalid parameter. */
268 REASON ("invalid parameter");
269 continue;
272 /* Set the locale and check whether it worked. */
273 printf ("LC_ALL=%s nl_langinfo(%s)", locale, paramstr);
274 setlocale (LC_ALL, locale);
275 if (strcmp (locale, setlocale (LC_ALL, NULL)) != 0)
277 puts (": failed to set locale");
278 result = 1;
279 continue;
282 actual = nl_langinfo (param);
283 printf (" = \"%s\", ", actual);
285 if (strcmp (actual, expected) == 0)
286 puts ("OK");
287 else
289 printf ("FAILED (expected: %s)\n", expected);
290 result = 1;
294 return result;
297 #define TEST_FUNCTION do_test ()
298 #include "../test-skeleton.c"