summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_filebuf/open
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/27_io/basic_filebuf/open
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_filebuf/open')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc74
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc59
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc54
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc72
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc30
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc72
7 files changed, 422 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc
new file mode 100644
index 000000000..fc69cd4eb
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc
@@ -0,0 +1,61 @@
+// Copyright (C) 2003, 2005, 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.8.1.3 filebuf member functions
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_character.h>
+
+// libstdc++/12790
+void test01()
+{
+ using namespace std;
+ using __gnu_test::pod_uchar;
+ typedef basic_filebuf<pod_uchar>::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_open_12790";
+
+ locale loc(locale::classic(),
+ new codecvt<traits_type::char_type, char,
+ traits_type::state_type>);
+
+ basic_filebuf<pod_uchar> fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc(pod_uchar::from<char>('b'));
+ fb.close();
+
+ // Check that reopened basic_filebuf begins in the initial state.
+ fb.open(name, ios_base::in);
+ traits_type::int_type c = fb.sbumpc();
+ VERIFY( c != traits_type::eof() );
+ VERIFY( traits_type::eq(traits_type::to_char_type(c),
+ pod_uchar::from<char>('b')) );
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc
new file mode 100644
index 000000000..1a40da155
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc
@@ -0,0 +1,74 @@
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 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.8.1.3 filebuf member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// various tests for filebuf::open() and filebuf::close() including
+// the non-portable functionality in the libstdc++-v3 IO library
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const char name_01[] = "filebuf_members-1.tst";
+const char name_02[] = "filebuf_members-1.txt";
+
+// Test member functions.
+void test_01()
+{
+ bool test __attribute__((unused)) = true;
+ const char* name_03 = "filebuf_members-3"; // empty file, need to create
+
+ std::filebuf fb_01; // in
+ std::filebuf fb_02; // out
+ std::filebuf fb_03; // in | out
+
+ // bool is_open()
+ VERIFY( !fb_01.is_open() );
+ VERIFY( !fb_02.is_open() );
+ VERIFY( !fb_03.is_open() );
+
+ // filebuf_type* open(const char* __s, ios_base::openmode __mode)
+ fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
+ VERIFY( fb_01.is_open() );
+
+ // Try to open two different files without closing the first:
+ // Should keep the old file attached, and disregard attempt to overthrow.
+ std::filebuf* f = fb_02.open(name_02, std::ios_base::in | std::ios_base::out
+ | std::ios_base::trunc);
+ VERIFY( f );
+ VERIFY( fb_02.is_open() );
+
+ f = fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
+ VERIFY( !f );
+ VERIFY( fb_02.is_open() );
+
+ fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc);
+ VERIFY( fb_03.is_open() );
+}
+
+int
+main()
+{
+ test_01();
+ return 0;
+}
+
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc
new file mode 100644
index 000000000..755784fb9
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc
@@ -0,0 +1,59 @@
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 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.8.1.3 filebuf member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// various tests for filebuf::open() and filebuf::close() including
+// the non-portable functionality in the libstdc++-v3 IO library
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <ext/stdio_filebuf.h>
+#include <testsuite_hooks.h>
+
+const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it
+
+void test_03()
+{
+ bool test __attribute__((unused)) = true;
+ int first_fd = ::open(name_01, O_RDONLY);
+ VERIFY( first_fd != -1 );
+ FILE* first_file = ::fdopen(first_fd, "r");
+ VERIFY( first_file );
+ __gnu_cxx::stdio_filebuf<char> fb(first_file, std::ios_base::in);
+
+ int second_fd = fb.fd();
+
+ VERIFY( first_fd == second_fd );
+}
+
+int
+main()
+{
+ test_03();
+ return 0;
+}
+
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc
new file mode 100644
index 000000000..6b076a699
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc
@@ -0,0 +1,54 @@
+// Copyright (C) 2001, 2002, 2003, 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.8.1.3 filebuf member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// various tests for filebuf::open() and filebuf::close() including
+// the non-portable functionality in the libstdc++-v3 IO library
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// Charles Leggett <CGLeggett@lbl.gov>
+void test_05()
+{
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_file5";
+
+ std::fstream scratch_file;
+
+ scratch_file.open(name, std::ios::out);
+ scratch_file.close();
+
+ scratch_file.open(name, std::ios::in);
+ if (!scratch_file)
+ VERIFY( false );
+ scratch_file.close();
+}
+
+int
+main()
+{
+ test_05();
+ return 0;
+}
+
+
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc
new file mode 100644
index 000000000..31d25422b
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc
@@ -0,0 +1,72 @@
+// 2006-10-01 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2006, 2007, 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/>.
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// DR 596.
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_file4";
+
+ std::fstream scratch_file;
+
+ scratch_file.open(name, std::ios_base::app);
+ VERIFY( scratch_file );
+ VERIFY( scratch_file.is_open() );
+ scratch_file.close();
+
+ scratch_file.open(name, std::ios_base::in | std::ios_base::out
+ | std::ios_base::app);
+ VERIFY( scratch_file );
+ VERIFY( scratch_file.is_open() );
+ scratch_file.close();
+
+ scratch_file.open(name, std::ios_base::in | std::ios_base::app);
+ VERIFY( scratch_file );
+ VERIFY( scratch_file.is_open() );
+ scratch_file.close();
+
+ scratch_file.open(name, std::ios_base::app | std::ios_base::binary);
+ VERIFY( scratch_file );
+ VERIFY( scratch_file.is_open() );
+ scratch_file.close();
+
+ scratch_file.open(name, std::ios_base::in | std::ios_base::out
+ | std::ios_base::app | std::ios_base::binary);
+ VERIFY( scratch_file );
+ VERIFY( scratch_file.is_open() );
+ scratch_file.close();
+
+ scratch_file.open(name, std::ios_base::in | std::ios_base::app
+ | std::ios_base::binary);
+ VERIFY( scratch_file );
+ VERIFY( scratch_file.is_open() );
+ scratch_file.close();
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc
new file mode 100644
index 000000000..47721e6ad
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc
@@ -0,0 +1,30 @@
+// Copyright (C) 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/>.
+
+// { dg-do compile }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+
+// Test member functions.
+void test01()
+{
+ std::filebuf fb;
+
+ const std::string name = "filebuf_name.txt";
+ fb.open(name, std::ios_base::in | std::ios_base::ate);
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc
new file mode 100644
index 000000000..5b404375e
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc
@@ -0,0 +1,72 @@
+// { dg-require-mkfifo "" }
+
+// Copyright (C) 2001, 2002, 2003, 2005, 2009, 2010
+// 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.8.1.3 filebuf member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// various tests for filebuf::open() and filebuf::close() including
+// the non-portable functionality in the libstdc++-v3 IO library
+
+#include <fstream>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <testsuite_hooks.h>
+
+// libstdc++/9507
+void test_06()
+{
+ using namespace __gnu_test;
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_fifo2";
+
+ signal(SIGPIPE, SIG_IGN);
+
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+
+ std::filebuf fbuf;
+ // The use of ios_base::ate implies an attempt to seek on the file
+ // descriptor. The seek will fail. Thus, at the OS level, this
+ // call to "fbuf.open" will result in a call to "open" (which will
+ // succeed), a call to "lseek" (which will fail), and, finally, a
+ // call to "close" (which will succeed). Thus, after this call, the
+ // file should be closed.
+ std::filebuf* r = fbuf.open(name,
+ std::ios_base::in
+ | std::ios_base::out
+ | std::ios_base::ate);
+ if (!r)
+ VERIFY( !fbuf.is_open() );
+ else
+ VERIFY( fbuf.is_open() );
+}
+
+int
+main()
+{
+ test_06();
+ return 0;
+}
+
+