summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/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_filebuf/seekoff/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_filebuf/seekoff/char')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc124
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc124
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc124
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc153
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc71
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc80
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc81
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc80
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc81
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc125
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc123
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc123
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc90
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc63
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc66
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc63
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc93
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc79
18 files changed, 1743 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc
new file mode 100644
index 000000000..248874617
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-in.cc
@@ -0,0 +1,124 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff.txt";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in
+ {
+ constraint_filebuf fb;
+ fb.open(name_01, ios_base::in);
+ VERIFY( !fb.write_position() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 0 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( !fb.write_position() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc
new file mode 100644
index 000000000..4dc6d8648
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-io.cc
@@ -0,0 +1,124 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+// { dg-require-binary-io "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-1io.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in | out
+ {
+ constraint_filebuf fb;
+ fb.open(name_01, ios_base::out | ios_base::in);
+ VERIFY( !fb.write_position() );
+ VERIFY( !fb.read_position() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( !fb.write_position() );
+ VERIFY( fb.read_position() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc
new file mode 100644
index 000000000..8d7ab1dfc
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/1-out.cc
@@ -0,0 +1,124 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-1out.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // out
+ {
+ constraint_filebuf fb;
+ fb.open(name_01, ios_base::out);
+ VERIFY( !fb.write_position() );
+ VERIFY( !fb.read_position() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( !fb.write_position() );
+ VERIFY( !fb.read_position() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc
new file mode 100644
index 000000000..2f6cf2988
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/11543.cc
@@ -0,0 +1,153 @@
+// Copyright (C) 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
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+struct MyState
+{
+};
+
+struct MyCharTraits : std::char_traits<char>
+{
+ typedef std::fpos<MyState> pos_type;
+ typedef MyState state_type;
+};
+
+namespace std
+{
+ template <>
+ class codecvt<char, char, MyState> :
+ public locale::facet, public codecvt_base
+ {
+ public:
+ typedef char intern_type;
+ typedef char extern_type;
+ typedef MyState state_type;
+
+ explicit codecvt(size_t refs = 0)
+ : locale::facet(refs) { }
+
+ result out(state_type& state, const intern_type* from,
+ const intern_type* from_end, const intern_type*& from_next,
+ extern_type* to, extern_type* to_limit,
+ extern_type*& to_next) const
+ { return do_out(state, from, from_end, from_next,
+ to, to_limit, to_next); }
+
+ result unshift(state_type& state, extern_type* to, extern_type* to_limit,
+ extern_type*& to_next) const
+ { return do_unshift(state, to, to_limit, to_next); }
+
+ result in(state_type& state, const extern_type* from,
+ const extern_type* from_end, const extern_type*& from_next,
+ intern_type* to, intern_type* to_limit,
+ intern_type*& to_next) const
+ { return do_in(state, from, from_end, from_next,
+ to, to_limit, to_next); }
+
+ int encoding() const throw()
+ { return do_encoding(); }
+
+ bool always_noconv() const throw()
+ { return do_always_noconv(); }
+
+ int length(state_type& state, const extern_type* from,
+ const extern_type* end, size_t max) const
+ { return do_length(state, from, end, max); }
+
+ int max_length() const throw()
+ { return do_max_length(); }
+
+ static locale::id id;
+
+ protected:
+ virtual ~codecvt();
+
+ virtual result do_out(state_type&, const intern_type* from,
+ const intern_type*, const intern_type*& from_next,
+ extern_type* to, extern_type*,
+ extern_type*& to_next) const
+ {
+ from_next = from;
+ to_next = to;
+ return noconv;
+ }
+
+ virtual result do_in(state_type&, const extern_type* from,
+ const extern_type*, const extern_type*& from_next,
+ intern_type* to, intern_type*,
+ intern_type*& to_next) const
+ {
+ from_next = from;
+ to_next = to;
+ return noconv;
+ }
+
+ virtual result do_unshift(state_type&, extern_type*, extern_type*,
+ extern_type*&) const
+ { return noconv; }
+
+ virtual int do_encoding() const throw()
+ { return 1; }
+
+ virtual bool do_always_noconv() const throw()
+ { return true; }
+
+ virtual int do_length(state_type&, const extern_type* from,
+ const extern_type* end, size_t max) const
+ {
+ size_t len = end - from;
+ return std::min(max, len);
+ }
+
+ virtual int do_max_length() const throw()
+ { return 1; }
+ };
+
+ locale::id codecvt<char, char, MyState>::id;
+
+ codecvt<char, char, MyState>::~codecvt()
+ { }
+}
+
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::locale loc(std::locale::classic(),
+ new std::codecvt<char, char, MyState>);
+ std::basic_filebuf<char, MyCharTraits> fb;
+ fb.pubimbue(loc);
+ fb.open("tmp_11543", std::ios_base::out);
+ VERIFY( fb.is_open() );
+ MyCharTraits::pos_type pos = fb.pubseekoff(0, std::ios_base::beg);
+ VERIFY( pos != MyCharTraits::pos_type(MyCharTraits::off_type(-1)) );
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc
new file mode 100644
index 000000000..a60293274
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12232.cc
@@ -0,0 +1,71 @@
+// Copyright (C) 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 <fstream>
+#include <testsuite_hooks.h>
+
+const char name[] = "tmp_12232";
+
+// libstdc++/12232
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ filebuf fbout;
+ fbout.open(name, ios_base::out);
+ fbout.sputn("abc", 3);
+
+ streampos p1 = fbout.pubseekoff(0, ios_base::cur, ios_base::in);
+ VERIFY( p1 != streampos(-1) );
+ fbout.sputn("de", 2);
+
+ streampos p2 = fbout.pubseekpos(p1, ios_base::openmode());
+ VERIFY( p2 != streampos(-1) );
+ fbout.sputn("34", 2);
+
+ streampos p3 = fbout.pubseekoff(0, ios_base::beg, ios_base::ate);
+ VERIFY( p3 != streampos(-1) );
+ fbout.sputn("012", 3);
+
+ fbout.close();
+
+ filebuf fbin;
+ fbin.open(name, ios_base::in);
+
+ streampos p4 = fbin.pubseekoff(0, ios_base::beg, ios_base::ate);
+ VERIFY( p4 != streampos(-1) );
+ VERIFY( fbin.sgetc() == '0' );
+
+ streampos p5 = fbin.pubseekoff(-1, ios_base::end, ios_base::out);
+ VERIFY( p5 != streampos(-1) );
+ VERIFY( fbin.sbumpc() == '4' );
+
+ streampos p6 = fbin.pubseekpos(p4, ios_base::binary);
+ VERIFY( p6 != streampos(-1) );
+ VERIFY( fbin.sbumpc() == '0' );
+
+ fbin.close();
+}
+
+int main()
+{
+ void test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc
new file mode 100644
index 000000000..d2860cbf5
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-1.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 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
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc('a');
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc
new file mode 100644
index 000000000..f0f1b9938
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-2.cc
@@ -0,0 +1,81 @@
+// Copyright (C) 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
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc('a');
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc
new file mode 100644
index 000000000..026d75029
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-3.cc
@@ -0,0 +1,80 @@
+// Copyright (C) 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
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift(),
+// but only if writing
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( !cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc
new file mode 100644
index 000000000..60813c899
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/12790-4.cc
@@ -0,0 +1,81 @@
+// Copyright (C) 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
+
+// { dg-require-fileio "" }
+
+#include <locale>
+#include <fstream>
+#include <testsuite_hooks.h>
+
+class Cvt : public std::codecvt<char, char, std::mbstate_t>
+{
+public:
+ mutable bool unshift_called;
+
+ Cvt()
+ : unshift_called(false)
+ { }
+
+protected:
+ bool
+ do_always_noconv() const throw()
+ { return false; }
+
+ int
+ do_encoding() const throw()
+ { return -1; }
+
+ std::codecvt_base::result
+ do_unshift(std::mbstate_t&, char* to, char*, char*& to_next) const
+ {
+ unshift_called = true;
+ to_next = to;
+ return std::codecvt_base::ok;
+ }
+};
+
+// libstdc++/12790
+// basic_filebuf::seekoff() should call codecvt::unshift()
+void test01()
+{
+ using namespace std;
+
+ bool test __attribute__((unused)) = true;
+ const char* name = "tmp_seekoff_12790";
+
+ Cvt* cvt = new Cvt;
+ locale loc(locale::classic(), cvt);
+
+ filebuf fb;
+ fb.pubimbue(loc);
+
+ fb.open(name, ios_base::out);
+ fb.sputc('a');
+ fb.pubsync(); // Does not call unshift()
+
+ VERIFY( !cvt->unshift_called );
+ fb.pubseekoff(0, ios_base::cur);
+ VERIFY( cvt->unshift_called );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc
new file mode 100644
index 000000000..3a8809da2
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-in.cc
@@ -0,0 +1,125 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff.txt";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in
+ {
+ constraint_filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.open(name_01, ios_base::in);
+ VERIFY( fb.unbuffered() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ VERIFY( c2 == traits_type::eof() );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 0 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( fb.unbuffered() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc
new file mode 100644
index 000000000..89fab2aed
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-io.cc
@@ -0,0 +1,123 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+// { dg-require-binary-io "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-2io.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // in | out
+ {
+ constraint_filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.open(name_01, ios_base::out | ios_base::in);
+ VERIFY( fb.unbuffered() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '9' );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == '9' );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == '1' );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( fb.unbuffered() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc
new file mode 100644
index 000000000..b1ad66e89
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/2-out.cc
@@ -0,0 +1,123 @@
+// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
+
+// Copyright (C) 2001, 2002, 2003, 2009, 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+#include <testsuite_io.h>
+
+// @require@ %-*.tst %-*.txt
+// @diff@ %-*.tst %*.txt
+
+const char name_01[] = "seekoff-2out.tst";
+
+void test05()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ typedef filebuf::int_type int_type;
+ typedef filebuf::pos_type pos_type;
+ typedef filebuf::off_type off_type;
+ typedef filebuf::traits_type traits_type;
+
+ bool test __attribute__((unused)) = true;
+ streamsize strmsz_1;
+
+ int_type c1;
+ int_type c2;
+ int_type c3;
+
+ pos_type pt_1(off_type(-1));
+ pos_type pt_2(off_type(0));
+ off_type off_1 = 0;
+ off_type off_2 = 0;
+
+ // seekoff
+ // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which)
+ // alters the stream position to off
+
+ // out
+ {
+ constraint_filebuf fb;
+ fb.pubsetbuf(0, 0);
+ fb.open(name_01, ios_base::out);
+ VERIFY( fb.unbuffered() );
+
+ //beg
+ strmsz_1 = fb.in_avail();
+ pt_1 = fb.pubseekoff(2, ios_base::beg);
+ fb.in_avail();
+ off_1 = off_type(pt_1);
+ VERIFY( off_1 > 0 );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(3, ios_base::beg);
+ c2 = fb.sputc('\n'); //current in pointer +1
+ fb.pubseekoff(4, ios_base::beg);
+ c3 = fb.sgetc();
+ VERIFY( c2 != c3 );
+ VERIFY( c3 == traits_type::eof() );
+ fb.pubsync();
+ c1 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //cur
+ pt_2 = fb.pubseekoff(2, ios_base::cur);
+ off_2 = off_type(pt_2);
+ VERIFY( (off_2 == (off_1 + 2 + 1 + 1)) );
+ c1 = fb.snextc(); //current in pointer +1
+ VERIFY( c1 == traits_type::eof() );
+ fb.pubseekoff(0, ios_base::cur);
+ c2 = fb.sputc('x'); //test current out pointer
+ c3 = fb.sputc('\n');
+ fb.pubseekoff(0, ios_base::cur);
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+
+ //end
+ pt_2 = fb.pubseekoff(0, ios_base::end);
+ off_1 = off_type(pt_2);
+ VERIFY( off_1 > off_2 ); //weak, but don't know exactly where it ends
+ c3 = fb.sputc('\n');
+ strmsz_1 = fb.sputn("because because because. . .", 28);
+ VERIFY( strmsz_1 == 28 );
+ fb.pubseekoff(-1, ios_base::end);
+ fb.sgetc();
+ c1 = fb.sungetc();
+ // Defect? retval of sungetc is not necessarily the character ungotten.
+ // So re-get it.
+ c1 = fb.sgetc();
+ fb.pubsync();
+ c3 = fb.sgetc();
+ VERIFY( c1 == c3 );
+ VERIFY( fb.unbuffered() );
+ }
+}
+
+int main()
+{
+ test05();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc
new file mode 100644
index 000000000..d98234bab
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/26777.cc
@@ -0,0 +1,90 @@
+// { dg-require-fork "" }
+// { dg-require-mkfifo "" }
+
+// 2006-03-22 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// No asserts, avoid leaking the semaphores if a VERIFY fails.
+#undef _GLIBCXX_ASSERT
+
+#include <testsuite_hooks.h>
+#include <fstream>
+#include <sstream>
+#include <cstdlib>
+#include <unistd.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+// libstdc++/26777
+bool test01()
+{
+ using namespace std;
+ using namespace __gnu_test;
+
+ bool test __attribute__((unused)) = true;
+
+ const char* name = "tmp_fifo6";
+
+ signal(SIGPIPE, SIG_IGN);
+
+ unlink(name);
+ mkfifo(name, S_IRWXU);
+ semaphore s1, s2;
+
+ int child = fork();
+ VERIFY( child != -1 );
+
+ if (child == 0)
+ {
+ filebuf fbout;
+ fbout.open(name, ios_base::in | ios_base::out);
+ VERIFY( fbout.is_open() );
+ fbout.sputn("Whatever", 8);
+ fbout.pubsync();
+ s1.signal();
+ s2.wait();
+ fbout.close();
+ s1.signal();
+ exit(0);
+ }
+
+ filebuf fbin;
+ fbin.open(name, ios::in);
+ s1.wait();
+
+ fbin.sgetc();
+ fbin.pubseekoff(0, ios::cur, ios::in);
+ s2.signal();
+ s1.wait();
+
+ ostringstream oss;
+ oss << &fbin;
+ fbin.close();
+
+ VERIFY( oss.str() == "Whatever" );
+
+ return test;
+}
+
+int main()
+{
+ return !test01();
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc
new file mode 100644
index 000000000..a0c4d5a86
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-in.cc
@@ -0,0 +1,63 @@
+// 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.7.1.3 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test02(std::filebuf& in, bool pass)
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef streambuf::pos_type pos_type;
+ typedef streambuf::off_type off_type;
+ pos_type bad = pos_type(off_type(-1));
+ pos_type p = 0;
+
+ // seekoff
+ p = in.pubseekoff(0, ios_base::beg, ios_base::in);
+ VERIFY( pass == (p != bad) );
+
+ p = in.pubseekoff(0, ios_base::beg, ios_base::out);
+ VERIFY( pass == (p != bad) ); // See libstdc++/12232
+
+ p = in.pubseekoff(0, ios_base::beg);
+ VERIFY( pass == (p != bad) );
+}
+
+const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it
+const char name_03[] = "filebuf_members-1.tst"; // empty file
+
+int main()
+{
+ using namespace std;
+
+ filebuf in1;
+ in1.open(name_01, ios_base::in);
+ filebuf in2;
+ filebuf in3;
+ in3.open(name_03, ios_base::in);
+ test02(in1, true);
+ test02(in2, false);
+ test02(in3, true);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc
new file mode 100644
index 000000000..803a81f27
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-io.cc
@@ -0,0 +1,66 @@
+// 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.7.1.3 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test02(std::filebuf& in, bool pass)
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef streambuf::pos_type pos_type;
+ typedef streambuf::off_type off_type;
+ pos_type bad = pos_type(off_type(-1));
+ pos_type p = 0;
+
+ // seekoff
+ p = in.pubseekoff(0, ios_base::beg, ios_base::in);
+ if (pass)
+ VERIFY( p != bad );
+
+ p = in.pubseekoff(0, ios_base::beg, ios_base::out);
+ if (pass)
+ VERIFY( p != bad );
+
+ p = in.pubseekoff(0, ios_base::beg);
+ if (pass)
+ VERIFY( p != bad );
+}
+
+const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it
+const char name_03[] = "filebuf_members-1.tst"; // empty file
+
+int main()
+{
+ using namespace std;
+
+ filebuf in1;
+ in1.open(name_01, ios_base::in | ios_base::out);
+ filebuf in2;
+ filebuf in3;
+ in3.open(name_03, ios_base::in | ios_base::out);
+ test02(in1, true);
+ test02(in2, false);
+ test02(in3, true);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc
new file mode 100644
index 000000000..08eac2933
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/3-out.cc
@@ -0,0 +1,63 @@
+// 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.7.1.3 Overridden virtual functions
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+void test02(std::filebuf& in, bool pass)
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+ typedef streambuf::pos_type pos_type;
+ typedef streambuf::off_type off_type;
+ pos_type bad = pos_type(off_type(-1));
+ pos_type p = 0;
+
+ // seekoff
+ p = in.pubseekoff(0, ios_base::beg, ios_base::in);
+ VERIFY( pass == (p != bad) ); // See libstdc++/12232
+
+ p = in.pubseekoff(0, ios_base::beg, ios_base::out);
+ VERIFY( pass == (p != bad) );
+
+ p = in.pubseekoff(0, ios_base::beg);
+ VERIFY( pass == (p != bad) );
+}
+
+const char name_01[] = "filebuf_virtuals-1.tst"; // file with data in it
+const char name_03[] = "filebuf_members-1.tst"; // empty file
+
+int main()
+{
+ using namespace std;
+
+ filebuf out1;
+ out1.open(name_01, ios_base::out);
+ filebuf out2;
+ filebuf out3;
+ out3.open(name_03, ios_base::out);
+ test02(out1, true);
+ test02(out2, false);
+ test02(out3, true);
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc
new file mode 100644
index 000000000..fe21b3a88
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc
@@ -0,0 +1,93 @@
+// { dg-require-fileio "" }
+
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <cstring>
+#include <testsuite_hooks.h>
+
+void test01()
+{
+ using namespace std;
+ bool test __attribute__((unused)) = true;
+
+ typedef filebuf::pos_type pos_type;
+ const char name[] = "tmp_seekoff-4.tst";
+
+ const size_t size = 12;
+ char buf[size];
+ streamsize n;
+
+ filebuf fb;
+ fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
+
+ n = fb.sputn("abcd", 4);
+ VERIFY( n == 4 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 3);
+ VERIFY( n == 3 );
+ VERIFY( !memcmp(buf, "abc", 3) );
+
+ // Check read => write without pubseekoff(0, ios_base::cur)
+
+ n = fb.sputn("ef", 2);
+ VERIFY( n == 2 );
+
+ fb.pubseekoff(0, ios_base::beg);
+
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 5 );
+ VERIFY( !memcmp(buf, "abcef", 5) );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sputn("gh", 2);
+ VERIFY( n == 2 );
+
+ // Check write => read without pubseekoff(0, ios_base::cur)
+
+ n = fb.sgetn( buf, 3 );
+ VERIFY( !memcmp(buf, "cef", 3) );
+
+ n = fb.sputn("ijkl", 4);
+ VERIFY( n == 4 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, 2);
+ VERIFY( n == 2 );
+ VERIFY( !memcmp(buf, "gh", 2) );
+
+ fb.pubseekoff(0, ios_base::end);
+ n = fb.sputn("mno", 3);
+ VERIFY( n == 3 );
+
+ fb.pubseekoff(0, ios_base::beg);
+ n = fb.sgetn(buf, size);
+ VERIFY( n == 12 );
+ VERIFY( !memcmp(buf, "ghcefijklmno", 12) );
+
+ fb.close();
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc
new file mode 100644
index 000000000..a80a33876
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/45628-1.cc
@@ -0,0 +1,79 @@
+// Copyright (C) 2010 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-require-fileio "" }
+
+#include <fstream>
+#include <testsuite_hooks.h>
+
+const char name_01[] = "tmp_seekoff_45628.tst";
+
+unsigned underflows, overflows;
+
+class my_filebuf
+: public std::filebuf
+{
+ virtual int_type
+ underflow()
+ {
+ ++underflows;
+ return std::filebuf::underflow();
+ }
+ virtual int_type
+ overflow(int_type c)
+ {
+ ++overflows;
+ return std::filebuf::overflow(c);
+ }
+};
+
+// libstdc++/45628
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ my_filebuf q;
+ q.open(name_01, std::ios_base::in | std::ios_base::out
+ | std::ios_base::trunc);
+
+ q.sputc('a');
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sputc('b');
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sputc('c');
+ q.pubseekoff(0, std::ios_base::cur);
+
+ VERIFY( overflows <= 1 ); // only initial sputc allowed to overflow
+ q.pubseekoff(0, std::ios_base::beg);
+
+ q.sbumpc();
+ VERIFY( underflows == 1 );
+
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sbumpc();
+ q.pubseekoff(0, std::ios_base::cur);
+ q.sbumpc();
+ q.pubseekoff(0, std::ios_base::cur);
+
+ VERIFY( underflows == 1 );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}