diff options
author | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-11-27 08:14:25 +0000 |
---|---|---|
committer | bkoz <bkoz@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-11-27 08:14:25 +0000 |
commit | 92fe9461fd7f8b4302153af00ec14585f7c06903 (patch) | |
tree | 27f6d0d3d427d9db5da892e2b7f7f741d945f41a /libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char | |
parent | 23d75d32f1390ef02a2c8288ab5f048a5c233020 (diff) | |
download | gcc-92fe9461fd7f8b4302153af00ec14585f7c06903.tar.gz |
2003-11-26 Benjamin Kosnik <bkoz@redhat.com>
PR libstdc++/9371
PR libstdc++/9546
PR libstdc++/10093
PR libstdc++/10095
* include/bits/basic_ios.h (basic_ios::setstate): Elide if goodbit.
(basic_ios::_M_setstate): Consolidate common error handling code.
* include/bits/basic_ios.tcc: Tweak.
* include/bits/fstream.tcc: Tweak.
* include/bits/istream.tcc: Use _M_setstate for common exception
handling. Move setstate calls after catch.
(basic_istream::tellg): Check for exceptions thrown by streambuf
virtual functions.
(basic_istream::seekg): Same.
* include/bits/ostream.tcc: Same, but for ostream.
(basic_ostream::flush): Check for exceptions thrown by streambuf
virtual functions.
(basic_istream::tellp): Same.
(basic_istream::seekp): Same.
* include/bits/locale_facets.tcc: Tweak.
* include/bits/streambuf.tcc: Tweak.
(__copy_streambufs): Propagate exceptions.
* testsuite/testsuite_io.h (fail_streambuf): New.
(fail_num_get): New.
(fail_num_put): New.
(facet_error): New.
(underflow_error): New.
(overflow_error): New.
(positioning_error): New.
* testsuite/27_io/basic_istream/exceptions/char/9561.cc: Tweak.
* testsuite/27_io/basic_istream/extractors_arithmetic/char/
exceptions_badbit_throw.cc, exceptions_failbit.cc,
exceptions_failbit_throw.cc: New.
* testsuite/27_io/basic_istream/extractors_other/char/
error_failbit.cc, exceptions_badbit_throw.cc,
exceptions_failbit_throw.cc, exceptions_null.cc: New.
* testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc:
New.
* testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc:
New.
* testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc:
New.
* testsuite/27_io/basic_ostream/inserters_arithmetic/char/
exceptions_badbit_throw.cc, exceptions_failbit_throw.cc: New.
* testsuite/27_io/basic_ostream/inserters_other/char/
error_failbit.cc, exceptions_badbit_throw.cc,
exceptions_failbit_throw.cc, exceptions_null.cc: New.
* testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc:
New.
* testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc:
New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@73979 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char')
4 files changed, 303 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc new file mode 100644 index 00000000000..ce47b6f3989 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test5() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + stream << &sbuf; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test7() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + __gnu_test::fail_streambuf bib; + + stream << &bib; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test5(); + test7(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc new file mode 100644 index 00000000000..13ff248940b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc @@ -0,0 +1,79 @@ +// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test13() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stream.exceptions(ios_base::badbit); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test15() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::badbit); + __gnu_test::fail_streambuf bib; + + try + { + stream << &bib; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test13(); + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc new file mode 100644 index 00000000000..5abaf92b804 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test9() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stream.exceptions(ios_base::failbit); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test11() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::failbit); + __gnu_test::fail_streambuf bib; + + try + { + stream << &bib; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test9(); + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc new file mode 100644 index 00000000000..3f2de4d683b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2003 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +using namespace std; + +void test1() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream << static_cast<streambuf*>(NULL); + VERIFY(stream.rdstate() & ios_base::badbit); +} + +void test3() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::badbit); + + try + { + stream << static_cast<streambuf*>(NULL); + VERIFY(false); + } + catch (ios_base::failure&) + { + } + + VERIFY(stream.rdstate() & ios_base::badbit); +} + +// libstdc++/9371 +int main() +{ + test1(); + test3(); + return 0; +} |