3 // Copyright (C) 1999, 2000 Free Software Foundation, Inc.
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 // 27.6.1.2.2 arithmetic extractors
32 std::string str_02("true false 0 1 110001");
33 std::string str_03("-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5");
35 std::stringbuf isbuf_01(std::ios_base::in);
36 std::stringbuf isbuf_02(str_02, std::ios_base::in);
37 std::stringbuf isbuf_03(str_03, std::ios_base::in);
39 std::istream is_01(NULL);
40 std::istream is_02(&isbuf_02);
41 std::istream is_03(&isbuf_03);
42 std::stringstream ss_01(str_01);
44 // minimal sanity check
55 unsigned short us1 = 0;
57 unsigned long ul1 = 0;
59 // Floating-point Types:
64 // process alphanumeric versions of bool values
65 std::ios_base::fmtflags fmt = is_02.flags();
66 bool testfmt = fmt & std::ios_base::boolalpha;
67 is_02.setf(std::ios_base::boolalpha);
69 testfmt = fmt & std::ios_base::boolalpha;
75 // process numeric versions of of bool values
76 is_02.unsetf(std::ios_base::boolalpha);
78 testfmt = fmt & std::ios_base::boolalpha;
84 // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"
86 test &= l1 == -19999999;
88 test &= ul1 == 777777;
90 test &= i1 == -234234;
100 test &= ld1 == 66300.25;
106 // test void pointers
122 // elaborated test for ints
126 const std::string str_01("20000AB");
127 std::stringbuf strb_01(str_01, std::ios_base::in);
128 std::istream is(&strb_01);
146 std::istream istr(&sbuf);
147 std::ostream ostr(&sbuf);
152 istr >> l01; // _M_in_end set completely incorrectly here.
153 test &= l01 == 12220101;
154 test &= istr.rdstate() == std::ios_base::eofbit;
163 // http://sourceware.cygnus.com/ml/libstdc++/2000-q1/msg00081.html
167 // default locale, grouping is turned off
169 unsigned int h4, h3, h2;
171 std::string s("205,199,144");
172 std::istringstream is(s);
185 test &= is.rdstate() == std::ios_base::eofbit;
189 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
197 class test_numpunct1 : public numpunct<char>
202 { return string(1, '\003'); }
208 // manufactured locale, grouping is turned on
210 unsigned int h4 = 0, h3 = 0, h2 = 0;
212 const std::string s1("205,199 23,445.25 1,024,365 123,22,24");
213 std::istringstream is(s1);
214 is.imbue(std::locale(std::locale(), new std::test_numpunct1));
218 test &= h4 == 205199;
223 test &= f1 == 23445.25;
228 test &= h3 == 1024365;
234 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
235 test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit);
237 // Stress tests for explicit errors in grouping corner cases. The
238 // validity of these tests and results have been hammered out in
239 // private email between bkoz and ncm between Jan 25 and Jan 27, 2000.
240 // Thanks nate -- benjamin
241 const std::string s2(",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567");
244 const char c_control = '?';
251 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
260 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
288 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
291 test &= c == ','; // second one
296 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
300 test &= h2 == 1000000;
306 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
307 test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit);
316 class test_numpunct2 : public numpunct<char>
321 { return string("\002\003"); }
327 // manufactured locale, grouping is turned on
329 unsigned int h4 = 0, h3 = 0, h2 = 0;
331 const std::string s1("1,22 205,19 22,123,22");
332 const std::string s2("1,220 2050,19 202,123,22");
334 std::istringstream is(s1);
335 is.imbue(std::locale(std::locale(), new std::test_numpunct2));
349 test &= h2 == 2212322;
350 test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit);
363 std::string st("2.456e3-+0.567e-2");
364 std::stringbuf sb(st);
365 std::istream is(&sb);
366 double f1 = 0, f2 = 0;
372 test &= f2 == 0.00567;
382 std::string str_01("0 00 000 +0 + 0 - 0");
383 std::stringbuf isbuf_01(str_01);
384 std::istream is_01(&isbuf_01);
406 test &= is_01.rdstate() == std::ios_base::eofbit;
408 std::string str_02("0x32 0X33 033 33");
409 std::stringbuf isbuf_02(str_02);
410 std::istream is_02(&isbuf_02);
411 is_02.unsetf(std::ios_base::basefield);
420 test &= is_02.rdstate() == std::ios_base::eofbit;
422 std::stringbuf isbuf_03(str_02);
423 std::istream is_03(&isbuf_03);
427 is_03 >> std::dec >> n >> c >> m;
432 is_03 >> std::oct >> m >> c >> n;
437 is_03 >> std::dec >> m >> n;
440 test &= is_03.rdstate() == std::ios_base::eofbit;
442 std::string str_04("3. 4.5E+ 2a5E-3 .6E1");
443 std::stringbuf isbuf_04(str_04);
444 std::istream is_04(&isbuf_04);
456 test &= is_03.rdstate() == std::ios_base::eofbit;
458 std::string str_05("0E20 5Ea E16");
459 std::stringbuf isbuf_05(str_05);
460 std::istream is_05(&isbuf_05);
466 test &= is_05.rdstate() == std::ios_base::failbit;
472 test &= is_05.rdstate() == std::ios_base::failbit;
503 // paul miller was right on with riddim warfare!