summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_istream/peek
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_istream/peek')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc92
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc40
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc49
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc89
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc40
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc47
6 files changed, 357 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc
new file mode 100644
index 000000000..39a3fdff3
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc
@@ -0,0 +1,92 @@
+// 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
+test01()
+{
+ typedef std::ios::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const std::string str_01;
+ const std::string str_02("soul eyes: john coltrane quartet");
+ std::string strtmp;
+
+ std::stringbuf isbuf_03(str_02, std::ios_base::in);
+ std::stringbuf isbuf_04(str_02, std::ios_base::in);
+
+ std::istream is_00(0);
+ std::istream is_03(&isbuf_03);
+ std::istream is_04(&isbuf_04);
+ std::ios_base::iostate state1, state2;
+
+ char carray[60] = "";
+
+ // istream& ignore(streamsize n = 1, int_type delim = traits::eof())
+ is_04.read(carray, 9);
+ VERIFY( is_04.peek() == ':' );
+
+ state1 = is_04.rdstate();
+ is_04.ignore();
+ VERIFY( is_04.gcount() == 1 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+ VERIFY( is_04.peek() == ' ' );
+
+ state1 = is_04.rdstate();
+ is_04.ignore(0);
+ VERIFY( is_04.gcount() == 0 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+ VERIFY( is_04.peek() == ' ' );
+
+ state1 = is_04.rdstate();
+ is_04.ignore(5, traits_type::to_int_type(' '));
+ VERIFY( is_04.gcount() == 1 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+ VERIFY( is_04.peek() == 'j' );
+
+ // int_type peek()
+ state1 = is_04.rdstate();
+ VERIFY( is_04.peek() == 'j' );
+ VERIFY( is_04.gcount() == 0 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+
+ is_04.ignore(30);
+ state1 = is_04.rdstate();
+ VERIFY( is_04.peek() == traits_type::eof() );
+ VERIFY( is_04.gcount() == 0 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 != state2 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc
new file mode 100644
index 000000000..7263c7c42
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc
@@ -0,0 +1,40 @@
+// Copyright (C) 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 <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/12296
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ istringstream stream;
+ VERIFY( stream.rdstate() == ios_base::goodbit );
+ istringstream::int_type c = stream.peek();
+ VERIFY( c == istringstream::traits_type::eof() );
+ VERIFY( stream.rdstate() == ios_base::eofbit );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc
new file mode 100644
index 000000000..5d02fc912
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc
@@ -0,0 +1,49 @@
+// 2000-06-29 bkoz
+
+// Copyright (C) 2000, 2001, 2002, 2003, 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
+// NB: ostream has a particular "seeks" category. Adopt this for istreams too.
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// fstreams
+void test04(void)
+{
+ bool test __attribute__((unused)) = true;
+ std::istream::pos_type pos01, pos02;
+ const char str_lit01[] = "istream_seeks-1.txt";
+ std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out);
+
+ // libstdc++/6414
+ if01.seekg(0, std::ios_base::beg);
+ pos01 = if01.tellg();
+ if01.peek();
+ pos02 = if01.tellg();
+ VERIFY( pos02 == pos01 );
+}
+
+int main()
+{
+ test04();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc
new file mode 100644
index 000000000..612e60600
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc
@@ -0,0 +1,89 @@
+// 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
+test01()
+{
+ typedef std::wios::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const std::wstring str_01;
+ const std::wstring str_02(L"soul eyes: john coltrane quartet");
+ std::wstring strtmp;
+
+ std::wstringbuf isbuf_03(str_02, std::ios_base::in);
+ std::wstringbuf isbuf_04(str_02, std::ios_base::in);
+
+ std::wistream is_00(0);
+ std::wistream is_03(&isbuf_03);
+ std::wistream is_04(&isbuf_04);
+ std::ios_base::iostate state1, state2;
+
+ wchar_t carray[60] = L"";
+
+ // istream& ignore(streamsize n = 1, int_type delim = traits::eof())
+ is_04.read(carray, 9);
+ VERIFY( is_04.peek() == L':' );
+
+ state1 = is_04.rdstate();
+ is_04.ignore();
+ VERIFY( is_04.gcount() == 1 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+ VERIFY( is_04.peek() == L' ' );
+
+ state1 = is_04.rdstate();
+ is_04.ignore(0);
+ VERIFY( is_04.gcount() == 0 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+ VERIFY( is_04.peek() == L' ' );
+
+ state1 = is_04.rdstate();
+ is_04.ignore(5, traits_type::to_int_type(' '));
+ VERIFY( is_04.gcount() == 1 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+ VERIFY( is_04.peek() == L'j' );
+
+ // int_type peek()
+ state1 = is_04.rdstate();
+ VERIFY( is_04.peek() == L'j' );
+ VERIFY( is_04.gcount() == 0 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 == state2 );
+
+ is_04.ignore(30);
+ state1 = is_04.rdstate();
+ VERIFY( is_04.peek() == traits_type::eof() );
+ VERIFY( is_04.gcount() == 0 );
+ state2 = is_04.rdstate();
+ VERIFY( state1 != state2 );
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc
new file mode 100644
index 000000000..c1fcce837
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc
@@ -0,0 +1,40 @@
+// 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 <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/12296
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ wistringstream stream;
+ VERIFY( stream.rdstate() == ios_base::goodbit );
+ wistringstream::int_type c = stream.peek();
+ VERIFY( c == wistringstream::traits_type::eof() );
+ VERIFY( stream.rdstate() == ios_base::eofbit );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc
new file mode 100644
index 000000000..9c74fa3f4
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc
@@ -0,0 +1,47 @@
+// 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
+// NB: ostream has a particular "seeks" category. Adopt this for istreams too.
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// fstreams
+void test04(void)
+{
+ bool test __attribute__((unused)) = true;
+ std::wistream::pos_type pos01, pos02;
+ const char str_lit01[] = "wistream_seeks-1.txt";
+ std::wifstream if01(str_lit01, std::ios_base::in | std::ios_base::out);
+
+ // libstdc++/6414
+ if01.seekg(0, std::ios_base::beg);
+ pos01 = if01.tellg();
+ if01.peek();
+ pos02 = if01.tellg();
+ VERIFY( pos02 == pos01 );
+}
+
+int main()
+{
+ test04();
+ return 0;
+}