diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-06-10 00:05:49 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-06-10 00:05:49 +0000 |
commit | 6b7deda823e34328ca62353264a3754a4f0ec5f0 (patch) | |
tree | 4796888c4873be33692877192639786c97003001 /libstdc++-v3/testsuite | |
parent | 052a89960ded15a1260b152fb3f9f107a73b48f4 (diff) | |
download | gcc-6b7deda823e34328ca62353264a3754a4f0ec5f0.tar.gz |
2003-06-09 Paolo Carlini <pcarlini@unitus.it>
* include/bits/fstream.tcc (_M_underflow): Do not special
case the unbuffered case, which really means simply a one char
get area.
(basic_filebuf): Initialize _M_buf_size.
(setbuf): Unbuffered means _M_buf_size == 1, since only
_M_buf_size - 1 == 0 chars are going to be used for the
put area and 1 for the get area.
* include/std/std_streambuf.h (_M_buf_size): Move to basic_filebuf.
(~basic_streambuf): Tweak.
(basic_streambuf): Do not initialize _M_buf_size.
* include/std/std_fstream.h (_M_buf_size): Add from basic_streambuf.
(~basic_filebuf): Tweak.
(_M_set_buffer): Tweak, considering that _M_buf_size == 1 is the
unbuffered situation (i.e., put area pointers NULL).
* include/bits/streambuf.tcc (sbumpc): Clean up.
* testsuite/27_io/basic_filebuf/sputbackc/char/1.cc: Split into...
* testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc: New.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc: New.
* testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc: New.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc: New.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc: New.
* testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67686 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
6 files changed, 522 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc new file mode 100644 index 00000000000..bd6e2055eff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003 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.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sputbackc('/'); + VERIFY( c1 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == ' ' ); + c1 = fb_01.sgetc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == 'a' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c1 == c3 ); + fb_01.pubseekoff(5, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == '0' ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '1' ); + c2 = fb_01.sputbackc('b'); + VERIFY( c2 == 'b' ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '1' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '7' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc new file mode 100644 index 00000000000..fd1708ef9f7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc @@ -0,0 +1,99 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003 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.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_1io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in | out + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + strmsz_1 = fb_01.sputn("racadabras", 10);//"abracadabras or what?" + strmsz_2 = fb_01.sputn(", i wanna reach out and", 10); + c1 = fb_01.sgetc(); // -1 + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( 1 == strmsz_2 ); + //test for _in_cur == _in_beg + // fb_01._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc + fb_01.pubseekoff(10, std::ios_base::beg, + std::ios_base::in | std::ios_base::out); + fb_01.sputc('m'); + strmsz_1 = fb_01.in_avail(); + c1 = fb_01.sgetc(); + fb_01.snextc(); + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == 'z' ); + // test for replacing char with identical one + fb_01.snextc(); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.sputc('a'); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sputbackc('a'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + VERIFY( fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc new file mode 100644 index 00000000000..78d3b790df6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003 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.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // out + { + constraint_filebuf fb_01; // out + fb_01.open(name_01, ios::out | ios::trunc); + VERIFY( fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c1 == c2 ); + VERIFY( fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc new file mode 100644 index 00000000000..5deafbc7da7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003 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.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "sgetc.txt"; // file with data in it + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sputbackc('/'); + VERIFY( c1 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == ' ' ); + c1 = fb_01.sgetc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == 'a' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == c2 ); + c3 = fb_01.sgetc(); + VERIFY( c1 == c3 ); + fb_01.pubseekoff(5, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == '0' ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '1' ); + c2 = fb_01.sputbackc('b'); + VERIFY( c2 == 'b' ); + fb_01.sbumpc(); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '1' ); + c3 = fb_01.sbumpc(); + VERIFY( c3 == '7' ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc new file mode 100644 index 00000000000..fba44813629 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc @@ -0,0 +1,98 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003 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.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_2io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_cxx_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // in | out + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.sputn("racadabras", 10);//"abracadabras or what?" + strmsz_2 = fb_01.sputn(", i wanna reach out and", 10); + c1 = fb_01.sgetc(); // -1 + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( 1 == strmsz_2 ); + //test for _in_cur == _in_beg + // fb_01._M_out_beg = "bd23456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZracada" etc + fb_01.pubseekoff(10, std::ios_base::beg, + std::ios_base::in | std::ios_base::out); + fb_01.sputc('m'); + strmsz_1 = fb_01.in_avail(); + c1 = fb_01.sgetc(); + fb_01.snextc(); + c2 = fb_01.sputbackc('z'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == 'z' ); + // test for replacing char with identical one + fb_01.snextc(); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.sputc('a'); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sputbackc('a'); + strmsz_2 = fb_01.in_avail(); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_01.unbuffered() ); + } +} + +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc new file mode 100644 index 00000000000..52f041d8af9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003 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.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sputbackc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_cxx_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test = true; + int_type c1, c2, c3; + + // int_type sputbackc(char_type c) + // if in_cur not avail || ! traits::eq(c, gptr() [-1]), return pbfail + // otherwise decrements in_cur and returns *gptr() + + // out + { + constraint_filebuf fb_01; // out + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::out | ios::trunc); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_01.sputbackc('a'); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sputbackc('a'); + VERIFY( c1 == c2 ); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + } +} + +main() +{ + test01(); + return 0; +} |