| 1 |
// 1999-10-11 bkoz |
| 2 |
|
| 3 |
// Copyright (C) 1999-2025 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. |
| 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 |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
|
| 21 |
// 27.5.2 template class basic_streambuf |
| 22 |
|
| 23 |
#include <streambuf> |
| 24 |
#include <cwchar> |
| 25 |
#include <cstring> |
| 26 |
#include <testsuite_hooks.h> |
| 27 |
|
| 28 |
class testbuf : public std::wstreambuf |
| 29 |
{ |
| 30 |
public: |
| 31 |
|
| 32 |
// Typedefs: |
| 33 |
typedef std::wstreambuf::traits_type traits_type; |
| 34 |
typedef std::wstreambuf::char_type char_type; |
| 35 |
|
| 36 |
testbuf(): std::wstreambuf() |
| 37 |
{ } |
| 38 |
|
| 39 |
void |
| 40 |
check_pointers() |
| 41 |
{ |
| 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 |
} |
| 49 |
|
| 50 |
int_type |
| 51 |
pub_uflow() |
| 52 |
{ return (this->uflow()); } |
| 53 |
|
| 54 |
int_type |
| 55 |
pub_overflow(int_type __c = traits_type::eof()) |
| 56 |
{ return (this->overflow(__c)); } |
| 57 |
|
| 58 |
int_type |
| 59 |
pub_pbackfail(int_type __c) |
| 60 |
{ return (this->pbackfail(__c)); } |
| 61 |
|
| 62 |
void |
| 63 |
pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) |
| 64 |
{ this->setg(beg, cur, end); } |
| 65 |
|
| 66 |
void |
| 67 |
pub_setp(wchar_t* beg, wchar_t* end) |
| 68 |
{ this->setp(beg, end); } |
| 69 |
|
| 70 |
protected: |
| 71 |
int_type |
| 72 |
underflow() |
| 73 |
{ |
| 74 |
int_type __retval = traits_type::eof(); |
| 75 |
if (this->gptr() < this->egptr()) |
| 76 |
__retval = traits_type::not_eof(0); |
| 77 |
return __retval; |
| 78 |
} |
| 79 |
}; |
| 80 |
|
| 81 |
void test01() |
| 82 |
{ |
| 83 |
typedef testbuf::traits_type traits_type; |
| 84 |
typedef testbuf::int_type int_type; |
| 85 |
|
| 86 |
testbuf buf01; |
| 87 |
|
| 88 |
// sputn/xsputn |
| 89 |
wchar_t lit02[] = L"isotope 217: the unstable molecule on thrill jockey"; |
| 90 |
const int i02 = std::wcslen(lit02); |
| 91 |
|
| 92 |
wchar_t carray[i02 + 1]; |
| 93 |
std::wmemset(carray, 0, i02 + 1); |
| 94 |
|
| 95 |
buf01.pub_setp(carray, (carray + i02)); |
| 96 |
buf01.sputn(lit02, 0); |
| 97 |
VERIFY( carray[0] == 0 ); |
| 98 |
VERIFY( lit02[0] == L'i' ); |
| 99 |
buf01.sputn(lit02, 1); |
| 100 |
VERIFY( lit02[0] == carray[0] ); |
| 101 |
VERIFY( lit02[1] == L's' ); |
| 102 |
VERIFY( carray[1] == 0 ); |
| 103 |
buf01.sputn(lit02 + 1, 10); |
| 104 |
VERIFY( std::memcmp(lit02, carray, 10) == 0 ); |
| 105 |
buf01.sputn(lit02 + 11, 20); |
| 106 |
VERIFY( std::memcmp(lit02, carray, 30) == 0 ); |
| 107 |
} |
| 108 |
|
| 109 |
int main() |
| 110 |
{ |
| 111 |
test01(); |
| 112 |
return 0; |
| 113 |
} |