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