2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_character / char / 3.cc
blob5e0ca5583eafcdb1d2f375c2cbe7330e265e5f45
1 // 1999-07-26 bkoz
3 // Copyright (C) 1999, 2003 Free Software Foundation
4 //
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)
9 // any later version.
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,
19 // USA.
21 // 27.6.1.2.3 character extractors
23 #include <istream>
24 #include <sstream>
25 #include <testsuite_hooks.h>
27 void test01()
29 bool test __attribute__((unused)) = true;
30 std::string str_01;
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*)
44 int n = 20;
45 char array1[n];
46 typedef std::ios::traits_type ctraits_type;
48 // testing with width() control enabled.
49 is_02.width(8);
50 state1 = is_02.rdstate();
51 is_02 >> array1; // should snake "coltran"
52 state2 = is_02.rdstate();
53 VERIFY( state1 == state2 );
54 VERIFY( !ctraits_type::compare(array1, "coltran", 7) );
56 is_02.width(1);
57 state1 = is_02.rdstate();
58 is_02 >> array1; // should snake nothing, set failbit
59 state2 = is_02.rdstate();
60 VERIFY( state1 != state2 );
61 VERIFY( state2 == statefail );
62 VERIFY( array1[0] == '\0' );
64 is_02.width(8);
65 is_02.clear();
66 state1 = is_02.rdstate();
67 VERIFY( !state1 );
68 is_02 >> array1; // should snake "e"
69 state2 = is_02.rdstate();
70 VERIFY( state1 == state2 );
71 VERIFY( !ctraits_type::compare(array1, "e", 1) );
73 // testing for correct exception setting
74 const std::string str_04(" impulse!!");
75 std::stringbuf isbuf_03(str_04, std::ios_base::in);
76 std::stringbuf isbuf_04(str_04, std::ios_base::in);
77 std::istream is_03(&isbuf_03);
78 std::istream is_04(&isbuf_04);
80 is_03 >> array1;
81 VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) );
82 VERIFY( is_03.rdstate() == std::ios_base::eofbit );
84 is_04.width(9);
85 is_04 >> array1;
86 VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) );
87 VERIFY( !is_04.rdstate() );
90 int main()
92 test01();
93 return 0;