OSDN Git Service

2003-09-23 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.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 __attribute__((unused)) = 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   ios_base::iostate err = ios_base::goodbit;
40   const locale loc_c = locale::classic();
41   const string str("20000106 Elizabeth Durack");
42   const string str2("0 true 0xbffff74c Durack");
43
44   istringstream iss; // need an ios, add my num_get facet
45   iss.imbue(locale(loc_c, new num_get_type));
46
47   // Iterator advanced, state, output.
48   const num_get_type& ng = use_facet<num_get_type>(iss.getloc());
49
50   // 01 get(long)
51   // 02 get(long double)
52   // 03 get(bool)
53   // 04 get(void*)
54
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   string rem1(end1, str.end());
60   VERIFY( err == goodbit );
61   VERIFY( i == 20000106);
62   VERIFY( rem1 == " Elizabeth Durack" );
63
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   string rem2(end2, str.end());
69   VERIFY( err == goodbit );
70   VERIFY( ld == 20000106);
71   VERIFY( rem2 == " Elizabeth Durack" );
72
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   string rem3(end3, str2.end());
79   VERIFY( err == goodbit );
80   VERIFY( b == 0 );
81   VERIFY( rem3 == " true 0xbffff74c Durack" );
82
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   string rem4(end4, str2.end());
88   VERIFY( err == goodbit );
89   VERIFY( b == true );
90   VERIFY( rem4 == " 0xbffff74c Durack" );
91
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   string rem5(end5, str2.end());
99   VERIFY( err == goodbit );
100   VERIFY( b == true );
101   VERIFY( rem5 == " Durack" );
102 }
103
104 int main()
105 {
106   test04();
107   return 0;
108 }
109
110
111 // Kathleen Hannah, humanitarian, woman, art-thief