]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/locale/cons/5.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / locale / cons / 5.cc
CommitLineData
9c69a458 1// { dg-require-namedlocale "de_DE" }
7640db57
MH
2// { dg-require-namedlocale "en_PH" }
3// { dg-require-namedlocale "es_MX" }
4// { dg-require-namedlocale "fr_FR" }
9c69a458 5// { dg-require-namedlocale "it_IT" }
f63a8495 6
5f8d36fe
BK
7// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
8
7adcbafe 9// Copyright (C) 2000-2022 Free Software Foundation, Inc.
5f8d36fe
BK
10//
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
748086b7 14// Free Software Foundation; either version 3, or (at your option)
5f8d36fe
BK
15// any later version.
16
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.
21
22// You should have received a copy of the GNU General Public License along
748086b7
JJ
23// with this library; see the file COPYING3. If not see
24// <http://www.gnu.org/licenses/>.
5f8d36fe
BK
25
26// 22.1.1.2 locale constructors and destructors [lib.locale.cons]
27
28#include <cwchar> // for mbstate_t
1b716e90 29#include <cstring>
debac9f4 30#include <cstdlib>
5f8d36fe
BK
31#include <locale>
32#include <stdexcept>
33#include <testsuite_hooks.h>
34
35// More tests for locale("") == POSIX locale::name.
36void test04()
37{
5f8d36fe
BK
38 using namespace std;
39
3d7c150e 40#ifdef _GLIBCXX_HAVE_SETENV
5f8d36fe 41
32aaf6ef 42 char* LANG_orig = strdup(getenv("LANG") ? getenv("LANG") : "");
5f8d36fe
BK
43
44 // Check that a "POSIX" LC_ALL is equivalent to "C".
45 if (!setenv("LC_ALL", "POSIX", 1))
46 {
f63a8495 47 locale loc = locale("");
5f8d36fe
BK
48 VERIFY( loc.name() == "C" );
49 }
50 setenv("LC_ALL", "", 1);
51
52 // Check that a "en_PH" LC_ALL is equivalent to "en_PH".
53 if (!setenv("LC_ALL", "en_PH", 1))
54 {
f63a8495 55 locale loc = locale("");
5f8d36fe
BK
56 VERIFY( loc.name() == "en_PH" );
57 }
58 setenv("LC_ALL", "", 1);
59
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))
62 {
63 if (!setenv("LC_ALL", "en_PH", 1))
64 {
f63a8495 65 locale loc = locale("");
5f8d36fe
BK
66 VERIFY( loc.name() == "en_PH" );
67 }
68 setenv("LC_ALL", "", 1);
32aaf6ef 69 setenv("LANG", LANG_orig, 1);
5f8d36fe
BK
70 }
71
72 // NB: LANG checks all LC_* macro settings. As such, all LC_* macros
32aaf6ef 73 // must be cleared for these tests.
5f8d36fe
BK
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);
3d7c150e 81#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
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);
88#endif
89
90 // Check the default set by LANG.
91 if (!setenv("LANG", "fr_FR", 1))
92 {
f63a8495 93 locale loc = locale("");
5f8d36fe
BK
94 VERIFY( loc.name() == "fr_FR" );
95 }
96
97 // Check that a "POSIX" LANG is equivalent to "C".
98 if (!setenv("LANG", "POSIX", 1))
99 {
100 locale loc("");
101 VERIFY( loc.name() == "C" );
102 }
103
104 // Setting a category in the "C" default.
105 if (!setenv("LC_COLLATE", "de_DE", 1))
106 {
f63a8495 107 locale loc = locale("");
5f8d36fe 108
3d7c150e 109#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
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" );
114#else
115 VERIFY( loc.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
116 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C" );
117#endif
118 }
119
120 // Changing the LANG default while LC_COLLATE is set.
121 if (!setenv("LANG", "fr_FR", 1))
122 {
f63a8495 123 locale loc = locale("");
3d7c150e 124#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
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" );
130#else
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" );
134#endif
135 }
136
137 // Changing another (C only) category.
3d7c150e 138#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
139 if (!setenv("LC_IDENTIFICATION", "it_IT", 1))
140 {
f63a8495 141 locale loc = locale("");
5f8d36fe
BK
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" );
147 }
148#endif
149
32aaf6ef 150 free(LANG_orig);
5f8d36fe 151
32aaf6ef 152#endif // _GLIBCXX_HAVE_SETENV
5f8d36fe
BK
153}
154
155int main()
156{
3d838e28 157 test04();
5f8d36fe
BK
158 return 0;
159}