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