Merged trunk at revision 161680 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / getline / char / 1.cc
blob48b245f9b96622ebe0dc81b8a9735a7328b050cf
1 // 1999-08-11 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010
4 // Free Software Foundation
5 //
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)
10 // any later version.
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
23 #include <istream>
24 #include <sstream>
25 #include <testsuite_hooks.h>
27 void
28 test02()
30 typedef std::char_traits<char> traits_type;
32 bool test __attribute__((unused)) = true;
33 const char str_lit01[] = "\t\t\t sun*ra \n"
34 " "
35 "and his myth science arkestra present\n"
36 " "
37 "angles and demons @ play\n"
38 " "
39 "the nubians of plutonia";
40 std::string str01(str_lit01);
41 std::string strtmp;
43 std::stringbuf sbuf_04(str01, std::ios_base::in);
45 std::istream is_00(0);
46 std::istream is_04(&sbuf_04);
47 std::ios_base::iostate state1, state2, statefail, stateeof;
48 statefail = std::ios_base::failbit;
49 stateeof = std::ios_base::eofbit;
50 char carray1[400] = "";
52 // istream& getline(char* s, streamsize n, char delim)
53 // istream& getline(char* s, streamsize n)
54 state1 = is_00.rdstate();
55 is_00.getline(carray1, 20, '*');
56 state2 = is_00.rdstate();
57 // make sure failbit was set, since we couldn't extract
58 // from the null streambuf...
59 VERIFY( state1 != state2 );
60 VERIFY( static_cast<bool>(state2 & statefail) );
62 VERIFY( is_04.gcount() == 0 );
63 state1 = is_04.rdstate();
64 is_04.getline(carray1, 1, '\t'); // extracts, throws away
65 state2 = is_04.rdstate();
66 VERIFY( is_04.gcount() == 1 );
67 VERIFY( state1 == state2 );
68 VERIFY( state1 == 0 );
69 VERIFY( !traits_type::compare("", carray1, 1) );
71 state1 = is_04.rdstate();
72 is_04.getline(carray1, 20, '*');
73 state2 = is_04.rdstate();
74 VERIFY( is_04.gcount() == 10 );
75 VERIFY( state1 == state2 );
76 VERIFY( state1 == 0 );
77 VERIFY( !traits_type::compare("\t\t sun", carray1, 10) );
79 state1 = is_04.rdstate();
80 is_04.getline(carray1, 20);
81 state2 = is_04.rdstate();
82 VERIFY( is_04.gcount() == 4 );
83 VERIFY( state1 == state2 );
84 VERIFY( state1 == 0 );
85 VERIFY( !traits_type::compare("ra ", carray1, 4) );
87 state1 = is_04.rdstate();
88 is_04.getline(carray1, 65);
89 state2 = is_04.rdstate();
90 VERIFY( is_04.gcount() == 64 );
91 VERIFY( state1 != state2 );
92 VERIFY( state2 == statefail );
93 VERIFY( !traits_type::compare(
94 " and his myth science arkestra presen",
95 carray1, 65) );
97 is_04.clear();
98 state1 = is_04.rdstate();
99 is_04.getline(carray1, 120, '|');
100 state2 = is_04.rdstate();
101 VERIFY( is_04.gcount() == 106 );
102 VERIFY( state1 != state2 );
103 VERIFY( state2 == stateeof );
105 is_04.clear();
106 state1 = is_04.rdstate();
107 is_04.getline(carray1, 100, '|');
108 state2 = is_04.rdstate();
109 VERIFY( is_04.gcount() == 0 );
110 VERIFY( state1 != state2 );
111 VERIFY( static_cast<bool>(state2 & stateeof) );
112 VERIFY( static_cast<bool>(state2 & statefail) );
115 int
116 main()
118 test02();
119 return 0;