b9e1391977ddf148f34ac08318a573f5a1dc9a3b
1 // 2000-09-13 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 22.1.1.2 locale constructors and destructors [lib.locale.cons]
23 #include <cwchar> // for mbstate_t
26 #include <testsuite_hooks.h>
28 // More tests for locale("") == POSIX locale::name.
34 #ifdef _GLIBCPP_HAVE_SETENV
36 const char* LANG_orig
= getenv("LANG") ? strdup(getenv("LANG")) : "";
37 const char* LC_ALL_orig
= getenv("LC_ALL") ? strdup(getenv("LC_ALL")) : "";
38 const char* LC_CTYPE_orig
=
39 getenv("LC_CTYPE") ? strdup(getenv("LC_CTYPE")) : "";
40 const char* LC_NUMERIC_orig
=
41 getenv("LC_NUMERIC") ? strdup(getenv("LC_NUMERIC")) : "";
42 const char* LC_TIME_orig
=
43 getenv("LC_TIME") ? strdup(getenv("LC_TIME")) : "";
44 const char* LC_COLLATE_orig
=
45 getenv("LC_COLLATE") ? strdup(getenv("LC_COLLATE")) : "";
46 const char* LC_MONETARY_orig
=
47 getenv("LC_MONETARY") ? strdup(getenv("LC_MONETARY")) : "";
48 const char* LC_MESSAGES_orig
=
49 getenv("LC_MESSAGES") ? strdup(getenv("LC_MESSAGES")) : "";
50 #if _GLIBCPP_NUM_CATEGORIES
51 const char* LC_PAPER_orig
=
52 getenv("LC_PAPER") ? strdup(getenv("LC_PAPER")) : "";
53 const char* LC_NAME_orig
=
54 getenv("LC_NAME") ? strdup(getenv("LC_NAME")) : "";
55 const char* LC_ADDRESS_orig
=
56 getenv("LC_ADDRESS") ? strdup(getenv("LC_ADDRESS")) : "";
57 const char* LC_TELEPHONE_orig
=
58 getenv("LC_TELEPHONE") ? strdup(getenv("LC_TELEPHONE")) : "";
59 const char* LC_MEASUREMENT_orig
=
60 getenv("LC_MEASUREMENT") ? strdup(getenv("LC_MEASUREMENT")) : "";
61 const char* LC_IDENTIFICATION_orig
=
62 getenv("LC_IDENTIFICATION") ? strdup(getenv("LC_IDENTIFICATION")) : "";
65 // Check that a "POSIX" LC_ALL is equivalent to "C".
66 if (!setenv("LC_ALL", "POSIX", 1))
69 VERIFY( loc
.name() == "C" );
71 setenv("LC_ALL", "", 1);
73 // Check that a "en_PH" LC_ALL is equivalent to "en_PH".
74 if (!setenv("LC_ALL", "en_PH", 1))
77 VERIFY( loc
.name() == "en_PH" );
79 setenv("LC_ALL", "", 1);
81 // Explicit check that LC_ALL sets regardless of LC_* and LANG.
82 if (!setenv("LANG", "es_MX", 1) && !setenv("LC_COLLATE", "de_DE", 1))
84 if (!setenv("LC_ALL", "en_PH", 1))
87 VERIFY( loc
.name() == "en_PH" );
89 setenv("LC_ALL", "", 1);
90 setenv("LANG", LANG_orig
? LANG_orig
: "", 1);
91 setenv("LC_COLLATE", LC_COLLATE_orig
? LC_COLLATE_orig
: "", 1);
94 // NB: LANG checks all LC_* macro settings. As such, all LC_* macros
95 // must be cleared for these tests, and then restored.
96 setenv("LC_ALL", "", 1);
97 setenv("LC_CTYPE", "", 1);
98 setenv("LC_NUMERIC", "", 1);
99 setenv("LC_TIME", "", 1);
100 setenv("LC_COLLATE", "", 1);
101 setenv("LC_MONETARY", "", 1);
102 setenv("LC_MESSAGES", "", 1);
103 #if _GLIBCPP_NUM_CATEGORIES
104 setenv("LC_PAPER", "", 1);
105 setenv("LC_NAME", "", 1);
106 setenv("LC_ADDRESS", "", 1);
107 setenv("LC_TELEPHONE", "", 1);
108 setenv("LC_MEASUREMENT", "", 1);
109 setenv("LC_IDENTIFICATION", "", 1);
112 // Check the default set by LANG.
113 if (!setenv("LANG", "fr_FR", 1))
116 VERIFY( loc
.name() == "fr_FR" );
119 // Check that a "POSIX" LANG is equivalent to "C".
120 if (!setenv("LANG", "POSIX", 1))
123 VERIFY( loc
.name() == "C" );
126 // Setting a category in the "C" default.
127 if (!setenv("LC_COLLATE", "de_DE", 1))
131 #if _GLIBCPP_NUM_CATEGORIES
132 VERIFY( loc
.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
133 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;"
134 "LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;"
135 "LC_IDENTIFICATION=C" );
137 VERIFY( loc
.name() == "LC_CTYPE=C;LC_NUMERIC=C;LC_TIME=C;"
138 "LC_COLLATE=de_DE;LC_MONETARY=C;LC_MESSAGES=C" );
142 // Changing the LANG default while LC_COLLATE is set.
143 if (!setenv("LANG", "fr_FR", 1))
146 #if _GLIBCPP_NUM_CATEGORIES
147 VERIFY( loc
.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
148 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
149 "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;"
150 "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;"
151 "LC_IDENTIFICATION=fr_FR" );
153 VERIFY( loc
.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
154 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
155 "LC_MESSAGES=fr_FR" );
159 // Changing another (C only) category.
160 #if _GLIBCPP_NUM_CATEGORIES
161 if (!setenv("LC_IDENTIFICATION", "it_IT", 1))
164 VERIFY( loc
.name() == "LC_CTYPE=fr_FR;LC_NUMERIC=fr_FR;"
165 "LC_TIME=fr_FR;LC_COLLATE=de_DE;LC_MONETARY=fr_FR;"
166 "LC_MESSAGES=fr_FR;LC_PAPER=fr_FR;LC_NAME=fr_FR;"
167 "LC_ADDRESS=fr_FR;LC_TELEPHONE=fr_FR;LC_MEASUREMENT=fr_FR;"
168 "LC_IDENTIFICATION=it_IT" );
172 // Restore the environment.
173 setenv("LANG", LANG_orig
? LANG_orig
: "", 1);
174 setenv("LC_ALL", LC_ALL_orig
? LC_ALL_orig
: "", 1);
175 setenv("LC_CTYPE", LC_CTYPE_orig
? LC_CTYPE_orig
: "", 1);
176 setenv("LC_NUMERIC", LC_NUMERIC_orig
? LC_NUMERIC_orig
: "", 1);
177 setenv("LC_TIME", LC_TIME_orig
? LC_TIME_orig
: "", 1);
178 setenv("LC_COLLATE", LC_COLLATE_orig
? LC_COLLATE_orig
: "", 1);
179 setenv("LC_MONETARY", LC_MONETARY_orig
? LC_MONETARY_orig
: "", 1);
180 setenv("LC_MESSAGES", LC_MESSAGES_orig
? LC_MESSAGES_orig
: "", 1);
181 #if _GLIBCPP_NUM_CATEGORIES
182 setenv("LC_PAPER", LC_PAPER_orig
? LC_PAPER_orig
: "", 1);
183 setenv("LC_NAME", LC_NAME_orig
? LC_NAME_orig
: "", 1);
184 setenv("LC_ADDRESS", LC_ADDRESS_orig
? LC_ADDRESS_orig
: "", 1);
185 setenv("LC_TELEPHONE", LC_TELEPHONE_orig
? LC_TELEPHONE_orig
: "", 1);
186 setenv("LC_MEASUREMENT", LC_MEASUREMENT_orig
? LC_MEASUREMENT_orig
: "", 1);
187 setenv("LC_IDENTIFICATION",
188 LC_IDENTIFICATION_orig
? LC_IDENTIFICATION_orig
: "", 1);