summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/27_io/basic_stringbuf
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2004-08-12 22:26:32 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2004-08-12 22:26:32 +0000
commit0a162bde464b45ccfdc3045d0c6e515981cc76d1 (patch)
tree3ffbfad7e0c608bace637fa9c73d9c009e271eb8 /libstdc++-v3/testsuite/27_io/basic_stringbuf
parentc5443745bd596fa6f7a9d5a6e6e90b03abb28463 (diff)
downloadgcc-0a162bde464b45ccfdc3045d0c6e515981cc76d1.tar.gz
re PR libstdc++/16956 ([3.4 only] std::stringbuf::seekoff return wrong position value)
2004-08-12 Paolo Carlini <pcarlini@suse.de> PR libstdc++/16956 * include/bits/sstream.tcc (basic_stringbuf<>::seekoff): Add __off to the returned value, reorganize a bit. * testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc: New. * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc: New. * testsuite/27_io/basic_stringbuf/seekoff/char/1.cc: Remove junk. * testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/seekpos/char/1.cc: Likewise. * testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc: Likewise. From-SVN: r85910
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_stringbuf')
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc16
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc14
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc61
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc14
-rw-r--r--libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc14
6 files changed, 131 insertions, 49 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
index 08e5afbce51..70d2fd6b3af 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc
@@ -1,6 +1,6 @@
// 981208 bkoz test functionality of basic_stringbuf for char_type == char
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -23,18 +23,13 @@
#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 overloaded virtual functions
void test04()
{
bool test __attribute__((unused)) = true;
std::string str_tmp;
- std::stringbuf strb_tmp;
std::streamsize strmsz_1, strmsz_2;
typedef std::stringbuf::int_type int_type;
typedef std::stringbuf::traits_type traits_type;
@@ -42,12 +37,8 @@ void test04()
typedef std::stringbuf::off_type off_type;
int_type c1 = strb_01.sbumpc();
- int_type c2 = strb_02.sbumpc();
- int_type c3 = strb_01.sbumpc();
+ int_type c2, c3;
- // PUT
- strb_03.str(str_01); //reset
-
// BUFFER MANAGEMENT & POSITIONING
// seekoff
@@ -58,8 +49,7 @@ void test04()
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);
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc
new file mode 100644
index 00000000000..8e85a03961f
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc
@@ -0,0 +1,61 @@
+// 2004-08-12 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 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.
+
+// 27.7.1.3 Overridden virtual functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/16956
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef stringbuf::int_type int_type;
+ typedef stringbuf::traits_type traits_type;
+ typedef stringbuf::pos_type pos_type;
+ typedef stringbuf::off_type off_type;
+
+ stringbuf strb_01("lara's place", ios_base::in);
+ pos_type pt_1 = strb_01.pubseekoff(5, ios_base::cur, ios_base::in);
+ int_type c1 = strb_01.sgetc();
+ VERIFY( c1 != traits_type::eof() );
+ pos_type pt_2 = strb_01.pubseekoff(2, ios_base::cur, ios_base::in);
+ pos_type pt_3 = strb_01.pubseekpos(pt_1, ios_base::in);
+ int_type c2 = strb_01.sbumpc();
+ VERIFY( off_type(pt_3) == off_type(pt_2) - 2 );
+ VERIFY( c2 == c1 );
+
+ stringbuf strb_02("-", ios_base::out);
+ pos_type pt_4 = strb_02.pubseekoff(0, ios_base::cur, ios_base::out);
+ strb_02.sputn("red", 3);
+ pos_type pt_5 = strb_02.pubseekoff(-3, ios_base::cur, ios_base::out);
+ strb_02.pubseekpos(pt_5, ios_base::out);
+ VERIFY( off_type(pt_5) == off_type(pt_4) );
+ strb_02.sputn("blu", 3);
+ VERIFY( strb_02.str() == "blu" );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
index c1a659e6be1..6177140c803 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc
@@ -23,18 +23,13 @@
#include <testsuite_hooks.h>
std::wstring str_01(L"mykonos. . . or what?");
-std::wstring str_02(L"paris, or sainte-maxime?");
-std::wstring str_03;
std::wstringbuf strb_01(str_01);
-std::wstringbuf strb_02(str_02, std::ios_base::in);
-std::wstringbuf strb_03(str_03, std::ios_base::out);
// test overloaded virtual functions
void test04()
{
bool test __attribute__((unused)) = true;
std::wstring str_tmp;
- std::wstringbuf strb_tmp;
std::streamsize strmsz_1, strmsz_2;
typedef std::wstringbuf::int_type int_type;
typedef std::wstringbuf::traits_type traits_type;
@@ -42,11 +37,7 @@ void test04()
typedef std::wstringbuf::off_type off_type;
int_type c1 = strb_01.sbumpc();
- int_type c2 = strb_02.sbumpc();
- int_type c3 = strb_01.sbumpc();
-
- // PUT
- strb_03.str(str_01); //reset
+ int_type c2, c3;
// BUFFER MANAGEMENT & POSITIONING
@@ -58,8 +49,7 @@ void test04()
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);
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc
new file mode 100644
index 00000000000..6b43b385cd1
--- /dev/null
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc
@@ -0,0 +1,61 @@
+// 2004-08-12 Paolo Carlini <pcarlini@suse.de>
+
+// Copyright (C) 2004 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.
+
+// 27.7.1.3 Overridden virtual functions
+
+#include <sstream>
+#include <testsuite_hooks.h>
+
+// libstdc++/16956
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+ using namespace std;
+
+ typedef wstringbuf::int_type int_type;
+ typedef wstringbuf::traits_type traits_type;
+ typedef wstringbuf::pos_type pos_type;
+ typedef wstringbuf::off_type off_type;
+
+ wstringbuf strb_01(L"lara's place", ios_base::in);
+ pos_type pt_1 = strb_01.pubseekoff(5, ios_base::cur, ios_base::in);
+ int_type c1 = strb_01.sgetc();
+ VERIFY( c1 != traits_type::eof() );
+ pos_type pt_2 = strb_01.pubseekoff(2, ios_base::cur, ios_base::in);
+ pos_type pt_3 = strb_01.pubseekpos(pt_1, ios_base::in);
+ int_type c2 = strb_01.sbumpc();
+ VERIFY( off_type(pt_3) == off_type(pt_2) - 2 );
+ VERIFY( c2 == c1 );
+
+ wstringbuf strb_02(L"-", ios_base::out);
+ pos_type pt_4 = strb_02.pubseekoff(0, ios_base::cur, ios_base::out);
+ strb_02.sputn(L"red", 3);
+ pos_type pt_5 = strb_02.pubseekoff(-3, ios_base::cur, ios_base::out);
+ strb_02.pubseekpos(pt_5, ios_base::out);
+ VERIFY( off_type(pt_5) == off_type(pt_4) );
+ strb_02.sputn(L"blu", 3);
+ VERIFY( strb_02.str() == L"blu" );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
index c84dbcd47a7..2420a80106b 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc
@@ -23,34 +23,25 @@
#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 overloaded virtual functions
void test04()
{
bool test __attribute__((unused)) = true;
std::string str_tmp;
- std::stringbuf strb_tmp;
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;
int_type c1 = strb_01.sbumpc();
- int_type c2 = strb_02.sbumpc();
+ int_type c2;
int_type c3 = strb_01.sbumpc();
pos_type pt_1(off_type(-1));
pos_type pt_2(off_type(0));
off_type off_1 = 0;
off_type off_2 = 0;
-
- // PUT
- strb_03.str(str_01); //reset
// BUFFER MANAGEMENT & POSITIONING
@@ -58,8 +49,7 @@ void test04()
// 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);
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
index bac614efa9f..41850d9ea86 100644
--- a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
+++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc
@@ -23,25 +23,19 @@
#include <testsuite_hooks.h>
std::wstring str_01(L"mykonos. . . or what?");
-std::wstring str_02(L"paris, or sainte-maxime?");
-std::wstring str_03;
std::wstringbuf strb_01(str_01);
-std::wstringbuf strb_02(str_02, std::ios_base::in);
-std::wstringbuf strb_03(str_03, std::ios_base::out);
// test overloaded virtual functions
void test04()
{
bool test __attribute__((unused)) = true;
std::wstring str_tmp;
- std::wstringbuf strb_tmp;
typedef std::wstringbuf::int_type int_type;
- typedef std::wstringbuf::traits_type traits_type;
typedef std::wstringbuf::pos_type pos_type;
typedef std::wstringbuf::off_type off_type;
int_type c1 = strb_01.sbumpc();
- int_type c2 = strb_02.sbumpc();
+ int_type c2;
int_type c3 = strb_01.sbumpc();
pos_type pt_1(off_type(-1));
@@ -49,17 +43,13 @@ void test04()
off_type off_1 = 0;
off_type off_2 = 0;
- // PUT
- strb_03.str(str_01); //reset
-
// BUFFER MANAGEMENT & POSITIONING
// 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);