]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/1.cc
bc07efdc67858416eb6647bb7d6b23d4b5662748
1 // Copyright (C) 2004-2020 Free Software Foundation, Inc.
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)
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.
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/>.
18 // 27.6.1.2.3 basic_istream::operator>>
22 #include <testsuite_hooks.h>
27 typedef std::wios::traits_type ctraits_type
;
29 const std::wstring str_01
;
30 const std::wstring
str_02(L
"art taylor kickin it on DAKAR");
33 std::wstringbuf
isbuf_00(std::ios_base::in
);
34 std::wstringbuf
isbuf_01(std::ios_base::in
| std::ios_base::out
);
35 std::wstringbuf
isbuf_02(str_01
, std::ios_base::in
);
36 std::wstringbuf
isbuf_03(str_01
, std::ios_base::in
| std::ios_base::out
);
37 std::wstringbuf
isbuf_04(str_02
, std::ios_base::in
);
38 std::wstringbuf
isbuf_05(str_02
, std::ios_base::in
| std::ios_base::out
);
40 std::wistream
is_00(0);
41 std::wistream
is_01(&isbuf_01
);
42 std::wistream
is_02(&isbuf_02
);
43 std::wistream
is_03(&isbuf_03
);
44 std::wistream
is_04(&isbuf_04
);
45 std::wistream
is_05(&isbuf_05
);
46 std::ios_base::iostate state1
, state2
, statefail
, stateeof
;
47 statefail
= std::ios_base::failbit
;
48 stateeof
= std::ios_base::eofbit
;
51 // template<_CharT, _Traits>
52 // basic_istream& operator>>(basic_streambuf*)
54 // null istream to empty in_buf
55 state1
= is_00
.rdstate();
57 state2
= is_00
.rdstate();
58 VERIFY( state1
!= state2
);
59 VERIFY( static_cast<bool>(state2
& statefail
) );
60 VERIFY( isbuf_00
.str() == str_01
);
62 // null istream to empty in_out_buf
63 is_00
.clear(std::ios_base::goodbit
);
64 state1
= is_00
.rdstate();
66 state2
= is_00
.rdstate();
67 VERIFY( state1
!= state2
);
68 VERIFY( static_cast<bool>(state2
& statefail
) );
69 VERIFY( isbuf_01
.str() == str_01
);
71 // null istream to full in_buf
72 is_00
.clear(std::ios_base::goodbit
);
73 state1
= is_00
.rdstate();
75 state2
= is_00
.rdstate();
76 VERIFY( state1
!= state2
);
77 VERIFY( static_cast<bool>(state2
& statefail
) );
78 VERIFY( isbuf_04
.str() == str_02
);
80 // null istream to full in_out_buf
81 is_00
.clear(std::ios_base::goodbit
);
82 state1
= is_00
.rdstate();
84 state2
= is_00
.rdstate();
85 VERIFY( state1
!= state2
);
86 VERIFY( static_cast<bool>(state2
& statefail
) );
87 VERIFY( isbuf_05
.str() == str_02
);
89 // empty but non-null istream to full in_buf
90 state1
= is_02
.rdstate();
92 state2
= is_02
.rdstate();
93 VERIFY( state1
!= state2
);
94 VERIFY( static_cast<bool>(state2
& statefail
) );
95 VERIFY( isbuf_04
.str() == str_02
); // as only an "in" buffer
96 VERIFY( isbuf_04
.sgetc() == L
'a' );
98 // empty but non-null istream to full in_out_buf
99 is_02
.clear(std::ios_base::goodbit
);
100 state1
= is_02
.rdstate();
102 state2
= is_02
.rdstate();
103 VERIFY( state1
!= state2
);
104 VERIFY( static_cast<bool>(state2
& statefail
) );
105 VERIFY( isbuf_05
.str() == str_02
); // as only an "in" buffer
106 VERIFY( isbuf_05
.sgetc() == L
'a' );
108 // full istream to empty in_buf (need out_buf, you know?)
109 state1
= is_04
.rdstate();
111 state2
= is_04
.rdstate();
112 VERIFY( state1
!= state2
);
113 VERIFY( static_cast<bool>(state2
& statefail
) );
114 VERIFY( isbuf_02
.str() == str_01
); // as only an "in" buffer
115 VERIFY( isbuf_02
.sgetc() == ctraits_type::eof() );
116 VERIFY( is_04
.peek() == ctraits_type::eof() ); // as failed
118 // full istream to empty in_out_buf
119 is_04
.clear(std::ios_base::goodbit
);
120 state1
= is_04
.rdstate();
122 state2
= is_04
.rdstate();
123 VERIFY( state1
!= state2
);
124 VERIFY( !static_cast<bool>(state2
& statefail
) );
125 VERIFY( state2
== stateeof
);
126 strtmp
= isbuf_03
.str();
127 VERIFY( strtmp
== str_02
); // as only an "in" buffer
128 VERIFY( isbuf_03
.sgetc() == L
'a' );
129 VERIFY( is_04
.peek() == ctraits_type::eof() );