1// 1999-10-11 bkoz 2 3// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 4// Free Software Foundation, Inc. 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 22// 27.5.2 template class basic_streambuf 23 24#include <cstring> // for memset, memcmp 25#include <streambuf> 26#include <sstream> 27#include <ostream> 28#include <testsuite_hooks.h> 29 30// libstdc++/9424 31class Outbuf_2 : public std::streambuf 32{ 33 char buf[1]; 34 35public: 36 Outbuf_2() 37 { 38 setp(buf, buf + 1); 39 } 40 41 int_type overflow(int_type c) 42 { 43 int_type eof = traits_type::eof(); 44 45 if (pptr() < epptr()) 46 { 47 if (traits_type::eq_int_type(c, eof)) 48 return traits_type::not_eof(c); 49 50 *pptr() = traits_type::to_char_type(c); 51 pbump(1); 52 return c; 53 } 54 55 return eof; 56 } 57}; 58 59class Inbuf_2 : public std::streambuf 60{ 61 static const char buf[]; 62 const char* current; 63 int size; 64 65public: 66 Inbuf_2() 67 { 68 current = buf; 69 size = std::strlen(buf); 70 } 71 72 int_type underflow() 73 { 74 if (current < buf + size) 75 return traits_type::to_int_type(*current); 76 return traits_type::eof(); 77 } 78 79 int_type uflow() 80 { 81 if (current < buf + size) 82 return traits_type::to_int_type(*current++); 83 return traits_type::eof(); 84 } 85}; 86 87const char Inbuf_2::buf[] = "Atteivlis"; 88 89void test12() 90{ 91 bool test __attribute__((unused)) = true; 92 93 Outbuf_2 outbuf2; 94 std::ostream os (&outbuf2); 95 Inbuf_2 inbuf2; 96 os << &inbuf2; 97 VERIFY( inbuf2.sgetc() == 't' ); 98 VERIFY( os.good() ); 99} 100 101int main() 102{ 103 test12(); 104 return 0; 105} 106