1 /* Test locale dependence of strfmon_l.
2 Copyright (C) 2016-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
26 static const char *const en_us_name
= "en_US.ISO-8859-1";
28 /* Locale value to be used by tests. */
30 static const char *loc_name
;
32 /* Set the global locale to GLOBAL_NAME, and the locale referenced by
33 the loc variable above to LOCAL_NAME. */
35 init_loc (const char *global_name
, const char *local_name
)
37 loc
= newlocale (LC_ALL_MASK
, local_name
, 0);
40 printf ("error: newlocale (%s): %m\n", local_name
);
43 loc_name
= local_name
;
45 if (setlocale (LC_ALL
, global_name
) == NULL
)
47 printf ("error: setlocale (%s): %m\n", global_name
);
52 /* Expected strings for a positive or negative value. */
55 const char *i
; /* %i */
56 const char *n
; /* %n */
57 const char *i_ungrouped
; /* %^i */
58 const char *n_ungrouped
; /* %^n */
61 /* Collected expected strings for both positive and negative
65 struct testcase positive
; /* 1234567.89 */
66 struct testcase negative
; /* -1234567.89 */
71 /* Test one value using the locale loc. */
73 test_one (const char *format
, double value
, const char *expected
)
75 static char actual
[64];
76 int result
= strfmon_l (actual
, sizeof (actual
), loc
, format
, value
);
79 printf ("error: locale %s, format \"%s\", value %g: strfmon_l: %m\n",
80 loc_name
, format
, value
);
83 else if (strcmp (actual
, expected
) != 0)
85 printf ("error: locale %s, format \"%s\", value %g: mismatch\n",
86 loc_name
, format
, value
);
87 printf ("error: expected: \"%s\"\n", expected
);
88 printf ("error: actual: \"%s\"\n", actual
);
94 test_pair (const struct testcase_pair
*pair
)
96 double positive
= 1234567.89;
97 test_one ("%i", positive
, pair
->positive
.i
);
98 test_one ("%n", positive
, pair
->positive
.n
);
99 test_one ("%^i", positive
, pair
->positive
.i_ungrouped
);
100 test_one ("%^n", positive
, pair
->positive
.n_ungrouped
);
101 double negative
= -1234567.89;
102 test_one ("%i", negative
, pair
->negative
.i
);
103 test_one ("%n", negative
, pair
->negative
.n
);
104 test_one ("%^i", negative
, pair
->negative
.i_ungrouped
);
105 test_one ("%^n", negative
, pair
->negative
.n_ungrouped
);
108 static const struct testcase_pair en_us
=
111 "USD 1,234,567.89", "$1,234,567.89",
112 "USD 1234567.89", "$1234567.89"
115 "-USD 1,234,567.89", "-$1,234,567.89",
116 "-USD 1234567.89", "-$1234567.89"
121 test_en_us (const char *other_name
)
123 init_loc (other_name
, en_us_name
);
130 const char *locale_name
;
131 struct testcase_pair pair
;
134 static const struct locale_pair tests
[] =
140 "1.234.567,89 EUR", "1.234.567,89 \u20ac",
141 "1234567,89 EUR", "1234567,89 \u20ac"
144 "-1.234.567,89 EUR", "-1.234.567,89 \u20ac",
145 "-1234567,89 EUR", "-1234567,89 \u20ac"
153 "1 234 567.89 TJS", "1 234 567.89 \u0440\u0443\u0431",
154 "1234567.89 TJS", "1234567.89 \u0440\u0443\u0431"
157 "-1 234 567.89 TJS", "-1 234 567.89 \u0440\u0443\u0431",
158 "-1234567.89 TJS", "-1234567.89 \u0440\u0443\u0431"
166 "INR12,34,567.89", "\u20b912,34,567.89",
167 "INR1234567.89", "\u20b91234567.89"
170 "-INR12,34,567.89", "-\u20b912,34,567.89",
171 "-INR1234567.89", "-\u20b91234567.89"
179 "INR 12,345,67.89", "\u20b9 12,345,67.89",
180 "INR 1234567.89", "\u20b9 1234567.89"
183 "-INR 12,345,67.89", "-\u20b9 12,345,67.89",
184 "-INR 1234567.89", "-\u20b9 1234567.89"
192 "1.234.567,89EUR", "1.234.567,89\u20ac",
193 "1234567,89EUR", "1234567,89\u20ac"
196 "-EUR1.234.567,89", "-\u20ac1.234.567,89",
197 "-EUR1234567,89", "-\u20ac1234567,89",
207 for (const struct locale_pair
*test
= tests
;
208 test
->locale_name
!= NULL
; ++test
)
210 init_loc (en_us_name
, test
->locale_name
);
211 test_pair (&test
->pair
);
213 test_en_us (test
->locale_name
);
219 #define TEST_FUNCTION do_test ()
220 #include "../test-skeleton.c"