]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/get/char/1.cc
3 // Copyright (C) 1999-2013 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
24 #include <testsuite_hooks.h>
29 typedef std::char_traits
<char> traits_type
;
31 bool test
__attribute__((unused
)) = true;
32 const char str_lit01
[] =
33 " sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n"
35 "jazz in silhouette: images and forecasts of tomorrow";
37 std::string
str01(str_lit01
);
40 std::stringbuf sbuf_03
;
41 std::stringbuf
sbuf_04(str01
, std::ios_base::in
);
42 std::stringbuf
sbuf_05(str01
, std::ios_base::in
);
44 std::istream
is_00(0);
45 std::istream
is_04(&sbuf_04
);
46 std::istream
is_05(&sbuf_05
);
47 std::ios_base::iostate statefail
, stateeof
;
48 statefail
= std::ios_base::failbit
;
49 stateeof
= std::ios_base::eofbit
;
50 char carray1
[400] = "";
53 // istream& get(char*, streamsize, char delim)
54 // istream& get(char*, streamsize)
55 // istream& get(streambuf&, char delim)
56 // istream& get(streambuf&)
57 is_00
.get(carray1
, 2);
58 VERIFY( static_cast<bool>(is_00
.rdstate() & statefail
) );
59 VERIFY( is_00
.gcount() == 0 );
61 is_04
.get(carray1
, 4);
62 VERIFY( !(is_04
.rdstate() & statefail
) );
63 VERIFY( !traits_type::compare(carray1
, " ", 4) );
64 VERIFY( is_04
.gcount() == 3 );
67 is_04
.get(carray1
+ 3, 200);
68 VERIFY( !(is_04
.rdstate() & statefail
) );
69 VERIFY( !(is_04
.rdstate() & stateeof
) );
70 VERIFY( !traits_type::compare(carray1
, str_lit01
, 10) );
71 VERIFY( is_04
.gcount() == 7 );
74 is_04
.get(carray1
, 200);
75 VERIFY( !(is_04
.rdstate() & stateeof
) );
76 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) ); // delimiter
77 VERIFY( is_04
.gcount() == 0 );
79 is_04
.get(carray1
, 200, '[');
80 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
81 VERIFY( !(is_04
.rdstate() & statefail
) );
82 VERIFY( is_04
.gcount() == 125 );
84 is_04
.get(carray1
, 200);
85 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
86 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) );
87 VERIFY( is_04
.gcount() == 0 );
89 std::stringbuf
sbuf_02(std::ios_base::in
);
92 VERIFY( is_05
.gcount() == 0 );
93 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );
94 VERIFY( !(is_05
.rdstate() & stateeof
) );
98 VERIFY( is_05
.gcount() == 10 );
99 VERIFY( sbuf_03
.str() == " sun*ra " );
100 VERIFY( !(is_05
.rdstate() & statefail
) );
101 VERIFY( !(is_05
.rdstate() & stateeof
) );
104 is_05
.get(sbuf_03
, '|');
105 VERIFY( is_05
.gcount() == 125 );
106 VERIFY( sbuf_03
.str() == str_lit01
);
107 VERIFY( !(is_05
.rdstate() & statefail
) );
108 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
111 is_05
.get(sbuf_03
, '|');
112 VERIFY( is_05
.gcount() == 0 );
113 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
114 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );