1 /* Test of duplicating a locale object.
2 Copyright (C) 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
31 #define ASSERT(expr) \
36 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
43 struct locale_dependent_values
51 get_locale_dependent_values (struct locale_dependent_values *result)
53 strfmon (result->monetary, sizeof (result->monetary),
55 /* result->monetary is usually "$123.75" */
56 snprintf (result->numeric, sizeof (result->numeric),
58 /* result->numeric is usually "3,5" */
59 strcpy (result->time, nl_langinfo (MON_1));
60 /* result->time is usually "janvier" */
66 struct locale_dependent_values expected_results;
70 /* Set up a locale which is a mix between different system locales. */
71 setlocale (LC_ALL, "en_US.UTF-8");
72 setlocale (LC_NUMERIC, "de_DE.UTF-8");
73 setlocale (LC_TIME, "fr_FR.UTF-8");
74 get_locale_dependent_values (&expected_results);
76 /* Save the locale in a locale_t object. */
77 mixed1 = duplocale (LC_GLOBAL_LOCALE);
78 ASSERT (mixed1 != NULL);
80 /* Use a per-thread locale. */
81 uselocale (newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL));
83 /* Save the locale in a locale_t object again. */
84 mixed2 = duplocale (LC_GLOBAL_LOCALE);
85 ASSERT (mixed2 != NULL);
87 /* Set up a default locale. */
88 setlocale (LC_ALL, "C");
89 uselocale (LC_GLOBAL_LOCALE);
91 struct locale_dependent_values c_results;
92 get_locale_dependent_values (&c_results);
95 /* Now use the saved locale mixed1 again. */
96 setlocale (LC_ALL, "C");
97 uselocale (LC_GLOBAL_LOCALE);
100 struct locale_dependent_values results;
101 get_locale_dependent_values (&results);
102 ASSERT (strcmp (results.monetary, expected_results.monetary) == 0);
103 ASSERT (strcmp (results.numeric, expected_results.numeric) == 0);
104 ASSERT (strcmp (results.time, expected_results.time) == 0);
107 /* Now use the saved locale mixed2 again. */
108 setlocale (LC_ALL, "C");
109 uselocale (LC_GLOBAL_LOCALE);
112 struct locale_dependent_values results;
113 get_locale_dependent_values (&results);
114 ASSERT (strcmp (results.monetary, expected_results.monetary) == 0);
115 ASSERT (strcmp (results.numeric, expected_results.numeric) == 0);
116 ASSERT (strcmp (results.time, expected_results.time) == 0);