1// 1999-10-11 bkoz
2
3// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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 <streambuf>
25#include <cwchar>
26#include <cstring>
27#include <testsuite_hooks.h>
28
29class testbuf : public std::wstreambuf
30{
31public:
32
33  // Typedefs:
34  typedef std::wstreambuf::traits_type traits_type;
35  typedef std::wstreambuf::char_type char_type;
36
37  testbuf(): std::wstreambuf()
38  { }
39
40  bool
41  check_pointers()
42  {
43    bool test __attribute__((unused)) = true;
44    VERIFY( this->eback() == NULL );
45    VERIFY( this->gptr() == NULL );
46    VERIFY( this->egptr() == NULL );
47    VERIFY( this->pbase() == NULL );
48    VERIFY( this->pptr() == NULL );
49    VERIFY( this->epptr() == NULL );
50    return test;
51  }
52
53  int_type
54  pub_uflow()
55  { return (this->uflow()); }
56
57  int_type
58  pub_overflow(int_type __c = traits_type::eof())
59  { return (this->overflow(__c)); }
60
61  int_type
62  pub_pbackfail(int_type __c)
63  { return (this->pbackfail(__c)); }
64
65  void
66  pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end)
67  { this->setg(beg, cur, end); }
68
69  void
70  pub_setp(wchar_t* beg, wchar_t* end)
71  { this->setp(beg, end); }
72
73protected:
74  int_type
75  underflow()
76  {
77    int_type __retval = traits_type::eof();
78    if (this->gptr() < this->egptr())
79      __retval = traits_type::not_eof(0);
80    return __retval;
81  }
82};
83
84void test01()
85{
86  typedef testbuf::traits_type traits_type;
87  typedef testbuf::int_type int_type;
88
89  bool test __attribute__((unused)) = true;
90  testbuf buf01;
91
92  // sputn/xsputn
93  wchar_t lit02[] = L"isotope 217: the unstable molecule on thrill jockey";
94  const int i02 = std::wcslen(lit02);
95
96  wchar_t carray[i02 + 1];
97  std::wmemset(carray, 0, i02 + 1);
98
99  buf01.pub_setp(carray, (carray + i02));
100  buf01.sputn(lit02, 0);
101  VERIFY( carray[0] == 0 );
102  VERIFY( lit02[0] == L'i' );
103  buf01.sputn(lit02, 1);
104  VERIFY( lit02[0] == carray[0] );
105  VERIFY( lit02[1] == L's' );
106  VERIFY( carray[1] == 0 );
107  buf01.sputn(lit02 + 1, 10);
108  VERIFY( std::memcmp(lit02, carray, 10) == 0 );
109  buf01.sputn(lit02 + 11, 20);
110  VERIFY( std::memcmp(lit02, carray, 30) == 0 );
111}
112
113int main()
114{
115  test01();
116  return 0;
117}
118