3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010
4 // Free Software Foundation
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // 27.6.1.3 unformatted input functions
25 #include <testsuite_hooks.h>
30 typedef std::char_traits
<char> traits_type
;
32 bool test
__attribute__((unused
)) = true;
33 const char str_lit01
[] =
34 " sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n"
36 "jazz in silhouette: images and forecasts of tomorrow";
38 std::string
str01(str_lit01
);
41 std::stringbuf sbuf_03
;
42 std::stringbuf
sbuf_04(str01
, std::ios_base::in
);
43 std::stringbuf
sbuf_05(str01
, std::ios_base::in
);
45 std::istream
is_00(0);
46 std::istream
is_04(&sbuf_04
);
47 std::istream
is_05(&sbuf_05
);
48 std::ios_base::iostate statefail
, stateeof
;
49 statefail
= std::ios_base::failbit
;
50 stateeof
= std::ios_base::eofbit
;
51 char carray1
[400] = "";
54 // istream& get(char*, streamsize, char delim)
55 // istream& get(char*, streamsize)
56 // istream& get(streambuf&, char delim)
57 // istream& get(streambuf&)
58 is_00
.get(carray1
, 2);
59 VERIFY( static_cast<bool>(is_00
.rdstate() & statefail
) );
60 VERIFY( is_00
.gcount() == 0 );
62 is_04
.get(carray1
, 4);
63 VERIFY( !(is_04
.rdstate() & statefail
) );
64 VERIFY( !traits_type::compare(carray1
, " ", 4) );
65 VERIFY( is_04
.gcount() == 3 );
68 is_04
.get(carray1
+ 3, 200);
69 VERIFY( !(is_04
.rdstate() & statefail
) );
70 VERIFY( !(is_04
.rdstate() & stateeof
) );
71 VERIFY( !traits_type::compare(carray1
, str_lit01
, 10) );
72 VERIFY( is_04
.gcount() == 7 );
75 is_04
.get(carray1
, 200);
76 VERIFY( !(is_04
.rdstate() & stateeof
) );
77 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) ); // delimiter
78 VERIFY( is_04
.gcount() == 0 );
80 is_04
.get(carray1
, 200, '[');
81 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
82 VERIFY( !(is_04
.rdstate() & statefail
) );
83 VERIFY( is_04
.gcount() == 125 );
85 is_04
.get(carray1
, 200);
86 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
87 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) );
88 VERIFY( is_04
.gcount() == 0 );
90 std::stringbuf
sbuf_02(std::ios_base::in
);
93 VERIFY( is_05
.gcount() == 0 );
94 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );
95 VERIFY( !(is_05
.rdstate() & stateeof
) );
99 VERIFY( is_05
.gcount() == 10 );
100 VERIFY( sbuf_03
.str() == " sun*ra " );
101 VERIFY( !(is_05
.rdstate() & statefail
) );
102 VERIFY( !(is_05
.rdstate() & stateeof
) );
105 is_05
.get(sbuf_03
, '|');
106 VERIFY( is_05
.gcount() == 125 );
107 VERIFY( sbuf_03
.str() == str_lit01
);
108 VERIFY( !(is_05
.rdstate() & statefail
) );
109 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
112 is_05
.get(sbuf_03
, '|');
113 VERIFY( is_05
.gcount() == 0 );
114 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
115 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );