Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 11.cc
blob28ca2d0ebc6d3cf1ebb74da9370bd4d4bc747d51
1 // Copyright (C) 2003 Free Software Foundation
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
6 // Free Software Foundation; either version 2, or (at your option)
7 // any later version.
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.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
19 // 22.2.2.1.1 num_get members
21 #include <locale>
22 #include <sstream>
23 #include <testsuite_hooks.h>
25 struct Punct1: std::numpunct<char>
27 std::string do_grouping() const { return "\1"; }
28 char do_thousands_sep() const { return '2'; }
29 char do_decimal_point() const { return '4'; }
32 struct Punct2: std::numpunct<char>
34 std::string do_grouping() const { return "\1"; }
35 char do_thousands_sep() const { return '2'; }
36 char do_decimal_point() const { return '2'; }
39 // http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html
40 void test01()
42 using namespace std;
43 typedef istreambuf_iterator<char> iterator_type;
45 bool test __attribute__((unused)) = true;
47 istringstream iss1, iss2;
48 iss1.imbue(locale(iss1.getloc(), new Punct1));
49 iss2.imbue(locale(iss2.getloc(), new Punct2));
50 const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc());
51 const num_get<char>& ng2 = use_facet<num_get<char> >(iss2.getloc());
53 ios_base::iostate err = ios_base::goodbit;
54 iterator_type end;
55 double d = 0.0;
56 double d1 = 13.0;
57 double d2 = 1.0;
58 double d3 = 30.0;
59 long l = 0l;
60 long l1 = 13l;
61 long l2 = 10l;
63 iss1.str("1234");
64 err = ios_base::goodbit;
65 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
66 VERIFY( err == ios_base::eofbit );
67 VERIFY( d == d1 );
69 iss1.str("142");
70 iss1.clear();
71 err = ios_base::goodbit;
72 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
73 VERIFY( err == ios_base::goodbit );
74 VERIFY( d == d2 );
76 iss1.str("3e14");
77 iss1.clear();
78 err = ios_base::goodbit;
79 end = ng1.get(iss1.rdbuf(), 0, iss1, err, d);
80 VERIFY( err == ios_base::goodbit );
81 VERIFY( d == d3 );
83 iss1.str("1234");
84 iss1.clear();
85 err = ios_base::goodbit;
86 end = ng1.get(iss1.rdbuf(), 0, iss1, err, l);
87 VERIFY( err == ios_base::goodbit );
88 VERIFY( l == l1 );
90 iss2.str("123");
91 err = ios_base::goodbit;
92 end = ng2.get(iss2.rdbuf(), 0, iss2, err, d);
93 VERIFY( err == ios_base::eofbit );
94 VERIFY( d == d1 );
96 iss2.str("120");
97 iss2.clear();
98 err = ios_base::goodbit;
99 end = ng2.get(iss2.rdbuf(), 0, iss2, err, l);
100 VERIFY( err == ios_base::eofbit );
101 VERIFY( l == l2 );
104 int main()
106 test01();
107 return 0;