2 // Petter Urkedal <petter@matfys.lth.se>
4 // Copyright (C) 2000, 2003 Free Software Foundation
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
27 #include <testsuite_hooks.h>
31 inline bool flteq(R x, R y)
33 if (x == R(0)) return y == R(0);
34 else return std::fabs(x-y) < 1e-6*std::fabs(x);
39 test_good(std::string str, R x, R y)
41 bool test __attribute__((unused)) = true;
44 std::istringstream iss(str);
47 VERIFY( flteq(z.real(), x) );
48 VERIFY( flteq(z.imag(), y) );
55 test_fail(std::string str)
57 bool test __attribute__((unused)) = true;
59 std::istringstream iss(str);
61 VERIFY( iss.fail() && !iss.bad() );
69 test_good<R>("(-1.1,3.7)#", -1.1, 3.7);
70 test_good<R>("( .7e6 , \n-3.1)#", .7e6, -3.1);
71 test_good<R>("(\t0,-1)#", 0.0, -1.0);
72 test_good<R>("(-3.14)#", -3.14, 0.0);
73 test_good<R>("-.1#", -.1, 0.0);
74 test_good<R>(" ( -2.7e3 )#", -2.7e3, 0.0);
75 test_good<R>(" -.1#", -.1, 0.0);
76 test_fail<R>("(a,1)");
78 test_fail<R>("(1,a)");
79 test_fail<R>("(1, )");
80 test_fail<R>("|1,1)");
81 test_fail<R>("(1|1)");
82 test_fail<R>("(1,1|");
90 bool test __attribute__((unused)) = true;
92 complex<float> cf01(-1.1, -333.2);
95 string str = ss.str();
96 VERIFY( str == "(-1.1,-333.2)" );
100 struct gnu_char_traits : public std::char_traits<char>
103 typedef std::basic_ostringstream<char, gnu_char_traits> gnu_sstream;
104 template class std::basic_string<char, gnu_char_traits, std::allocator<char> >;
108 bool test __attribute__((unused)) = true;
110 // Construct locale with specialized facets.
111 typedef gnu_sstream::__num_put_type numput_type;
112 typedef gnu_sstream::__num_get_type numget_type;
113 std::locale loc_c = std::locale::classic();
114 std::locale loc_1(loc_c, new numput_type);
115 std::locale loc_2(loc_1, new numget_type);
116 VERIFY( std::has_facet<numput_type>(loc_2) );
117 VERIFY( std::has_facet<numget_type>(loc_2) );
123 std::complex<double> x(3, 4);
125 VERIFY( sstr.str() == "(3,4)" );
133 testall<long double>();