diff options
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic')
11 files changed, 706 insertions, 0 deletions
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 00000000000..4382473586e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc @@ -0,0 +1,68 @@ +// 2005-07-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 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/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc new file mode 100644 index 00000000000..d398fdff0f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "" } + +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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 00000000000..0078c71e4d5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc new file mode 100644 index 00000000000..4ad87a5372b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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 00000000000..e2db338e6a6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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 = 1.2345678901234567890123456789e+1000L; + 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 = 3.5e230; + + 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 00000000000..7284c5e9670 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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 00000000000..4129ca93325 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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 00000000000..87013e7ae7a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc @@ -0,0 +1,68 @@ +// 2005-07-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005 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 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 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 00000000000..f2e830b1338 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <ostream> +#include <streambuf> +#include <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 00000000000..3c36f0300c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#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 00000000000..6211a9cd421 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2005 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include <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; +} |