]>
Commit | Line | Data |
---|---|---|
5f8d36fe BK |
1 | // 2001-11-21 Benjamin Kosnik <bkoz@redhat.com> |
2 | ||
748086b7 | 3 | // Copyright (C) 2001, 2002, 2003, 2004, 2009 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 | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
5f8d36fe BK |
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 | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
5f8d36fe BK |
19 | |
20 | // 22.2.2.1.1 num_get members | |
21 | ||
a5ea7a0b RS |
22 | // { dg-do run { xfail lax_strtofp } } |
23 | ||
5f8d36fe BK |
24 | #include <locale> |
25 | #include <sstream> | |
26 | #include <testsuite_hooks.h> | |
27 | ||
28 | void test02() | |
29 | { | |
30 | using namespace std; | |
31 | typedef istreambuf_iterator<char> iterator_type; | |
32 | ||
11f10e6b | 33 | bool test __attribute__((unused)) = true; |
5f8d36fe BK |
34 | |
35 | // basic construction | |
36 | locale loc_c = locale::classic(); | |
5f8d36fe | 37 | |
5f8d36fe BK |
38 | // sanity check the data is correct. |
39 | const string empty; | |
5f8d36fe BK |
40 | |
41 | bool b1 = true; | |
42 | bool b0 = false; | |
5f8d36fe BK |
43 | unsigned long ul1 = 1294967294; |
44 | unsigned long ul2 = 0; | |
45 | unsigned long ul; | |
46 | double d1 = 1.02345e+308; | |
47 | double d2 = 3.15e-308; | |
48 | double d; | |
5f8d36fe BK |
49 | |
50 | // cache the num_get facet | |
51 | istringstream iss; | |
52 | iss.imbue(loc_c); | |
53 | const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc()); | |
54 | const ios_base::iostate goodbit = ios_base::goodbit; | |
55 | const ios_base::iostate eofbit = ios_base::eofbit; | |
56 | ios_base::iostate err = ios_base::goodbit; | |
57 | ||
58 | // C | |
59 | // bool, more twisted examples | |
60 | iss.str("true "); | |
61 | iss.clear(); | |
62 | iss.setf(ios_base::boolalpha); | |
63 | err = goodbit; | |
64 | ng.get(iss.rdbuf(), 0, iss, err, b0); | |
65 | VERIFY( b0 == true ); | |
66 | VERIFY( err == goodbit ); | |
67 | ||
68 | iss.str("false "); | |
69 | iss.clear(); | |
70 | iss.setf(ios_base::boolalpha); | |
71 | err = goodbit; | |
72 | ng.get(iss.rdbuf(), 0, iss, err, b1); | |
73 | VERIFY( b1 == false ); | |
74 | VERIFY( err == goodbit ); | |
75 | ||
76 | // unsigned long, in a locale that does not group | |
77 | iss.imbue(loc_c); | |
78 | iss.str("1294967294"); | |
79 | iss.clear(); | |
80 | err = goodbit; | |
81 | ng.get(iss.rdbuf(), 0, iss, err, ul); | |
82 | VERIFY( ul == ul1); | |
83 | VERIFY( err == eofbit ); | |
84 | ||
85 | iss.str("0+++++++++++++++++++"); | |
86 | iss.clear(); | |
87 | err = goodbit; | |
88 | ng.get(iss.rdbuf(), 0, iss, err, ul); | |
89 | VERIFY( ul == ul2); | |
90 | VERIFY( err == goodbit ); | |
91 | ||
92 | // double | |
93 | iss.imbue(loc_c); | |
94 | iss.str("1.02345e+308++++++++"); | |
95 | iss.clear(); | |
96 | iss.width(20); | |
97 | iss.setf(ios_base::left, ios_base::adjustfield); | |
98 | err = goodbit; | |
99 | ng.get(iss.rdbuf(), 0, iss, err, d); | |
100 | VERIFY( d == d1 ); | |
101 | VERIFY( err == goodbit ); | |
102 | ||
103 | iss.str("+3.15e-308"); | |
104 | iss.clear(); | |
105 | iss.width(20); | |
106 | iss.setf(ios_base::right, ios_base::adjustfield); | |
107 | err = goodbit; | |
108 | ng.get(iss.rdbuf(), 0, iss, err, d); | |
109 | VERIFY( d == d2 ); | |
110 | VERIFY( err == eofbit ); | |
111 | } | |
112 | ||
113 | int main() | |
114 | { | |
3d838e28 | 115 | test02(); |
5f8d36fe BK |
116 | return 0; |
117 | } | |
118 | ||
119 | ||
120 | // Kathleen Hannah, humanitarian, woman, art-thief |