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. --- .../testsuite/27_io/basic_filebuf/close/12790-1.cc | 79 +++++++++++++++ .../testsuite/27_io/basic_filebuf/close/char/1.cc | 87 +++++++++++++++++ .../27_io/basic_filebuf/close/char/12790-1.cc | 80 +++++++++++++++ .../27_io/basic_filebuf/close/char/12790-2.cc | 82 ++++++++++++++++ .../27_io/basic_filebuf/close/char/12790-3.cc | 81 ++++++++++++++++ .../27_io/basic_filebuf/close/char/12790-4.cc | 81 ++++++++++++++++ .../testsuite/27_io/basic_filebuf/close/char/2.cc | 80 +++++++++++++++ .../testsuite/27_io/basic_filebuf/close/char/3.cc | 89 +++++++++++++++++ .../testsuite/27_io/basic_filebuf/close/char/4.cc | 73 ++++++++++++++ .../27_io/basic_filebuf/close/char/4879.cc | 108 +++++++++++++++++++++ .../testsuite/27_io/basic_filebuf/close/char/5.cc | 106 ++++++++++++++++++++ .../27_io/basic_filebuf/close/char/9964.cc | 89 +++++++++++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-1.cc | 78 +++++++++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-2.cc | 80 +++++++++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-3.cc | 79 +++++++++++++++ .../27_io/basic_filebuf/close/wchar_t/12790-4.cc | 79 +++++++++++++++ 16 files changed, 1351 insertions(+) create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc create mode 100644 libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc (limited to 'libstdc++-v3/testsuite/27_io/basic_filebuf/close') diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc new file mode 100644 index 000000000..99d5eda88 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc @@ -0,0 +1,79 @@ +// 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.3 filebuf member functions + +// { dg-require-fileio "" } + +#include +#include +#include +#include + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + locale loc(locale::classic(), + new codecvt); + + basic_filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from('b')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + + // Check that close() writes unshift sequence + fb.close(); + + fb.open(name, ios_base::in | ios_base::out | ios_base::ate); + + fb.sputc(pod_uchar::from('a')); + fb.sputc(pod_uchar::from(0xff)); + fb.sputc(pod_uchar::from(0)); + + fb.close(); + + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc new file mode 100644 index 000000000..0a12e7224 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include +#include + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + VERIFY( fb_01.is_open() ); + + // Try to open two different files without closing the first: + // Should keep the old file attached, and disregard attempt to overthrow. + fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + VERIFY( fb_02.is_open() ); + + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_03.is_open() ); + + // filebuf_type* close() + std::filebuf* f; + f = fb_01.close(); + VERIFY( f ); + VERIFY( !fb_01.is_open() ); + + f = fb_02.close(); + VERIFY( f ); + VERIFY( !fb_02.is_open() ); + + f = fb_03.close(); + VERIFY( f ); + VERIFY( !fb_03.is_open() ); + + f = fb_03.close(); + VERIFY( !f ); + VERIFY( !fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc new file mode 100644 index 000000000..508261ba2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc @@ -0,0 +1,80 @@ +// 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.3 filebuf member functions + +// { dg-require-fileio "" } + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc new file mode 100644 index 000000000..0a4bdb3c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc @@ -0,0 +1,82 @@ +// 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 +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + fb.in_avail(); // showmanyc() should have no effect on close(). + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc new file mode 100644 index 000000000..fe0624d10 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return codecvt_base::error; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should fail if codecvt::unshift() fails +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + filebuf* ret = fb.close(); + VERIFY( cvt->unshift_called ); + VERIFY( !ret ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc new file mode 100644 index 000000000..e54c61682 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc @@ -0,0 +1,81 @@ +// 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 +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc new file mode 100644 index 000000000..c1a0f79c8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include + +// Verify that std::filebuf doesn't close files that it didn't open +// when using the following std::filebuf ctor: +// +// std::filebuf(__c_file_type* __f, +// ios_base::openmode __mode, +// int_type __s); +// +// Thanks to "George T. Talbot" for uncovering +// this bug/situation. + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +void test_02() +{ + bool test __attribute__((unused)) = true; + int close_num = 0; + + // read (ext) + FILE* f2 = fopen(name_01, "r"); + VERIFY( f2 ); + if (f2) + { + __gnu_cxx::stdio_filebuf fb(f2, std::ios_base::in, 512); + close_num = fclose(f2); + } + VERIFY( close_num == 0 ); + + // read (standard) + FILE* f = fopen(name_01, "r"); + VERIFY( f ); + if (f) + { + std::ifstream ifstream1(name_01); + VERIFY( ifstream1.is_open() ); + std::ios_base::iostate st01 = ifstream1.rdstate(); + VERIFY( st01 == std::ios_base::goodbit ); + close_num = fclose(f); + } + VERIFY( close_num == 0 ); +} + +int +main() +{ + test_02(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc new file mode 100644 index 000000000..a5db2aed6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc @@ -0,0 +1,89 @@ +// 2001-05-21 Benjamin Kosnik + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.4 Overridden virtual functions + +#include +#include + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +// NB: This test assumes that _M_buf_size == 40, and not the usual +// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be +// simulated a bit more readily. +// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. +const int buffer_size = 8192; +//const int buffer_size = 40; + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create +const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create + +class derived_filebuf: public std::filebuf +{ + public: + void + set_size(int_type __size) { _M_buf_size = __size; } +}; + +derived_filebuf fb_01; // in +derived_filebuf fb_02; // out +derived_filebuf fb_03; // in | out + +// Initialize filebufs to be the same size regardless of platform. +void test03() +{ + fb_01.set_size(buffer_size); + fb_02.set_size(buffer_size); + fb_03.set_size(buffer_size); +} + +// Test overloaded virtual functions. +void test05() +{ + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::filebuf f_tmp; + + fb_01.open(name_01, std::ios_base::in); + fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); + + // NB Have to close these suckers. . . + // filebuf_type* close() + fb_01.close(); + fb_02.close(); + fb_03.close(); + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); +} + +int main() +{ + test03(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc new file mode 100644 index 000000000..cd4f5e15b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc @@ -0,0 +1,73 @@ +// 2003-05-19 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 +// . + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// Test that upon filebuf::close() 27.8.1.1,3 is enforced. + +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +void test_04() +{ + typedef std::filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + std::filebuf fb_01, fb_02; + char buffer[] = "xxxxxxxxxx"; + + // 'in' + fb_01.open(name_01, std::ios_base::in); + VERIFY( fb_01.sgetc() != traits_type::eof() ); + VERIFY( fb_01.sbumpc() != traits_type::eof() ); + VERIFY( fb_01.snextc() != traits_type::eof() ); + VERIFY( fb_01.sgetn(buffer, sizeof(buffer)) == sizeof(buffer) ); + + fb_01.close(); + + VERIFY( fb_01.sgetc() == traits_type::eof() ); + VERIFY( fb_01.sbumpc() == traits_type::eof() ); + VERIFY( fb_01.snextc() == traits_type::eof() ); + VERIFY( fb_01.sgetn(buffer, sizeof(buffer)) == 0 ); + + // 'out' + fb_02.open(name_02, std::ios_base::out); + VERIFY( fb_02.sputc('T') != traits_type::eof() ); + VERIFY( fb_02.sputn(buffer, sizeof(buffer)) == sizeof(buffer) ); + + fb_02.close(); + + VERIFY( fb_02.sputc('T') == traits_type::eof() ); + VERIFY( fb_02.sputn(buffer, sizeof(buffer)) == 0 ); +} + +int +main() +{ + test_04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc new file mode 100644 index 000000000..9d2c647ca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc @@ -0,0 +1,108 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +// libstdc++/2913, libstdc++/4879 +// John Fardo , Brad Garcia +bool +test_04() +{ + using namespace __gnu_test; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo1"; + semaphore s1, s2; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + if (0 != mkfifo(name, S_IRWXU)) + { + std::cerr << "failed to create fifo" << std::endl; + exit(-1); + } + + int fval = fork(); + if (fval == -1) + { + std::cerr << "failed to fork" << std::endl; + unlink(name); + return false; + } + else if (fval == 0) + { + std::ifstream ifs(name); + s1.wait(); + ifs.close(); + s2.signal(); + exit(0); + } + + std::ofstream ofs(name); + s1.signal(); + s2.wait(); + ofs.put('t'); + + /* + * ISO/IED 14882:1998(E) 27.8.1.10.4 + * + * void close(); + * + * Effects: Calls rdbuf()->close() and, if that function fails + * (returns a null pointer), calls setstate(failbit)... + */ + ofs.close(); + if (!(ofs.rdstate() & std::ios::failbit)) + { + test = false; + VERIFY( test ); + } + + unlink(name); + + return test; +} + +int +main() +{ + return !test_04(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc new file mode 100644 index 000000000..25ae66b41 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc @@ -0,0 +1,106 @@ +// 2003-05-20 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// Test that upon filebuf::close() 27.8.1.1,3 is enforced. + +#include +#include + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +bool overflow_called; +bool underflow_called; +bool uflow_called; + +class Close_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + overflow_called = true; + return std::filebuf::overflow(c); + } + + int_type underflow() + { + underflow_called = true; + return std::filebuf::underflow(); + } + + int_type uflow() + { + uflow_called = true; + return std::filebuf::uflow(); + } +}; + +void test_05() +{ + bool test __attribute__((unused)) = true; + + Close_filebuf fb_01, fb_02; + char buffer[] = "xxxxxxxxxx"; + + // 'in' + fb_01.open(name_01, std::ios_base::in); + fb_01.sgetc(); + + fb_01.close(); + + underflow_called = false; + fb_01.sgetc(); + VERIFY( underflow_called == true ); + + uflow_called = false; + fb_01.sbumpc(); + VERIFY( uflow_called == true ); + + uflow_called = false; + fb_01.snextc(); + VERIFY( uflow_called == true ); + + uflow_called = false; + fb_01.sgetn(buffer, sizeof(buffer)); + VERIFY( uflow_called == true ); + + // 'out' + fb_02.open(name_02, std::ios_base::out); + + fb_02.close(); + + overflow_called = false; + fb_02.sputc('T'); + VERIFY( overflow_called == true ); + + overflow_called = false; + fb_02.sputn(buffer, sizeof(buffer)); + VERIFY( overflow_called == true ); +} + +int +main() +{ + test_05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc new file mode 100644 index 000000000..f2c5abc3e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc @@ -0,0 +1,89 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include +#include +#include +#include +#include +#include +#include + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include + +// libstdc++/9964 +bool test_07() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + semaphore s1, s2; + + const char* name = "tmp_fifo3"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + filebuf fbin; + fbin.open(name, ios_base::in); + s1.wait(); + fbin.close(); + s2.signal(); + exit(0); + } + + filebuf fb; + filebuf* ret = fb.open(name, ios_base::in | ios_base::out); + VERIFY( ret != 0 ); + VERIFY( fb.is_open() ); + s1.signal(); + s2.wait(); + fb.sputc('a'); + + ret = fb.close(); + VERIFY( ret != 0 ); + VERIFY( !fb.is_open() ); + + return test; +} + +int +main() +{ + return !test_07(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc new file mode 100644 index 000000000..85222f596 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc @@ -0,0 +1,78 @@ +// 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.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc new file mode 100644 index 000000000..eeade5812 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc @@ -0,0 +1,80 @@ +// 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.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.in_avail(); // showmanyc() should have no effect on close(). + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc new file mode 100644 index 000000000..417fbc2ce --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 27.8.1.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return codecvt_base::error; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should fail if codecvt::unshift() fails +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + wfilebuf* ret = fb.close(); + VERIFY( cvt->unshift_called ); + VERIFY( !ret ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc new file mode 100644 index 000000000..240417a93 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc @@ -0,0 +1,79 @@ +// 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.3 filebuf member functions + +#include +#include +#include + +class Cvt : public std::codecvt +{ +public: + mutable bool unshift_called; + + Cvt() + : unshift_called(false) + { } + +protected: + bool + do_always_noconv() const throw() + { return false; } + + int + do_encoding() const throw() + { return -1; } + + std::codecvt_base::result + do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const + { + unshift_called = true; + to_next = to; + return std::codecvt_base::ok; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} -- cgit v1.2.3