summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_istream/getline
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_istream/getline')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc120
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc99
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc60
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc99
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc88
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc57
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc117
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc98
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc58
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc103
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc88
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc57
12 files changed, 1044 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc
new file mode 100644
index 000000000..48b245f9b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc
@@ -0,0 +1,120 @@
+// 1999-08-11 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010
+// Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test02()
+{
+ typedef std::char_traits<char> traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const char str_lit01[] = "\t\t\t sun*ra \n"
+ " "
+ "and his myth science arkestra present\n"
+ " "
+ "angles and demons @ play\n"
+ " "
+ "the nubians of plutonia";
+ std::string str01(str_lit01);
+ std::string strtmp;
+
+ std::stringbuf sbuf_04(str01, std::ios_base::in);
+
+ std::istream is_00(0);
+ std::istream is_04(&sbuf_04);
+ std::ios_base::iostate state1, state2, statefail, stateeof;
+ statefail = std::ios_base::failbit;
+ stateeof = std::ios_base::eofbit;
+ char carray1[400] = "";
+
+ // istream& getline(char* s, streamsize n, char delim)
+ // istream& getline(char* s, streamsize n)
+ state1 = is_00.rdstate();
+ is_00.getline(carray1, 20, '*');
+ state2 = is_00.rdstate();
+ // make sure failbit was set, since we couldn't extract
+ // from the null streambuf...
+ VERIFY( state1 != state2 );
+ VERIFY( static_cast<bool>(state2 & statefail) );
+
+ VERIFY( is_04.gcount() == 0 );
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 1, '\t'); // extracts, throws away
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 1 );
+ VERIFY( state1 == state2 );
+ VERIFY( state1 == 0 );
+ VERIFY( !traits_type::compare("", carray1, 1) );
+
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 20, '*');
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 10 );
+ VERIFY( state1 == state2 );
+ VERIFY( state1 == 0 );
+ VERIFY( !traits_type::compare("\t\t sun", carray1, 10) );
+
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 20);
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 4 );
+ VERIFY( state1 == state2 );
+ VERIFY( state1 == 0 );
+ VERIFY( !traits_type::compare("ra ", carray1, 4) );
+
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 65);
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 64 );
+ VERIFY( state1 != state2 );
+ VERIFY( state2 == statefail );
+ VERIFY( !traits_type::compare(
+ " and his myth science arkestra presen",
+ carray1, 65) );
+
+ is_04.clear();
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 120, '|');
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 106 );
+ VERIFY( state1 != state2 );
+ VERIFY( state2 == stateeof );
+
+ is_04.clear();
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 100, '|');
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 0 );
+ VERIFY( state1 != state2 );
+ VERIFY( static_cast<bool>(state2 & stateeof) );
+ VERIFY( static_cast<bool>(state2 & statefail) );
+}
+
+int
+main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc
new file mode 100644
index 000000000..486e0e5fc
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc
@@ -0,0 +1,99 @@
+// 1999-08-11 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <cstring> // for strlen
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type)
+// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html
+void
+test05()
+{
+ const char* charray = "\n"
+"a\n"
+"aa\n"
+"aaa\n"
+"aaaa\n"
+"aaaaa\n"
+"aaaaaa\n"
+"aaaaaaa\n"
+"aaaaaaaa\n"
+"aaaaaaaaa\n"
+"aaaaaaaaaa\n"
+"aaaaaaaaaaa\n"
+"aaaaaaaaaaaa\n"
+"aaaaaaaaaaaaa\n"
+"aaaaaaaaaaaaaa\n";
+
+ bool test __attribute__((unused)) = true;
+ const std::streamsize it = 5;
+ std::streamsize br = 0;
+ char tmp[it];
+ std::stringbuf sb(charray, std::ios_base::in);
+ std::istream ifs(&sb);
+ std::streamsize blen = std::strlen(charray);
+ VERIFY(!(!ifs));
+ while(ifs.getline(tmp, it) || ifs.gcount())
+ {
+ br += ifs.gcount();
+ if(ifs.eof())
+ {
+ // Just sanity checks to make sure we've extracted the same
+ // number of chars that were in the streambuf
+ VERIFY(br == blen);
+ // Also, we should only set the failbit if we could
+ // _extract_ no chars from the stream, i.e. the first read
+ // returned EOF.
+ VERIFY(ifs.fail() && ifs.gcount() == 0);
+ }
+ else if(ifs.fail())
+ {
+ // delimiter not read
+ //
+ // either
+ // -> extracted no characters
+ // or
+ // -> n - 1 characters are stored
+ ifs.clear(ifs.rdstate() & ~std::ios::failbit);
+ VERIFY((ifs.gcount() == 0) || (std::strlen(tmp) == it - 1));
+ VERIFY(!(!ifs));
+ continue;
+ }
+ else
+ {
+ // delimiter was read.
+ //
+ // -> strlen(__s) < n - 1
+ // -> delimiter was seen -> gcount() > strlen(__s)
+ VERIFY(ifs.gcount() == static_cast<std::streamsize>(std::strlen(tmp) + 1) );
+ continue;
+ }
+ }
+}
+
+int
+main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc
new file mode 100644
index 000000000..f71e1ca16
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc
@@ -0,0 +1,60 @@
+// 1999-08-11 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <cstring> // for strlen
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// [bug] istream::getline(char*,streamsize) still broken
+// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00126.html
+// brent verner <brent at rcfile dot org
+void
+test06()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const streamsize it = 5;
+ char tmp[it];
+ const char* str_lit = "abcd\n";
+
+ stringbuf strbuf(str_lit, std::ios_base::in);
+ istream istr(&strbuf);
+
+ istr.getline(tmp,it);
+ VERIFY( istr.gcount() == it ); // extracted whole string
+ VERIFY( strlen(tmp) == 4 ); // stored all but '\n'
+ VERIFY( !istr.eof() ); // extracted up to but not eof
+ VERIFY( !istr.fail() ); // failbit not set
+
+ char c = 'z';
+ istr.get(c);
+ VERIFY( c == 'z' );
+ VERIFY( istr.eof() );
+}
+
+int
+main()
+{
+ test06();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc
new file mode 100644
index 000000000..4f2909232
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc
@@ -0,0 +1,99 @@
+// Copyright (C) 2004, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// 27.6.1.3 unformatted input functions
+
+#include <cstring> // for strlen
+#include <istream>
+#include <testsuite_hooks.h>
+
+class Inbuf : public std::streambuf
+{
+ static const char buf[];
+ const char* current;
+ int size;
+
+public:
+ Inbuf()
+ {
+ current = buf;
+ size = std::strlen(buf);
+ }
+
+ int_type underflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current);
+ return traits_type::eof();
+ }
+
+ int_type uflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current++);
+ return traits_type::eof();
+ }
+};
+
+const char Inbuf::buf[] = "1234567890abcdefghij";
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef char_traits<char> traits_type;
+
+ Inbuf inbuf1;
+ istream is(&inbuf1);
+
+ char buffer[10];
+ traits_type::assign(buffer, sizeof(buffer), 'X');
+
+ is.getline(buffer, sizeof(buffer), '0');
+ VERIFY( is.rdstate() == ios_base::goodbit );
+ VERIFY( !traits_type::compare(buffer, "123456789\0", sizeof(buffer)) );
+ VERIFY( is.gcount() == 10 );
+
+ is.clear();
+ traits_type::assign(buffer, sizeof(buffer), 'X');
+ is.getline(buffer, sizeof(buffer));
+ VERIFY( is.rdstate() == ios_base::failbit );
+ VERIFY( !traits_type::compare(buffer, "abcdefghi\0", sizeof(buffer)) );
+ VERIFY( is.gcount() == 9 );
+
+ is.clear();
+ traits_type::assign(buffer, sizeof(buffer), 'X');
+ is.getline(buffer, sizeof(buffer));
+ VERIFY( is.rdstate() == ios_base::eofbit );
+ VERIFY( !traits_type::compare(buffer, "j\0XXXXXXXX", sizeof(buffer)) );
+ VERIFY( is.gcount() == 1 );
+
+ is.clear();
+ traits_type::assign(buffer, sizeof(buffer), 'X');
+ is.getline(buffer, sizeof(buffer));
+ VERIFY( is.rdstate() == (ios_base::eofbit | ios_base::failbit) );
+ VERIFY( !traits_type::compare(buffer, "\0XXXXXXXXX", sizeof(buffer)) );
+ VERIFY( is.gcount() == 0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc
new file mode 100644
index 000000000..310f637f9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc
@@ -0,0 +1,88 @@
+// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+// { dg-require-fileio "" }
+
+#include <istream>
+#include <string>
+#include <fstream>
+#include <cstdlib>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+string prepare(string::size_type len, unsigned nchunks, char delim)
+{
+ string ret;
+ for (unsigned i = 0; i < nchunks; ++i)
+ {
+ for (string::size_type j = 0; j < len; ++j)
+ ret.push_back('a' + rand() % 26);
+ len *= 2;
+ ret.push_back(delim);
+ }
+ return ret;
+}
+
+void check(istream& stream, const string& str, unsigned nchunks, char delim)
+{
+ bool test __attribute__((unused)) = true;
+
+ char buf[1000000];
+ string::size_type index = 0, index_new = 0;
+ unsigned n = 0;
+
+ while (stream.getline(buf, sizeof(buf), delim))
+ {
+ index_new = str.find(delim, index);
+ VERIFY( static_cast<string::size_type>(stream.gcount()) ==
+ index_new - index + 1 );
+ VERIFY( !str.compare(index, index_new - index, buf) );
+ index = index_new + 1;
+ ++n;
+ }
+ VERIFY( stream.gcount() == 0 );
+ VERIFY( stream.eof() );
+ VERIFY( n == nchunks );
+}
+
+void test01()
+{
+ const char filename[] = "istream_getline.txt";
+
+ const char delim = '|';
+ const unsigned nchunks = 10;
+ const string data = prepare(777, nchunks, delim);
+
+ ofstream ofstrm;
+ ofstrm.open(filename);
+ ofstrm.write(data.data(), data.size());
+ ofstrm.close();
+
+ ifstream ifstrm;
+ ifstrm.open(filename);
+ check(ifstrm, data, nchunks, delim);
+ ifstrm.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc
new file mode 100644
index 000000000..0a129ecbf
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc
@@ -0,0 +1,57 @@
+// 2004-11-26 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// DR 243. get and getline when sentry reports failure.
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ stringbuf strbuf01;
+ stringbuf strbuf02;
+ istream istr01(&strbuf01);
+ istream istr02(&strbuf02);
+ char buf02[2] = "*" ;
+
+ istr01.peek();
+ VERIFY( istr01.eof() );
+
+ istr01.getline(0, 0);
+ VERIFY( istr01.gcount() == 0 );
+ VERIFY( istr01.fail() );
+
+ istr02.peek();
+ VERIFY( istr02.eof() );
+
+ istr02.getline(buf02, 1);
+ VERIFY( istr02.gcount() == 0 );
+ VERIFY( istr02.fail() );
+ VERIFY( buf02[0] == char() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc
new file mode 100644
index 000000000..2445dd4f7
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc
@@ -0,0 +1,117 @@
+// Copyright (C) 2004, 2009, 2010 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+void
+test02()
+{
+ typedef std::char_traits<wchar_t> traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const wchar_t str_lit01[] = L"\t\t\t sun*ra \n"
+ L" "
+ L"and his myth science arkestra present\n"
+ L" "
+ L"angles and demons @ play\n"
+ L" "
+ L"the nubians of plutonia";
+ std::wstring str01(str_lit01);
+ std::wstring strtmp;
+
+ std::wstringbuf sbuf_04(str01, std::ios_base::in);
+
+ std::wistream is_00(0);
+ std::wistream is_04(&sbuf_04);
+ std::ios_base::iostate state1, state2, statefail, stateeof;
+ statefail = std::ios_base::failbit;
+ stateeof = std::ios_base::eofbit;
+ wchar_t carray1[400] = L"";
+
+ // istream& getline(wchar_t* s, streamsize n, wchar_t delim)
+ // istream& getline(wchar_t* s, streamsize n)
+ state1 = is_00.rdstate();
+ is_00.getline(carray1, 20, L'*');
+ state2 = is_00.rdstate();
+ // make sure failbit was set, since we couldn't extract
+ // from the null streambuf...
+ VERIFY( state1 != state2 );
+ VERIFY( static_cast<bool>(state2 & statefail) );
+
+ VERIFY( is_04.gcount() == 0 );
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 1, L'\t'); // extracts, throws away
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 1 );
+ VERIFY( state1 == state2 );
+ VERIFY( state1 == 0 );
+ VERIFY( !traits_type::compare(L"", carray1, 1) );
+
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 20, L'*');
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 10 );
+ VERIFY( state1 == state2 );
+ VERIFY( state1 == 0 );
+ VERIFY( !traits_type::compare(L"\t\t sun", carray1, 10) );
+
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 20);
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 4 );
+ VERIFY( state1 == state2 );
+ VERIFY( state1 == 0 );
+ VERIFY( !traits_type::compare(L"ra ", carray1, 4) );
+
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 65);
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 64 );
+ VERIFY( state1 != state2 );
+ VERIFY( state2 == statefail );
+ VERIFY( !traits_type::compare(
+ L" and his myth science arkestra presen",
+ carray1, 65) );
+
+ is_04.clear();
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 120, L'|');
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 106 );
+ VERIFY( state1 != state2 );
+ VERIFY( state2 == stateeof );
+
+ is_04.clear();
+ state1 = is_04.rdstate();
+ is_04.getline(carray1, 100, L'|');
+ state2 = is_04.rdstate();
+ VERIFY( is_04.gcount() == 0 );
+ VERIFY( state1 != state2 );
+ VERIFY( static_cast<bool>(state2 & stateeof) );
+ VERIFY( static_cast<bool>(state2 & statefail) );
+}
+
+int
+main()
+{
+ test02();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc
new file mode 100644
index 000000000..192de56a2
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc
@@ -0,0 +1,98 @@
+// Copyright (C) 2004, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <cwchar> // for wcslen
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type)
+// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html
+void
+test05()
+{
+ const wchar_t* charray = L"\n"
+L"a\n"
+L"aa\n"
+L"aaa\n"
+L"aaaa\n"
+L"aaaaa\n"
+L"aaaaaa\n"
+L"aaaaaaa\n"
+L"aaaaaaaa\n"
+L"aaaaaaaaa\n"
+L"aaaaaaaaaa\n"
+L"aaaaaaaaaaa\n"
+L"aaaaaaaaaaaa\n"
+L"aaaaaaaaaaaaa\n"
+L"aaaaaaaaaaaaaa\n";
+
+ bool test __attribute__((unused)) = true;
+ const std::streamsize it = 5;
+ std::streamsize br = 0;
+ wchar_t tmp[it];
+ std::wstringbuf sb(charray, std::ios_base::in);
+ std::wistream ifs(&sb);
+ std::streamsize blen = std::wcslen(charray);
+ VERIFY(!(!ifs));
+ while(ifs.getline(tmp, it) || ifs.gcount())
+ {
+ br += ifs.gcount();
+ if(ifs.eof())
+ {
+ // Just sanity checks to make sure we've extracted the same
+ // number of chars that were in the streambuf
+ VERIFY( br == blen );
+ // Also, we should only set the failbit if we could
+ // _extract_ no chars from the stream, i.e. the first read
+ // returned EOF.
+ VERIFY( ifs.fail() && ifs.gcount() == 0 );
+ }
+ else if(ifs.fail())
+ {
+ // delimiter not read
+ //
+ // either
+ // -> extracted no characters
+ // or
+ // -> n - 1 characters are stored
+ ifs.clear(ifs.rdstate() & ~std::ios::failbit);
+ VERIFY( (ifs.gcount() == 0) || (std::wcslen(tmp) == it - 1) );
+ VERIFY( !(!ifs) );
+ continue;
+ }
+ else
+ {
+ // delimiter was read.
+ //
+ // -> wcslen(__s) < n - 1
+ // -> delimiter was seen -> gcount() > wcslen(__s)
+ VERIFY( ifs.gcount() == static_cast<std::streamsize>(std::wcslen(tmp)
+ + 1) );
+ continue;
+ }
+ }
+}
+
+int
+main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc
new file mode 100644
index 000000000..af7033ddd
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc
@@ -0,0 +1,58 @@
+// Copyright (C) 2004, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <cwchar> // for wcslen
+#include <istream>
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// [bug] istream::getline(char*,streamsize) still broken
+// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00126.html
+// brent verner <brent at rcfile dot org
+void
+test06()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const streamsize it = 5;
+ wchar_t tmp[it];
+ const wchar_t* str_lit = L"abcd\n";
+
+ wstringbuf strbuf(str_lit, std::ios_base::in);
+ wistream istr(&strbuf);
+
+ istr.getline(tmp,it);
+ VERIFY( istr.gcount() == it ); // extracted whole string
+ VERIFY( wcslen(tmp) == 4 ); // stored all but '\n'
+ VERIFY( !istr.eof() ); // extracted up to but not eof
+ VERIFY( !istr.fail() ); // failbit not set
+
+ wchar_t c = L'z';
+ istr.get(c);
+ VERIFY( c == L'z' );
+ VERIFY( istr.eof() );
+}
+
+int
+main()
+{
+ test06();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc
new file mode 100644
index 000000000..1e147c748
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc
@@ -0,0 +1,103 @@
+// Copyright (C) 2004, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// 27.6.1.3 unformatted input functions
+
+#include <cwchar> // for wcslen
+#include <istream>
+#include <testsuite_hooks.h>
+
+class Inbuf : public std::wstreambuf
+{
+ static const wchar_t buf[];
+ const wchar_t* current;
+ int size;
+
+public:
+ Inbuf()
+ {
+ current = buf;
+ size = std::wcslen(buf);
+ }
+
+ int_type underflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current);
+ return traits_type::eof();
+ }
+
+ int_type uflow()
+ {
+ if (current < buf + size)
+ return traits_type::to_int_type(*current++);
+ return traits_type::eof();
+ }
+};
+
+const wchar_t Inbuf::buf[] = L"1234567890abcdefghij";
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef char_traits<wchar_t> traits_type;
+
+ Inbuf inbuf1;
+ wistream is(&inbuf1);
+
+ wchar_t buffer[10];
+ traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X');
+
+ is.getline(buffer, sizeof(buffer) / sizeof(wchar_t), L'0');
+ VERIFY( is.rdstate() == ios_base::goodbit );
+ VERIFY( !traits_type::compare(buffer, L"123456789\0",
+ sizeof(buffer) / sizeof(wchar_t)) );
+ VERIFY( is.gcount() == 10 );
+
+ is.clear();
+ traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X');
+ is.getline(buffer, sizeof(buffer) / sizeof(wchar_t));
+ VERIFY( is.rdstate() == ios_base::failbit );
+ VERIFY( !traits_type::compare(buffer, L"abcdefghi\0",
+ sizeof(buffer) / sizeof(wchar_t)) );
+ VERIFY( is.gcount() == 9 );
+
+ is.clear();
+ traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X');
+ is.getline(buffer, sizeof(buffer) / sizeof(wchar_t));
+ VERIFY( is.rdstate() == ios_base::eofbit );
+ VERIFY( !traits_type::compare(buffer, L"j\0XXXXXXXX",
+ sizeof(buffer) / sizeof(wchar_t)) );
+ VERIFY( is.gcount() == 1 );
+
+ is.clear();
+ traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X');
+ is.getline(buffer, sizeof(buffer) / sizeof(wchar_t));
+ VERIFY( is.rdstate() == (ios_base::eofbit | ios_base::failbit) );
+ VERIFY( !traits_type::compare(buffer, L"\0XXXXXXXXX",
+ sizeof(buffer) / sizeof(wchar_t)) );
+ VERIFY( is.gcount() == 0 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc
new file mode 100644
index 000000000..39fb59572
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc
@@ -0,0 +1,88 @@
+// Copyright (C) 2004, 2005, 2006, 2007, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <istream>
+#include <string>
+#include <fstream>
+#include <cstdlib>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+wstring
+prepare(wstring::size_type len, unsigned nchunks, wchar_t delim)
+{
+ wstring ret;
+ for (unsigned i = 0; i < nchunks; ++i)
+ {
+ for (wstring::size_type j = 0; j < len; ++j)
+ ret.push_back(L'a' + rand() % 26);
+ len *= 2;
+ ret.push_back(delim);
+ }
+ return ret;
+}
+
+void
+check(wistream& stream, const wstring& str, unsigned nchunks, wchar_t delim)
+{
+ bool test __attribute__((unused)) = true;
+
+ static wchar_t buf[1000000];
+ wstring::size_type index = 0, index_new = 0;
+ unsigned n = 0;
+
+ while (stream.getline(buf, sizeof(buf) / sizeof(wchar_t), delim))
+ {
+ index_new = str.find(delim, index);
+ VERIFY( static_cast<string::size_type>(stream.gcount()) ==
+ index_new - index + 1 );
+ VERIFY( !str.compare(index, index_new - index, buf) );
+ index = index_new + 1;
+ ++n;
+ }
+ VERIFY( stream.gcount() == 0 );
+ VERIFY( stream.eof() );
+ VERIFY( n == nchunks );
+}
+
+void test01()
+{
+ const char filename[] = "wistream_getline.txt";
+
+ const wchar_t delim = L'|';
+ const unsigned nchunks = 10;
+ const wstring data = prepare(777, nchunks, delim);
+
+ wofstream ofstrm;
+ ofstrm.open(filename);
+ ofstrm.write(data.data(), data.size());
+ ofstrm.close();
+
+ wifstream ifstrm;
+ ifstrm.open(filename);
+ check(ifstrm, data, nchunks, delim);
+ ifstrm.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc
new file mode 100644
index 000000000..0a4376c88
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc
@@ -0,0 +1,57 @@
+// 2004-11-26 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 Free Software Foundation
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.6.1.3 unformatted input functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// DR 243. get and getline when sentry reports failure.
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wstringbuf strbuf01;
+ wstringbuf strbuf02;
+ wistream istr01(&strbuf01);
+ wistream istr02(&strbuf02);
+ wchar_t buf02[2] = L"*" ;
+
+ istr01.peek();
+ VERIFY( istr01.eof() );
+
+ istr01.getline(0, 0);
+ VERIFY( istr01.gcount() == 0 );
+ VERIFY( istr01.fail() );
+
+ istr02.peek();
+ VERIFY( istr02.eof() );
+
+ istr02.getline(buf02, 1);
+ VERIFY( istr02.gcount() == 0 );
+ VERIFY( istr02.fail() );
+ VERIFY( buf02[0] == wchar_t() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}