summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc62
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc72
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc57
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc58
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc62
5 files changed, 311 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc
new file mode 100644
index 000000000..cdf84ef91
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc
@@ -0,0 +1,62 @@
+// 2004-07-07 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.7.1.3 basic_stringbuf overridden virtual functions.
+
+#include <sstream>
+#include <cstdlib>
+#include <testsuite_hooks.h>
+
+using namespace std;
+
+string
+data(unsigned len)
+{
+ string ret;
+ for (unsigned i = 0; i < len; ++i)
+ ret.push_back('a' + rand() % 26);
+ return ret;
+}
+
+void
+test01(unsigned iter)
+{
+ bool test __attribute__((unused)) = true;
+
+ for (unsigned n = 1; n <= iter; n *= 10)
+ {
+ const string str = data(n);
+ stringbuf sstr;
+ for (unsigned i = 0; i < n; ++i)
+ sstr.sputc(str[i]);
+ VERIFY( str == sstr.str() );
+ }
+}
+
+// This can take long on simulators, timing out the test.
+// { dg-options "-DITERATIONS=10000" { target simulator } }
+#ifndef ITERATIONS
+#define ITERATIONS 10000000
+#endif
+
+int main()
+{
+ test01(ITERATIONS);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc
new file mode 100644
index 000000000..3328e5520
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc
@@ -0,0 +1,72 @@
+// 1999-10-11 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// 27.5.2 template class basic_streambuf
+
+#include <sstream>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+// 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_stringbuf<charT, traits>
+ {
+ protected:
+ typedef typename
+ std::basic_stringbuf<charT, traits>::int_type int_type;
+ virtual int_type
+ overflow(int_type c)
+ { return traits::not_eof(c); }
+ };
+
+typedef basic_nullbuf<char> nullbuf;
+
+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 __attribute__((unused)) = 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 );
+}
+
+int main()
+{
+ test03();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc
new file mode 100644
index 000000000..a16fabc8c
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc
@@ -0,0 +1,57 @@
+// Copyright (C) 2006, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+struct pubbuf
+: std::stringbuf
+{
+ using std::stringbuf::eback;
+ using std::stringbuf::egptr;
+ using std::stringbuf::pbase;
+ using std::stringbuf::pptr;
+ using std::stringbuf::epptr;
+ using std::stringbuf::overflow;
+};
+
+// libstdc++/26250
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ pubbuf buf;
+
+ VERIFY( buf.overflow('x') == 'x' );
+ VERIFY( buf.pptr() - buf.pbase() == 1 );
+
+ // not required but good for efficiency
+ // NB: we are implementing DR 169 and DR 432
+ const int write_positions = buf.epptr() - buf.pbase();
+ VERIFY( write_positions > 1 );
+
+ // 27.7.1.3, p8:
+ VERIFY( buf.egptr() - buf.eback() == 1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc
new file mode 100644
index 000000000..b9d86a6ec
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc
@@ -0,0 +1,58 @@
+// 1999-10-11 bkoz
+
+// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009
+// Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+#include <sstream>
+#include <ostream>
+#include <testsuite_hooks.h>
+
+// libstdc++/3599
+class testbuf : public std::stringbuf
+{
+public:
+ typedef std::stringbuf::traits_type traits_type;
+
+ testbuf() : std::stringbuf() { }
+
+protected:
+ int_type
+ overflow(int_type c __attribute__((unused)) = traits_type::eof())
+ { return traits_type::not_eof(0); }
+};
+
+void
+test07()
+{
+ bool test __attribute__((unused)) = true;
+ testbuf ob;
+ std::ostream out(&ob);
+
+ out << "gasp";
+ VERIFY(out.good());
+
+ out << std::endl;
+ VERIFY(out.good());
+}
+
+int main()
+{
+ test07();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc
new file mode 100644
index 000000000..cf1653073
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc
@@ -0,0 +1,62 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+class OverBuf : public std::stringbuf
+{
+public:
+ int_type pub_overflow(int_type c = traits_type::eof())
+ { return std::stringbuf::overflow(c); }
+};
+
+// libstdc++/9988
+// filebuf::overflow writes EOF to file
+void test15()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ OverBuf sb;
+
+ sb.sputc('a');
+ sb.pub_overflow('b');
+ sb.pub_overflow();
+ sb.sputc('c');
+
+ stringbuf sbin(sb.str(), ios_base::in);
+ stringbuf::int_type c;
+ c = sbin.sbumpc();
+ VERIFY( c == 'a' );
+ c = sbin.sbumpc();
+ VERIFY( c == 'b' );
+ c = sbin.sbumpc();
+ VERIFY( c == 'c' );
+ c = sbin.sbumpc();
+ VERIFY( c == stringbuf::traits_type::eof() );
+}
+
+int main()
+{
+ test15();
+ return 0;
+}