1// 1999-06-28 bkoz 2 3// Copyright (C) 1999-2015 Free Software Foundation, Inc. 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 3, 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 COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20// 24.5.3 template class istreambuf_iterator 21 22#include <sstream> 23#include <iterator> 24#include <testsuite_hooks.h> 25 26bool test02(void) 27{ 28 29 typedef std::istreambuf_iterator<char> cistreambuf_iter; 30 typedef cistreambuf_iter::streambuf_type cstreambuf_type; 31 bool test __attribute__((unused)) = true; 32 const char slit01[] = "playa hermosa, liberia, guanacaste"; 33 std::string str01(slit01); 34 std::istringstream istrs00(str01); 35 std::istringstream istrs01(str01); 36 37 // ctor sanity checks 38 cistreambuf_iter istrb_it01(istrs00); 39 cistreambuf_iter istrb_it02; 40 std::string tmp(istrb_it01, istrb_it02); 41 VERIFY( tmp == str01 ); 42 43 cistreambuf_iter istrb_it03(0); 44 cistreambuf_iter istrb_it04; 45 VERIFY( istrb_it03 == istrb_it04 ); 46 47 cistreambuf_iter istrb_it05(istrs01); 48 cistreambuf_iter istrb_it06(istrs01.rdbuf()); 49 VERIFY( istrb_it05 == istrb_it06 ); 50 51 // bool equal(istreambuf_iter& b) 52 cistreambuf_iter istrb_it07(0); 53 cistreambuf_iter istrb_it08; 54 VERIFY( istrb_it07.equal(istrb_it08) ); 55 cistreambuf_iter istrb_it09(0); 56 cistreambuf_iter istrb_it10; 57 VERIFY( istrb_it10.equal(istrb_it09) ); 58 59 cistreambuf_iter istrb_it11(istrs01); 60 cistreambuf_iter istrb_it12(istrs01.rdbuf()); 61 VERIFY( istrb_it11.equal(istrb_it12) ); 62 cistreambuf_iter istrb_it13(istrs01); 63 cistreambuf_iter istrb_it14(istrs01.rdbuf()); 64 VERIFY( istrb_it14.equal(istrb_it13) ); 65 66 cistreambuf_iter istrb_it15(istrs01); 67 cistreambuf_iter istrb_it16; 68 VERIFY( !(istrb_it15.equal(istrb_it16)) ); 69 cistreambuf_iter istrb_it17(istrs01); 70 cistreambuf_iter istrb_it18; 71 VERIFY( !(istrb_it18.equal(istrb_it17)) ); 72 73 // bool operator==(const istreambuf_iterator&a, const istreambuf_iterator& b) 74 // bool operator!=(const istreambuf_iterator&a, const istreambuf_iterator& b) 75 cistreambuf_iter istrb_it19(0); 76 cistreambuf_iter istrb_it20; 77 VERIFY( istrb_it19 == istrb_it20 ); 78 79 cistreambuf_iter istrb_it21(istrs01); 80 cistreambuf_iter istrb_it22(istrs01.rdbuf()); 81 VERIFY( istrb_it22 == istrb_it21 ); 82 83 cistreambuf_iter istrb_it23(istrs01); 84 cistreambuf_iter istrb_it24; 85 VERIFY( istrb_it23 != istrb_it24 ); 86 87 cistreambuf_iter istrb_it25(0); 88 cistreambuf_iter istrb_it26(istrs01.rdbuf()); 89 VERIFY( istrb_it25 != istrb_it26 ); 90 91 // charT operator*() const 92 // istreambuf_iterator& operator++(); 93 // istreambuf_iterator& operator++(int); 94 cistreambuf_iter istrb_it27(istrs01.rdbuf()); 95 char c; 96 for (std::size_t i = 0; i < sizeof(slit01) - 2; ++i) 97 { 98 c = *istrb_it27++; 99 VERIFY( c == slit01[i] ); 100 } 101 102 std::istringstream istrs02(str01); 103 cistreambuf_iter istrb_it28(istrs02); 104 for (std::size_t i = 0; i < sizeof(slit01) - 2;) 105 { 106 c = *++istrb_it28; 107 VERIFY( c == slit01[++i] ); 108 } 109 return test; 110} 111 112int main() 113{ 114 test02(); 115 return 0; 116} 117