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