1 /* Test of duplicating a locale object.
2 Copyright (C) 2009-2016 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. */
23 #if HAVE_DUPLOCALE && HAVE_MONETARY_H
25 #include "signature.h"
26 SIGNATURE_CHECK (duplocale, locale_t, (locale_t));
35 struct locale_dependent_values
43 get_locale_dependent_values (struct locale_dependent_values *result)
45 strfmon (result->monetary, sizeof (result->monetary),
47 /* result->monetary is usually "$123.75" */
48 snprintf (result->numeric, sizeof (result->numeric),
50 /* result->numeric is usually "3,5" */
51 strcpy (result->time, nl_langinfo (MON_1));
52 /* result->time is usually "janvier" */
58 struct locale_dependent_values expected_results;
63 /* Set up a locale which is a mix between different system locales. */
64 setlocale (LC_ALL, "en_US.UTF-8");
65 setlocale (LC_NUMERIC, "de_DE.UTF-8");
66 setlocale (LC_TIME, "fr_FR.UTF-8");
67 get_locale_dependent_values (&expected_results);
69 /* Save the locale in a locale_t object. */
70 mixed1 = duplocale (LC_GLOBAL_LOCALE);
71 ASSERT (mixed1 != NULL);
73 /* Use a per-thread locale. */
74 perthread = newlocale (LC_ALL_MASK, "es_ES.UTF-8", NULL);
75 uselocale (perthread);
77 /* Save the locale in a locale_t object again. */
78 mixed2 = duplocale (LC_GLOBAL_LOCALE);
79 ASSERT (mixed2 != NULL);
81 /* Set up a default locale. */
82 setlocale (LC_ALL, "C");
83 uselocale (LC_GLOBAL_LOCALE);
85 struct locale_dependent_values c_results;
86 get_locale_dependent_values (&c_results);
89 /* Now use the saved locale mixed1 again. */
90 setlocale (LC_ALL, "C");
91 uselocale (LC_GLOBAL_LOCALE);
94 struct locale_dependent_values results;
95 get_locale_dependent_values (&results);
96 ASSERT (strcmp (results.monetary, expected_results.monetary) == 0);
97 ASSERT (strcmp (results.numeric, expected_results.numeric) == 0);
98 ASSERT (strcmp (results.time, expected_results.time) == 0);
101 /* Now use the saved locale mixed2 again. */
102 setlocale (LC_ALL, "C");
103 uselocale (LC_GLOBAL_LOCALE);
106 struct locale_dependent_values results;
107 get_locale_dependent_values (&results);
108 ASSERT (strcmp (results.monetary, expected_results.monetary) == 0);
109 ASSERT (strcmp (results.numeric, expected_results.numeric) == 0);
110 ASSERT (strcmp (results.time, expected_results.time) == 0);
113 setlocale (LC_ALL, "C");
116 freelocale (perthread);
127 fprintf (stderr, "Skipping test: function duplocale not available\n");