]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/3.cc
3 // Copyright (C) 1999, 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.2.3 character extractors
25 #include <testsuite_hooks.h>
31 const std::string
str_02("coltrane playing 'softly as a morning sunrise'");
32 const std::string
str_03("coltrane");
34 std::stringbuf
isbuf_01(std::ios_base::in
);
35 std::stringbuf
isbuf_02(str_02
, std::ios_base::in
);
36 std::istream
is_01(NULL
);
37 std::istream
is_02(&isbuf_02
);
39 std::ios_base::iostate state1
, state2
, statefail
;
40 statefail
= std::ios_base::failbit
;
42 // template<_CharT, _Traits>
43 // basic_istream& operator>>(istream&, _CharT*)
46 typedef std::ios::traits_type ctraits_type
;
47 ctraits_type::int_type i1
, i2
;
49 // testing with width() control enabled.
51 state1
= is_02
.rdstate();
52 is_02
>> array1
; // should snake "coltran"
53 state2
= is_02
.rdstate();
54 VERIFY( state1
== state2
);
55 VERIFY( !ctraits_type::compare(array1
, "coltran", 7) );
58 state1
= is_02
.rdstate();
59 is_02
>> array1
; // should snake nothing, set failbit
60 state2
= is_02
.rdstate();
61 VERIFY( state1
!= state2
);
62 VERIFY( state2
== statefail
);
63 VERIFY( array1
[0] == '\0' );
67 state1
= is_02
.rdstate();
69 is_02
>> array1
; // should snake "e"
70 state2
= is_02
.rdstate();
71 VERIFY( state1
== state2
);
72 VERIFY( !ctraits_type::compare(array1
, "e", 1) );
74 // testing for correct exception setting
75 const std::string
str_04(" impulse!!");
76 std::stringbuf
isbuf_03(str_04
, std::ios_base::in
);
77 std::stringbuf
isbuf_04(str_04
, std::ios_base::in
);
78 std::istream
is_03(&isbuf_03
);
79 std::istream
is_04(&isbuf_04
);
82 VERIFY( !ctraits_type::compare(array1
,"impulse!!", 10) );
83 VERIFY( is_03
.rdstate() == std::ios_base::eofbit
);
87 VERIFY( ! std::ios::traits_type::compare(array1
,"impulse!", 9) );
88 VERIFY( !is_04
.rdstate() );