]> 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
PC
1// { dg-require-namedlocale "en_PH" }
2// { dg-require-namedlocale "de_DE" }
3// { dg-require-namedlocale "it_IT" }
f63a8495 4
5f8d36fe
BK
5// 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
6
85ec4feb 7// Copyright (C) 2000-2018 Free Software Foundation, Inc.
5f8d36fe
BK
8//
9// This file is part of the GNU ISO C++ Library. This library is free
10// software; you can redistribute it and/or modify it under the
11// terms of the GNU General Public License as published by the
748086b7 12// Free Software Foundation; either version 3, or (at your option)
5f8d36fe
BK
13// any later version.
14
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19
20// You should have received a copy of the GNU General Public License along
748086b7
JJ
21// with this library; see the file COPYING3. If not see
22// <http://www.gnu.org/licenses/>.
5f8d36fe
BK
23
24// 22.1.1.2 locale constructors and destructors [lib.locale.cons]
25
26#include <cwchar> // for mbstate_t
1b716e90 27#include <cstring>
debac9f4 28#include <cstdlib>
5f8d36fe
BK
29#include <locale>
30#include <stdexcept>
31#include <testsuite_hooks.h>
32
33// More tests for locale("") == POSIX locale::name.
34void test04()
35{
5f8d36fe
BK
36 using namespace std;
37
3d7c150e 38#ifdef _GLIBCXX_HAVE_SETENV
5f8d36fe 39
32aaf6ef 40 char* LANG_orig = strdup(getenv("LANG") ? getenv("LANG") : "");
5f8d36fe
BK
41
42 // Check that a "POSIX" LC_ALL is equivalent to "C".
43 if (!setenv("LC_ALL", "POSIX", 1))
44 {
f63a8495 45 locale loc = locale("");
5f8d36fe
BK
46 VERIFY( loc.name() == "C" );
47 }
48 setenv("LC_ALL", "", 1);
49
50 // Check that a "en_PH" LC_ALL is equivalent to "en_PH".
51 if (!setenv("LC_ALL", "en_PH", 1))
52 {
f63a8495 53 locale loc = locale("");
5f8d36fe
BK
54 VERIFY( loc.name() == "en_PH" );
55 }
56 setenv("LC_ALL", "", 1);
57
58 // Explicit check that LC_ALL sets regardless of LC_* and LANG.
59 if (!setenv("LANG", "es_MX", 1) && !setenv("LC_COLLATE", "de_DE", 1))
60 {
61 if (!setenv("LC_ALL", "en_PH", 1))
62 {
f63a8495 63 locale loc = locale("");
5f8d36fe
BK
64 VERIFY( loc.name() == "en_PH" );
65 }
66 setenv("LC_ALL", "", 1);
32aaf6ef 67 setenv("LANG", LANG_orig, 1);
5f8d36fe
BK
68 }
69
70 // NB: LANG checks all LC_* macro settings. As such, all LC_* macros
32aaf6ef 71 // must be cleared for these tests.
5f8d36fe
BK
72 setenv("LC_ALL", "", 1);
73 setenv("LC_CTYPE", "", 1);
74 setenv("LC_NUMERIC", "", 1);
75 setenv("LC_TIME", "", 1);
76 setenv("LC_COLLATE", "", 1);
77 setenv("LC_MONETARY", "", 1);
78 setenv("LC_MESSAGES", "", 1);
3d7c150e 79#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
80 setenv("LC_PAPER", "", 1);
81 setenv("LC_NAME", "", 1);
82 setenv("LC_ADDRESS", "", 1);
83 setenv("LC_TELEPHONE", "", 1);
84 setenv("LC_MEASUREMENT", "", 1);
85 setenv("LC_IDENTIFICATION", "", 1);
86#endif
87
88 // Check the default set by LANG.
89 if (!setenv("LANG", "fr_FR", 1))
90 {
f63a8495 91 locale loc = locale("");
5f8d36fe
BK
92 VERIFY( loc.name() == "fr_FR" );
93 }
94
95 // Check that a "POSIX" LANG is equivalent to "C".
96 if (!setenv("LANG", "POSIX", 1))
97 {
98 locale loc("");
99 VERIFY( loc.name() == "C" );
100 }
101
102 // Setting a category in the "C" default.
103 if (!setenv("LC_COLLATE", "de_DE", 1))
104 {
f63a8495 105 locale loc = locale("");
5f8d36fe 106
3d7c150e 107#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
108 VERIFY( loc.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
109 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;"
110 "LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;"
111 "LC_IDENTIFICATION=C" );
112#else
113 VERIFY( loc.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
114 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C" );
115#endif
116 }
117
118 // Changing the LANG default while LC_COLLATE is set.
119 if (!setenv("LANG", "fr_FR", 1))
120 {
f63a8495 121 locale loc = locale("");
3d7c150e 122#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
123 VERIFY( loc.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
124 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
125 "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;"
126 "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;"
127 "LC_IDENTIFICATION=fr_FR" );
128#else
129 VERIFY( loc.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
130 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
131 "LC_MESSAGES=fr_FR" );
132#endif
133 }
134
135 // Changing another (C only) category.
3d7c150e 136#if _GLIBCXX_NUM_CATEGORIES
5f8d36fe
BK
137 if (!setenv("LC_IDENTIFICATION", "it_IT", 1))
138 {
f63a8495 139 locale loc = locale("");
5f8d36fe
BK
140 VERIFY( loc.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
141 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
142 "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;"
143 "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;"
144 "LC_IDENTIFICATION=it_IT" );
145 }
146#endif
147
32aaf6ef 148 free(LANG_orig);
5f8d36fe 149
32aaf6ef 150#endif // _GLIBCXX_HAVE_SETENV
5f8d36fe
BK
151}
152
153int main()
154{
3d838e28 155 test04();
5f8d36fe
BK
156 return 0;
157}