1// Copyright (C) 2004 Free Software Foundation, Inc.
2//
3// This file is part of the GNU ISO C++ Library.  This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 2, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING.  If not, write to the Free
16// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17// USA.
18
19// 27.6.1.2.2 arithmetic extractors
20
21#include <cstdio> // for printf
22#include <istream>
23#include <sstream>
24#include <locale>
25#include <testsuite_hooks.h>
26
27std::wstring str_01;
28std::wstring str_02(L"true false 0 1 110001");
29std::wstring str_03(L"-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5");
30std::wstring str_04(L"0123");
31
32std::wstringbuf isbuf_01(std::ios_base::in);
33std::wstringbuf isbuf_02(str_02, std::ios_base::in);
34std::wstringbuf isbuf_03(str_03, std::ios_base::in);
35std::wstringbuf isbuf_04(str_04, std::ios_base::in);
36
37std::wistream is_01(NULL);
38std::wistream is_02(&isbuf_02);
39std::wistream is_03(&isbuf_03);
40std::wistream is_04(&isbuf_04);
41std::wstringstream ss_01(str_01);
42
43// minimal sanity check
44bool test01() {
45
46  bool test __attribute__((unused)) = true;
47
48  // Integral Types:
49  bool 			b1  = false;
50  short 		s1  = 0;
51  int	 		i1  = 0;
52  long	 		l1  = 0;
53  unsigned short 	us1 = 0;
54  unsigned int 		ui1 = 0;
55  unsigned long 	ul1 = 0;
56
57  // Floating-point Types:
58  float 		f1  = 0;
59  double 		d1  = 0;
60  long double 		ld1 = 0;
61
62  // process alphanumeric versions of bool values
63  std::ios_base::fmtflags fmt = is_02.flags();
64  bool testfmt = fmt & std::ios_base::boolalpha;
65  is_02.setf(std::ios_base::boolalpha);
66  fmt = is_02.flags();
67  testfmt = fmt & std::ios_base::boolalpha;
68  is_02 >> b1;
69  VERIFY( b1 == 1 );
70  is_02 >> b1;
71  VERIFY( b1 == 0 );
72
73  // process numeric versions of of bool values
74  is_02.unsetf(std::ios_base::boolalpha);
75  fmt = is_02.flags();
76  testfmt = fmt & std::ios_base::boolalpha;
77  is_02 >> b1;
78  VERIFY( b1 == 0 );
79  is_02 >> b1;
80  VERIFY( b1 == 1 );
81
82  // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"
83  is_03 >> l1;
84  VERIFY( l1 == -19999999 );
85  is_03 >> ul1;
86  VERIFY( ul1 == 777777 );
87  is_03 >> i1;
88  VERIFY( i1 == -234234 );
89  is_03 >> ui1;
90  VERIFY( ui1 == 233 );
91  is_03 >> s1;
92  VERIFY( s1 == -234 );
93  is_03 >> us1;
94  VERIFY( us1 == 33 );
95  is_03 >> b1;
96  VERIFY( b1 == 1 );
97  is_03 >> ld1;
98  VERIFY( ld1 == 66300.25 );
99  is_03 >> d1;
100  VERIFY( d1 == .315 );
101  is_03 >> f1;
102  VERIFY( f1 == 1.5 );
103
104  is_04 >> std::hex >> i1;
105  std::printf ("%d %d %d\n", i1, i1 == 0x123, test);
106  VERIFY( i1 == 0x123 );
107  std::printf ("%d %d %d\n", i1, i1 == 0x123, test);
108
109  // test void pointers
110  int i = 55;
111  void* po = &i;
112  void* pi;
113
114  ss_01 << po;
115  ss_01 >> pi;
116  std::printf ("%p %p\n", pi, po);
117  VERIFY( po == pi );
118  return test;
119}
120
121int main()
122{
123  test01();
124  return 0;
125}
126