OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_other / char / 1.cc
1 // 1999-07-28 bkoz
2
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009
4 // Free Software Foundation
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3.  If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // 27.6.1.2.3 basic_istream::operator>>
22
23 #include <istream>
24 #include <sstream>
25 #include <testsuite_hooks.h>
26
27 // stringbufs.
28 void test01() 
29 {
30   typedef std::ios::traits_type ctraits_type;
31
32   bool test __attribute__((unused)) = true;
33   const std::string str_01;
34   const std::string str_02("art taylor kickin it on DAKAR");
35   std::string strtmp;
36
37   std::stringbuf isbuf_00(std::ios_base::in);
38   std::stringbuf isbuf_01(std::ios_base::in | std::ios_base::out);
39   std::stringbuf isbuf_02(str_01, std::ios_base::in);
40   std::stringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out);
41   std::stringbuf isbuf_04(str_02, std::ios_base::in);
42   std::stringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out);
43
44   std::istream is_00(NULL);
45   std::istream is_01(&isbuf_01);
46   std::istream is_02(&isbuf_02);
47   std::istream is_03(&isbuf_03);
48   std::istream is_04(&isbuf_04);
49   std::istream is_05(&isbuf_05);
50   std::ios_base::iostate state1, state2, statefail, stateeof;
51   statefail = std::ios_base::failbit;
52   stateeof = std::ios_base::eofbit;
53
54
55   // template<_CharT, _Traits>
56   //  basic_istream& operator>>(basic_streambuf*)
57
58   // null istream to empty in_buf
59   state1 = is_00.rdstate();
60   is_00 >> &isbuf_00;   
61   state2 = is_00.rdstate();
62   VERIFY( state1 != state2 );
63   VERIFY( static_cast<bool>(state2 & statefail) );
64   VERIFY( isbuf_00.str() == str_01 ); 
65
66   // null istream to empty in_out_buf
67   is_00.clear(std::ios_base::goodbit);
68   state1 = is_00.rdstate();
69   is_00 >> &isbuf_01;   
70   state2 = is_00.rdstate();
71   VERIFY( state1 != state2 );
72   VERIFY( static_cast<bool>(state2 & statefail) );
73   VERIFY( isbuf_01.str() == str_01 ); 
74
75   // null istream to full in_buf
76   is_00.clear(std::ios_base::goodbit);
77   state1 = is_00.rdstate();
78   is_00 >> &isbuf_04;   
79   state2 = is_00.rdstate();
80   VERIFY( state1 != state2 );
81   VERIFY( static_cast<bool>(state2 & statefail) );
82   VERIFY( isbuf_04.str() == str_02 ); 
83
84   // null istream to full in_out_buf
85   is_00.clear(std::ios_base::goodbit);
86   state1 = is_00.rdstate();
87   is_00 >> &isbuf_05;   
88   state2 = is_00.rdstate();
89   VERIFY( state1 != state2 );
90   VERIFY( static_cast<bool>(state2 & statefail) );
91   VERIFY( isbuf_05.str() == str_02 ); 
92
93   // empty but non-null istream to full in_buf
94   state1 = is_02.rdstate();
95   is_02 >> &isbuf_04;   
96   state2 = is_02.rdstate();
97   VERIFY( state1 != state2 );
98   VERIFY( static_cast<bool>(state2 & statefail) );
99   VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer
100   VERIFY( isbuf_04.sgetc() == 'a' );
101
102   // empty but non-null istream to full in_out_buf
103   is_02.clear(std::ios_base::goodbit);
104   state1 = is_02.rdstate();
105   is_02 >> &isbuf_05;   
106   state2 = is_02.rdstate();
107   VERIFY( state1 != state2 );
108   VERIFY( static_cast<bool>(state2 & statefail) );
109   VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer
110   VERIFY( isbuf_05.sgetc() == 'a' );
111
112   // full istream to empty in_buf (need out_buf, you know?)
113   state1 = is_04.rdstate();
114   is_04 >> &isbuf_02;   
115   state2 = is_04.rdstate();
116   VERIFY( state1 != state2 );
117   VERIFY( static_cast<bool>(state2 & statefail) );
118   VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer
119   VERIFY( isbuf_02.sgetc() == ctraits_type::eof() );
120   VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed
121
122   // full istream to empty in_out_buf
123   is_04.clear(std::ios_base::goodbit);
124   state1 = is_04.rdstate();
125   is_04 >> &isbuf_03;   
126   state2 = is_04.rdstate();
127   VERIFY( state1 != state2 );
128   VERIFY( !static_cast<bool>(state2 & statefail) );
129   VERIFY( state2 == stateeof );
130   strtmp = isbuf_03.str();
131   VERIFY( strtmp == str_02 ); // as only an "in" buffer
132   VERIFY( isbuf_03.sgetc() == 'a' );
133   VERIFY( is_04.peek() == ctraits_type::eof() );
134 }
135
136 int main()
137 {
138   test01();
139   return 0;
140 }