Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / testsuite / 27_io / basic_istream / getline / char / 2.cc
blob5fd79929811e9d408535addbea03127ae9e5bfd0
1 // 1999-08-11 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // 27.6.1.3 unformatted input functions
23 #include <cstring> // for strlen
24 #include <istream>
25 #include <sstream>
26 #include <testsuite_hooks.h>
28 // [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type)
29 // http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html
30 void
31 test05()
33 const char* charray = "\n"
34 "a\n"
35 "aa\n"
36 "aaa\n"
37 "aaaa\n"
38 "aaaaa\n"
39 "aaaaaa\n"
40 "aaaaaaa\n"
41 "aaaaaaaa\n"
42 "aaaaaaaaa\n"
43 "aaaaaaaaaa\n"
44 "aaaaaaaaaaa\n"
45 "aaaaaaaaaaaa\n"
46 "aaaaaaaaaaaaa\n"
47 "aaaaaaaaaaaaaa\n";
49 bool test __attribute__((unused)) = true;
50 const std::streamsize it = 5;
51 std::streamsize br = 0;
52 char tmp[it];
53 std::stringbuf sb(charray, std::ios_base::in);
54 std::istream ifs(&sb);
55 std::streamsize blen = std::strlen(charray);
56 VERIFY(!(!ifs));
57 while(ifs.getline(tmp, it) || ifs.gcount())
59 br += ifs.gcount();
60 if(ifs.eof())
62 // Just sanity checks to make sure we've extracted the same
63 // number of chars that were in the streambuf
64 VERIFY(br == blen);
65 // Also, we should only set the failbit if we could
66 // _extract_ no chars from the stream, i.e. the first read
67 // returned EOF.
68 VERIFY(ifs.fail() && ifs.gcount() == 0);
70 else if(ifs.fail())
72 // delimiter not read
74 // either
75 // -> extracted no characters
76 // or
77 // -> n - 1 characters are stored
78 ifs.clear(ifs.rdstate() & ~std::ios::failbit);
79 VERIFY((ifs.gcount() == 0) || (std::strlen(tmp) == it - 1));
80 VERIFY(!(!ifs));
81 continue;
83 else
85 // delimiter was read.
87 // -> strlen(__s) < n - 1
88 // -> delimiter was seen -> gcount() > strlen(__s)
89 VERIFY(ifs.gcount() == static_cast<std::streamsize>(std::strlen(tmp) + 1) );
90 continue;
95 int
96 main()
98 test05();
99 return 0;