1 // { dg-require-namedlocale "" }
3 // 2001-11-19 Benjamin Kosnik <bkoz@redhat.com>
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
6 // Free Software Foundation
8 // This file is part of the GNU ISO C++ Library. This library is free
9 // software; you can redistribute it and/or modify it under the
10 // terms of the GNU General Public License as published by the
11 // Free Software Foundation; either version 2, or (at your option)
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 // GNU General Public License for more details.
19 // You should have received a copy of the GNU General Public License along
20 // with this library; see the file COPYING. If not, write to the Free
21 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 // 22.2.2.2.1 num_put members
28 #include <testsuite_hooks.h>
33 typedef ostreambuf_iterator
<wchar_t> iterator_type
;
35 bool test
__attribute__((unused
)) = true;
38 locale loc_c
= locale::classic();
39 locale loc_de
= locale("de_DE");
40 VERIFY( loc_c
!= loc_de
);
42 // cache the numpunct facets
43 const numpunct
<wchar_t>& numpunct_de
= use_facet
<numpunct
<wchar_t> >(loc_de
);
45 // sanity check the data is correct.
52 unsigned long ul1
= 1294967294;
53 double d1
= 1.7976931348623157e+308;
54 double d2
= 2.2250738585072014e-308;
55 long double ld1
= 1.7976931348623157e+308;
56 long double ld2
= 2.2250738585072014e-308;
57 const void* cv
= &ld1
;
59 // cache the num_put facet
62 const num_put
<wchar_t>& np
= use_facet
<num_put
<wchar_t> >(oss
.getloc());
65 iterator_type os_it00
= oss
.rdbuf();
66 iterator_type os_it01
= np
.put(os_it00
, oss
, L
'+', b1
);
68 VERIFY( result1
== L
"1" );
71 np
.put(oss
.rdbuf(), oss
, L
'+', b0
);
73 VERIFY( result2
== L
"0" );
75 // ... and one that does
80 oss
.setf(ios_base::left
, ios_base::adjustfield
);
81 np
.put(oss
.rdbuf(), oss
, L
'+', ul1
);
83 VERIFY( result1
== L
"1.294.967.294+++++++" );
89 oss
.setf(ios_base::left
, ios_base::adjustfield
);
90 np
.put(oss
.rdbuf(), oss
, L
'+', d1
);
92 VERIFY( result1
== L
"1,79769e+308++++++++" );
97 oss
.setf(ios_base::right
, ios_base::adjustfield
);
98 np
.put(oss
.rdbuf(), oss
, L
'+', d2
);
100 VERIFY( result1
== L
"++++++++2,22507e-308" );
105 oss
.setf(ios_base::right
, ios_base::adjustfield
);
106 oss
.setf(ios_base::scientific
, ios_base::floatfield
);
107 np
.put(oss
.rdbuf(), oss
, L
'+', d2
);
109 VERIFY( result2
== L
"+++++++2,225074e-308" );
115 oss
.setf(ios_base::right
, ios_base::adjustfield
);
116 oss
.setf(ios_base::scientific
, ios_base::floatfield
);
117 oss
.setf(ios_base::uppercase
);
118 np
.put(oss
.rdbuf(), oss
, L
'+', d2
);
120 VERIFY( result1
== L
"+++2,2250738585E-308" );
125 np
.put(oss
.rdbuf(), oss
, L
'+', ld1
);
127 VERIFY( result1
== L
"1,7976931349E+308" );
132 oss
.setf(ios_base::fixed
, ios_base::floatfield
);
133 np
.put(oss
.rdbuf(), oss
, L
'+', ld2
);
135 VERIFY( result1
== L
"0" );
140 np
.put(oss
.rdbuf(), oss
, L
'+', cv
);
142 // No grouping characters.
143 VERIFY( !char_traits
<wchar_t>::find(result1
.c_str(),
145 numpunct_de
.decimal_point()) );
146 // Should contain an 'x'.
147 VERIFY( result1
.find(L
'x') == 1 );
149 #ifdef _GLIBCXX_USE_LONG_LONG
150 long long ll1
= 9223372036854775807LL;
154 np
.put(oss
.rdbuf(), oss
, L
'+', ll1
);
156 VERIFY( result1
== L
"9.223.372.036.854.775.807" );