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