Use Linux 4.18 in build-many-glibcs.py.
[glibc.git] / localedata / tst-langinfo.c
blob5b2c11729227fe51bb57a512f0626a936a37a7b8
1 /* Test driver for nl_langinfo[_l] functions.
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 int param;
167 if (fgets (buf, sizeof (buf), stdin) == NULL)
168 break;
170 /* Split the fields. There are three is them:
171 1. locale
172 2. langinfo() parameter
173 3. expected result; this can be a string with white space etc.
175 rp = buf;
176 while (*rp == ' ' || *rp == '\t')
177 ++rp;
179 if (*rp == '#')
181 /* It's a comment line. Ignore it. */
182 REASON ("comment");
183 continue;
185 locale = rp;
187 while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
188 ++rp;
189 if (*rp == '\0' || *rp == '\n')
191 /* Incomplete line. */
192 REASON ("incomplete line");
193 continue;
195 *rp++ = '\0';
197 while (*rp == ' ' || *rp == '\t')
198 ++rp;
199 paramstr = rp;
201 while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
202 ++rp;
203 if (*rp == '\0' || *rp == '\n')
205 /* Incomplete line. */
206 REASON ("incomplete line");
207 continue;
209 *rp++ = '\0';
211 while (*rp == ' ' || *rp == '\t')
212 ++rp;
214 if (*rp == '"')
216 char *wp;
218 expected = wp = ++rp;
219 while (*rp != '"' && *rp != '\n' && *rp != '\0')
221 if (*rp == '\\')
223 ++rp;
224 if (*rp == '\0')
225 break;
226 if (*rp >= '0' && *rp <= '9')
228 int val = *rp - '0';
229 if (rp[1] >= '0' && rp[1] <= '9')
231 ++rp;
232 val *= 10;
233 val += *rp - '0';
234 if (rp[1] >= '0' && rp[1] <= '9')
236 ++rp;
237 val *= 10;
238 val += *rp - '0';
241 *rp = val;
244 *wp++ = *rp++;
247 if (*rp != '"')
249 REASON ("missing '\"'");
250 continue;
253 *wp = '\0';
255 else
257 expected = rp;
258 while (*rp != '\0' && *rp != '\n')
259 ++rp;
260 *rp = '\0';
263 param = map_paramstr (paramstr);
264 if (param == -1)
266 /* Invalid parameter. */
267 REASON ("invalid parameter");
268 continue;
271 result = test_locale (locale, paramstr, param, expected);
274 return result;
277 #define TEST_FUNCTION do_test ()
278 #include "../test-skeleton.c"