From fbd5f73b3e4b1f00827aa3e87dbbd9af2c844a91 Mon Sep 17 00:00:00 2001 From: Benjamin Kosnik Date: Fri, 30 Jun 2000 02:47:19 +0000 Subject: [PATCH] ostream_manip.cc (test02): Add tests. 2000-06-29 Benjamin Kosnik * testsuite/27_io/ostream_manip.cc (test02): Add tests. * bits/ostream.tcc: Tweak. * bits/std_fstream.h (basic_filebuf::setbuf): Reset _M_buf_size_opt too. * bits/std_streambuf.h (basic_streambuf::~basic_streambuf): Zero out _M_buf_size_opt. * bits/std_sstream.h (basic_stringbuf::_M_init_stringbuf): Set _M_buf_size_opt out here. * bits/char_traits.h (char_traits::eos): Non standard member function, uglify to __eos. Return char_type(). * bits/std_ostream.h: Change. * testsuite/27_io/ostream_seeks.cc: New file. * testsuite/27_io/ostream_seeks-1.tst: New file. * testsuite/27_io/istream_unformatted.cc (main): Move test04 and test05 to... * testsuite/27_io/istream_seeks.cc: New file. From-SVN: r34801 --- libstdc++-v3/ChangeLog | 8 +- libstdc++-v3/testsuite/27_io/istream_seeks.cc | 299 ++++++++++++++++++++ .../testsuite/27_io/istream_unformatted.cc | 225 +-------------- libstdc++-v3/testsuite/27_io/ostream_seeks-1.tst | 0 libstdc++-v3/testsuite/27_io/ostream_seeks.cc | 304 +++++++++++++++++++++ 5 files changed, 613 insertions(+), 223 deletions(-) create mode 100644 libstdc++-v3/testsuite/27_io/istream_seeks.cc create mode 100644 libstdc++-v3/testsuite/27_io/ostream_seeks-1.tst create mode 100644 libstdc++-v3/testsuite/27_io/ostream_seeks.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c1680a6..e6025c7 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -17,7 +17,13 @@ * bits/char_traits.h (char_traits::eos): Non standard member function, uglify to __eos. Return char_type(). * bits/std_ostream.h: Change. - + + * testsuite/27_io/ostream_seeks.cc (test01): New file. + * testsuite/27_io/ostream_seeks-1.tst: New file. + * testsuite/27_io/istream_unformatted.cc (main): Move test04 and + test05 to... + * testsuite/27_io/istream_seeks.cc: New file. + 2000-06-29 Branko Cibej * bits/std_memory.h (auto_ptr_ref): Reworked and defined only if diff --git a/libstdc++-v3/testsuite/27_io/istream_seeks.cc b/libstdc++-v3/testsuite/27_io/istream_seeks.cc new file mode 100644 index 0000000..4a506f2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/istream_seeks.cc @@ -0,0 +1,299 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000 Free Software Foundation +// +// 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include +#include +#include +#ifdef DEBUG_ASSERT + #include +#endif + + +bool test01() +{ + using namespace std; + typedef ios::pos_type pos_type; + + bool test = true; + const char str_lit01[] = "testsuite/istream_unformatted-1.tst"; + + // in + // test default ctors leave things in the same positions... + istringstream ist1; + pos_type p3 = ist1.tellg(); + + ifstream ifs1; + pos_type p4 = ifs1.tellg(); + + test &= p3 == p4; + + // in + // test ctors leave things in the same positions... + istringstream ist2("bob_marley:kaya"); + p3 = ist2.tellg(); + + ifstream ifs2(str_lit01); + p4 = ifs2.tellg(); + + test &= p3 == p4; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +// fstreams +void test04(void) +{ + bool test = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "testsuite/istream_unformatted-1.txt"; + const char str_lit02[] = "testsuite/istream_unformatted-2.txt"; + std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); + std::ifstream if02(str_lit01, std::ios_base::in); + std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); + test &= if01.good(); + test &= if02.good(); + test &= if03.good(); + + std::istream is01(if01.rdbuf()); + std::istream is02(if02.rdbuf()); + std::istream is03(if03.rdbuf()); + + // pos_type tellg() + // in | out + pos01 = is01.tellg(); + pos02 = is01.tellg(); + test &= pos01 == pos02; + // test &= istream::pos_type(0) != pos01; //depricated + + // in + pos03 = is02.tellg(); + pos04 = is02.tellg(); + test &= pos03 == pos04; + // test &= istream::pos_type(0) != pos03; //depricated + + // out + pos05 = is03.tellg(); + pos06 = is03.tellg(); + test &= pos05 == pos06; + // test &= istream::pos_type(0) != pos01; //depricated + + // istream& seekg(pos_type) + // istream& seekg(off_type, ios_base::seekdir) + + // cur + // NB: see library issues list 136. It's the v-3 interp that seekg + // only sets the input buffer, or else istreams with buffers that + // have _M_mode == ios_base::out will fail to have consistency + // between seekg and tellg. + state01 = is01.rdstate(); + is01.seekg(10, std::ios_base::cur); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellg(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellg(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + test &= pos05 == pos06 + 10; + test &= state01 == state02; + pos06 = is03.tellg(); + test &= pos05 == pos06; + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellg(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellg(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + test &= pos05 == pos06 + 10; + test &= state01 == state02; + pos06 = is03.tellg(); + test &= pos05 == pos06; + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +// stringstreams +void test05(void) +{ + bool test = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "testsuite/istream_unformatted-1.tst"; + std::ifstream if01(str_lit01); + std::ifstream if02(str_lit01); + std::ifstream if03(str_lit01); + test &= if01.good(); + test &= if02.good(); + test &= if03.good(); + + std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out); + if01 >> &strbuf01; + // initialize stringbufs that are ios_base::out + std::stringbuf strbuf03(strbuf01.str(), std::ios_base::out); + // initialize stringbufs that are ios_base::in + std::stringbuf strbuf02(strbuf01.str(), std::ios_base::in); + + std::istream is01(&strbuf01); + std::istream is02(&strbuf02); + std::istream is03(&strbuf03); + + // pos_type tellg() + // in | out + pos01 = is01.tellg(); + pos02 = is01.tellg(); + test &= pos01 == pos02; + // test &= istream::pos_type(0) != pos01; // deprecated + + // in + pos03 = is02.tellg(); + pos04 = is02.tellg(); + test &= pos03 == pos04; + // test &= istream::pos_type(0) != pos03; // deprecated + + // out + pos05 = is03.tellg(); + pos06 = is03.tellg(); + test &= pos05 == pos06; + // test &= istream::pos_type(0) != pos01; //deprecated + + // istream& seekg(pos_type) + // istream& seekg(off_type, ios_base::seekdir) + + // cur + // NB: see library issues list 136. It's the v-3 interp that seekg + // only sets the input buffer, or else istreams with buffers that + // have _M_mode == ios_base::out will fail to have consistency + // between seekg and tellg. + state01 = is01.rdstate(); + is01.seekg(10, std::ios_base::cur); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellg(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellg(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + test &= pos05 == pos06; // as only out buffer + test &= state01 == state02; + pos06 = is03.tellg(); + test &= pos05 == pos06; + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellg(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellg(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + test &= pos05 == pos06; // as only out buffer + test &= state01 == state02; + pos06 = is03.tellg(); + test &= pos05 == pos06; + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +int main() +{ + test01(); + test04(); + test05(); + return 0; +} + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc index df22457..59f40eb 100644 --- a/libstdc++-v3/testsuite/27_io/istream_unformatted.cc +++ b/libstdc++-v3/testsuite/27_io/istream_unformatted.cc @@ -1,6 +1,6 @@ // 1999-08-11 bkoz -// Copyright (C) 1999 Free Software Foundation +// Copyright (C) 1999, 2000 Free Software Foundation // // 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 @@ -27,7 +27,6 @@ #include #endif - bool test01() { typedef std::ios::traits_type traits_type; @@ -317,224 +316,6 @@ bool test03(void) return test; } -// fstreams -void test04(void) -{ - bool test = true; - std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; - std::ios_base::iostate state01, state02; - const char str_lit01[] = "testsuite/istream_unformatted-1.txt"; - const char str_lit02[] = "testsuite/istream_unformatted-2.txt"; - std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); - std::ifstream if02(str_lit01, std::ios_base::in); - std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); - test &= if01.good(); - test &= if02.good(); - test &= if03.good(); - - std::istream is01(if01.rdbuf()); - std::istream is02(if02.rdbuf()); - std::istream is03(if03.rdbuf()); - - // pos_type tellg() - // in | out - pos01 = is01.tellg(); - pos02 = is01.tellg(); - test &= pos01 == pos02; - // test &= istream::pos_type(0) != pos01; //depricated - - // in - pos03 = is02.tellg(); - pos04 = is02.tellg(); - test &= pos03 == pos04; - // test &= istream::pos_type(0) != pos03; //depricated - - // out - pos05 = is03.tellg(); - pos06 = is03.tellg(); - test &= pos05 == pos06; - // test &= istream::pos_type(0) != pos01; //depricated - - // istream& seekg(pos_type) - // istream& seekg(off_type, ios_base::seekdir) - - // cur - // NB: see library issues list 136. It's the v-3 interp that seekg - // only sets the input buffer, or else istreams with buffers that - // have _M_mode == ios_base::out will fail to have consistency - // between seekg and tellg. - state01 = is01.rdstate(); - is01.seekg(10, std::ios_base::cur); - state02 = is01.rdstate(); - pos01 = is01.tellg(); - test &= pos01 == pos02 + 10; - test &= state01 == state02; - pos02 = is01.tellg(); - test &= pos02 == pos01; - - state01 = is02.rdstate(); - is02.seekg(10, std::ios_base::cur); - state02 = is02.rdstate(); - pos03 = is02.tellg(); - test &= pos03 == pos04 + 10; - test &= state01 == state02; - pos04 = is02.tellg(); - test &= pos03 == pos04; - - state01 = is03.rdstate(); - is03.seekg(10, std::ios_base::cur); - state02 = is03.rdstate(); - pos05 = is03.tellg(); - test &= pos05 == pos06 + 10; - test &= state01 == state02; - pos06 = is03.tellg(); - test &= pos05 == pos06; - - // beg - state01 = is01.rdstate(); - is01.seekg(20, std::ios_base::beg); - state02 = is01.rdstate(); - pos01 = is01.tellg(); - test &= pos01 == pos02 + 10; - test &= state01 == state02; - pos02 = is01.tellg(); - test &= pos02 == pos01; - - state01 = is02.rdstate(); - is02.seekg(20, std::ios_base::beg); - state02 = is02.rdstate(); - pos03 = is02.tellg(); - test &= pos03 == pos04 + 10; - test &= state01 == state02; - pos04 = is02.tellg(); - test &= pos03 == pos04; - - state01 = is03.rdstate(); - is03.seekg(20, std::ios_base::beg); - state02 = is03.rdstate(); - pos05 = is03.tellg(); - test &= pos05 == pos06 + 10; - test &= state01 == state02; - pos06 = is03.tellg(); - test &= pos05 == pos06; - -#ifdef DEBUG_ASSERT - assert(test); -#endif -} - -// stringstreams -void test05(void) -{ - bool test = true; - std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; - std::ios_base::iostate state01, state02; - const char str_lit01[] = "testsuite/istream_unformatted-1.tst"; - std::ifstream if01(str_lit01); - std::ifstream if02(str_lit01); - std::ifstream if03(str_lit01); - test &= if01.good(); - test &= if02.good(); - test &= if03.good(); - - std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out); - if01 >> &strbuf01; - // initialize stringbufs that are ios_base::out - std::stringbuf strbuf03(strbuf01.str(), std::ios_base::out); - // initialize stringbufs that are ios_base::in - std::stringbuf strbuf02(strbuf01.str(), std::ios_base::in); - - std::istream is01(&strbuf01); - std::istream is02(&strbuf02); - std::istream is03(&strbuf03); - - // pos_type tellg() - // in | out - pos01 = is01.tellg(); - pos02 = is01.tellg(); - test &= pos01 == pos02; - // test &= istream::pos_type(0) != pos01; // deprecated - - // in - pos03 = is02.tellg(); - pos04 = is02.tellg(); - test &= pos03 == pos04; - // test &= istream::pos_type(0) != pos03; // deprecated - - // out - pos05 = is03.tellg(); - pos06 = is03.tellg(); - test &= pos05 == pos06; - // test &= istream::pos_type(0) != pos01; //deprecated - - // istream& seekg(pos_type) - // istream& seekg(off_type, ios_base::seekdir) - - // cur - // NB: see library issues list 136. It's the v-3 interp that seekg - // only sets the input buffer, or else istreams with buffers that - // have _M_mode == ios_base::out will fail to have consistency - // between seekg and tellg. - state01 = is01.rdstate(); - is01.seekg(10, std::ios_base::cur); - state02 = is01.rdstate(); - pos01 = is01.tellg(); - test &= pos01 == pos02 + 10; - test &= state01 == state02; - pos02 = is01.tellg(); - test &= pos02 == pos01; - - state01 = is02.rdstate(); - is02.seekg(10, std::ios_base::cur); - state02 = is02.rdstate(); - pos03 = is02.tellg(); - test &= pos03 == pos04 + 10; - test &= state01 == state02; - pos04 = is02.tellg(); - test &= pos03 == pos04; - - state01 = is03.rdstate(); - is03.seekg(10, std::ios_base::cur); - state02 = is03.rdstate(); - pos05 = is03.tellg(); - test &= pos05 == pos06; // as only out buffer - test &= state01 == state02; - pos06 = is03.tellg(); - test &= pos05 == pos06; - - // beg - state01 = is01.rdstate(); - is01.seekg(20, std::ios_base::beg); - state02 = is01.rdstate(); - pos01 = is01.tellg(); - test &= pos01 == pos02 + 10; - test &= state01 == state02; - pos02 = is01.tellg(); - test &= pos02 == pos01; - - state01 = is02.rdstate(); - is02.seekg(20, std::ios_base::beg); - state02 = is02.rdstate(); - pos03 = is02.tellg(); - test &= pos03 == pos04 + 10; - test &= state01 == state02; - pos04 = is02.tellg(); - test &= pos03 == pos04; - - state01 = is03.rdstate(); - is03.seekg(20, std::ios_base::beg); - state02 = is03.rdstate(); - pos05 = is03.tellg(); - test &= pos05 == pos06; // as only out buffer - test &= state01 == state02; - pos06 = is03.tellg(); - test &= pos05 == pos06; - -#ifdef DEBUG_ASSERT - assert(test); -#endif -} - // http://sourceware.cygnus.com/ml/libstdc++/2000-q1/msg00177.html void test06() { @@ -569,8 +350,6 @@ int main() test01(); test02(); test03(); - test04(); - test05(); test06(); return 0; } @@ -580,3 +359,5 @@ int main() + + diff --git a/libstdc++-v3/testsuite/27_io/ostream_seeks-1.tst b/libstdc++-v3/testsuite/27_io/ostream_seeks-1.tst new file mode 100644 index 0000000..e69de29 diff --git a/libstdc++-v3/testsuite/27_io/ostream_seeks.cc b/libstdc++-v3/testsuite/27_io/ostream_seeks.cc new file mode 100644 index 0000000..4963d58 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ostream_seeks.cc @@ -0,0 +1,304 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000 Free Software Foundation +// +// 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.6.2.4 basic_ostream seek members + +#include +#include +#include +#ifdef DEBUG_ASSERT + #include +#endif + + +bool test01() +{ + using namespace std; + typedef ios::pos_type pos_type; + + bool test = true; + const char str_lit01[] = "testsuite/ostream_seeks-1.txt"; + + // out + // test default ctors leave things in the same positions... + ostringstream ost1; + pos_type p1 = ost1.tellp(); + + ofstream ofs1; + pos_type p2 = ofs1.tellp(); + + test &= p1 == p2; + + // out + // test ctors leave things in the same positions... + ostringstream ost2("bob_marley:kaya"); + p1 = ost2.tellp(); + + ofstream ofs2(str_lit01); + p2 = ofs2.tellp(); + + test &= p1 == p2; + +#ifdef DEBUG_ASSERT + assert(test); +#endif + + return test; +} + +#if 0 +// XXX FIX ME +// basically this is the istreams_seeks.cc code. We need to fix it up +// for ostreams...... + +// fstreams +void test04(void) +{ + bool test = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "testsuite/istream_unformatted-1.txt"; + const char str_lit02[] = "testsuite/istream_unformatted-2.txt"; + std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); + std::ifstream if02(str_lit01, std::ios_base::in); + std::ifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); + test &= if01.good(); + test &= if02.good(); + test &= if03.good(); + + std::istream is01(if01.rdbuf()); + std::istream is02(if02.rdbuf()); + std::istream is03(if03.rdbuf()); + + // pos_type tellp() + // in | out + pos01 = is01.tellp(); + pos02 = is01.tellp(); + test &= pos01 == pos02; + // test &= istream::pos_type(0) != pos01; //depricated + + // in + pos03 = is02.tellp(); + pos04 = is02.tellp(); + test &= pos03 == pos04; + // test &= istream::pos_type(0) != pos03; //depricated + + // out + pos05 = is03.tellp(); + pos06 = is03.tellp(); + test &= pos05 == pos06; + // test &= istream::pos_type(0) != pos01; //depricated + + // istream& seekg(pos_type) + // istream& seekg(off_type, ios_base::seekdir) + + // cur + // NB: see library issues list 136. It's the v-3 interp that seekg + // only sets the input buffer, or else istreams with buffers that + // have _M_mode == ios_base::out will fail to have consistency + // between seekg and tellp. + state01 = is01.rdstate(); + is01.seekg(10, std::ios_base::cur); + state02 = is01.rdstate(); + pos01 = is01.tellp(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellp(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellp(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellp(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellp(); + test &= pos05 == pos06 + 10; + test &= state01 == state02; + pos06 = is03.tellp(); + test &= pos05 == pos06; + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellp(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellp(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellp(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellp(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellp(); + test &= pos05 == pos06 + 10; + test &= state01 == state02; + pos06 = is03.tellp(); + test &= pos05 == pos06; + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} + +// stringstreams +void test05(void) +{ + bool test = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "testsuite/istream_unformatted-1.tst"; + std::ifstream if01(str_lit01); + std::ifstream if02(str_lit01); + std::ifstream if03(str_lit01); + test &= if01.good(); + test &= if02.good(); + test &= if03.good(); + + std::stringbuf strbuf01(std::ios_base::in | std::ios_base::out); + if01 >> &strbuf01; + // initialize stringbufs that are ios_base::out + std::stringbuf strbuf03(strbuf01.str(), std::ios_base::out); + // initialize stringbufs that are ios_base::in + std::stringbuf strbuf02(strbuf01.str(), std::ios_base::in); + + std::istream is01(&strbuf01); + std::istream is02(&strbuf02); + std::istream is03(&strbuf03); + + // pos_type tellp() + // in | out + pos01 = is01.tellp(); + pos02 = is01.tellp(); + test &= pos01 == pos02; + // test &= istream::pos_type(0) != pos01; // deprecated + + // in + pos03 = is02.tellp(); + pos04 = is02.tellp(); + test &= pos03 == pos04; + // test &= istream::pos_type(0) != pos03; // deprecated + + // out + pos05 = is03.tellp(); + pos06 = is03.tellp(); + test &= pos05 == pos06; + // test &= istream::pos_type(0) != pos01; //deprecated + + // istream& seekg(pos_type) + // istream& seekg(off_type, ios_base::seekdir) + + // cur + // NB: see library issues list 136. It's the v-3 interp that seekg + // only sets the input buffer, or else istreams with buffers that + // have _M_mode == ios_base::out will fail to have consistency + // between seekg and tellp. + state01 = is01.rdstate(); + is01.seekg(10, std::ios_base::cur); + state02 = is01.rdstate(); + pos01 = is01.tellp(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellp(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellp(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellp(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellp(); + test &= pos05 == pos06; // as only out buffer + test &= state01 == state02; + pos06 = is03.tellp(); + test &= pos05 == pos06; + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellp(); + test &= pos01 == pos02 + 10; + test &= state01 == state02; + pos02 = is01.tellp(); + test &= pos02 == pos01; + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellp(); + test &= pos03 == pos04 + 10; + test &= state01 == state02; + pos04 = is02.tellp(); + test &= pos03 == pos04; + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellp(); + test &= pos05 == pos06; // as only out buffer + test &= state01 == state02; + pos06 = is03.tellp(); + test &= pos05 == pos06; + +#ifdef DEBUG_ASSERT + assert(test); +#endif +} +#endif // XXX + +int main() +{ + test01(); + // test04(); + // test05(); + return 0; +} + + + + + + + + -- 2.7.4