From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../complex/inserters_extractors/char/1.cc | 138 +++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc (limited to 'libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char') diff --git a/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc new file mode 100644 index 000000000..b7e65594c --- /dev/null +++ b/libstdc++-v3/testsuite/26_numerics/complex/inserters_extractors/char/1.cc @@ -0,0 +1,138 @@ +// 2000-02-10 +// Petter Urkedal + +// Copyright (C) 2000, 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 +// . + + +#include +#include +#include +#include +#include +#include + +template +inline bool flteq(R x, R y) +{ + if (x == R(0)) return y == R(0); + else return std::fabs(x-y) < 1e-6*std::fabs(x); +} + +template +int +test_good(std::string str, R x, R y) +{ + bool test __attribute__((unused)) = true; + std::complex z; + char ch; + std::istringstream iss(str); + iss >> z >> ch; + VERIFY( iss.good() ); + VERIFY( flteq(z.real(), x) ); + VERIFY( flteq(z.imag(), y) ); + VERIFY( ch == '#' ); + return 0; +} + +template +int +test_fail(std::string str) +{ + bool test __attribute__((unused)) = true; + std::complex z; + std::istringstream iss(str); + iss >> z; + VERIFY( iss.fail() && !iss.bad() ); + return 0; +} + +template +int +testall() +{ + test_good("(-1.1,3.7)#", -1.1, 3.7); + test_good("( .7e6 , \n-3.1)#", .7e6, -3.1); + test_good("(\t0,-1)#", 0.0, -1.0); + test_good("(-3.14)#", -3.14, 0.0); + test_good("-.1#", -.1, 0.0); + test_good(" ( -2.7e3 )#", -2.7e3, 0.0); + test_good(" -.1#", -.1, 0.0); + test_fail("(a,1)"); + test_fail("(,1)"); + test_fail("(1,a)"); + test_fail("(1, )"); + test_fail("|1,1)"); + test_fail("(1|1)"); + test_fail("(1,1|"); + return 0; +} + +// libstdc++/2970 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + complex cf01(-1.1, -333.2); + stringstream ss; + ss << cf01; + string str = ss.str(); + VERIFY( str == "(-1.1,-333.2)" ); +} + +// libstdc++/2985 +struct gnu_char_traits : public std::char_traits +{ }; + +typedef std::basic_ostringstream gnu_sstream; +template class std::basic_string >; + +void test02() +{ + bool test __attribute__((unused)) = true; + + // Construct locale with specialized facets. + typedef gnu_sstream::__num_put_type numput_type; + typedef gnu_sstream::__num_get_type numget_type; + std::locale loc_c = std::locale::classic(); + std::locale loc_1(loc_c, new numput_type); + std::locale loc_2(loc_1, new numget_type); + VERIFY( std::has_facet(loc_2) ); + VERIFY( std::has_facet(loc_2) ); + + gnu_sstream sstr; + sstr.imbue(loc_2); + + + std::complex x(3, 4); + sstr << x; + VERIFY( sstr.str() == "(3,4)" ); +} + +int +main() +{ + testall(); + testall(); + testall(); + + test01(); + test02(); + + return 0; +} -- cgit v1.2.3