]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/read/char/1.cc
3 // Copyright (C) 1999-2019 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.3 unformatted input functions
22 #include <cstring> // for strncmp,...
25 #include <testsuite_hooks.h>
30 const std::string
str_02("soul eyes: john coltrane quartet");
32 std::stringbuf
isbuf_03(str_02
, std::ios_base::in
);
33 std::stringbuf
isbuf_04(str_02
, std::ios_base::in
);
35 std::istream
is_00(0);
36 std::istream
is_03(&isbuf_03
);
37 std::istream
is_04(&isbuf_04
);
38 std::ios_base::iostate state1
, state2
, statefail
, stateeof
;
39 statefail
= std::ios_base::failbit
;
40 stateeof
= std::ios_base::eofbit
;
42 // istream& read(char_type* s, streamsize n)
44 state1
= is_04
.rdstate();
45 is_04
.read(carray
, 0);
46 state2
= is_04
.rdstate();
47 VERIFY( state1
== state2
);
49 state1
= is_04
.rdstate();
50 is_04
.read(carray
, 9);
51 state2
= is_04
.rdstate();
52 VERIFY( state1
== state2
);
53 VERIFY( !std::strncmp(carray
, "soul eyes", 9) );
54 VERIFY( is_04
.peek() == ':' );
56 state1
= is_03
.rdstate();
57 is_03
.read(carray
, 60);
58 state2
= is_03
.rdstate();
59 VERIFY( state1
!= state2
);
60 VERIFY( static_cast<bool>(state2
& stateeof
) );
61 VERIFY( static_cast<bool>(state2
& statefail
) );
62 VERIFY( !std::strncmp(carray
, "soul eyes: john coltrane quartet", 35) );