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/>. */
32 #define VAL(name) { #name, name }
67 VAL (CURRENCY_SYMBOL
),
85 VAL (INT_CURR_SYMBOL
),
86 VAL (INT_FRAC_DIGITS
),
99 VAL (MON_DECIMAL_POINT
),
101 VAL (MON_THOUSANDS_SEP
),
106 VAL (N_SEP_BY_SPACE
),
111 VAL (P_SEP_BY_SPACE
),
124 map_paramstr (const char *str
)
127 int high
= sizeof (map
) / sizeof (map
[0]);
131 int med
= (low
+ high
) / 2;
134 cmpres
= strcmp (str
, map
[med
].str
);
148 # define REASON(str) printf ("\"%s\" ignored: %s\n", buf, str)
158 while (! feof (stdin
))
168 if (fgets (buf
, sizeof (buf
), stdin
) == NULL
)
171 /* Split the fields. There are three is them:
173 2. langinfo() parameter
174 3. expected result; this can be a string with white space etc.
177 while (*rp
== ' ' || *rp
== '\t')
182 /* It's a comment line. Ignore it. */
188 while (*rp
!= '\0' && *rp
!= ' ' && *rp
!= '\t' && *rp
!= '\n')
190 if (*rp
== '\0' || *rp
== '\n')
192 /* Incomplete line. */
193 REASON ("incomplete line");
198 while (*rp
== ' ' || *rp
== '\t')
202 while (*rp
!= '\0' && *rp
!= ' ' && *rp
!= '\t' && *rp
!= '\n')
204 if (*rp
== '\0' || *rp
== '\n')
206 /* Incomplete line. */
207 REASON ("incomplete line");
212 while (*rp
== ' ' || *rp
== '\t')
219 expected
= wp
= ++rp
;
220 while (*rp
!= '"' && *rp
!= '\n' && *rp
!= '\0')
227 if (*rp
>= '0' && *rp
<= '9')
230 if (rp
[1] >= '0' && rp
[1] <= '9')
235 if (rp
[1] >= '0' && rp
[1] <= '9')
250 REASON ("missing '\"'");
259 while (*rp
!= '\0' && *rp
!= '\n')
264 param
= map_paramstr (paramstr
);
267 /* Invalid parameter. */
268 REASON ("invalid parameter");
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");
282 actual
= nl_langinfo (param
);
283 printf (" = \"%s\", ", actual
);
285 if (strcmp (actual
, expected
) == 0)
289 printf ("FAILED (expected: %s)\n", expected
);
297 #define TEST_FUNCTION do_test ()
298 #include "../test-skeleton.c"