]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/1.cc
3 // Copyright (C) 1999-2024 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 27.6.1.2.3 basic_istream::operator>>
24 #include <testsuite_hooks.h>
29 typedef std::ios::traits_type ctraits_type
;
31 const std::string str_01
;
32 const std::string
str_02("art taylor kickin it on DAKAR");
35 std::stringbuf
isbuf_00(std::ios_base::in
);
36 std::stringbuf
isbuf_01(std::ios_base::in
| std::ios_base::out
);
37 std::stringbuf
isbuf_02(str_01
, std::ios_base::in
);
38 std::stringbuf
isbuf_03(str_01
, std::ios_base::in
| std::ios_base::out
);
39 std::stringbuf
isbuf_04(str_02
, std::ios_base::in
);
40 std::stringbuf
isbuf_05(str_02
, std::ios_base::in
| std::ios_base::out
);
42 std::istream
is_00(0);
43 std::istream
is_01(&isbuf_01
);
44 std::istream
is_02(&isbuf_02
);
45 std::istream
is_03(&isbuf_03
);
46 std::istream
is_04(&isbuf_04
);
47 std::istream
is_05(&isbuf_05
);
48 std::ios_base::iostate state1
, state2
, statefail
, stateeof
;
49 statefail
= std::ios_base::failbit
;
50 stateeof
= std::ios_base::eofbit
;
53 // template<_CharT, _Traits>
54 // basic_istream& operator>>(basic_streambuf*)
56 // null istream to empty in_buf
57 state1
= is_00
.rdstate();
59 state2
= is_00
.rdstate();
60 VERIFY( state1
!= state2
);
61 VERIFY( static_cast<bool>(state2
& statefail
) );
62 VERIFY( isbuf_00
.str() == str_01
);
64 // null istream to empty in_out_buf
65 is_00
.clear(std::ios_base::goodbit
);
66 state1
= is_00
.rdstate();
68 state2
= is_00
.rdstate();
69 VERIFY( state1
!= state2
);
70 VERIFY( static_cast<bool>(state2
& statefail
) );
71 VERIFY( isbuf_01
.str() == str_01
);
73 // null istream to full in_buf
74 is_00
.clear(std::ios_base::goodbit
);
75 state1
= is_00
.rdstate();
77 state2
= is_00
.rdstate();
78 VERIFY( state1
!= state2
);
79 VERIFY( static_cast<bool>(state2
& statefail
) );
80 VERIFY( isbuf_04
.str() == str_02
);
82 // null istream to full in_out_buf
83 is_00
.clear(std::ios_base::goodbit
);
84 state1
= is_00
.rdstate();
86 state2
= is_00
.rdstate();
87 VERIFY( state1
!= state2
);
88 VERIFY( static_cast<bool>(state2
& statefail
) );
89 VERIFY( isbuf_05
.str() == str_02
);
91 // empty but non-null istream to full in_buf
92 state1
= is_02
.rdstate();
94 state2
= is_02
.rdstate();
95 VERIFY( state1
!= state2
);
96 VERIFY( static_cast<bool>(state2
& statefail
) );
97 VERIFY( isbuf_04
.str() == str_02
); // as only an "in" buffer
98 VERIFY( isbuf_04
.sgetc() == 'a' );
100 // empty but non-null istream to full in_out_buf
101 is_02
.clear(std::ios_base::goodbit
);
102 state1
= is_02
.rdstate();
104 state2
= is_02
.rdstate();
105 VERIFY( state1
!= state2
);
106 VERIFY( static_cast<bool>(state2
& statefail
) );
107 VERIFY( isbuf_05
.str() == str_02
); // as only an "in" buffer
108 VERIFY( isbuf_05
.sgetc() == 'a' );
110 // full istream to empty in_buf (need out_buf, you know?)
111 state1
= is_04
.rdstate();
113 state2
= is_04
.rdstate();
114 VERIFY( state1
!= state2
);
115 VERIFY( static_cast<bool>(state2
& statefail
) );
116 VERIFY( isbuf_02
.str() == str_01
); // as only an "in" buffer
117 VERIFY( isbuf_02
.sgetc() == ctraits_type::eof() );
118 VERIFY( is_04
.peek() == ctraits_type::eof() ); // as failed
120 // full istream to empty in_out_buf
121 is_04
.clear(std::ios_base::goodbit
);
122 state1
= is_04
.rdstate();
124 state2
= is_04
.rdstate();
125 VERIFY( state1
!= state2
);
126 VERIFY( !static_cast<bool>(state2
& statefail
) );
127 VERIFY( state2
== stateeof
);
128 strtmp
= isbuf_03
.str();
129 VERIFY( strtmp
== str_02
); // as only an "in" buffer
130 VERIFY( isbuf_03
.sgetc() == 'a' );
131 VERIFY( is_04
.peek() == ctraits_type::eof() );