1 /* Test of gl_locale_name function and its variants.
2 Copyright (C) 2007-2020 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 <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
21 #include "localename.h"
29 #if HAVE_WORKING_NEWLOCALE && HAVE_WORKING_USELOCALE && !HAVE_FAKE_LOCALES
30 # define HAVE_GOOD_USELOCALE 1
34 #if HAVE_GOOD_USELOCALE
36 static struct { int cat
; int mask
; const char *string
; } const categories
[] =
38 { LC_CTYPE
, LC_CTYPE_MASK
, "LC_CTYPE" },
39 { LC_NUMERIC
, LC_NUMERIC_MASK
, "LC_NUMERIC" },
40 { LC_TIME
, LC_TIME_MASK
, "LC_TIME" },
41 { LC_COLLATE
, LC_COLLATE_MASK
, "LC_COLLATE" },
42 { LC_MONETARY
, LC_MONETARY_MASK
, "LC_MONETARY" },
43 { LC_MESSAGES
, LC_MESSAGES_MASK
, "LC_MESSAGES" }
45 , { LC_PAPER
, LC_PAPER_MASK
, "LC_PAPER" }
48 , { LC_NAME
, LC_NAME_MASK
, "LC_NAME" }
51 , { LC_ADDRESS
, LC_ADDRESS_MASK
, "LC_ADDRESS" }
54 , { LC_TELEPHONE
, LC_TELEPHONE_MASK
, "LC_TELEPHONE" }
56 # ifdef LC_MEASUREMENT
57 , { LC_MEASUREMENT
, LC_MEASUREMENT_MASK
, "LC_MEASUREMENT" }
59 # ifdef LC_IDENTIFICATION
60 , { LC_IDENTIFICATION
, LC_IDENTIFICATION_MASK
, "LC_IDENTIFICATION" }
66 /* Test the gl_locale_name() function. */
68 test_locale_name (void)
73 /* Check that gl_locale_name returns non-NULL. */
74 ASSERT (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES") != NULL
);
76 /* Get into a defined state, */
77 setlocale (LC_ALL
, "en_US.UTF-8");
78 #if HAVE_GOOD_USELOCALE
79 uselocale (LC_GLOBAL_LOCALE
);
82 /* Check that when all environment variables are unset,
83 gl_locale_name returns the default locale. */
85 unsetenv ("LC_CTYPE");
86 unsetenv ("LC_MESSAGES");
87 unsetenv ("LC_NUMERIC");
89 /* Need also to unset all environment variables that specify standard or
90 non-standard locale categories. Otherwise, on glibc systems, when some
91 of these variables are set and reference a nonexistent locale, the
92 setlocale (LC_ALL, "") call below would fail. */
93 unsetenv ("LC_COLLATE");
94 unsetenv ("LC_MONETARY");
96 unsetenv ("LC_ADDRESS");
97 unsetenv ("LC_IDENTIFICATION");
98 unsetenv ("LC_MEASUREMENT");
100 unsetenv ("LC_PAPER");
101 unsetenv ("LC_TELEPHONE");
102 ret
= setlocale (LC_ALL
, "");
103 ASSERT (ret
!= NULL
);
104 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"),
105 gl_locale_name_default ()) == 0);
106 ASSERT (strcmp (gl_locale_name (LC_NUMERIC
, "LC_NUMERIC"),
107 gl_locale_name_default ()) == 0);
109 /* Check that an empty environment variable is treated like an unset
110 environment variable. */
112 setenv ("LC_ALL", "", 1);
113 unsetenv ("LC_CTYPE");
114 unsetenv ("LC_MESSAGES");
116 setlocale (LC_ALL
, "");
117 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"),
118 gl_locale_name_default ()) == 0);
121 setenv ("LC_CTYPE", "", 1);
122 unsetenv ("LC_MESSAGES");
124 setlocale (LC_ALL
, "");
125 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"),
126 gl_locale_name_default ()) == 0);
129 unsetenv ("LC_CTYPE");
130 setenv ("LC_MESSAGES", "", 1);
132 setlocale (LC_ALL
, "");
133 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"),
134 gl_locale_name_default ()) == 0);
137 unsetenv ("LC_CTYPE");
138 unsetenv ("LC_MESSAGES");
139 setenv ("LANG", "", 1);
140 setlocale (LC_ALL
, "");
141 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"),
142 gl_locale_name_default ()) == 0);
144 /* Check that LC_ALL overrides the others, and LANG is overridden by the
147 setenv ("LC_ALL", "C", 1);
148 unsetenv ("LC_CTYPE");
149 unsetenv ("LC_MESSAGES");
151 setlocale (LC_ALL
, "");
152 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"), "C") == 0);
155 setenv ("LC_CTYPE", "C", 1);
156 setenv ("LC_MESSAGES", "C", 1);
158 setlocale (LC_ALL
, "");
159 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"), "C") == 0);
162 unsetenv ("LC_CTYPE");
163 unsetenv ("LC_MESSAGES");
164 setenv ("LANG", "C", 1);
165 setlocale (LC_ALL
, "");
166 ASSERT (strcmp (gl_locale_name (LC_MESSAGES
, "LC_MESSAGES"), "C") == 0);
168 /* Check mixed situations. */
171 unsetenv ("LC_CTYPE");
172 setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
173 setenv ("LANG", "de_DE.UTF-8", 1);
174 if (setlocale (LC_ALL
, "") != NULL
)
176 name
= gl_locale_name (LC_CTYPE
, "LC_CTYPE");
177 #if defined _WIN32 && !defined __CYGWIN__
178 /* On native Windows, here,
179 gl_locale_name_thread (LC_CTYPE, "LC_CTYPE")
181 gl_locale_name_posix (LC_CTYPE, "LC_CTYPE")
182 returns either "de_DE" or "de_DE.UTF-8". */
183 ASSERT (strcmp (name
, "de_DE") == 0 || strcmp (name
, "de_DE.UTF-8") == 0);
185 ASSERT (strcmp (name
, "de_DE.UTF-8") == 0);
187 name
= gl_locale_name (LC_MESSAGES
, "LC_MESSAGES");
188 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
192 unsetenv ("LC_CTYPE");
193 setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
195 if (setlocale (LC_ALL
, "") != NULL
)
197 name
= gl_locale_name (LC_CTYPE
, "LC_CTYPE");
198 ASSERT (strcmp (name
, gl_locale_name_default ()) == 0);
199 name
= gl_locale_name (LC_MESSAGES
, "LC_MESSAGES");
200 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
203 #if HAVE_GOOD_USELOCALE
204 /* Check that gl_locale_name considers the thread locale. */
206 locale_t locale
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
210 name
= gl_locale_name (LC_CTYPE
, "LC_CTYPE");
211 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
212 name
= gl_locale_name (LC_MESSAGES
, "LC_MESSAGES");
213 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
214 uselocale (LC_GLOBAL_LOCALE
);
219 /* Check that gl_locale_name distinguishes different categories of the
220 thread locale, and that the name is the right one for each. */
224 for (i
= 0; i
< SIZEOF (categories
); i
++)
226 int category_mask
= categories
[i
].mask
;
227 locale_t loc
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
230 locale_t locale
= newlocale (category_mask
, "de_DE.UTF-8", loc
);
238 for (j
= 0; j
< SIZEOF (categories
); j
++)
241 gl_locale_name (categories
[j
].cat
, categories
[j
].string
);
243 ASSERT (strcmp (name_j
, "de_DE.UTF-8") == 0);
245 ASSERT (strcmp (name_j
, "fr_FR.UTF-8") == 0);
247 uselocale (LC_GLOBAL_LOCALE
);
256 /* Test the gl_locale_name_thread() function. */
258 test_locale_name_thread (void)
260 /* Get into a defined state, */
261 setlocale (LC_ALL
, "en_US.UTF-8");
263 #if HAVE_GOOD_USELOCALE
264 /* Check that gl_locale_name_thread returns NULL when no thread locale is
266 uselocale (LC_GLOBAL_LOCALE
);
267 ASSERT (gl_locale_name_thread (LC_CTYPE
, "LC_CTYPE") == NULL
);
268 ASSERT (gl_locale_name_thread (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
270 /* Check that gl_locale_name_thread considers the thread locale. */
272 locale_t locale
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
278 name
= gl_locale_name_thread (LC_CTYPE
, "LC_CTYPE");
279 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
280 name
= gl_locale_name_thread (LC_MESSAGES
, "LC_MESSAGES");
281 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
282 uselocale (LC_GLOBAL_LOCALE
);
287 /* Check that gl_locale_name_thread distinguishes different categories of the
288 thread locale, and that the name is the right one for each. */
292 for (i
= 0; i
< SIZEOF (categories
); i
++)
294 int category_mask
= categories
[i
].mask
;
295 locale_t loc
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
298 locale_t locale
= newlocale (category_mask
, "de_DE.UTF-8", loc
);
306 for (j
= 0; j
< SIZEOF (categories
); j
++)
309 gl_locale_name_thread (categories
[j
].cat
,
310 categories
[j
].string
);
312 ASSERT (strcmp (name_j
, "de_DE.UTF-8") == 0);
314 ASSERT (strcmp (name_j
, "fr_FR.UTF-8") == 0);
316 uselocale (LC_GLOBAL_LOCALE
);
323 /* Check that gl_locale_name_thread returns a string that is allocated with
324 indefinite extent. */
326 /* Try many locale names in turn, in order to defeat possible caches. */
327 static const char * const choices
[] =
433 /* Remember which locales are available. */
434 unsigned char /* bool */ available
[SIZEOF (choices
)];
435 /* Array of remembered results of gl_locale_name_thread. */
436 const char *unsaved_names
[SIZEOF (choices
)][SIZEOF (categories
)];
437 /* Array of remembered results of gl_locale_name_thread, stored in safe
439 char *saved_names
[SIZEOF (choices
)][SIZEOF (categories
)];
442 for (j
= 0; j
< SIZEOF (choices
); j
++)
444 locale_t locale
= newlocale (LC_ALL_MASK
, choices
[j
], NULL
);
445 available
[j
] = (locale
!= NULL
);
451 for (i
= 0; i
< SIZEOF (categories
); i
++)
453 unsaved_names
[j
][i
] = gl_locale_name_thread (categories
[i
].cat
, categories
[i
].string
);
454 saved_names
[j
][i
] = strdup (unsaved_names
[j
][i
]);
456 uselocale (LC_GLOBAL_LOCALE
);
460 /* Verify the unsaved_names are still valid. */
461 for (j
= 0; j
< SIZEOF (choices
); j
++)
466 for (i
= 0; i
< SIZEOF (categories
); i
++)
467 ASSERT (strcmp (unsaved_names
[j
][i
], saved_names
[j
][i
]) == 0);
469 /* Allocate many locales, without freeing them. This is an attempt at
470 overwriting as much of the previously allocated memory as possible. */
471 for (j
= SIZEOF (choices
); j
> 0; )
476 locale_t locale
= newlocale (LC_ALL_MASK
, choices
[j
], NULL
);
479 ASSERT (locale
!= NULL
);
481 for (i
= 0; i
< SIZEOF (categories
); i
++)
483 const char *name
= gl_locale_name_thread (categories
[i
].cat
, categories
[i
].string
);
484 ASSERT (strcmp (unsaved_names
[j
][i
], name
) == 0);
486 uselocale (LC_GLOBAL_LOCALE
);
490 /* Verify the unsaved_names are still valid. */
491 for (j
= 0; j
< SIZEOF (choices
); j
++)
496 for (i
= 0; i
< SIZEOF (categories
); i
++)
498 ASSERT (strcmp (unsaved_names
[j
][i
], saved_names
[j
][i
]) == 0);
499 free (saved_names
[j
][i
]);
504 /* Check that gl_locale_name_thread always returns NULL. */
505 ASSERT (gl_locale_name_thread (LC_CTYPE
, "LC_CTYPE") == NULL
);
506 ASSERT (gl_locale_name_thread (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
510 /* Test the gl_locale_name_posix() function. */
512 test_locale_name_posix (void)
517 /* Get into a defined state, */
518 setlocale (LC_ALL
, "en_US.UTF-8");
519 #if HAVE_GOOD_USELOCALE
520 uselocale (LC_GLOBAL_LOCALE
);
523 /* Check that when all environment variables are unset,
524 gl_locale_name_posix returns either NULL or the default locale. */
526 unsetenv ("LC_CTYPE");
527 unsetenv ("LC_MESSAGES");
528 unsetenv ("LC_NUMERIC");
530 /* Need also to unset all environment variables that specify standard or
531 non-standard locale categories. Otherwise, on glibc systems, when some
532 of these variables are set and reference a nonexistent locale, the
533 setlocale (LC_ALL, "") call below would fail. */
534 unsetenv ("LC_COLLATE");
535 unsetenv ("LC_MONETARY");
536 unsetenv ("LC_TIME");
537 unsetenv ("LC_ADDRESS");
538 unsetenv ("LC_IDENTIFICATION");
539 unsetenv ("LC_MEASUREMENT");
540 unsetenv ("LC_NAME");
541 unsetenv ("LC_PAPER");
542 unsetenv ("LC_TELEPHONE");
543 ret
= setlocale (LC_ALL
, "");
544 ASSERT (ret
!= NULL
);
545 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
546 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
547 name
= gl_locale_name_posix (LC_NUMERIC
, "LC_NUMERIC");
548 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
550 /* Check that an empty environment variable is treated like an unset
551 environment variable. */
553 setenv ("LC_ALL", "", 1);
554 unsetenv ("LC_CTYPE");
555 unsetenv ("LC_MESSAGES");
557 setlocale (LC_ALL
, "");
558 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
559 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
562 setenv ("LC_CTYPE", "", 1);
563 unsetenv ("LC_MESSAGES");
565 setlocale (LC_ALL
, "");
566 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
567 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
570 unsetenv ("LC_CTYPE");
571 setenv ("LC_MESSAGES", "", 1);
573 setlocale (LC_ALL
, "");
574 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
575 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
578 unsetenv ("LC_CTYPE");
579 unsetenv ("LC_MESSAGES");
580 setenv ("LANG", "", 1);
581 setlocale (LC_ALL
, "");
582 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
583 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
585 /* Check that LC_ALL overrides the others, and LANG is overridden by the
588 setenv ("LC_ALL", "C", 1);
589 unsetenv ("LC_CTYPE");
590 unsetenv ("LC_MESSAGES");
592 setlocale (LC_ALL
, "");
593 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
594 ASSERT (strcmp (name
, "C") == 0);
597 setenv ("LC_CTYPE", "C", 1);
598 setenv ("LC_MESSAGES", "C", 1);
600 setlocale (LC_ALL
, "");
601 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
602 ASSERT (strcmp (name
, "C") == 0);
605 unsetenv ("LC_CTYPE");
606 unsetenv ("LC_MESSAGES");
607 setenv ("LANG", "C", 1);
608 setlocale (LC_ALL
, "");
609 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
610 ASSERT (strcmp (name
, "C") == 0);
612 /* Check mixed situations. */
615 unsetenv ("LC_CTYPE");
616 setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
617 setenv ("LANG", "de_DE.UTF-8", 1);
618 if (setlocale (LC_ALL
, "") != NULL
)
620 name
= gl_locale_name_posix (LC_CTYPE
, "LC_CTYPE");
621 #if defined _WIN32 && !defined __CYGWIN__
622 ASSERT (strcmp (name
, "de_DE") == 0 || strcmp (name
, "de_DE.UTF-8") == 0);
624 ASSERT (strcmp (name
, "de_DE.UTF-8") == 0);
626 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
627 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
631 unsetenv ("LC_CTYPE");
632 setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
634 if (setlocale (LC_ALL
, "") != NULL
)
636 name
= gl_locale_name_posix (LC_CTYPE
, "LC_CTYPE");
637 ASSERT (name
== NULL
|| strcmp (name
, gl_locale_name_default ()) == 0);
638 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
639 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
642 #if HAVE_GOOD_USELOCALE
643 /* Check that gl_locale_name_posix ignores the thread locale. */
645 locale_t locale
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
649 unsetenv ("LC_CTYPE");
650 unsetenv ("LC_MESSAGES");
651 setenv ("LANG", "C", 1);
652 setlocale (LC_ALL
, "");
654 name
= gl_locale_name_posix (LC_MESSAGES
, "LC_MESSAGES");
655 ASSERT (strcmp (name
, "C") == 0);
656 uselocale (LC_GLOBAL_LOCALE
);
663 /* Test the gl_locale_name_environ() function. */
665 test_locale_name_environ (void)
669 /* Get into a defined state, */
670 setlocale (LC_ALL
, "en_US.UTF-8");
671 #if HAVE_GOOD_USELOCALE
672 uselocale (LC_GLOBAL_LOCALE
);
675 /* Check that when all environment variables are unset,
676 gl_locale_name_environ returns NULL. */
678 unsetenv ("LC_CTYPE");
679 unsetenv ("LC_MESSAGES");
680 unsetenv ("LC_NUMERIC");
682 ASSERT (gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
683 ASSERT (gl_locale_name_environ (LC_NUMERIC
, "LC_NUMERIC") == NULL
);
685 /* Check that an empty environment variable is treated like an unset
686 environment variable. */
688 setenv ("LC_ALL", "", 1);
689 unsetenv ("LC_CTYPE");
690 unsetenv ("LC_MESSAGES");
692 ASSERT (gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
695 setenv ("LC_CTYPE", "", 1);
696 unsetenv ("LC_MESSAGES");
698 ASSERT (gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
701 unsetenv ("LC_CTYPE");
702 setenv ("LC_MESSAGES", "", 1);
704 ASSERT (gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
707 unsetenv ("LC_CTYPE");
708 unsetenv ("LC_MESSAGES");
709 setenv ("LANG", "", 1);
710 ASSERT (gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES") == NULL
);
712 /* Check that LC_ALL overrides the others, and LANG is overridden by the
715 setenv ("LC_ALL", "C", 1);
716 unsetenv ("LC_CTYPE");
717 unsetenv ("LC_MESSAGES");
719 name
= gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES");
720 ASSERT (strcmp (name
, "C") == 0);
723 setenv ("LC_CTYPE", "C", 1);
724 setenv ("LC_MESSAGES", "C", 1);
726 name
= gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES");
727 ASSERT (strcmp (name
, "C") == 0);
730 unsetenv ("LC_CTYPE");
731 unsetenv ("LC_MESSAGES");
732 setenv ("LANG", "C", 1);
733 name
= gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES");
734 ASSERT (strcmp (name
, "C") == 0);
736 /* Check mixed situations. */
739 unsetenv ("LC_CTYPE");
740 setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
741 setenv ("LANG", "de_DE.UTF-8", 1);
742 name
= gl_locale_name_environ (LC_CTYPE
, "LC_CTYPE");
743 ASSERT (strcmp (name
, "de_DE.UTF-8") == 0);
744 name
= gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES");
745 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
748 unsetenv ("LC_CTYPE");
749 setenv ("LC_MESSAGES", "fr_FR.UTF-8", 1);
751 name
= gl_locale_name_environ (LC_CTYPE
, "LC_CTYPE");
752 ASSERT (name
== NULL
);
753 name
= gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES");
754 ASSERT (strcmp (name
, "fr_FR.UTF-8") == 0);
756 #if HAVE_GOOD_USELOCALE
757 /* Check that gl_locale_name_environ ignores the thread locale. */
759 locale_t locale
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
763 unsetenv ("LC_CTYPE");
764 unsetenv ("LC_MESSAGES");
765 setenv ("LANG", "C", 1);
766 setlocale (LC_ALL
, "");
768 name
= gl_locale_name_environ (LC_MESSAGES
, "LC_MESSAGES");
769 ASSERT (strcmp (name
, "C") == 0);
770 uselocale (LC_GLOBAL_LOCALE
);
777 /* Test the gl_locale_name_default() function. */
779 test_locale_name_default (void)
781 const char *name
= gl_locale_name_default ();
783 ASSERT (name
!= NULL
);
785 /* Only Mac OS X and Windows have a facility for the user to set the default
787 #if !((defined __APPLE__ && defined __MACH__) || (defined _WIN32 || defined __CYGWIN__))
788 ASSERT (strcmp (name
, "C") == 0);
791 #if HAVE_GOOD_USELOCALE
792 /* Check that gl_locale_name_default ignores the thread locale. */
794 locale_t locale
= newlocale (LC_ALL_MASK
, "fr_FR.UTF-8", NULL
);
798 ASSERT (strcmp (gl_locale_name_default (), name
) == 0);
799 uselocale (LC_GLOBAL_LOCALE
);
810 test_locale_name_thread ();
811 test_locale_name_posix ();
812 test_locale_name_environ ();
813 test_locale_name_default ();