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");
34 std::string str_04("0123");
36 std::stringbuf isbuf_01(std::ios_base::in);
37 std::stringbuf isbuf_02(str_02, std::ios_base::in);
38 std::stringbuf isbuf_03(str_03, std::ios_base::in);
39 std::stringbuf isbuf_04(str_04, std::ios_base::in);
41 std::istream is_01(NULL);
42 std::istream is_02(&isbuf_02);
43 std::istream is_03(&isbuf_03);
44 std::istream is_04(&isbuf_04);
45 std::stringstream ss_01(str_01);
47 // minimal sanity check
58 unsigned short us1 = 0;
60 unsigned long ul1 = 0;
62 // Floating-point Types:
67 // process alphanumeric versions of bool values
68 std::ios_base::fmtflags fmt = is_02.flags();
69 bool testfmt = fmt & std::ios_base::boolalpha;
70 is_02.setf(std::ios_base::boolalpha);
72 testfmt = fmt & std::ios_base::boolalpha;
78 // process numeric versions of of bool values
79 is_02.unsetf(std::ios_base::boolalpha);
81 testfmt = fmt & std::ios_base::boolalpha;
87 // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"
89 test &= l1 == -19999999;
91 test &= ul1 == 777777;
93 test &= i1 == -234234;
103 test &= ld1 == 66300.25;
109 is_04 >> std::hex >> i1;
110 printf ("%d %d %d\n", i1, i1 == 0x123, test);
112 printf ("%d %d %d\n", i1, i1 == 0x123, test);
114 // test void pointers
121 printf ("%x %x\n", pi, po);
131 // elaborated test for ints
135 const std::string str_01("20000AB");
136 std::stringbuf strb_01(str_01, std::ios_base::in);
137 std::istream is(&strb_01);
155 std::istream istr(&sbuf);
156 std::ostream ostr(&sbuf);
161 istr >> l01; // _M_in_end set completely incorrectly here.
162 test &= l01 == 12220101;
163 test &= istr.rdstate() == std::ios_base::eofbit;
172 // http://sourceware.cygnus.com/ml/libstdc++/2000-q1/msg00081.html
176 // default locale, grouping is turned off
178 unsigned int h4, h3, h2;
180 std::string s("205,199,144");
181 std::istringstream is(s);
194 test &= is.rdstate() == std::ios_base::eofbit;
198 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
206 class test_numpunct1 : public numpunct<char>
211 { return string(1, '\003'); }
217 // manufactured locale, grouping is turned on
219 unsigned int h4 = 0, h3 = 0, h2 = 0;
221 const std::string s1("205,199 23,445.25 1,024,365 123,22,24");
222 std::istringstream is(s1);
223 is.imbue(std::locale(std::locale(), new std::test_numpunct1));
227 test &= h4 == 205199;
232 test &= f1 == 23445.25;
237 test &= h3 == 1024365;
243 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
244 test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit);
246 // Stress tests for explicit errors in grouping corner cases. The
247 // validity of these tests and results have been hammered out in
248 // private email between bkoz and ncm between Jan 25 and Jan 27, 2000.
249 // Thanks nate -- benjamin
250 const std::string s2(",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567");
253 const char c_control = '?';
260 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
269 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
297 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
300 test &= c == ','; // second one
305 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
309 test &= h2 == 1000000;
315 test &= static_cast<bool>(is.rdstate() & std::ios_base::failbit);
316 test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit);
325 class test_numpunct2 : public numpunct<char>
330 { return string("\002\003"); }
336 // manufactured locale, grouping is turned on
338 unsigned int h4 = 0, h3 = 0, h2 = 0;
340 const std::string s1("1,22 205,19 22,123,22");
341 const std::string s2("1,220 2050,19 202,123,22");
343 std::istringstream is(s1);
344 is.imbue(std::locale(std::locale(), new std::test_numpunct2));
358 test &= h2 == 2212322;
359 test &= static_cast<bool>(is.rdstate() & std::ios_base::eofbit);
372 std::string st("2.456e3-+0.567e-2");
373 std::stringbuf sb(st);
374 std::istream is(&sb);
375 double f1 = 0, f2 = 0;
381 test &= f2 == 0.00567;
391 std::string str_01("0 00 000 +0 + 0 - 0");
392 std::stringbuf isbuf_01(str_01);
393 std::istream is_01(&isbuf_01);
415 test &= is_01.rdstate() == std::ios_base::eofbit;
417 std::string str_02("0x32 0X33 033 33");
418 std::stringbuf isbuf_02(str_02);
419 std::istream is_02(&isbuf_02);
420 is_02.unsetf(std::ios_base::basefield);
429 test &= is_02.rdstate() == std::ios_base::eofbit;
431 std::stringbuf isbuf_03(str_02);
432 std::istream is_03(&isbuf_03);
436 is_03 >> std::dec >> n >> c >> m;
441 is_03 >> std::oct >> m >> c >> n;
446 is_03 >> std::dec >> m >> n;
449 test &= is_03.rdstate() == std::ios_base::eofbit;
451 std::string str_04("3. 4.5E+ 2a5E-3 .6E1");
452 std::stringbuf isbuf_04(str_04);
453 std::istream is_04(&isbuf_04);
465 test &= is_03.rdstate() == std::ios_base::eofbit;
467 std::string str_05("0E20 5Ea E16");
468 std::stringbuf isbuf_05(str_05);
469 std::istream is_05(&isbuf_05);
475 test &= is_05.rdstate() == std::ios_base::failbit;
481 test &= is_05.rdstate() == std::ios_base::failbit;
512 // paul miller was right on with riddim warfare!