Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_arithmetic / wchar_t / 10.cc
1 // Copyright (C) 2004-2013 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 3, 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 COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 27.6.1.2.2 arithmetic extractors
19
20 #include <istream>
21 #include <sstream>
22 #include <locale>
23 #include <testsuite_hooks.h>
24
25 bool test10()
26 {
27   std::wstring str_01(L"0 00 000 +0 +0 -0");
28   std::wstringbuf isbuf_01(str_01);
29   std::wistream is_01(&isbuf_01);
30
31   bool test __attribute__((unused)) = true;
32
33   int n = 365;
34   is_01 >> n;
35   VERIFY( n == 0 );
36   n = 364;
37   is_01 >> n;
38   VERIFY( n == 0 );
39   n = 363;
40   is_01 >> n;
41   VERIFY( n == 0 );
42   n = 362;
43   is_01 >> n;
44   VERIFY( n == 0 );
45   n = 361;
46   is_01 >> n;
47   VERIFY( n == 0 );
48   n = 360;
49   is_01 >> n;
50   VERIFY( n == 0 );
51   VERIFY( is_01.rdstate() == std::ios_base::eofbit );
52
53   std::wstring str_02(L"0x32 0X33 033 33");
54   std::wstringbuf isbuf_02(str_02);
55   std::wistream is_02(&isbuf_02);
56   is_02.unsetf(std::ios_base::basefield);
57   is_02 >> n;
58   VERIFY( n == 50 );
59   is_02 >> n;
60   VERIFY( n == 51 );
61   is_02 >> n;
62   VERIFY( n == 27 );
63   is_02 >> n;
64   VERIFY( n == 33 );
65   VERIFY( is_02.rdstate() == std::ios_base::eofbit );
66
67   std::wstringbuf isbuf_03(str_02);
68   std::wistream is_03(&isbuf_03);
69   wchar_t c;
70   int m;
71
72   is_03 >> std::dec >> n >> c >> m;
73   VERIFY( n == 0 );
74   VERIFY( c == L'x' );
75   VERIFY( m == 32 );
76
77   is_03 >> std::oct >> m >> c >> n;
78   VERIFY( m == 0 );
79   VERIFY( c == L'X' );
80   VERIFY( n == 27 );
81
82   is_03 >> std::dec >> m >> n;
83   VERIFY( m == 33 );
84   VERIFY( n == 33 );
85   VERIFY( is_03.rdstate() == std::ios_base::eofbit );
86
87   std::wstring str_04(L"3. 4.5E+2a5E-3 .6E1");
88   std::wstringbuf isbuf_04(str_04);
89   std::wistream is_04(&isbuf_04);
90
91   double f;
92   is_04 >> f;
93   VERIFY( f == 3.0 );
94   is_04 >> f;
95   VERIFY( f == 450.0 );
96   is_04.ignore();
97   is_04 >> f;
98   VERIFY( f == 0.005 );
99   is_04 >> f;
100   VERIFY( f == 6 );
101   VERIFY( is_03.rdstate() == std::ios_base::eofbit );
102
103   std::wstring str_05(L"0E20 5Ea E16");
104   std::wstringbuf isbuf_05(str_05);
105   std::wistream is_05(&isbuf_05);
106
107   is_05 >> f;
108   VERIFY( f == 0 );
109   f = 1;
110   is_05 >> f;
111   VERIFY( f == 0 );
112   VERIFY( is_05.rdstate() == std::ios_base::failbit );
113   is_05.clear();
114   is_05 >> c;
115   VERIFY( c == L'a' );
116   f = 1;
117   is_05 >> f;
118   VERIFY( f == 0 );
119   VERIFY( is_05.rdstate() == std::ios_base::failbit );
120   is_05.clear();
121   is_05.ignore();
122   is_05 >> n;
123   VERIFY( n == 16 );
124   return test;
125 }
126
127 int main()
128 {
129   test10();
130   return 0;
131 }