]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libstdc++/7216 (basic_iostream::traits_type is ambiguous issue)
authorBenjamin Kosnik <bkoz@redhat.com>
Fri, 26 Jul 2002 01:49:36 +0000 (01:49 +0000)
committerBenjamin Kosnik <bkoz@gcc.gnu.org>
Fri, 26 Jul 2002 01:49:36 +0000 (01:49 +0000)
2002-07-25  Benjamin Kosnik  <bkoz@redhat.com>

PR libstdc++/7216
* include/std/std_istream.h (basic_iostream): Add typedefs for
char_type, int_type, pos_type, off_type, and traits_type.
* testsuite/27_io/iostream.cc (test01): Add typedef tests.
* testsuite/27_io/istream.cc: Same.
* testsuite/27_io/ostream.cc: Same.
* testsuite/27_io/filebuf.cc: Same.
* testsuite/27_io/stringbuf.cc: Replace content, move to...
* testsuite/27_io/stringbuf_members.cc: ...here.
* testsuite/27_io/streambuf.cc: Replace content, move to...
* testsuite/27_io/streambuf_members.cc: ...here.
* testsuite/27_io/stringstream.cc: Replace content, move to...
* testsuite/27_io/stringstream_members.cc: ...here.
* testsuite/27_io/ios.cc: New file.
* testsuite/27_io/fstream.cc: New file.
* testsuite/27_io/ifstream.cc: New file.
* testsuite/27_io/ofstream.cc: New file.
* testsuite/27_io/istringstream.cc: New file.
* testsuite/27_io/ostringstream.cc: New file.

From-SVN: r55767

19 files changed:
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/std_istream.h
libstdc++-v3/testsuite/27_io/filebuf.cc
libstdc++-v3/testsuite/27_io/fstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/ifstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/ios.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/iostream.cc
libstdc++-v3/testsuite/27_io/istream.cc
libstdc++-v3/testsuite/27_io/istringstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/ofstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/ostream.cc
libstdc++-v3/testsuite/27_io/ostringstream.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/ostringstream_members.cc
libstdc++-v3/testsuite/27_io/streambuf.cc
libstdc++-v3/testsuite/27_io/streambuf_members.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/stringbuf.cc
libstdc++-v3/testsuite/27_io/stringbuf_members.cc [new file with mode: 0644]
libstdc++-v3/testsuite/27_io/stringstream.cc
libstdc++-v3/testsuite/27_io/stringstream_members.cc

index b3c52e445f51a46786f1207b734e43ffc811f0fe..bd80812f794cc874d2eea51c9db3a96f43e99bed 100644 (file)
@@ -1,3 +1,25 @@
+2002-07-25  Benjamin Kosnik  <bkoz@redhat.com>
+
+       PR libstdc++/7216
+       * include/std/std_istream.h (basic_iostream): Add typedefs for
+       char_type, int_type, pos_type, off_type, and traits_type.
+       * testsuite/27_io/iostream.cc (test01): Add typedef tests.
+       * testsuite/27_io/istream.cc: Same.
+       * testsuite/27_io/ostream.cc: Same.
+       * testsuite/27_io/filebuf.cc: Same.
+       * testsuite/27_io/stringbuf.cc: Replace content, move to...
+       * testsuite/27_io/stringbuf_members.cc: ...here.        
+       * testsuite/27_io/streambuf.cc: Replace content, move to...
+       * testsuite/27_io/streambuf_members.cc: ...here.        
+       * testsuite/27_io/stringstream.cc: Replace content, move to...
+       * testsuite/27_io/stringstream_members.cc: ...here.
+       * testsuite/27_io/ios.cc: New file.
+       * testsuite/27_io/fstream.cc: New file.
+       * testsuite/27_io/ifstream.cc: New file.        
+       * testsuite/27_io/ofstream.cc: New file.                
+       * testsuite/27_io/istringstream.cc: New file.   
+       * testsuite/27_io/ostringstream.cc: New file.   
+       
 2002-07-25  Benjamin Kosnik  <bkoz@redhat.com>
 
        PR libstdc++/7220
index 40f4b67fb9f75dee50024b244add9088a2ac7ed2..8aa9123ed5c5683ca003dafb5b15c12b5cc3b773 100644 (file)
@@ -261,6 +261,16 @@ namespace std
       public basic_ostream<_CharT, _Traits>
     {
     public:
+#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
+// 271. basic_iostream missing typedefs
+      // Types (inherited):
+      typedef _CharT                                   char_type;
+      typedef typename _Traits::int_type               int_type;
+      typedef typename _Traits::pos_type               pos_type;
+      typedef typename _Traits::off_type               off_type;
+      typedef _Traits                                  traits_type;
+#endif
+
       // Non-standard Types:
       typedef basic_istream<_CharT, _Traits>           __istream_type;
       typedef basic_ostream<_CharT, _Traits>           __ostream_type;
index 558d196f9fb359de9dc8a8522b397a55cb102f62..9919365a552b3d3f37cedf00d3fdde6a068811aa 100644 (file)
 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 // USA.
 
-// NB: this test assumes that _M_buf_size == 40, and not the usual
-// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be
-// simulated a bit more readily.
+// 27.8.1.1 - Template class basic_filebuf 
+// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES.
 
 #include <fstream>
 #include <testsuite_hooks.h>
 
 // { dg-do compile }
 
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::filebuf test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
 // test05
 // libstdc++/1886
 // should be able to instantiate basic_filebuf for non-standard types.
@@ -35,6 +46,7 @@ template class std::basic_filebuf<short, std::char_traits<short> >;
 
 int main() 
 {
+  test01();
   return 0;
 }
 
diff --git a/libstdc++-v3/testsuite/27_io/fstream.cc b/libstdc++-v3/testsuite/27_io/fstream.cc
new file mode 100644 (file)
index 0000000..2ecd077
--- /dev/null
@@ -0,0 +1,60 @@
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.8.1.11 - Template class basic_fstream
+// NB: This file is for testing basic_fstream with NO OTHER INCLUDES.
+
+#include <fstream>
+
+// { dg-do compile }
+
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::fstream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
+namespace test 
+{
+  using namespace std;
+  typedef short type_t;
+  template class basic_fstream<type_t, char_traits<type_t> >;
+} // test
+
+int main() 
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/ifstream.cc b/libstdc++-v3/testsuite/27_io/ifstream.cc
new file mode 100644 (file)
index 0000000..9bc38a8
--- /dev/null
@@ -0,0 +1,60 @@
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.8.1.5 - Template class basic_ifstream
+// NB: This file is for testing basic_ifstream with NO OTHER INCLUDES.
+
+#include <fstream>
+
+// { dg-do compile }
+
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::ifstream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
+namespace test 
+{
+  using namespace std;
+  typedef short type_t;
+  template class basic_ifstream<type_t, char_traits<type_t> >;
+} // test
+
+int main() 
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/ios.cc b/libstdc++-v3/testsuite/27_io/ios.cc
new file mode 100644 (file)
index 0000000..c124938
--- /dev/null
@@ -0,0 +1,60 @@
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.4.4 - Template class basic_ios
+// NB: This file is for testing basic_ios with NO OTHER INCLUDES.
+
+#include <ios>
+
+// { dg-do compile }
+
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::ios test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
+namespace test 
+{
+  using namespace std;
+  typedef short type_t;
+  template class basic_ios<type_t, char_traits<type_t> >;
+} // test
+
+int main() 
+{
+  test01();
+  return 0;
+}
index 26849ac0fd2f318bd7ffb0bf29c50c8c01142043..943819bf82fd572b0f16dda98c089b4fcbc77223 100644 (file)
 
 #include <istream>
 
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::iostream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
 namespace test 
 {
   using namespace std;
@@ -43,5 +55,6 @@ namespace test
 
 int main() 
 {
+  test01();
   return 0;
 }
index ef88a39f727e00004799d1f9ffb5f0b5ea988af1..05db50ed461f627ebc366b4a03b671e492a9235b 100644 (file)
 
 // { dg-do compile }
 
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::istream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
 namespace test 
 {
   using namespace std;
@@ -43,5 +55,6 @@ namespace test
 
 int main() 
 {
+  test01();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/istringstream.cc b/libstdc++-v3/testsuite/27_io/istringstream.cc
new file mode 100644 (file)
index 0000000..d119f67
--- /dev/null
@@ -0,0 +1,60 @@
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.7.2 - Template class basic_istringstream
+// NB: This file is for testing basic_istringstream with NO OTHER INCLUDES.
+
+#include <sstream>
+
+// { dg-do compile }
+
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::istringstream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
+namespace test 
+{
+  using namespace std;
+  typedef short type_t;
+  template class basic_istringstream<type_t, char_traits<type_t> >;
+} // test
+
+int main() 
+{
+  test01();
+  return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/ofstream.cc b/libstdc++-v3/testsuite/27_io/ofstream.cc
new file mode 100644 (file)
index 0000000..6b9d07d
--- /dev/null
@@ -0,0 +1,60 @@
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.8.1.8 - Template class basic_ofstream
+// NB: This file is for testing basic_ofstream with NO OTHER INCLUDES.
+
+#include <fstream>
+
+// { dg-do compile }
+
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::ifstream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
+namespace test 
+{
+  using namespace std;
+  typedef short type_t;
+  template class basic_ifstream<type_t, char_traits<type_t> >;
+} // test
+
+int main() 
+{
+  test01();
+  return 0;
+}
index cbc4a6739c2b8f47f43bef8be605ec9df17f27d2..ae524ec61f29eb32efcaee96806ef569f75b2758 100644 (file)
 
 // { dg-do compile }
 
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::ostream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
 namespace test 
 {
   using namespace std;
@@ -43,5 +55,6 @@ namespace test
 
 int main() 
 {
+  test01();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/ostringstream.cc b/libstdc++-v3/testsuite/27_io/ostringstream.cc
new file mode 100644 (file)
index 0000000..c8a9dfc
--- /dev/null
@@ -0,0 +1,60 @@
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.7.3 - Class basic_ostringstream
+// NB: This file is for testing basic_ostringstream with NO OTHER INCLUDES.
+
+#include <sstream>
+
+// { dg-do compile }
+
+// libstdc++/7216
+void test01()
+{
+  // Check for required typedefs
+  typedef std::ostringstream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
+}
+
+namespace test 
+{
+  using namespace std;
+  typedef short type_t;
+  template class basic_ostringstream<type_t, char_traits<type_t> >;
+} // test
+
+int main() 
+{
+  test01();
+  return 0;
+}
index 4e7f861b516f8990886dcbc10da65eef6144604a..bf823697c830811400126d5b26466d8fc34ced79 100644 (file)
@@ -1,6 +1,6 @@
 // 2001-05-23 Benjamin Kosnik  <bkoz@redhat.com>
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
@@ -97,9 +97,61 @@ void test02()
   // These semantics are a joke, a serious defect, and incredibly lame.
 }
 
+// 03: sanity checks for strings, stringbufs
+void
+test03()
+{
+  bool test = false;
+
+  // Empty string sanity check.
+  std::string str01;
+  std::string::iterator __i_start = str01.begin();
+  std::string::iterator __i_end = str01.end();
+  std::string::size_type len = str01.size();
+  test = __i_start == __i_end;
+  VERIFY( len == 0 );
+
+  // Full string sanity check.
+  std::string str02("these golden days, i spend waiting for you:\n"
+                   "Betty Carter on Verve with I'm Yours and You're Mine.");
+  __i_start = str02.begin();
+  __i_end = str02.end();
+  len = str02.size();
+  VERIFY( __i_start != __i_end );
+  VERIFY( len != 0 );
+  // Test an empty ostringstream for sanity.
+  std::ostringstream ostrstream0;
+  std::string str03 = ostrstream0.str();
+  __i_start = str03.begin();
+  __i_end = str03.end();
+  len = str03.size();
+  VERIFY( __i_start == __i_end );
+  VERIFY( len == 0 );
+  VERIFY( str01 == str03 );
+}
+
+// user-reported error
+class derived_oss: public std::ostringstream 
+{
+public:
+  derived_oss() : std::ostringstream() { }
+};
+
+void
+test04()
+{
+  bool test = true;
+  derived_oss yy;
+  yy << "buena vista social club\n";
+  VERIFY( yy.str() == std::string("buena vista social club\n") );
+}
+
 int main()
 {
   test01();
   test02();
+  test03();
+  test04();
   return 0;
 }
index 3f9a3192b7e0174c1ccb6aa843a185d585210f6f..905dee089de81cac8c2892af5d7c2d2fd81791a9 100644 (file)
@@ -1,6 +1,6 @@
-// 1999-10-11 bkoz
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
 
-// Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+// Copyright (C) 2002 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
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-// 27.5.2 template class basic_streambuf
+// 27.5.2 - Template class basic_streambuf
+// NB: This file is for testing basic_streambuf with NO OTHER INCLUDES.
 
-#include <cstring> // for memset, memcmp
 #include <streambuf>
-#include <string>
-#include <ostream>
-#include <testsuite_hooks.h>
 
-class testbuf : public std::streambuf
-{
-public:
-
-  // Typedefs:
-  typedef std::streambuf::traits_type traits_type;
-  typedef std::streambuf::char_type char_type;
-
-  testbuf(): std::streambuf() 
-  { _M_mode = (std::ios_base::in | std::ios_base::out); }
-
-  bool
-  check_pointers()
-  { 
-    bool test = true;
-    VERIFY( this->eback() == NULL );
-    VERIFY( this->gptr() == NULL );
-    VERIFY( this->egptr() == NULL );
-    VERIFY( this->pbase() == NULL );
-    VERIFY( this->pptr() == NULL );
-    VERIFY( this->epptr() == NULL );
-    return test;
-  }
-
-  int_type 
-  pub_uflow() 
-  { return (this->uflow()); }
-
-  int_type 
-  pub_overflow(int_type __c = traits_type::eof()) 
-  { return (this->overflow(__c)); }
-
-  int_type 
-  pub_pbackfail(int_type __c) 
-  { return (this->pbackfail(__c)); }
-
-  void 
-  pub_setg(char* beg, char* cur, char *end) 
-  { this->setg(beg, cur, end); }
-
-  void 
-  pub_setp(char* beg, char* end) 
-  { this->setp(beg, end); }
-
-protected:
-  int_type 
-  underflow() 
-  { 
-    int_type __retval = traits_type::eof();
-    if (this->gptr() < this->egptr())
-      __retval = traits_type::not_eof(0); 
-    return __retval;
-  }
-};
+// { dg-do compile }
 
+// libstdc++/7216
 void test01()
 {
-  typedef testbuf::traits_type traits_type;
-  typedef testbuf::int_type int_type;
-
-  bool test = true;
-  char* lit01 = "chicago underground trio/possible cube on delmark";
-  testbuf buf01;
-
-  // 27.5.2.1 basic_streambuf ctors
-  // default ctor initializes 
-  // - all pointer members to null pointers
-  // - locale to current global locale
-  VERIFY( buf01.check_pointers() );
-  VERIFY( buf01.getloc() == std::locale() );
-
-  // 27.5.2.3.1 get area
-  // 27.5.2.2.3 get area
-  // 27.5.2.4.3 get area
-  int i01 = 3;
-  buf01.pub_setg(lit01, lit01, (lit01 + i01));
-  VERIFY( i01 == buf01.in_avail() );
-
-  VERIFY( buf01.pub_uflow() == lit01[0] );
-  VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) );
-  VERIFY( buf01.pub_uflow() == lit01[1] );
-  VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) );
-  VERIFY( buf01.pub_uflow() == lit01[2] );
-  VERIFY( buf01.sgetc() == traits_type::eof() );
-
-  // pbackfail
-  buf01.pub_setg(lit01, lit01, (lit01 + i01));
-  VERIFY( i01 == buf01.in_avail() );
-  int_type intt01 = traits_type::to_int_type('b');
-  VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) );
-
-  // overflow
-  VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) );
-  VERIFY( traits_type::eof() == buf01.pub_overflow() );
-  VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) );
-
-  // sputn/xsputn
-  char* lit02 = "isotope 217: the unstable molecule on thrill jockey";
-  int i02 = std::strlen(lit02);
-  char carray[i02 + 1];
-  std::memset(carray, 0, i02 + 1);
-
-  buf01.pub_setp(carray, (carray + i02));
-  buf01.sputn(lit02, 0);
-  VERIFY( carray[0] == 0 );
-  VERIFY( lit02[0] == 'i' );
-  buf01.sputn(lit02, 1);
-  VERIFY( lit02[0] == carray[0] );
-  VERIFY( lit02[1] == 's' );
-  VERIFY( carray[1] == 0 );
-  buf01.sputn(lit02 + 1, 10);
-  VERIFY( std::memcmp(lit02, carray, 10) == 0 );
-  buf01.sputn(lit02 + 11, 20);
-  VERIFY( std::memcmp(lit02, carray, 30) == 0 );
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-}
-
-void test02()
-{
-  typedef testbuf::traits_type traits_type;
-  typedef testbuf::int_type int_type;
-
-  bool test = true;
-  char* lit01 = "chicago underground trio/possible cube on delmark";
-  testbuf buf01;
-
-  // 27.5.2.1 basic_streambuf ctors
-  // default ctor initializes 
-  // - all pointer members to null pointers
-  // - locale to current global locale
-  VERIFY( buf01.check_pointers() );
-  VERIFY( buf01.getloc() == std::locale() );
-
-  // 27.5.2.2.5 Put area
-  size_t i01 = traits_type::length(lit01);
-  char carray01[i01];
-  std::memset(carray01, 0, i01);
-  
-  buf01.pub_setg(lit01, lit01, lit01 + i01);
-  buf01.sgetn(carray01, 0);
-  VERIFY( carray01[0] == 0 );
-  buf01.sgetn(carray01, 1);
-  VERIFY( carray01[0] == 'c' );
-  buf01.sgetn(carray01 + 1, i01 - 1);
-  VERIFY( carray01[0] == 'c' );
-  VERIFY( carray01[1] == 'h' );
-  VERIFY( carray01[i01 - 1] == 'k' );
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
+  // Check for required typedefs
+  typedef std::streambuf test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
 }
-// test03
-// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html
-template<typename charT, typename traits = std::char_traits<charT> >
-  class basic_nullbuf : public std::basic_streambuf<charT, traits>
-  {
-  protected:
-    typedef typename
-      std::basic_streambuf<charT, traits>::int_type int_type;
-    virtual int_type 
-    overflow(int_type c) 
-    {  return traits::not_eof(c); }
-  };
-
-typedef basic_nullbuf<char> nullbuf;
-typedef basic_nullbuf<wchar_t> wnullbuf;
-
-template<typename T>
-  char
-  print(const T& x) 
-  {
-   nullbuf ob;
-   std::ostream out(&ob); 
-   out << x << std::endl;
-   return (!out ? '0' : '1');
- }
 
-void test03() 
+namespace test 
 {
-  bool test = true;
-  const std::string control01("11111");
-  std::string test01;
-
-  test01 += print(true);
-  test01 += print(3.14159);
-  test01 += print(10);
-  test01 += print('x');
-  test01 += print("pipo");
-
-  VERIFY( test01 == control01 );
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-}
-
-class setpbuf : public std::streambuf
-{
-  char                 buffer[4];
-  std::string  result;
-
-public:
-
-  std::string&
-  get_result()
-  { return result; }
-
-  setpbuf()
-  {
-    char foo [32];
-    setp(foo, foo + 32);
-    setp(buffer, buffer + 4);
-  }
-
-  ~setpbuf()
-  { sync(); }
-
-  virtual int_type 
-  overflow(int_type n)
-  {
-    if (sync() != 0)
-      return traits_type::eof();
-    
-    result += traits_type::to_char_type(n);
-    
-    return n;
-  }
-  
-  virtual int 
-  sync()
-  {
-    result.append(pbase(), pptr());
-    setp(buffer, buffer + 4);
-    return 0;
-  }
-};
-
-// libstdc++/1057
-void test04()
-{
-  bool test = true;
-  std::string text = "abcdefghijklmn";
-  
-  // 01
-  setpbuf sp1;
-  // Here xsputn writes over sp1.result
-  sp1.sputn(text.c_str(), text.length());
-
-  // This crashes when result is accessed
-  sp1.pubsync();
-  VERIFY( sp1.get_result() == text );
-  
-
-  // 02
-  setpbuf sp2;
-  for (std::string::size_type i = 0; i < text.length(); ++i)
-    {
-      // sputc also writes over result
-      sp2.sputc(text[i]);
-    }
-  
-  // Crash here
-  sp2.pubsync();
-  VERIFY( sp2.get_result() == text );
-}
-
-class nullsetpbuf : public std::streambuf
-{
-  char foo[64];
-public:
-  nullsetpbuf()
-  {
-    setp(foo, foo + 64);
-    setp(NULL, NULL);
-  }
-};
-
-// libstdc++/1057
-void test05()
-{
-    std::string text1 = "abcdefghijklmn";
-
-    nullsetpbuf nsp;
-    // Immediate crash as xsputn writes to null pointer
-    nsp.sputn(text1.c_str(), text1.length());
-    // ditto
-    nsp.sputc('a');
-}
-
-// test06
-namespace gnu 
-{
-  class something_derived;
-}
-
-class gnu::something_derived : std::streambuf { };
-
-// libstdc++/3599
-class testbuf2 : public std::streambuf
-{
-public:
-  typedef std::streambuf::traits_type traits_type;
-
-  testbuf2() : std::streambuf() { }
-protected:
-  int_type 
-  overflow(int_type c = traits_type::eof()) 
-  { return traits_type::not_eof(0); }
-};
-
-void
-test07()
-{
-  bool test = true;
-  testbuf2 ob;
-  std::ostream out(&ob); 
-
-  out << "gasp";
-  VERIFY(out.good());
-
-  out << std::endl;
-  VERIFY(out.good());
-}
+  using namespace std;
+  typedef short type_t;
+  template class basic_streambuf<type_t, char_traits<type_t> >;
+} // test
 
 int main() 
 {
   test01();
-  test02();
-  test03();
-
-  test04();
-  test05();
-
-  test07();
   return 0;
 }
diff --git a/libstdc++-v3/testsuite/27_io/streambuf_members.cc b/libstdc++-v3/testsuite/27_io/streambuf_members.cc
new file mode 100644 (file)
index 0000000..3f9a319
--- /dev/null
@@ -0,0 +1,378 @@
+// 1999-10-11 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
+
+// 27.5.2 template class basic_streambuf
+
+#include <cstring> // for memset, memcmp
+#include <streambuf>
+#include <string>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+class testbuf : public std::streambuf
+{
+public:
+
+  // Typedefs:
+  typedef std::streambuf::traits_type traits_type;
+  typedef std::streambuf::char_type char_type;
+
+  testbuf(): std::streambuf() 
+  { _M_mode = (std::ios_base::in | std::ios_base::out); }
+
+  bool
+  check_pointers()
+  { 
+    bool test = true;
+    VERIFY( this->eback() == NULL );
+    VERIFY( this->gptr() == NULL );
+    VERIFY( this->egptr() == NULL );
+    VERIFY( this->pbase() == NULL );
+    VERIFY( this->pptr() == NULL );
+    VERIFY( this->epptr() == NULL );
+    return test;
+  }
+
+  int_type 
+  pub_uflow() 
+  { return (this->uflow()); }
+
+  int_type 
+  pub_overflow(int_type __c = traits_type::eof()) 
+  { return (this->overflow(__c)); }
+
+  int_type 
+  pub_pbackfail(int_type __c) 
+  { return (this->pbackfail(__c)); }
+
+  void 
+  pub_setg(char* beg, char* cur, char *end) 
+  { this->setg(beg, cur, end); }
+
+  void 
+  pub_setp(char* beg, char* end) 
+  { this->setp(beg, end); }
+
+protected:
+  int_type 
+  underflow() 
+  { 
+    int_type __retval = traits_type::eof();
+    if (this->gptr() < this->egptr())
+      __retval = traits_type::not_eof(0); 
+    return __retval;
+  }
+};
+
+void test01()
+{
+  typedef testbuf::traits_type traits_type;
+  typedef testbuf::int_type int_type;
+
+  bool test = true;
+  char* lit01 = "chicago underground trio/possible cube on delmark";
+  testbuf buf01;
+
+  // 27.5.2.1 basic_streambuf ctors
+  // default ctor initializes 
+  // - all pointer members to null pointers
+  // - locale to current global locale
+  VERIFY( buf01.check_pointers() );
+  VERIFY( buf01.getloc() == std::locale() );
+
+  // 27.5.2.3.1 get area
+  // 27.5.2.2.3 get area
+  // 27.5.2.4.3 get area
+  int i01 = 3;
+  buf01.pub_setg(lit01, lit01, (lit01 + i01));
+  VERIFY( i01 == buf01.in_avail() );
+
+  VERIFY( buf01.pub_uflow() == lit01[0] );
+  VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) );
+  VERIFY( buf01.pub_uflow() == lit01[1] );
+  VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) );
+  VERIFY( buf01.pub_uflow() == lit01[2] );
+  VERIFY( buf01.sgetc() == traits_type::eof() );
+
+  // pbackfail
+  buf01.pub_setg(lit01, lit01, (lit01 + i01));
+  VERIFY( i01 == buf01.in_avail() );
+  int_type intt01 = traits_type::to_int_type('b');
+  VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) );
+
+  // overflow
+  VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) );
+  VERIFY( traits_type::eof() == buf01.pub_overflow() );
+  VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) );
+
+  // sputn/xsputn
+  char* lit02 = "isotope 217: the unstable molecule on thrill jockey";
+  int i02 = std::strlen(lit02);
+  char carray[i02 + 1];
+  std::memset(carray, 0, i02 + 1);
+
+  buf01.pub_setp(carray, (carray + i02));
+  buf01.sputn(lit02, 0);
+  VERIFY( carray[0] == 0 );
+  VERIFY( lit02[0] == 'i' );
+  buf01.sputn(lit02, 1);
+  VERIFY( lit02[0] == carray[0] );
+  VERIFY( lit02[1] == 's' );
+  VERIFY( carray[1] == 0 );
+  buf01.sputn(lit02 + 1, 10);
+  VERIFY( std::memcmp(lit02, carray, 10) == 0 );
+  buf01.sputn(lit02 + 11, 20);
+  VERIFY( std::memcmp(lit02, carray, 30) == 0 );
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+}
+
+void test02()
+{
+  typedef testbuf::traits_type traits_type;
+  typedef testbuf::int_type int_type;
+
+  bool test = true;
+  char* lit01 = "chicago underground trio/possible cube on delmark";
+  testbuf buf01;
+
+  // 27.5.2.1 basic_streambuf ctors
+  // default ctor initializes 
+  // - all pointer members to null pointers
+  // - locale to current global locale
+  VERIFY( buf01.check_pointers() );
+  VERIFY( buf01.getloc() == std::locale() );
+
+  // 27.5.2.2.5 Put area
+  size_t i01 = traits_type::length(lit01);
+  char carray01[i01];
+  std::memset(carray01, 0, i01);
+  
+  buf01.pub_setg(lit01, lit01, lit01 + i01);
+  buf01.sgetn(carray01, 0);
+  VERIFY( carray01[0] == 0 );
+  buf01.sgetn(carray01, 1);
+  VERIFY( carray01[0] == 'c' );
+  buf01.sgetn(carray01 + 1, i01 - 1);
+  VERIFY( carray01[0] == 'c' );
+  VERIFY( carray01[1] == 'h' );
+  VERIFY( carray01[i01 - 1] == 'k' );
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+}
+// test03
+// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html
+template<typename charT, typename traits = std::char_traits<charT> >
+  class basic_nullbuf : public std::basic_streambuf<charT, traits>
+  {
+  protected:
+    typedef typename
+      std::basic_streambuf<charT, traits>::int_type int_type;
+    virtual int_type 
+    overflow(int_type c) 
+    {  return traits::not_eof(c); }
+  };
+
+typedef basic_nullbuf<char> nullbuf;
+typedef basic_nullbuf<wchar_t> wnullbuf;
+
+template<typename T>
+  char
+  print(const T& x) 
+  {
+   nullbuf ob;
+   std::ostream out(&ob); 
+   out << x << std::endl;
+   return (!out ? '0' : '1');
+ }
+
+void test03() 
+{
+  bool test = true;
+  const std::string control01("11111");
+  std::string test01;
+
+  test01 += print(true);
+  test01 += print(3.14159);
+  test01 += print(10);
+  test01 += print('x');
+  test01 += print("pipo");
+
+  VERIFY( test01 == control01 );
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+}
+
+class setpbuf : public std::streambuf
+{
+  char                 buffer[4];
+  std::string  result;
+
+public:
+
+  std::string&
+  get_result()
+  { return result; }
+
+  setpbuf()
+  {
+    char foo [32];
+    setp(foo, foo + 32);
+    setp(buffer, buffer + 4);
+  }
+
+  ~setpbuf()
+  { sync(); }
+
+  virtual int_type 
+  overflow(int_type n)
+  {
+    if (sync() != 0)
+      return traits_type::eof();
+    
+    result += traits_type::to_char_type(n);
+    
+    return n;
+  }
+  
+  virtual int 
+  sync()
+  {
+    result.append(pbase(), pptr());
+    setp(buffer, buffer + 4);
+    return 0;
+  }
+};
+
+// libstdc++/1057
+void test04()
+{
+  bool test = true;
+  std::string text = "abcdefghijklmn";
+  
+  // 01
+  setpbuf sp1;
+  // Here xsputn writes over sp1.result
+  sp1.sputn(text.c_str(), text.length());
+
+  // This crashes when result is accessed
+  sp1.pubsync();
+  VERIFY( sp1.get_result() == text );
+  
+
+  // 02
+  setpbuf sp2;
+  for (std::string::size_type i = 0; i < text.length(); ++i)
+    {
+      // sputc also writes over result
+      sp2.sputc(text[i]);
+    }
+  
+  // Crash here
+  sp2.pubsync();
+  VERIFY( sp2.get_result() == text );
+}
+
+class nullsetpbuf : public std::streambuf
+{
+  char foo[64];
+public:
+  nullsetpbuf()
+  {
+    setp(foo, foo + 64);
+    setp(NULL, NULL);
+  }
+};
+
+// libstdc++/1057
+void test05()
+{
+    std::string text1 = "abcdefghijklmn";
+
+    nullsetpbuf nsp;
+    // Immediate crash as xsputn writes to null pointer
+    nsp.sputn(text1.c_str(), text1.length());
+    // ditto
+    nsp.sputc('a');
+}
+
+// test06
+namespace gnu 
+{
+  class something_derived;
+}
+
+class gnu::something_derived : std::streambuf { };
+
+// libstdc++/3599
+class testbuf2 : public std::streambuf
+{
+public:
+  typedef std::streambuf::traits_type traits_type;
+
+  testbuf2() : std::streambuf() { }
+protected:
+  int_type 
+  overflow(int_type c = traits_type::eof()) 
+  { return traits_type::not_eof(0); }
+};
+
+void
+test07()
+{
+  bool test = true;
+  testbuf2 ob;
+  std::ostream out(&ob); 
+
+  out << "gasp";
+  VERIFY(out.good());
+
+  out << std::endl;
+  VERIFY(out.good());
+}
+
+int main() 
+{
+  test01();
+  test02();
+  test03();
+
+  test04();
+  test05();
+
+  test07();
+  return 0;
+}
index bc0bbb4dd8e1365e5ffe2135e991ba0ce7da342d..00825b6b69c7130b20babc83ea34895f4a958ec5 100644 (file)
@@ -1,7 +1,6 @@
-// 981208 bkoz test functionality of basic_stringbuf for char_type == char
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
-// Free Software Foundation, Inc.
+// Copyright (C) 2002 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
 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
 // USA.
 
-#include <sstream>
-#include <testsuite_hooks.h>
-
-std::string str_01("mykonos. . . or what?");
-std::string str_02("paris, or sainte-maxime?");
-std::string str_03;
-std::stringbuf strb_01(str_01);
-std::stringbuf strb_02(str_02, std::ios_base::in);
-std::stringbuf strb_03(str_03, std::ios_base::out);
-
-
-// test the underlying allocator
-bool test01() {
-  bool test = false;
-  std::allocator<char> alloc_01;
-  std::allocator<char>::size_type size_01 = alloc_01.max_size();
-  std::allocator<char>::pointer p_01 = alloc_01.allocate(32);
-
-  return true;
-}
-
-
-// test the streambuf/stringbuf locale settings
-bool test02() {
-  std::locale loc_tmp;
-  loc_tmp = strb_01.getloc();
-  strb_01.pubimbue(loc_tmp); //This should initialize _M_init to true
-  strb_01.getloc(); //This should just return _M_locale
-
-  return true;
-}
-
-
-// test member functions
-bool test03() {
-  bool test = true;
-
-  //stringbuf::str()
-  VERIFY( strb_01.str() == str_01 );
-  VERIFY( strb_02.str() == str_02 );
-  VERIFY( strb_03.str() == str_03 );
-  //stringbuf::str(string&)
-  strb_03.str("none of the above, go to the oberoi in cairo, egypt.");
-  strb_03.str(str_01);
-  std::streamsize d1 = strb_01.in_avail();
-  std::streamsize d2 = strb_03.in_avail();
-  VERIFY( d1 ); // non-zero
-  VERIFY( !d2 ); // zero, cuz ios_base::out
-  VERIFY( d1 != d2 ); //these should be the same
-  VERIFY( str_01.length() == d1 );  
-  VERIFY( strb_01.str() == strb_03.str() ); //ditto
-
-  // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the
-  // string in question contains embedded NUL characters.  Note that in this
-  // embedded-NUL situation, the size must be passed to the string ctor.
-  std::string str_nulls ("eschew \0 obfuscation", 20);  // tested in 21_strings
-  std::stringbuf strb_normal (str_01);
-  std::stringbuf strb_nulls (str_nulls);
-  strb_normal.str(str_nulls);  // tried using 'strb_01' rather than declaring
-                               // another variable, but then test04 broke!
-  VERIFY( strb_nulls.in_avail() == str_nulls.size()  );
-  VERIFY( strb_nulls.str().size() == 20              );
-  VERIFY( strb_normal.in_avail() == str_nulls.size() );
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-  return test;
-}
-
-
-// test overloaded virtual functions
-bool test04() {
-  bool                         test = true;
-  std::string          str_tmp;
-  std::stringbuf               strb_tmp;
-  std::streamsize              strmsz_1, strmsz_2;
-  std::streamoff               strmof_1(-1), strmof_2;
-  typedef std::stringbuf::int_type int_type;
-  typedef std::stringbuf::traits_type traits_type;
-  typedef std::stringbuf::pos_type pos_type;
-  typedef std::stringbuf::off_type off_type;
-
-  // GET
-  // int in_avail()
-  strmof_1 = strb_01.in_avail();
-  strmof_2 = strb_02.in_avail();
-  VERIFY( strmof_1 != strmof_2 );
-  VERIFY( strmof_1 == str_01.length() );
-  VERIFY( strmof_2 == str_02.length() );
-  strmof_1 = strb_03.in_avail(); 
-  VERIFY( strmof_1 == 0 ); // zero cuz write-only, or eof()? zero, from showmany
-
-  // int_type sbumpc()
-  // if read_cur not avail, return uflow(), else return *read_cur & increment
-  int_type c1 = strb_01.sbumpc();
-  int_type c2 = strb_02.sbumpc();
-  VERIFY( c1 != c2 );
-  VERIFY( c1 == str_01[0] );
-  VERIFY( c2 == str_02[0] ); //should equal first letter at this point
-  int_type c3 = strb_01.sbumpc();
-  int_type c4 = strb_02.sbumpc();
-  VERIFY( c1 != c2 );
-  VERIFY( c1 != c3 );
-  VERIFY( c2 != c4 );
-  int_type c5 = strb_03.sbumpc();
-  VERIFY( c5 == traits_type::eof() );
-
-  // int_type sgetc()
-  // if read_cur not avail, return uflow(), else return *read_cur  
-  int_type c6 = strb_01.sgetc();
-  int_type c7 = strb_02.sgetc();
-  VERIFY( c6 != c3 );
-  VERIFY( c7 != c4 );
-  int_type c8 = strb_01.sgetc();
-  int_type c9 = strb_02.sgetc();
-  VERIFY( c6 == c8 );
-  VERIFY( c7 == c9 );
-  c5 = strb_03.sgetc();
-  VERIFY( c5 == traits_type::eof() );
-
-  // int_type snextc()
-  // calls sbumpc and if sbumpc != eof, return sgetc
-  c6 = strb_01.snextc();
-  c7 = strb_02.snextc();
-  VERIFY( c6 != c8 );
-  VERIFY( c7 != c9 );
-  VERIFY( c6 == str_01[3] );
-  VERIFY( c7 == str_02[3] ); //should equal fourth letter at this point
-  c5 = strb_03.snextc();
-  VERIFY( c5 == traits_type::eof() );
-
-  // int showmanyc
-  // streamsize sgetn(char_type *s, streamsize n)
-  // streamsize xsgetn(char_type *s, streamsize n)
-  // assign up to n chars to s from input sequence, indexing in_cur as
-  // approp and returning the number of chars assigned
-  strmsz_1 = strb_01.in_avail();
-  strmsz_2 = strb_02.in_avail();
-  test = strmsz_1 != strmsz_2;
-  VERIFY( strmsz_1 != str_01.length() );
-  VERIFY( strmsz_2 != str_02.length() ); //because now we've moved into string
-  char carray1[11] = "";
-  strmsz_1 = strb_01.sgetn(carray1, 10);
-  char carray2[20] = "";
-  strmsz_2 = strb_02.sgetn(carray2, 10);
-  VERIFY( strmsz_1 == strmsz_2 );
-  VERIFY( strmsz_1 == 10 );
-  c1 = strb_01.sgetc();
-  c2 = strb_02.sgetc();
-  VERIFY( c6 == c1 ); //just by co-incidence both o's
-  VERIFY( c7 != c2 ); // n != i
-  VERIFY( c1 == str_01[13] );
-  VERIFY( c2 == str_02[13] ); //should equal fourteenth letter at this point
-  strmsz_1 = strb_03.sgetn(carray1, 10);
-  VERIFY( !strmsz_1 ); //zero
-  strmsz_1 = strb_02.in_avail();
-  strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5);
-  VERIFY( strmsz_1 == strmsz_2 ); //write off the end
-  c4 = strb_02.sgetc(); // should be EOF
-  VERIFY( c4 == traits_type::eof() );
-
-  // PUT
-  // int_type sputc(char_type c)
-  // if out_cur not avail, return overflow. Else, stores c at out_cur,
-  // increments out_cur, and returns c as int_type
-  strb_03.str(str_01); //reset
-  std::string::size_type sz1 = strb_03.str().length();
-  c1 = strb_03.sputc('a'); 
-  std::string::size_type sz2 = strb_03.str().length();
-  VERIFY( sz1 == sz2 ); //cuz inserting at out_cur, which is at beg to start
-  c2 = strb_03.sputc('b'); 
-  VERIFY( c1 != c2 );
-  VERIFY( strb_03.str() != str_01 );
-  c3 = strb_02.sputc('a'); // should be EOF because this is read-only
-  VERIFY( c3 == traits_type::eof() );
-  
-  // streamsize sputn(const char_typs* s, streamsize n)
-  // write up to n chars to out_cur from s, returning number assigned
-  // NB *sputn will happily put '\0' into your stream if you give it a chance*
-  str_tmp = strb_03.str();
-  sz1 = str_tmp.length();
-  strmsz_1 = strb_03.sputn("racadabras", 10);//"abracadabras or what?"
-  sz2 = strb_03.str().length();
-  VERIFY( sz1 == sz2 ); //shouldn't have changed length
-  VERIFY( strmsz_1 == 10 );
-  VERIFY( str_tmp != strb_03.str() );
-  strmsz_2 = strb_03.sputn(", i wanna reach out and", 10);
-  VERIFY( strmsz_1 == strmsz_2 ); // should re-allocate, copy 10 chars.
-  VERIFY( strmsz_1 == 10 );
-  VERIFY( strmsz_2 == 10 );
-  sz2 = strb_03.str().length();
-  VERIFY( sz1 != sz2 ); // need to change length
-  VERIFY( str_tmp != strb_03.str() );
-  str_tmp = strb_02.str();
-  strmsz_1 = strb_02.sputn("racadabra", 10);
-  VERIFY( strmsz_1 == 0 );  
-  VERIFY( str_tmp == strb_02.str() );
-
-  // PUTBACK
-  // int_type pbfail(int_type c)
-  // called when gptr() null, gptr() == eback(), or traits::eq(*gptr, c) false
-  // "pending sequence" is:
-  //   1) everything as defined in underflow
-  //   2) + if (traits::eq_int_type(c, traits::eof()), then input
-  //   sequence is backed up one char before the pending sequence is
-  //   determined.
-  //   3) + if (not 2) then c is prepended. Left unspecified is
-  //   whether the input sequence is backedup or modified in any way
-  // returns traits::eof() for failure, unspecified other value for success
+// As a special exception, you may use this file as part of a free software
+// library without restriction.  Specifically, if other files instantiate
+// templates or use macros or inline functions from this file, or you compile
+// this file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be covered by
+// the GNU General Public License.  This exception does not however
+// invalidate any other reasons why the executable file might be covered by
+// the GNU General Public License.
 
-  // int_type sputbackc(char_type c)
-  // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
-  // otherwise decrements in_cur and returns *gptr()
-  strmsz_1 = strb_01.in_avail();
-  str_tmp = strb_01.str();
-  c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
-  c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?"
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( c3 == c2 );
-  VERIFY( strb_01.str() == std::string("mykonos. . .zor what?") );
-  VERIFY( str_tmp.size() == strb_01.str().size() );
-  //test for _in_cur == _in_beg
-  strb_01.str(str_tmp);
-  strmsz_1 = strb_01.in_avail();
-  c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
-  c2 = strb_01.sputbackc('z');//"mykonos. . . or what?"
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( c3 != c2 );
-  VERIFY( c1 == c3 );
-  VERIFY( c2 == traits_type::eof() );
-  VERIFY( strb_01.str() == str_tmp );
-  VERIFY( str_tmp.size() == strb_01.str().size() );
-  // test for replacing char with identical one
-  strb_01.str(str_01); //reset
-  strmsz_1 = strb_01.in_avail();
-  strb_01.sbumpc();
-  strb_01.sbumpc();
-  c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
-  c2 = strb_01.sputbackc('y');//"mykonos. . . or what?"
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( c3 == c2 );
-  VERIFY( c1 != c3 );
-  VERIFY( strb_01.str() == str_01 );
-  VERIFY( str_01.size() == strb_01.str().size() );
-  //test for ios_base::out
-  strmsz_2 = strb_03.in_avail();
-  c4 = strb_03.sputbackc('x');
-  VERIFY( c4 == traits_type::eof() );
+// 27.7.1 - Template class basic_stringbuf
+// NB: This file is for testing basic_stringbuf with NO OTHER INCLUDES.
 
-  // int_type sungetc()
-  // if in_cur not avail, return pbackfail(), else decrement and
-  // return to_int_type(*gptr())
-  for (int i = 0; i<12; ++i)
-    strb_01.sbumpc();
-  strmsz_1 = strb_01.in_avail();
-  str_tmp = strb_01.str();
-  c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
-  c2 = strb_01.sungetc();//"mykonos. . . or what?"
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( c3 == c2 );
-  VERIFY( c1 != c3 );
-  VERIFY( c2 == ' ' );
-  VERIFY( strb_01.str() == str_01 );
-  VERIFY( str_01.size() == strb_01.str().size() );
-  //test for _in_cur == _in_beg
-  strb_01.str(str_tmp);
-  strmsz_1 = strb_01.in_avail();
-  c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
-  c2 = strb_01.sungetc();//"mykonos. . . or what?"
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( c3 != c2 );
-  VERIFY( c1 == c3 );
-  VERIFY( c2 == traits_type::eof() );
-  VERIFY( strb_01.str() == str_01 );
-  VERIFY( str_01.size() == strb_01.str().size() );
-  // test for replacing char with identical one
-  strb_01.str(str_01); //reset
-  strmsz_1 = strb_01.in_avail();
-  strb_01.sbumpc();
-  strb_01.sbumpc();
-  c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
-  c2 = strb_01.sungetc();//"mykonos. . . or what?"
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( c3 == c2 );
-  VERIFY( c1 != c3 );
-  VERIFY( strb_01.str() == str_01 );
-  VERIFY( str_01.size() == strb_01.str().size() );
-  //test for ios_base::out
-  strmsz_2 = strb_03.in_avail();
-  c4 = strb_03.sungetc();
-  VERIFY( c4 == traits_type::eof() );
-
-  // BUFFER MANAGEMENT & POSITIONING
-  // sync
-  // pubsync
-  strb_01.pubsync();
-  strb_02.pubsync();
-  strb_03.pubsync();
-
-  // setbuf
-  // pubsetbuf(char_type* s, streamsize n)
-  str_tmp = std::string("naaaah, go to cebu");
-  strb_01.pubsetbuf(const_cast<char*> (str_tmp.c_str()), str_tmp.size());
-  VERIFY( strb_01.str() == str_tmp );
-  strb_01.pubsetbuf(0,0);
-  VERIFY( strb_01.str() == str_tmp );
-
-  // seekoff
-  // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
-  // alters the stream position to off
-  pos_type pt_1(off_type(-1));
-  pos_type pt_2(off_type(0));
-  off_type off_1 = 0;
-  off_type off_2 = 0;
-  strb_01.str(str_01); //in|out ("mykonos. . . or what?");
-  strb_02.str(str_02); //in ("paris, or sainte-maxime?");
-  strb_03.str(str_03); //out ("")
-  //IN|OUT
-  //beg
-  pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
-  off_1 = pt_1;
-  VERIFY( off_1 >= 0 );
-  c1 = strb_01.snextc(); //current in pointer +1
-  VERIFY( c1 == 'o' );
-  c2 = strb_01.sputc('x');  //test current out pointer
-  str_tmp = std::string("myxonos. . . or what?");
-  VERIFY( strb_01.str() == str_tmp );
-  //cur
-  pt_1 = strb_01.pubseekoff(2, std::ios_base::cur);
-  off_1 = pt_1;
-  VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams
-  pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
-  off_1 = pt_1;
-  pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
-  off_2 = pt_2;
-  VERIFY( off_2 == off_1 + 2 );
-  c1 = strb_01.snextc(); //current in pointer + 1
-  VERIFY( c1 == ' ' );
-  c2 = strb_01.sputc('x');  //test current out pointer
-  str_tmp = std::string("myxxnos. . . or what?");
-  VERIFY( strb_01.str() == str_tmp );
-  //end
-  pt_2 = strb_01.pubseekoff(2, std::ios_base::end);
-  off_1 = pt_2;
-  VERIFY( off_1 == -1 ); // not a valid position
-  VERIFY( strb_01.str() == str_tmp );
-  // end part two (from the filebuf tests)
-  strb_01.pubseekoff(0, std::ios_base::end);
-  strmsz_1 = strb_01.in_avail(); // 0 cuz at the end
-  c1 = strb_01.sgetc(); 
-  c2 = strb_01.sungetc();
-  strmsz_2 = strb_01.in_avail(); // 1
-  c3 = strb_01.sgetc();
-  VERIFY( c1 != c2 );
-  VERIFY( strmsz_2 != strmsz_1 );
-  VERIFY( strmsz_2 == 1 );
-  // end part three
-  strmsz_1 = strb_01.str().size();
-  strmsz_2 = strb_01.sputn(" ravi shankar meets carlos santana in LoHa", 90);
-  strb_01.pubseekoff(0, std::ios_base::end);
-  strb_01.sputc('<');
-  str_tmp = strb_01.str();
-  VERIFY( str_tmp.size() == strmsz_1 + strmsz_2 + 1 );
-  // IN
-  // OUT
-
-  // seekpos
-  // pubseekpos(pos_type sp, ios_base::openmode)
-  // alters the stream position to sp
-  strb_01.str(str_01); //in|out ("mykonos. . . or what?");
-  strb_02.str(str_02); //in ("paris, or sainte-maxime?");
-  strb_03.str(str_03); //out ("")
-  //IN|OUT
-  //beg
-  pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
-  off_1 = pt_1;
-  VERIFY( off_1 >= 0 );
-  pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out);
-  off_1 = pt_1;
-  c1 = strb_01.snextc(); //current in pointer +1
-  VERIFY( c1 == 'o' );
-  c2 = strb_01.sputc('x');  //test current out pointer
-  str_tmp = std::string("myxonos. . . or what?");
-  VERIFY( strb_01.str() == str_tmp );
-  strb_01.pubsync(); //resets pointers
-  pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out);
-  off_2 = pt_2;
-  VERIFY( off_1 == off_2 );
-  c3 = strb_01.snextc(); //current in pointer +1
-  VERIFY( c1 == c3 );
-  c2 = strb_01.sputc('x');  //test current out pointer
-  str_tmp = std::string("myxonos. . . or what?");
-  VERIFY( strb_01.str() == str_tmp );
-
-  // VIRTUALS (indirectly tested)
-  // underflow
-  // if read position avail, returns *gptr()
-
-  // pbackfail(int_type c)
-  // put c back into input sequence
-
-  // overflow
-  // appends c to output seq
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-
-  return test;
-}
+#include <sstream>
 
+// { dg-do compile }
 
-// libstdc++/3955 -- ios_base::app overwrites from the beginning
-bool test05()
+// libstdc++/7216
+void test01()
 {
-  bool test = true;
-
-  std::ostringstream os ("foo");
-  os << "bar";
-
-  test = os.str() == "bar";
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-
-  return test;
+  // Check for required typedefs
+  typedef std::stringbuf test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
 }
 
-bool test06()
+namespace test 
 {
-  bool test = true;
-
-  std::ostringstream os ("foo", std::ios_base::app);
-  os << "bar";
-
-  test = os.str() == "foobar";
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
+  using namespace std;
+  typedef short type_t;
+  template class basic_stringbuf<type_t, char_traits<type_t> >;
+} // test
 
-  return test;
-}
-
-int main()
+int main() 
 {
   test01();
-  test02();
-  test03();
-  test04();
-  test05();
-  test06();
-
   return 0;
 }
-
-
-
-// more candy!!!
diff --git a/libstdc++-v3/testsuite/27_io/stringbuf_members.cc b/libstdc++-v3/testsuite/27_io/stringbuf_members.cc
new file mode 100644 (file)
index 0000000..bc0bbb4
--- /dev/null
@@ -0,0 +1,490 @@
+// 981208 bkoz test functionality of basic_stringbuf for char_type == char
+
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+std::string str_01("mykonos. . . or what?");
+std::string str_02("paris, or sainte-maxime?");
+std::string str_03;
+std::stringbuf strb_01(str_01);
+std::stringbuf strb_02(str_02, std::ios_base::in);
+std::stringbuf strb_03(str_03, std::ios_base::out);
+
+
+// test the underlying allocator
+bool test01() {
+  bool test = false;
+  std::allocator<char> alloc_01;
+  std::allocator<char>::size_type size_01 = alloc_01.max_size();
+  std::allocator<char>::pointer p_01 = alloc_01.allocate(32);
+
+  return true;
+}
+
+
+// test the streambuf/stringbuf locale settings
+bool test02() {
+  std::locale loc_tmp;
+  loc_tmp = strb_01.getloc();
+  strb_01.pubimbue(loc_tmp); //This should initialize _M_init to true
+  strb_01.getloc(); //This should just return _M_locale
+
+  return true;
+}
+
+
+// test member functions
+bool test03() {
+  bool test = true;
+
+  //stringbuf::str()
+  VERIFY( strb_01.str() == str_01 );
+  VERIFY( strb_02.str() == str_02 );
+  VERIFY( strb_03.str() == str_03 );
+  //stringbuf::str(string&)
+  strb_03.str("none of the above, go to the oberoi in cairo, egypt.");
+  strb_03.str(str_01);
+  std::streamsize d1 = strb_01.in_avail();
+  std::streamsize d2 = strb_03.in_avail();
+  VERIFY( d1 ); // non-zero
+  VERIFY( !d2 ); // zero, cuz ios_base::out
+  VERIFY( d1 != d2 ); //these should be the same
+  VERIFY( str_01.length() == d1 );  
+  VERIFY( strb_01.str() == strb_03.str() ); //ditto
+
+  // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the
+  // string in question contains embedded NUL characters.  Note that in this
+  // embedded-NUL situation, the size must be passed to the string ctor.
+  std::string str_nulls ("eschew \0 obfuscation", 20);  // tested in 21_strings
+  std::stringbuf strb_normal (str_01);
+  std::stringbuf strb_nulls (str_nulls);
+  strb_normal.str(str_nulls);  // tried using 'strb_01' rather than declaring
+                               // another variable, but then test04 broke!
+  VERIFY( strb_nulls.in_avail() == str_nulls.size()  );
+  VERIFY( strb_nulls.str().size() == 20              );
+  VERIFY( strb_normal.in_avail() == str_nulls.size() );
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+  return test;
+}
+
+
+// test overloaded virtual functions
+bool test04() {
+  bool                         test = true;
+  std::string          str_tmp;
+  std::stringbuf               strb_tmp;
+  std::streamsize              strmsz_1, strmsz_2;
+  std::streamoff               strmof_1(-1), strmof_2;
+  typedef std::stringbuf::int_type int_type;
+  typedef std::stringbuf::traits_type traits_type;
+  typedef std::stringbuf::pos_type pos_type;
+  typedef std::stringbuf::off_type off_type;
+
+  // GET
+  // int in_avail()
+  strmof_1 = strb_01.in_avail();
+  strmof_2 = strb_02.in_avail();
+  VERIFY( strmof_1 != strmof_2 );
+  VERIFY( strmof_1 == str_01.length() );
+  VERIFY( strmof_2 == str_02.length() );
+  strmof_1 = strb_03.in_avail(); 
+  VERIFY( strmof_1 == 0 ); // zero cuz write-only, or eof()? zero, from showmany
+
+  // int_type sbumpc()
+  // if read_cur not avail, return uflow(), else return *read_cur & increment
+  int_type c1 = strb_01.sbumpc();
+  int_type c2 = strb_02.sbumpc();
+  VERIFY( c1 != c2 );
+  VERIFY( c1 == str_01[0] );
+  VERIFY( c2 == str_02[0] ); //should equal first letter at this point
+  int_type c3 = strb_01.sbumpc();
+  int_type c4 = strb_02.sbumpc();
+  VERIFY( c1 != c2 );
+  VERIFY( c1 != c3 );
+  VERIFY( c2 != c4 );
+  int_type c5 = strb_03.sbumpc();
+  VERIFY( c5 == traits_type::eof() );
+
+  // int_type sgetc()
+  // if read_cur not avail, return uflow(), else return *read_cur  
+  int_type c6 = strb_01.sgetc();
+  int_type c7 = strb_02.sgetc();
+  VERIFY( c6 != c3 );
+  VERIFY( c7 != c4 );
+  int_type c8 = strb_01.sgetc();
+  int_type c9 = strb_02.sgetc();
+  VERIFY( c6 == c8 );
+  VERIFY( c7 == c9 );
+  c5 = strb_03.sgetc();
+  VERIFY( c5 == traits_type::eof() );
+
+  // int_type snextc()
+  // calls sbumpc and if sbumpc != eof, return sgetc
+  c6 = strb_01.snextc();
+  c7 = strb_02.snextc();
+  VERIFY( c6 != c8 );
+  VERIFY( c7 != c9 );
+  VERIFY( c6 == str_01[3] );
+  VERIFY( c7 == str_02[3] ); //should equal fourth letter at this point
+  c5 = strb_03.snextc();
+  VERIFY( c5 == traits_type::eof() );
+
+  // int showmanyc
+  // streamsize sgetn(char_type *s, streamsize n)
+  // streamsize xsgetn(char_type *s, streamsize n)
+  // assign up to n chars to s from input sequence, indexing in_cur as
+  // approp and returning the number of chars assigned
+  strmsz_1 = strb_01.in_avail();
+  strmsz_2 = strb_02.in_avail();
+  test = strmsz_1 != strmsz_2;
+  VERIFY( strmsz_1 != str_01.length() );
+  VERIFY( strmsz_2 != str_02.length() ); //because now we've moved into string
+  char carray1[11] = "";
+  strmsz_1 = strb_01.sgetn(carray1, 10);
+  char carray2[20] = "";
+  strmsz_2 = strb_02.sgetn(carray2, 10);
+  VERIFY( strmsz_1 == strmsz_2 );
+  VERIFY( strmsz_1 == 10 );
+  c1 = strb_01.sgetc();
+  c2 = strb_02.sgetc();
+  VERIFY( c6 == c1 ); //just by co-incidence both o's
+  VERIFY( c7 != c2 ); // n != i
+  VERIFY( c1 == str_01[13] );
+  VERIFY( c2 == str_02[13] ); //should equal fourteenth letter at this point
+  strmsz_1 = strb_03.sgetn(carray1, 10);
+  VERIFY( !strmsz_1 ); //zero
+  strmsz_1 = strb_02.in_avail();
+  strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5);
+  VERIFY( strmsz_1 == strmsz_2 ); //write off the end
+  c4 = strb_02.sgetc(); // should be EOF
+  VERIFY( c4 == traits_type::eof() );
+
+  // PUT
+  // int_type sputc(char_type c)
+  // if out_cur not avail, return overflow. Else, stores c at out_cur,
+  // increments out_cur, and returns c as int_type
+  strb_03.str(str_01); //reset
+  std::string::size_type sz1 = strb_03.str().length();
+  c1 = strb_03.sputc('a'); 
+  std::string::size_type sz2 = strb_03.str().length();
+  VERIFY( sz1 == sz2 ); //cuz inserting at out_cur, which is at beg to start
+  c2 = strb_03.sputc('b'); 
+  VERIFY( c1 != c2 );
+  VERIFY( strb_03.str() != str_01 );
+  c3 = strb_02.sputc('a'); // should be EOF because this is read-only
+  VERIFY( c3 == traits_type::eof() );
+  
+  // streamsize sputn(const char_typs* s, streamsize n)
+  // write up to n chars to out_cur from s, returning number assigned
+  // NB *sputn will happily put '\0' into your stream if you give it a chance*
+  str_tmp = strb_03.str();
+  sz1 = str_tmp.length();
+  strmsz_1 = strb_03.sputn("racadabras", 10);//"abracadabras or what?"
+  sz2 = strb_03.str().length();
+  VERIFY( sz1 == sz2 ); //shouldn't have changed length
+  VERIFY( strmsz_1 == 10 );
+  VERIFY( str_tmp != strb_03.str() );
+  strmsz_2 = strb_03.sputn(", i wanna reach out and", 10);
+  VERIFY( strmsz_1 == strmsz_2 ); // should re-allocate, copy 10 chars.
+  VERIFY( strmsz_1 == 10 );
+  VERIFY( strmsz_2 == 10 );
+  sz2 = strb_03.str().length();
+  VERIFY( sz1 != sz2 ); // need to change length
+  VERIFY( str_tmp != strb_03.str() );
+  str_tmp = strb_02.str();
+  strmsz_1 = strb_02.sputn("racadabra", 10);
+  VERIFY( strmsz_1 == 0 );  
+  VERIFY( str_tmp == strb_02.str() );
+
+  // PUTBACK
+  // int_type pbfail(int_type c)
+  // called when gptr() null, gptr() == eback(), or traits::eq(*gptr, c) false
+  // "pending sequence" is:
+  //   1) everything as defined in underflow
+  //   2) + if (traits::eq_int_type(c, traits::eof()), then input
+  //   sequence is backed up one char before the pending sequence is
+  //   determined.
+  //   3) + if (not 2) then c is prepended. Left unspecified is
+  //   whether the input sequence is backedup or modified in any way
+  // returns traits::eof() for failure, unspecified other value for success
+
+  // int_type sputbackc(char_type c)
+  // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail
+  // otherwise decrements in_cur and returns *gptr()
+  strmsz_1 = strb_01.in_avail();
+  str_tmp = strb_01.str();
+  c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
+  c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?"
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( c3 == c2 );
+  VERIFY( strb_01.str() == std::string("mykonos. . .zor what?") );
+  VERIFY( str_tmp.size() == strb_01.str().size() );
+  //test for _in_cur == _in_beg
+  strb_01.str(str_tmp);
+  strmsz_1 = strb_01.in_avail();
+  c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
+  c2 = strb_01.sputbackc('z');//"mykonos. . . or what?"
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( c3 != c2 );
+  VERIFY( c1 == c3 );
+  VERIFY( c2 == traits_type::eof() );
+  VERIFY( strb_01.str() == str_tmp );
+  VERIFY( str_tmp.size() == strb_01.str().size() );
+  // test for replacing char with identical one
+  strb_01.str(str_01); //reset
+  strmsz_1 = strb_01.in_avail();
+  strb_01.sbumpc();
+  strb_01.sbumpc();
+  c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
+  c2 = strb_01.sputbackc('y');//"mykonos. . . or what?"
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( c3 == c2 );
+  VERIFY( c1 != c3 );
+  VERIFY( strb_01.str() == str_01 );
+  VERIFY( str_01.size() == strb_01.str().size() );
+  //test for ios_base::out
+  strmsz_2 = strb_03.in_avail();
+  c4 = strb_03.sputbackc('x');
+  VERIFY( c4 == traits_type::eof() );
+
+  // int_type sungetc()
+  // if in_cur not avail, return pbackfail(), else decrement and
+  // return to_int_type(*gptr())
+  for (int i = 0; i<12; ++i)
+    strb_01.sbumpc();
+  strmsz_1 = strb_01.in_avail();
+  str_tmp = strb_01.str();
+  c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?"
+  c2 = strb_01.sungetc();//"mykonos. . . or what?"
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( c3 == c2 );
+  VERIFY( c1 != c3 );
+  VERIFY( c2 == ' ' );
+  VERIFY( strb_01.str() == str_01 );
+  VERIFY( str_01.size() == strb_01.str().size() );
+  //test for _in_cur == _in_beg
+  strb_01.str(str_tmp);
+  strmsz_1 = strb_01.in_avail();
+  c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?"
+  c2 = strb_01.sungetc();//"mykonos. . . or what?"
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( c3 != c2 );
+  VERIFY( c1 == c3 );
+  VERIFY( c2 == traits_type::eof() );
+  VERIFY( strb_01.str() == str_01 );
+  VERIFY( str_01.size() == strb_01.str().size() );
+  // test for replacing char with identical one
+  strb_01.str(str_01); //reset
+  strmsz_1 = strb_01.in_avail();
+  strb_01.sbumpc();
+  strb_01.sbumpc();
+  c1 = strb_01.sgetc(); //"my'k'onos. . . or what?"
+  c2 = strb_01.sungetc();//"mykonos. . . or what?"
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( c3 == c2 );
+  VERIFY( c1 != c3 );
+  VERIFY( strb_01.str() == str_01 );
+  VERIFY( str_01.size() == strb_01.str().size() );
+  //test for ios_base::out
+  strmsz_2 = strb_03.in_avail();
+  c4 = strb_03.sungetc();
+  VERIFY( c4 == traits_type::eof() );
+
+  // BUFFER MANAGEMENT & POSITIONING
+  // sync
+  // pubsync
+  strb_01.pubsync();
+  strb_02.pubsync();
+  strb_03.pubsync();
+
+  // setbuf
+  // pubsetbuf(char_type* s, streamsize n)
+  str_tmp = std::string("naaaah, go to cebu");
+  strb_01.pubsetbuf(const_cast<char*> (str_tmp.c_str()), str_tmp.size());
+  VERIFY( strb_01.str() == str_tmp );
+  strb_01.pubsetbuf(0,0);
+  VERIFY( strb_01.str() == str_tmp );
+
+  // seekoff
+  // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+  // alters the stream position to off
+  pos_type pt_1(off_type(-1));
+  pos_type pt_2(off_type(0));
+  off_type off_1 = 0;
+  off_type off_2 = 0;
+  strb_01.str(str_01); //in|out ("mykonos. . . or what?");
+  strb_02.str(str_02); //in ("paris, or sainte-maxime?");
+  strb_03.str(str_03); //out ("")
+  //IN|OUT
+  //beg
+  pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
+  off_1 = pt_1;
+  VERIFY( off_1 >= 0 );
+  c1 = strb_01.snextc(); //current in pointer +1
+  VERIFY( c1 == 'o' );
+  c2 = strb_01.sputc('x');  //test current out pointer
+  str_tmp = std::string("myxonos. . . or what?");
+  VERIFY( strb_01.str() == str_tmp );
+  //cur
+  pt_1 = strb_01.pubseekoff(2, std::ios_base::cur);
+  off_1 = pt_1;
+  VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams
+  pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
+  off_1 = pt_1;
+  pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in);
+  off_2 = pt_2;
+  VERIFY( off_2 == off_1 + 2 );
+  c1 = strb_01.snextc(); //current in pointer + 1
+  VERIFY( c1 == ' ' );
+  c2 = strb_01.sputc('x');  //test current out pointer
+  str_tmp = std::string("myxxnos. . . or what?");
+  VERIFY( strb_01.str() == str_tmp );
+  //end
+  pt_2 = strb_01.pubseekoff(2, std::ios_base::end);
+  off_1 = pt_2;
+  VERIFY( off_1 == -1 ); // not a valid position
+  VERIFY( strb_01.str() == str_tmp );
+  // end part two (from the filebuf tests)
+  strb_01.pubseekoff(0, std::ios_base::end);
+  strmsz_1 = strb_01.in_avail(); // 0 cuz at the end
+  c1 = strb_01.sgetc(); 
+  c2 = strb_01.sungetc();
+  strmsz_2 = strb_01.in_avail(); // 1
+  c3 = strb_01.sgetc();
+  VERIFY( c1 != c2 );
+  VERIFY( strmsz_2 != strmsz_1 );
+  VERIFY( strmsz_2 == 1 );
+  // end part three
+  strmsz_1 = strb_01.str().size();
+  strmsz_2 = strb_01.sputn(" ravi shankar meets carlos santana in LoHa", 90);
+  strb_01.pubseekoff(0, std::ios_base::end);
+  strb_01.sputc('<');
+  str_tmp = strb_01.str();
+  VERIFY( str_tmp.size() == strmsz_1 + strmsz_2 + 1 );
+  // IN
+  // OUT
+
+  // seekpos
+  // pubseekpos(pos_type sp, ios_base::openmode)
+  // alters the stream position to sp
+  strb_01.str(str_01); //in|out ("mykonos. . . or what?");
+  strb_02.str(str_02); //in ("paris, or sainte-maxime?");
+  strb_03.str(str_03); //out ("")
+  //IN|OUT
+  //beg
+  pt_1 = strb_01.pubseekoff(2, std::ios_base::beg);
+  off_1 = pt_1;
+  VERIFY( off_1 >= 0 );
+  pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out);
+  off_1 = pt_1;
+  c1 = strb_01.snextc(); //current in pointer +1
+  VERIFY( c1 == 'o' );
+  c2 = strb_01.sputc('x');  //test current out pointer
+  str_tmp = std::string("myxonos. . . or what?");
+  VERIFY( strb_01.str() == str_tmp );
+  strb_01.pubsync(); //resets pointers
+  pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out);
+  off_2 = pt_2;
+  VERIFY( off_1 == off_2 );
+  c3 = strb_01.snextc(); //current in pointer +1
+  VERIFY( c1 == c3 );
+  c2 = strb_01.sputc('x');  //test current out pointer
+  str_tmp = std::string("myxonos. . . or what?");
+  VERIFY( strb_01.str() == str_tmp );
+
+  // VIRTUALS (indirectly tested)
+  // underflow
+  // if read position avail, returns *gptr()
+
+  // pbackfail(int_type c)
+  // put c back into input sequence
+
+  // overflow
+  // appends c to output seq
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+
+  return test;
+}
+
+
+// libstdc++/3955 -- ios_base::app overwrites from the beginning
+bool test05()
+{
+  bool test = true;
+
+  std::ostringstream os ("foo");
+  os << "bar";
+
+  test = os.str() == "bar";
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+
+  return test;
+}
+
+bool test06()
+{
+  bool test = true;
+
+  std::ostringstream os ("foo", std::ios_base::app);
+  os << "bar";
+
+  test = os.str() == "foobar";
+
+#ifdef DEBUG_ASSERT
+  assert(test);
+#endif
+
+  return test;
+}
+
+int main()
+{
+  test01();
+  test02();
+  test03();
+  test04();
+  test05();
+  test06();
+
+  return 0;
+}
+
+
+
+// more candy!!!
index 45ca438a59031cbd3ac68372c7d0d2615fa694db..1a1b017807418e67330de5663ffa57a7e03b0b67 100644 (file)
@@ -1,7 +1,6 @@
-// 981015 bkoz
-// i,o,stringstream usage
+// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com>
 
-// Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
+// Copyright (C) 2002 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
 // invalidate any other reasons why the executable file might be covered by
 // the GNU General Public License.
 
-#include <vector>
-#include <string>
-#include <sstream>
-#include <testsuite_hooks.h>
-
-// 01: sanity checks for strings, stringbufs
-std::string 
-test01()
-{
-  bool test = false;
-
-  // Empty string sanity check.
-  std::string str01;
-  std::string::iterator __i_start = str01.begin();
-  std::string::iterator __i_end = str01.end();
-  std::string::size_type len = str01.size();
-  test = __i_start == __i_end;
-  VERIFY( len == 0 );
-
-  // Full string sanity check.
-  std::string str02("these golden days, i spend waiting for you:\n"
-                   "Betty Carter on Verve with I'm Yours and You're Mine.");
-  __i_start = str02.begin();
-  __i_end = str02.end();
-  len = str02.size();
-  VERIFY( __i_start != __i_end );
-  VERIFY( len != 0 );
-  // Test an empty ostring stream for sanity.
-  std::ostringstream ostrstream0;
-  std::string str03 = ostrstream0.str();
-  __i_start = str03.begin();
-  __i_end = str03.end();
-  len = str03.size();
-  VERIFY( __i_start == __i_end );
-  VERIFY( len == 0 );
-  VERIFY( str01 == str03 );
+// 27.7.4 - Template class basic_stringstream
+// NB: This file is for testing basic_stringstream with NO OTHER INCLUDES.
 
-  return str02;
-}
+#include <sstream>
 
+// { dg-do compile }
 
-int
-test02()
+// libstdc++/7216
+void test01()
 {
-  bool test = true;
-
-  //
-  // 1: Automatic formatting of a compound string
-  //
-  int i = 1024;
-  int *pi = &i;
-  double d = 3.14159;
-  double *pd = &d;
-  std::string blank;
-  std::ostringstream ostrst01; 
-  std::ostringstream ostrst02(blank); 
-  
-  // No buffer,so should be created.
-  ostrst01 << "i: " << i << " i's address:  " << pi << "\n"
-            << "d: " << d << " d's address: " << pd << std::endl;
-  // Buffer, so existing buffer should be overwritten.
-  ostrst02 << "i: " << i << " i's address:  " << pi << "\n"
-            << "d: " << d << " d's address: " << pd << std::endl;
-
-  std::string msg01 = ostrst01.str();
-  std::string msg02 = ostrst02.str();
-  VERIFY( msg01 == msg02 );
-  VERIFY( msg02 != blank );
-
-  //
-  // 2: istringstream
-  //
-  // extracts the stored ascii values, placing them in turn in the four vars
-#if 0
-  int i2 = 0;
-  int *pi2 = &i2;
-  double d2 = 0.0;
-  double *pd2 = &d2;
-  std::istringstream istrst01(ostrst02.str());
-
-  istrst01 >> i2 >> pi2 >> d2 >> pd2;
-  //istrst01 >> i2;
-  //istrst01 >> pi2;
-  VERIFY( i2 == i );
-  VERIFY( d2 == d );
-  VERIFY( pd2 == pd );
-  VERIFY( pi2 == pi );
-#endif
-
-  // stringstream
-  std::string str1("");
-  std::string str3("this is a somewhat  string");
-  std::stringstream ss1(str1, std::ios_base::in|std::ios_base::out);
-  std::stringstream ss2(str3, std::ios_base::in|std::ios_base::out);
-
-  return 0;
+  // Check for required typedefs
+  typedef std::stringstream test_type;
+  typedef test_type::char_type char_type;
+  typedef test_type::traits_type traits_type;
+  typedef test_type::int_type int_type;
+  typedef test_type::pos_type pos_type;
+  typedef test_type::off_type off_type;
 }
 
-// user-reported error
-class derived_oss: public std::ostringstream 
-{
-public:
-  derived_oss() : std::ostringstream() {}
-};
-
-int
-test03()
+namespace test 
 {
-  bool test = true;
-  derived_oss yy;
-  yy << "buena vista social club\n";
-  VERIFY( yy.str() == std::string("buena vista social club\n") );
-
-#ifdef DEBUG_ASSERT
-  assert(test);
-#endif
-
-  return 0;
-}
+  using namespace std;
+  typedef short type_t;
+  template class basic_stringstream<type_t, char_traits<type_t> >;
+} // test
 
-int 
-main() 
+int main() 
 {
   test01();
-  test02();
-  test03();
-  
   return 0;
 }
index 4de7b8c52411f101c138dfe26c654b191914ac8e..91ee79bcf40b6e06f18faf4ccd2971be907a05da 100644 (file)
@@ -1,6 +1,6 @@
 // 2001-05-24 Benjamin Kosnik  <bkoz@redhat.com>
 
-// Copyright (C) 2001 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002 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
@@ -120,12 +120,67 @@ void test02()
   // These semantics are a joke, a serious defect, and incredibly lame.
 }
 
+void
+test03()
+{
+  bool test = true;
+
+  //
+  // 1: Automatic formatting of a compound string
+  //
+  int i = 1024;
+  int *pi = &i;
+  double d = 3.14159;
+  double *pd = &d;
+  std::string blank;
+  std::ostringstream ostrst01; 
+  std::ostringstream ostrst02(blank); 
+  
+  // No buffer, so should be created.
+  ostrst01 << "i: " << i << " i's address:  " << pi << "\n"
+            << "d: " << d << " d's address: " << pd << std::endl;
+  // Buffer, so existing buffer should be overwritten.
+  ostrst02 << "i: " << i << " i's address:  " << pi << "\n"
+            << "d: " << d << " d's address: " << pd << std::endl;
+
+  std::string msg01 = ostrst01.str();
+  std::string msg02 = ostrst02.str();
+  VERIFY( msg01 == msg02 );
+  VERIFY( msg02 != blank );
+
+  //
+  // 2: istringstream
+  //
+  // extracts the stored ascii values, placing them in turn in the four vars
+#if 0
+  int i2 = 0;
+  //int* pi2 = &i2;
+  void* pi2 = &i2;
+  double d2 = 0.0;
+  //  double* pd2 = &d2;
+  void* pd2 = &d2;
+  std::istringstream istrst01(ostrst02.str());
+
+  istrst01 >> i2 >> pi2 >> d2 >> pd2;
+  //istrst01 >> i2;
+  //istrst01 >> pi2;
+  VERIFY( i2 == i );
+  VERIFY( d2 == d );
+  VERIFY( pd2 == pd );
+  VERIFY( pi2 == pi );
+#endif
+
+  // stringstream
+  std::string str1("");
+  std::string str3("this is a somewhat  string");
+  std::stringstream ss1(str1, std::ios_base::in|std::ios_base::out);
+  std::stringstream ss2(str3, std::ios_base::in|std::ios_base::out);
+}
+
 int main()
 {
   test01();
   test02();
+  test03();
   return 0;
 }
-
-
-