]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/num_get/get/char/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / num_get / get / char / 1.cc
CommitLineData
4216708a 1// { dg-require-namedlocale "de_DE.ISO8859-15" }
f63a8495 2
5f8d36fe
BK
3// 2001-11-21 Benjamin Kosnik <bkoz@redhat.com>
4
a945c346 5// Copyright (C) 2001-2024 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.1.1 num_get members
23
24#include <locale>
25#include <sstream>
26#include <testsuite_hooks.h>
27
28void test01()
29{
30 using namespace std;
31 typedef istreambuf_iterator<char> 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 37
5f8d36fe
BK
38 // sanity check the data is correct.
39 const string empty;
5f8d36fe
BK
40
41 bool b1 = true;
42 bool b0 = false;
5f8d36fe 43 unsigned long ul1 = 1294967294;
5f8d36fe
BK
44 unsigned long ul;
45 double d1 = 1.02345e+308;
46 double d2 = 3.15e-308;
47 double d;
48 long double ld1 = 6.630025e+4;
5f8d36fe 49 long double ld;
90737ab7 50 void* v = 0;
5f8d36fe
BK
51
52 // cache the num_get facet
53 istringstream iss;
54 iss.imbue(loc_de);
55 const num_get<char>& ng = use_facet<num_get<char> >(iss.getloc());
56 const ios_base::iostate goodbit = ios_base::goodbit;
57 const ios_base::iostate eofbit = ios_base::eofbit;
58 ios_base::iostate err = ios_base::goodbit;
59
60 // bool, simple
61 iss.str("1");
62 iterator_type os_it00 = iss.rdbuf();
567d4027 63 ng.get(os_it00, 0, iss, err, b1);
5f8d36fe
BK
64 VERIFY( b1 == true );
65 VERIFY( err & ios_base::eofbit );
66
67 iss.str("0");
68 err = goodbit;
69 ng.get(iss.rdbuf(), 0, iss, err, b0);
70 VERIFY( b0 == false );
71 VERIFY( err & eofbit );
72
73 // ... and one that does
74 iss.imbue(loc_de);
75 iss.str("1.294.967.294+++++++");
76 iss.clear();
77 iss.width(20);
78 iss.setf(ios_base::left, ios_base::adjustfield);
79 err = goodbit;
80 ng.get(iss.rdbuf(), 0, iss, err, ul);
81 VERIFY( ul == ul1 );
82 VERIFY( err == goodbit );
83
84 iss.str("+1,02345e+308");
85 iss.clear();
86 iss.width(20);
87 iss.setf(ios_base::right, ios_base::adjustfield);
88 iss.setf(ios_base::scientific, ios_base::floatfield);
89 err = goodbit;
90 ng.get(iss.rdbuf(), 0, iss, err, d);
91 VERIFY( d == d1 );
92 VERIFY( err == eofbit );
93
94 iss.str("3,15E-308 ");
95 iss.clear();
96 iss.width(20);
97 iss.precision(10);
98 iss.setf(ios_base::right, ios_base::adjustfield);
99 iss.setf(ios_base::scientific, ios_base::floatfield);
100 iss.setf(ios_base::uppercase);
101 err = goodbit;
102 ng.get(iss.rdbuf(), 0, iss, err, d);
103 VERIFY( d == d2 );
104 VERIFY( err == goodbit );
105
106 // long double
107 iss.str("6,630025e+4");
108 iss.clear();
109 err = goodbit;
110 ng.get(iss.rdbuf(), 0, iss, err, ld);
111 VERIFY( ld == ld1 );
112 VERIFY( err == eofbit );
113
114 iss.str("0 ");
115 iss.clear();
116 iss.precision(0);
117 iss.setf(ios_base::fixed, ios_base::floatfield);
118 err = goodbit;
119 ng.get(iss.rdbuf(), 0, iss, err, ld);
120 VERIFY( ld == 0 );
121 VERIFY( err == goodbit );
122
90737ab7 123 // void*
5f8d36fe
BK
124 iss.str("0xbffff74c,");
125 iss.clear();
126 err = goodbit;
127 ng.get(iss.rdbuf(), 0, iss, err, v);
90737ab7 128 VERIFY( v != 0 );
5f8d36fe
BK
129 VERIFY( err == goodbit );
130
3d7c150e 131#ifdef _GLIBCXX_USE_LONG_LONG
5f8d36fe 132 long long ll1 = 9223372036854775807LL;
5f8d36fe
BK
133 long long ll;
134
135 iss.str("9.223.372.036.854.775.807");
136 iss.clear();
137 err = goodbit;
138 ng.get(iss.rdbuf(), 0, iss, err, ll);
139 VERIFY( ll == ll1 );
140 VERIFY( err == eofbit );
141#endif
142}
143
144int main()
145{
3d838e28 146 test01();
5f8d36fe
BK
147 return 0;
148}
149
150
151// Kathleen Hannah, humanitarian, woman, art-thief