]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/num_put/put/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_put / put / char / 1.cc
1 // { dg-require-namedlocale "de_DE.ISO8859-15" }
2
3 // 2001-11-19 Benjamin Kosnik <bkoz@redhat.com>
4
5 // Copyright (C) 2001-2020 Free Software Foundation, Inc.
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
10 // Free Software Foundation; either version 3, or (at your option)
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
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // 22.2.2.2.1 num_put members
23
24 #include <locale>
25 #include <sstream>
26 #include <testsuite_hooks.h>
27
28 void test01()
29 {
30 using namespace std;
31 typedef ostreambuf_iterator<char> iterator_type;
32
33 // basic construction
34 locale loc_c = locale::classic();
35 locale loc_de = locale(ISO_8859(15,de_DE));
36 VERIFY( loc_c != loc_de );
37
38 // cache the numpunct facets
39 const numpunct<char>& numpunct_de = use_facet<numpunct<char> >(loc_de);
40
41 // sanity check the data is correct.
42 const string empty;
43 string result1;
44 string result2;
45
46 bool b1 = true;
47 bool b0 = false;
48 unsigned long ul1 = 1294967294;
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 ostringstream oss;
57 oss.imbue(loc_de);
58 const num_put<char>& np = use_facet<num_put<char> >(oss.getloc());
59
60 // bool, simple
61 iterator_type os_it00 = oss.rdbuf();
62 np.put(os_it00, oss, '+', b1);
63 result1 = oss.str();
64 VERIFY( result1 == "1" );
65
66 oss.str(empty);
67 np.put(oss.rdbuf(), oss, '+', b0);
68 result2 = oss.str();
69 VERIFY( result2 == "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);
77 np.put(oss.rdbuf(), oss, '+', ul1);
78 result1 = oss.str();
79 VERIFY( result1 == "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);
86 np.put(oss.rdbuf(), oss, '+', d1);
87 result1 = oss.str();
88 VERIFY( result1 == "1,79769e+308++++++++" );
89
90 oss.str(empty);
91 oss.clear();
92 oss.width(20);
93 oss.setf(ios_base::right, ios_base::adjustfield);
94 np.put(oss.rdbuf(), oss, '+', d2);
95 result1 = oss.str();
96 VERIFY( result1 == "++++++++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);
103 np.put(oss.rdbuf(), oss, '+', d2);
104 result2 = oss.str();
105 VERIFY( result2 == "+++++++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);
114 np.put(oss.rdbuf(), oss, '+', d2);
115 result1 = oss.str();
116 VERIFY( result1 == "+++2,2250738585E-308" );
117
118 // long double
119 oss.str(empty);
120 oss.clear();
121 np.put(oss.rdbuf(), oss, '+', ld1);
122 result1 = oss.str();
123 VERIFY( result1 == "1,7976931349E+308" );
124
125 oss.str(empty);
126 oss.clear();
127 oss.precision(0);
128 oss.setf(ios_base::fixed, ios_base::floatfield);
129 np.put(oss.rdbuf(), oss, '+', ld2);
130 result1 = oss.str();
131 VERIFY( result1 == "0" );
132
133 // const void*
134 oss.str(empty);
135 oss.clear();
136 np.put(oss.rdbuf(), oss, '+', cv);
137 result1 = oss.str();
138 // No grouping characters.
139 VERIFY( !char_traits<char>::find(result1.c_str(),
140 result1.size(),
141 numpunct_de.decimal_point()) );
142 // Should contain an 'x'.
143 VERIFY( result1.find('x') == 1 );
144
145 #ifdef _GLIBCXX_USE_LONG_LONG
146 long long ll1 = 9223372036854775807LL;
147
148 oss.str(empty);
149 oss.clear();
150 np.put(oss.rdbuf(), oss, '+', ll1);
151 result1 = oss.str();
152 VERIFY( result1 == "9.223.372.036.854.775.807" );
153 #endif
154 }
155
156 int main()
157 {
158 test01();
159 return 0;
160 }
161
162