]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/num_get_members_wchar_t.cc
1 // 2001-11-26 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001, 2002 Free Software Foundation
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 22.2.2.1.1 num_get members
25 #include <testsuite_hooks.h>
27 // XXX This test is not working for non-glibc locale models.
28 // { dg-do run { xfail *-*-* } }
30 #ifdef _GLIBCPP_USE_WCHAR_T
34 typedef istreambuf_iterator
<wchar_t> iterator_type
;
39 locale loc_c
= locale::classic();
40 locale
loc_hk("en_HK");
41 locale
loc_fr("fr_FR@euro");
42 locale
loc_de("de_DE");
43 VERIFY( loc_c
!= loc_de
);
44 VERIFY( loc_hk
!= loc_fr
);
45 VERIFY( loc_hk
!= loc_de
);
46 VERIFY( loc_de
!= loc_fr
);
48 // cache the numpunct facets
49 const numpunct
<wchar_t>& numpunct_c
= use_facet
<numpunct
<wchar_t> >(loc_c
);
50 const numpunct
<wchar_t>& numpunct_de
= use_facet
<numpunct
<wchar_t> >(loc_de
);
51 const numpunct
<wchar_t>& numpunct_hk
= use_facet
<numpunct
<wchar_t> >(loc_hk
);
53 // sanity check the data is correct.
60 long l2
= -2147483647;
62 unsigned long ul1
= 1294967294;
63 unsigned long ul2
= 0;
65 double d1
= 1.02345e+308;
66 double d2
= 3.15e-308;
68 long double ld1
= 6.630025e+4;
69 long double ld2
= 0.0;
72 const void* cv
= &ul2
;
74 // cache the num_get facet
77 const num_get
<wchar_t>& ng
= use_facet
<num_get
<wchar_t> >(iss
.getloc());
78 const ios_base::iostate goodbit
= ios_base::goodbit
;
79 const ios_base::iostate eofbit
= ios_base::eofbit
;
80 ios_base::iostate err
= ios_base::goodbit
;
84 iterator_type os_it00
= iss
.rdbuf();
85 iterator_type os_it01
= ng
.get(os_it00
, 0, iss
, err
, b1
);
87 VERIFY( err
& ios_base::eofbit
);
91 ng
.get(iss
.rdbuf(), 0, iss
, err
, b0
);
92 VERIFY( b0
== false );
93 VERIFY( err
& eofbit
);
95 // bool, more twisted examples
99 iss
.setf(ios_base::boolalpha
);
101 ng
.get(iss
.rdbuf(), 0, iss
, err
, b0
);
102 VERIFY( b0
== true );
103 VERIFY( err
== goodbit
);
107 iss
.setf(ios_base::boolalpha
);
109 ng
.get(iss
.rdbuf(), 0, iss
, err
, b1
);
110 VERIFY( b1
== false );
111 VERIFY( err
== goodbit
);
113 // long, in a locale that expects grouping
115 iss
.str(L
"2,147,483,647 ");
118 ng
.get(iss
.rdbuf(), 0, iss
, err
, l
);
120 VERIFY( err
== goodbit
);
122 iss
.str(L
"-2,147,483,647++++++");
125 ng
.get(iss
.rdbuf(), 0, iss
, err
, l
);
127 VERIFY( err
== goodbit
);
129 // unsigned long, in a locale that does not group
131 iss
.str(L
"1294967294");
134 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
136 VERIFY( err
== eofbit
);
138 iss
.str(L
"0+++++++++++++++++++");
141 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
143 VERIFY( err
== goodbit
);
145 // ... and one that does
147 iss
.str(L
"1.294.967.294+++++++");
150 iss
.setf(ios_base::left
, ios_base::adjustfield
);
152 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
154 VERIFY( err
== goodbit
);
158 iss
.str(L
"1.02345e+308++++++++");
161 iss
.setf(ios_base::left
, ios_base::adjustfield
);
163 ng
.get(iss
.rdbuf(), 0, iss
, err
, d
);
165 VERIFY( err
== goodbit
);
167 iss
.str(L
"+3.15e-308");
170 iss
.setf(ios_base::right
, ios_base::adjustfield
);
172 ng
.get(iss
.rdbuf(), 0, iss
, err
, d
);
174 VERIFY( err
== eofbit
);
177 iss
.str(L
"+1,02345e+308");
180 iss
.setf(ios_base::right
, ios_base::adjustfield
);
181 iss
.setf(ios_base::scientific
, ios_base::floatfield
);
183 ng
.get(iss
.rdbuf(), 0, iss
, err
, d
);
185 VERIFY( err
== eofbit
);
187 iss
.str(L
"3,15E-308 ");
191 iss
.setf(ios_base::right
, ios_base::adjustfield
);
192 iss
.setf(ios_base::scientific
, ios_base::floatfield
);
193 iss
.setf(ios_base::uppercase
);
195 ng
.get(iss
.rdbuf(), 0, iss
, err
, d
);
197 VERIFY( err
== goodbit
);
200 iss
.str(L
"6,630025e+4");
203 ng
.get(iss
.rdbuf(), 0, iss
, err
, ld
);
205 VERIFY( err
== eofbit
);
210 iss
.setf(ios_base::fixed
, ios_base::floatfield
);
212 ng
.get(iss
.rdbuf(), 0, iss
, err
, ld
);
214 VERIFY( err
== goodbit
);
217 iss
.str(L
"0xbffff74c,");
220 ng
.get(iss
.rdbuf(), 0, iss
, err
, v
);
222 VERIFY( err
== goodbit
);
225 #ifdef _GLIBCPP_USE_LONG_LONG
226 long long ll1
= 9223372036854775807LL;
227 long long ll2
= -9223372036854775807LL;
230 iss
.str(L
"9.223.372.036.854.775.807");
233 ng
.get(iss
.rdbuf(), 0, iss
, err
, ll
);
235 VERIFY( err
== eofbit
);
239 // 2002-01-10 David Seymour <seymour_dj@yahoo.com>
246 // Check num_get works with other iterators besides streambuf
247 // output iterators. (As long as output_iterator requirements are met.)
248 typedef wstring::const_iterator iter_type
;
249 typedef num_get
<wchar_t, iter_type
> num_get_type
;
250 const ios_base::iostate goodbit
= ios_base::goodbit
;
251 const ios_base::iostate eofbit
= ios_base::eofbit
;
252 ios_base::iostate err
= ios_base::goodbit
;
253 const locale loc_c
= locale::classic();
254 const wstring
str(L
"20000106 Elizabeth Durack");
255 const wstring
str2(L
"0 true 0xbffff74c Durack");
257 istringstream iss
; // need an ios, add my num_get facet
258 iss
.imbue(locale(loc_c
, new num_get_type
));
260 // Iterator advanced, state, output.
261 const num_get_type
& ng
= use_facet
<num_get_type
>(iss
.getloc());
264 // 02 get(long double)
271 iter_type end1
= ng
.get(str
.begin(), str
.end(), iss
, err
, i
);
272 wstring
rem1(end1
, str
.end());
273 VERIFY( err
== goodbit
);
274 VERIFY( i
== 20000106);
275 VERIFY( rem1
== L
" Elizabeth Durack" );
277 // 02 get(long double)
278 long double ld
= 0.0;
280 iter_type end2
= ng
.get(str
.begin(), str
.end(), iss
, err
, ld
);
281 wstring
rem2(end2
, str
.end());
282 VERIFY( err
== goodbit
);
283 VERIFY( ld
== 20000106);
284 VERIFY( rem2
== L
" Elizabeth Durack" );
287 // const string str2("0 true 0xbffff74c Durack");
291 iter_type end3
= ng
.get(str2
.begin(), str2
.end(), iss
, err
, b
);
292 wstring
rem3(end3
, str2
.end());
293 VERIFY( err
== goodbit
);
295 VERIFY( rem3
== L
" true 0xbffff74c Durack" );
299 iss
.setf(ios_base::boolalpha
);
300 iter_type end4
= ng
.get(++end3
, str2
.end(), iss
, err
, b
);
301 wstring
rem4(end4
, str2
.end());
302 VERIFY( err
== goodbit
);
304 VERIFY( rem4
== L
" 0xbffff74c Durack" );
310 iss
.setf(ios_base::fixed
, ios_base::floatfield
);
311 iter_type end5
= ng
.get(++end4
, str2
.end(), iss
, err
, v
);
312 wstring
rem5(end5
, str2
.end());
313 VERIFY( err
== goodbit
);
315 VERIFY( rem5
== L
" Durack" );
321 #ifdef _GLIBCPP_HAVE_SETENV
322 // Set the global locale to non-"C".
323 std::locale
loc_de("de_DE");
324 std::locale::global(loc_de
);
326 // Set LANG environment variable to de_DE.
327 const char* oldLANG
= getenv("LANG");
328 if (!setenv("LANG", "de_DE", 1))
332 setenv("LANG", oldLANG
? oldLANG
: "", 1);
337 // Testing the correct parsing of grouped hexadecimals and octals.
348 // A locale that expects grouping
349 locale
loc_de("de_DE");
352 const num_get
<wchar_t>& ng
= use_facet
<num_get
<wchar_t> >(iss
.getloc());
353 const ios_base::iostate goodbit
= ios_base::goodbit
;
354 ios_base::iostate err
= ios_base::goodbit
;
356 iss
.setf(ios::hex
, ios::basefield
);
357 iss
.str(L
"0xbf.fff.74c ");
359 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
360 VERIFY( err
== goodbit
);
361 VERIFY( ul
== 0xbffff74c );
363 iss
.str(L
"0Xf.fff ");
365 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
366 VERIFY( err
== goodbit
);
367 VERIFY( ul
== 0xffff );
371 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
372 VERIFY( err
== goodbit
);
373 VERIFY( ul
== 0xffe );
375 iss
.setf(ios::oct
, ios::basefield
);
376 iss
.str(L
"07.654.321 ");
378 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
379 VERIFY( err
== goodbit
);
380 VERIFY( ul
== 07654321 );
384 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
385 VERIFY( err
== goodbit
);
386 VERIFY( ul
== 07777 );
390 ng
.get(iss
.rdbuf(), 0, iss
, err
, ul
);
391 VERIFY( err
== goodbit
);
392 VERIFY( ul
== 0776 );
404 locale
loc_de("de_DE");
407 const num_get
<wchar_t>& ng
= use_facet
<num_get
<wchar_t> >(iss
.getloc());
408 const ios_base::iostate goodbit
= ios_base::goodbit
;
409 ios_base::iostate err
= ios_base::goodbit
;
413 ng
.get(iss
.rdbuf(), 0, iss
, err
, d
);
414 VERIFY( err
== goodbit
);
415 VERIFY( d
== 1234.5 );
418 // http://gcc.gnu.org/ml/libstdc++/2002-05/msg00038.html
423 const char* tentLANG
= std::setlocale(LC_ALL
, "ja_JP.eucjp");
424 if (tentLANG
!= NULL
)
426 std::string preLANG
= tentLANG
;
431 std::string postLANG
= std::setlocale(LC_ALL
, NULL
);
432 VERIFY( preLANG
== postLANG
);
439 #ifdef _GLIBCPP_USE_WCHAR_T
451 // Kathleen Hannah, humanitarian, woman, art-thief