Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / sputn / char / 1.cc
blobd4a7e9cfabcbc808ddfd658fcce2a242f80ebbe6
1 // 1999-10-11 bkoz
3 // Copyright (C) 1999-2013 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.
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.
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/>.
21 // 27.5.2 template class basic_streambuf
23 #include <streambuf>
24 #include <cstring>
25 #include <testsuite_hooks.h>
27 class testbuf : public std::streambuf
29 public:
31 // Typedefs:
32 typedef std::streambuf::traits_type traits_type;
33 typedef std::streambuf::char_type char_type;
35 testbuf(): std::streambuf()
36 { }
38 bool
39 check_pointers()
41 bool test __attribute__((unused)) = true;
42 VERIFY( !this->eback() );
43 VERIFY( !this->gptr() );
44 VERIFY( !this->egptr() );
45 VERIFY( !this->pbase() );
46 VERIFY( !this->pptr() );
47 VERIFY( !this->epptr() );
48 return test;
51 int_type
52 pub_uflow()
53 { return (this->uflow()); }
55 int_type
56 pub_overflow(int_type __c = traits_type::eof())
57 { return (this->overflow(__c)); }
59 int_type
60 pub_pbackfail(int_type __c)
61 { return (this->pbackfail(__c)); }
63 void
64 pub_setg(char* beg, char* cur, char *end)
65 { this->setg(beg, cur, end); }
67 void
68 pub_setp(char* beg, char* end)
69 { this->setp(beg, end); }
71 protected:
72 int_type
73 underflow()
75 int_type __retval = traits_type::eof();
76 if (this->gptr() < this->egptr())
77 __retval = traits_type::not_eof(0);
78 return __retval;
82 void test01()
84 typedef testbuf::traits_type traits_type;
85 typedef testbuf::int_type int_type;
87 bool test __attribute__((unused)) = true;
88 testbuf buf01;
90 // sputn/xsputn
91 char lit02[] = "isotope 217: the unstable molecule on thrill jockey";
92 const int i02 = std::strlen(lit02);
94 char carray[i02 + 1];
95 std::memset(carray, 0, i02 + 1);
97 buf01.pub_setp(carray, (carray + i02));
98 buf01.sputn(lit02, 0);
99 VERIFY( carray[0] == 0 );
100 VERIFY( lit02[0] == 'i' );
101 buf01.sputn(lit02, 1);
102 VERIFY( lit02[0] == carray[0] );
103 VERIFY( lit02[1] == 's' );
104 VERIFY( carray[1] == 0 );
105 buf01.sputn(lit02 + 1, 10);
106 VERIFY( std::memcmp(lit02, carray, 10) == 0 );
107 buf01.sputn(lit02 + 11, 20);
108 VERIFY( std::memcmp(lit02, carray, 30) == 0 );
111 int main()
113 test01();
114 return 0;