]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/3.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_character / char / 3.cc
CommitLineData
23cac885
BK
1// 1999-07-26 bkoz
2
748086b7 3// Copyright (C) 1999, 2003, 2009 Free Software Foundation
23cac885
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
23cac885
BK
9// any later version.
10
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.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
23cac885
BK
19
20// 27.6.1.2.3 character extractors
21
22#include <istream>
23#include <sstream>
24#include <testsuite_hooks.h>
25
26void test01()
27{
11f10e6b 28 bool test __attribute__((unused)) = true;
23cac885
BK
29 std::string str_01;
30 const std::string str_02("coltrane playing 'softly as a morning sunrise'");
31 const std::string str_03("coltrane");
32
33 std::stringbuf isbuf_01(std::ios_base::in);
34 std::stringbuf isbuf_02(str_02, std::ios_base::in);
35 std::istream is_01(NULL);
36 std::istream is_02(&isbuf_02);
37
38 std::ios_base::iostate state1, state2, statefail;
39 statefail = std::ios_base::failbit;
40
41 // template<_CharT, _Traits>
42 // basic_istream& operator>>(istream&, _CharT*)
43 int n = 20;
44 char array1[n];
45 typedef std::ios::traits_type ctraits_type;
23cac885
BK
46
47 // testing with width() control enabled.
48 is_02.width(8);
49 state1 = is_02.rdstate();
50 is_02 >> array1; // should snake "coltran"
51 state2 = is_02.rdstate();
52 VERIFY( state1 == state2 );
53 VERIFY( !ctraits_type::compare(array1, "coltran", 7) );
54
55 is_02.width(1);
56 state1 = is_02.rdstate();
57 is_02 >> array1; // should snake nothing, set failbit
58 state2 = is_02.rdstate();
59 VERIFY( state1 != state2 );
60 VERIFY( state2 == statefail );
61 VERIFY( array1[0] == '\0' );
62
63 is_02.width(8);
64 is_02.clear();
65 state1 = is_02.rdstate();
66 VERIFY( !state1 );
67 is_02 >> array1; // should snake "e"
68 state2 = is_02.rdstate();
69 VERIFY( state1 == state2 );
70 VERIFY( !ctraits_type::compare(array1, "e", 1) );
71
72 // testing for correct exception setting
73 const std::string str_04(" impulse!!");
74 std::stringbuf isbuf_03(str_04, std::ios_base::in);
75 std::stringbuf isbuf_04(str_04, std::ios_base::in);
76 std::istream is_03(&isbuf_03);
77 std::istream is_04(&isbuf_04);
78
79 is_03 >> array1;
80 VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) );
81 VERIFY( is_03.rdstate() == std::ios_base::eofbit );
82
83 is_04.width(9);
84 is_04 >> array1;
85 VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) );
86 VERIFY( !is_04.rdstate() );
87}
88
89int main()
90{
91 test01();
92 return 0;
93}