This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::string overloads for xfstream


Here is a revised patch with end of line witespace removed and all the new functions in the ChangeList.

Note: when testing this patch I had to add the empty file "testsuite/data/fstream_members-1.txt" by hand.  The file is needed to make the basic_fstream testcases pass.  The patch utility seems to clobber things that are empty at the end of the process.

Ed


Attachment: CL_fstream_string
Description: CL_fstream_string

Index: include/std/fstream
===================================================================
--- include/std/fstream	(revision 144904)
+++ include/std/fstream	(working copy)
@@ -45,8 +45,11 @@
 #include <istream>
 #include <ostream>
 #include <bits/codecvt.h>
-#include <cstdio>             // For BUFSIZ     
+#include <cstdio>             // For BUFSIZ
 #include <bits/basic_file.h>  // For __basic_file, __c_lock
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#include <string>             // For std::string overloads.
+#endif
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -121,12 +124,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       bool			_M_buf_allocated;
 
       /**
-       *  _M_reading == false && _M_writing == false for 'uncommitted' mode;  
+       *  _M_reading == false && _M_writing == false for 'uncommitted' mode;
        *  _M_reading == true for 'read' mode;
        *  _M_writing == true for 'write' mode;
        *
        *  NB: _M_reading == true && _M_writing == true is unused.
-      */ 
+      */
       bool                      _M_reading;
       bool                      _M_writing;
 
@@ -136,10 +139,10 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *
        *  @note pbacks of over one character are not currently supported.
       */
-      char_type			_M_pback; 
+      char_type			_M_pback;
       char_type*		_M_pback_cur_save;
       char_type*		_M_pback_end_save;
-      bool			_M_pback_init; 
+      bool			_M_pback_init;
       //@}
 
       // Cached codecvt facet.
@@ -149,19 +152,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Buffer for external characters. Used for input when
        *  codecvt::always_noconv() == false. When valid, this corresponds
        *  to eback().
-      */ 
+      */
       char*			_M_ext_buf;
 
       /**
        *  Size of buffer held by _M_ext_buf.
-      */ 
+      */
       streamsize		_M_ext_buf_size;
 
       /**
        *  Pointers into the buffer held by _M_ext_buf that delimit a
        *  subsequence of bytes that have been read but not yet converted.
        *  When valid, _M_ext_next corresponds to egptr().
-      */ 
+      */
       const char*		_M_ext_next;
       char*			_M_ext_end;
 
@@ -186,7 +189,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *  Deactivates pback buffer contents, and restores normal buffer.
        *  Assumptions:
        *  The pback buffer has only moved forward.
-      */ 
+      */
       void
       _M_destroy_pback() throw()
       {
@@ -266,6 +269,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       __filebuf_type*
       open(const char* __s, ios_base::openmode __mode);
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *  @return  @c this on success, NULL on failure
+       */
+      __filebuf_type*
+      open(const std::string& __s, ios_base::openmode __mode)
+      { return open(__s.c_str(), __mode); }
+#endif
+
       /**
        *  @brief  Closes the currently associated file.
        *  @return  @c this on success, NULL on failure
@@ -367,7 +382,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        *   __off == egptr() - eback() upon underflow/uflow ('read' mode);
        *   __off == 0 upon overflow ('write' mode);
        *   __off == -1 upon open, setbuf, seekoff/pos ('uncommitted' mode).
-       * 
+       *
        *  NB: epptr() - pbase() == _M_buf_size - 1, since _M_buf_size
        *  reflects the actual allocated memory and the last cell is reserved
        *  for the overflow char of a full put area.
@@ -448,6 +463,24 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an input file stream.
+       *  @param  s  std::string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       *
+       *  @c ios_base::in is automatically included in @a mode.
+      */
+      explicit
+      basic_ifstream(const std::string& __s,
+		     ios_base::openmode __mode = ios_base::in)
+      : __istream_type(), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -504,6 +537,27 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode|in).  If that function
+       *  fails, @c failbit is set in the stream's error state.
+      */
+      void
+      open(const std::string& __s, ios_base::openmode __mode = ios_base::in)
+      {
+	if (!_M_filebuf.open(__s, __mode | ios_base::in))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
@@ -579,6 +633,25 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an output file stream.
+       *  @param  s  std::string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       *
+       *  @c ios_base::out|ios_base::trunc is automatically included in
+       *  @a mode.
+      */
+      explicit
+      basic_ofstream(const std::string& __s,
+		     ios_base::openmode __mode = ios_base::out|ios_base::trunc)
+      : __ostream_type(), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -636,6 +709,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode|out|trunc).  If that
+       *  function fails, @c failbit is set in the stream's error state.
+      */
+      void
+      open(const std::string& __s,
+	   ios_base::openmode __mode = ios_base::out | ios_base::trunc)
+      {
+	if (!_M_filebuf.open(__s, __mode | ios_base::out))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
@@ -710,6 +805,22 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	this->open(__s, __mode);
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Create an input/output file stream.
+       *  @param  s  Null terminated string specifying the filename.
+       *  @param  mode  Open file in specified mode (see std::ios_base).
+       */
+      explicit
+      basic_fstream(const std::string& __s,
+		    ios_base::openmode __mode = ios_base::in | ios_base::out)
+      : __iostream_type(NULL), _M_filebuf()
+      {
+	this->init(&_M_filebuf);
+	this->open(__s, __mode);
+      }
+#endif
+
       /**
        *  @brief  The destructor does nothing.
        *
@@ -767,6 +878,28 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
 	  this->clear();
       }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Opens an external file.
+       *  @param  s  The name of the file.
+       *  @param  mode  The open mode flags.
+       *
+       *  Calls @c std::basic_filebuf::open(s,mode).  If that
+       *  function fails, @c failbit is set in the stream's error state.
+       */
+      void
+      open(const std::string& __s,
+	   ios_base::openmode __mode = ios_base::in | ios_base::out)
+      {
+	if (!_M_filebuf.open(__s, __mode))
+	  this->setstate(ios_base::failbit);
+	else
+	  // _GLIBCXX_RESOLVE_LIB_DEFECTS
+	  // 409. Closing an fstream should clear error state
+	  this->clear();
+      }
+#endif
+
       /**
        *  @brief  Close the file.
        *
Index: testsuite/27_io/basic_ofstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_ofstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ofstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,62 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.13 ofstream member functions
+// @require@ %-*.tst
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <ostream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "ofstream_members-1.tst";
+const std::string name_02 = "ofstream_members-1.txt";
+
+// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00136.html
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::ofstream ofs1;
+  ofs1.close();
+
+  // false as expected:
+  VERIFY( !ofs1.is_open() );
+   // this is now true:
+  VERIFY( !(ofs1) );
+
+  ofs1.open(name_02);
+  VERIFY( ofs1.is_open() );
+
+  // As per the resolution of DR 409.
+  VERIFY( (ofs1) );
+  VERIFY( ofs1.rdstate() == std::ios_base::goodbit );
+
+  ofs1.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ofstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_ofstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ofstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,51 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.11 ofstream constructors
+// @require@ %-*.tst
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <ostream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_02 = "ofstream_members-1.txt";
+
+void test02()
+{
+  bool test __attribute__((unused)) = true;
+  const int more_than_max_open_files = 8200;
+
+  for(int i = 0; ++i < more_than_max_open_files;)
+    {
+      std::ofstream ofs(name_02);
+      VERIFY( static_cast<bool>(ofs) );
+    }
+}
+
+int main()
+{
+  test02();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_fstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_fstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_fstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,59 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.17 fstream member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "fstream_members-1.txt";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::fstream fs1;
+  fs1.close();
+  
+  // false as expected:
+  VERIFY( !fs1.is_open() );
+   // this is now true:
+  VERIFY( !(fs1) );
+  
+  fs1.open(name_01);
+  VERIFY( fs1.is_open() );
+
+  // As per the resolution of DR 409.
+  VERIFY( (fs1) );
+  VERIFY( fs1.rdstate() == std::ios_base::goodbit );
+
+  fs1.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_fstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_fstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_fstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,50 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.15 fstream constructors
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "fstream_members-1.txt";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  const int more_than_max_open_files = 8200;
+  
+  for (int i = 0; ++i < more_than_max_open_files;)
+    {
+      std::fstream fs(name_01);
+      VERIFY( static_cast<bool>(fs) );
+    }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ifstream/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_ifstream/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ifstream/open/string/1.cc	(revision 0)
@@ -0,0 +1,60 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.9 ifstream member functions
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "ifstream_members-1.tst";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  std::ifstream ifs1;
+  ifs1.close();
+
+  // false as expected:
+  VERIFY( !ifs1.is_open() );
+   // this is now true:
+  VERIFY( !(ifs1) );
+
+  ifs1.open(name_01);
+  VERIFY( ifs1.is_open() );
+
+  // As per the resolution of DR 409.
+  VERIFY( (ifs1) );
+  VERIFY( ifs1.rdstate() == std::ios_base::goodbit );
+
+  ifs1.close();
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_ifstream/cons/string/1.cc
===================================================================
--- testsuite/27_io/basic_ifstream/cons/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_ifstream/cons/string/1.cc	(revision 0)
@@ -0,0 +1,51 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 27.8.1.7 ifstream constructors
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %-*.txt
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <istream>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "ifstream_members-1.tst";
+
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  const int more_than_max_open_files = 8200;
+
+  for (int i = 0; ++i < more_than_max_open_files;)
+    {
+      std::ifstream ifs(name_01);
+      VERIFY( static_cast<bool>(ifs) );
+    }
+}
+
+int main()
+{
+  test01();
+  return 0;
+}
+
+
+
Index: testsuite/27_io/basic_filebuf/open/string/1.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/1.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/1.cc	(revision 0)
@@ -0,0 +1,75 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 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 "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const std::string name_01 = "filebuf_members-1.tst";
+const std::string name_02 = "filebuf_members-1.txt";
+
+// Test member functions.
+void test_01()
+{
+  bool test __attribute__((unused)) = true;
+  const std::string 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() );
+
+  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 != NULL );
+  VERIFY( fb_02.is_open() );
+
+  f = fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
+  VERIFY( f == NULL );
+  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;
+}
+
+
Index: testsuite/27_io/basic_filebuf/open/string/3.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/3.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/3.cc	(revision 0)
@@ -0,0 +1,56 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// 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 "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// Charles Leggett <CGLeggett@lbl.gov>
+void test_05()
+{
+  bool test __attribute__((unused)) = true;
+  const std::string 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;
+}
+
+
Index: testsuite/27_io/basic_filebuf/open/string/4.cc
===================================================================
--- testsuite/27_io/basic_filebuf/open/string/4.cc	(revision 0)
+++ testsuite/27_io/basic_filebuf/open/string/4.cc	(revision 0)
@@ -0,0 +1,72 @@
+// 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 2, 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 COPYING.  If not, write to the Free
+// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+// USA.
+
+// { dg-require-fileio "" }
+// { dg-options "-std=gnu++0x" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+// DR 596.
+void test01()
+{
+  bool test __attribute__((unused)) = true;
+  const std::string 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;
+}
Index: testsuite/data/fstream_members-1.txt
===================================================================

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]