locale_facets.tcc (num_get<>::do_get(iter_type, ios_base&, ios_base::iostate&, void...
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_put / put / wchar_t / 1.cc
1 // { dg-require-namedlocale "" }
2
3 // 2001-11-19 Benjamin Kosnik <bkoz@redhat.com>
4
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
6 // Free Software Foundation
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
11 // Free Software Foundation; either version 2, or (at your option)
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
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,
22 // USA.
23
24 // 22.2.2.2.1 num_put members
25
26 #include <locale>
27 #include <sstream>
28 #include <testsuite_hooks.h>
29
30 void test01()
31 {
32 using namespace std;
33 typedef ostreambuf_iterator<wchar_t> iterator_type;
34
35 bool test __attribute__((unused)) = true;
36
37 // basic construction
38 locale loc_c = locale::classic();
39 locale loc_de = locale("de_DE");
40 VERIFY( loc_c != loc_de );
41
42 // cache the numpunct facets
43 const numpunct<wchar_t>& numpunct_de = use_facet<numpunct<wchar_t> >(loc_de);
44
45 // sanity check the data is correct.
46 const wstring empty;
47 wstring result1;
48 wstring result2;
49
50 bool b1 = true;
51 bool b0 = false;
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;
58
59 // cache the num_put facet
60 wostringstream oss;
61 oss.imbue(loc_de);
62 const num_put<wchar_t>& np = use_facet<num_put<wchar_t> >(oss.getloc());
63
64 // bool, simple
65 iterator_type os_it00 = oss.rdbuf();
66 iterator_type os_it01 = np.put(os_it00, oss, L'+', b1);
67 result1 = oss.str();
68 VERIFY( result1 == L"1" );
69
70 oss.str(empty);
71 np.put(oss.rdbuf(), oss, L'+', b0);
72 result2 = oss.str();
73 VERIFY( result2 == L"0" );
74
75 // ... and one that does
76 oss.imbue(loc_de);
77 oss.str(empty);
78 oss.clear();
79 oss.width(20);
80 oss.setf(ios_base::left, ios_base::adjustfield);
81 np.put(oss.rdbuf(), oss, L'+', ul1);
82 result1 = oss.str();
83 VERIFY( result1 == L"1.294.967.294+++++++" );
84
85 // double
86 oss.str(empty);
87 oss.clear();
88 oss.width(20);
89 oss.setf(ios_base::left, ios_base::adjustfield);
90 np.put(oss.rdbuf(), oss, L'+', d1);
91 result1 = oss.str();
92 VERIFY( result1 == L"1,79769e+308++++++++" );
93
94 oss.str(empty);
95 oss.clear();
96 oss.width(20);
97 oss.setf(ios_base::right, ios_base::adjustfield);
98 np.put(oss.rdbuf(), oss, L'+', d2);
99 result1 = oss.str();
100 VERIFY( result1 == L"++++++++2,22507e-308" );
101
102 oss.str(empty);
103 oss.clear();
104 oss.width(20);
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);
108 result2 = oss.str();
109 VERIFY( result2 == L"+++++++2,225074e-308" );
110
111 oss.str(empty);
112 oss.clear();
113 oss.width(20);
114 oss.precision(10);
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);
119 result1 = oss.str();
120 VERIFY( result1 == L"+++2,2250738585E-308" );
121
122 // long double
123 oss.str(empty);
124 oss.clear();
125 np.put(oss.rdbuf(), oss, L'+', ld1);
126 result1 = oss.str();
127 VERIFY( result1 == L"1,7976931349E+308" );
128
129 oss.str(empty);
130 oss.clear();
131 oss.precision(0);
132 oss.setf(ios_base::fixed, ios_base::floatfield);
133 np.put(oss.rdbuf(), oss, L'+', ld2);
134 result1 = oss.str();
135 VERIFY( result1 == L"0" );
136
137 // const void*
138 oss.str(empty);
139 oss.clear();
140 np.put(oss.rdbuf(), oss, L'+', cv);
141 result1 = oss.str();
142 // No grouping characters.
143 VERIFY( !char_traits<wchar_t>::find(result1.c_str(),
144 result1.size(),
145 numpunct_de.decimal_point()) );
146 // Should contain an 'x'.
147 VERIFY( result1.find(L'x') == 1 );
148
149 #ifdef _GLIBCXX_USE_LONG_LONG
150 long long ll1 = 9223372036854775807LL;
151
152 oss.str(empty);
153 oss.clear();
154 np.put(oss.rdbuf(), oss, L'+', ll1);
155 result1 = oss.str();
156 VERIFY( result1 == L"9.223.372.036.854.775.807" );
157 #endif
158 }
159
160 int main()
161 {
162 test01();
163 return 0;
164 }