|
Packit Service |
82fcde |
/* Test driver for nl_langinfo[_l] functions.
|
|
Packit Service |
82fcde |
Copyright (C) 2000-2018 Free Software Foundation, Inc.
|
|
Packit Service |
82fcde |
This file is part of the GNU C Library.
|
|
Packit Service |
82fcde |
Contributed by Ulrich Drepper <drepper@cygnus.com>.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
82fcde |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License as published by the Free Software Foundation; either
|
|
Packit Service |
82fcde |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
82fcde |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
82fcde |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
82fcde |
Lesser General Public License for more details.
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
82fcde |
License along with the GNU C Library; if not, see
|
|
Packit Service |
82fcde |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#include <langinfo.h>
|
|
Packit Service |
82fcde |
#include <locale.h>
|
|
Packit Service |
82fcde |
#include <stdio.h>
|
|
Packit Service |
82fcde |
#include <string.h>
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
struct map
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
const char *str;
|
|
Packit Service |
82fcde |
int val;
|
|
Packit Service |
82fcde |
} map[] =
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
#define VAL(name) { #name, name }
|
|
Packit Service |
82fcde |
VAL (ABDAY_1),
|
|
Packit Service |
82fcde |
VAL (ABDAY_2),
|
|
Packit Service |
82fcde |
VAL (ABDAY_3),
|
|
Packit Service |
82fcde |
VAL (ABDAY_4),
|
|
Packit Service |
82fcde |
VAL (ABDAY_5),
|
|
Packit Service |
82fcde |
VAL (ABDAY_6),
|
|
Packit Service |
82fcde |
VAL (ABDAY_7),
|
|
Packit Service |
82fcde |
VAL (ABMON_1),
|
|
Packit Service |
82fcde |
VAL (ABMON_10),
|
|
Packit Service |
82fcde |
VAL (ABMON_11),
|
|
Packit Service |
82fcde |
VAL (ABMON_12),
|
|
Packit Service |
82fcde |
VAL (ABMON_2),
|
|
Packit Service |
82fcde |
VAL (ABMON_3),
|
|
Packit Service |
82fcde |
VAL (ABMON_4),
|
|
Packit Service |
82fcde |
VAL (ABMON_5),
|
|
Packit Service |
82fcde |
VAL (ABMON_6),
|
|
Packit Service |
82fcde |
VAL (ABMON_7),
|
|
Packit Service |
82fcde |
VAL (ABMON_8),
|
|
Packit Service |
82fcde |
VAL (ABMON_9),
|
|
Packit Service |
82fcde |
VAL (ALT_DIGITS),
|
|
Packit Service |
82fcde |
VAL (ALTMON_1),
|
|
Packit Service |
82fcde |
VAL (ALTMON_10),
|
|
Packit Service |
82fcde |
VAL (ALTMON_11),
|
|
Packit Service |
82fcde |
VAL (ALTMON_12),
|
|
Packit Service |
82fcde |
VAL (ALTMON_2),
|
|
Packit Service |
82fcde |
VAL (ALTMON_3),
|
|
Packit Service |
82fcde |
VAL (ALTMON_4),
|
|
Packit Service |
82fcde |
VAL (ALTMON_5),
|
|
Packit Service |
82fcde |
VAL (ALTMON_6),
|
|
Packit Service |
82fcde |
VAL (ALTMON_7),
|
|
Packit Service |
82fcde |
VAL (ALTMON_8),
|
|
Packit Service |
82fcde |
VAL (ALTMON_9),
|
|
Packit Service |
82fcde |
VAL (AM_STR),
|
|
Packit Service |
82fcde |
VAL (CRNCYSTR),
|
|
Packit Service |
82fcde |
VAL (CURRENCY_SYMBOL),
|
|
Packit Service |
82fcde |
VAL (DAY_1),
|
|
Packit Service |
82fcde |
VAL (DAY_2),
|
|
Packit Service |
82fcde |
VAL (DAY_3),
|
|
Packit Service |
82fcde |
VAL (DAY_4),
|
|
Packit Service |
82fcde |
VAL (DAY_5),
|
|
Packit Service |
82fcde |
VAL (DAY_6),
|
|
Packit Service |
82fcde |
VAL (DAY_7),
|
|
Packit Service |
82fcde |
VAL (DECIMAL_POINT),
|
|
Packit Service |
82fcde |
VAL (D_FMT),
|
|
Packit Service |
82fcde |
VAL (D_T_FMT),
|
|
Packit Service |
82fcde |
VAL (ERA),
|
|
Packit Service |
82fcde |
VAL (ERA_D_FMT),
|
|
Packit Service |
82fcde |
VAL (ERA_D_T_FMT),
|
|
Packit Service |
82fcde |
VAL (ERA_T_FMT),
|
|
Packit Service |
82fcde |
VAL (ERA_YEAR),
|
|
Packit Service |
82fcde |
VAL (FRAC_DIGITS),
|
|
Packit Service |
82fcde |
VAL (GROUPING),
|
|
Packit Service |
82fcde |
VAL (INT_CURR_SYMBOL),
|
|
Packit Service |
82fcde |
VAL (INT_FRAC_DIGITS),
|
|
Packit Service |
82fcde |
VAL (MON_1),
|
|
Packit Service |
82fcde |
VAL (MON_10),
|
|
Packit Service |
82fcde |
VAL (MON_11),
|
|
Packit Service |
82fcde |
VAL (MON_12),
|
|
Packit Service |
82fcde |
VAL (MON_2),
|
|
Packit Service |
82fcde |
VAL (MON_3),
|
|
Packit Service |
82fcde |
VAL (MON_4),
|
|
Packit Service |
82fcde |
VAL (MON_5),
|
|
Packit Service |
82fcde |
VAL (MON_6),
|
|
Packit Service |
82fcde |
VAL (MON_7),
|
|
Packit Service |
82fcde |
VAL (MON_8),
|
|
Packit Service |
82fcde |
VAL (MON_9),
|
|
Packit Service |
82fcde |
VAL (MON_DECIMAL_POINT),
|
|
Packit Service |
82fcde |
VAL (MON_GROUPING),
|
|
Packit Service |
82fcde |
VAL (MON_THOUSANDS_SEP),
|
|
Packit Service |
82fcde |
VAL (NEGATIVE_SIGN),
|
|
Packit Service |
82fcde |
VAL (NOEXPR),
|
|
Packit Service |
82fcde |
VAL (NOSTR),
|
|
Packit Service |
82fcde |
VAL (N_CS_PRECEDES),
|
|
Packit Service |
82fcde |
VAL (N_SEP_BY_SPACE),
|
|
Packit Service |
82fcde |
VAL (N_SIGN_POSN),
|
|
Packit Service |
82fcde |
VAL (PM_STR),
|
|
Packit Service |
82fcde |
VAL (POSITIVE_SIGN),
|
|
Packit Service |
82fcde |
VAL (P_CS_PRECEDES),
|
|
Packit Service |
82fcde |
VAL (P_SEP_BY_SPACE),
|
|
Packit Service |
82fcde |
VAL (P_SIGN_POSN),
|
|
Packit Service |
82fcde |
VAL (RADIXCHAR),
|
|
Packit Service |
82fcde |
VAL (THOUSANDS_SEP),
|
|
Packit Service |
82fcde |
VAL (THOUSEP),
|
|
Packit Service |
82fcde |
VAL (T_FMT),
|
|
Packit Service |
82fcde |
VAL (T_FMT_AMPM),
|
|
Packit Service |
82fcde |
VAL (YESEXPR),
|
|
Packit Service |
82fcde |
VAL (YESSTR)
|
|
Packit Service |
82fcde |
};
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static int
|
|
Packit Service |
82fcde |
map_paramstr (const char *str)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int low = 0;
|
|
Packit Service |
82fcde |
int high = sizeof (map) / sizeof (map[0]);
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (low < high)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int med = (low + high) / 2;
|
|
Packit Service |
82fcde |
int cmpres;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
cmpres = strcmp (str, map[med].str);
|
|
Packit Service |
82fcde |
if (cmpres == 0)
|
|
Packit Service |
82fcde |
return map[med].val;
|
|
Packit Service |
82fcde |
else if (cmpres > 0)
|
|
Packit Service |
82fcde |
low = med + 1;
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
high = med;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return -1;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#ifdef DEBUG
|
|
Packit Service |
82fcde |
# define REASON(str) printf ("\"%s\" ignored: %s\n", buf, str)
|
|
Packit Service |
82fcde |
#else
|
|
Packit Service |
82fcde |
# define REASON(str)
|
|
Packit Service |
82fcde |
#endif
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
static int
|
|
Packit Service |
82fcde |
do_test (void)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int result = 0;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (! feof (stdin))
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
char buf[1000];
|
|
Packit Service |
82fcde |
char *rp;
|
|
Packit Service |
82fcde |
char *locale;
|
|
Packit Service |
82fcde |
char *paramstr;
|
|
Packit Service |
82fcde |
char *expected;
|
|
Packit Service |
82fcde |
int param;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (fgets (buf, sizeof (buf), stdin) == NULL)
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
/* Split the fields. There are three is them:
|
|
Packit Service |
82fcde |
1. locale
|
|
Packit Service |
82fcde |
2. langinfo() parameter
|
|
Packit Service |
82fcde |
3. expected result; this can be a string with white space etc.
|
|
Packit Service |
82fcde |
*/
|
|
Packit Service |
82fcde |
rp = buf;
|
|
Packit Service |
82fcde |
while (*rp == ' ' || *rp == '\t')
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (*rp == '#')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* It's a comment line. Ignore it. */
|
|
Packit Service |
82fcde |
REASON ("comment");
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
locale = rp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
if (*rp == '\0' || *rp == '\n')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Incomplete line. */
|
|
Packit Service |
82fcde |
REASON ("incomplete line");
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
*rp++ = '\0';
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (*rp == ' ' || *rp == '\t')
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
paramstr = rp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
if (*rp == '\0' || *rp == '\n')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Incomplete line. */
|
|
Packit Service |
82fcde |
REASON ("incomplete line");
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
*rp++ = '\0';
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
while (*rp == ' ' || *rp == '\t')
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (*rp == '"')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
char *wp;
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
expected = wp = ++rp;
|
|
Packit Service |
82fcde |
while (*rp != '"' && *rp != '\n' && *rp != '\0')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
if (*rp == '\\')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
if (*rp == '\0')
|
|
Packit Service |
82fcde |
break;
|
|
Packit Service |
82fcde |
if (*rp >= '0' && *rp <= '9')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
int val = *rp - '0';
|
|
Packit Service |
82fcde |
if (rp[1] >= '0' && rp[1] <= '9')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
val *= 10;
|
|
Packit Service |
82fcde |
val += *rp - '0';
|
|
Packit Service |
82fcde |
if (rp[1] >= '0' && rp[1] <= '9')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
val *= 10;
|
|
Packit Service |
82fcde |
val += *rp - '0';
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
*rp = val;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
*wp++ = *rp++;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
if (*rp != '"')
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
REASON ("missing '\"'");
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
*wp = '\0';
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
else
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
expected = rp;
|
|
Packit Service |
82fcde |
while (*rp != '\0' && *rp != '\n')
|
|
Packit Service |
82fcde |
++rp;
|
|
Packit Service |
82fcde |
*rp = '\0';
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
param = map_paramstr (paramstr);
|
|
Packit Service |
82fcde |
if (param == -1)
|
|
Packit Service |
82fcde |
{
|
|
Packit Service |
82fcde |
/* Invalid parameter. */
|
|
Packit Service |
82fcde |
REASON ("invalid parameter");
|
|
Packit Service |
82fcde |
continue;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
result = test_locale (locale, paramstr, param, expected);
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
return result;
|
|
Packit Service |
82fcde |
}
|
|
Packit Service |
82fcde |
|
|
Packit Service |
82fcde |
#define TEST_FUNCTION do_test ()
|
|
Packit Service |
82fcde |
#include "../test-skeleton.c"
|