]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_streambuf/cons/57394.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_streambuf / cons / 57394.cc
1 // Copyright (C) 2014-2016 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-options "-std=gnu++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 bool test __attribute__((unused)) = true;
51
52 streambuf a(*this);
53
54 VERIFY( eback() == a.eback() );
55 VERIFY( gptr() == a.gptr() );
56 VERIFY( egptr() == a.egptr() );
57 VERIFY( pbase() == a.pbase() );
58 VERIFY( pptr() == a.pptr() );
59 VERIFY( epptr() == a.epptr() );
60 VERIFY( getloc() == a.getloc() );
61 }
62
63 void streambuf::test_assign() const
64 {
65 bool test __attribute__((unused)) = true;
66
67 streambuf a;
68 a = *this;
69
70 VERIFY( eback() == a.eback() );
71 VERIFY( gptr() == a.gptr() );
72 VERIFY( egptr() == a.egptr() );
73 VERIFY( pbase() == a.pbase() );
74 VERIFY( pptr() == a.pptr() );
75 VERIFY( epptr() == a.epptr() );
76 VERIFY( getloc() == a.getloc() );
77 }
78
79 void streambuf::test_swap() const
80 {
81 bool test __attribute__((unused)) = true;
82
83 streambuf a(*this);
84 streambuf b;
85 const streambuf c(b);
86
87 a.swap(b);
88
89 VERIFY( eback() == b.eback() );
90 VERIFY( gptr() == b.gptr() );
91 VERIFY( egptr() == b.egptr() );
92 VERIFY( pbase() == b.pbase() );
93 VERIFY( pptr() == b.pptr() );
94 VERIFY( epptr() == b.epptr() );
95 VERIFY( getloc() == b.getloc() );
96
97 VERIFY( c.eback() == a.eback() );
98 VERIFY( c.gptr() == a.gptr() );
99 VERIFY( c.egptr() == a.egptr() );
100 VERIFY( c.pbase() == a.pbase() );
101 VERIFY( c.pptr() == a.pptr() );
102 VERIFY( c.epptr() == a.epptr() );
103 VERIFY( c.getloc() == a.getloc() );
104 }
105
106 int main()
107 {
108 std::locale loc(ISO_8859(15,de_DE));
109 streambuf s(loc);
110 s.test_copy();
111 s.test_assign();
112 s.test_swap();
113 }