]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/2.cc
Reshuffle 27_io testsuite.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_stringstream / str / char / 2.cc
CommitLineData
d422980b
BK
1// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com>
2
23cac885 3// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
d422980b
BK
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 2, 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 COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
23cac885 21// 27.7.6 member functions (stringstream_members)
d422980b 22
23cac885 23#include <sstream>
fe413112 24#include <testsuite_hooks.h>
d422980b
BK
25
26void
27redirect_buffer(std::ios& stream, std::streambuf* new_buf)
28{ stream.rdbuf(new_buf); }
29
30std::streambuf*
31active_buffer(std::ios& stream)
32{ return stream.rdbuf(); }
33
34// libstdc++/2832
35void test02()
36{
37 bool test = true;
38 const char* strlit01 = "fuck war";
39 const char* strlit02 = "two less cars abstract riot crew, critical mass/SF";
40 const std::string str00;
41 const std::string str01(strlit01);
42 std::string str02;
23cac885
BK
43 std::stringbuf sbuf(str01);
44 std::streambuf* pbasebuf0 = &sbuf;
d422980b 45
23cac885
BK
46 std::stringstream sstrm1;
47 VERIFY( sstrm1.str() == str00 );
d422980b
BK
48 // derived rdbuf() always returns original streambuf, even though
49 // it's no longer associated with the stream.
23cac885 50 std::stringbuf* const buf1 = sstrm1.rdbuf();
d422980b
BK
51 // base rdbuf() returns the currently associated streambuf
52 std::streambuf* pbasebuf1 = active_buffer(sstrm1);
23cac885
BK
53 redirect_buffer(sstrm1, &sbuf);
54 std::stringbuf* const buf2 = sstrm1.rdbuf();
d422980b
BK
55 std::streambuf* pbasebuf2 = active_buffer(sstrm1);
56 VERIFY( buf1 == buf2 );
57 VERIFY( pbasebuf1 != pbasebuf2 );
58 VERIFY( pbasebuf2 == pbasebuf0 );
59
23cac885
BK
60 // derived rdbuf() returns the original buf, so str() doesn't change.
61 VERIFY( sstrm1.str() != str01 );
62 VERIFY( sstrm1.str() == str00 );
63 // however, casting the active streambuf to a stringbuf shows what's up:
64 std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2);
65 str02 = psbuf->str();
66 VERIFY( str02 == str01 );
67
d422980b
BK
68 // How confusing and non-intuitive is this?
69 // These semantics are a joke, a serious defect, and incredibly lame.
70}
71
72int main()
73{
74 test02();
75 return 0;
76}