| 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" } |
| 6 |
|
| 7 |
// 2000-09-13 Benjamin Kosnik <[email protected]> |
| 8 |
|
| 9 |
// Copyright (C) 2000-2025 Free Software Foundation, Inc. |
| 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 |
| 14 |
// Free Software Foundation; either version 3, or (at your option) |
| 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 |
| 23 |
// with this library; see the file COPYING3. If not see |
| 24 |
// <http://www.gnu.org/licenses/>. |
| 25 |
|
| 26 |
// 22.1.1.2 locale constructors and destructors [lib.locale.cons] |
| 27 |
|
| 28 |
#include <cwchar> // for mbstate_t |
| 29 |
#include <cstring> |
| 30 |
#include <cstdlib> |
| 31 |
#include <locale> |
| 32 |
#include <stdexcept> |
| 33 |
#include <testsuite_hooks.h> |
| 34 |
|
| 35 |
// More tests for locale("") == POSIX locale::name. |
| 36 |
void test04() |
| 37 |
{ |
| 38 |
using namespace std; |
| 39 |
|
| 40 |
#ifdef _GLIBCXX_HAVE_SETENV |
| 41 |
|
| 42 |
char* LANG_orig = strdup(getenv("LANG") ? getenv("LANG") : ""); |
| 43 |
|
| 44 |
// Check that a "POSIX" LC_ALL is equivalent to "C". |
| 45 |
if (!setenv("LC_ALL", "POSIX", 1)) |
| 46 |
{ |
| 47 |
locale loc = locale(""); |
| 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 |
{ |
| 55 |
locale loc = locale(""); |
| 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 |
{ |
| 65 |
locale loc = locale(""); |
| 66 |
VERIFY( loc.name() == "en_PH" ); |
| 67 |
} |
| 68 |
setenv("LC_ALL", "", 1); |
| 69 |
setenv("LANG", LANG_orig, 1); |
| 70 |
} |
| 71 |
|
| 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); |
| 88 |
#endif |
| 89 |
|
| 90 |
// Check the default set by LANG. |
| 91 |
if (!setenv("LANG", "fr_FR", 1)) |
| 92 |
{ |
| 93 |
locale loc = locale(""); |
| 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 |
{ |
| 107 |
locale loc = locale(""); |
| 108 |
|
| 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" ); |
| 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 |
{ |
| 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" ); |
| 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. |
| 138 |
#if _GLIBCXX_NUM_CATEGORIES |
| 139 |
if (!setenv("LC_IDENTIFICATION", "it_IT", 1)) |
| 140 |
{ |
| 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" ); |
| 147 |
} |
| 148 |
#endif |
| 149 |
|
| 150 |
free(LANG_orig); |
| 151 |
|
| 152 |
#endif // _GLIBCXX_HAVE_SETENV |
| 153 |
} |
| 154 |
|
| 155 |
int main() |
| 156 |
{ |
| 157 |
test04(); |
| 158 |
return 0; |
| 159 |
} |