]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_arithmetic / wchar_t / 01.cc
1 // Copyright (C) 2004-2019 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 <cstdio> // for printf
21 #include <istream>
22 #include <sstream>
23 #include <locale>
24 #include <testsuite_hooks.h>
25
26 std::wstring str_01;
27 std::wstring str_02(L"true false 0 1 110001");
28 std::wstring str_03(L"-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5");
29 std::wstring str_04(L"0123");
30
31 std::wstringbuf isbuf_01(std::ios_base::in);
32 std::wstringbuf isbuf_02(str_02, std::ios_base::in);
33 std::wstringbuf isbuf_03(str_03, std::ios_base::in);
34 std::wstringbuf isbuf_04(str_04, std::ios_base::in);
35
36 std::wistream is_01(0);
37 std::wistream is_02(&isbuf_02);
38 std::wistream is_03(&isbuf_03);
39 std::wistream is_04(&isbuf_04);
40 std::wstringstream ss_01(str_01);
41
42 // minimal sanity check
43 void test01() {
44
45 // Integral Types:
46 bool b1 = false;
47 short s1 = 0;
48 int i1 = 0;
49 long l1 = 0;
50 unsigned short us1 = 0;
51 unsigned int ui1 = 0;
52 unsigned long ul1 = 0;
53
54 // Floating-point Types:
55 float f1 = 0;
56 double d1 = 0;
57 long double ld1 = 0;
58
59 // process alphanumeric versions of bool values
60 is_02.setf(std::ios_base::boolalpha);
61 is_02.flags();
62 is_02 >> b1;
63 VERIFY( b1 == 1 );
64 is_02 >> b1;
65 VERIFY( b1 == 0 );
66
67 // process numeric versions of of bool values
68 is_02.unsetf(std::ios_base::boolalpha);
69 is_02.flags();
70 is_02 >> b1;
71 VERIFY( b1 == 0 );
72 is_02 >> b1;
73 VERIFY( b1 == 1 );
74
75 // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"
76 is_03 >> l1;
77 VERIFY( l1 == -19999999 );
78 is_03 >> ul1;
79 VERIFY( ul1 == 777777 );
80 is_03 >> i1;
81 VERIFY( i1 == -234234 );
82 is_03 >> ui1;
83 VERIFY( ui1 == 233 );
84 is_03 >> s1;
85 VERIFY( s1 == -234 );
86 is_03 >> us1;
87 VERIFY( us1 == 33 );
88 is_03 >> b1;
89 VERIFY( b1 == 1 );
90 is_03 >> ld1;
91 VERIFY( ld1 == 66300.25 );
92 is_03 >> d1;
93 VERIFY( d1 == .315 );
94 is_03 >> f1;
95 VERIFY( f1 == 1.5 );
96
97 is_04 >> std::hex >> i1;
98 std::printf ("%d %d\n", i1, i1 == 0x123);
99 VERIFY( i1 == 0x123 );
100 std::printf ("%d %d\n", i1, i1 == 0x123);
101
102 // test void pointers
103 int i = 55;
104 void* po = &i;
105 void* pi;
106
107 ss_01 << po;
108 ss_01 >> pi;
109 std::printf ("%p %p\n", pi, po);
110 VERIFY( po == pi );
111 }
112
113 int main()
114 {
115 test01();
116 return 0;
117 }