From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; 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. --- .../27_io/basic_filebuf/underflow/10096.cc | 71 +++++++ .../27_io/basic_filebuf/underflow/char/1.cc | 83 +++++++++ .../27_io/basic_filebuf/underflow/char/10097.cc | 115 ++++++++++++ .../27_io/basic_filebuf/underflow/char/2.cc | 49 +++++ .../27_io/basic_filebuf/underflow/char/3.cc | 84 +++++++++ .../27_io/basic_filebuf/underflow/char/45841.cc | 41 +++++ .../27_io/basic_filebuf/underflow/char/9027.cc | 85 +++++++++ .../27_io/basic_filebuf/underflow/wchar_t/1.cc | 111 +++++++++++ .../basic_filebuf/underflow/wchar_t/11389-1.cc | 50 +++++ .../basic_filebuf/underflow/wchar_t/11389-2.cc | 52 ++++++ .../basic_filebuf/underflow/wchar_t/11389-3.cc | 51 ++++++ .../basic_filebuf/underflow/wchar_t/11389-4.cc | 53 ++++++ .../basic_filebuf/underflow/wchar_t/11544-1.cc | 184 +++++++++++++++++++ .../basic_filebuf/underflow/wchar_t/11544-2.cc | 184 +++++++++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/11603.cc | 201 ++++++++++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/2.cc | 112 +++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/3.cc | 117 ++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/4.cc | 55 ++++++ .../27_io/basic_filebuf/underflow/wchar_t/45841.cc | 41 +++++ .../27_io/basic_filebuf/underflow/wchar_t/5.cc | 74 ++++++++ .../27_io/basic_filebuf/underflow/wchar_t/9178.cc | 204 +++++++++++++++++++++ .../27_io/basic_filebuf/underflow/wchar_t/9520.cc | 61 ++++++ 22 files changed, 2078 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc (limited to 'libstdc++-v3/testsuite/27_io/basic_filebuf/underflow') diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc new file mode 100644 index 000000000..fb8d2f615 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc @@ -0,0 +1,71 @@ +// 2003-05-03 Petur Runolfsson + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class MyTraits : public std::char_traits +{ +}; + +// libstdc++/10096 +void test01() +{ + using namespace std; + + const char* name = "filebuf_virtuals-1.txt"; + + string str; + filebuf fb1; + fb1.open(name, ios_base::in); + + filebuf::int_type c1; + while ((c1 = fb1.sbumpc()) != filebuf::traits_type::eof()) + str.push_back(filebuf::traits_type::to_char_type(c1)); + fb1.close(); + + basic_filebuf fb; + VERIFY( fb.sgetc() == MyTraits::eof() ); + + fb.open(name, ios_base::in); + VERIFY( fb.is_open() ); + + for (string::iterator i = str.begin(); i != str.end(); ++i) + { + MyTraits::int_type c2 = fb.sbumpc(); + VERIFY( c2 != MyTraits::eof() ); + VERIFY( c2 == MyTraits::to_int_type(*i) ); + } + + VERIFY( fb.sgetc() == MyTraits::eof() ); + fb.close(); + VERIFY( !fb.is_open() ); + VERIFY( fb.sgetc() == MyTraits::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc new file mode 100644 index 000000000..03fcd7d9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc @@ -0,0 +1,83 @@ +// 2003-05-03 Petur Runolfsson + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// Check that basic_filebuf::underflow() handles +// codecvt::always_noconv() == false and codecvt::in() == noconv. +class NoconvCvt : public std::codecvt +{ +protected: + virtual bool + do_always_noconv() const throw() + { return false; } + + virtual result + do_in(state_type&, const char* from, const char*, const char*& from_next, + char* to, char*, char*& to_next) + { + from_next = from; + to_next = to; + return noconv; + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + + string str; + filebuf fb; + filebuf::int_type c1; + + if (fb.open(name, ios_base::in)) + { + while ((c1 = fb.sbumpc()) != EOF) + str.push_back(filebuf::traits_type::to_char_type(c1)); + fb.close(); + } + + locale loc(locale::classic(), new NoconvCvt); + fb.pubimbue(loc); + + if (fb.open(name, ios_base::in)) + { + for (string::iterator i = str.begin(); i != str.end(); ++i) + { + c1 = fb.sbumpc(); + VERIFY( c1 != filebuf::traits_type::eof() ); + VERIFY( c1 == filebuf::traits_type::to_int_type(*i) ); + } + VERIFY( fb.sgetc() == filebuf::traits_type::eof() ); + fb.close(); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc new file mode 100644 index 000000000..af0e9141c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc @@ -0,0 +1,115 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +class UnderBuf : public std::filebuf +{ +public: + int_type + pub_underflow() + { return underflow(); } + + std::streamsize + pub_showmanyc() + { return showmanyc(); } +}; + +// libstdc++/10097 +// filebuf::underflow drops characters. +bool test16() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo1"; + + signal(SIGPIPE, SIG_IGN); + unlink(name); + + if (0 != mkfifo(name, S_IRWXU)) + { + VERIFY( false ); + } + + semaphore s1, s2; + int fval = fork(); + if (fval == -1) + { + unlink(name); + VERIFY( false ); + } + else if (fval == 0) + { + filebuf fbout; + fbout.open(name, ios_base::in|ios_base::out); + VERIFY( fbout.is_open() ); + fbout.sputn("0123456789", 10); + fbout.pubsync(); + s1.wait(); + fbout.close(); + s2.signal(); + exit(0); + } + + UnderBuf fb; + fb.open(name, ios_base::in); + + fb.sgetc(); + streamsize n = fb.pub_showmanyc(); + + while (n > 0) + { + --n; + + UnderBuf::int_type c = fb.pub_underflow(); + VERIFY( c != UnderBuf::traits_type::eof() ); + + fb.sbumpc(); + } + + fb.close(); + s1.signal(); + s2.wait(); + + return test; +} + +int main() +{ + return !test16(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc new file mode 100644 index 000000000..0d36be046 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc @@ -0,0 +1,49 @@ +// 2003-06-25 Paolo Carlini + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb_out, fb_in_out; + + fb_out.open("tmp_underflow.tst", ios::out); + fb_out.sputc('S'); + fb_out.sputc('T'); + fb_out.close(); + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out); + while (fb_in_out.sbumpc() != filebuf::traits_type::eof()); + + VERIFY( fb_in_out.sputc('x') == 'x' ); + fb_in_out.close(); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc new file mode 100644 index 000000000..4de8a4d46 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc @@ -0,0 +1,84 @@ +// Copyright (C) 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 +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +class Mycvtcc +: public std::codecvt +{ +protected: + virtual result + do_in(state_type&, + const extern_type* from, const extern_type* from_end, + const extern_type*& from_next, + intern_type* to, intern_type* to_limit, + intern_type*& to_next) const + { + from_next = from, to_next = to; + + if (from_next == from_end || to_next == to_limit) + return partial; + + if (std::islower(*from_next)) + *to_next = std::toupper(*from_next); + else + *to_next = *from_next; + ++from_next, ++to_next; + return ok; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// See Novell Bug 255122 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const char* name = "tmp_underflow_3.tst"; + filebuf fbuf, fbufx; + + fbuf.open(name, ios_base::out | ios_base::trunc); + VERIFY( fbuf.sputc('a') == 'a' ); + VERIFY( fbuf.sputc('b') == 'b' ); + VERIFY( fbuf.sputc('\n') == '\n' ); + fbuf.close(); + + fbufx.pubimbue(locale(locale::classic(), new Mycvtcc)); + fbufx.open(name, ios_base::in); + VERIFY( fbufx.sbumpc() == 'A' ); + VERIFY( fbufx.sbumpc() == 'B' ); + VERIFY( fbufx.sbumpc() == '\n' ); + VERIFY( fbufx.sbumpc() == filebuf::traits_type::eof() ); + fbufx.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc new file mode 100644 index 000000000..a356d626e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/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 +// . + +// { dg-require-fileio "" } + +#include +#include + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb_in_out; + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc); + + VERIFY( fb_in_out.sputc('x') == 'x' ); + VERIFY( fb_in_out.sgetc() == filebuf::traits_type::eof() ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc new file mode 100644 index 000000000..25f55493d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc @@ -0,0 +1,85 @@ +// 2003-05-03 Petur Runolfsson + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +class Cvt_to_upper : public std::codecvt +{ + typedef std::codecvt Base; + +public: + explicit Cvt_to_upper(std::size_t refs = 0) + : Base(refs) + { } + +protected: + virtual result + do_in(state_type&, + 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 + { + while (from < from_end && to < to_end) + *to++ = std::toupper(*from++); + + to_next = to; + from_next = from; + return from == from_end ? ok : partial; + } + + virtual bool + do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9027 +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + locale loc (locale::classic(), new Cvt_to_upper); + + filebuf fbin; + fbin.pubimbue(loc); + fbin.open(name, ios_base::in); + + int c; + while ((c = fbin.sbumpc()) != EOF) + { + VERIFY( !islower(c) ); + } + + fbin.close(); +} + +int main() +{ + test01(); + return 0; +} 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 + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// 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(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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt 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::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(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt::ok + : std::codecvt::partial; + } + + virtual typename std::codecvt::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt::ok; + } + + virtual typename std::codecvt::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(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt::error : + (from_next == from_end ? std::codecvt::ok + : std::codecvt::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(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(*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); + + 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt 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::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(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt::ok + : std::codecvt::partial; + } + + virtual typename std::codecvt::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt::ok; + } + + virtual typename std::codecvt::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(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt::error : + (from_next == from_end ? std::codecvt::ok + : std::codecvt::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(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(*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); + + 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 +// . + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-binary-io "" } + +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt 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(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = + reinterpret_cast(from); + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(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(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*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(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(*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); + + 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 + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// 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(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 + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// 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(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 +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include + +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 +// . + +// { dg-require-fileio "" } + +#include +#include + +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 + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include + +// 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 +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include +#include +#include +#include +#include + +template +class checksumcvt : public std::codecvt +{ + typedef std::codecvt 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::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(from_end - from), + static_cast(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt::ok + : std::codecvt::partial; + } + + virtual typename std::codecvt::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt::ok; + } + + virtual typename std::codecvt::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(to_end - to), + static_cast(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt::error : + (from_next == from_end ? std::codecvt::ok + : std::codecvt::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(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(*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); + + 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(&fbuf2), + istreambuf_iterator(), + 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 + +// 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 +// . + +#include +#include +#include + +// 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(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; +} -- cgit v1.2.3