summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/27_io/basic_filebuf/imbue
downloadcbb-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_filebuf/imbue')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc125
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc44
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc62
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc46
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc83
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc56
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc84
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc68
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc44
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc62
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc59
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc86
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc74
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc95
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc55
21 files changed, 1379 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc
new file mode 100644
index 000000000..4c6bebf1f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc
@@ -0,0 +1,125 @@
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+
+typedef unsigned char Char;
+
+namespace std
+{
+ template <>
+ class codecvt<Char, char, mbstate_t> :
+ public locale::facet, public codecvt_base
+ {
+ public:
+ typedef Char intern_type;
+ typedef char extern_type;
+ typedef mbstate_t state_type;
+
+ explicit codecvt(size_t refs = 0)
+ : locale::facet(refs) { }
+ result out(mbstate_t& state, const Char* from,
+ const Char* from_end, const Char*& from_next,
+ char* to, char* to_limit, char*& to_next) const
+ {
+ return do_out(state, from, from_end, from_next,
+ to, to_limit, to_next);
+ }
+ result in(mbstate_t& state, const char* from,
+ const char* from_end, const char*& from_next,
+ Char* to, Char* to_limit, Char*& to_next) const
+ {
+ return do_in(state, from, from_end, from_next,
+ to, to_limit, to_next);
+ }
+ result unshift(mbstate_t& state, char* to, char* to_end,
+ char*& to_next) const
+ { return do_unshift(state, to, to_end, to_next); }
+ int length(mbstate_t& state, const char* from,
+ const char* from_end, size_t max) const
+ { return do_length(state, from, from_end, max); }
+ int encoding() const throw()
+ { return do_encoding(); }
+ bool always_noconv() const throw()
+ { return do_always_noconv(); }
+ int max_length() const throw()
+ { return do_max_length(); }
+
+ static locale::id id;
+
+ protected:
+ virtual result do_out(mbstate_t&, const Char*,
+ const Char*,
+ const Char*&, char*,
+ char*, char*&) const
+ { return ok; }
+ virtual result do_in(mbstate_t&, const char*,
+ const char*,
+ const char*&, Char*,
+ Char*, Char*&) const
+ { return ok; }
+ virtual result do_unshift(mbstate_t&, char*, char*,
+ char*&) const
+ { return noconv; }
+ virtual int do_length(mbstate_t&, const char*,
+ const char*, size_t) const
+ { return 1; }
+ virtual int do_encoding() const throw()
+ { return 1; }
+ virtual bool do_always_noconv() const throw()
+ { return false; }
+ virtual int do_max_length() const throw()
+ { return 1; }
+ };
+
+ locale::id codecvt<Char, char, mbstate_t>::id;
+}
+
+// libstdc++/12206
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(),
+ new codecvt<Char, char, std::mbstate_t>);
+ locale::global(loc);
+
+ basic_filebuf<Char, char_traits<Char> > fb;
+
+ loc = locale::classic();
+ locale::global(loc);
+ fb.pubimbue(loc);
+
+ fb.open("tmp_12206", ios_base::out);
+ try
+ {
+ fb.pubseekoff(0, ios_base::cur);
+ }
+ catch (std::exception&)
+ {
+ }
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc
new file mode 100644
index 000000000..37bc1a555
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc
@@ -0,0 +1,44 @@
+// 981208 bkoz test functionality of basic_stringbuf for char_type == char
+
+// Copyright (C) 1997, 1998, 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/>.
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+std::filebuf fbuf;
+
+// test the filebuf locale settings
+void test02()
+{
+ std::locale loc_c = std::locale::classic();
+ loc_c = fbuf.getloc();
+ fbuf.pubimbue(loc_c); //This should initialize _M_init to true
+ std::locale loc_tmp = fbuf.getloc();
+ VERIFY( loc_tmp == loc_c );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
+
+
+
+// more candy!!!
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc
new file mode 100644
index 000000000..326aa1fd8
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc
@@ -0,0 +1,62 @@
+// { dg-require-namedlocale "fr_FR" }
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::filebuf
+{
+public:
+ std::locale before;
+ std::locale after;
+
+protected:
+ void imbue(const std::locale& loc)
+ {
+ before = getloc();
+
+ std::filebuf::imbue(loc);
+
+ after = getloc();
+ }
+};
+
+// libstdc++/13007
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf buf;
+ std::locale loc(std::locale("fr_FR"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+ VERIFY( buf.before == std::locale::classic() );
+ VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc
new file mode 100644
index 000000000..9fbf67aef
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc
@@ -0,0 +1,46 @@
+// { dg-require-namedlocale "en_US" }
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+// libstdc++/13171
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ filebuf fb;
+
+ fb.pubimbue(locale("en_US"));
+ fb.pubimbue(locale("en_US"));
+
+ fb.open("tmp_13171-1", ios_base::out);
+ fb.sputc('F');
+ fb.pubsync();
+ fb.close();
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc
new file mode 100644
index 000000000..fa0bf15c0
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc
@@ -0,0 +1,83 @@
+// { dg-require-namedlocale "fr_FR" }
+// { dg-require-namedlocale "en_US" }
+// { dg-require-fork "" }
+// { dg-require-mkfifo "" }
+
+// Copyright (C) 2003, 2004, 2005, 2006, 2007, 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.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <cstdlib>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// No asserts, avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
+#include <testsuite_hooks.h>
+
+// libstdc++/13171
+bool test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ using namespace __gnu_test;
+
+ locale loc_fr(locale("fr_FR"));
+ locale loc_en(locale("en_US"));
+
+ const char* name = "tmp_fifo_13171-2";
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+ semaphore s1, s2;
+
+ int child = fork();
+ if (child == 0)
+ {
+ filebuf fb;
+ fb.open(name, ios_base::out);
+ fb.sputc('S');
+ fb.pubsync();
+ s1.signal();
+ s2.wait();
+ fb.close();
+ exit(0);
+ }
+
+ filebuf fb;
+ fb.pubimbue(loc_fr);
+ fb.open(name, ios_base::in);
+ s1.wait();
+ VERIFY( fb.is_open() );
+ fb.pubimbue(loc_en);
+ filebuf::int_type c = fb.sgetc();
+ fb.close();
+ VERIFY( c == 'S' );
+ s2.signal();
+
+ return test;
+}
+
+int main()
+{
+ return !test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc
new file mode 100644
index 000000000..1ac9557ce
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc
@@ -0,0 +1,56 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "fr_FR" }
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+protected:
+ int do_encoding() const throw()
+ { return -1; }
+
+ bool do_always_noconv() const throw()
+ { return false; }
+};
+
+// libstdc++/13171
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ filebuf fb;
+ fb.pubimbue(locale(locale("en_US"), new Cvt));
+ fb.open("tmp_13171-4", ios_base::out);
+ fb.pubimbue(locale("fr_FR"));
+ fb.sputc('N');
+ fb.pubsync();
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc
new file mode 100644
index 000000000..fdcc03022
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc
@@ -0,0 +1,84 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "fr_FR" }
+// { dg-require-fork "" }
+// { dg-require-mkfifo "" }
+
+// 2004-01-11 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2004, 2005, 2006, 2007, 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.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <cstdlib>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <testsuite_hooks.h>
+
+// libstdc++/13582
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ using namespace __gnu_test;
+
+ locale loc_en(locale("en_US"));
+ locale loc_fr(locale("fr_FR"));
+
+ const char* name = "tmp_fifo_13582-2";
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+
+ int child = fork();
+ if (child == 0)
+ {
+ filebuf fbout;
+ fbout.open(name, ios_base::out);
+ fbout.sputn("12345", 5);
+ fbout.pubsync();
+ fbout.close();
+ exit(0);
+ }
+
+ filebuf fbin;
+ fbin.open(name, ios_base::in);
+ filebuf::int_type n = fbin.sbumpc();
+ VERIFY( n == '1' );
+ fbin.pubimbue(loc_en);
+ n = fbin.sbumpc();
+ VERIFY( n == '2' );
+ fbin.pubimbue(loc_fr);
+ n = fbin.sbumpc();
+ VERIFY( n == '3' );
+ n = fbin.sbumpc();
+ VERIFY( n == '4' );
+ n = fbin.sbumpc();
+ VERIFY( n == '5' );
+ n = fbin.sbumpc();
+ VERIFY( n == filebuf::traits_type::eof() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc
new file mode 100644
index 000000000..5007b085e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc
@@ -0,0 +1,68 @@
+// { dg-require-namedlocale "en_US" }
+
+// 2004-04-16 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2004, 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.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::filebuf
+{
+protected:
+ virtual int_type
+ overflow(int_type c = traits_type::eof())
+ {
+ return traits_type::eq_int_type(c, traits_type::eof()) ?
+ traits_type::eof() : std::filebuf::overflow(c);
+ }
+};
+
+// libstdc++/14975
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ Buf fb;
+ locale loc_us = locale("en_US");
+ fb.pubimbue(loc_us);
+ fb.open("tmp_14975-1", ios_base::out);
+
+ try
+ {
+ fb.sputc('a');
+ fb.sputc('b');
+ fb.pubimbue(locale::classic());
+ fb.sputc('c');
+ fb.pubsync();
+ fb.close();
+ }
+ catch (std::exception&)
+ {
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc
new file mode 100644
index 000000000..f4d574c21
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc
@@ -0,0 +1,55 @@
+// { dg-require-namedlocale "de_DE" }
+
+// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+void test02()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
+
+ locale loc;
+ filebuf ob;
+ VERIFY( ob.getloc() == loc );
+ ob.open(name_01, ios_base::in);
+ VERIFY( ob.is_open() );
+
+ typedef streambuf::pos_type pos_type;
+ pos_type bad = pos_type(streambuf::off_type(-1));
+ pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
+ VERIFY( p != bad);
+
+ // According to 27.5.2.2.1, loc == getloc() after pubimbue(loc).
+ locale loc_de = locale("de_DE");
+ locale ret = ob.pubimbue(loc_de);
+ VERIFY( ob.getloc() == loc_de );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc
new file mode 100644
index 000000000..055573b96
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc
@@ -0,0 +1,55 @@
+// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class state_codecvt : public std::codecvt<char, char, std::mbstate_t>
+{
+protected:
+ int
+ do_encoding() const throw()
+ { return -1; }
+};
+
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc_s(locale::classic(), new state_codecvt);
+ filebuf ob;
+ ob.pubimbue(loc_s);
+ VERIFY( ob.getloc() == loc_s );
+
+ // 2 "if encoding of current locale is state dependent" and
+ // not at the beginning of the file fails...
+ locale loc_c = locale::classic();
+ locale ret = ob.pubimbue(loc_s);
+ VERIFY( ob.getloc() == loc_s );
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc
new file mode 100644
index 000000000..8a611e0dc
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc
@@ -0,0 +1,55 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "de_DE" }
+
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+// libstdc++/9322
+void test07()
+{
+ using std::locale;
+ bool test __attribute__((unused)) = true;
+
+ locale loc;
+ std::filebuf ob;
+ VERIFY( ob.getloc() == loc );
+
+ locale::global(locale("en_US"));
+ VERIFY( ob.getloc() == loc );
+
+ locale loc_de = locale("de_DE");
+ locale ret = ob.pubimbue(loc_de);
+ VERIFY( ob.getloc() == loc_de );
+ VERIFY( ret == loc );
+
+ locale::global(loc);
+ VERIFY( ob.getloc() == loc_de );
+}
+
+int main()
+{
+ test07();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc
new file mode 100644
index 000000000..f5c6daac3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc
@@ -0,0 +1,44 @@
+// 981208 bkoz test functionality of basic_stringbuf for char_type == char
+
+// Copyright (C) 1997, 1998, 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/>.
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+std::wfilebuf fbuf;
+
+// test the filebuf locale settings
+void test02()
+{
+ std::locale loc_c = std::locale::classic();
+ loc_c = fbuf.getloc();
+ fbuf.pubimbue(loc_c); //This should initialize _M_init to true
+ std::locale loc_tmp = fbuf.getloc();
+ VERIFY( loc_tmp == loc_c );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
+
+
+
+// more candy!!!
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc
new file mode 100644
index 000000000..bc7c3c1bd
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc
@@ -0,0 +1,61 @@
+// { dg-require-namedlocale "is_IS.UTF-8" }
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <ostream>
+#include <fstream>
+#include <locale>
+#include <string>
+#include <testsuite_hooks.h>
+
+// libstdc++/12868
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc_is(locale("is_IS.UTF-8"));
+
+ {
+ wofstream out("tmp_12868");
+ out << L"<? xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
+ out.imbue(loc_is);
+ VERIFY( out.rdbuf()->getloc() == loc_is );
+ out << L"<greeting>Hall\u00f3 heimur</greeting>\n";
+ }
+
+ {
+ wifstream in("tmp_12868");
+ wstring str;
+ getline(in, str);
+ if (str.find(L"encoding=\"UTF-8\"") != wstring::npos)
+ {
+ in.imbue(loc_is);
+ VERIFY( in.rdbuf()->getloc() == loc_is );
+ }
+ getline(in, str);
+ VERIFY( str == L"<greeting>Hall\u00f3 heimur</greeting>" );
+ }
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc
new file mode 100644
index 000000000..9bb1f4035
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc
@@ -0,0 +1,62 @@
+// { dg-require-namedlocale "fr_FR" }
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::wfilebuf
+{
+public:
+ std::locale before;
+ std::locale after;
+
+protected:
+ void imbue(const std::locale& loc)
+ {
+ before = getloc();
+
+ std::wfilebuf::imbue(loc);
+
+ after = getloc();
+ }
+};
+
+// libstdc++/13007
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf buf;
+ std::locale loc(std::locale("fr_FR"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+ VERIFY( buf.before == std::locale::classic() );
+ VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc
new file mode 100644
index 000000000..ec11237d0
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc
@@ -0,0 +1,59 @@
+// { dg-require-namedlocale "fr_FR" }
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "de_DE" }
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <iostream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+// libstdc++/13171
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ locale::global(locale("fr_FR"));
+
+ ios_base::sync_with_stdio(false);
+
+ locale::global(locale("en_US"));
+ cin.imbue(locale("en_US"));
+ cout.imbue(locale("en_US"));
+ cerr.imbue(locale("en_US"));
+ clog.imbue(locale("de_DE"));
+ wcin.imbue(locale("en_US"));
+ wcout.imbue(locale("en_US"));
+ wcerr.imbue(locale("en_US"));
+ wclog.imbue(locale("de_DE"));
+
+ cout << 'f' << endl;
+ cerr << 'r' << endl;
+ clog << 'A' << endl;
+ wcout << L's' << endl;
+ wcerr << L'i' << endl;
+ wclog << L'L' << endl;
+}
+
+int main()
+{
+ test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc
new file mode 100644
index 000000000..7a997739f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc
@@ -0,0 +1,86 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "fr_FR" }
+// { dg-require-fork "" }
+// { dg-require-mkfifo "" }
+
+// 2004-01-11 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2004, 2005, 2006, 2007, 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.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <cstdlib>
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <testsuite_hooks.h>
+
+// libstdc++/13582
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ using namespace __gnu_test;
+
+ locale loc_en(locale("en_US"));
+ locale loc_fr(locale("fr_FR"));
+
+ const char* name = "tmp_fifo_13582-2";
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+
+ int child = fork();
+ if (child == 0)
+ {
+ filebuf fbout;
+ fbout.open(name, ios_base::out);
+ fbout.sputn("12345", 5);
+ fbout.pubsync();
+ sleep(2);
+ fbout.close();
+ exit(0);
+ }
+
+ wfilebuf fbin;
+ fbin.open(name, ios_base::in);
+ sleep(1);
+ wfilebuf::int_type n = fbin.sbumpc();
+ VERIFY( n == L'1' );
+ fbin.pubimbue(loc_en);
+ n = fbin.sbumpc();
+ VERIFY( n == L'2' );
+ fbin.pubimbue(loc_fr);
+ n = fbin.sbumpc();
+ VERIFY( n == L'3' );
+ n = fbin.sbumpc();
+ VERIFY( n == L'4' );
+ n = fbin.sbumpc();
+ VERIFY( n == L'5' );
+ n = fbin.sbumpc();
+ VERIFY( n == wfilebuf::traits_type::eof() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc
new file mode 100644
index 000000000..246ae8c6e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc
@@ -0,0 +1,74 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "fr_FR" }
+
+// 2004-01-11 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2004, 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.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+// libstdc++/13582
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ locale loc_en(locale("en_US"));
+ locale loc_fr(locale("fr_FR"));
+
+ const char* name = "tmp_13582-3.tst";
+
+ {
+ filebuf fbout;
+ fbout.open(name, ios_base::out);
+ fbout.sputn("AbCdE", 5);
+ fbout.close();
+ }
+
+ {
+ wfilebuf fbin;
+ fbin.open(name, ios_base::in);
+ wfilebuf::int_type n = fbin.sbumpc();
+ VERIFY( n == L'A' );
+ fbin.pubimbue(loc_en);
+ fbin.pubseekoff(0, ios_base::cur);
+ n = fbin.sbumpc();
+ VERIFY( n == L'b' );
+ fbin.pubimbue(loc_fr);
+ n = fbin.sbumpc();
+ VERIFY( n == L'C' );
+ n = fbin.sbumpc();
+ VERIFY( n == L'd' );
+ fbin.pubseekoff(0, ios_base::cur);
+ n = fbin.sbumpc();
+ VERIFY( n == L'E' );
+ n = fbin.sbumpc();
+ VERIFY( n == wfilebuf::traits_type::eof() );
+ fbin.close();
+ }
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc
new file mode 100644
index 000000000..dc1314556
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc
@@ -0,0 +1,95 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-fork "" }
+// { dg-require-mkfifo "" }
+
+// 2004-04-16 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 2004, 2005, 2006, 2007, 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 <fstream>
+#include <locale>
+#include <cstdlib>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// No asserts, avoid leaking the semaphore if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
+#include <testsuite_hooks.h>
+
+// libstdc++/14975
+bool test01()
+{
+ using namespace std;
+ using namespace __gnu_test;
+ bool test __attribute__((unused)) = true;
+
+ locale loc_us = locale("en_US");
+
+ const char* name = "tmp_14975-2";
+
+ signal(SIGPIPE, SIG_IGN);
+
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+ semaphore s1;
+
+ int child = fork();
+ VERIFY( child != -1 );
+
+ if (child == 0)
+ {
+ {
+ filebuf fbin;
+ fbin.open(name, ios_base::in);
+ }
+ s1.signal();
+ exit(0);
+ }
+
+ wfilebuf fb;
+ fb.pubimbue(loc_us);
+ wfilebuf* ret = fb.open(name, ios_base::out);
+ VERIFY( ret != 0 );
+ VERIFY( fb.is_open() );
+
+ s1.wait();
+
+ try
+ {
+ fb.sputc(L'a');
+ fb.sputc(L'b');
+ fb.pubimbue(locale::classic());
+ fb.sputc(L'c');
+ fb.close();
+ }
+ catch (std::exception&)
+ {
+ }
+
+ return test;
+}
+
+int main()
+{
+ return !test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc
new file mode 100644
index 000000000..52941a5fc
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc
@@ -0,0 +1,55 @@
+// { dg-require-namedlocale "de_DE" }
+
+// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+void test02()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
+
+ locale loc;
+ wfilebuf ob;
+ VERIFY( ob.getloc() == loc );
+ ob.open(name_01, ios_base::in);
+ VERIFY( ob.is_open() );
+
+ typedef streambuf::pos_type pos_type;
+ pos_type bad = pos_type(streambuf::off_type(-1));
+ pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
+ VERIFY( p != bad);
+
+ // According to 27.5.2.2.1, p1, loc == getloc() after pubimbue(loc).
+ locale loc_de = locale("de_DE");
+ locale ret = ob.pubimbue(loc_de);
+ VERIFY( ob.getloc() == loc_de );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc
new file mode 100644
index 000000000..01baec6b5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc
@@ -0,0 +1,55 @@
+// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com>
+
+// 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class state_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t>
+{
+protected:
+ int
+ do_encoding() const throw()
+ { return -1; }
+};
+
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc_s(locale::classic(), new state_codecvt);
+ wfilebuf ob;
+ ob.pubimbue(loc_s);
+ VERIFY( ob.getloc() == loc_s );
+
+ // 2 "if encoding of current locale is state dependent" and
+ // not at the beginning of the file fails...
+ locale loc_c = locale::classic();
+ locale ret = ob.pubimbue(loc_s);
+ VERIFY( ob.getloc() == loc_s );
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc
new file mode 100644
index 000000000..f69d9f0d6
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc
@@ -0,0 +1,55 @@
+// { dg-require-namedlocale "en_US" }
+// { dg-require-namedlocale "de_DE" }
+
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 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/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+// libstdc++/9322
+void test07()
+{
+ using std::locale;
+ bool test __attribute__((unused)) = true;
+
+ locale loc;
+ std::wfilebuf ob;
+ VERIFY( ob.getloc() == loc );
+
+ locale::global(locale("en_US"));
+ VERIFY( ob.getloc() == loc );
+
+ locale loc_de = locale("de_DE");
+ locale ret = ob.pubimbue(loc_de);
+ VERIFY( ob.getloc() == loc_de );
+ VERIFY( ret == loc );
+
+ locale::global(loc);
+ VERIFY( ob.getloc() == loc_de );
+}
+
+int main()
+{
+ test07();
+ return 0;
+}