1 /* Test program for nl_langinfo() function.
2 Copyright (C) 2000-2015 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 }
55 VAL (CURRENCY_SYMBOL
),
73 VAL (INT_CURR_SYMBOL
),
74 VAL (INT_FRAC_DIGITS
),
87 VAL (MON_DECIMAL_POINT
),
89 VAL (MON_THOUSANDS_SEP
),
112 map_paramstr (const char *str
)
115 int high
= sizeof (map
) / sizeof (map
[0]);
119 int med
= (low
+ high
) / 2;
122 cmpres
= strcmp (str
, map
[med
].str
);
136 # define REASON(str) printf ("\"%s\" ignored: %s\n", buf, str)
146 while (! feof (stdin
))
156 if (fgets (buf
, sizeof (buf
), stdin
) == NULL
)
159 /* Split the fields. There are three is them:
161 2. langinfo() parameter
162 3. expected result; this can be a string with white space etc.
165 while (*rp
== ' ' || *rp
== '\t')
170 /* It's a comment line. Ignore it. */
176 while (*rp
!= '\0' && *rp
!= ' ' && *rp
!= '\t' && *rp
!= '\n')
178 if (*rp
== '\0' || *rp
== '\n')
180 /* Incomplete line. */
181 REASON ("incomplete line");
186 while (*rp
== ' ' || *rp
== '\t')
190 while (*rp
!= '\0' && *rp
!= ' ' && *rp
!= '\t' && *rp
!= '\n')
192 if (*rp
== '\0' || *rp
== '\n')
194 /* Incomplete line. */
195 REASON ("incomplete line");
200 while (*rp
== ' ' || *rp
== '\t')
207 expected
= wp
= ++rp
;
208 while (*rp
!= '"' && *rp
!= '\n' && *rp
!= '\0')
215 if (*rp
>= '0' && *rp
<= '9')
218 if (rp
[1] >= '0' && rp
[1] <= '9')
223 if (rp
[1] >= '0' && rp
[1] <= '9')
238 REASON ("missing '\"'");
247 while (*rp
!= '\0' && *rp
!= '\n')
252 param
= map_paramstr (paramstr
);
255 /* Invalid parameter. */
256 REASON ("invalid parameter");
260 /* Set the locale and check whether it worked. */
261 printf ("LC_ALL=%s nl_langinfo(%s)", locale
, paramstr
);
262 setlocale (LC_ALL
, locale
);
263 if (strcmp (locale
, setlocale (LC_ALL
, NULL
)) != 0)
265 puts (": failed to set locale");
270 actual
= nl_langinfo (param
);
271 printf (" = \"%s\", ", actual
);
273 if (strcmp (actual
, expected
) == 0)
277 printf ("FAILED (expected: %s)\n", expected
);
285 #define TEST_FUNCTION do_test ()
286 #include "../test-skeleton.c"