]>
Commit | Line | Data |
---|---|---|
fbd26352 | 1 | // Copyright (C) 2003-2019 Free Software Foundation, Inc. |
1ef3ba97 | 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 | |
6bc9506f | 6 | // Free Software Foundation; either version 3, or (at your option) |
1ef3ba97 | 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 | |
6bc9506f | 15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
1ef3ba97 | 17 | |
18 | // 22.2.2.1.1 num_get members | |
19 | ||
20 | #include <locale> | |
21 | #include <sstream> | |
22 | #include <testsuite_hooks.h> | |
23 | ||
4c5a278e | 24 | struct Punct1: std::numpunct<char> |
1ef3ba97 | 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 | ||
4c5a278e | 31 | struct 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 | ||
22831f13 | 38 | // http://gcc.gnu.org/ml/libstdc++/2003-12/msg00201.html |
1ef3ba97 | 39 | void test01() |
40 | { | |
41 | using namespace std; | |
42 | typedef istreambuf_iterator<char> iterator_type; | |
1ef3ba97 | 43 | |
4c5a278e | 44 | istringstream iss1, iss2; |
4d4d9c37 | 45 | iss1.imbue(locale(iss1.getloc(), new Punct1)); |
46 | iss2.imbue(locale(iss2.getloc(), new Punct2)); | |
4c5a278e | 47 | const num_get<char>& ng1 = use_facet<num_get<char> >(iss1.getloc()); |
48 | const num_get<char>& ng2 = use_facet<num_get<char> >(iss2.getloc()); | |
49 | ||
1ef3ba97 | 50 | ios_base::iostate err = ios_base::goodbit; |
51 | iterator_type end; | |
52 | double d = 0.0; | |
53 | double d1 = 13.0; | |
4c5a278e | 54 | double d2 = 1.0; |
55 | double d3 = 30.0; | |
1ef3ba97 | 56 | long l = 0l; |
57 | long l1 = 13l; | |
4c5a278e | 58 | long l2 = 10l; |
1ef3ba97 | 59 | |
4c5a278e | 60 | iss1.str("1234"); |
1ef3ba97 | 61 | err = ios_base::goodbit; |
4c5a278e | 62 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); |
1ef3ba97 | 63 | VERIFY( err == ios_base::eofbit ); |
64 | VERIFY( d == d1 ); | |
65 | ||
4c5a278e | 66 | iss1.str("142"); |
67 | iss1.clear(); | |
68 | err = ios_base::goodbit; | |
69 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); | |
70 | VERIFY( err == ios_base::goodbit ); | |
71 | VERIFY( d == d2 ); | |
72 | ||
73 | iss1.str("3e14"); | |
74 | iss1.clear(); | |
75 | err = ios_base::goodbit; | |
76 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, d); | |
77 | VERIFY( err == ios_base::goodbit ); | |
78 | VERIFY( d == d3 ); | |
79 | ||
80 | iss1.str("1234"); | |
81 | iss1.clear(); | |
1ef3ba97 | 82 | err = ios_base::goodbit; |
4c5a278e | 83 | end = ng1.get(iss1.rdbuf(), 0, iss1, err, l); |
1ef3ba97 | 84 | VERIFY( err == ios_base::goodbit ); |
85 | VERIFY( l == l1 ); | |
1ef3ba97 | 86 | |
4c5a278e | 87 | iss2.str("123"); |
88 | err = ios_base::goodbit; | |
89 | end = ng2.get(iss2.rdbuf(), 0, iss2, err, d); | |
90 | VERIFY( err == ios_base::eofbit ); | |
91 | VERIFY( d == d1 ); | |
92 | ||
93 | iss2.str("120"); | |
94 | iss2.clear(); | |
95 | err = ios_base::goodbit; | |
96 | end = ng2.get(iss2.rdbuf(), 0, iss2, err, l); | |
97 | VERIFY( err == ios_base::eofbit ); | |
98 | VERIFY( l == l2 ); | |
99 | } | |
1ef3ba97 | 100 | |
101 | int main() | |
102 | { | |
103 | test01(); | |
104 | return 0; | |
105 | } |