Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update.
	* Makefile: Add rules to build, run, and distribute tst-langinfo.
	* tst-langinfo.c: New file.
	* tst-langinfo.sh: New file.
  • Loading branch information
Ulrich Drepper committed Jul 25, 2000
1 parent 71433ae commit f79d99c
Show file tree
Hide file tree
Showing 4 changed files with 576 additions and 3 deletions.
4 changes: 4 additions & 0 deletions localedata/ChangeLog
@@ -1,5 +1,9 @@
2000-07-24 Ulrich Drepper <drepper@redhat.com>

* Makefile: Add rules to build, run, and distribute tst-langinfo.
* tst-langinfo.c: New file.
* tst-langinfo.sh: New file.

* locales/ja_JP (era_d_t_fmt): Fix typo.

* Makefile: Add rules to build, run, and distribute tst-wctype.
Expand Down
11 changes: 8 additions & 3 deletions localedata/Makefile
Expand Up @@ -43,7 +43,7 @@ vpath %.h tests-mbwc

test-srcs := collate-test xfrm-test tst-fmon tst-rpmatch tst-trans \
tst-mbswcs1 tst-mbswcs2 tst-mbswcs3 tst-mbswcs4 tst-mbswcs5 \
tst-ctype tst-wctype
tst-ctype tst-wctype tst-langinfo
#test-input := de_DE.ISO-8859-1 da_DK.ISO-8859-1 fr_CA,2.13.ISO-8859-1 \
# hr_HR.ISO-8859-2 # once it is fixed: cs_CZ.ISO-8859-2
test-input := de_DE.ISO-8859-1 en_US.ISO-8859-1
Expand All @@ -70,7 +70,7 @@ distribute := CHECKSUMS README SUPPORTED ChangeLog \
th_TH.in cs_CZ.in tst-mbswcs.sh tst-trans.sh tst-ctype.sh \
tst-ctype-de_DE.in $(wildcard tests-mbwc/*.[ch]) \
$(addprefix tst-fmon-locales/tstfmon_,$(fmon-tests)) \
gen-locale.sh show-ucs-data.c \
gen-locale.sh show-ucs-data.c tst-langinfo.sh \
tst-wctype.sh tst-wctype.input

# Get $(inst_i18ndir) defined.
Expand Down Expand Up @@ -137,7 +137,8 @@ $(addsuffix .out,$(addprefix $(objpfx),$(locale_test_suite))): %: \

tests: $(objpfx)sort-test.out $(objpfx)tst-fmon.out $(objpfx)tst-locale.out \
$(objpfx)tst-rpmatch.out $(objpfx)tst-trans.out \
$(objpfx)tst-mbswcs.out $(objpfx)tst-ctype.out $(objpfx)tst-wctype.out
$(objpfx)tst-mbswcs.out $(objpfx)tst-ctype.out $(objpfx)tst-wctype.out \
$(objpfx)tst-langinfo.out

$(objpfx)sort-test.out: sort-test.sh $(objpfx)collate-test $(objpfx)xfrm-test \
$(test-input-data) $(addprefix $(objpfx),$(CTYPE_FILES))
Expand Down Expand Up @@ -171,6 +172,10 @@ $(objpfx)tst-wctype.out: tst-wctype.sh $(objpfx)tst-wctype \
$(objpfx)sort-test.out tst-wctype.input \
$(addprefix $(objpfx),$(CTYPE_FILES))
$(SHELL) -e $< $(common-objpfx) '$(built-program-cmd)'
$(objpfx)tst-langinfo.out: tst-langinfo.sh $(objpfx)tst-langinfo \
$(objpfx)sort-test.out \
$(addprefix $(objpfx),$(CTYPE_FILES))
$(SHELL) -e $< $(common-objpfx) '$(built-program-cmd)'
endif

# Sometimes the whole collection of locale files should be installed.
Expand Down
263 changes: 263 additions & 0 deletions localedata/tst-langinfo.c
@@ -0,0 +1,263 @@
#include <langinfo.h>
#include <locale.h>
#include <stdio.h>


struct map
{
const char *str;
int val;
} map[] =
{
#define VAL(name) { #name, name }
VAL (ABDAY_1),
VAL (ABDAY_2),
VAL (ABDAY_3),
VAL (ABDAY_4),
VAL (ABDAY_5),
VAL (ABDAY_6),
VAL (ABDAY_7),
VAL (ABMON_1),
VAL (ABMON_10),
VAL (ABMON_11),
VAL (ABMON_12),
VAL (ABMON_2),
VAL (ABMON_3),
VAL (ABMON_4),
VAL (ABMON_5),
VAL (ABMON_6),
VAL (ABMON_7),
VAL (ABMON_8),
VAL (ABMON_9),
VAL (ALT_DIGITS),
VAL (AM_STR),
VAL (CRNCYSTR),
VAL (CURRENCY_SYMBOL),
VAL (DAY_1),
VAL (DAY_2),
VAL (DAY_3),
VAL (DAY_4),
VAL (DAY_5),
VAL (DAY_6),
VAL (DAY_7),
VAL (DECIMAL_POINT),
VAL (D_FMT),
VAL (D_T_FMT),
VAL (ERA),
VAL (ERA_D_FMT),
VAL (ERA_D_T_FMT),
VAL (ERA_T_FMT),
VAL (ERA_YEAR),
VAL (FRAC_DIGITS),
VAL (GROUPING),
VAL (INT_CURR_SYMBOL),
VAL (INT_FRAC_DIGITS),
VAL (MON_1),
VAL (MON_10),
VAL (MON_11),
VAL (MON_12),
VAL (MON_2),
VAL (MON_3),
VAL (MON_4),
VAL (MON_5),
VAL (MON_6),
VAL (MON_7),
VAL (MON_8),
VAL (MON_9),
VAL (MON_DECIMAL_POINT),
VAL (MON_GROUPING),
VAL (MON_THOUSANDS_SEP),
VAL (NEGATIVE_SIGN),
VAL (NOEXPR),
VAL (NOSTR),
VAL (N_CS_PRECEDES),
VAL (N_SEP_BY_SPACE),
VAL (N_SIGN_POSN),
VAL (PM_STR),
VAL (POSITIVE_SIGN),
VAL (P_CS_PRECEDES),
VAL (P_SEP_BY_SPACE),
VAL (P_SIGN_POSN),
VAL (RADIXCHAR),
VAL (THOUSANDS_SEP),
VAL (THOUSEP),
VAL (T_FMT),
VAL (T_FMT_AMPM),
VAL (YESEXPR),
VAL (YESSTR)
};


static int
map_paramstr (const char *str)
{
int low = 0;
int high = sizeof (map) / sizeof (map[0]);

while (low < high)
{
int med = (low + high) / 2;
int cmpres;

cmpres = strcmp (str, map[med].str);
if (cmpres == 0)
return map[med].val;
else if (cmpres > 0)
low = med + 1;
else
high = med;
}

return -1;
}


#ifdef DEBUG
# define REASON(str) printf ("\"%s\" ignored: %s\n", buf, str)
#else
# define REASON(str)
#endif

int
main (void)
{
int result = 0;

while (! feof (stdin))
{
char buf[1000];
char *rp;
char *locale;
char *paramstr;
char *expected;
char *actual;
int param;

if (fgets (buf, sizeof (buf), stdin) == NULL)
break;

/* Split the fields. There are three is them:
1. locale
2. langinfo() parameter
3. expected result; this can be a string with white space etc.
*/
rp = buf;
while (*rp == ' ' || *rp == '\t')
++rp;

if (*rp == '#')
{
/* It's a comment line. Ignore it. */
REASON ("comment");
continue;
}
locale = rp;

while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
++rp;
if (*rp == '\0' || *rp == '\n')
{
/* Incomplete line. */
REASON ("incomplete line");
continue;
}
*rp++ = '\0';

while (*rp == ' ' || *rp == '\t')
++rp;
paramstr = rp;

while (*rp != '\0' && *rp != ' ' && *rp != '\t' && *rp != '\n')
++rp;
if (*rp == '\0' || *rp == '\n')
{
/* Incomplete line. */
REASON ("incomplete line");
continue;
}
*rp++ = '\0';

while (*rp == ' ' || *rp == '\t')
++rp;

if (*rp == '"')
{
char *wp;

expected = wp = ++rp;
while (*rp != '"' && *rp != '\n' && *rp != '\0')
{
if (*rp == '\\')
{
++rp;
if (*rp == '\0')
break;
if (*rp >= '\0' && *rp <= 'p')
{
int val = *rp - '0';
if (rp[1] >= '0' && rp[1] <= '9')
{
++rp;
val *= 10;
val += *rp - '0';
if (rp[1] >= '0' && rp[1] <= '9')
{
++rp;
val *= 10;
val += *rp - '0';
}
}
*rp = val;
}
}
*wp++ = *rp++;
}

if (*rp != '"')
{
REASON ("missing '\"'");
continue;
}

*wp = '\0';
}
else
{
expected = rp;
while (*rp != '\0' && *rp != '\n')
++rp;
*rp = '\0';
}

param = map_paramstr (paramstr);
if (param == -1)
{
/* Invalid parameter. */
REASON ("invalid parameter");
continue;
}

/* Set the locale and check whether it worked. */
printf ("LC_ALL=%s nl_langinfo(%s)", locale, paramstr);
setlocale (LC_ALL, locale);
if (strcmp (locale, setlocale (LC_ALL, NULL)) != 0)
{
puts (": failed to set locale");
result = 1;
continue;
}

actual = nl_langinfo (param);
printf (" = \"%s\", ", actual);

if (strcmp (actual, expected) == 0)
puts ("OK");
else
{
printf ("FAILED (expected: %s)\n", expected);
result = 1;
}
}

return result;
}

0 comments on commit f79d99c

Please sign in to comment.