]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_put/put/wchar_t/1.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_put / put / wchar_t / 1.cc
CommitLineData
f63a8495
PC
1// { dg-require-namedlocale "" }
2
5f8d36fe
BK
3// 2001-11-19 Benjamin Kosnik <bkoz@redhat.com>
4
748086b7 5// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009
90737ab7 6// Free Software Foundation
5f8d36fe
BK
7//
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
748086b7 11// Free Software Foundation; either version 3, or (at your option)
5f8d36fe
BK
12// any later version.
13
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.
18
19// You should have received a copy of the GNU General Public License along
748086b7
JJ
20// with this library; see the file COPYING3. If not see
21// <http://www.gnu.org/licenses/>.
5f8d36fe
BK
22
23// 22.2.2.2.1 num_put members
24
25#include <locale>
26#include <sstream>
27#include <testsuite_hooks.h>
28
29void test01()
30{
31 using namespace std;
32 typedef ostreambuf_iterator<wchar_t> iterator_type;
33
11f10e6b 34 bool test __attribute__((unused)) = true;
5f8d36fe
BK
35
36 // basic construction
37 locale loc_c = locale::classic();
f63a8495 38 locale loc_de = locale("de_DE");
5f8d36fe 39 VERIFY( loc_c != loc_de );
5f8d36fe
BK
40
41 // cache the numpunct facets
11f10e6b
BK
42 const numpunct<wchar_t>& numpunct_de = use_facet<numpunct<wchar_t> >(loc_de);
43
5f8d36fe
BK
44 // sanity check the data is correct.
45 const wstring empty;
46 wstring result1;
47 wstring result2;
5f8d36fe
BK
48
49 bool b1 = true;
50 bool b0 = false;
5f8d36fe 51 unsigned long ul1 = 1294967294;
5f8d36fe
BK
52 double d1 = 1.7976931348623157e+308;
53 double d2 = 2.2250738585072014e-308;
54 long double ld1 = 1.7976931348623157e+308;
55 long double ld2 = 2.2250738585072014e-308;
56 const void* cv = &ld1;
57
58 // cache the num_put facet
59 wostringstream oss;
60 oss.imbue(loc_de);
61 const num_put<wchar_t>& np = use_facet<num_put<wchar_t> >(oss.getloc());
62
63 // bool, simple
64 iterator_type os_it00 = oss.rdbuf();
fea6ecb7 65 iterator_type os_it01 = np.put(os_it00, oss, L'+', b1);
5f8d36fe
BK
66 result1 = oss.str();
67 VERIFY( result1 == L"1" );
5f8d36fe
BK
68
69 oss.str(empty);
fea6ecb7 70 np.put(oss.rdbuf(), oss, L'+', b0);
5f8d36fe
BK
71 result2 = oss.str();
72 VERIFY( result2 == L"0" );
73
74 // ... and one that does
75 oss.imbue(loc_de);
76 oss.str(empty);
77 oss.clear();
78 oss.width(20);
79 oss.setf(ios_base::left, ios_base::adjustfield);
fea6ecb7 80 np.put(oss.rdbuf(), oss, L'+', ul1);
5f8d36fe
BK
81 result1 = oss.str();
82 VERIFY( result1 == L"1.294.967.294+++++++" );
83
84 // double
85 oss.str(empty);
86 oss.clear();
87 oss.width(20);
88 oss.setf(ios_base::left, ios_base::adjustfield);
fea6ecb7 89 np.put(oss.rdbuf(), oss, L'+', d1);
5f8d36fe
BK
90 result1 = oss.str();
91 VERIFY( result1 == L"1,79769e+308++++++++" );
92
93 oss.str(empty);
94 oss.clear();
95 oss.width(20);
96 oss.setf(ios_base::right, ios_base::adjustfield);
fea6ecb7 97 np.put(oss.rdbuf(), oss, L'+', d2);
5f8d36fe
BK
98 result1 = oss.str();
99 VERIFY( result1 == L"++++++++2,22507e-308" );
100
101 oss.str(empty);
102 oss.clear();
103 oss.width(20);
104 oss.setf(ios_base::right, ios_base::adjustfield);
105 oss.setf(ios_base::scientific, ios_base::floatfield);
fea6ecb7 106 np.put(oss.rdbuf(), oss, L'+', d2);
5f8d36fe
BK
107 result2 = oss.str();
108 VERIFY( result2 == L"+++++++2,225074e-308" );
109
110 oss.str(empty);
111 oss.clear();
112 oss.width(20);
113 oss.precision(10);
114 oss.setf(ios_base::right, ios_base::adjustfield);
115 oss.setf(ios_base::scientific, ios_base::floatfield);
116 oss.setf(ios_base::uppercase);
fea6ecb7 117 np.put(oss.rdbuf(), oss, L'+', d2);
5f8d36fe
BK
118 result1 = oss.str();
119 VERIFY( result1 == L"+++2,2250738585E-308" );
120
121 // long double
122 oss.str(empty);
123 oss.clear();
fea6ecb7 124 np.put(oss.rdbuf(), oss, L'+', ld1);
5f8d36fe
BK
125 result1 = oss.str();
126 VERIFY( result1 == L"1,7976931349E+308" );
127
128 oss.str(empty);
129 oss.clear();
130 oss.precision(0);
131 oss.setf(ios_base::fixed, ios_base::floatfield);
fea6ecb7 132 np.put(oss.rdbuf(), oss, L'+', ld2);
5f8d36fe
BK
133 result1 = oss.str();
134 VERIFY( result1 == L"0" );
135
90737ab7 136 // const void*
5f8d36fe
BK
137 oss.str(empty);
138 oss.clear();
fea6ecb7 139 np.put(oss.rdbuf(), oss, L'+', cv);
5f8d36fe
BK
140 result1 = oss.str();
141 // No grouping characters.
142 VERIFY( !char_traits<wchar_t>::find(result1.c_str(),
143 result1.size(),
144 numpunct_de.decimal_point()) );
145 // Should contain an 'x'.
146 VERIFY( result1.find(L'x') == 1 );
147
3d7c150e 148#ifdef _GLIBCXX_USE_LONG_LONG
5f8d36fe 149 long long ll1 = 9223372036854775807LL;
5f8d36fe
BK
150
151 oss.str(empty);
152 oss.clear();
fea6ecb7 153 np.put(oss.rdbuf(), oss, L'+', ll1);
5f8d36fe
BK
154 result1 = oss.str();
155 VERIFY( result1 == L"9.223.372.036.854.775.807" );
156#endif
157}
158
159int main()
160{
161 test01();
162 return 0;
163}