Imported Upstream version 4.7.2
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / wchar_t / 12.cc
1 // 2003-12-22  Paolo Carlini  <pcarlini@suse.de>
2
3 // Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 // Free Software Foundation
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3.  If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 22.2.2.1.1  num_get members
22
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
26
27 struct Punct1: std::numpunct<wchar_t>
28 {
29   std::string do_grouping() const { return "\1"; }
30   wchar_t do_thousands_sep() const { return L'+'; }
31   wchar_t do_decimal_point() const { return L'x'; }
32 };
33
34 struct Punct2: std::numpunct<wchar_t>
35 {
36   std::string do_grouping() const { return "\1"; }
37   wchar_t do_thousands_sep() const { return L'X'; }
38   wchar_t do_decimal_point() const { return L'-'; }
39 };
40
41 // http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html
42 void test01()
43 {
44   using namespace std;
45   typedef istreambuf_iterator<wchar_t> iterator_type;
46   
47   bool test __attribute__((unused)) = true;
48
49   wistringstream iss1, iss2;
50   iss1.imbue(locale(iss1.getloc(), new Punct1));
51   iss2.imbue(locale(iss2.getloc(), new Punct2));
52   const num_get<wchar_t>& ng1 = use_facet<num_get<wchar_t> >(iss1.getloc()); 
53   const num_get<wchar_t>& ng2 = use_facet<num_get<wchar_t> >(iss2.getloc()); 
54
55   ios_base::iostate err = ios_base::goodbit;
56   iterator_type end;
57   long l = 1l;
58   long l1 = 0l;
59   long l2 = 10l;
60   long l3 = 1l;
61   long l4 = 63l;
62   double d = 0.0;
63   double d1 = .4;
64   double d2 = 0.0;
65   double d3 = .1;
66
67   iss1.str(L"+3");
68   err = ios_base::goodbit;
69   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
70   VERIFY( err == ios_base::failbit );
71   VERIFY( *end == L'+' );
72
73   iss1.str(L"0x1");
74   iss1.clear();
75   err = ios_base::goodbit;
76   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
77   VERIFY( err == ios_base::goodbit );
78   VERIFY( *end == L'x' );
79   VERIFY( l == l1 );
80
81   iss1.str(L"0Xa");
82   iss1.clear();
83   iss1.unsetf(ios::basefield);
84   err = ios_base::goodbit;
85   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
86   VERIFY( err == ios_base::eofbit );
87   VERIFY( l == l2 );
88
89   iss1.str(L"0xa");
90   iss1.clear();
91   err = ios_base::goodbit;
92   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
93   VERIFY( err == ios_base::goodbit );
94   VERIFY( *end == L'x' );
95   VERIFY( l == l1 );  
96
97   iss1.str(L"+5");
98   iss1.clear();
99   err = ios_base::goodbit;
100   end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
101   VERIFY( err == ios_base::failbit );
102   VERIFY( *end == L'+' );
103
104   iss1.str(L"x4");
105   iss1.clear();
106   err = ios_base::goodbit;
107   end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
108   VERIFY( err == ios_base::eofbit );
109   VERIFY( d == d1 );
110
111   iss2.str(L"0001-");
112   err = ios_base::goodbit;
113   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
114   VERIFY( err == ios_base::goodbit );
115   VERIFY( *end == L'-' );
116   VERIFY( l == l3 );
117
118   iss2.str(L"-2");
119   iss2.clear();
120   err = ios_base::goodbit;
121   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
122   VERIFY( err == ios_base::failbit );
123   VERIFY( *end == L'-' );
124
125   iss2.str(L"0X1");
126   iss2.clear();
127   iss2.unsetf(ios::basefield);
128   err = ios_base::goodbit;
129   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
130   VERIFY( err == ios_base::failbit );
131   VERIFY( *end == L'X' );
132   VERIFY( l == 0 );
133
134   iss2.str(L"000778");
135   iss2.clear();
136   err = ios_base::goodbit;
137   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
138   VERIFY( err == ios_base::goodbit );
139   VERIFY( *end == L'8' );
140   VERIFY( l == l4 );
141
142   iss2.str(L"00X");
143   iss2.clear();
144   err = ios_base::goodbit;
145   end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
146   VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
147   VERIFY( d == d2 );
148
149   iss2.str(L"-1");
150   iss2.clear();
151   err = ios_base::goodbit;
152   end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
153   VERIFY( err == ios_base::eofbit );
154   VERIFY( d == d3 );  
155 }
156
157 int main()
158 {
159   test01();
160   return 0;
161 }