mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-27 04:41:02 +08:00
5a82c74822
Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
239 lines
6.3 KiB
C
239 lines
6.3 KiB
C
/* Test locale dependence of strfmon_l.
|
|
Copyright (C) 2016-2019 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include <monetary.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <locale.h>
|
|
|
|
static const char *const en_us_name = "en_US.ISO-8859-1";
|
|
|
|
/* Locale value to be used by tests. */
|
|
static locale_t loc;
|
|
static const char *loc_name;
|
|
|
|
/* Set the global locale to GLOBAL_NAME, and the locale referenced by
|
|
the loc variable above to LOCAL_NAME. */
|
|
static void
|
|
init_loc (const char *global_name, const char *local_name)
|
|
{
|
|
loc = newlocale (LC_ALL_MASK, local_name, 0);
|
|
if (loc == 0)
|
|
{
|
|
printf ("error: newlocale (%s): %m\n", local_name);
|
|
abort ();
|
|
}
|
|
loc_name = local_name;
|
|
|
|
if (setlocale (LC_ALL, global_name) == NULL)
|
|
{
|
|
printf ("error: setlocale (%s): %m\n", global_name);
|
|
abort ();
|
|
}
|
|
}
|
|
|
|
/* Expected strings for a positive or negative value. */
|
|
struct testcase
|
|
{
|
|
const char *i; /* %i */
|
|
const char *n; /* %n */
|
|
const char *i_ungrouped; /* %^i */
|
|
const char *n_ungrouped; /* %^n */
|
|
};
|
|
|
|
/* Collected expected strings for both positive and negative
|
|
values. */
|
|
struct testcase_pair
|
|
{
|
|
struct testcase positive; /* 1234567.89 */
|
|
struct testcase negative; /* -1234567.89 */
|
|
};
|
|
|
|
static bool errors;
|
|
|
|
/* Test one value using the locale loc. */
|
|
static void
|
|
test_one (const char *format, double value, const char *ldformat,
|
|
long double ldvalue, const char *expected)
|
|
{
|
|
static char actual[64], actualld[64];
|
|
int result = strfmon_l (actual, sizeof (actual), loc, format, value);
|
|
int res_ld = strfmon_l (actualld, sizeof (actualld), loc, ldformat, ldvalue);
|
|
if (result < 0)
|
|
{
|
|
printf ("error: locale %s, format \"%s\", value %g: strfmon_l: %m\n",
|
|
loc_name, format, value);
|
|
errors = true;
|
|
}
|
|
else if (res_ld < 0)
|
|
{
|
|
printf ("error: locale %s, format \"%s\", value %Lg: strfmon_l: %m\n",
|
|
loc_name, ldformat, ldvalue);
|
|
errors = true;
|
|
}
|
|
else if (strcmp (actual, expected) != 0)
|
|
{
|
|
printf ("error: locale %s, format \"%s\", value %g: mismatch\n",
|
|
loc_name, format, value);
|
|
printf ("error: expected: \"%s\"\n", expected);
|
|
printf ("error: actual: \"%s\"\n", actual);
|
|
errors = true;
|
|
}
|
|
else if (strcmp (actualld, expected) != 0)
|
|
{
|
|
printf ("error: locale %s, format \"%s\", value %Lg: mismatch\n",
|
|
loc_name, ldformat, ldvalue);
|
|
printf ("error: expected: \"%s\"\n", expected);
|
|
printf ("error: actual: \"%s\"\n", actualld);
|
|
errors = true;
|
|
}
|
|
}
|
|
|
|
static void
|
|
test_pair (const struct testcase_pair *pair)
|
|
{
|
|
double positive = 1234567.89;
|
|
long double pos = 1234567.89L;
|
|
test_one ("%i", positive, "%Li", pos, pair->positive.i);
|
|
test_one ("%n", positive, "%Ln", pos, pair->positive.n);
|
|
test_one ("%^i", positive, "%^Li", pos, pair->positive.i_ungrouped);
|
|
test_one ("%^n", positive, "%^Ln", pos, pair->positive.n_ungrouped);
|
|
double negative = -1234567.89;
|
|
long double neg = -1234567.89L;
|
|
test_one ("%i", negative, "%Li", neg, pair->negative.i);
|
|
test_one ("%n", negative, "%Ln", neg, pair->negative.n);
|
|
test_one ("%^i", negative, "%^Li", neg, pair->negative.i_ungrouped);
|
|
test_one ("%^n", negative, "%^Ln", neg, pair->negative.n_ungrouped);
|
|
}
|
|
|
|
static const struct testcase_pair en_us =
|
|
{
|
|
{
|
|
"USD 1,234,567.89", "$1,234,567.89",
|
|
"USD 1234567.89", "$1234567.89"
|
|
},
|
|
{
|
|
"-USD 1,234,567.89", "-$1,234,567.89",
|
|
"-USD 1234567.89", "-$1234567.89"
|
|
}
|
|
};
|
|
|
|
static void
|
|
test_en_us (const char *other_name)
|
|
{
|
|
init_loc (other_name, en_us_name);
|
|
test_pair (&en_us);
|
|
freelocale (loc);
|
|
}
|
|
|
|
struct locale_pair
|
|
{
|
|
const char *locale_name;
|
|
struct testcase_pair pair;
|
|
};
|
|
|
|
static const struct locale_pair tests[] =
|
|
{
|
|
{
|
|
"de_DE.UTF-8",
|
|
{
|
|
{
|
|
"1.234.567,89 EUR", "1.234.567,89 \u20ac",
|
|
"1234567,89 EUR", "1234567,89 \u20ac"
|
|
},
|
|
{
|
|
"-1.234.567,89 EUR", "-1.234.567,89 \u20ac",
|
|
"-1234567,89 EUR", "-1234567,89 \u20ac"
|
|
}
|
|
},
|
|
},
|
|
{
|
|
"tg_TJ.UTF-8",
|
|
{
|
|
{
|
|
"1\u202f234\u202f567.89 TJS", "1\u202f234\u202f567.89 \u0440\u0443\u0431",
|
|
"1234567.89 TJS", "1234567.89 \u0440\u0443\u0431"
|
|
},
|
|
{
|
|
"-1\u202f234\u202f567.89 TJS", "-1\u202f234\u202f567.89 \u0440\u0443\u0431",
|
|
"-1234567.89 TJS", "-1234567.89 \u0440\u0443\u0431"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"hr_HR.UTF-8",
|
|
{
|
|
{
|
|
"HRK 1.234.567,89", "1.234.567,89 kn",
|
|
"HRK 1234567,89", "1234567,89 kn"
|
|
},
|
|
{
|
|
"-HRK 1.234.567,89", "-1.234.567,89 kn",
|
|
"-HRK 1234567,89", "-1234567,89 kn"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"hi_IN.UTF-8",
|
|
{
|
|
{
|
|
"INR12,34,567.89", "\u20b912,34,567.89",
|
|
"INR1234567.89", "\u20b91234567.89"
|
|
},
|
|
{
|
|
"-INR12,34,567.89", "-\u20b912,34,567.89",
|
|
"-INR1234567.89", "-\u20b91234567.89"
|
|
}
|
|
}
|
|
},
|
|
{
|
|
"el_GR.UTF-8",
|
|
{
|
|
{
|
|
"1.234.567,89EUR", "1.234.567,89\u20ac",
|
|
"1234567,89EUR", "1234567,89\u20ac"
|
|
},
|
|
{
|
|
"-1.234.567,89EUR", "-1.234.567,89\u20ac",
|
|
"-1234567,89EUR", "-1234567,89\u20ac",
|
|
}
|
|
}
|
|
},
|
|
{}
|
|
};
|
|
|
|
static int
|
|
do_test (void)
|
|
{
|
|
for (const struct locale_pair *test = tests;
|
|
test->locale_name != NULL; ++test)
|
|
{
|
|
init_loc (en_us_name, test->locale_name);
|
|
test_pair (&test->pair);
|
|
freelocale (loc);
|
|
test_en_us (test->locale_name);
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#include "../test-skeleton.c"
|