]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/num_get/get/char/4.cc
Update copyright years in libstdc++-v3/
[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-2014 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 bool test __attribute__((unused)) = true;
32
33 // Check num_get works with other iterators besides streambuf
34 // output iterators. (As long as output_iterator requirements are met.)
35 typedef string::const_iterator iter_type;
36 typedef num_get<char, iter_type> num_get_type;
37 const ios_base::iostate goodbit = ios_base::goodbit;
38 ios_base::iostate err = ios_base::goodbit;
39 const locale loc_c = locale::classic();
40 const string str("20000106 Elizabeth Durack");
41 const string str2("0 true 0xbffff74c Durack");
42
43 istringstream iss; // need an ios, add my num_get facet
44 iss.imbue(locale(loc_c, new num_get_type));
45
46 // Iterator advanced, state, output.
47 const num_get_type& ng = use_facet<num_get_type>(iss.getloc());
48
49 // 01 get(long)
50 // 02 get(long double)
51 // 03 get(bool)
52 // 04 get(void*)
53
54 // 01 get(long)
55 long i = 0;
56 err = goodbit;
57 iter_type end1 = ng.get(str.begin(), str.end(), iss, err, i);
58 string rem1(end1, str.end());
59 VERIFY( err == goodbit );
60 VERIFY( i == 20000106);
61 VERIFY( rem1 == " Elizabeth Durack" );
62
63 // 02 get(long double)
64 long double ld = 0.0;
65 err = goodbit;
66 iter_type end2 = ng.get(str.begin(), str.end(), iss, err, ld);
67 string rem2(end2, str.end());
68 VERIFY( err == goodbit );
69 VERIFY( ld == 20000106);
70 VERIFY( rem2 == " Elizabeth Durack" );
71
72 // 03 get(bool)
73 bool b = 1;
74 iss.clear();
75 err = goodbit;
76 iter_type end3 = ng.get(str2.begin(), str2.end(), iss, err, b);
77 string rem3(end3, str2.end());
78 VERIFY( err == goodbit );
79 VERIFY( b == 0 );
80 VERIFY( rem3 == " true 0xbffff74c Durack" );
81
82 iss.clear();
83 err = goodbit;
84 iss.setf(ios_base::boolalpha);
85 iter_type end4 = ng.get(++end3, str2.end(), iss, err, b);
86 string rem4(end4, str2.end());
87 VERIFY( err == goodbit );
88 VERIFY( b == true );
89 VERIFY( rem4 == " 0xbffff74c Durack" );
90
91 // 04 get(void*)
92 void* v;
93 iss.clear();
94 err = goodbit;
95 iss.setf(ios_base::fixed, ios_base::floatfield);
96 iter_type end5 = ng.get(++end4, str2.end(), iss, err, v);
97 string rem5(end5, str2.end());
98 VERIFY( err == goodbit );
99 VERIFY( b == true );
100 VERIFY( rem5 == " Durack" );
101 }
102
103 int main()
104 {
105 test04();
106 return 0;
107 }
108
109
110 // Kathleen Hannah, humanitarian, woman, art-thief