diff options
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_ostream')
122 files changed, 8106 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/2020.cc new file mode 100644 index 000000000..07fb7b82e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/2020.cc @@ -0,0 +1,55 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2009, 2010 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_ostream<__gnu_test::pod_ushort> gnu_ostr; + + try + { + gnu_ostr obj(0); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/cons/char/9827.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/char/9827.cc new file mode 100644 index 000000000..c5283236b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/char/9827.cc @@ -0,0 +1,45 @@ +// 2003-02-24 Petur Runolfsson <peturr02 at ru dot is> + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9827 +class Buf : public std::streambuf +{ +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + Buf buf; + ostream stream(&buf); + + stream << 1; + VERIFY(!stream.good()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/cons/wchar_t/9827.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/wchar_t/9827.cc new file mode 100644 index 000000000..8397c690b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/wchar_t/9827.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9827 +class Buf : public std::wstreambuf +{ +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + Buf buf; + wostream stream(&buf); + + stream << 1; + VERIFY(!stream.good()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/endl/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/char/1.cc new file mode 100644 index 000000000..7ebc2fe62 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/char/1.cc @@ -0,0 +1,54 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::string str01(" santa barbara "); + std::string str04; + std::string str05; + + std::ostringstream oss01(str01); + std::ostringstream oss02; + typedef std::ostringstream::traits_type traits_type; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::endl; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::endl; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/endl/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/wchar_t/1.cc new file mode 100644 index 000000000..6a8b16373 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/wchar_t/1.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::wstring str01(L" santa barbara "); + std::wstring str04; + std::wstring str05; + + std::wostringstream oss01(str01); + std::wostringstream oss02; + typedef std::wostringstream::traits_type traits_type; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::endl; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::endl; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/1.cc new file mode 100644 index 000000000..4c2af14b2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/1.cc @@ -0,0 +1,54 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::string str01(" santa barbara "); + std::string str04; + std::string str05; + + std::ostringstream oss01(str01); + std::ostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::ends; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::ends; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); + VERIFY( str05[0] == char() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/2.cc new file mode 100644 index 000000000..c2e4c614a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/2.cc @@ -0,0 +1,63 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// based vaguely on this: +// http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00109.html +void test02() +{ + using namespace std; + typedef ostringstream::int_type int_type; + + bool test __attribute__((unused)) = true; + ostringstream osst_01; + const string str_00("herbie_hancock"); + int_type len1 = str_00.size(); + osst_01 << str_00; + VERIFY( static_cast<int_type>(osst_01.str().size()) == len1 ); + + osst_01 << ends; + + const string str_01("speak like a child"); + int_type len2 = str_01.size(); + osst_01 << str_01; + int_type len3 = osst_01.str().size(); + VERIFY( len1 < len3 ); + VERIFY( len3 == len1 + len2 + 1 ); + + osst_01 << ends; + + const string str_02("+ inventions and dimensions"); + int_type len4 = str_02.size(); + osst_01 << str_02; + int_type len5 = osst_01.str().size(); + VERIFY( len3 < len5 ); + VERIFY( len5 == len3 + len4 + 1 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/1.cc new file mode 100644 index 000000000..118488132 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/1.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::wstring str01(L" santa barbara "); + std::wstring str04; + std::wstring str05; + + std::wostringstream oss01(str01); + std::wostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::ends; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::ends; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); + VERIFY( str05[0] == wchar_t() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/2.cc new file mode 100644 index 000000000..d05c105c0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/2.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// based vaguely on this: +// http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00109.html +void test02() +{ + using namespace std; + typedef wostringstream::int_type int_type; + + bool test __attribute__((unused)) = true; + wostringstream osst_01; + const wstring str_00(L"herbie_hancock"); + int_type len1 = str_00.size(); + osst_01 << str_00; + VERIFY( static_cast<int_type>(osst_01.str().size()) == len1 ); + + osst_01 << ends; + + const wstring str_01(L"speak like a child"); + int_type len2 = str_01.size(); + osst_01 << str_01; + int_type len3 = osst_01.str().size(); + VERIFY( len1 < len3 ); + VERIFY( len3 == len1 + len2 + 1 ); + + osst_01 << ends; + + const wstring str_02(L"+ inventions and dimensions"); + int_type len4 = str_02.size(); + osst_01 << str_02; + int_type len5 = osst_01.str().size(); + VERIFY( len3 < len5 ); + VERIFY( len5 == len3 + len4 + 1 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/char/9561.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/char/9561.cc new file mode 100644 index 000000000..b7cf707e9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/char/9561.cc @@ -0,0 +1,69 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9561 +struct foobar: std::exception { }; + +struct buf: std::streambuf +{ + virtual int_type + overflow(int_type) + { + throw foobar(); + return int_type(); + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + buf b; + std::ostream strm (&b); + strm.exceptions(std::ios::badbit); + + try + { + strm << std::endl; + } + catch(foobar) + { + // strm should throw foobar and not do anything else + VERIFY(strm.bad()); + return; + } + catch(...) + { + VERIFY( false ); + return; + } + + VERIFY( false ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc new file mode 100644 index 000000000..c528eccab --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9561 +struct foobar: std::exception { }; + +struct buf: std::wstreambuf +{ + virtual int_type + overflow(int_type) + { + throw foobar(); + return int_type(); + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + buf b; + std::wostream strm(&b); + strm.exceptions(std::wios::badbit); + + try + { + strm << std::endl; + } + catch(foobar) + { + // strm should throw foobar and not do anything else + VERIFY(strm.bad()); + return; + } + catch(...) + { + VERIFY( false ); + return; + } + VERIFY( false ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/1.cc new file mode 100644 index 000000000..810c92084 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/1.cc @@ -0,0 +1,53 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::string str01(" santa barbara "); + std::string str04; + std::string str05; + + std::ostringstream oss01(str01); + std::ostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& flush(basic_ostream<_Char, _Traits>& os) + oss01.flush(); + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02.flush(); + str05 = oss02.str(); + VERIFY( str05.size() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/2.cc new file mode 100644 index 000000000..c830a39f1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/2.cc @@ -0,0 +1,65 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::flush() does not behave as an unformatted output function. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_streambuf buf; + std::ostream os(&buf); + + __gnu_test::sync_streambuf buf_tie; + std::ostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + os.flush(); + + VERIFY( os.good() ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); + + // os.rdbuf()->pubsync() should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + os.flush(); + + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); +} + +int main() +{ + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..0a494c552 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.flush(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/1.cc new file mode 100644 index 000000000..f6d3fb71d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/1.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::wstring str01(L" santa barbara "); + std::wstring str04; + std::wstring str05; + + std::wostringstream oss01(str01); + std::wostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& flush(basic_ostream<_Char, _Traits>& os) + oss01.flush(); + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02.flush(); + str05 = oss02.str(); + VERIFY( str05.size() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc new file mode 100644 index 000000000..a6d235ae1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::flush() does not behave as an unformatted output function. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_wstreambuf buf; + std::wostream os(&buf); + + __gnu_test::sync_wstreambuf buf_tie; + std::wostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + os.flush(); + + VERIFY( os.good() ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); + + // os.rdbuf()->pubsync() should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + os.flush(); + + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); +} + +int main() +{ + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..d06858208 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.flush(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc new file mode 100644 index 000000000..35fe23287 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc @@ -0,0 +1,190 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +using namespace std; + +#ifndef _GLIBCXX_ASSERT +# define TEST_NUMPUT_VERBOSE 1 +#endif + +struct _TestCase +{ + double val; + + int precision; + int width; + char decimal; + char fill; + + bool fixed; + bool scientific; + bool showpos; + bool showpoint; + bool uppercase; + bool internal; + bool left; + bool right; + + const char* result; +}; + +static bool T=true; +static bool F=false; + +static _TestCase testcases[] = +{ + // standard output (no formatting applied) + { 1.2, 6,0,'.',' ', F,F,F,F,F,F,F,F, "1.2" }, + { 54, 6,0,'.',' ', F,F,F,F,F,F,F,F, "54" }, + { -.012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-0.012" }, + { -.00000012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-1.2e-07" }, + + // fixed formatting + { 10.2345, 0,0,'.',' ', T,F,F,F,F,F,F,F, "10" }, + { 10.2345, 0,0,'.',' ', T,F,F,T,F,F,F,F, "10." }, + { 10.2345, 1,0,'.',' ', T,F,F,F,F,F,F,F, "10.2" }, + { 10.2345, 4,0,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 6,0,'.',' ', T,F,T,F,F,F,F,F, "+10.234500" }, + { -10.2345, 6,0,'.',' ', T,F,F,F,F,F,F,F, "-10.234500" }, + { -10.2345, 6,0,',',' ', T,F,F,F,F,F,F,F, "-10,234500" }, + + // fixed formatting with width + { 10.2345, 4,5,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 4,6,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 4,7,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 4,8,'.',' ', T,F,F,F,F,F,F,F, " 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,F, " 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,T,F, "10.2345 " }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,T, " 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, " 10.2345" }, + { -10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, "- 10.2345" }, + { -10.2345, 4,10,'.','A', T,F,F,F,F,T,F,F, "-AA10.2345" }, + { 10.2345, 4,10,'.','#', T,F,T,F,F,T,F,F, "+##10.2345" }, + + // scientific formatting + { 1.23e+12, 1,0,'.',' ', F,T,F,F,F,F,F,F, "1.2e+12" }, + { 1.23e+12, 1,0,'.',' ', F,T,F,F,T,F,F,F, "1.2E+12" }, + { 1.23e+12, 2,0,'.',' ', F,T,F,F,F,F,F,F, "1.23e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "1.230e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,T,F,F,F,F,F, "+1.230e+12" }, + { -1.23e-12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "-1.230e-12" }, + { 1.23e+12, 3,0,',',' ', F,T,F,F,F,F,F,F, "1,230e+12" }, +}; + +template<typename _CharT> +class testpunct : public numpunct<_CharT> +{ +public: + typedef _CharT char_type; + const char_type dchar; + + explicit + testpunct(char_type decimal_char) : numpunct<_CharT>(), dchar(decimal_char) + { } + +protected: + char_type + do_decimal_point() const + { return dchar; } + + char_type + do_thousands_sep() const + { return ','; } + + string + do_grouping() const + { return string(); } +}; + +template<typename _CharT> +void apply_formatting(const _TestCase & tc, basic_ostream<_CharT> & os) +{ + os.precision(tc.precision); + os.width(tc.width); + os.fill(static_cast<_CharT>(tc.fill)); + if (tc.fixed) + os.setf(ios::fixed); + if (tc.scientific) + os.setf(ios::scientific); + if (tc.showpos) + os.setf(ios::showpos); + if (tc.showpoint) + os.setf(ios::showpoint); + if (tc.uppercase) + os.setf(ios::uppercase); + if (tc.internal) + os.setf(ios::internal); + if (tc.left) + os.setf(ios::left); + if (tc.right) + os.setf(ios::right); +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + for (std::size_t j = 0; j<sizeof(testcases)/sizeof(testcases[0]); j++) + { + _TestCase & tc = testcases[j]; +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << tc.result << endl; +#endif + // test double with char type + { + testpunct<char>* __tp = new testpunct<char>(tc.decimal); + ostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << tc.val; +#ifdef TEST_NUMPUT_VERBOSE + cout << j << "result 1: " << os.str() << endl; +#endif + VERIFY( os && os.str() == tc.result ); + } + // test long double with char type + { + testpunct<char>* __tp = new testpunct<char>(tc.decimal); + ostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << (long double)tc.val; +#ifdef TEST_NUMPUT_VERBOSE + cout << j << "result 2: " << os.str() << endl; +#endif + VERIFY( os && os.str() == tc.result ); + } + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/2.cc new file mode 100644 index 000000000..d0ffa2c2a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/2.cc @@ -0,0 +1,57 @@ +// { dg-require-namedlocale "de_DE" } + +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <locale> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = 3.5e230; + + ostringstream os2; + os2.precision(3); + os2.setf(ios::fixed); + + // Check it can be done in a locale with grouping on. + locale loc2 = locale("de_DE"); + os2.imbue(loc2); + os2 << fixed << setprecision(3) << val2 << endl; + os2 << endl; + os2 << fixed << setprecision(1) << val2 << endl; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc new file mode 100644 index 000000000..88b55ad9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc @@ -0,0 +1,37 @@ +// 2005-09-15 Janis Johnson <janis187@us.ibm.com> + +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do compile } + +// libstdc++/23871 + +#include <iostream> + +class mytest { +public: + mytest (int); + unsigned char operator|| (const mytest&) const; + friend unsigned char operator|| (const int&, const mytest&); +}; + +inline unsigned char operator|| (const int& lhs, const mytest& rhs) +{ + std::cout << 1 << std::endl; + return (mytest)lhs || rhs; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/3.cc new file mode 100644 index 000000000..fd1d14955 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/3.cc @@ -0,0 +1,68 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +template<typename T> +bool +test03_check(T n) +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf strbuf; + ostream o(&strbuf); + const char *expect; + + if (numeric_limits<T>::digits + 1 == 16) + expect = "177777 ffff"; + else if (numeric_limits<T>::digits + 1 == 32) + expect = "37777777777 ffffffff"; + else if (numeric_limits<T>::digits + 1 == 64) + expect = "1777777777777777777777 ffffffffffffffff"; + else + expect = "wow, you've got some big numbers here"; + + o << oct << n << ' ' << hex << n; + VERIFY ( strbuf.str() == expect ); + + return test; +} + +void +test03() +{ + short s = -1; + int i = -1; + long l = -1; + + test03_check (s); + test03_check (i); + test03_check (l); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/31031.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/31031.cc new file mode 100644 index 000000000..1f34663a9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/31031.cc @@ -0,0 +1,51 @@ +// { dg-do compile } + +// 2007-03-03 Paolo Carlini <pcarlini@suse.de> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <sstream> + +class MyClass +{ + double x; + +public: + MyClass(double X) : x(X) {} + friend bool operator&&(int i, const MyClass& Z); +}; + +inline bool +operator&&(int i, const MyClass& Z) +{ return int(Z.x) == i; } + +// libstdc++/31031 +void test01() +{ + int k =3; + MyClass X(3.1); + std::ostringstream oss; + + oss << (k && X); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4.cc new file mode 100644 index 000000000..a2b686ae7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4.cc @@ -0,0 +1,50 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iomanip> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3655 +int +test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf strbuf1, strbuf2; + ostream o1(&strbuf1), o2(&strbuf2); + + o1 << hex << showbase << setw(6) << internal << 0xff; + VERIFY( strbuf1.str() == "0x ff" ); + + // ... vs internal-adjusted const char*-type objects + o2 << hex << showbase << setw(6) << internal << "0xff"; + VERIFY( strbuf2.str() == " 0xff" ); + + return 0; +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4402.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4402.cc new file mode 100644 index 000000000..fe1c3b6f2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4402.cc @@ -0,0 +1,74 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2000, 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 +// <http://www.gnu.org/licenses/>. + +#include <cstdio> // for sprintf +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // make sure we can output a very long float + long double val = numeric_limits<long double>::max(); + int prec = numeric_limits<long double>::digits10; + + ostringstream os; + os.precision(prec); + os.setf(ios::scientific); + os << val; + + char largebuf[512]; + sprintf(largebuf, "%.*Le", prec, val); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os.str() << endl; +#endif + VERIFY( os && os.str() == largebuf ); + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = numeric_limits<double>::max(); + + ostringstream os2; + os2.precision(3); + os2.setf(ios::fixed); + os2 << val2; + + sprintf(largebuf, "%.*f", 3, val2); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os2.str() << endl; +#endif + VERIFY( os2 && os2.str() == largebuf ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/5.cc new file mode 100644 index 000000000..ba0e6a390 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/5.cc @@ -0,0 +1,49 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + double pi = 3.14159265358979323846; + ostringstream ostr; + ostr.precision(20); + ostr << pi; + string sval = ostr.str(); + istringstream istr (sval); + double d; + istr >> d; + VERIFY( abs(pi-d)/pi < DBL_EPSILON ); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/6.cc new file mode 100644 index 000000000..2a3d1542b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/6.cc @@ -0,0 +1,54 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { xfail lax_strtofp } } + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/9151 +void +test06() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + int prec = numeric_limits<double>::digits10 + 2; + double oval = numeric_limits<double>::min(); + + stringstream ostr; + ostr.precision(prec); + ostr << oval; + string sval = ostr.str(); + istringstream istr (sval); + double ival; + istr >> ival; + VERIFY( abs(oval-ival)/oval < DBL_EPSILON ); +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc new file mode 100644 index 000000000..d3e3213dd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc @@ -0,0 +1,67 @@ +// 2005-07-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.2 Arithmetic inserters + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringstream ostr1, ostr2, ostr3, ostr4; + + ostr1.setf(ios_base::oct); + ostr1.setf(ios_base::hex); + + short s = -1; + ostr1 << s; + VERIFY( ostr1.str() == "-1" ); + + ostr2.setf(ios_base::oct); + ostr2.setf(ios_base::hex); + + int i = -1; + ostr2 << i; + VERIFY( ostr2.str() == "-1" ); + + ostr3.setf(ios_base::oct); + ostr3.setf(ios_base::hex); + + long l = -1; + ostr3 << l; + VERIFY( ostr3.str() == "-1" ); + +#ifdef _GLIBCXX_USE_LONG_LONG + ostr4.setf(ios_base::oct); + ostr4.setf(ios_base::hex); + + long long ll = -1LL; + ostr4 << ll; + VERIFY( ostr4.str() == "-1" ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/9555-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/9555-oa.cc new file mode 100644 index 000000000..ed1e34b77 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/9555-oa.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::ostream os(&b); + os.exceptions(std::ios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..6c917ad84 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc @@ -0,0 +1,73 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_char); + ostringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i = T(); + stream << i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc new file mode 100644 index 000000000..19b1fcd84 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_char); + ostringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i = T(); + stream << i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/pod/23875.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/pod/23875.cc new file mode 100644 index 000000000..ac4042194 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/pod/23875.cc @@ -0,0 +1,84 @@ +// 2005-09-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.2 Arithmetic inserters + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +bool test __attribute__((unused)) = true; +using __gnu_test::pod_ushort; + +namespace std +{ + template<> + basic_ostream<pod_ushort>& + basic_ostream<pod_ushort>:: + operator<<(long) + { + VERIFY( false ); + return *this; + } + + template<> + basic_ostream<pod_ushort>& + basic_ostream<pod_ushort>:: + operator<<(unsigned long) + { + VERIFY( false ); + return *this; + } + + template<> + basic_ostream<pod_ushort>& + basic_ostream<pod_ushort>:: + operator<<(double) + { + VERIFY( false ); + return *this; + } +} + +// libstdc++/23875 +void test01() +{ + std::basic_ostringstream<pod_ushort> ostr; + + short s = 1; + ostr << s; + + unsigned short us = 1; + ostr << us; + + int i = 1; + ostr << i; + + unsigned int ui = 1; + ostr << ui; + + float f = 1.0f; + ostr << f; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc new file mode 100644 index 000000000..0108fd067 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc @@ -0,0 +1,185 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +using namespace std; + +#ifndef _GLIBCXX_ASSERT +# define TEST_NUMPUT_VERBOSE 1 +#endif + +struct _TestCase +{ + double val; + + int precision; + int width; + char decimal; + char fill; + + bool fixed; + bool scientific; + bool showpos; + bool showpoint; + bool uppercase; + bool internal; + bool left; + bool right; + + const char* result; + const wchar_t* wresult; +}; + +static bool T=true; +static bool F=false; + +static _TestCase testcases[] = +{ + // standard output (no formatting applied) 1-4 + { 1.2, 6,0,'.',' ', F,F,F,F,F,F,F,F, "1.2",L"1.2" }, + { 54, 6,0,'.',' ', F,F,F,F,F,F,F,F, "54",L"54" }, + { -.012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-0.012",L"-0.012" }, + { -.00000012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-1.2e-07",L"-1.2e-07" }, + + // fixed formatting 5-11 + { 10.2345, 0,0,'.',' ', T,F,F,F,F,F,F,F, "10",L"10" }, + { 10.2345, 0,0,'.',' ', T,F,F,T,F,F,F,F, "10.",L"10." }, + { 10.2345, 1,0,'.',' ', T,F,F,F,F,F,F,F, "10.2",L"10.2" }, + { 10.2345, 4,0,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 6,0,'.',' ', T,F,T,F,F,F,F,F, "+10.234500",L"+10.234500" }, + { -10.2345, 6,0,'.',' ', T,F,F,F,F,F,F,F, "-10.234500",L"-10.234500" }, + { -10.2345, 6,0,',',' ', T,F,F,F,F,F,F,F, "-10,234500",L"-10,234500" }, + + // fixed formatting with width 12-22 + { 10.2345, 4,5,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 4,6,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 4,7,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 4,8,'.',' ', T,F,F,F,F,F,F,F, " 10.2345",L" 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,F, " 10.2345",L" 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,T,F, "10.2345 ",L"10.2345 " }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,T, " 10.2345",L" 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, " 10.2345",L" 10.2345" }, + { -10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, "- 10.2345",L"- 10.2345" }, + { -10.2345, 4,10,'.','A', T,F,F,F,F,T,F,F, "-AA10.2345",L"-AA10.2345" }, + { 10.2345, 4,10,'.','#', T,F,T,F,F,T,F,F, "+##10.2345",L"+##10.2345" }, + + // scientific formatting 23-29 + { 1.23e+12, 1,0,'.',' ', F,T,F,F,F,F,F,F, "1.2e+12",L"1.2e+12" }, + { 1.23e+12, 1,0,'.',' ', F,T,F,F,T,F,F,F, "1.2E+12",L"1.2E+12" }, + { 1.23e+12, 2,0,'.',' ', F,T,F,F,F,F,F,F, "1.23e+12",L"1.23e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "1.230e+12",L"1.230e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,T,F,F,F,F,F, "+1.230e+12",L"+1.230e+12" }, + { -1.23e-12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "-1.230e-12",L"-1.230e-12" }, + { 1.23e+12, 3,0,',',' ', F,T,F,F,F,F,F,F, "1,230e+12",L"1,230e+12" }, +}; + +template<typename _CharT> +class testpunct : public numpunct<_CharT> +{ +public: + typedef _CharT char_type; + const char_type dchar; + + explicit + testpunct(char_type decimal_char) : numpunct<_CharT>(), dchar(decimal_char) + { } + +protected: + char_type + do_decimal_point() const + { return dchar; } + + char_type + do_thousands_sep() const + { return ','; } + + string + do_grouping() const + { return string(); } +}; + +template<typename _CharT> +void apply_formatting(const _TestCase & tc, basic_ostream<_CharT> & os) +{ + os.precision(tc.precision); + os.width(tc.width); + os.fill(static_cast<_CharT>(tc.fill)); + if (tc.fixed) + os.setf(ios::fixed); + if (tc.scientific) + os.setf(ios::scientific); + if (tc.showpos) + os.setf(ios::showpos); + if (tc.showpoint) + os.setf(ios::showpoint); + if (tc.uppercase) + os.setf(ios::uppercase); + if (tc.internal) + os.setf(ios::internal); + if (tc.left) + os.setf(ios::left); + if (tc.right) + os.setf(ios::right); +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + for (std::size_t j = 0; j<sizeof(testcases)/sizeof(testcases[0]); j++) + { + _TestCase & tc = testcases[j]; +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << tc.result << endl; +#endif + // test double with wchar_t type + { + testpunct<wchar_t>* __tp = new testpunct<wchar_t>(tc.decimal); + wostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << tc.val; + VERIFY( os && os.str() == tc.wresult ); + } + // test long double with wchar_t type + { + testpunct<wchar_t>* __tp = new testpunct<wchar_t>(tc.decimal); + wostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << (long double)tc.val; + VERIFY( os && os.str() == tc.wresult ); + } + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc new file mode 100644 index 000000000..e786f7589 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc @@ -0,0 +1,54 @@ +// { dg-require-namedlocale "de_DE" } + +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <locale> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = 3.5e230; + + wostringstream os2; + os2.precision(3); + os2.setf(wios::fixed); + + // Check it can be done in a locale with grouping on. + locale loc2 = locale("de_DE"); + os2.imbue(loc2); + os2 << fixed << setprecision(3) << val2 << endl; + os2 << endl; + os2 << fixed << setprecision(1) << val2 << endl; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc new file mode 100644 index 000000000..436fae353 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +template<typename T> +bool +test03_check(T n) +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf strbuf; + wostream o(&strbuf); + const wchar_t *expect; + + if (numeric_limits<T>::digits + 1 == 16) + expect = L"177777 ffff"; + else if (numeric_limits<T>::digits + 1 == 32) + expect = L"37777777777 ffffffff"; + else if (numeric_limits<T>::digits + 1 == 64) + expect = L"1777777777777777777777 ffffffffffffffff"; + else + expect = L"wow, you've got some big numbers here"; + + o << oct << n << L' ' << hex << n; + VERIFY ( strbuf.str() == expect ); + + return test; +} + +void +test03() +{ + short s = -1; + int i = -1; + long l = -1; + + test03_check(s); + test03_check(i); + test03_check(l); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/31031.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/31031.cc new file mode 100644 index 000000000..bb5aedadd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/31031.cc @@ -0,0 +1,51 @@ +// { dg-do compile } + +// 2007-03-03 Paolo Carlini <pcarlini@suse.de> +// +// 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 +// <http://www.gnu.org/licenses/>. + +#include <sstream> + +class MyClass +{ + double x; + +public: + MyClass(double X) : x(X) {} + friend bool operator&&(int i, const MyClass& Z); +}; + +inline bool +operator&&(int i, const MyClass& Z) +{ return int(Z.x) == i; } + +// libstdc++/31031 +void test01() +{ + int k =3; + MyClass X(3.1); + std::wostringstream oss; + + oss << (k && X); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc new file mode 100644 index 000000000..9592d9482 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iomanip> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3655 +int +test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf strbuf1, strbuf2; + wostream o1(&strbuf1), o2(&strbuf2); + + o1 << hex << showbase << setw(6) << internal << 0xff; + VERIFY( strbuf1.str() == L"0x ff" ); + + // ... vs internal-adjusted const char*-type objects + o2 << hex << showbase << setw(6) << internal << L"0xff"; + VERIFY( strbuf2.str() == L" 0xff" ); + + return 0; +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc new file mode 100644 index 000000000..54b339e99 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc @@ -0,0 +1,72 @@ +// { dg-require-swprintf "" } + +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <cstdio> // for swprintf +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // make sure we can output a very long float + long double val = numeric_limits<long double>::max(); + int prec = numeric_limits<long double>::digits10; + + wostringstream os; + os.precision(prec); + os.setf(wios::scientific); + os << val; + + wchar_t largebuf[512]; + swprintf(largebuf, 512, L"%.*Le", prec, val); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os.str() << endl; +#endif + VERIFY( os && os.str() == largebuf ); + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = numeric_limits<double>::max(); + + wostringstream os2; + os2.precision(3); + os2.setf(wios::fixed); + os2 << val2; + + swprintf(largebuf, 512, L"%.*f", 3, val2); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os2.str() << endl; +#endif + VERIFY( os2 && os2.str() == largebuf ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc new file mode 100644 index 000000000..d48fee3b9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + double pi = 3.14159265358979323846; + wostringstream ostr; + ostr.precision(20); + ostr << pi; + wstring sval = ostr.str(); + wistringstream istr(sval); + double d; + istr >> d; + VERIFY( abs(pi-d)/pi < DBL_EPSILON ); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc new file mode 100644 index 000000000..96f34ccb5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-do run { xfail lax_strtofp } } + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/9151 +void +test06() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + int prec = numeric_limits<double>::digits10 + 2; + double oval = numeric_limits<double>::min(); + + wstringstream ostr; + ostr.precision(prec); + ostr << oval; + wstring sval = ostr.str(); + wistringstream istr(sval); + double ival; + istr >> ival; + VERIFY( abs(oval-ival)/oval < DBL_EPSILON ); +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc new file mode 100644 index 000000000..41e230ca7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc @@ -0,0 +1,67 @@ +// 2005-07-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.2 Arithmetic inserters + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringstream ostr1, ostr2, ostr3, ostr4; + + ostr1.setf(ios_base::oct); + ostr1.setf(ios_base::hex); + + short s = -1; + ostr1 << s; + VERIFY( ostr1.str() == L"-1" ); + + ostr2.setf(ios_base::oct); + ostr2.setf(ios_base::hex); + + int i = -1; + ostr2 << i; + VERIFY( ostr2.str() == L"-1" ); + + ostr3.setf(ios_base::oct); + ostr3.setf(ios_base::hex); + + long l = -1; + ostr3 << l; + VERIFY( ostr3.str() == L"-1" ); + +#ifdef _GLIBCXX_USE_LONG_LONG + ostr4.setf(ios_base::oct); + ostr4.setf(ios_base::hex); + + long long ll = -1LL; + ostr4 << ll; + VERIFY( ostr4.str() == L"-1" ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc new file mode 100644 index 000000000..0acd426a2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wostream os(&b); + os.exceptions(std::wios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..86b0884da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_wchar_t); + wostringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i = T(); + stream << i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..1cf29cba4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_wchar_t); + wostringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i = T(); + stream << i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/1.cc new file mode 100644 index 000000000..926b68bc7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/1.cc @@ -0,0 +1,57 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// ofstream +void test01() +{ + std::string str01; + const int size = 1000; + const char name_02[] = "ostream_inserter_char-1.txt"; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += '1'; + str01 += '2'; + str01 += '3'; + str01 += '4'; + str01 += '5'; + str01 += '6'; + str01 += '7'; + str01 += '8'; + str01 += '9'; + str01 += '\n'; + } + std::ofstream f(name_02); + + f << str01; + f.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc new file mode 100644 index 000000000..aeec2d51c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, char) +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream oss_01; + + oss_01.width(-60); + oss_01 << 'C'; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == "C" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc new file mode 100644 index 000000000..80ef77595 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream<char, _Traits>&, const char*) +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream oss_01; + + oss_01.width(-60); + oss_01 << "Consoli"; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == "Consoli" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc new file mode 100644 index 000000000..43e1e0db0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, const basic_string&) +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream oss_01; + + oss_01.width(-60); + oss_01 << std::string("Consoli"); + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == "Consoli" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/2.cc new file mode 100644 index 000000000..988da4491 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/2.cc @@ -0,0 +1,67 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream width() != zero +// left +void +test02(void) +{ + bool test __attribute__((unused)) = true; + std::string tmp; + + std::string str01 = ""; + std::ostringstream oss01; + oss01.width(5); + oss01.fill('0'); + oss01.flags(std::ios_base::left); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == "00000" ); + + std::string str02 = "1"; + std::ostringstream oss02; + oss02.width(5); + oss02.fill('0'); + oss02.flags(std::ios_base::left); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == "10000" ); + + std::string str03 = "909909"; + std::ostringstream oss03; + oss03.width(5); + oss03.fill('0'); + oss03.flags(std::ios_base::left); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == "909909" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc new file mode 100644 index 000000000..0d1c2f483 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc @@ -0,0 +1,53 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-DWIDTH=200000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 20000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << 'a'; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == string::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc new file mode 100644 index 000000000..fe80c76ba --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc @@ -0,0 +1,54 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-DWIDTH=200000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 20000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == string::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/3.cc new file mode 100644 index 000000000..87e299db5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/3.cc @@ -0,0 +1,66 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// width() != zero +// right +void test03(void) +{ + bool test __attribute__((unused)) = true; + std::string tmp; + + std::string str01 = ""; + std::ostringstream oss01; + oss01.width(5); + oss01.fill('0'); + oss01.flags(std::ios_base::right); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == "00000" ); + + std::string str02 = "1"; + std::ostringstream oss02; + oss02.width(5); + oss02.fill('0'); + oss02.flags(std::ios_base::right); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == "00001" ); + + std::string str03 = "909909"; + std::ostringstream oss03; + oss03.width(5); + oss03.fill('0'); + oss03.flags(std::ios_base::right); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == "909909" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/4.cc new file mode 100644 index 000000000..5ec21367b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/4.cc @@ -0,0 +1,54 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2005, 2009, 2010 +// Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// stringstream and large strings +void +test04() +{ + bool test __attribute__((unused)) = true; + std::string str_01; + std::string str_tmp; + const int i_max=250; + + std::ostringstream oss_02(str_01, std::ios_base::out); + + // template<_CharT, _Traits> + // basic_ostream& operator<<(ostream&, const char*) + for (int i = 0; i < i_max; ++i) + oss_02 << "Test: " << i << std::endl; + str_tmp = oss_02.str(); + VERIFY( !oss_02.bad() ); + VERIFY( oss_02.good() ); + VERIFY( str_tmp != str_01 ); + VERIFY( str_tmp.size() == 2390 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/5.cc new file mode 100644 index 000000000..6b6cbb38d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/5.cc @@ -0,0 +1,76 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and large strings number 2 +void +test05() +{ + bool test __attribute__((unused)) = true; + std::string str05, str10; + + typedef std::ostream::pos_type pos_type; + typedef std::ostream::off_type off_type; + std::string str01; + const int size = 1000; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += '1'; + str01 += '2'; + str01 += '3'; + str01 += '4'; + str01 += '5'; + str01 += '6'; + str01 += '7'; + str01 += '8'; + str01 += '9'; + str01 += '\n'; + } + + // test 1: out + std::ostringstream sstr01(str01, std::ios_base::out); + std::ostringstream sstr02; + sstr02 << str01; + str05 = sstr01.str(); + str10 = sstr02.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); + + // test 2: in | out + std::ostringstream sstr04(str01, std::ios_base::out | std::ios_base::in); + std::ostringstream sstr05(std::ios_base::in | std::ios_base::out); + sstr05 << str01; + str05 = sstr04.str(); + str10 = sstr05.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/6.cc new file mode 100644 index 000000000..25aad8a04 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/6.cc @@ -0,0 +1,57 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and positioning, multiple writes +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00326.html +void test06() +{ + bool test __attribute__((unused)) = true; + const char carray01[] = "mos def & talib kweli are black star"; + + // normal + std::ostringstream ostr1("mos def"); + VERIFY( ostr1.str() == "mos def" ); + ostr1 << " & talib kweli"; // should overwrite first part of buffer + VERIFY( ostr1.str() == " & talib kweli" ); + ostr1 << " are black star"; // should append to string from above + VERIFY( ostr1.str() != carray01 ); + VERIFY( ostr1.str() == " & talib kweli are black star" ); + + // appending + std::ostringstream ostr2("blackalicious", + std::ios_base::out | std::ios_base::ate); + VERIFY( ostr2.str() == "blackalicious" ); + ostr2 << " NIA "; // should not overwrite first part of buffer + VERIFY( ostr2.str() == "blackalicious NIA " ); + ostr2 << "4: deception (5:19)"; // should append to full string from above + VERIFY( ostr2.str() == "blackalicious NIA 4: deception (5:19)" ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/8.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/8.cc new file mode 100644 index 000000000..f38e2e703 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/8.cc @@ -0,0 +1,47 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test08() +{ + bool test __attribute__((unused)) = true; + char* pt = 0; + + // 1 + std::ostringstream oss; + oss << pt; + VERIFY( oss.bad() ); + VERIFY( oss.str().size() == 0 ); + + oss.clear(); + oss << ""; + VERIFY( oss.good() ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/9555-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/9555-oc.cc new file mode 100644 index 000000000..b46b2aede --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/9555-oc.cc @@ -0,0 +1,69 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::ostream os(&b); + os.exceptions(std::ios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + char c = 'a'; + unsigned char uc = 'a'; + signed char sc = 'a'; + const char* ccp = "governor ann richards"; + const signed char* cscp = reinterpret_cast<const signed char*>(ccp); + const unsigned char* cucp = reinterpret_cast<const unsigned char*>(ccp); + + testthrow(c); + testthrow(uc); + testthrow(sc); + testthrow(ccp); + testthrow(cscp); + testthrow(cucp); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/1.cc new file mode 100644 index 000000000..863590677 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/1.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// ofstream +void test01() +{ + std::wstring str01; + const int size = 1000; + const char name_02[] = "wostream_inserter_char-1.txt"; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += L'1'; + str01 += L'2'; + str01 += L'3'; + str01 += L'4'; + str01 += L'5'; + str01 += L'6'; + str01 += L'7'; + str01 += L'8'; + str01 += L'9'; + str01 += L'\n'; + } + std::wofstream f(name_02); + + f << str01; + f.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc new file mode 100644 index 000000000..8fd1d1167 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, _CharT) +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream oss_01; + + oss_01.width(-60); + oss_01 << L'C'; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == L"C" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc new file mode 100644 index 000000000..64e630302 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, const _CharT*) +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream oss_01; + + oss_01.width(-60); + oss_01 << L"Consoli"; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == L"Consoli" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc new file mode 100644 index 000000000..783027d0e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream<_CharT, _Traits>&, const char*) +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream oss_01; + + oss_01.width(-60); + oss_01 << "Consoli"; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == L"Consoli" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/2.cc new file mode 100644 index 000000000..361e82938 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/2.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream width() != zero +// left +void +test02(void) +{ + bool test __attribute__((unused)) = true; + std::wstring tmp; + + std::wstring str01 = L""; + std::wostringstream oss01; + oss01.width(5); + oss01.fill(L'0'); + oss01.flags(std::ios_base::left); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == L"00000" ); + + std::wstring str02 = L"1"; + std::wostringstream oss02; + oss02.width(5); + oss02.fill(L'0'); + oss02.flags(std::ios_base::left); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == L"10000" ); + + std::wstring str03 = L"909909"; + std::wostringstream oss03; + oss03.width(5); + oss03.fill(L'0'); + oss03.flags(std::ios_base::left); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == L"909909" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc new file mode 100644 index 000000000..d2658641d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc @@ -0,0 +1,45 @@ +// 2006-07-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const string str_01(5000000, 'a'); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == str_01.size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc new file mode 100644 index 000000000..6280fa1d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc @@ -0,0 +1,48 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(5000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == wstring::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc new file mode 100644 index 000000000..ea0afa7f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc @@ -0,0 +1,53 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-DWIDTH=500000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 50000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << L'a'; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == wstring::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc new file mode 100644 index 000000000..d3563a308 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc @@ -0,0 +1,54 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-options "-DWIDTH=500000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 50000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const wstring str_01(50, L'a'); + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == wstring::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/3.cc new file mode 100644 index 000000000..f4a2a9766 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/3.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// width() != zero +// right +void test03(void) +{ + bool test __attribute__((unused)) = true; + std::wstring tmp; + + std::wstring str01 = L""; + std::wostringstream oss01; + oss01.width(5); + oss01.fill(L'0'); + oss01.flags(std::ios_base::right); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == L"00000" ); + + std::wstring str02 = L"1"; + std::wostringstream oss02; + oss02.width(5); + oss02.fill(L'0'); + oss02.flags(std::ios_base::right); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == L"00001" ); + + std::wstring str03 = L"909909"; + std::wostringstream oss03; + oss03.width(5); + oss03.fill(L'0'); + oss03.flags(std::ios_base::right); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == L"909909" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/4.cc new file mode 100644 index 000000000..902539e8c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/4.cc @@ -0,0 +1,53 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// stringstream and large strings +void +test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_01; + std::wstring str_tmp; + const int i_max=250; + + std::wostringstream oss_02(str_01, std::ios_base::out); + + // template<_CharT, _Traits> + // basic_ostream& operator<<(ostream&, const wchar_t*) + for (int i = 0; i < i_max; ++i) + oss_02 << L"Test: " << i << std::endl; + str_tmp = oss_02.str(); + VERIFY( !oss_02.bad() ); + VERIFY( oss_02.good() ); + VERIFY( str_tmp != str_01 ); + VERIFY( str_tmp.size() == 2390 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/5.cc new file mode 100644 index 000000000..80f6e475a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/5.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and large strings number 2 +void +test05() +{ + bool test __attribute__((unused)) = true; + std::wstring str05, str10; + + typedef std::wostream::pos_type pos_type; + typedef std::wostream::off_type off_type; + std::wstring str01; + const int size = 1000; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += L'1'; + str01 += L'2'; + str01 += L'3'; + str01 += L'4'; + str01 += L'5'; + str01 += L'6'; + str01 += L'7'; + str01 += L'8'; + str01 += L'9'; + str01 += L'\n'; + } + + // test 1: out + std::wostringstream sstr01(str01, std::ios_base::out); + std::wostringstream sstr02; + sstr02 << str01; + str05 = sstr01.str(); + str10 = sstr02.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); + + // test 2: in | out + std::wostringstream sstr04(str01, std::ios_base::out | std::ios_base::in); + std::wostringstream sstr05(std::ios_base::in | std::ios_base::out); + sstr05 << str01; + str05 = sstr04.str(); + str10 = sstr05.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/6.cc new file mode 100644 index 000000000..b3d6c203f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/6.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and positioning, multiple writes +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00326.html +void test06() +{ + bool test __attribute__((unused)) = true; + const wchar_t carray01[] = L"mos def & talib kweli are black star"; + + // normal + std::wostringstream ostr1(L"mos def"); + VERIFY( ostr1.str() == L"mos def" ); + ostr1 << L" & talib kweli"; // should overwrite first part of buffer + VERIFY( ostr1.str() == L" & talib kweli" ); + ostr1 << L" are black star"; // should append to string from above + VERIFY( ostr1.str() != carray01 ); + VERIFY( ostr1.str() == L" & talib kweli are black star" ); + + // appending + std::wostringstream ostr2(L"blackalicious", + std::ios_base::out | std::ios_base::ate); + VERIFY( ostr2.str() == L"blackalicious" ); + ostr2 << L" NIA "; // should not overwrite first part of buffer + VERIFY( ostr2.str() == L"blackalicious NIA " ); + ostr2 << L"4: deception (5:19)"; // should append to full string from above + VERIFY( ostr2.str() == L"blackalicious NIA 4: deception (5:19)" ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/7.cc new file mode 100644 index 000000000..3c588ecfc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/7.cc @@ -0,0 +1,91 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +// Global counter, needs to be reset after use. +bool used; + +class gnu_ctype : public std::ctype<wchar_t> +{ +protected: + char_type + do_widen(char c) const + { + used = true; + return std::ctype<wchar_t>::do_widen(c); + } + + const char* + do_widen(const char* low, const char* high, char_type* dest) const + { + used = true; + return std::ctype<wchar_t>::do_widen(low, high, dest); + } +}; + +// 27.6.2.5.4 - Character inserter template functions +// [lib.ostream.inserters.character] +void test07() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* buffer = "SFPL 5th floor, outside carrol, the Asian side"; + + wostringstream oss; + oss.imbue(locale(locale::classic(), new gnu_ctype)); + + // 1 + // template<class charT, class traits> + // basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, + // const char* s); + used = false; + oss << buffer; + VERIFY( used ); // Only required for char_type != char + wstring str = oss.str(); + wchar_t c1 = oss.widen(buffer[0]); + VERIFY( str[0] == c1 ); + wchar_t c2 = oss.widen(buffer[1]); + VERIFY( str[1] == c2 ); + + // 2 + // template<class charT, class traits> + // basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, + // char c); + used = false; + oss.str(wstring()); + oss << 'b'; + VERIFY( used ); // Only required for char_type != char + str = oss.str(); + wchar_t c3 = oss.widen('b'); + VERIFY( str[0] == c3 ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/8.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/8.cc new file mode 100644 index 000000000..76490b3c5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/8.cc @@ -0,0 +1,58 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test08() +{ + bool test __attribute__((unused)) = true; + char* pt = 0; + + // 2 + std::wostringstream woss; + woss << pt; + VERIFY( woss.bad() ); + VERIFY( woss.str().size() == 0 ); + + woss.clear(); + woss << ""; + VERIFY( woss.good() ); + + // 3 + wchar_t* wt = 0; + woss.clear(); + woss << wt; + VERIFY( woss.bad() ); + VERIFY( woss.str().size() == 0 ); + + woss.clear(); + woss << L""; + VERIFY( woss.good() ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/9555-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/9555-oc.cc new file mode 100644 index 000000000..86fa18c4f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/9555-oc.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wostream os(&b); + os.exceptions(std::wios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + wchar_t c = L'a'; + const wchar_t* ccp = L"governor ann richards"; + + testthrow(c); + testthrow(ccp); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc new file mode 100644 index 000000000..0c94c6815 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc @@ -0,0 +1,84 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +const int size = 1000; +const char name_01[] = "ostream_inserter_other-1.tst"; +const char name_02[] = "ostream_inserter_other-1.txt"; +const char name_03[] = "ostream_inserter_other-2.tst"; +const char name_04[] = "ostream_inserter_other-2.txt"; + +// fstream +void +test02() +{ + typedef std::ios_base::iostate iostate; + bool test __attribute__((unused)) = true; + + // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb) + // filebuf-> NULL + std::ifstream f_in1(name_01); + std::ofstream f_out1(name_02); + std::stringbuf* strbuf01 = 0; + iostate state01 = f_in1.rdstate(); + f_in1 >> strbuf01; + iostate state02 = f_in1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::failbit) != 0 ); + state01 = f_out1.rdstate(); + f_out1 << strbuf01; + state02 = f_out1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::badbit) != 0 ); + + // filebuf->filebuf + std::ifstream f_in(name_01); + std::ofstream f_out(name_02); + f_out << f_in.rdbuf(); + f_in.close(); + f_out.close(); + + // filebuf->stringbuf->filebuf + std::ifstream f_in2(name_03); + std::ofstream f_out2(name_04); // should be different name + std::stringbuf strbuf02; + f_in2 >> &strbuf02; + f_out2 << &strbuf02; + f_in2.close(); + f_out2.close(); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc new file mode 100644 index 000000000..d49251b2c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc @@ -0,0 +1,69 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2009 +// Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// via Brent Verner <brent@rcfile.org> +// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html +void +test03(void) +{ + using namespace std; + + typedef ios::pos_type pos_type; + + const char* TEST_IN = "ostream_inserter_other_in"; + const char* TEST_OUT = "ostream_inserter_other_out"; + pos_type i_read, i_wrote, rs, ws; + double tf_size = BUFSIZ * 2.5; + ofstream testfile(TEST_IN); + + for (int i = 0; i < tf_size; ++i) + testfile.put('.'); + testfile.close(); + + ifstream in(TEST_IN); + ofstream out(TEST_OUT); + out << in.rdbuf(); + in.seekg(0, ios_base::beg); + out.seekp(0, ios_base::beg); + rs = in.tellg(); + ws = out.tellp(); + in.seekg(0, ios_base::end); + out.seekp(0, ios_base::end); + i_read = in.tellg() - rs; + i_wrote = out.tellp() - ws; + in.close(); + out.close(); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc new file mode 100644 index 000000000..ba84d7b61 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc @@ -0,0 +1,47 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3272 +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + istringstream istr("inside betty carter"); + ostringstream ostr; + ostr << istr.rdbuf() << endl; + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + + VERIFY( test ); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc new file mode 100644 index 000000000..dcbd629e5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc @@ -0,0 +1,152 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, +// 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <cstdio> +#include <testsuite_hooks.h> + +class test_buffer_1 : public std::streambuf +{ +public: + test_buffer_1(const std::string& s) : str(s), it(str.begin()) { } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + +private: + const std::string str; + std::string::const_iterator it; +}; + + +class test_buffer_2 : public std::streambuf +{ +public: + test_buffer_2(const std::string& s) : str(s), it(str.begin()) { } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + virtual std::streamsize showmanyc() { return std::distance(it, str.end()); } +private: + const std::string str; + std::string::const_iterator it; +}; + + +class test_buffer_3 : public std::streambuf +{ +public: + test_buffer_3(const std::string& s) : str(s), it(str.begin()) { } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + virtual std::streamsize showmanyc() + { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } +private: + const std::string str; + std::string::const_iterator it; +}; + +class test_buffer_4 : public std::streambuf { +public: + test_buffer_4(const std::string& s) : str(s), it(str.begin()) + { + if (it != str.end()) { + buf[0] = *it++; + setg(buf, buf, buf+1); + } + } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + virtual std::streamsize showmanyc() { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } +private: + const std::string str; + std::string::const_iterator it; + char buf[1]; +}; + +void test(const std::string& str, std::streambuf& buf) +{ + bool test __attribute__((unused)) = true; + + std::ostringstream out; + std::istream in(&buf); + + out << in.rdbuf(); + + if (out.str() != str) + VERIFY( false ); +} + +// libstdc++/6745 +// libstdc++/8071 +// libstdc++/8127 +// Jonathan Lennox <lennox@cs.columbia.edu> +void test05() +{ + std::string string_a("Hello, world!"); + std::string string_b(""); + + test_buffer_1 buf1a(string_a); + test_buffer_1 buf1b(string_b); + + test_buffer_2 buf2a(string_a); + test_buffer_2 buf2b(string_b); + + test_buffer_3 buf3a(string_a); + test_buffer_3 buf3b(string_b); + + test_buffer_4 buf4a(string_a); + test_buffer_4 buf4b(string_b); + + test(string_a, buf1a); + test(string_b, buf1b); + + test(string_a, buf2a); + test(string_b, buf2b); + + test(string_a, buf3a); + test(string_b, buf3b); + + test(string_a, buf4a); + test(string_b, buf4b); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc new file mode 100644 index 000000000..1c93f0982 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc @@ -0,0 +1,98 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.3 basic_ostream manipulator inserters +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// Inserters for manipulators do not behave as formatted output functions. + +#include <ostream> +#include <stdexcept> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +std::ostream& func1(std::ostream&) +{ throw std::runtime_error(""); } + +std::ios& func2(std::ios&) +{ throw std::runtime_error(""); } + +std::ios_base& func3(std::ios_base&) +{ throw std::runtime_error(""); } + +template<typename T> +void test(T& (*f)(T&)) +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_streambuf buf; + std::ostream os(&buf); + + __gnu_test::sync_streambuf buf_tie; + std::ostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.good() ); + VERIFY( !buf_tie.sync_called() ); + + // The manipulator should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( !buf_tie.sync_called() ); +} + +void test05() +{ + test(&func1); + test(&func2); + test(&func3); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc new file mode 100644 index 000000000..8ba8a9b64 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc @@ -0,0 +1,65 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9318 +class Outbuf : public std::streambuf +{ +public: + typedef std::streambuf::traits_type traits_type; + + std::string result() const { return str; } + +protected: + virtual int_type overflow(int_type c = traits_type::eof()) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) + str.push_back(traits_type::to_char_type(c)); + return traits_type::not_eof(c); + } + +private: + std::string str; +}; + +void test10() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf sbuf("Bad Moon Rising", std::ios::in); + Outbuf buf; + std::ostream stream(&buf); + stream << &sbuf; + + VERIFY( buf.result() == "Bad Moon Rising" ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc new file mode 100644 index 000000000..753c95a72 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc @@ -0,0 +1,105 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <cstring> // for memset, memcmp +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9424 +class Outbuf_2 : public std::streambuf +{ + char buf[1]; + +public: + Outbuf_2() + { + setp(buf, buf + 1); + } + + int_type overflow(int_type c) + { + int_type eof = traits_type::eof(); + + if (pptr() < epptr()) + { + if (traits_type::eq_int_type(c, eof)) + return traits_type::not_eof(c); + + *pptr() = traits_type::to_char_type(c); + pbump(1); + return c; + } + + return eof; + } +}; + +class Inbuf_2 : public std::streambuf +{ + static const char buf[]; + const char* current; + int size; + +public: + Inbuf_2() + { + current = buf; + size = std::strlen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const char Inbuf_2::buf[] = "Atteivlis"; + +void test12() +{ + bool test __attribute__((unused)) = true; + + Outbuf_2 outbuf2; + std::ostream os (&outbuf2); + Inbuf_2 inbuf2; + os << &inbuf2; + VERIFY( inbuf2.sgetc() == 't' ); + VERIFY( os.good() ); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc new file mode 100644 index 000000000..80e9dc060 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::ostream os(&b); + os.exceptions(std::ios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + buf b; + + testthrow(&b); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc new file mode 100644 index 000000000..d25337453 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <sstream> +#include <system_error> +#include <algorithm> +#include <cstdio> +#include <testsuite_hooks.h> + +// Effects: os << ec.category().name() << ':' << ec.value(); +void test() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + char buf[64]; + error_code e1; + error_code e2(make_error_code(errc::bad_address)); + string s, s1, s2; + + { + ostringstream ostr; + ostr << e1 << endl; + s1 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s1.begin(), s1.end(), ':') != s1.end() ); + + sprintf(buf, "%i", e1.value()); + s = buf; + VERIFY( s1.find(s) != string::npos); + + { + ostringstream ostr; + ostr << e2 << endl; + s2 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s2.begin(), s2.end(), ':') != s2.end() ); + + sprintf(buf, "%i", e2.value()); + s = buf; + VERIFY( s2.find(s) != string::npos); +} + +int +main() +{ + test(); + return 0; +} 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 000000000..5f2373fc5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#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 000000000..822763b33 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#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 000000000..55d5c47c7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <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 000000000..6d28c5f04 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2003, 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +void test1() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream stream; + stream << static_cast<streambuf*>(0); + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +void test3() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream stream; + stream.exceptions(ios_base::badbit); + + try + { + stream << static_cast<streambuf*>(0); + VERIFY( false ); + } + catch (ios_base::failure&) + { + } + + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +// libstdc++/9371 +int main() +{ + test1(); + test3(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc new file mode 100644 index 000000000..6e12a65bf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2005, 2009, 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +const int size = 1000; +const char name_01[] = "wostream_inserter_other-1.tst"; +const char name_02[] = "wostream_inserter_other-1.txt"; +const char name_03[] = "wostream_inserter_other-2.tst"; +const char name_04[] = "wostream_inserter_other-2.txt"; + +// fstream +void +test02() +{ + typedef std::ios_base::iostate iostate; + bool test __attribute__((unused)) = true; + + // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb) + // filebuf-> NULL + std::wifstream f_in1(name_01); + std::wofstream f_out1(name_02); + std::wstringbuf* strbuf01 = 0; + iostate state01 = f_in1.rdstate(); + f_in1 >> strbuf01; + iostate state02 = f_in1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::failbit) != 0 ); + state01 = f_out1.rdstate(); + f_out1 << strbuf01; + state02 = f_out1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::badbit) != 0 ); + + // filebuf->filebuf + std::wifstream f_in(name_01); + std::wofstream f_out(name_02); + f_out << f_in.rdbuf(); + f_in.close(); + f_out.close(); + + // filebuf->stringbuf->filebuf + std::wifstream f_in2(name_03); + std::wofstream f_out2(name_04); // should be different name + std::wstringbuf strbuf02; + f_in2 >> &strbuf02; + f_out2 << &strbuf02; + f_in2.close(); + f_out2.close(); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc new file mode 100644 index 000000000..bb12a7cc4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// via Brent Verner <brent@rcfile.org> +// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html +void +test03(void) +{ + using namespace std; + + typedef wios::pos_type pos_type; + + const char* TEST_IN = "wostream_inserter_other_in.txt"; + const char* TEST_OUT = "wostream_inserter_other_out.txt"; + pos_type i_read, i_wrote, rs, ws; + double tf_size = BUFSIZ * 2.5; + ofstream testfile(TEST_IN); + + for (int i = 0; i < tf_size; ++i) + testfile.put(L'.'); + testfile.close(); + + wifstream in(TEST_IN); + wofstream out(TEST_OUT); + out << in.rdbuf(); + in.seekg(0, ios_base::beg); + out.seekp(0, ios_base::beg); + rs = in.tellg(); + ws = out.tellp(); + in.seekg(0, ios_base::end); + out.seekp(0, ios_base::end); + i_read = in.tellg() - rs; + i_wrote = out.tellp() - ws; + in.close(); + out.close(); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc new file mode 100644 index 000000000..51e329b5d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3272 +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + wistringstream istr(L"inside betty carter"); + wostringstream ostr; + ostr << istr.rdbuf() << endl; + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + + VERIFY( test ); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc new file mode 100644 index 000000000..3cd771c7f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc @@ -0,0 +1,184 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +class test_buffer_1 : public std::wstreambuf +{ +public: + test_buffer_1(const std::wstring& s) + : str(s), it(str.begin()) { } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + +private: + const std::wstring str; + std::wstring::const_iterator it; +}; + + +class test_buffer_2 : public std::wstreambuf +{ +public: + test_buffer_2(const std::wstring& s) + : str(s), it(str.begin()) { } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + + virtual std::streamsize + showmanyc() + { return std::distance(it, str.end()); } + +private: + const std::wstring str; + std::wstring::const_iterator it; +}; + + +class test_buffer_3 : public std::wstreambuf +{ +public: + test_buffer_3(const std::wstring& s) + : str(s), it(str.begin()) { } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + + virtual std::streamsize + showmanyc() + { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } + +private: + const std::wstring str; + std::wstring::const_iterator it; +}; + +class test_buffer_4 : public std::wstreambuf +{ +public: + test_buffer_4(const std::wstring& s) + : str(s), it(str.begin()) + { + if (it != str.end()) + { + buf[0] = *it++; + setg(buf, buf, buf+1); + } + } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + + virtual std::streamsize + showmanyc() + { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } + +private: + const std::wstring str; + std::wstring::const_iterator it; + wchar_t buf[1]; +}; + +void test(const std::wstring& str, std::wstreambuf& buf) +{ + bool test __attribute__((unused)) = true; + + std::wostringstream out; + std::wistream in(&buf); + + out << in.rdbuf(); + + if (out.str() != str) + VERIFY( false ); +} + +// libstdc++/6745 +// libstdc++/8071 +// libstdc++/8127 +// Jonathan Lennox <lennox@cs.columbia.edu> +void test05() +{ + std::wstring string_a(L"Hello, world!"); + std::wstring string_b(L""); + + test_buffer_1 buf1a(string_a); + test_buffer_1 buf1b(string_b); + + test_buffer_2 buf2a(string_a); + test_buffer_2 buf2b(string_b); + + test_buffer_3 buf3a(string_a); + test_buffer_3 buf3b(string_b); + + test_buffer_4 buf4a(string_a); + test_buffer_4 buf4b(string_b); + + test(string_a, buf1a); + test(string_b, buf1b); + + test(string_a, buf2a); + test(string_b, buf2b); + + test(string_a, buf3a); + test(string_b, buf3b); + + test(string_a, buf4a); + test(string_b, buf4b); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc new file mode 100644 index 000000000..e8818f542 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc @@ -0,0 +1,96 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.5.3 basic_ostream manipulator inserters +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// Inserters for manipulators do not behave as formatted output functions. + +#include <ostream> +#include <stdexcept> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +std::wostream& func1(std::wostream&) +{ throw std::runtime_error(""); } + +std::wios& func2(std::wios&) +{ throw std::runtime_error(""); } + +std::ios_base& func3(std::ios_base&) +{ throw std::runtime_error(""); } + +template<typename T> +void test(T& (*f)(T&)) +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_wstreambuf buf; + std::wostream os(&buf); + + __gnu_test::sync_wstreambuf buf_tie; + std::wostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.good() ); + VERIFY( !buf_tie.sync_called() ); + + // The manipulator should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( !buf_tie.sync_called() ); +} + +void test05() +{ + test(&func1); + test(&func2); + test(&func3); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc new file mode 100644 index 000000000..a02ed488b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9318 +class Outbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + std::wstring result() const { return str; } + +protected: + virtual int_type + overflow(int_type c = traits_type::eof()) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) + str.push_back(traits_type::to_char_type(c)); + return traits_type::not_eof(c); + } + +private: + std::wstring str; +}; + +void test10() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf sbuf(L"Bad Moon Rising", std::wios::in); + Outbuf buf; + std::wostream stream(&buf); + stream << &sbuf; + + VERIFY( buf.result() == L"Bad Moon Rising" ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc new file mode 100644 index 000000000..7b89d26df --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc @@ -0,0 +1,105 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <cwchar> +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9424 +class Outbuf_2 : public std::wstreambuf +{ + wchar_t buf[1]; + +public: + Outbuf_2() + { + setp(buf, buf + 1); + } + + int_type overflow(int_type c) + { + int_type eof = traits_type::eof(); + + if (pptr() < epptr()) + { + if (traits_type::eq_int_type(c, eof)) + return traits_type::not_eof(c); + + *pptr() = traits_type::to_char_type(c); + pbump(1); + return c; + } + + return eof; + } +}; + +class Inbuf_2 : public std::wstreambuf +{ + static const wchar_t buf[]; + const wchar_t* current; + int size; + +public: + Inbuf_2() + { + current = buf; + size = std::wcslen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const wchar_t Inbuf_2::buf[] = L"Atteivlis"; + +void test12() +{ + bool test __attribute__((unused)) = true; + + Outbuf_2 outbuf2; + std::wostream os (&outbuf2); + Inbuf_2 inbuf2; + os << &inbuf2; + VERIFY( inbuf2.sgetc() == L't' ); + VERIFY( os.good() ); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc new file mode 100644 index 000000000..89a5d361e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wostream os(&b); + os.exceptions(std::wios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + buf b; + + testthrow(&b); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc new file mode 100644 index 000000000..16f9108a3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-swprintf "" } + +// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <sstream> +#include <system_error> +#include <algorithm> +#include <cwchar> +#include <testsuite_hooks.h> + +// Effects: os << ec.category().name() << ':' << ec.value(); +void test() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wchar_t buf[64]; + error_code e1; + error_code e2(make_error_code(errc::bad_address)); + wstring s, s1, s2; + + { + wostringstream ostr; + ostr << e1 << endl; + s1 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s1.begin(), s1.end(), L':') != s1.end() ); + + swprintf(buf, 64, L"%i", e1.value()); + s = buf; + VERIFY( s1.find(s) != string::npos); + + { + wostringstream ostr; + ostr << e2 << endl; + s2 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s2.begin(), s2.end(), L':') != s2.end() ); + + swprintf(buf, 64, L"%i", e2.value()); + s = buf; + VERIFY( s2.find(s) != string::npos); +} + +int +main() +{ + test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc new file mode 100644 index 000000000..3df90b873 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <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_wstreambuf bob; + wostream stream(&bob); + wstringbuf sbuf(L"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; + wostringstream stream; + __gnu_test::fail_wstreambuf 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/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..954d56790 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <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_wstreambuf bob; + wostream stream(&bob); + stream.exceptions(ios_base::badbit); + wstringbuf sbuf(L"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; + wostringstream stream; + stream.exceptions(ios_base::badbit); + __gnu_test::fail_wstreambuf 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/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..789d3cc3c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <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_wstreambuf bob; + wostream stream(&bob); + stream.exceptions(ios_base::failbit); + wstringbuf sbuf(L"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; + wostringstream stream; + stream.exceptions(ios_base::failbit); + __gnu_test::fail_wstreambuf 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/wchar_t/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc new file mode 100644 index 000000000..076aece64 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +void test1() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream stream; + stream << static_cast<wstreambuf*>(0); + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +void test3() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream stream; + stream.exceptions(ios_base::badbit); + + try + { + stream << static_cast<wstreambuf*>(0); + VERIFY( false ); + } + catch (ios_base::failure&) + { + } + + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +// libstdc++/9371 +int main() +{ + test1(); + test3(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/put/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/put/char/1.cc new file mode 100644 index 000000000..8db9012f3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/put/char/1.cc @@ -0,0 +1,72 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::put(char_type) is an unformatted output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::streambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::ostream os(&buf); + + VERIFY( os.good() ); + + os.put('a'); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.put('b'); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/put/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/put/wchar_t/1.cc new file mode 100644 index 000000000..d9b135d75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/put/wchar_t/1.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::put(char_type) is an unformatted output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::wstreambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::wostream os(&buf); + + VERIFY( os.good() ); + + os.put(L'a'); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.put(L'b'); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/base_classes.cc new file mode 100644 index 000000000..08727f3c5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/base_classes.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.1 - Template class basic_filebuf + +#include <ostream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::ostream test_type; + typedef std::ios base_type; + + std::stringbuf buf; + const test_type& obj = *new test_type(&buf); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..fd7ad18fd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/explicit_instantiation.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.1 basic_ostream +// NB: This file is for testing ostream with NO OTHER INCLUDES. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_ostream<type_t, char_traits<type_t> >; + template class basic_ostream<pod_char, char_traits<pod_char> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/typedefs.cc new file mode 100644 index 000000000..21e8ed99c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/typedefs.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.1 basic_ostream +// NB: This file is for testing ostream with NO OTHER INCLUDES. + +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::ostream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc new file mode 100644 index 000000000..36fa2c03e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc @@ -0,0 +1,92 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks] +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <ostream> +#include <istream> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << '-' << i << s << '\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::ios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, '\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// fstream +// libstdc++/2346 +void test02() +{ + std::fstream ofstrm; + ofstrm.open("istream_seeks-3.txt", std::ios::out); + if (!ofstrm) + std::abort(); + write_rewind(ofstrm); + ofstrm.close(); + + std::fstream ifstrm; + ifstrm.open("istream_seeks-3.txt", std::ios::in); + check_contents(ifstrm); + ifstrm.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc new file mode 100644 index 000000000..d0030eaf7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc @@ -0,0 +1,80 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks] + +#include <ostream> +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << '-' << i << s << '\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::ios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, '\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// stringstream +// libstdc++/2346 +// N.B. The original testcase was broken, using tellg/seekg in write_rewind. +void test03() +{ + std::stringstream sstrm; + + write_rewind(sstrm); + check_contents(sstrm); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..fac361e14 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + ostream::pos_type pos = ostream::pos_type(); + + try + { + stream.seekp(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + ostream::off_type off(5); + + try + { + stream.seekp(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc new file mode 100644 index 000000000..e37cec8f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks] +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <istream> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << L'-' << i << s << L'\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::wios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, L'\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// fstream +// libstdc++/2346 +void test02() +{ + std::wfstream ofstrm; + ofstrm.open("wistream_seeks-3.txt", std::wios::out); + if (!ofstrm) + std::abort(); + write_rewind(ofstrm); + ofstrm.close(); + + std::wfstream ifstrm; + ifstrm.open("wistream_seeks-3.txt", std::wios::in); + check_contents(ifstrm); + ifstrm.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc new file mode 100644 index 000000000..4120c8827 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks] + +#include <ostream> +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << L'-' << i << s << L'\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::wios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, L'\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// stringstream +// libstdc++/2346 +// N.B. The original testcase was broken, using tellg/seekg in write_rewind. +void test03() +{ + std::wstringstream sstrm; + + write_rewind(sstrm); + check_contents(sstrm); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..737691f2e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + wostream::pos_type pos = wostream::pos_type(); + + try + { + stream.seekp(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + wostream::off_type off(5); + + try + { + stream.seekp(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/1.cc new file mode 100644 index 000000000..d7a4812e1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/1.cc @@ -0,0 +1,44 @@ +// 2003-02-06 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9562 +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf strbuf01; + std::ostream strm1(&strbuf01); + const std::ostream::sentry sentry1(strm1); + + VERIFY( bool(sentry1) == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/2.cc new file mode 100644 index 000000000..1a68b1d9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/2.cc @@ -0,0 +1,64 @@ +// 2003-02-06 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9563 +struct buf : std::streambuf +{ + std::ios *io_; + + buf(std::ios *io) + : io_(io) { } + + virtual int + sync() + { + io_->setstate (std::ios::failbit); + return 0; + } +}; + +void +test02() +{ + bool test __attribute__((unused)) = true; + + buf b(0); + std::ostream strm(&b); + + buf tb(&strm); + std::ostream tied(&tb); + + strm.tie(&tied); + std::ostream::sentry s(strm); + + VERIFY( !s ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/pod/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/pod/1.cc new file mode 100644 index 000000000..00becef25 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/pod/1.cc @@ -0,0 +1,123 @@ +// 1999-10-14 bkoz + +// Copyright (C) 1999, 2000, 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 +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.1.2 class basic_istream::sentry + +#include <ostream> +#include <sstream> +#include <typeinfo> +#include <ext/pod_char_traits.h> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +void test01() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef basic_string<pod_ushort> string_type; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_ostream<pod_ushort> ostream_type; + + bool test __attribute__((unused)) = true; + + + const string_type str01; + stringbuf_type* strbuf01 = 0; + stringbuf_type strbuf02(str01); + ostream_type ostr01(strbuf01); + ostream_type ostr02(&strbuf02); + + // test negatives + try + { + ostream_type::sentry sentry01(ostr01); + } + catch (std::bad_cast& obj) + { + // Not ok, throws bad_cast because locale has no ctype facet, + // but none is needed for ostream::sentry. + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + // imbued. + const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>); + ostr01.imbue(loc); + try + { + ostream_type::sentry sentry01(ostr01); + VERIFY( bool(sentry01) == false ); + } + catch (...) + { + VERIFY( false ); + } + + // test positive + try + { + ostream_type::sentry sentry03(ostr02); + } + catch (std::bad_cast& obj) + { + // Not ok, throws bad_cast because locale has no ctype facet, + // but none is needed for ostream::sentry. + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + // imbued. + ostr02.clear(); + ostr02.imbue(loc); + try + { + ostream_type::sentry sentry03(ostr02); + VERIFY( bool(sentry03) == true ); + } + catch (...) + { + VERIFY( false ); + } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/1.cc new file mode 100644 index 000000000..aeac11f6d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/1.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9562 +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf strbuf01; + std::wostream strm1(&strbuf01); + const std::wostream::sentry sentry1(strm1); + + VERIFY( bool(sentry1) == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/2.cc new file mode 100644 index 000000000..ad8174811 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/2.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9563 +struct buf : std::wstreambuf +{ + std::wios *io_; + + buf(std::wios *io) + : io_(io) { } + + virtual int + sync() + { + io_->setstate (std::wios::failbit); + return 0; + } +}; + +void +test02() +{ + bool test __attribute__((unused)) = true; + + buf b(0); + std::wostream strm(&b); + + buf tb(&strm); + std::wostream tied(&tb); + + strm.tie(&tied); + std::wostream::sentry s(strm); + + VERIFY( !s ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc new file mode 100644 index 000000000..ab492e17e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc @@ -0,0 +1,65 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.4 basic_ostream seek members + +// { dg-require-fileio "" } + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef ios::off_type off_type; + typedef ios::pos_type pos_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "ostream_seeks-1.txt"; + + // out + ostringstream ost1; + pos_type p1 = ost1.tellp(); + + ofstream ofs1; + pos_type p2 = ofs1.tellp(); + + // N.B. We implement the resolution of DR 453 and + // ostringstream::tellp() doesn't fail. + VERIFY( p1 == pos_type(off_type(0)) ); + VERIFY( p2 == pos_type(off_type(-1)) ); + + // out + // test ctors leave things in the same positions... + ostringstream ost2("bob_marley:kaya"); + p1 = ost2.tellp(); + + ofstream ofs2(str_lit01); + p2 = ofs2.tellp(); + + VERIFY( p1 == p2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc new file mode 100644 index 000000000..abfa2ff27 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc @@ -0,0 +1,49 @@ +// 2000-03-23 bkoz + +// Copyright (C) 2000, 2003, 2004, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. +// + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef std::stringbuf::pos_type pos_type; + typedef std::stringbuf::off_type off_type; + bool test __attribute__((unused)) = true; + + // tellp + ostringstream ost; + pos_type pos1; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(0)) ); + ost << "RZA "; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(4)) ); + ost << "ghost dog: way of the samurai"; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(33)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..30cbc1714 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellp(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/1.cc new file mode 100644 index 000000000..65affb91e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/1.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.4 basic_ostream seek members + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef wios::off_type off_type; + typedef wios::pos_type pos_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "wostream_seeks-1.txt"; + + // out + wostringstream ost1; + pos_type p1 = ost1.tellp(); + + wofstream ofs1; + pos_type p2 = ofs1.tellp(); + + // N.B. We implement the resolution of DR 453 and + // ostringstream::tellp() doesn't fail. + VERIFY( p1 == pos_type(off_type(0)) ); + VERIFY( p2 == pos_type(off_type(-1)) ); + + // out + // test ctors leave things in the same positions... + wostringstream ost2(L"bob_marley:kaya"); + p1 = ost2.tellp(); + + wofstream ofs2(str_lit01); + p2 = ofs2.tellp(); + + VERIFY( p1 == p2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/2.cc new file mode 100644 index 000000000..98287f439 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/2.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2005, 2009 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. +// + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + bool test __attribute__((unused)) = true; + + // tellp + wostringstream ost; + pos_type pos1; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(0)) ); + ost << L"RZA "; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(4)) ); + ost << L"ghost dog: way of the samurai"; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(33)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..434485b92 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellp(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/1.cc new file mode 100644 index 000000000..49b712de2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/1.cc @@ -0,0 +1,73 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::write(const char_type*, streamsize) is an unformatted +// output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::streambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::ostream os(&buf); + + VERIFY( os.good() ); + + os.write("a", 1); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.write("b", 1); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/1.cc new file mode 100644 index 000000000..0bdd4d989 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/1.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::write(const char_type*, streamsize) is an unformatted +// output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::wstreambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::wostream os(&buf); + + VERIFY( os.good() ); + + os.write(L"a", 1); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.write(L"b", 1); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} |