]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_get/get/char/12.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 12.cc
CommitLineData
22831f13 1// 2003-12-22 Paolo Carlini <pcarlini@suse.de>
2
f1717362 3// Copyright (C) 2003-2016 Free Software Foundation, Inc.
22831f13 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
22831f13 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
22831f13 19
20// 22.2.2.1.1 num_get members
21
22#include <locale>
23#include <sstream>
24#include <testsuite_hooks.h>
25
26struct Punct1: std::numpunct<char>
27{
28 std::string do_grouping() const { return "\1"; }
29 char do_thousands_sep() const { return '+'; }
30 char do_decimal_point() const { return 'x'; }
31};
32
33struct Punct2: std::numpunct<char>
34{
35 std::string do_grouping() const { return "\1"; }
36 char do_thousands_sep() const { return 'X'; }
37 char do_decimal_point() const { return '-'; }
38};
39
40// http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html
41void test01()
42{
43 using namespace std;
44 typedef istreambuf_iterator<char> iterator_type;
45
46 bool test __attribute__((unused)) = true;
47
48 istringstream iss1, iss2;
4d4d9c37 49 iss1.imbue(locale(iss1.getloc(), new Punct1));
50 iss2.imbue(locale(iss2.getloc(), new Punct2));
22831f13 51 const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc());
52 const num_get<char>& ng2 = use_facet<num_get<char> >(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;
fbaa96d6 62 double d1 = .4;
63 double d2 = 0.0;
64 double d3 = .1;
22831f13 65
66 iss1.str("+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 == '+' );
71
72 iss1.str("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 == 'x' );
78 VERIFY( l == l1 );
79
80 iss1.str("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("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 == 'x' );
94 VERIFY( l == l1 );
95
96 iss1.str("+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 == '+' );
102
103 iss1.str("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("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 == '-' );
115 VERIFY( l == l3 );
116
117 iss2.str("-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 == '-' );
123
124 iss2.str("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 == 'X' );
7c23b837 131 VERIFY( l == 0 );
22831f13 132
133 iss2.str("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 == '8' );
139 VERIFY( l == l4 );
140
141 iss2.str("00X");
142 iss2.clear();
143 err = ios_base::goodbit;
144 end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
fbaa96d6 145 VERIFY( err == (ios_base::eofbit | ios_base::failbit) );
146 VERIFY( d == d2 );
22831f13 147
148 iss2.str("-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 );
fbaa96d6 153 VERIFY( d == d3 );
22831f13 154}
155
156
157int main()
158{
159 test01();
160 return 0;
161}