]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/num_get/get/char/4.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 4.cc
1 // 2001-11-21 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001-2022 Free Software Foundation, Inc.
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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 22.2.2.1.1 num_get members
21
22 #include <locale>
23 #include <sstream>
24 #include <testsuite_hooks.h>
25
26 // 2002-01-10 David Seymour <seymour_dj@yahoo.com>
27 // libstdc++/5331
28 void test04()
29 {
30 using namespace std;
31
32 // Check num_get works with other iterators besides streambuf
33 // output iterators. (As long as output_iterator requirements are met.)
34 typedef string::const_iterator iter_type;
35 typedef num_get<char, iter_type> num_get_type;
36 const ios_base::iostate goodbit = ios_base::goodbit;
37 ios_base::iostate err = ios_base::goodbit;
38 const locale loc_c = locale::classic();
39 const string str("20000106 Elizabeth Durack");
40 const string str2("0 true 0xbffff74c Durack");
41
42 istringstream iss; // need an ios, add my num_get facet
43 iss.imbue(locale(loc_c, new num_get_type));
44
45 // Iterator advanced, state, output.
46 const num_get_type& ng = use_facet<num_get_type>(iss.getloc());
47
48 // 01 get(long)
49 // 02 get(long double)
50 // 03 get(bool)
51 // 04 get(void*)
52
53 // 01 get(long)
54 long i = 0;
55 err = goodbit;
56 iter_type end1 = ng.get(str.begin(), str.end(), iss, err, i);
57 string rem1(end1, str.end());
58 VERIFY( err == goodbit );
59 VERIFY( i == 20000106);
60 VERIFY( rem1 == " Elizabeth Durack" );
61
62 // 02 get(long double)
63 long double ld = 0.0;
64 err = goodbit;
65 iter_type end2 = ng.get(str.begin(), str.end(), iss, err, ld);
66 string rem2(end2, str.end());
67 VERIFY( err == goodbit );
68 VERIFY( ld == 20000106);
69 VERIFY( rem2 == " Elizabeth Durack" );
70
71 // 03 get(bool)
72 bool b = 1;
73 iss.clear();
74 err = goodbit;
75 iter_type end3 = ng.get(str2.begin(), str2.end(), iss, err, b);
76 string rem3(end3, str2.end());
77 VERIFY( err == goodbit );
78 VERIFY( b == 0 );
79 VERIFY( rem3 == " true 0xbffff74c Durack" );
80
81 iss.clear();
82 err = goodbit;
83 iss.setf(ios_base::boolalpha);
84 iter_type end4 = ng.get(++end3, str2.end(), iss, err, b);
85 string rem4(end4, str2.end());
86 VERIFY( err == goodbit );
87 VERIFY( b == true );
88 VERIFY( rem4 == " 0xbffff74c Durack" );
89
90 // 04 get(void*)
91 void* v;
92 iss.clear();
93 err = goodbit;
94 iss.setf(ios_base::fixed, ios_base::floatfield);
95 iter_type end5 = ng.get(++end4, str2.end(), iss, err, v);
96 string rem5(end5, str2.end());
97 VERIFY( err == goodbit );
98 VERIFY( b == true );
99 VERIFY( rem5 == " Durack" );
100 }
101
102 int main()
103 {
104 test04();
105 return 0;
106 }
107
108
109 // Kathleen Hannah, humanitarian, woman, art-thief