Reset branch to trunk.
[official-gcc.git] / trunk / libstdc++-v3 / testsuite / 22_locale / num_get / get / wchar_t / 12.cc
blobaaea6f42e0ae60d14c699fa623c9403fc5157e67
1 // 2003-12-22 Paolo Carlini <pcarlini@suse.de>
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.
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.
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/>.
21 // 22.2.2.1.1 num_get members
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
27 struct Punct1: std::numpunct<wchar_t>
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'; }
34 struct Punct2: std::numpunct<wchar_t>
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'-'; }
41 // http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html
42 void test01()
44 using namespace std;
45 typedef istreambuf_iterator<wchar_t> iterator_type;
47 bool test __attribute__((unused)) = true;
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());
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;
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'+' );
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 );
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 );
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 );
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'+' );
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 );
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 );
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'-' );
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 );
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 );
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 );
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 );
157 int main()
159 test01();
160 return 0;