]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_get/get/char/2.cc
re PR testsuite/39696 (gcc.dg/tree-ssa/ssa-ccp-25.c scan-tree-dump doesn't work on...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 2.cc
CommitLineData
5f8d36fe
BK
1// 2001-11-21 Benjamin Kosnik <bkoz@redhat.com>
2
895510be 3// Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation
5f8d36fe
BK
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 2, 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 COPYING. If not, write to the Free
83f51799 18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
5f8d36fe
BK
19// USA.
20
21// 22.2.2.1.1 num_get members
22
a5ea7a0b
RS
23// { dg-do run { xfail lax_strtofp } }
24
5f8d36fe
BK
25#include <locale>
26#include <sstream>
27#include <testsuite_hooks.h>
28
29void test02()
30{
31 using namespace std;
32 typedef istreambuf_iterator<char> iterator_type;
33
11f10e6b 34 bool test __attribute__((unused)) = true;
5f8d36fe
BK
35
36 // basic construction
37 locale loc_c = locale::classic();
5f8d36fe 38
5f8d36fe
BK
39 // sanity check the data is correct.
40 const string empty;
5f8d36fe
BK
41
42 bool b1 = true;
43 bool b0 = false;
5f8d36fe
BK
44 unsigned long ul1 = 1294967294;
45 unsigned long ul2 = 0;
46 unsigned long ul;
47 double d1 = 1.02345e+308;
48 double d2 = 3.15e-308;
49 double d;
5f8d36fe
BK
50
51 // cache the num_get facet
52 istringstream iss;
53 iss.imbue(loc_c);
54 const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
55 const ios_base::iostate goodbit = ios_base::goodbit;
56 const ios_base::iostate eofbit = ios_base::eofbit;
57 ios_base::iostate err = ios_base::goodbit;
58
59 // C
60 // bool, more twisted examples
61 iss.str("true ");
62 iss.clear();
63 iss.setf(ios_base::boolalpha);
64 err = goodbit;
65 ng.get(iss.rdbuf(), 0, iss, err, b0);
66 VERIFY( b0 == true );
67 VERIFY( err == goodbit );
68
69 iss.str("false ");
70 iss.clear();
71 iss.setf(ios_base::boolalpha);
72 err = goodbit;
73 ng.get(iss.rdbuf(), 0, iss, err, b1);
74 VERIFY( b1 == false );
75 VERIFY( err == goodbit );
76
77 // unsigned long, in a locale that does not group
78 iss.imbue(loc_c);
79 iss.str("1294967294");
80 iss.clear();
81 err = goodbit;
82 ng.get(iss.rdbuf(), 0, iss, err, ul);
83 VERIFY( ul == ul1);
84 VERIFY( err == eofbit );
85
86 iss.str("0+++++++++++++++++++");
87 iss.clear();
88 err = goodbit;
89 ng.get(iss.rdbuf(), 0, iss, err, ul);
90 VERIFY( ul == ul2);
91 VERIFY( err == goodbit );
92
93 // double
94 iss.imbue(loc_c);
95 iss.str("1.02345e+308++++++++");
96 iss.clear();
97 iss.width(20);
98 iss.setf(ios_base::left, ios_base::adjustfield);
99 err = goodbit;
100 ng.get(iss.rdbuf(), 0, iss, err, d);
101 VERIFY( d == d1 );
102 VERIFY( err == goodbit );
103
104 iss.str("+3.15e-308");
105 iss.clear();
106 iss.width(20);
107 iss.setf(ios_base::right, ios_base::adjustfield);
108 err = goodbit;
109 ng.get(iss.rdbuf(), 0, iss, err, d);
110 VERIFY( d == d2 );
111 VERIFY( err == eofbit );
112}
113
114int main()
115{
3d838e28 116 test02();
5f8d36fe
BK
117 return 0;
118}
119
120
121// Kathleen Hannah, humanitarian, woman, art-thief