]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/locale/cons/5.cc
1 // { dg-require-namedlocale "de_DE" }
2 // { dg-require-namedlocale "en_PH" }
3 // { dg-require-namedlocale "es_MX" }
4 // { dg-require-namedlocale "fr_FR" }
5 // { dg-require-namedlocale "it_IT" }
7 // 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
9 // Copyright (C) 2000-2024 Free Software Foundation, Inc.
11 // This file is part of the GNU ISO C++ Library. This library is free
12 // software; you can redistribute it and/or modify it under the
13 // terms of the GNU General Public License as published by the
14 // Free Software Foundation; either version 3, or (at your option)
17 // This library is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
22 // You should have received a copy of the GNU General Public License along
23 // with this library; see the file COPYING3. If not see
24 // <http://www.gnu.org/licenses/>.
26 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
28 #include <cwchar> // for mbstate_t
33 #include <testsuite_hooks.h>
35 // More tests for locale("") == POSIX locale::name.
40 #ifdef _GLIBCXX_HAVE_SETENV
42 char* LANG_orig
= strdup(getenv("LANG") ? getenv("LANG") : "");
44 // Check that a "POSIX" LC_ALL is equivalent to "C".
45 if (!setenv("LC_ALL", "POSIX", 1))
47 locale loc
= locale("");
48 VERIFY( loc
.name() == "C" );
50 setenv("LC_ALL", "", 1);
52 // Check that a "en_PH" LC_ALL is equivalent to "en_PH".
53 if (!setenv("LC_ALL", "en_PH", 1))
55 locale loc
= locale("");
56 VERIFY( loc
.name() == "en_PH" );
58 setenv("LC_ALL", "", 1);
60 // Explicit check that LC_ALL sets regardless of LC_* and LANG.
61 if (!setenv("LANG", "es_MX", 1) && !setenv("LC_COLLATE", "de_DE", 1))
63 if (!setenv("LC_ALL", "en_PH", 1))
65 locale loc
= locale("");
66 VERIFY( loc
.name() == "en_PH" );
68 setenv("LC_ALL", "", 1);
69 setenv("LANG", LANG_orig
, 1);
72 // NB: LANG checks all LC_* macro settings. As such, all LC_* macros
73 // must be cleared for these tests.
74 setenv("LC_ALL", "", 1);
75 setenv("LC_CTYPE", "", 1);
76 setenv("LC_NUMERIC", "", 1);
77 setenv("LC_TIME", "", 1);
78 setenv("LC_COLLATE", "", 1);
79 setenv("LC_MONETARY", "", 1);
80 setenv("LC_MESSAGES", "", 1);
81 #if _GLIBCXX_NUM_CATEGORIES
82 setenv("LC_PAPER", "", 1);
83 setenv("LC_NAME", "", 1);
84 setenv("LC_ADDRESS", "", 1);
85 setenv("LC_TELEPHONE", "", 1);
86 setenv("LC_MEASUREMENT", "", 1);
87 setenv("LC_IDENTIFICATION", "", 1);
90 // Check the default set by LANG.
91 if (!setenv("LANG", "fr_FR", 1))
93 locale loc
= locale("");
94 VERIFY( loc
.name() == "fr_FR" );
97 // Check that a "POSIX" LANG is equivalent to "C".
98 if (!setenv("LANG", "POSIX", 1))
101 VERIFY( loc
.name() == "C" );
104 // Setting a category in the "C" default.
105 if (!setenv("LC_COLLATE", "de_DE", 1))
107 locale loc
= locale("");
109 #if _GLIBCXX_NUM_CATEGORIES
110 VERIFY( loc
.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
111 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;"
112 "LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;"
113 "LC_IDENTIFICATION=C" );
115 VERIFY( loc
.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
116 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C" );
120 // Changing the LANG default while LC_COLLATE is set.
121 if (!setenv("LANG", "fr_FR", 1))
123 locale loc
= locale("");
124 #if _GLIBCXX_NUM_CATEGORIES
125 VERIFY( loc
.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
126 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
127 "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;"
128 "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;"
129 "LC_IDENTIFICATION=fr_FR" );
131 VERIFY( loc
.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
132 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
133 "LC_MESSAGES=fr_FR" );
137 // Changing another (C only) category.
138 #if _GLIBCXX_NUM_CATEGORIES
139 if (!setenv("LC_IDENTIFICATION", "it_IT", 1))
141 locale loc
= locale("");
142 VERIFY( loc
.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
143 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
144 "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;"
145 "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;"
146 "LC_IDENTIFICATION=it_IT" );
152 #endif // _GLIBCXX_HAVE_SETENV