]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / inserters_other / char / 9424-out.cc
CommitLineData
23cac885 1// 1999-10-11 bkoz
b2dad0e3 2
8d9254fc 3// Copyright (C) 1999-2020 Free Software Foundation, Inc.
b2dad0e3
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
b2dad0e3
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
19
b2dad0e3 20
23cac885 21// 27.5.2 template class basic_streambuf
b2dad0e3 22
23cac885
BK
23#include <cstring> // for memset, memcmp
24#include <streambuf>
25#include <sstream>
b2dad0e3 26#include <ostream>
f13a69ec 27#include <testsuite_hooks.h>
b2dad0e3 28
23cac885
BK
29// libstdc++/9424
30class Outbuf_2 : public std::streambuf
bcc6a03a 31{
23cac885
BK
32 char buf[1];
33
34public:
35 Outbuf_2()
36 {
37 setp(buf, buf + 1);
38 }
39
40 int_type overflow(int_type c)
41 {
42 int_type eof = traits_type::eof();
43
44 if (pptr() < epptr())
45 {
46 if (traits_type::eq_int_type(c, eof))
47 return traits_type::not_eof(c);
48
49 *pptr() = traits_type::to_char_type(c);
50 pbump(1);
51 return c;
52 }
53
54 return eof;
55 }
56};
bcc6a03a 57
23cac885 58class Inbuf_2 : public std::streambuf
e6705174 59{
23cac885
BK
60 static const char buf[];
61 const char* current;
62 int size;
63
64public:
65 Inbuf_2()
66 {
67 current = buf;
68 size = std::strlen(buf);
69 }
70
71 int_type underflow()
72 {
73 if (current < buf + size)
74 return traits_type::to_int_type(*current);
75 return traits_type::eof();
76 }
77
78 int_type uflow()
79 {
80 if (current < buf + size)
81 return traits_type::to_int_type(*current++);
82 return traits_type::eof();
83 }
84};
85
86const char Inbuf_2::buf[] = "Atteivlis";
87
88void test12()
fd0bf20c 89{
23cac885
BK
90 Outbuf_2 outbuf2;
91 std::ostream os (&outbuf2);
92 Inbuf_2 inbuf2;
93 os << &inbuf2;
94 VERIFY( inbuf2.sgetc() == 't' );
95 VERIFY( os.good() );
96}
b2dad0e3 97
e6705174
BK
98int main()
99{
23cac885 100 test12();
b2dad0e3
BK
101 return 0;
102}