Imported Upstream version 4.8.1
[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-2013 Free Software Foundation, Inc.
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 3, 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 COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 22.2.2.1.1  num_get members
21
22 #include <locale>
23 #include <sstream>
24 #include <testsuite_hooks.h>
25
26 struct Punct1: std::numpunct<wchar_t>
27 {
28   std::string do_grouping() const { return "\1"; }
29   wchar_t do_thousands_sep() const { return L'+'; }
30   wchar_t do_decimal_point() const { return L'x'; }
31 };
32
33 struct Punct2: std::numpunct<wchar_t>
34 {
35   std::string do_grouping() const { return "\1"; }
36   wchar_t do_thousands_sep() const { return L'X'; }
37   wchar_t do_decimal_point() const { return L'-'; }
38 };
39
40 // http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html
41 void test01()
42 {
43   using namespace std;
44   typedef istreambuf_iterator<wchar_t> iterator_type;
45   
46   bool test __attribute__((unused)) = true;
47
48   wistringstream iss1, iss2;
49   iss1.imbue(locale(iss1.getloc(), new Punct1));
50   iss2.imbue(locale(iss2.getloc(), new Punct2));
51   const num_get<wchar_t>& ng1 = use_facet<num_get<wchar_t> >(iss1.getloc()); 
52   const num_get<wchar_t>& ng2 = use_facet<num_get<wchar_t> >(iss2.getloc()); 
53
54   ios_base::iostate err = ios_base::goodbit;
55   iterator_type end;
56   long l = 1l;
57   long l1 = 0l;
58   long l2 = 10l;
59   long l3 = 1l;
60   long l4 = 63l;
61   double d = 0.0;
62   double d1 = .4;
63   double d2 = 0.0;
64   double d3 = .1;
65
66   iss1.str(L"+3");
67   err = ios_base::goodbit;
68   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
69   VERIFY( err == ios_base::failbit );
70   VERIFY( *end == L'+' );
71
72   iss1.str(L"0x1");
73   iss1.clear();
74   err = ios_base::goodbit;
75   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
76   VERIFY( err == ios_base::goodbit );
77   VERIFY( *end == L'x' );
78   VERIFY( l == l1 );
79
80   iss1.str(L"0Xa");
81   iss1.clear();
82   iss1.unsetf(ios::basefield);
83   err = ios_base::goodbit;
84   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
85   VERIFY( err == ios_base::eofbit );
86   VERIFY( l == l2 );
87
88   iss1.str(L"0xa");
89   iss1.clear();
90   err = ios_base::goodbit;
91   end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
92   VERIFY( err == ios_base::goodbit );
93   VERIFY( *end == L'x' );
94   VERIFY( l == l1 );  
95
96   iss1.str(L"+5");
97   iss1.clear();
98   err = ios_base::goodbit;
99   end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
100   VERIFY( err == ios_base::failbit );
101   VERIFY( *end == L'+' );
102
103   iss1.str(L"x4");
104   iss1.clear();
105   err = ios_base::goodbit;
106   end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
107   VERIFY( err == ios_base::eofbit );
108   VERIFY( d == d1 );
109
110   iss2.str(L"0001-");
111   err = ios_base::goodbit;
112   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
113   VERIFY( err == ios_base::goodbit );
114   VERIFY( *end == L'-' );
115   VERIFY( l == l3 );
116
117   iss2.str(L"-2");
118   iss2.clear();
119   err = ios_base::goodbit;
120   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
121   VERIFY( err == ios_base::failbit );
122   VERIFY( *end == L'-' );
123
124   iss2.str(L"0X1");
125   iss2.clear();
126   iss2.unsetf(ios::basefield);
127   err = ios_base::goodbit;
128   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
129   VERIFY( err == ios_base::failbit );
130   VERIFY( *end == L'X' );
131   VERIFY( l == 0 );
132
133   iss2.str(L"000778");
134   iss2.clear();
135   err = ios_base::goodbit;
136   end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
137   VERIFY( err == ios_base::goodbit );
138   VERIFY( *end == L'8' );
139   VERIFY( l == l4 );
140
141   iss2.str(L"00X");
142   iss2.clear();
143   err = ios_base::goodbit;
144   end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
145   VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
146   VERIFY( d == d2 );
147
148   iss2.str(L"-1");
149   iss2.clear();
150   err = ios_base::goodbit;
151   end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
152   VERIFY( err == ios_base::eofbit );
153   VERIFY( d == d3 );  
154 }
155
156 int main()
157 {
158   test01();
159   return 0;
160 }