1// 2001-08-23 Benjamin Kosnik <bkoz@redhat.com> 2 3// Copyright (C) 2001, 2002 Free Software Foundation 4// 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) 9// any later version. 10 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. 15 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, 19// USA. 20 21// 22.2.6.3.1 moneypunct members 22 23#include <locale> 24#include <testsuite_hooks.h> 25 26// XXX This test is not working for non-glibc locale models. 27// { dg-do run { xfail *-*-* } } 28 29void test01() 30{ 31 using namespace std; 32 typedef money_base::part part; 33 typedef money_base::pattern pattern; 34 35 bool test = true; 36 37 // basic construction 38 locale loc_c = locale::classic(); 39 locale loc_us("en_US"); 40 locale loc_fr("fr_FR"); 41 locale loc_de("de_DE"); 42 VERIFY( loc_c != loc_de ); 43 VERIFY( loc_us != loc_fr ); 44 VERIFY( loc_us != loc_de ); 45 VERIFY( loc_de != loc_fr ); 46 47 // cache the moneypunct facets 48 typedef moneypunct<char, true> __money_true; 49 typedef moneypunct<char, false> __money_false; 50 const __money_true& monp_c_t = use_facet<__money_true>(loc_c); 51 const __money_true& monp_us_t = use_facet<__money_true>(loc_us); 52 const __money_true& monp_fr_t = use_facet<__money_true>(loc_fr); 53 const __money_true& monp_de_t = use_facet<__money_true>(loc_de); 54 const __money_false& monp_c_f = use_facet<__money_false>(loc_c); 55 const __money_false& monp_us_f = use_facet<__money_false>(loc_us); 56 const __money_false& monp_fr_f = use_facet<__money_false>(loc_fr); 57 const __money_false& monp_de_f = use_facet<__money_false>(loc_de); 58 59 // quick sanity check for data. 60 char q1 = monp_c_t.decimal_point(); 61 char q2 = monp_c_t.thousands_sep(); 62 char q3 = monp_c_f.decimal_point(); 63 char q4 = monp_c_f.thousands_sep(); 64 VERIFY( q1 != char() ); 65 VERIFY( q2 != char() ); 66 VERIFY( q3 != char() ); 67 VERIFY( q4 != char() ); 68 69 // sanity check the data is correct. 70 char dp1 = monp_c_t.decimal_point(); 71 char th1 = monp_c_t.thousands_sep(); 72 string g1 = monp_c_t.grouping(); 73 string cs1 = monp_c_t.curr_symbol(); 74 string ps1 = monp_c_t.positive_sign(); 75 string ns1 = monp_c_t.negative_sign(); 76 int fd1 = monp_c_t.frac_digits(); 77 pattern pos1 = monp_c_t.pos_format(); 78 pattern neg1 = monp_c_t.neg_format(); 79 80 char dp2 = monp_de_t.decimal_point(); 81 char th2 = monp_de_t.thousands_sep(); 82 string g2 = monp_de_t.grouping(); 83 string cs2 = monp_de_t.curr_symbol(); 84 string ps2 = monp_de_t.positive_sign(); 85 string ns2 = monp_de_t.negative_sign(); 86 int fd2 = monp_de_t.frac_digits(); 87 pattern pos2 = monp_de_t.pos_format(); 88 pattern neg2 = monp_de_t.neg_format(); 89 90 VERIFY( dp1 != dp2 ); 91 VERIFY( th1 != th2 ); 92 VERIFY( g1 != g2 ); 93 VERIFY( cs1 != cs2 ); 94 // VERIFY( ps1 != ps2 ); 95 VERIFY( ns1 != ns2 ); 96 VERIFY( fd1 != fd2 ); 97 VERIFY(static_cast<part>(pos1.field[0]) != static_cast<part>(pos2.field[0])); 98 VERIFY(static_cast<part>(pos1.field[1]) != static_cast<part>(pos2.field[1])); 99 VERIFY(static_cast<part>(pos1.field[2]) != static_cast<part>(pos2.field[2])); 100 VERIFY(static_cast<part>(pos1.field[3]) != static_cast<part>(pos2.field[3])); 101 102 VERIFY(static_cast<part>(neg1.field[0]) != static_cast<part>(neg2.field[0])); 103 VERIFY(static_cast<part>(neg1.field[1]) != static_cast<part>(neg2.field[1])); 104 VERIFY(static_cast<part>(neg1.field[2]) != static_cast<part>(neg2.field[2])); 105 VERIFY(static_cast<part>(neg1.field[3]) != static_cast<part>(neg2.field[3])); 106} 107 108// libstdc++/5280 109void test02() 110{ 111#ifdef _GLIBCPP_HAVE_SETENV 112 // Set the global locale to non-"C". 113 std::locale loc_de("de_DE"); 114 std::locale::global(loc_de); 115 116 // Set LANG environment variable to de_DE. 117 const char* oldLANG = getenv("LANG"); 118 if (!setenv("LANG", "de_DE", 1)) 119 { 120 test01(); 121 setenv("LANG", oldLANG ? oldLANG : "", 1); 122 } 123#endif 124} 125 126// http://gcc.gnu.org/ml/libstdc++/2002-05/msg00038.html 127void test03() 128{ 129 bool test = true; 130 131 const char* tentLANG = std::setlocale(LC_ALL, "ja_JP.eucjp"); 132 if (tentLANG != NULL) 133 { 134 std::string preLANG = tentLANG; 135 test01(); 136 std::string postLANG = std::setlocale(LC_ALL, NULL); 137 VERIFY( preLANG == postLANG ); 138 } 139} 140 141int main() 142{ 143 test01(); 144 test02(); 145 test03(); 146 return 0; 147} 148