summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc84
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc69
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc47
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc152
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc98
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc65
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc105
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc59
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc74
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc58
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc70
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc80
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc78
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc65
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc44
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc184
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc96
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc63
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc105
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc59
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc75
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc58
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc70
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc80
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc61
26 files changed, 2060 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc
new file mode 100644
index 000000000..0c94c6815
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc
@@ -0,0 +1,84 @@
+// 1999-08-16 bkoz
+// 1999-11-01 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010
+// Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+
+#include <ostream>
+#include <sstream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const int size = 1000;
+const char name_01[] = "ostream_inserter_other-1.tst";
+const char name_02[] = "ostream_inserter_other-1.txt";
+const char name_03[] = "ostream_inserter_other-2.tst";
+const char name_04[] = "ostream_inserter_other-2.txt";
+
+// fstream
+void
+test02()
+{
+ typedef std::ios_base::iostate iostate;
+ bool test __attribute__((unused)) = true;
+
+ // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb)
+ // filebuf-> NULL
+ std::ifstream f_in1(name_01);
+ std::ofstream f_out1(name_02);
+ std::stringbuf* strbuf01 = 0;
+ iostate state01 = f_in1.rdstate();
+ f_in1 >> strbuf01;
+ iostate state02 = f_in1.rdstate();
+ VERIFY( state01 != state02 );
+ VERIFY( (state02 & std::ios_base::failbit) != 0 );
+ state01 = f_out1.rdstate();
+ f_out1 << strbuf01;
+ state02 = f_out1.rdstate();
+ VERIFY( state01 != state02 );
+ VERIFY( (state02 & std::ios_base::badbit) != 0 );
+
+ // filebuf->filebuf
+ std::ifstream f_in(name_01);
+ std::ofstream f_out(name_02);
+ f_out << f_in.rdbuf();
+ f_in.close();
+ f_out.close();
+
+ // filebuf->stringbuf->filebuf
+ std::ifstream f_in2(name_03);
+ std::ofstream f_out2(name_04); // should be different name
+ std::stringbuf strbuf02;
+ f_in2 >> &strbuf02;
+ f_out2 << &strbuf02;
+ f_in2.close();
+ f_out2.close();
+}
+
+int
+main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc
new file mode 100644
index 000000000..d49251b2c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc
@@ -0,0 +1,69 @@
+// 1999-08-16 bkoz
+// 1999-11-01 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2009
+// Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+#include <ostream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// via Brent Verner <brent@rcfile.org>
+// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html
+void
+test03(void)
+{
+ using namespace std;
+
+ typedef ios::pos_type pos_type;
+
+ const char* TEST_IN = "ostream_inserter_other_in";
+ const char* TEST_OUT = "ostream_inserter_other_out";
+ pos_type i_read, i_wrote, rs, ws;
+ double tf_size = BUFSIZ * 2.5;
+ ofstream testfile(TEST_IN);
+
+ for (int i = 0; i < tf_size; ++i)
+ testfile.put('.');
+ testfile.close();
+
+ ifstream in(TEST_IN);
+ ofstream out(TEST_OUT);
+ out << in.rdbuf();
+ in.seekg(0, ios_base::beg);
+ out.seekp(0, ios_base::beg);
+ rs = in.tellg();
+ ws = out.tellp();
+ in.seekg(0, ios_base::end);
+ out.seekp(0, ios_base::end);
+ i_read = in.tellg() - rs;
+ i_wrote = out.tellp() - ws;
+ in.close();
+ out.close();
+}
+
+int
+main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc
new file mode 100644
index 000000000..ba84d7b61
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc
@@ -0,0 +1,47 @@
+// 1999-08-16 bkoz
+// 1999-11-01 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/3272
+void test04()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ istringstream istr("inside betty carter");
+ ostringstream ostr;
+ ostr << istr.rdbuf() << endl;
+
+ if (ostr.rdstate() & ios_base::eofbit)
+ test = false;
+
+ VERIFY( test );
+}
+
+int
+main()
+{
+ test04();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc
new file mode 100644
index 000000000..dcbd629e5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc
@@ -0,0 +1,152 @@
+// 1999-08-16 bkoz
+// 1999-11-01 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+// 2008, 2009 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+class test_buffer_1 : public std::streambuf
+{
+public:
+ test_buffer_1(const std::string& s) : str(s), it(str.begin()) { }
+
+protected:
+ virtual int underflow() { return (it != str.end() ? *it : EOF); }
+ virtual int uflow() { return (it != str.end() ? *it++ : EOF); }
+
+private:
+ const std::string str;
+ std::string::const_iterator it;
+};
+
+
+class test_buffer_2 : public std::streambuf
+{
+public:
+ test_buffer_2(const std::string& s) : str(s), it(str.begin()) { }
+
+protected:
+ virtual int underflow() { return (it != str.end() ? *it : EOF); }
+ virtual int uflow() { return (it != str.end() ? *it++ : EOF); }
+ virtual std::streamsize showmanyc() { return std::distance(it, str.end()); }
+private:
+ const std::string str;
+ std::string::const_iterator it;
+};
+
+
+class test_buffer_3 : public std::streambuf
+{
+public:
+ test_buffer_3(const std::string& s) : str(s), it(str.begin()) { }
+
+protected:
+ virtual int underflow() { return (it != str.end() ? *it : EOF); }
+ virtual int uflow() { return (it != str.end() ? *it++ : EOF); }
+ virtual std::streamsize showmanyc()
+ {
+ std::streamsize ret = std::distance(it, str.end());
+ return ret > 0 ? ret : -1;
+ }
+private:
+ const std::string str;
+ std::string::const_iterator it;
+};
+
+class test_buffer_4 : public std::streambuf {
+public:
+ test_buffer_4(const std::string& s) : str(s), it(str.begin())
+ {
+ if (it != str.end()) {
+ buf[0] = *it++;
+ setg(buf, buf, buf+1);
+ }
+ }
+
+protected:
+ virtual int underflow() { return (it != str.end() ? *it : EOF); }
+ virtual int uflow() { return (it != str.end() ? *it++ : EOF); }
+ virtual std::streamsize showmanyc() {
+ std::streamsize ret = std::distance(it, str.end());
+ return ret > 0 ? ret : -1;
+ }
+private:
+ const std::string str;
+ std::string::const_iterator it;
+ char buf[1];
+};
+
+void test(const std::string& str, std::streambuf& buf)
+{
+ bool test __attribute__((unused)) = true;
+
+ std::ostringstream out;
+ std::istream in(&buf);
+
+ out << in.rdbuf();
+
+ if (out.str() != str)
+ VERIFY( false );
+}
+
+// libstdc++/6745
+// libstdc++/8071
+// libstdc++/8127
+// Jonathan Lennox <lennox@cs.columbia.edu>
+void test05()
+{
+ std::string string_a("Hello, world!");
+ std::string string_b("");
+
+ test_buffer_1 buf1a(string_a);
+ test_buffer_1 buf1b(string_b);
+
+ test_buffer_2 buf2a(string_a);
+ test_buffer_2 buf2b(string_b);
+
+ test_buffer_3 buf3a(string_a);
+ test_buffer_3 buf3b(string_b);
+
+ test_buffer_4 buf4a(string_a);
+ test_buffer_4 buf4b(string_b);
+
+ test(string_a, buf1a);
+ test(string_b, buf1b);
+
+ test(string_a, buf2a);
+ test(string_b, buf2b);
+
+ test(string_a, buf3a);
+ test(string_b, buf3b);
+
+ test(string_a, buf4a);
+ test(string_b, buf4b);
+}
+
+int
+main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc
new file mode 100644
index 000000000..1c93f0982
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc
@@ -0,0 +1,98 @@
+// 2003-09-22 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2003, 2009 Free Software Foundation
+//
+// 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.6.2.5.3 basic_ostream manipulator inserters
+//
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// DR 60. What is a formatted input function?
+// Inserters for manipulators do not behave as formatted output functions.
+
+#include <ostream>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+std::ostream& func1(std::ostream&)
+{ throw std::runtime_error(""); }
+
+std::ios& func2(std::ios&)
+{ throw std::runtime_error(""); }
+
+std::ios_base& func3(std::ios_base&)
+{ throw std::runtime_error(""); }
+
+template<typename T>
+void test(T& (*f)(T&))
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_test::sync_streambuf buf;
+ std::ostream os(&buf);
+
+ __gnu_test::sync_streambuf buf_tie;
+ std::ostream os_tie(&buf_tie);
+
+ // No sentry should be constructed so os.tie()->flush() should not be
+ // called.
+ os.tie(&os_tie);
+
+ try
+ {
+ os << f;
+ // Exceptions thrown by f should not be caught
+ VERIFY( false );
+ }
+ catch (std::runtime_error&)
+ {
+ }
+
+ // Exceptions thrown by f should not cause badbit to be set
+ VERIFY( os.good() );
+ VERIFY( !buf_tie.sync_called() );
+
+ // The manipulator should be called even if !os.good().
+ os.setstate(std::ios_base::eofbit);
+
+ try
+ {
+ os << f;
+ // Exceptions thrown by f should not be caught
+ VERIFY( false );
+ }
+ catch (std::runtime_error&)
+ {
+ }
+
+ // Exceptions thrown by f should not cause badbit to be set
+ VERIFY( os.rdstate() == std::ios_base::eofbit );
+ VERIFY( !buf_tie.sync_called() );
+}
+
+void test05()
+{
+ test(&func1);
+ test(&func2);
+ test(&func3);
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc
new file mode 100644
index 000000000..8ba8a9b64
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc
@@ -0,0 +1,65 @@
+// 1999-10-11 bkoz
+
+// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf
+
+#include <streambuf>
+#include <sstream>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/9318
+class Outbuf : public std::streambuf
+{
+public:
+ typedef std::streambuf::traits_type traits_type;
+
+ std::string result() const { return str; }
+
+protected:
+ virtual int_type overflow(int_type c = traits_type::eof())
+ {
+ if (!traits_type::eq_int_type(c, traits_type::eof()))
+ str.push_back(traits_type::to_char_type(c));
+ return traits_type::not_eof(c);
+ }
+
+private:
+ std::string str;
+};
+
+void test10()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::stringbuf sbuf("Bad Moon Rising", std::ios::in);
+ Outbuf buf;
+ std::ostream stream(&buf);
+ stream << &sbuf;
+
+ VERIFY( buf.result() == "Bad Moon Rising" );
+}
+
+int main()
+{
+ test10();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc
new file mode 100644
index 000000000..753c95a72
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc
@@ -0,0 +1,105 @@
+// 1999-10-11 bkoz
+
+// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf
+
+#include <cstring> // for memset, memcmp
+#include <streambuf>
+#include <sstream>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/9424
+class Outbuf_2 : public std::streambuf
+{
+ char buf[1];
+
+public:
+ Outbuf_2()
+ {
+ setp(buf, buf + 1);
+ }
+
+ int_type overflow(int_type c)
+ {
+ int_type eof = traits_type::eof();
+
+ if (pptr() < epptr())
+ {
+ if (traits_type::eq_int_type(c, eof))
+ return traits_type::not_eof(c);
+
+ *pptr() = traits_type::to_char_type(c);
+ pbump(1);
+ return c;
+ }
+
+ return eof;
+ }
+};
+
+class Inbuf_2 : public std::streambuf
+{
+ static const char buf[];
+ const char* current;
+ int size;
+
+public:
+ Inbuf_2()
+ {
+ current = buf;
+ size = std::strlen(buf);
+ }
+
+ int_type underflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current);
+ return traits_type::eof();
+ }
+
+ int_type uflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current++);
+ return traits_type::eof();
+ }
+};
+
+const char Inbuf_2::buf[] = "Atteivlis";
+
+void test12()
+{
+ bool test __attribute__((unused)) = true;
+
+ Outbuf_2 outbuf2;
+ std::ostream os (&outbuf2);
+ Inbuf_2 inbuf2;
+ os << &inbuf2;
+ VERIFY( inbuf2.sgetc() == 't' );
+ VERIFY( os.good() );
+}
+
+int main()
+{
+ test12();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc
new file mode 100644
index 000000000..80e9dc060
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc
@@ -0,0 +1,59 @@
+// Copyright (C) 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <testsuite_hooks.h>
+
+struct buf: std::streambuf
+{
+ virtual int_type overflow(int_type)
+ { throw 0; }
+};
+
+template<typename T>
+void testthrow(T arg)
+{
+ bool test __attribute__((unused)) = true;
+ buf b;
+ std::ostream os(&b);
+ os.exceptions(std::ios::badbit);
+
+ try
+ {
+ os << arg;
+ }
+ catch(int)
+ {
+ // Expected return is zero.
+ VERIFY( os.bad() );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ buf b;
+
+ testthrow(&b);
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc
new file mode 100644
index 000000000..d25337453
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc
@@ -0,0 +1,74 @@
+// { dg-options "-std=gnu++0x" }
+
+// Copyright (C) 2007, 2008, 2009 Free Software Foundation
+//
+// 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/>.
+
+#include <ostream>
+#include <sstream>
+#include <system_error>
+#include <algorithm>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Effects: os << ec.category().name() << ':' << ec.value();
+void test()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ char buf[64];
+ error_code e1;
+ error_code e2(make_error_code(errc::bad_address));
+ string s, s1, s2;
+
+ {
+ ostringstream ostr;
+ ostr << e1 << endl;
+ s1 = ostr.str();
+
+ if (ostr.rdstate() & ios_base::eofbit)
+ test = false;
+ }
+ VERIFY( test );
+ VERIFY( find(s1.begin(), s1.end(), ':') != s1.end() );
+
+ sprintf(buf, "%i", e1.value());
+ s = buf;
+ VERIFY( s1.find(s) != string::npos);
+
+ {
+ ostringstream ostr;
+ ostr << e2 << endl;
+ s2 = ostr.str();
+
+ if (ostr.rdstate() & ios_base::eofbit)
+ test = false;
+ }
+ VERIFY( test );
+ VERIFY( find(s2.begin(), s2.end(), ':') != s2.end() );
+
+ sprintf(buf, "%i", e2.value());
+ s = buf;
+ VERIFY( s2.find(s) != string::npos);
+}
+
+int
+main()
+{
+ test();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc
new file mode 100644
index 000000000..5f2373fc5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc
@@ -0,0 +1,58 @@
+// Copyright (C) 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test5()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bob;
+ ostream stream(&bob);
+ stringbuf sbuf("Foo, bar, qux", ios_base::in);
+
+ stream << &sbuf;
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+void test7()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ __gnu_test::fail_streambuf bib;
+
+ stream << &bib;
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+// libstdc++/9371
+int main()
+{
+ test5();
+ test7();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc
new file mode 100644
index 000000000..822763b33
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc
@@ -0,0 +1,70 @@
+// Copyright (C) 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test13()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bob;
+ ostream stream(&bob);
+ stream.exceptions(ios_base::badbit);
+ stringbuf sbuf("Foo, bar, qux", ios_base::in);
+
+ try
+ {
+ stream << &sbuf;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+void test15()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ stream.exceptions(ios_base::badbit);
+ __gnu_test::fail_streambuf bib;
+
+ try
+ {
+ stream << &bib;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+// libstdc++/9371
+int main()
+{
+ test13();
+ test15();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc
new file mode 100644
index 000000000..55d5c47c7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 2003, 2005, 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test9()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_streambuf bob;
+ ostream stream(&bob);
+ stream.exceptions(ios_base::failbit);
+ stringbuf sbuf("Foo, bar, qux", ios_base::in);
+
+ try
+ {
+ stream << &sbuf;
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ { VERIFY( false ); }
+ catch (__gnu_test::overflow_error&)
+ { }
+ catch (...)
+ { VERIFY( false ); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+void test11()
+{
+ bool test __attribute__((unused)) = true;
+ ostringstream stream;
+ stream.exceptions(ios_base::failbit);
+ __gnu_test::fail_streambuf bib;
+
+ try
+ {
+ stream << &bib;
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ { VERIFY( false ); }
+ catch (__gnu_test::underflow_error&)
+ { }
+ catch (...)
+ { VERIFY( false ); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+// libstdc++/9371
+int main()
+{
+ test9();
+ test11();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc
new file mode 100644
index 000000000..6d28c5f04
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc
@@ -0,0 +1,61 @@
+// Copyright (C) 2003, 2005, 2009, 2010 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/>.
+
+
+#include <istream>
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test1()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ ostringstream stream;
+ stream << static_cast<streambuf*>(0);
+ VERIFY( stream.rdstate() & ios_base::badbit );
+}
+
+void test3()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ ostringstream stream;
+ stream.exceptions(ios_base::badbit);
+
+ try
+ {
+ stream << static_cast<streambuf*>(0);
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ {
+ }
+
+ VERIFY( stream.rdstate() & ios_base::badbit );
+}
+
+// libstdc++/9371
+int main()
+{
+ test1();
+ test3();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc
new file mode 100644
index 000000000..6e12a65bf
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc
@@ -0,0 +1,78 @@
+// Copyright (C) 2005, 2009, 2010 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+#include <ostream>
+#include <sstream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const int size = 1000;
+const char name_01[] = "wostream_inserter_other-1.tst";
+const char name_02[] = "wostream_inserter_other-1.txt";
+const char name_03[] = "wostream_inserter_other-2.tst";
+const char name_04[] = "wostream_inserter_other-2.txt";
+
+// fstream
+void
+test02()
+{
+ typedef std::ios_base::iostate iostate;
+ bool test __attribute__((unused)) = true;
+
+ // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb)
+ // filebuf-> NULL
+ std::wifstream f_in1(name_01);
+ std::wofstream f_out1(name_02);
+ std::wstringbuf* strbuf01 = 0;
+ iostate state01 = f_in1.rdstate();
+ f_in1 >> strbuf01;
+ iostate state02 = f_in1.rdstate();
+ VERIFY( state01 != state02 );
+ VERIFY( (state02 & std::ios_base::failbit) != 0 );
+ state01 = f_out1.rdstate();
+ f_out1 << strbuf01;
+ state02 = f_out1.rdstate();
+ VERIFY( state01 != state02 );
+ VERIFY( (state02 & std::ios_base::badbit) != 0 );
+
+ // filebuf->filebuf
+ std::wifstream f_in(name_01);
+ std::wofstream f_out(name_02);
+ f_out << f_in.rdbuf();
+ f_in.close();
+ f_out.close();
+
+ // filebuf->stringbuf->filebuf
+ std::wifstream f_in2(name_03);
+ std::wofstream f_out2(name_04); // should be different name
+ std::wstringbuf strbuf02;
+ f_in2 >> &strbuf02;
+ f_out2 << &strbuf02;
+ f_in2.close();
+ f_out2.close();
+}
+
+int
+main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc
new file mode 100644
index 000000000..bb12a7cc4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc
@@ -0,0 +1,65 @@
+// Copyright (C) 2005, 2009 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+#include <ostream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// via Brent Verner <brent@rcfile.org>
+// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html
+void
+test03(void)
+{
+ using namespace std;
+
+ typedef wios::pos_type pos_type;
+
+ const char* TEST_IN = "wostream_inserter_other_in.txt";
+ const char* TEST_OUT = "wostream_inserter_other_out.txt";
+ pos_type i_read, i_wrote, rs, ws;
+ double tf_size = BUFSIZ * 2.5;
+ ofstream testfile(TEST_IN);
+
+ for (int i = 0; i < tf_size; ++i)
+ testfile.put(L'.');
+ testfile.close();
+
+ wifstream in(TEST_IN);
+ wofstream out(TEST_OUT);
+ out << in.rdbuf();
+ in.seekg(0, ios_base::beg);
+ out.seekp(0, ios_base::beg);
+ rs = in.tellg();
+ ws = out.tellp();
+ in.seekg(0, ios_base::end);
+ out.seekp(0, ios_base::end);
+ i_read = in.tellg() - rs;
+ i_wrote = out.tellp() - ws;
+ in.close();
+ out.close();
+}
+
+int
+main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc
new file mode 100644
index 000000000..51e329b5d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc
@@ -0,0 +1,44 @@
+// Copyright (C) 2005, 2009 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/3272
+void test04()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ wistringstream istr(L"inside betty carter");
+ wostringstream ostr;
+ ostr << istr.rdbuf() << endl;
+
+ if (ostr.rdstate() & ios_base::eofbit)
+ test = false;
+
+ VERIFY( test );
+}
+
+int
+main()
+{
+ test04();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc
new file mode 100644
index 000000000..3cd771c7f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc
@@ -0,0 +1,184 @@
+// Copyright (C) 2005, 2009 Free Software Foundation
+//
+// 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.6.2.5.4 basic_ostream character inserters
+
+#include <ostream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+class test_buffer_1 : public std::wstreambuf
+{
+public:
+ test_buffer_1(const std::wstring& s)
+ : str(s), it(str.begin()) { }
+
+protected:
+ virtual int_type
+ underflow()
+ { return (it != str.end() ? *it : WEOF); }
+
+ virtual int_type
+ uflow()
+ { return (it != str.end() ? *it++ : WEOF); }
+
+private:
+ const std::wstring str;
+ std::wstring::const_iterator it;
+};
+
+
+class test_buffer_2 : public std::wstreambuf
+{
+public:
+ test_buffer_2(const std::wstring& s)
+ : str(s), it(str.begin()) { }
+
+protected:
+ virtual int_type
+ underflow()
+ { return (it != str.end() ? *it : WEOF); }
+
+ virtual int_type
+ uflow()
+ { return (it != str.end() ? *it++ : WEOF); }
+
+ virtual std::streamsize
+ showmanyc()
+ { return std::distance(it, str.end()); }
+
+private:
+ const std::wstring str;
+ std::wstring::const_iterator it;
+};
+
+
+class test_buffer_3 : public std::wstreambuf
+{
+public:
+ test_buffer_3(const std::wstring& s)
+ : str(s), it(str.begin()) { }
+
+protected:
+ virtual int_type
+ underflow()
+ { return (it != str.end() ? *it : WEOF); }
+
+ virtual int_type
+ uflow()
+ { return (it != str.end() ? *it++ : WEOF); }
+
+ virtual std::streamsize
+ showmanyc()
+ {
+ std::streamsize ret = std::distance(it, str.end());
+ return ret > 0 ? ret : -1;
+ }
+
+private:
+ const std::wstring str;
+ std::wstring::const_iterator it;
+};
+
+class test_buffer_4 : public std::wstreambuf
+{
+public:
+ test_buffer_4(const std::wstring& s)
+ : str(s), it(str.begin())
+ {
+ if (it != str.end())
+ {
+ buf[0] = *it++;
+ setg(buf, buf, buf+1);
+ }
+ }
+
+protected:
+ virtual int_type
+ underflow()
+ { return (it != str.end() ? *it : WEOF); }
+
+ virtual int_type
+ uflow()
+ { return (it != str.end() ? *it++ : WEOF); }
+
+ virtual std::streamsize
+ showmanyc()
+ {
+ std::streamsize ret = std::distance(it, str.end());
+ return ret > 0 ? ret : -1;
+ }
+
+private:
+ const std::wstring str;
+ std::wstring::const_iterator it;
+ wchar_t buf[1];
+};
+
+void test(const std::wstring& str, std::wstreambuf& buf)
+{
+ bool test __attribute__((unused)) = true;
+
+ std::wostringstream out;
+ std::wistream in(&buf);
+
+ out << in.rdbuf();
+
+ if (out.str() != str)
+ VERIFY( false );
+}
+
+// libstdc++/6745
+// libstdc++/8071
+// libstdc++/8127
+// Jonathan Lennox <lennox@cs.columbia.edu>
+void test05()
+{
+ std::wstring string_a(L"Hello, world!");
+ std::wstring string_b(L"");
+
+ test_buffer_1 buf1a(string_a);
+ test_buffer_1 buf1b(string_b);
+
+ test_buffer_2 buf2a(string_a);
+ test_buffer_2 buf2b(string_b);
+
+ test_buffer_3 buf3a(string_a);
+ test_buffer_3 buf3b(string_b);
+
+ test_buffer_4 buf4a(string_a);
+ test_buffer_4 buf4b(string_b);
+
+ test(string_a, buf1a);
+ test(string_b, buf1b);
+
+ test(string_a, buf2a);
+ test(string_b, buf2b);
+
+ test(string_a, buf3a);
+ test(string_b, buf3b);
+
+ test(string_a, buf4a);
+ test(string_b, buf4b);
+}
+
+int
+main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc
new file mode 100644
index 000000000..e8818f542
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc
@@ -0,0 +1,96 @@
+// Copyright (C) 2005, 2009 Free Software Foundation
+//
+// 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.6.2.5.3 basic_ostream manipulator inserters
+//
+// _GLIBCXX_RESOLVE_LIB_DEFECTS
+// DR 60. What is a formatted input function?
+// Inserters for manipulators do not behave as formatted output functions.
+
+#include <ostream>
+#include <stdexcept>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+std::wostream& func1(std::wostream&)
+{ throw std::runtime_error(""); }
+
+std::wios& func2(std::wios&)
+{ throw std::runtime_error(""); }
+
+std::ios_base& func3(std::ios_base&)
+{ throw std::runtime_error(""); }
+
+template<typename T>
+void test(T& (*f)(T&))
+{
+ bool test __attribute__((unused)) = true;
+
+ __gnu_test::sync_wstreambuf buf;
+ std::wostream os(&buf);
+
+ __gnu_test::sync_wstreambuf buf_tie;
+ std::wostream os_tie(&buf_tie);
+
+ // No sentry should be constructed so os.tie()->flush() should not be
+ // called.
+ os.tie(&os_tie);
+
+ try
+ {
+ os << f;
+ // Exceptions thrown by f should not be caught
+ VERIFY( false );
+ }
+ catch (std::runtime_error&)
+ {
+ }
+
+ // Exceptions thrown by f should not cause badbit to be set
+ VERIFY( os.good() );
+ VERIFY( !buf_tie.sync_called() );
+
+ // The manipulator should be called even if !os.good().
+ os.setstate(std::ios_base::eofbit);
+
+ try
+ {
+ os << f;
+ // Exceptions thrown by f should not be caught
+ VERIFY( false );
+ }
+ catch (std::runtime_error&)
+ {
+ }
+
+ // Exceptions thrown by f should not cause badbit to be set
+ VERIFY( os.rdstate() == std::ios_base::eofbit );
+ VERIFY( !buf_tie.sync_called() );
+}
+
+void test05()
+{
+ test(&func1);
+ test(&func2);
+ test(&func3);
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc
new file mode 100644
index 000000000..a02ed488b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc
@@ -0,0 +1,63 @@
+// Copyright (C) 2005, 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.5.2 template class basic_streambuf
+
+#include <streambuf>
+#include <sstream>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/9318
+class Outbuf : public std::wstreambuf
+{
+public:
+ typedef std::wstreambuf::traits_type traits_type;
+
+ std::wstring result() const { return str; }
+
+protected:
+ virtual int_type
+ overflow(int_type c = traits_type::eof())
+ {
+ if (!traits_type::eq_int_type(c, traits_type::eof()))
+ str.push_back(traits_type::to_char_type(c));
+ return traits_type::not_eof(c);
+ }
+
+private:
+ std::wstring str;
+};
+
+void test10()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::wstringbuf sbuf(L"Bad Moon Rising", std::wios::in);
+ Outbuf buf;
+ std::wostream stream(&buf);
+ stream << &sbuf;
+
+ VERIFY( buf.result() == L"Bad Moon Rising" );
+}
+
+int main()
+{
+ test10();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc
new file mode 100644
index 000000000..7b89d26df
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc
@@ -0,0 +1,105 @@
+// 1999-10-11 bkoz
+
+// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf
+
+#include <cwchar>
+#include <streambuf>
+#include <sstream>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/9424
+class Outbuf_2 : public std::wstreambuf
+{
+ wchar_t buf[1];
+
+public:
+ Outbuf_2()
+ {
+ setp(buf, buf + 1);
+ }
+
+ int_type overflow(int_type c)
+ {
+ int_type eof = traits_type::eof();
+
+ if (pptr() < epptr())
+ {
+ if (traits_type::eq_int_type(c, eof))
+ return traits_type::not_eof(c);
+
+ *pptr() = traits_type::to_char_type(c);
+ pbump(1);
+ return c;
+ }
+
+ return eof;
+ }
+};
+
+class Inbuf_2 : public std::wstreambuf
+{
+ static const wchar_t buf[];
+ const wchar_t* current;
+ int size;
+
+public:
+ Inbuf_2()
+ {
+ current = buf;
+ size = std::wcslen(buf);
+ }
+
+ int_type underflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current);
+ return traits_type::eof();
+ }
+
+ int_type uflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current++);
+ return traits_type::eof();
+ }
+};
+
+const wchar_t Inbuf_2::buf[] = L"Atteivlis";
+
+void test12()
+{
+ bool test __attribute__((unused)) = true;
+
+ Outbuf_2 outbuf2;
+ std::wostream os (&outbuf2);
+ Inbuf_2 inbuf2;
+ os << &inbuf2;
+ VERIFY( inbuf2.sgetc() == L't' );
+ VERIFY( os.good() );
+}
+
+int main()
+{
+ test12();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc
new file mode 100644
index 000000000..89a5d361e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc
@@ -0,0 +1,59 @@
+// Copyright (C) 2005, 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <testsuite_hooks.h>
+
+struct buf: std::wstreambuf
+{
+ virtual int_type overflow(int_type)
+ { throw 0; }
+};
+
+template<typename T>
+void testthrow(T arg)
+{
+ bool test __attribute__((unused)) = true;
+ buf b;
+ std::wostream os(&b);
+ os.exceptions(std::wios::badbit);
+
+ try
+ {
+ os << arg;
+ }
+ catch(int)
+ {
+ // Expected return is zero.
+ VERIFY( os.bad() );
+ }
+ catch(...)
+ {
+ VERIFY( false );
+ }
+}
+
+int main()
+{
+ buf b;
+
+ testthrow(&b);
+
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc
new file mode 100644
index 000000000..16f9108a3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc
@@ -0,0 +1,75 @@
+// { dg-options "-std=gnu++0x" }
+// { dg-require-swprintf "" }
+
+// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation
+//
+// 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/>.
+
+#include <ostream>
+#include <sstream>
+#include <system_error>
+#include <algorithm>
+#include <cwchar>
+#include <testsuite_hooks.h>
+
+// Effects: os << ec.category().name() << ':' << ec.value();
+void test()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wchar_t buf[64];
+ error_code e1;
+ error_code e2(make_error_code(errc::bad_address));
+ wstring s, s1, s2;
+
+ {
+ wostringstream ostr;
+ ostr << e1 << endl;
+ s1 = ostr.str();
+
+ if (ostr.rdstate() & ios_base::eofbit)
+ test = false;
+ }
+ VERIFY( test );
+ VERIFY( find(s1.begin(), s1.end(), L':') != s1.end() );
+
+ swprintf(buf, 64, L"%i", e1.value());
+ s = buf;
+ VERIFY( s1.find(s) != string::npos);
+
+ {
+ wostringstream ostr;
+ ostr << e2 << endl;
+ s2 = ostr.str();
+
+ if (ostr.rdstate() & ios_base::eofbit)
+ test = false;
+ }
+ VERIFY( test );
+ VERIFY( find(s2.begin(), s2.end(), L':') != s2.end() );
+
+ swprintf(buf, 64, L"%i", e2.value());
+ s = buf;
+ VERIFY( s2.find(s) != string::npos);
+}
+
+int
+main()
+{
+ test();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc
new file mode 100644
index 000000000..3df90b873
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc
@@ -0,0 +1,58 @@
+// Copyright (C) 2005, 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test5()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_wstreambuf bob;
+ wostream stream(&bob);
+ wstringbuf sbuf(L"Foo, bar, qux", ios_base::in);
+
+ stream << &sbuf;
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+void test7()
+{
+ bool test __attribute__((unused)) = true;
+ wostringstream stream;
+ __gnu_test::fail_wstreambuf bib;
+
+ stream << &bib;
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+// libstdc++/9371
+int main()
+{
+ test5();
+ test7();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc
new file mode 100644
index 000000000..954d56790
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc
@@ -0,0 +1,70 @@
+// Copyright (C) 2005, 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test13()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_wstreambuf bob;
+ wostream stream(&bob);
+ stream.exceptions(ios_base::badbit);
+ wstringbuf sbuf(L"Foo, bar, qux", ios_base::in);
+
+ try
+ {
+ stream << &sbuf;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+void test15()
+{
+ bool test __attribute__((unused)) = true;
+ wostringstream stream;
+ stream.exceptions(ios_base::badbit);
+ __gnu_test::fail_wstreambuf bib;
+
+ try
+ {
+ stream << &bib;
+ }
+ catch (...)
+ { VERIFY(false); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+// libstdc++/9371
+int main()
+{
+ test13();
+ test15();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc
new file mode 100644
index 000000000..789d3cc3c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 2005, 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/>.
+
+
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+using namespace std;
+
+void test9()
+{
+ bool test __attribute__((unused)) = true;
+ __gnu_test::fail_wstreambuf bob;
+ wostream stream(&bob);
+ stream.exceptions(ios_base::failbit);
+ wstringbuf sbuf(L"Foo, bar, qux", ios_base::in);
+
+ try
+ {
+ stream << &sbuf;
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ { VERIFY( false ); }
+ catch (__gnu_test::overflow_error&)
+ { }
+ catch (...)
+ { VERIFY( false ); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+void test11()
+{
+ bool test __attribute__((unused)) = true;
+ wostringstream stream;
+ stream.exceptions(ios_base::failbit);
+ __gnu_test::fail_wstreambuf bib;
+
+ try
+ {
+ stream << &bib;
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ { VERIFY( false ); }
+ catch (__gnu_test::underflow_error&)
+ { }
+ catch (...)
+ { VERIFY( false ); }
+
+ VERIFY( stream.rdstate() & ios_base::failbit );
+ VERIFY( (stream.rdstate() & ios_base::badbit) == 0 );
+}
+
+// libstdc++/9371
+int main()
+{
+ test9();
+ test11();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc
new file mode 100644
index 000000000..076aece64
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc
@@ -0,0 +1,61 @@
+// Copyright (C) 2005, 2009, 2010 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/>.
+
+
+#include <istream>
+#include <ostream>
+#include <streambuf>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void test1()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wostringstream stream;
+ stream << static_cast<wstreambuf*>(0);
+ VERIFY( stream.rdstate() & ios_base::badbit );
+}
+
+void test3()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wostringstream stream;
+ stream.exceptions(ios_base::badbit);
+
+ try
+ {
+ stream << static_cast<wstreambuf*>(0);
+ VERIFY( false );
+ }
+ catch (ios_base::failure&)
+ {
+ }
+
+ VERIFY( stream.rdstate() & ios_base::badbit );
+}
+
+// libstdc++/9371
+int main()
+{
+ test1();
+ test3();
+ return 0;
+}