summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t
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/underflow/wchar_t
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/underflow/wchar_t')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc111
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc50
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc52
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc51
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc53
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc184
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc184
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc201
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc112
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc117
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc55
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc41
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc74
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc204
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc61
15 files changed, 1550 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc
new file mode 100644
index 000000000..72c3ecb0a
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc
@@ -0,0 +1,111 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-04 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 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.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Test handing of UTF-8 in basic_filebuf::underflow
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ const char name[] = "tmp_underflow-1.tst";
+
+ const char cstr[] =
+ "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13"
+ "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&"
+ "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2"
+ "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a"
+ "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2"
+ "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99"
+ "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3"
+ "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85"
+ "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4"
+ "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94"
+ "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf"
+ "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0"
+ "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0"
+ "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0"
+ "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0"
+ "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0"
+ "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80"
+ "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80"
+ "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1"
+ "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80"
+ "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80"
+ "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80"
+ "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80"
+ "\xfd\x80\x80\x80\x80\x80";
+
+ const wchar_t wstr[] = {
+ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc,
+ 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!',
+ L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+',
+ L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5',
+ L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?',
+ L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,
+ 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100,
+ 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109,
+ 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112,
+ 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9,
+ 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802,
+ 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b,
+ 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814,
+ 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@',
+ 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
+ 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000,
+ 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000,
+ 0x20000000, 0x40000000, 0x0
+ };
+
+ const size_t clen = sizeof(cstr) / sizeof(cstr[0]);
+ const size_t wlen = sizeof(wstr) / sizeof(wstr[0]);
+
+ locale loc = locale("se_NO.UTF-8");
+
+ FILE* file = fopen(name, "w");
+ fwrite(cstr, 1, clen, file);
+ fclose(file);
+
+ wchar_t wbuf[wlen + 1];
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+ fb.open(name, ios_base::in);
+ streamsize n = fb.sgetn(wbuf, wlen + 1);
+ fb.close();
+
+ VERIFY( n == static_cast<streamsize>(wlen) );
+ VERIFY( !wmemcmp(wbuf, wstr, wlen) );
+}
+
+int main ()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc
new file mode 100644
index 000000000..55e226705
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc
@@ -0,0 +1,50 @@
+// { dg-require-namedlocale "en_US.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 <fstream>
+#include <testsuite_hooks.h>
+
+const char name_01[] = "tmp_11389-1";
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open(name_01, ios_base::out);
+ fbout.sputc('a');
+ fbout.close();
+
+ wfilebuf fbin;
+ locale loc(locale("en_US.UTF-8"));
+ fbin.pubimbue(loc);
+ fbin.open(name_01, ios_base::in);
+ VERIFY( fbin.sbumpc() == L'a' );
+ VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() );
+ fbin.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc
new file mode 100644
index 000000000..e4527ee69
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc
@@ -0,0 +1,52 @@
+// { dg-require-namedlocale "en_US.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 <fstream>
+#include <testsuite_hooks.h>
+
+const char name_02[] = "tmp_11389-2";
+
+void test02()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open(name_02, ios_base::out);
+ fbout.sputc('a');
+ fbout.sputc('b');
+ fbout.close();
+
+ wfilebuf fbin;
+ locale loc(locale("en_US.UTF-8"));
+ fbin.pubimbue(loc);
+ fbin.open(name_02, ios_base::in);
+ VERIFY( fbin.sbumpc() == L'a' );
+ VERIFY( fbin.sbumpc() == L'b' );
+ VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() );
+ fbin.close();
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc
new file mode 100644
index 000000000..45bb4bdf5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc
@@ -0,0 +1,51 @@
+// { dg-require-namedlocale "en_US.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 <fstream>
+#include <testsuite_hooks.h>
+
+const char name_03[] = "tmp_11389-3";
+
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open(name_03, ios_base::out);
+ fbout.sputc('a');
+ fbout.close();
+
+ wfilebuf fbin;
+ locale loc(locale("en_US.UTF-8"));
+ fbin.pubimbue(loc);
+ fbin.pubsetbuf(0, 0);
+ fbin.open(name_03, ios_base::in);
+ VERIFY( fbin.sbumpc() == L'a' );
+ VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() );
+ fbin.close();
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc
new file mode 100644
index 000000000..637f89806
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc
@@ -0,0 +1,53 @@
+// { dg-require-namedlocale "en_US.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 <fstream>
+#include <testsuite_hooks.h>
+
+const char name_04[] = "tmp_11389-4";
+
+void test04()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open(name_04, ios_base::out);
+ fbout.sputc('a');
+ fbout.sputc('b');
+ fbout.close();
+
+ wfilebuf fbin;
+ locale loc(locale("en_US.UTF-8"));
+ fbin.pubimbue(loc);
+ fbin.pubsetbuf(0, 0);
+ fbin.open(name_04, ios_base::in);
+ VERIFY( fbin.sbumpc() == L'a' );
+ VERIFY( fbin.sbumpc() == L'b' );
+ VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() );
+ fbin.close();
+}
+
+int main()
+{
+ test04();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc
new file mode 100644
index 000000000..7a27acd6f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc
@@ -0,0 +1,184 @@
+// 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 <cstdio>
+#include <testsuite_hooks.h>
+
+template <typename InternT, typename StateT = mbstate_t>
+class checksumcvt : public std::codecvt<InternT, char, StateT>
+{
+ typedef std::codecvt<InternT, char, StateT> Base;
+ static const size_t width = sizeof(InternT) + 1;
+
+public:
+ typedef InternT intern_type;
+ typedef char extern_type;
+
+ explicit checksumcvt(size_t refs = 0)
+ : Base(refs)
+ { }
+
+protected:
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_out(StateT&, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_end,
+ extern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(from_end - from),
+ static_cast<size_t>(to_end - to) / width);
+
+ while (len--)
+ {
+ const char* p = reinterpret_cast<const char*>(from);
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ *to++ = p[i];
+ checksum ^= static_cast<unsigned char>(p[i]);
+ }
+
+ *to++ = checksum;
+ ++from;
+ }
+
+ from_next = from;
+ to_next = to;
+ return from_next == from_end ? std::codecvt<InternT, char, StateT>::ok
+ : std::codecvt<InternT, char, StateT>::partial;
+ }
+
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_unshift(StateT&, extern_type* to,
+ extern_type*, extern_type*& to_next) const
+ {
+ to_next = to;
+ return std::codecvt<InternT, char, StateT>::ok;
+ }
+
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_in(StateT&, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_end,
+ intern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(to_end - to),
+ static_cast<size_t>(from_end - from) / width);
+
+ while (len)
+ {
+ const char* f = from;
+ intern_type tmp;
+ char* p = reinterpret_cast<char*>(&tmp);
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ p[i] = *f;
+ checksum ^= static_cast<unsigned char>(*f++);
+ }
+
+ if (*f++ != checksum)
+ break;
+
+ from = f;
+ *to++ = tmp;
+ len--;
+ }
+
+ from_next = from;
+ to_next = to;
+ return len ? std::codecvt<InternT, char, StateT>::error :
+ (from_next == from_end ? std::codecvt<InternT, char, StateT>::ok
+ : std::codecvt<InternT, char, StateT>::partial);
+ }
+
+ virtual int
+ do_encoding() const throw()
+ { return width; }
+
+ virtual int
+ do_length(StateT&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = std::min(max, static_cast<size_t>(end - from) / width);
+
+ int ret = 0;
+ while (len--)
+ {
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ checksum ^= static_cast<unsigned char>(*from++);
+ }
+
+ if (*from++ != checksum)
+ break;
+
+ ret++;
+ }
+
+ return ret;
+ }
+
+ virtual int
+ do_max_length() const throw()
+ { return width; }
+
+ virtual bool
+ do_always_noconv() const throw()
+ { return false; }
+};
+
+// libstdc++/11544 (incomplete character in file)
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(), new checksumcvt<wchar_t>);
+
+ const char* name = "tmp_11544-1";
+
+ FILE* f = fopen(name, "w");
+ putc('a', f);
+ fclose(f);
+
+ wifstream in;
+ in.imbue(loc);
+ in.open(name);
+
+ VERIFY( in.good() );
+ in.get();
+ VERIFY( !in.good() );
+ VERIFY( in.bad() );
+ VERIFY( !in.eof() );
+
+ in.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc
new file mode 100644
index 000000000..f6a2eaca9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc
@@ -0,0 +1,184 @@
+// 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 <cstdio>
+#include <testsuite_hooks.h>
+
+template <typename InternT, typename StateT = mbstate_t>
+class checksumcvt : public std::codecvt<InternT, char, StateT>
+{
+ typedef std::codecvt<InternT, char, StateT> Base;
+ static const size_t width = sizeof(InternT) + 1;
+
+public:
+ typedef InternT intern_type;
+ typedef char extern_type;
+
+ explicit checksumcvt(size_t refs = 0)
+ : Base(refs)
+ { }
+
+protected:
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_out(StateT&, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_end,
+ extern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(from_end - from),
+ static_cast<size_t>(to_end - to) / width);
+
+ while (len--)
+ {
+ const char* p = reinterpret_cast<const char*>(from);
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ *to++ = p[i];
+ checksum ^= static_cast<unsigned char>(p[i]);
+ }
+
+ *to++ = checksum;
+ ++from;
+ }
+
+ from_next = from;
+ to_next = to;
+ return from_next == from_end ? std::codecvt<InternT, char, StateT>::ok
+ : std::codecvt<InternT, char, StateT>::partial;
+ }
+
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_unshift(StateT&, extern_type* to,
+ extern_type*, extern_type*& to_next) const
+ {
+ to_next = to;
+ return std::codecvt<InternT, char, StateT>::ok;
+ }
+
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_in(StateT&, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_end,
+ intern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(to_end - to),
+ static_cast<size_t>(from_end - from) / width);
+
+ while (len)
+ {
+ const char* f = from;
+ intern_type tmp;
+ char* p = reinterpret_cast<char*>(&tmp);
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ p[i] = *f;
+ checksum ^= static_cast<unsigned char>(*f++);
+ }
+
+ if (*f++ != checksum)
+ break;
+
+ from = f;
+ *to++ = tmp;
+ len--;
+ }
+
+ from_next = from;
+ to_next = to;
+ return len ? std::codecvt<InternT, char, StateT>::error :
+ (from_next == from_end ? std::codecvt<InternT, char, StateT>::ok
+ : std::codecvt<InternT, char, StateT>::partial);
+ }
+
+ virtual int
+ do_encoding() const throw()
+ { return width; }
+
+ virtual int
+ do_length(StateT&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = std::min(max, static_cast<size_t>(end - from) / width);
+
+ int ret = 0;
+ while (len--)
+ {
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ checksum ^= static_cast<unsigned char>(*from++);
+ }
+
+ if (*from++ != checksum)
+ break;
+
+ ret++;
+ }
+
+ return ret;
+ }
+
+ virtual int
+ do_max_length() const throw()
+ { return width; }
+
+ virtual bool
+ do_always_noconv() const throw()
+ { return false; }
+};
+
+// libstdc++/11544 (invalid byte sequence in file)
+void test02()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc(locale::classic(), new checksumcvt<wchar_t>);
+
+ const char* name = "tmp_11544-2";
+
+ FILE* f = fopen(name, "w");
+ VERIFY( fwrite("aaaab", 1, 5, f) == 5 );
+ fclose(f);
+
+ wifstream in;
+ in.imbue(loc);
+ in.open(name);
+
+ VERIFY( in.good() );
+ in.get();
+ VERIFY( !in.good() );
+ VERIFY( in.bad() );
+ VERIFY( !in.eof() );
+
+ in.close();
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc
new file mode 100644
index 000000000..116c404a5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc
@@ -0,0 +1,201 @@
+// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-binary-io "" }
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+template <typename InternT, typename StateT = std::mbstate_t>
+class checksumcvt : public std::codecvt<InternT, char, StateT>
+{
+ typedef std::codecvt<InternT, char, StateT> Base;
+ static const std::size_t width = sizeof(InternT) + 1;
+
+public:
+ typedef InternT intern_type;
+ typedef char extern_type;
+
+ explicit checksumcvt(std::size_t refs = 0)
+ : Base(refs)
+ { }
+
+protected:
+ virtual std::codecvt_base::result
+ do_out(StateT&, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_end,
+ extern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(from_end - from),
+ static_cast<size_t>(to_end - to) / width);
+
+ while (len--)
+ {
+ const char* p =
+ reinterpret_cast<const char*>(from);
+ unsigned char checksum = 0;
+
+ for (std::size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ *to++ = p[i];
+ checksum ^= static_cast<unsigned char>(p[i]);
+ }
+
+ *to++ = checksum;
+ ++from;
+ }
+
+ from_next = from;
+ to_next = to;
+ return from_next == from_end ? std::codecvt_base::ok
+ : std::codecvt_base::partial;
+ }
+
+ virtual std::codecvt_base::result
+ do_unshift(StateT&, extern_type* to,
+ extern_type*, extern_type*& to_next) const
+ {
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+
+ virtual std::codecvt_base::result
+ do_in(StateT&, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_end,
+ intern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(to_end - to),
+ static_cast<size_t>(from_end - from) / width);
+
+ while (len)
+ {
+ const char* f = from;
+ intern_type tmp;
+ char* p = reinterpret_cast<char*>(&tmp);
+ unsigned char checksum = 0;
+
+ for (std::size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ p[i] = *f;
+ checksum ^= static_cast<unsigned char>(*f++);
+ }
+
+ if (*f++ != checksum)
+ break;
+
+ from = f;
+ *to++ = tmp;
+ len--;
+ }
+
+ from_next = from;
+ to_next = to;
+ return len ? std::codecvt_base::error :
+ (from_next == from_end ? std::codecvt_base::ok
+ : std::codecvt_base::partial);
+ }
+
+ virtual int
+ do_encoding() const throw()
+ { return width; }
+
+ virtual int
+ do_length(const StateT&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = std::min(max,
+ static_cast<size_t>(end - from) / width);
+
+ int ret = 0;
+ while (len--)
+ {
+ unsigned char checksum = 0;
+
+ for (std::size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ checksum ^= static_cast<unsigned char>(*from++);
+ }
+
+ if (*from++ != checksum)
+ break;
+
+ ret++;
+ }
+
+ return ret;
+ }
+
+ virtual int
+ do_max_length() const throw()
+ { return width; }
+
+ virtual bool
+ do_always_noconv() const throw()
+ { return false; }
+};
+
+class Buf : public std::wfilebuf
+{
+public:
+ std::streamsize pub_showmanyc()
+ { return showmanyc(); }
+ std::wfilebuf::int_type pub_underflow()
+ { return underflow(); }
+};
+
+// libstdc++/11603
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open("tmp_11603", ios_base::out);
+ fbout.sputn("aaaab", 5);
+ fbout.close();
+
+ locale loc(locale::classic(), new checksumcvt<wchar_t>);
+
+ Buf fb;
+ fb.pubimbue(loc);
+ fb.open("tmp_11603", ios_base::in);
+ VERIFY( fb.pub_showmanyc() == 1 );
+
+ try
+ {
+ wfilebuf::int_type ret = fb.pub_underflow();
+ VERIFY( ret != wfilebuf::traits_type::eof() );
+ fb.sbumpc();
+ ret = fb.pub_underflow();
+ VERIFY( ret == wfilebuf::traits_type::eof() );
+ }
+ catch (...)
+ { }
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc
new file mode 100644
index 000000000..c6f30442c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc
@@ -0,0 +1,112 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-04 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 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.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Test handing of UTF-8 in unbuffered basic_filebuf::underflow
+void test02()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ const char name[] = "tmp_underflow-2.tst";
+
+ const char cstr[] =
+ "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13"
+ "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&"
+ "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2"
+ "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a"
+ "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2"
+ "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99"
+ "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3"
+ "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85"
+ "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4"
+ "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94"
+ "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf"
+ "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0"
+ "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0"
+ "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0"
+ "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0"
+ "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0"
+ "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80"
+ "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80"
+ "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1"
+ "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80"
+ "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80"
+ "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80"
+ "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80"
+ "\xfd\x80\x80\x80\x80\x80";
+
+ const wchar_t wstr[] = {
+ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc,
+ 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!',
+ L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+',
+ L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5',
+ L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?',
+ L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,
+ 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100,
+ 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109,
+ 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112,
+ 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9,
+ 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802,
+ 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b,
+ 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814,
+ 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@',
+ 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
+ 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000,
+ 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000,
+ 0x20000000, 0x40000000, 0x0
+ };
+
+ const size_t clen = sizeof(cstr) / sizeof(cstr[0]);
+ const size_t wlen = sizeof(wstr) / sizeof(wstr[0]);
+
+ locale loc = locale("se_NO.UTF-8");
+
+ FILE* file = fopen(name, "w");
+ fwrite(cstr, 1, clen, file);
+ fclose(file);
+
+ wchar_t wbuf[wlen + 1];
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+ fb.pubsetbuf(0, 0);
+ fb.open(name, ios_base::in);
+ streamsize n = fb.sgetn(wbuf, wlen + 1);
+ fb.close();
+
+ VERIFY( n == static_cast<streamsize>(wlen) );
+ VERIFY( !wmemcmp(wbuf, wstr, wlen) );
+}
+
+int main ()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc
new file mode 100644
index 000000000..42892e4ac
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc
@@ -0,0 +1,117 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-04 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 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.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Test handing of UTF-8 in basic_filebuf::underflow
+void test03()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ const char name[] = "tmp_underflow-3.tst";
+
+ const char cstr[] =
+ "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13"
+ "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&"
+ "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2"
+ "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a"
+ "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2"
+ "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99"
+ "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3"
+ "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85"
+ "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4"
+ "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94"
+ "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf"
+ "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0"
+ "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0"
+ "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0"
+ "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0"
+ "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0"
+ "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80"
+ "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80"
+ "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1"
+ "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80"
+ "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80"
+ "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80"
+ "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80"
+ "\xfd\x80\x80\x80\x80\x80";
+
+ const wchar_t wstr[] = {
+ 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc,
+ 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!',
+ L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+',
+ L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5',
+ L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?',
+ L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85,
+ 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+ 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100,
+ 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109,
+ 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112,
+ 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9,
+ 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802,
+ 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b,
+ 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814,
+ 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@',
+ 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
+ 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000,
+ 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000,
+ 0x20000000, 0x40000000, 0x0
+ };
+
+ const size_t clen = sizeof(cstr) / sizeof(cstr[0]);
+ const size_t wlen = sizeof(wstr) / sizeof(wstr[0]);
+
+ const int loops = 2 * BUFSIZ / wlen;
+ locale loc = locale("se_NO.UTF-8");
+
+ FILE* file = fopen(name, "w");
+ for (int i = 0; i < loops; ++i)
+ fwrite(cstr, 1, clen, file);
+ fclose(file);
+
+ wchar_t wbuf[wlen];
+
+ wfilebuf fb;
+ fb.pubimbue(loc);
+ fb.open(name, ios_base::in);
+ for (int i = 0; i < loops; ++i)
+ {
+ streamsize n = fb.sgetn(wbuf, wlen);
+ VERIFY( n == static_cast<streamsize>(wlen) );
+ VERIFY( !wmemcmp(wbuf, wstr, wlen) );
+ }
+
+ VERIFY( fb.sgetc() == wfilebuf::traits_type::eof() );
+ fb.close();
+}
+
+int main ()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc
new file mode 100644
index 000000000..6e63db09d
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc
@@ -0,0 +1,55 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-04 Petur Runolfsson <peturr02@ru.is>
+// Adapted from 27_io/basic_filebuf/underflow/char/2.cc
+
+// 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 test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ locale loc (locale("se_NO.UTF-8"));
+ wfilebuf fb_out, fb_in_out;
+ fb_out.pubimbue(loc);
+ fb_in_out.pubimbue(loc);
+
+ fb_out.open("tmp_underflow.tst", ios::out);
+ fb_out.sputc(L'S');
+ fb_out.sputc(L'T');
+ fb_out.close();
+
+ fb_in_out.open("tmp_underflow.tst", ios::in | ios::out);
+ while (fb_in_out.sbumpc() != wfilebuf::traits_type::eof());
+
+ VERIFY( fb_in_out.sputc(L'x') == L'x' );
+ fb_in_out.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc
new file mode 100644
index 000000000..2d7cb7af2
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc
@@ -0,0 +1,41 @@
+// Copyright (C) 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/>.
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ wfilebuf fb_in_out;
+
+ fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc);
+
+ VERIFY( fb_in_out.sputc(L'x') == L'x' );
+ VERIFY( fb_in_out.sgetc() == wfilebuf::traits_type::eof() );
+ fb_in_out.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc
new file mode 100644
index 000000000..4c4b8d3b4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc
@@ -0,0 +1,74 @@
+// { dg-require-namedlocale "se_NO.UTF-8" }
+
+// 2003-09-04 Petur Runolfsson <peturr02@ru.is>
+
+// Copyright (C) 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.8.1.4 Overridden virtual functions
+
+#include <locale>
+#include <fstream>
+#include <cstdio>
+#include <testsuite_hooks.h>
+
+// Test that unbuffered really means unbuffered for UTF-8
+void test05()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_underflow-5";
+
+ wfilebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.pubimbue(locale("se_NO.UTF-8"));
+
+ FILE* file = fopen(name, "w");
+ setvbuf(file, 0, _IONBF, 0);
+ fputs("abcde", file);
+
+ fb.open(name, ios_base::in);
+ VERIFY( fb.sbumpc() == L'a' );
+
+ fseek(file, 1, SEEK_SET);
+ fputc('0', file);
+
+ VERIFY( fb.sbumpc() == L'0' );
+ VERIFY( fb.sbumpc() == L'c' );
+
+ fputc('1', file);
+ fputc('2', file);
+
+ VERIFY( fb.sbumpc() == L'2' );
+ VERIFY( fb.sbumpc() == L'e' );
+ VERIFY( fb.sbumpc() == WEOF );
+
+ fputc('3', file);
+ fputc('4', file);
+
+ VERIFY( fb.sbumpc() == L'4' );
+ VERIFY( fb.sbumpc() == WEOF );
+
+ fb.close();
+ fclose(file);
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc
new file mode 100644
index 000000000..344db32d7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc
@@ -0,0 +1,204 @@
+// 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 <string>
+#include <iterator>
+#include <algorithm>
+#include <locale>
+#include <testsuite_hooks.h>
+
+template <typename InternT, typename StateT = mbstate_t>
+class checksumcvt : public std::codecvt<InternT, char, StateT>
+{
+ typedef std::codecvt<InternT, char, StateT> Base;
+ static const size_t width = sizeof(InternT) + 1;
+
+public:
+ typedef InternT intern_type;
+ typedef char extern_type;
+
+ explicit checksumcvt(size_t refs = 0)
+ : Base(refs)
+ { }
+
+protected:
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_out(StateT&, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_end,
+ extern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(from_end - from),
+ static_cast<size_t>(to_end - to) / width);
+
+ while (len--)
+ {
+ const char* p = reinterpret_cast<const char*>(from);
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ *to++ = p[i];
+ checksum ^= static_cast<unsigned char>(p[i]);
+ }
+
+ *to++ = checksum;
+ ++from;
+ }
+
+ from_next = from;
+ to_next = to;
+ return from_next == from_end ? std::codecvt<InternT, char, StateT>::ok
+ : std::codecvt<InternT, char, StateT>::partial;
+ }
+
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_unshift(StateT&, extern_type* to,
+ extern_type*, extern_type*& to_next) const
+ {
+ to_next = to;
+ return std::codecvt<InternT, char, StateT>::ok;
+ }
+
+ virtual typename std::codecvt<InternT, char, StateT>::result
+ do_in(StateT&, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_end,
+ intern_type*& to_next) const
+ {
+ size_t len = std::min(static_cast<size_t>(to_end - to),
+ static_cast<size_t>(from_end - from) / width);
+
+ while (len)
+ {
+ const char* f = from;
+ intern_type tmp;
+ char* p = reinterpret_cast<char*>(&tmp);
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ p[i] = *f;
+ checksum ^= static_cast<unsigned char>(*f++);
+ }
+
+ if (*f++ != checksum)
+ break;
+
+ from = f;
+ *to++ = tmp;
+ len--;
+ }
+
+ from_next = from;
+ to_next = to;
+ return len ? std::codecvt<InternT, char, StateT>::error :
+ (from_next == from_end ? std::codecvt<InternT, char, StateT>::ok
+ : std::codecvt<InternT, char, StateT>::partial);
+ }
+
+ virtual int
+ do_encoding() const throw()
+ {
+ return width;
+ }
+
+ virtual int
+ do_length(StateT&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = std::min(max, static_cast<size_t>(end - from) / width);
+
+ int ret = 0;
+ while (len--)
+ {
+ unsigned char checksum = 0;
+
+ for (size_t i = 0; i < sizeof(intern_type); ++i)
+ {
+ checksum ^= static_cast<unsigned char>(*from++);
+ }
+
+ if (*from++ != checksum)
+ break;
+
+ ret++;
+ }
+
+ return ret;
+ }
+
+ virtual int
+ do_max_length() const throw()
+ {
+ return width;
+ }
+
+ virtual bool
+ do_always_noconv() const throw()
+ {
+ return false;
+ }
+};
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ locale loc;
+ loc = locale(loc, new checksumcvt<wchar_t>);
+
+ wfilebuf fbuf1;
+ fbuf1.pubimbue(loc);
+ fbuf1.open("tmp_9178", ios_base::out | ios_base::trunc);
+
+ string tmpstr = "abcdefghijklmnopqrstuvwxyz0123456789 \t\n";
+
+ wifstream stream;
+ wstring str1;
+
+ while (str1.length() < 20000)
+ {
+ transform(tmpstr.begin(), tmpstr.end(),
+ back_inserter(str1),
+ bind1st(std::mem_fun(&std::wios::widen), &stream));
+ }
+
+ fbuf1.sputn(str1.data(), str1.size());
+ fbuf1.close();
+
+ wfilebuf fbuf2;
+ fbuf2.pubimbue(loc);
+ fbuf2.open("tmp_9178", std::ios_base::in);
+
+ wstring str2;
+ copy(istreambuf_iterator<wchar_t>(&fbuf2),
+ istreambuf_iterator<wchar_t>(),
+ back_inserter(str2));
+
+ VERIFY( str1 == str2 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc
new file mode 100644
index 000000000..f791b86aa
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc
@@ -0,0 +1,61 @@
+// { dg-require-namedlocale "de_DE.ISO-8859-15@euro" }
+
+// 2003-05-03 Petur Runolfsson <peturr02@ru.is>
+
+// 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 <testsuite_hooks.h>
+#include <fstream>
+#include <cstdio>
+
+// libstdc++/9520
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_9520";
+
+ FILE* file = fopen(name, "w");
+ for (int i = 1; i < 256; ++i)
+ putc(static_cast<unsigned char>(i), file);
+ fclose(file);
+
+ locale loc (locale("de_DE.ISO-8859-15@euro"));
+ wchar_t buf[1];
+ wfilebuf fb;
+ fb.pubimbue(loc);
+ fb.pubsetbuf(buf, 1);
+ fb.open(name, ios_base::in);
+
+ for (int j = 1; j < 256; ++j)
+ {
+ wfilebuf::int_type c1 = fb.sgetc();
+ VERIFY( c1 != wfilebuf::traits_type::eof() );
+ wfilebuf::int_type c2 = fb.sbumpc();
+ VERIFY( c1 == c2 );
+ }
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}