2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / wchar_t / 4.cc
blob9b956571d02fea39da3c6ee065d555bc67057aa0
1 // 2001-11-21 Benjamin Kosnik <bkoz@redhat.com>
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.
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.
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.
21 // 22.2.2.1.1 num_get members
23 #include <locale>
24 #include <sstream>
25 #include <testsuite_hooks.h>
27 // 2002-01-10 David Seymour <seymour_dj@yahoo.com>
28 // libstdc++/5331
29 void test04()
31 using namespace std;
32 bool test __attribute__((unused)) = true;
34 // Check num_get works with other iterators besides streambuf
35 // output iterators. (As long as output_iterator requirements are met.)
36 typedef wstring::const_iterator iter_type;
37 typedef num_get<wchar_t, iter_type> num_get_type;
38 const ios_base::iostate goodbit = ios_base::goodbit;
39 ios_base::iostate err = ios_base::goodbit;
40 const locale loc_c = locale::classic();
41 const wstring str(L"20000106 Elizabeth Durack");
42 const wstring str2(L"0 true 0xbffff74c Durack");
44 wistringstream iss; // need an ios, add my num_get facet
45 iss.imbue(locale(loc_c, new num_get_type));
47 // Iterator advanced, state, output.
48 const num_get_type& ng = use_facet<num_get_type>(iss.getloc());
50 // 01 get(long)
51 // 02 get(long double)
52 // 03 get(bool)
53 // 04 get(void*)
55 // 01 get(long)
56 long i = 0;
57 err = goodbit;
58 iter_type end1 = ng.get(str.begin(), str.end(), iss, err, i);
59 wstring rem1(end1, str.end());
60 VERIFY( err == goodbit );
61 VERIFY( i == 20000106);
62 VERIFY( rem1 == L" Elizabeth Durack" );
64 // 02 get(long double)
65 long double ld = 0.0;
66 err = goodbit;
67 iter_type end2 = ng.get(str.begin(), str.end(), iss, err, ld);
68 wstring rem2(end2, str.end());
69 VERIFY( err == goodbit );
70 VERIFY( ld == 20000106);
71 VERIFY( rem2 == L" Elizabeth Durack" );
73 // 03 get(bool)
74 bool b = 1;
75 iss.clear();
76 err = goodbit;
77 iter_type end3 = ng.get(str2.begin(), str2.end(), iss, err, b);
78 wstring rem3(end3, str2.end());
79 VERIFY( err == goodbit );
80 VERIFY( b == 0 );
81 VERIFY( rem3 == L" true 0xbffff74c Durack" );
83 iss.clear();
84 err = goodbit;
85 iss.setf(ios_base::boolalpha);
86 iter_type end4 = ng.get(++end3, str2.end(), iss, err, b);
87 wstring rem4(end4, str2.end());
88 VERIFY( err == goodbit );
89 VERIFY( b == true );
90 VERIFY( rem4 == L" 0xbffff74c Durack" );
92 // 04 get(void*)
93 void* v;
94 iss.clear();
95 err = goodbit;
96 iss.setf(ios_base::fixed, ios_base::floatfield);
97 iter_type end5 = ng.get(++end4, str2.end(), iss, err, v);
98 wstring rem5(end5, str2.end());
99 VERIFY( err == goodbit );
100 VERIFY( b == true );
101 VERIFY( rem5 == L" Durack" );
104 int main()
106 test04();
107 return 0;
111 // Kathleen Hannah, humanitarian, woman, art-thief