| 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 <testsuite_hooks.h> |
| 26 |
|
| 27 |
class testbuf : public std::wstreambuf |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
// Typedefs: |
| 32 |
typedef std::wstreambuf::traits_type traits_type; |
| 33 |
typedef std::wstreambuf::char_type char_type; |
| 34 |
|
| 35 |
testbuf(): std::wstreambuf() |
| 36 |
{ } |
| 37 |
|
| 38 |
void |
| 39 |
check_pointers() |
| 40 |
{ |
| 41 |
VERIFY( !this->eback() ); |
| 42 |
VERIFY( !this->gptr() ); |
| 43 |
VERIFY( !this->egptr() ); |
| 44 |
VERIFY( !this->pbase() ); |
| 45 |
VERIFY( !this->pptr() ); |
| 46 |
VERIFY( !this->epptr() ); |
| 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(wchar_t* beg, wchar_t* cur, wchar_t* end) |
| 63 |
{ this->setg(beg, cur, end); } |
| 64 |
|
| 65 |
void |
| 66 |
pub_setp(wchar_t* beg, wchar_t* end) |
| 67 |
{ this->setp(beg, end); } |
| 68 |
|
| 69 |
protected: |
| 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 |
|
| 80 |
void test02() |
| 81 |
{ |
| 82 |
typedef testbuf::traits_type traits_type; |
| 83 |
typedef testbuf::int_type int_type; |
| 84 |
|
| 85 |
wchar_t lit01[] = L"chicago underground trio/possible cube on delmark"; |
| 86 |
size_t i01 = traits_type::length(lit01); |
| 87 |
|
| 88 |
testbuf buf01; |
| 89 |
|
| 90 |
// 27.5.2.1 basic_streambuf ctors |
| 91 |
// default ctor initializes |
| 92 |
// - all pointer members to null pointers |
| 93 |
// - locale to current global locale |
| 94 |
buf01.check_pointers(); |
| 95 |
VERIFY( buf01.getloc() == std::locale() ); |
| 96 |
|
| 97 |
// 27.5.2.2.5 Put area |
| 98 |
|
| 99 |
wchar_t carray01[i01]; |
| 100 |
std::wmemset(carray01, 0, i01); |
| 101 |
|
| 102 |
buf01.pub_setg(lit01, lit01, lit01 + i01); |
| 103 |
buf01.sgetn(carray01, 0); |
| 104 |
VERIFY( carray01[0] == 0 ); |
| 105 |
buf01.sgetn(carray01, 1); |
| 106 |
VERIFY( carray01[0] == L'c' ); |
| 107 |
buf01.sgetn(carray01 + 1, i01 - 1); |
| 108 |
VERIFY( carray01[0] == L'c' ); |
| 109 |
VERIFY( carray01[1] == L'h' ); |
| 110 |
VERIFY( carray01[i01 - 1] == L'k' ); |
| 111 |
} |
| 112 |
|
| 113 |
int main() |
| 114 |
{ |
| 115 |
test02(); |
| 116 |
return 0; |
| 117 |
} |