diff options
author | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
---|---|---|
committer | upstream source tree <ports@midipix.org> | 2015-03-15 20:14:05 -0400 |
commit | 554fd8c5195424bdbcabf5de30fdc183aba391bd (patch) | |
tree | 976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf | |
download | cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2 cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz |
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig;
imported gcc-4.6.4 source tree from verified upstream tarball.
downloading a git-generated archive based on the 'upstream' tag
should provide you with a source tree that is binary identical
to the one extracted from the above tarball.
if you have obtained the source via the command 'git clone',
however, do note that line-endings of files in your working
directory might differ from line-endings of the respective
files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc | 74 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc | 72 |
2 files changed, 146 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..51f5547b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc @@ -0,0 +1,74 @@ +// 2001-05-23 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::stringbuf sbuf(str01); + std::streambuf* pbasebuf0 = &sbuf; + + std::ostringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::stringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::stringbuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc new file mode 100644 index 000000000..b89464043 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::wios& stream, std::wstreambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::wstreambuf* +active_buffer(std::wios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const wchar_t* strlit01 = L"fuck war"; + const std::wstring str00; + const std::wstring str01(strlit01); + std::wstring str02; + std::wstringbuf sbuf(str01); + std::wstreambuf* pbasebuf0 = &sbuf; + + std::wostringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::wstringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::wstreambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::wstringbuf* const buf2 = sstrm1.rdbuf(); + std::wstreambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::wstringbuf* psbuf = dynamic_cast<std::wstringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} |