| 1 |
// Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// { dg-do run { target c++11 } } |
| 19 |
// { dg-require-namedlocale "de_DE.ISO8859-15" } |
| 20 |
|
| 21 |
// 27.6.3 template class basic_streambuf |
| 22 |
|
| 23 |
#include <streambuf> |
| 24 |
#include <testsuite_hooks.h> |
| 25 |
|
| 26 |
struct streambuf : std::streambuf |
| 27 |
{ |
| 28 |
streambuf() |
| 29 |
{ |
| 30 |
setp(pbuf, std::end(pbuf)); |
| 31 |
setg(gbuf, gbuf, gbuf); |
| 32 |
} |
| 33 |
|
| 34 |
streambuf(const std::locale& loc) : streambuf() |
| 35 |
{ |
| 36 |
imbue(loc); |
| 37 |
} |
| 38 |
|
| 39 |
// implement tests as member functions to be able to call protected members |
| 40 |
void test_copy() const; |
| 41 |
void test_assign() const; |
| 42 |
void test_swap() const; |
| 43 |
|
| 44 |
char gbuf[32]; |
| 45 |
char pbuf[32]; |
| 46 |
}; |
| 47 |
|
| 48 |
void streambuf::test_copy() const |
| 49 |
{ |
| 50 |
streambuf a(*this); |
| 51 |
|
| 52 |
VERIFY( eback() == a.eback() ); |
| 53 |
VERIFY( gptr() == a.gptr() ); |
| 54 |
VERIFY( egptr() == a.egptr() ); |
| 55 |
VERIFY( pbase() == a.pbase() ); |
| 56 |
VERIFY( pptr() == a.pptr() ); |
| 57 |
VERIFY( epptr() == a.epptr() ); |
| 58 |
VERIFY( getloc() == a.getloc() ); |
| 59 |
} |
| 60 |
|
| 61 |
void streambuf::test_assign() const |
| 62 |
{ |
| 63 |
streambuf a; |
| 64 |
a = *this; |
| 65 |
|
| 66 |
VERIFY( eback() == a.eback() ); |
| 67 |
VERIFY( gptr() == a.gptr() ); |
| 68 |
VERIFY( egptr() == a.egptr() ); |
| 69 |
VERIFY( pbase() == a.pbase() ); |
| 70 |
VERIFY( pptr() == a.pptr() ); |
| 71 |
VERIFY( epptr() == a.epptr() ); |
| 72 |
VERIFY( getloc() == a.getloc() ); |
| 73 |
} |
| 74 |
|
| 75 |
void streambuf::test_swap() const |
| 76 |
{ |
| 77 |
streambuf a(*this); |
| 78 |
streambuf b; |
| 79 |
const streambuf c(b); |
| 80 |
|
| 81 |
a.swap(b); |
| 82 |
|
| 83 |
VERIFY( eback() == b.eback() ); |
| 84 |
VERIFY( gptr() == b.gptr() ); |
| 85 |
VERIFY( egptr() == b.egptr() ); |
| 86 |
VERIFY( pbase() == b.pbase() ); |
| 87 |
VERIFY( pptr() == b.pptr() ); |
| 88 |
VERIFY( epptr() == b.epptr() ); |
| 89 |
VERIFY( getloc() == b.getloc() ); |
| 90 |
|
| 91 |
VERIFY( c.eback() == a.eback() ); |
| 92 |
VERIFY( c.gptr() == a.gptr() ); |
| 93 |
VERIFY( c.egptr() == a.egptr() ); |
| 94 |
VERIFY( c.pbase() == a.pbase() ); |
| 95 |
VERIFY( c.pptr() == a.pptr() ); |
| 96 |
VERIFY( c.epptr() == a.epptr() ); |
| 97 |
VERIFY( c.getloc() == a.getloc() ); |
| 98 |
} |
| 99 |
|
| 100 |
int main() |
| 101 |
{ |
| 102 |
std::locale loc(ISO_8859(15,de_DE)); |
| 103 |
streambuf s(loc); |
| 104 |
s.test_copy(); |
| 105 |
s.test_assign(); |
| 106 |
s.test_swap(); |
| 107 |
} |