]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / sputn / char / 1.cc
CommitLineData
23cac885
BK
1// 1999-10-11 bkoz
2
a5544970 3// Copyright (C) 1999-2019 Free Software Foundation, Inc.
23cac885
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)
23cac885
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/>.
23cac885 19
23cac885
BK
20
21// 27.5.2 template class basic_streambuf
22
23#include <streambuf>
1b716e90 24#include <cstring>
23cac885
BK
25#include <testsuite_hooks.h>
26
27class testbuf : public std::streambuf
28{
29public:
30
31 // Typedefs:
32 typedef std::streambuf::traits_type traits_type;
33 typedef std::streambuf::char_type char_type;
34
35 testbuf(): std::streambuf()
cd16e04b 36 { }
23cac885 37
fd0bf20c 38 void
23cac885 39 check_pointers()
fd0bf20c 40 {
8fc81078
PC
41 VERIFY( !this->eback() );
42 VERIFY( !this->gptr() );
43 VERIFY( !this->egptr() );
44 VERIFY( !this->pbase() );
45 VERIFY( !this->pptr() );
46 VERIFY( !this->epptr() );
23cac885
BK
47 }
48
49 int_type
50 pub_uflow()
51 { return (this->uflow()); }
52
53 int_type
54 pub_overflow(int_type __c = traits_type::eof())
55 { return (this->overflow(__c)); }
56
57 int_type
58 pub_pbackfail(int_type __c)
59 { return (this->pbackfail(__c)); }
60
61 void
62 pub_setg(char* beg, char* cur, char *end)
63 { this->setg(beg, cur, end); }
64
65 void
66 pub_setp(char* beg, char* end)
67 { this->setp(beg, end); }
68
69protected:
70 int_type
71 underflow()
72 {
73 int_type __retval = traits_type::eof();
74 if (this->gptr() < this->egptr())
75 __retval = traits_type::not_eof(0);
76 return __retval;
77 }
78};
79
80void test01()
81{
82 typedef testbuf::traits_type traits_type;
83 typedef testbuf::int_type int_type;
84
23cac885 85 testbuf buf01;
23cac885
BK
86
87 // sputn/xsputn
894b1dff
MF
88 char lit02[] = "isotope 217: the unstable molecule on thrill jockey";
89 const int i02 = std::strlen(lit02);
11f10e6b 90
23cac885
BK
91 char carray[i02 + 1];
92 std::memset(carray, 0, i02 + 1);
93
94 buf01.pub_setp(carray, (carray + i02));
95 buf01.sputn(lit02, 0);
96 VERIFY( carray[0] == 0 );
97 VERIFY( lit02[0] == 'i' );
98 buf01.sputn(lit02, 1);
99 VERIFY( lit02[0] == carray[0] );
100 VERIFY( lit02[1] == 's' );
101 VERIFY( carray[1] == 0 );
102 buf01.sputn(lit02 + 1, 10);
103 VERIFY( std::memcmp(lit02, carray, 10) == 0 );
104 buf01.sputn(lit02 + 11, 20);
105 VERIFY( std::memcmp(lit02, carray, 30) == 0 );
106}
107
108int main()
109{
110 test01();
111 return 0;
112}