]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_get/get/char/11.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 11.cc
CommitLineData
aa118a03 1// Copyright (C) 2003-2014 Free Software Foundation, Inc.
cc16f8b9
PC
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
748086b7 6// Free Software Foundation; either version 3, or (at your option)
cc16f8b9
PC
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
748086b7
JJ
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
cc16f8b9
PC
17
18// 22.2.2.1.1 num_get members
19
20#include <locale>
21#include <sstream>
22#include <testsuite_hooks.h>
23
4f0c9c8a 24struct Punct1: std::numpunct<char>
cc16f8b9
PC
25{
26 std::string do_grouping() const { return "\1"; }
27 char do_thousands_sep() const { return '2'; }
28 char do_decimal_point() const { return '4'; }
29};
30
4f0c9c8a
PC
31struct Punct2: std::numpunct<char>
32{
33 std::string do_grouping() const { return "\1"; }
34 char do_thousands_sep() const { return '2'; }
35 char do_decimal_point() const { return '2'; }
36};
37
a827daa0 38// http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html
cc16f8b9
PC
39void test01()
40{
41 using namespace std;
42 typedef istreambuf_iterator<char> iterator_type;
43
44 bool test __attribute__((unused)) = true;
45
4f0c9c8a 46 istringstream iss1, iss2;
28f2a265
PC
47 iss1.imbue(locale(iss1.getloc(), new Punct1));
48 iss2.imbue(locale(iss2.getloc(), new Punct2));
4f0c9c8a
PC
49 const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc());
50 const num_get<char>& ng2 = use_facet<num_get<char> >(iss2.getloc());
51
cc16f8b9
PC
52 ios_base::iostate err = ios_base::goodbit;
53 iterator_type end;
54 double d = 0.0;
55 double d1 = 13.0;
4f0c9c8a
PC
56 double d2 = 1.0;
57 double d3 = 30.0;
cc16f8b9
PC
58 long l = 0l;
59 long l1 = 13l;
4f0c9c8a 60 long l2 = 10l;
cc16f8b9 61
4f0c9c8a 62 iss1.str("1234");
cc16f8b9 63 err = ios_base::goodbit;
4f0c9c8a 64 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
cc16f8b9
PC
65 VERIFY( err == ios_base::eofbit );
66 VERIFY( d == d1 );
67
4f0c9c8a
PC
68 iss1.str("142");
69 iss1.clear();
70 err = ios_base::goodbit;
71 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
72 VERIFY( err == ios_base::goodbit );
73 VERIFY( d == d2 );
74
75 iss1.str("3e14");
76 iss1.clear();
77 err = ios_base::goodbit;
78 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
79 VERIFY( err == ios_base::goodbit );
80 VERIFY( d == d3 );
81
82 iss1.str("1234");
83 iss1.clear();
cc16f8b9 84 err = ios_base::goodbit;
4f0c9c8a 85 end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
cc16f8b9
PC
86 VERIFY( err == ios_base::goodbit );
87 VERIFY( l == l1 );
cc16f8b9 88
4f0c9c8a
PC
89 iss2.str("123");
90 err = ios_base::goodbit;
91 end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
92 VERIFY( err == ios_base::eofbit );
93 VERIFY( d == d1 );
94
95 iss2.str("120");
96 iss2.clear();
97 err = ios_base::goodbit;
98 end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
99 VERIFY( err == ios_base::eofbit );
100 VERIFY( l == l2 );
101}
cc16f8b9
PC
102
103int main()
104{
105 test01();
106 return 0;
107}