3 // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 27.6.1.3 unformatted input functions
22 // @require@ %-*.tst %-*.txt
23 // @diff@ %-*.tst %-*.txt
25 #include <cstring> // for strncmp,...
29 #include <testsuite_hooks.h>
34 typedef std::char_traits
<char> traits_type
;
36 bool test
__attribute__((unused
)) = true;
37 const char str_lit01
[] =
38 " sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n"
40 "jazz in silhouette: images and forecasts of tomorrow";
42 std::string
str01(str_lit01
);
45 std::stringbuf sbuf_03
;
46 std::stringbuf
sbuf_04(str01
, std::ios_base::in
);
47 std::stringbuf
sbuf_05(str01
, std::ios_base::in
);
49 std::istream
is_00(NULL
);
50 std::istream
is_04(&sbuf_04
);
51 std::istream
is_05(&sbuf_05
);
52 std::ios_base::iostate statefail
, stateeof
;
53 statefail
= std::ios_base::failbit
;
54 stateeof
= std::ios_base::eofbit
;
55 char carray1
[400] = "";
58 // istream& get(char*, streamsize, char delim)
59 // istream& get(char*, streamsize)
60 // istream& get(streambuf&, char delim)
61 // istream& get(streambuf&)
62 is_00
.get(carray1
, 2);
63 VERIFY( static_cast<bool>(is_00
.rdstate() & statefail
) );
64 VERIFY( is_00
.gcount() == 0 );
66 is_04
.get(carray1
, 4);
67 VERIFY( !(is_04
.rdstate() & statefail
) );
68 VERIFY( !traits_type::compare(carray1
, " ", 4) );
69 VERIFY( is_04
.gcount() == 3 );
72 is_04
.get(carray1
+ 3, 200);
73 VERIFY( !(is_04
.rdstate() & statefail
) );
74 VERIFY( !(is_04
.rdstate() & stateeof
) );
75 VERIFY( !traits_type::compare(carray1
, str_lit01
, 10) );
76 VERIFY( is_04
.gcount() == 7 );
79 is_04
.get(carray1
, 200);
80 VERIFY( !(is_04
.rdstate() & stateeof
) );
81 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) ); // delimiter
82 VERIFY( is_04
.gcount() == 0 );
84 is_04
.get(carray1
, 200, '[');
85 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
86 VERIFY( !(is_04
.rdstate() & statefail
) );
87 VERIFY( is_04
.gcount() == 125 );
89 is_04
.get(carray1
, 200);
90 VERIFY( static_cast<bool>(is_04
.rdstate() & stateeof
) );
91 VERIFY( static_cast<bool>(is_04
.rdstate() & statefail
) );
92 VERIFY( is_04
.gcount() == 0 );
94 std::stringbuf
sbuf_02(std::ios_base::in
);
97 VERIFY( is_05
.gcount() == 0 );
98 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );
99 VERIFY( !(is_05
.rdstate() & stateeof
) );
103 VERIFY( is_05
.gcount() == 10 );
104 VERIFY( sbuf_03
.str() == " sun*ra " );
105 VERIFY( !(is_05
.rdstate() & statefail
) );
106 VERIFY( !(is_05
.rdstate() & stateeof
) );
109 is_05
.get(sbuf_03
, '|');
110 VERIFY( is_05
.gcount() == 125 );
111 VERIFY( sbuf_03
.str() == str_lit01
);
112 VERIFY( !(is_05
.rdstate() & statefail
) );
113 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
116 is_05
.get(sbuf_03
, '|');
117 VERIFY( is_05
.gcount() == 0 );
118 VERIFY( static_cast<bool>(is_05
.rdstate() & stateeof
) );
119 VERIFY( static_cast<bool>(is_05
.rdstate() & statefail
) );