]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9424-in.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_other / char / 9424-in.cc
CommitLineData
23cac885 1// 1999-10-11 bkoz
b2dad0e3 2
748086b7
JJ
3// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009
4// Free Software Foundation, Inc.
b2dad0e3
BK
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
748086b7 9// Free Software Foundation; either version 3, or (at your option)
b2dad0e3
BK
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
748086b7
JJ
18// with this library; see the file COPYING3. If not see
19// <http://www.gnu.org/licenses/>.
20
b2dad0e3 21
23cac885 22// 27.5.2 template class basic_streambuf
b2dad0e3 23
23cac885
BK
24#include <cstring> // for memset, memcmp
25#include <streambuf>
26#include <sstream>
b2dad0e3 27#include <ostream>
f13a69ec 28#include <testsuite_hooks.h>
b2dad0e3 29
23cac885
BK
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 }
e6705174 54
23cac885
BK
55 return eof;
56 }
57};
58
59class Inbuf_2 : public std::streambuf
bcc6a03a 60{
23cac885
BK
61 static const char buf[];
62 const char* current;
63 int size;
bcc6a03a 64
23cac885
BK
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 test11()
e6705174 90{
11f10e6b 91 bool test __attribute__((unused)) = true;
23cac885
BK
92
93 Inbuf_2 inbuf1;
94 std::istream is(&inbuf1);
95 Outbuf_2 outbuf1;
96 is >> &outbuf1;
97 VERIFY( inbuf1.sgetc() == 't' );
98 VERIFY( is.good() );
99}
b2dad0e3 100
e6705174
BK
101int main()
102{
23cac885 103 test11();
b2dad0e3
BK
104 return 0;
105}