diff options
Diffstat (limited to 'libstdc++-v3/testsuite/27_io')
870 files changed, 56728 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc new file mode 100644 index 000000000..99d5eda88 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/12790-1.cc @@ -0,0 +1,79 @@ +// 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.3 filebuf member functions + +// { dg-require-fileio "" } + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from<char>('b')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>(0)); + + // Check that close() writes unshift sequence + fb.close(); + + fb.open(name, ios_base::in | ios_base::out | ios_base::ate); + + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>(0)); + + fb.close(); + + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc new file mode 100644 index 000000000..0a12e7224 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/1.cc @@ -0,0 +1,87 @@ +// 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + VERIFY( fb_01.is_open() ); + + // Try to open two different files without closing the first: + // Should keep the old file attached, and disregard attempt to overthrow. + fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + VERIFY( fb_02.is_open() ); + + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_03.is_open() ); + + // filebuf_type* close() + std::filebuf* f; + f = fb_01.close(); + VERIFY( f ); + VERIFY( !fb_01.is_open() ); + + f = fb_02.close(); + VERIFY( f ); + VERIFY( !fb_02.is_open() ); + + f = fb_03.close(); + VERIFY( f ); + VERIFY( !fb_03.is_open() ); + + f = fb_03.close(); + VERIFY( !f ); + VERIFY( !fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-1.cc new file mode 100644 index 000000000..508261ba2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/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.3 filebuf member 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::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_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.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc new file mode 100644 index 000000000..0a4bdb3c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-2.cc @@ -0,0 +1,82 @@ +// 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/>. + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#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::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_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'); + fb.in_avail(); // showmanyc() should have no effect on close(). + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc new file mode 100644 index 000000000..fe0624d10 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-3.cc @@ -0,0 +1,81 @@ +// Copyright (C) 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/>. + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#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 codecvt_base::error; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should fail if codecvt::unshift() fails +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_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 ); + filebuf* ret = fb.close(); + VERIFY( cvt->unshift_called ); + VERIFY( !ret ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/12790-4.cc new file mode 100644 index 000000000..e54c61682 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/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/>. + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions + +#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::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_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.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc new file mode 100644 index 000000000..c1a0f79c8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/2.cc @@ -0,0 +1,80 @@ +// 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/>. + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include <fstream> +#include <ext/stdio_filebuf.h> +#include <testsuite_hooks.h> + +// Verify that std::filebuf doesn't close files that it didn't open +// when using the following std::filebuf ctor: +// +// std::filebuf(__c_file_type* __f, +// ios_base::openmode __mode, +// int_type __s); +// +// Thanks to "George T. Talbot" <george@moberg.com> for uncovering +// this bug/situation. + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +void test_02() +{ + bool test __attribute__((unused)) = true; + int close_num = 0; + + // read (ext) + FILE* f2 = fopen(name_01, "r"); + VERIFY( f2 ); + if (f2) + { + __gnu_cxx::stdio_filebuf<char> fb(f2, std::ios_base::in, 512); + close_num = fclose(f2); + } + VERIFY( close_num == 0 ); + + // read (standard) + FILE* f = fopen(name_01, "r"); + VERIFY( f ); + if (f) + { + std::ifstream ifstream1(name_01); + VERIFY( ifstream1.is_open() ); + std::ios_base::iostate st01 = ifstream1.rdstate(); + VERIFY( st01 == std::ios_base::goodbit ); + close_num = fclose(f); + } + VERIFY( close_num == 0 ); +} + +int +main() +{ + test_02(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc new file mode 100644 index 000000000..a5db2aed6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/3.cc @@ -0,0 +1,89 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +// NB: This test assumes that _M_buf_size == 40, and not the usual +// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be +// simulated a bit more readily. +// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. +const int buffer_size = 8192; +//const int buffer_size = 40; + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create +const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create + +class derived_filebuf: public std::filebuf +{ + public: + void + set_size(int_type __size) { _M_buf_size = __size; } +}; + +derived_filebuf fb_01; // in +derived_filebuf fb_02; // out +derived_filebuf fb_03; // in | out + +// Initialize filebufs to be the same size regardless of platform. +void test03() +{ + fb_01.set_size(buffer_size); + fb_02.set_size(buffer_size); + fb_03.set_size(buffer_size); +} + +// Test overloaded virtual functions. +void test05() +{ + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::filebuf f_tmp; + + fb_01.open(name_01, std::ios_base::in); + fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); + + // NB Have to close these suckers. . . + // filebuf_type* close() + fb_01.close(); + fb_02.close(); + fb_03.close(); + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); +} + +int main() +{ + test03(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc new file mode 100644 index 000000000..cd4f5e15b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4.cc @@ -0,0 +1,73 @@ +// 2003-05-19 Paolo Carlini <pcarlini@unitus.it> + +// 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/>. + +// { dg-require-fileio "" } + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// Test that upon filebuf::close() 27.8.1.1,3 is enforced. + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +void test_04() +{ + typedef std::filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + std::filebuf fb_01, fb_02; + char buffer[] = "xxxxxxxxxx"; + + // 'in' + fb_01.open(name_01, std::ios_base::in); + VERIFY( fb_01.sgetc() != traits_type::eof() ); + VERIFY( fb_01.sbumpc() != traits_type::eof() ); + VERIFY( fb_01.snextc() != traits_type::eof() ); + VERIFY( fb_01.sgetn(buffer, sizeof(buffer)) == sizeof(buffer) ); + + fb_01.close(); + + VERIFY( fb_01.sgetc() == traits_type::eof() ); + VERIFY( fb_01.sbumpc() == traits_type::eof() ); + VERIFY( fb_01.snextc() == traits_type::eof() ); + VERIFY( fb_01.sgetn(buffer, sizeof(buffer)) == 0 ); + + // 'out' + fb_02.open(name_02, std::ios_base::out); + VERIFY( fb_02.sputc('T') != traits_type::eof() ); + VERIFY( fb_02.sputn(buffer, sizeof(buffer)) == sizeof(buffer) ); + + fb_02.close(); + + VERIFY( fb_02.sputc('T') == traits_type::eof() ); + VERIFY( fb_02.sputn(buffer, sizeof(buffer)) == 0 ); +} + +int +main() +{ + test_04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc new file mode 100644 index 000000000..9d2c647ca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc @@ -0,0 +1,108 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include <fstream> +#include <iostream> +#include <cstdlib> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +// libstdc++/2913, libstdc++/4879 +// John Fardo <jfardo@laurelnetworks.com>, Brad Garcia <garsh@attbi.com> +bool +test_04() +{ + using namespace __gnu_test; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo1"; + semaphore s1, s2; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + if (0 != mkfifo(name, S_IRWXU)) + { + std::cerr << "failed to create fifo" << std::endl; + exit(-1); + } + + int fval = fork(); + if (fval == -1) + { + std::cerr << "failed to fork" << std::endl; + unlink(name); + return false; + } + else if (fval == 0) + { + std::ifstream ifs(name); + s1.wait(); + ifs.close(); + s2.signal(); + exit(0); + } + + std::ofstream ofs(name); + s1.signal(); + s2.wait(); + ofs.put('t'); + + /* + * ISO/IED 14882:1998(E) 27.8.1.10.4 + * + * void close(); + * + * Effects: Calls rdbuf()->close() and, if that function fails + * (returns a null pointer), calls setstate(failbit)... + */ + ofs.close(); + if (!(ofs.rdstate() & std::ios::failbit)) + { + test = false; + VERIFY( test ); + } + + unlink(name); + + return test; +} + +int +main() +{ + return !test_04(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc new file mode 100644 index 000000000..25ae66b41 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/5.cc @@ -0,0 +1,106 @@ +// 2003-05-20 Paolo Carlini <pcarlini@unitus.it> + +// 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// Test that upon filebuf::close() 27.8.1.1,3 is enforced. + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create + +bool overflow_called; +bool underflow_called; +bool uflow_called; + +class Close_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + overflow_called = true; + return std::filebuf::overflow(c); + } + + int_type underflow() + { + underflow_called = true; + return std::filebuf::underflow(); + } + + int_type uflow() + { + uflow_called = true; + return std::filebuf::uflow(); + } +}; + +void test_05() +{ + bool test __attribute__((unused)) = true; + + Close_filebuf fb_01, fb_02; + char buffer[] = "xxxxxxxxxx"; + + // 'in' + fb_01.open(name_01, std::ios_base::in); + fb_01.sgetc(); + + fb_01.close(); + + underflow_called = false; + fb_01.sgetc(); + VERIFY( underflow_called == true ); + + uflow_called = false; + fb_01.sbumpc(); + VERIFY( uflow_called == true ); + + uflow_called = false; + fb_01.snextc(); + VERIFY( uflow_called == true ); + + uflow_called = false; + fb_01.sgetn(buffer, sizeof(buffer)); + VERIFY( uflow_called == true ); + + // 'out' + fb_02.open(name_02, std::ios_base::out); + + fb_02.close(); + + overflow_called = false; + fb_02.sputc('T'); + VERIFY( overflow_called == true ); + + overflow_called = false; + fb_02.sputn(buffer, sizeof(buffer)); + VERIFY( overflow_called == true ); +} + +int +main() +{ + test_05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc new file mode 100644 index 000000000..f2c5abc3e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc @@ -0,0 +1,89 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include <fstream> +#include <cstdlib> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +// libstdc++/9964 +bool test_07() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + semaphore s1, s2; + + const char* name = "tmp_fifo3"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + filebuf fbin; + fbin.open(name, ios_base::in); + s1.wait(); + fbin.close(); + s2.signal(); + exit(0); + } + + filebuf fb; + filebuf* ret = fb.open(name, ios_base::in | ios_base::out); + VERIFY( ret != 0 ); + VERIFY( fb.is_open() ); + s1.signal(); + s2.wait(); + fb.sputc('a'); + + ret = fb.close(); + VERIFY( ret != 0 ); + VERIFY( !fb.is_open() ); + + return test; +} + +int +main() +{ + return !test_07(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc new file mode 100644 index 000000000..85222f596 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-1.cc @@ -0,0 +1,78 @@ +// 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.3 filebuf member functions + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.cc new file mode 100644 index 000000000..eeade5812 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-2.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.3 filebuf member functions + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.in_avail(); // showmanyc() should have no effect on close(). + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc new file mode 100644 index 000000000..417fbc2ce --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-3.cc @@ -0,0 +1,79 @@ +// Copyright (C) 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.3 filebuf member functions + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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 codecvt_base::error; + } +}; + +// libstdc++/12790 +// basic_filebuf::close() should fail if codecvt::unshift() fails +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + wfilebuf* ret = fb.close(); + VERIFY( cvt->unshift_called ); + VERIFY( !ret ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc new file mode 100644 index 000000000..240417a93 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/close/wchar_t/12790-4.cc @@ -0,0 +1,79 @@ +// 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.3 filebuf member functions + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::close() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_close_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.close(); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc new file mode 100644 index 000000000..377e519a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/2020.cc @@ -0,0 +1,52 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf; + + try + { gnu_filebuf obj; } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc new file mode 100644 index 000000000..ab2e2c70f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/char/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.2 basic_filebuf constructors [lib.filebuf.cons] + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_filebuf fbuf; + VERIFY( fbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc new file mode 100644 index 000000000..e2081de7c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.2 basic_filebuf constructors [lib.filebuf.cons] + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_wfilebuf fbuf; + VERIFY( fbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc new file mode 100644 index 000000000..69d2d4517 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/cons/wchar_t/10132-1.cc @@ -0,0 +1,52 @@ +// 2003-04-24 Pétur Runólfsson <peturr02@ru.is> +// 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/>. + +#include <fstream> +#include <locale> +#include <stdexcept> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t> +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t*, const wchar_t*, const wchar_t*&, + char*, char*, char*&) const + { throw std::runtime_error("codecvt failed"); } +}; + +int main() +{ + bool test __attribute__((unused)) = true; + + std::locale loc = std::locale(std::locale::classic(), new Cvt); + std::wfilebuf* fb = new std::wfilebuf; + fb->pubimbue(loc); + fb->open("tmp_10132", std::ios_base::out); + fb->sputc(L'a'); + + try + { + delete fb; + } + catch(std::exception& obj) + { + VERIFY( false ); + } + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc new file mode 100644 index 000000000..4c6bebf1f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/12206.cc @@ -0,0 +1,125 @@ +// 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> + +typedef unsigned char Char; + +namespace std +{ + template <> + class codecvt<Char, char, mbstate_t> : + public locale::facet, public codecvt_base + { + public: + typedef Char intern_type; + typedef char extern_type; + typedef mbstate_t state_type; + + explicit codecvt(size_t refs = 0) + : locale::facet(refs) { } + result out(mbstate_t& state, const Char* from, + const Char* from_end, const Char*& from_next, + char* to, char* to_limit, char*& to_next) const + { + return do_out(state, from, from_end, from_next, + to, to_limit, to_next); + } + result in(mbstate_t& state, const char* from, + const char* from_end, const char*& from_next, + Char* to, Char* to_limit, Char*& to_next) const + { + return do_in(state, from, from_end, from_next, + to, to_limit, to_next); + } + result unshift(mbstate_t& state, char* to, char* to_end, + char*& to_next) const + { return do_unshift(state, to, to_end, to_next); } + int length(mbstate_t& state, const char* from, + const char* from_end, size_t max) const + { return do_length(state, from, from_end, max); } + int encoding() const throw() + { return do_encoding(); } + bool always_noconv() const throw() + { return do_always_noconv(); } + int max_length() const throw() + { return do_max_length(); } + + static locale::id id; + + protected: + virtual result do_out(mbstate_t&, const Char*, + const Char*, + const Char*&, char*, + char*, char*&) const + { return ok; } + virtual result do_in(mbstate_t&, const char*, + const char*, + const char*&, Char*, + Char*, Char*&) const + { return ok; } + virtual result do_unshift(mbstate_t&, char*, char*, + char*&) const + { return noconv; } + virtual int do_length(mbstate_t&, const char*, + const char*, size_t) const + { return 1; } + virtual int do_encoding() const throw() + { return 1; } + virtual bool do_always_noconv() const throw() + { return false; } + virtual int do_max_length() const throw() + { return 1; } + }; + + locale::id codecvt<Char, char, mbstate_t>::id; +} + +// libstdc++/12206 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), + new codecvt<Char, char, std::mbstate_t>); + locale::global(loc); + + basic_filebuf<Char, char_traits<Char> > fb; + + loc = locale::classic(); + locale::global(loc); + fb.pubimbue(loc); + + fb.open("tmp_12206", ios_base::out); + try + { + fb.pubseekoff(0, ios_base::cur); + } + catch (std::exception&) + { + } + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc new file mode 100644 index 000000000..37bc1a555 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/1.cc @@ -0,0 +1,44 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <fstream> +#include <testsuite_hooks.h> + +std::filebuf fbuf; + +// test the filebuf locale settings +void test02() +{ + std::locale loc_c = std::locale::classic(); + loc_c = fbuf.getloc(); + fbuf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = fbuf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc new file mode 100644 index 000000000..326aa1fd8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13007.cc @@ -0,0 +1,62 @@ +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +class Buf : public std::filebuf +{ +public: + std::locale before; + std::locale after; + +protected: + void imbue(const std::locale& loc) + { + before = getloc(); + + std::filebuf::imbue(loc); + + after = getloc(); + } +}; + +// libstdc++/13007 +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::locale loc(std::locale("fr_FR")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); + VERIFY( buf.before == std::locale::classic() ); + VERIFY( buf.after == std::locale::classic() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc new file mode 100644 index 000000000..9fbf67aef --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-1.cc @@ -0,0 +1,46 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +// libstdc++/13171 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb; + + fb.pubimbue(locale("en_US")); + fb.pubimbue(locale("en_US")); + + fb.open("tmp_13171-1", ios_base::out); + fb.sputc('F'); + fb.pubsync(); + fb.close(); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc new file mode 100644 index 000000000..fa0bf15c0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc @@ -0,0 +1,83 @@ +// { dg-require-namedlocale "fr_FR" } +// { dg-require-namedlocale "en_US" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <locale> +#include <cstdlib> + +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +// libstdc++/13171 +bool test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace __gnu_test; + + locale loc_fr(locale("fr_FR")); + locale loc_en(locale("en_US")); + + const char* name = "tmp_fifo_13171-2"; + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1, s2; + + int child = fork(); + if (child == 0) + { + filebuf fb; + fb.open(name, ios_base::out); + fb.sputc('S'); + fb.pubsync(); + s1.signal(); + s2.wait(); + fb.close(); + exit(0); + } + + filebuf fb; + fb.pubimbue(loc_fr); + fb.open(name, ios_base::in); + s1.wait(); + VERIFY( fb.is_open() ); + fb.pubimbue(loc_en); + filebuf::int_type c = fb.sgetc(); + fb.close(); + VERIFY( c == 'S' ); + s2.signal(); + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc new file mode 100644 index 000000000..1ac9557ce --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-4.cc @@ -0,0 +1,56 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<char, char, std::mbstate_t> +{ +protected: + int do_encoding() const throw() + { return -1; } + + bool do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/13171 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb; + fb.pubimbue(locale(locale("en_US"), new Cvt)); + fb.open("tmp_13171-4", ios_base::out); + fb.pubimbue(locale("fr_FR")); + fb.sputc('N'); + fb.pubsync(); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc new file mode 100644 index 000000000..fdcc03022 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc @@ -0,0 +1,84 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2004-01-11 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <locale> +#include <cstdlib> + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <testsuite_hooks.h> + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace __gnu_test; + + locale loc_en(locale("en_US")); + locale loc_fr(locale("fr_FR")); + + const char* name = "tmp_fifo_13582-2"; + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + if (child == 0) + { + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("12345", 5); + fbout.pubsync(); + fbout.close(); + exit(0); + } + + filebuf fbin; + fbin.open(name, ios_base::in); + filebuf::int_type n = fbin.sbumpc(); + VERIFY( n == '1' ); + fbin.pubimbue(loc_en); + n = fbin.sbumpc(); + VERIFY( n == '2' ); + fbin.pubimbue(loc_fr); + n = fbin.sbumpc(); + VERIFY( n == '3' ); + n = fbin.sbumpc(); + VERIFY( n == '4' ); + n = fbin.sbumpc(); + VERIFY( n == '5' ); + n = fbin.sbumpc(); + VERIFY( n == filebuf::traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc new file mode 100644 index 000000000..5007b085e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/14975-1.cc @@ -0,0 +1,68 @@ +// { dg-require-namedlocale "en_US" } + +// 2004-04-16 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 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 <locale> +#include <testsuite_hooks.h> + +class Buf : public std::filebuf +{ +protected: + virtual int_type + overflow(int_type c = traits_type::eof()) + { + return traits_type::eq_int_type(c, traits_type::eof()) ? + traits_type::eof() : std::filebuf::overflow(c); + } +}; + +// libstdc++/14975 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + Buf fb; + locale loc_us = locale("en_US"); + fb.pubimbue(loc_us); + fb.open("tmp_14975-1", ios_base::out); + + try + { + fb.sputc('a'); + fb.sputc('b'); + fb.pubimbue(locale::classic()); + fb.sputc('c'); + fb.pubsync(); + fb.close(); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc new file mode 100644 index 000000000..f4d574c21 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/2.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "de_DE" } + +// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + + locale loc; + filebuf ob; + VERIFY( ob.getloc() == loc ); + ob.open(name_01, ios_base::in); + VERIFY( ob.is_open() ); + + typedef streambuf::pos_type pos_type; + pos_type bad = pos_type(streambuf::off_type(-1)); + pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in); + VERIFY( p != bad); + + // According to 27.5.2.2.1, loc == getloc() after pubimbue(loc). + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc new file mode 100644 index 000000000..055573b96 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/3.cc @@ -0,0 +1,55 @@ +// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com> + +// 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 <locale> +#include <testsuite_hooks.h> + +class state_codecvt : public std::codecvt<char, char, std::mbstate_t> +{ +protected: + int + do_encoding() const throw() + { return -1; } +}; + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc_s(locale::classic(), new state_codecvt); + filebuf ob; + ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); + + // 2 "if encoding of current locale is state dependent" and + // not at the beginning of the file fails... + locale loc_c = locale::classic(); + locale ret = ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc new file mode 100644 index 000000000..8a611e0dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/9322.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +// libstdc++/9322 +void test07() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + std::filebuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc new file mode 100644 index 000000000..f5c6daac3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/1.cc @@ -0,0 +1,44 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <fstream> +#include <testsuite_hooks.h> + +std::wfilebuf fbuf; + +// test the filebuf locale settings +void test02() +{ + std::locale loc_c = std::locale::classic(); + loc_c = fbuf.getloc(); + fbuf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = fbuf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc new file mode 100644 index 000000000..bc7c3c1bd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/12868.cc @@ -0,0 +1,61 @@ +// { dg-require-namedlocale "is_IS.UTF-8" } + +// Copyright (C) 2003, 2005, 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 <ostream> +#include <fstream> +#include <locale> +#include <string> +#include <testsuite_hooks.h> + +// libstdc++/12868 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc_is(locale("is_IS.UTF-8")); + + { + wofstream out("tmp_12868"); + out << L"<? xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"; + out.imbue(loc_is); + VERIFY( out.rdbuf()->getloc() == loc_is ); + out << L"<greeting>Hall\u00f3 heimur</greeting>\n"; + } + + { + wifstream in("tmp_12868"); + wstring str; + getline(in, str); + if (str.find(L"encoding=\"UTF-8\"") != wstring::npos) + { + in.imbue(loc_is); + VERIFY( in.rdbuf()->getloc() == loc_is ); + } + getline(in, str); + VERIFY( str == L"<greeting>Hall\u00f3 heimur</greeting>" ); + } +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc new file mode 100644 index 000000000..9bb1f4035 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc @@ -0,0 +1,62 @@ +// { dg-require-namedlocale "fr_FR" } + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +class Buf : public std::wfilebuf +{ +public: + std::locale before; + std::locale after; + +protected: + void imbue(const std::locale& loc) + { + before = getloc(); + + std::wfilebuf::imbue(loc); + + after = getloc(); + } +}; + +// libstdc++/13007 +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::locale loc(std::locale("fr_FR")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); + VERIFY( buf.before == std::locale::classic() ); + VERIFY( buf.after == std::locale::classic() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc new file mode 100644 index 000000000..ec11237d0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13171-3.cc @@ -0,0 +1,59 @@ +// { dg-require-namedlocale "fr_FR" } +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// Copyright (C) 2003, 2005, 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 <iostream> +#include <locale> +#include <testsuite_hooks.h> + +// libstdc++/13171 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale::global(locale("fr_FR")); + + ios_base::sync_with_stdio(false); + + locale::global(locale("en_US")); + cin.imbue(locale("en_US")); + cout.imbue(locale("en_US")); + cerr.imbue(locale("en_US")); + clog.imbue(locale("de_DE")); + wcin.imbue(locale("en_US")); + wcout.imbue(locale("en_US")); + wcerr.imbue(locale("en_US")); + wclog.imbue(locale("de_DE")); + + cout << 'f' << endl; + cerr << 'r' << endl; + clog << 'A' << endl; + wcout << L's' << endl; + wcerr << L'i' << endl; + wclog << L'L' << endl; +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc new file mode 100644 index 000000000..7a997739f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc @@ -0,0 +1,86 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2004-01-11 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <locale> +#include <cstdlib> + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> + +#include <testsuite_hooks.h> + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + using namespace __gnu_test; + + locale loc_en(locale("en_US")); + locale loc_fr(locale("fr_FR")); + + const char* name = "tmp_fifo_13582-2"; + unlink(name); + mkfifo(name, S_IRWXU); + + int child = fork(); + if (child == 0) + { + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("12345", 5); + fbout.pubsync(); + sleep(2); + fbout.close(); + exit(0); + } + + wfilebuf fbin; + fbin.open(name, ios_base::in); + sleep(1); + wfilebuf::int_type n = fbin.sbumpc(); + VERIFY( n == L'1' ); + fbin.pubimbue(loc_en); + n = fbin.sbumpc(); + VERIFY( n == L'2' ); + fbin.pubimbue(loc_fr); + n = fbin.sbumpc(); + VERIFY( n == L'3' ); + n = fbin.sbumpc(); + VERIFY( n == L'4' ); + n = fbin.sbumpc(); + VERIFY( n == L'5' ); + n = fbin.sbumpc(); + VERIFY( n == wfilebuf::traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc new file mode 100644 index 000000000..246ae8c6e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-3.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "fr_FR" } + +// 2004-01-11 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 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 <locale> +#include <testsuite_hooks.h> + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale loc_en(locale("en_US")); + locale loc_fr(locale("fr_FR")); + + const char* name = "tmp_13582-3.tst"; + + { + filebuf fbout; + fbout.open(name, ios_base::out); + fbout.sputn("AbCdE", 5); + fbout.close(); + } + + { + wfilebuf fbin; + fbin.open(name, ios_base::in); + wfilebuf::int_type n = fbin.sbumpc(); + VERIFY( n == L'A' ); + fbin.pubimbue(loc_en); + fbin.pubseekoff(0, ios_base::cur); + n = fbin.sbumpc(); + VERIFY( n == L'b' ); + fbin.pubimbue(loc_fr); + n = fbin.sbumpc(); + VERIFY( n == L'C' ); + n = fbin.sbumpc(); + VERIFY( n == L'd' ); + fbin.pubseekoff(0, ios_base::cur); + n = fbin.sbumpc(); + VERIFY( n == L'E' ); + n = fbin.sbumpc(); + VERIFY( n == wfilebuf::traits_type::eof() ); + fbin.close(); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc new file mode 100644 index 000000000..dc1314556 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc @@ -0,0 +1,95 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2004-04-16 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 2006, 2007, 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/>. + +#include <fstream> +#include <locale> +#include <cstdlib> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphore if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +// libstdc++/14975 +bool test01() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + locale loc_us = locale("en_US"); + + const char* name = "tmp_14975-2"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + { + filebuf fbin; + fbin.open(name, ios_base::in); + } + s1.signal(); + exit(0); + } + + wfilebuf fb; + fb.pubimbue(loc_us); + wfilebuf* ret = fb.open(name, ios_base::out); + VERIFY( ret != 0 ); + VERIFY( fb.is_open() ); + + s1.wait(); + + try + { + fb.sputc(L'a'); + fb.sputc(L'b'); + fb.pubimbue(locale::classic()); + fb.sputc(L'c'); + fb.close(); + } + catch (std::exception&) + { + } + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc new file mode 100644 index 000000000..52941a5fc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "de_DE" } + +// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + + locale loc; + wfilebuf ob; + VERIFY( ob.getloc() == loc ); + ob.open(name_01, ios_base::in); + VERIFY( ob.is_open() ); + + typedef streambuf::pos_type pos_type; + pos_type bad = pos_type(streambuf::off_type(-1)); + pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in); + VERIFY( p != bad); + + // According to 27.5.2.2.1, p1, loc == getloc() after pubimbue(loc). + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc new file mode 100644 index 000000000..01baec6b5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/3.cc @@ -0,0 +1,55 @@ +// 2003-05-13 Benjamin Kosnik <bkoz@redhat.com> + +// 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 <locale> +#include <testsuite_hooks.h> + +class state_codecvt : public std::codecvt<wchar_t, char, std::mbstate_t> +{ +protected: + int + do_encoding() const throw() + { return -1; } +}; + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc_s(locale::classic(), new state_codecvt); + wfilebuf ob; + ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); + + // 2 "if encoding of current locale is state dependent" and + // not at the beginning of the file fails... + locale loc_c = locale::classic(); + locale ret = ob.pubimbue(loc_s); + VERIFY( ob.getloc() == loc_s ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc new file mode 100644 index 000000000..f69d9f0d6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/9322.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +// libstdc++/9322 +void test07() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + std::wfilebuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc new file mode 100644 index 000000000..94b331867 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/1.cc @@ -0,0 +1,100 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +// NB: This test assumes that _M_buf_size == 40, and not the usual +// buffer_size length of BUFSIZ (8192), so that overflow/underflow can be +// simulated a bit more readily. +// NRB (Nota Really Bene): setting it to 40 breaks the test, as intended. +const int buffer_size = 8192; +//const int buffer_size = 40; + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_02[] = "filebuf_virtuals-2.txt"; // empty file, need to create +const char name_03[] = "filebuf_virtuals-3.txt"; // empty file, need to create + +class derived_filebuf: public std::filebuf +{ + public: + void + set_size(int_type __size) { _M_buf_size = __size; } +}; + +derived_filebuf fb_01; // in +derived_filebuf fb_02; // out +derived_filebuf fb_03; // in | out + +// Initialize filebufs to be the same size regardless of platform. +void test03() +{ + fb_01.set_size(buffer_size); + fb_02.set_size(buffer_size); + fb_03.set_size(buffer_size); +} + +// Test overloaded virtual functions. +void test05() +{ + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::filebuf f_tmp; + std::streamoff strmof_1, strmof_2; + + // GET + // int in_avail() + // if a read position is available, return _M_in_end - _M_in_cur. + // else return showmanyc. + strmof_1 = fb_01.in_avail(); + strmof_2 = fb_02.in_avail(); + VERIFY( strmof_1 == -1 ); + VERIFY( strmof_1 == strmof_2 ); //fail because not open + strmof_1 = fb_03.in_avail(); + VERIFY( strmof_1 == strmof_2 ); + fb_01.open(name_01, std::ios_base::in); + fb_02.open(name_02, std::ios_base::out | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::in | std::ios_base::trunc); + strmof_1 = fb_01.in_avail(); + strmof_2 = fb_02.in_avail(); + VERIFY( strmof_1 != strmof_2 ); + VERIFY( strmof_1 >= 0 ); + VERIFY( strmof_2 == -1 ); // empty file + strmof_1 = fb_03.in_avail(); + VERIFY( strmof_1 == 0 ); // empty file +} + +int main() +{ + test03(); + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc new file mode 100644 index 000000000..b68f65647 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/in_avail/char/9701-3.cc @@ -0,0 +1,60 @@ +// 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.5.2.2.3 Get area + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +class Derived_fbuf : public std::filebuf +{ +public: + const char_type* pub_egptr() const + { return egptr(); } + + const char_type* pub_gptr() const + { return gptr(); } +}; + +// libstdc++/9701 (in_avail) +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_file1"; + + Derived_fbuf df2; + df2.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + df2.sputn("Comomoc", 7); + + df2.pubseekoff(0, ios_base::beg); + df2.sbumpc(); + df2.sputbackc('t'); + + VERIFY( df2.pub_gptr() < df2.pub_egptr() ); + VERIFY( df2.in_avail() == df2.pub_egptr() - df2.pub_gptr() ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc new file mode 100644 index 000000000..1b5a66ea8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/is_open/char/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_01.is_open() ); + VERIFY( fb_02.is_open() ); + VERIFY( fb_03.is_open() ); + + // filebuf_type* close() + fb_01.close(); + fb_02.close(); + fb_03.close(); + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc new file mode 100644 index 000000000..fc69cd4eb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/12790-1.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2003, 2005, 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.3 filebuf member functions + +// { dg-require-fileio "" } + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_open_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(pod_uchar::from<char>('b')); + fb.close(); + + // Check that reopened basic_filebuf begins in the initial state. + fb.open(name, ios_base::in); + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('b')) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc new file mode 100644 index 000000000..1a40da155 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/1.cc @@ -0,0 +1,74 @@ +// 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_members-1.tst"; +const char name_02[] = "filebuf_members-1.txt"; + +// Test member functions. +void test_01() +{ + bool test __attribute__((unused)) = true; + const char* name_03 = "filebuf_members-3"; // empty file, need to create + + std::filebuf fb_01; // in + std::filebuf fb_02; // out + std::filebuf fb_03; // in | out + + // bool is_open() + VERIFY( !fb_01.is_open() ); + VERIFY( !fb_02.is_open() ); + VERIFY( !fb_03.is_open() ); + + // filebuf_type* open(const char* __s, ios_base::openmode __mode) + fb_01.open(name_01, std::ios_base::in | std::ios_base::ate); + VERIFY( fb_01.is_open() ); + + // Try to open two different files without closing the first: + // Should keep the old file attached, and disregard attempt to overthrow. + std::filebuf* f = fb_02.open(name_02, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + VERIFY( f ); + VERIFY( fb_02.is_open() ); + + f = fb_02.open(name_03, std::ios_base::in | std::ios_base::out); + VERIFY( !f ); + VERIFY( fb_02.is_open() ); + + fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc); + VERIFY( fb_03.is_open() ); +} + +int +main() +{ + test_01(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc new file mode 100644 index 000000000..755784fb9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/2.cc @@ -0,0 +1,59 @@ +// 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include <fstream> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <ext/stdio_filebuf.h> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test_03() +{ + bool test __attribute__((unused)) = true; + int first_fd = ::open(name_01, O_RDONLY); + VERIFY( first_fd != -1 ); + FILE* first_file = ::fdopen(first_fd, "r"); + VERIFY( first_file ); + __gnu_cxx::stdio_filebuf<char> fb(first_file, std::ios_base::in); + + int second_fd = fb.fd(); + + VERIFY( first_fd == second_fd ); +} + +int +main() +{ + test_03(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc new file mode 100644 index 000000000..6b076a699 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/3.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +// Charles Leggett <CGLeggett@lbl.gov> +void test_05() +{ + bool test __attribute__((unused)) = true; + const char* name = "tmp_file5"; + + std::fstream scratch_file; + + scratch_file.open(name, std::ios::out); + scratch_file.close(); + + scratch_file.open(name, std::ios::in); + if (!scratch_file) + VERIFY( false ); + scratch_file.close(); +} + +int +main() +{ + test_05(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc new file mode 100644 index 000000000..31d25422b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/4.cc @@ -0,0 +1,72 @@ +// 2006-10-01 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/>. + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +// DR 596. +void test01() +{ + bool test __attribute__((unused)) = true; + const char* name = "tmp_file4"; + + std::fstream scratch_file; + + scratch_file.open(name, std::ios_base::app); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::out + | std::ios_base::app); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::app); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::app | std::ios_base::binary); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::out + | std::ios_base::app | std::ios_base::binary); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); + + scratch_file.open(name, std::ios_base::in | std::ios_base::app + | std::ios_base::binary); + VERIFY( scratch_file ); + VERIFY( scratch_file.is_open() ); + scratch_file.close(); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc new file mode 100644 index 000000000..47721e6ad --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/5.cc @@ -0,0 +1,30 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +// Test member functions. +void test01() +{ + std::filebuf fb; + + const std::string name = "filebuf_name.txt"; + fb.open(name, std::ios_base::in | std::ios_base::ate); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc new file mode 100644 index 000000000..5b404375e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc @@ -0,0 +1,72 @@ +// { dg-require-mkfifo "" } + +// Copyright (C) 2001, 2002, 2003, 2005, 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.3 filebuf member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// various tests for filebuf::open() and filebuf::close() including +// the non-portable functionality in the libstdc++-v3 IO library + +#include <fstream> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <testsuite_hooks.h> + +// libstdc++/9507 +void test_06() +{ + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo2"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + + std::filebuf fbuf; + // The use of ios_base::ate implies an attempt to seek on the file + // descriptor. The seek will fail. Thus, at the OS level, this + // call to "fbuf.open" will result in a call to "open" (which will + // succeed), a call to "lseek" (which will fail), and, finally, a + // call to "close" (which will succeed). Thus, after this call, the + // file should be closed. + std::filebuf* r = fbuf.open(name, + std::ios_base::in + | std::ios_base::out + | std::ios_base::ate); + if (!r) + VERIFY( !fbuf.is_open() ); + else + VERIFY( fbuf.is_open() ); +} + +int +main() +{ + test_06(); + return 0; +} + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc new file mode 100644 index 000000000..7c6874313 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/1.cc @@ -0,0 +1,70 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <fstream> +#include <ostream> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_filebuf<charT, traits> + { + protected: + typedef typename + std::basic_filebuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<char> nullbuf; + +template<typename T> + char + print(const T& x) + { + nullbuf ob; + std::ostream out(&ob); + out << x << std::endl; + return (!out ? '0' : '1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::string control01("11111"); + std::string test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print('x'); + test01 += print("pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc new file mode 100644 index 000000000..27f7b3664 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/13858.cc @@ -0,0 +1,69 @@ +// 2004-02-14 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <locale> + +class Cvt : public std::codecvt<char, char, std::mbstate_t> +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const char* from, const char*, + const char*& from_next, char* to, char*, char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt_base::error; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/13858 +void test01() +{ + using namespace std; + + filebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_13858_char", ios_base::out); + + try + { + fb.sputc('a'); + fb.sputc('b'); + fb.pubimbue(locale::classic()); + fb.sputc('c'); + fb.pubsync(); + fb.close(); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc new file mode 100644 index 000000000..792b7970a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2-unbuf.cc @@ -0,0 +1,55 @@ +// 2003-06-10 Paolo Carlini <pcarlini@unitus.it> + +// 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 <testsuite_hooks.h> + +const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create + +class OverBuf : public std::filebuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::filebuf::overflow(c); } +}; + +// According to 27.5.2.4.5 filebuf::overflow() returns not_eof(eof()). +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef OverBuf::traits_type traits_type; + + OverBuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_08, ios_base::out | ios_base::trunc); + + VERIFY( fb.pub_overflow() == traits_type::not_eof(traits_type::eof()) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc new file mode 100644 index 000000000..1cb8e503d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/2.cc @@ -0,0 +1,54 @@ +// 2003-06-10 Paolo Carlini <pcarlini@unitus.it> + +// 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 <testsuite_hooks.h> + +const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create + +class OverBuf : public std::filebuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::filebuf::overflow(c); } +}; + +// According to 27.5.2.4.5 filebuf::overflow() returns not_eof(eof()). +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef OverBuf::traits_type traits_type; + + OverBuf fb; + fb.open(name_08, ios_base::out | ios_base::trunc); + + VERIFY( fb.pub_overflow() == traits_type::not_eof(traits_type::eof()) ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc new file mode 100644 index 000000000..d02872cc0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/3599.cc @@ -0,0 +1,58 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <fstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/3599 +class testbuf : public std::filebuf +{ +public: + typedef std::filebuf::traits_type traits_type; + + testbuf() : std::filebuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::ostream out(&ob); + + out << "gasp"; + VERIFY(out.good()); + + out << std::endl; + VERIFY(out.good()); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc new file mode 100644 index 000000000..239c79a65 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9169.cc @@ -0,0 +1,73 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +const char name_04[] = "filebuf_virtuals-4.txt"; // empty file, need to create + +class Cvt_to_upper : public std::codecvt<char, char, mbstate_t> +{ + bool do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9169 +// filebuf output fails if codecvt<>::out returns noconv +void test10() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale c_loc = locale::classic(); + locale loc(c_loc, new Cvt_to_upper); + + string str("abcdefghijklmnopqrstuvwxyz"); + string tmp; + + { + ofstream out; + out.imbue(loc); + out.open(name_04); + copy(str.begin(), str.end(), ostreambuf_iterator<char>(out)); + } + + { + ifstream in; + in.open(name_04); + copy(istreambuf_iterator<char>(in), istreambuf_iterator<char>(), + back_inserter(tmp)); + } + + VERIFY( tmp.size() == str.size() ); + VERIFY( tmp == str ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc new file mode 100644 index 000000000..80d001199 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9182-2.cc @@ -0,0 +1,80 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +const char name_07[] = "filebuf_virtuals-7.txt"; // empty file, need to create + +class errorcvt : public std::codecvt<char, char, mbstate_t> +{ +protected: + std::codecvt_base::result + do_out(mbstate_t&, const char* from, const char*, + const char*& from_next, char* to, char*, + char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt<char, char, mbstate_t>::error; + } + + virtual bool do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9182 +// basic_filebuf<>::sync and overflow do not write out any characters +// if codecvt<>::out returns error +void test14() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc = locale::classic(); + loc = locale(loc, new errorcvt); + + filebuf fbuf1; + fbuf1.pubimbue(loc); + fbuf1.pubsetbuf(0, 0); + fbuf1.open(name_07, ios_base::out | ios_base::trunc); + + try + { + fbuf1.sputn("onne", 4); + fbuf1.close(); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test14(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc new file mode 100644 index 000000000..74dd04bb8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/char/9988.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_08[] = "filebuf_virtuals-8.txt"; // empty file, need to create + +class OverBuf : public std::filebuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::filebuf::overflow(c); } +}; + +// libstdc++/9988 +// filebuf::overflow writes EOF to file +void test15() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + OverBuf fb; + fb.open(name_08, ios_base::out | ios_base::trunc); + + fb.sputc('a'); + fb.pub_overflow('b'); + fb.pub_overflow(); + fb.sputc('c'); + fb.close(); + + filebuf fbin; + fbin.open(name_08, ios_base::in); + filebuf::int_type c; + c = fbin.sbumpc(); + VERIFY( c == 'a' ); + c = fbin.sbumpc(); + VERIFY( c == 'b' ); + c = fbin.sbumpc(); + VERIFY( c == 'c' ); + c = fbin.sbumpc(); + VERIFY( c == filebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc new file mode 100644 index 000000000..7faa0501a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-1.cc @@ -0,0 +1,47 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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 + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.pubsetbuf(0, 0); + fb.open("tmp_11305-1", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc new file mode 100644 index 000000000..e4a726a0d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-2.cc @@ -0,0 +1,49 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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 + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.pubsetbuf(0, 0); + fb.open("tmp_11305-2", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf::int_type n2 = fb.sputc(0x40000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( n2 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc new file mode 100644 index 000000000..5d49ed0df --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-3.cc @@ -0,0 +1,46 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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 + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.open("tmp_11305-3", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc new file mode 100644 index 000000000..3076a1777 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/11305-4.cc @@ -0,0 +1,48 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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 + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wfilebuf fb; + locale loc(locale("en_US.UTF-8")); + fb.pubimbue(loc); + fb.open("tmp_11405-4", ios_base::out); + wfilebuf::int_type n1 = fb.sputc(0x20000000); + wfilebuf::int_type n2 = fb.sputc(0x40000000); + wfilebuf* f = fb.close(); + + VERIFY( n1 != wfilebuf::traits_type::eof() ); + VERIFY( n2 != wfilebuf::traits_type::eof() ); + VERIFY( f ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc new file mode 100644 index 000000000..dd745267a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/overflow/wchar_t/13858.cc @@ -0,0 +1,70 @@ +// 2004-02-14 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <locale> + +class Cvt : public std::codecvt<wchar_t, char, std::mbstate_t> +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t* from, const wchar_t*, + const wchar_t*& from_next, char* to, char*, + char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt_base::error; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/13858 +void test01() +{ + using namespace std; + + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_13858_wchar_t", ios_base::out); + + try + { + fb.sputc(L'a'); + fb.sputc(L'b'); + fb.pubimbue(locale::classic()); + fb.sputc(L'c'); + fb.pubsync(); + fb.close(); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc new file mode 100644 index 000000000..539460a52 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/pbackfail/char/9761.cc @@ -0,0 +1,56 @@ +// 2003-06-02 Paolo Carlini <pcarlini@unitus.it> + +// 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 <testsuite_hooks.h> + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// libstdc++/9761 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf; + filebuf::int_type r1, r2; + + fbuf.open(name_01, ios_base::in); + + fbuf.sbumpc(); + fbuf.sbumpc(); + + r1 = fbuf.sputbackc('a'); + r2 = fbuf.sputbackc('b'); + + fbuf.close(); + + VERIFY( r1 != filebuf::traits_type::eof() ); + VERIFY( r2 == filebuf::traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc new file mode 100644 index 000000000..b02fa5be3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/base_classes.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <fstream> + +void test01() +{ + // Check for required base class. + typedef std::filebuf test_type; + typedef std::streambuf base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..dee3b3b35 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/explicit_instantiation.cc @@ -0,0 +1,49 @@ +// { dg-do compile } +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// test05 +// libstdc++/1886 +// should be able to instantiate basic_filebuf for non-standard types. +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_filebuf<type_t, char_traits<type_t> >; + template class basic_filebuf<pod_char, char_traits<pod_char> >; +} // test + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc new file mode 100644 index 000000000..e3539806f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/requirements/typedefs.cc @@ -0,0 +1,48 @@ +// { dg-do compile } +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::filebuf test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc new file mode 100644 index 000000000..9e0814ff3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-in.cc @@ -0,0 +1,80 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc new file mode 100644 index 000000000..791a6dddb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-io.cc @@ -0,0 +1,93 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_03[] = "tmp_sbumpc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + int_type c5 = fb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( !fb_01.write_position() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc new file mode 100644 index 000000000..14235217b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/1-out.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sbumpc_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + int_type c2 = fb_02.sbumpc(); + VERIFY( c2 == traits_type::eof() ); + int_type c4 = fb_02.sbumpc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc new file mode 100644 index 000000000..acb517ebf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-in.cc @@ -0,0 +1,80 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc new file mode 100644 index 000000000..576dee3ed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-io.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_03[] = "tmp_sbumpc_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + int_type c5 = fb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + + int_type c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + int_type c3 = fb_01.sbumpc(); + VERIFY( c3 == '/' ); + + c1 = fb_01.sgetc(); + int_type c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + VERIFY( c3 == '9' ); + VERIFY( c1 == c2 ); + VERIFY( c2 != c3 ); + + c1 = fb_01.sbumpc(); + c2 = fb_01.sbumpc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '9' ); + VERIFY( c2 == '9' ); + VERIFY( c3 == '0' ); + + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-out.cc new file mode 100644 index 000000000..ccc650e02 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/2-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.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_02[] = "tmp_sbumpc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + // int_type sbumpc() + // if read_cur not avail returns uflow(), else return *read_cur & increment + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + int_type c2 = fb_02.sbumpc(); + VERIFY( c2 == traits_type::eof() ); + int_type c4 = fb_02.sbumpc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc new file mode 100644 index 000000000..50ff2e662 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sbumpc/char/9825.cc @@ -0,0 +1,56 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_06[] = "filebuf_virtuals-6.txt"; // empty file, need to create + +// libstdc++/9825 +// filebuf::sputbackc breaks sbumpc +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf; + + fbuf.open(name_06, ios_base::in|ios_base::out|ios_base::trunc); + fbuf.sputn("crazy bees!", 11); + fbuf.pubseekoff(0, ios_base::beg); + fbuf.sbumpc(); + fbuf.sputbackc('x'); + filebuf::int_type c = fbuf.sbumpc(); + VERIFY( c == 'x' ); + c = fbuf.sbumpc(); + VERIFY( c == 'r' ); + c = fbuf.sbumpc(); + VERIFY( c == 'a' ); + fbuf.close(); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc new file mode 100644 index 000000000..008b56d21 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/10132-2.cc @@ -0,0 +1,54 @@ +// 2003-04-24 bkoz + +// Copyright (C) 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/10132, add on +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf; + + try + { + // Need codecvt facet for width argument in seekoff. + gnu_filebuf obj; + obj.pubseekoff(2, std::ios_base::beg); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc new file mode 100644 index 000000000..14e0b0a3a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-1.cc @@ -0,0 +1,83 @@ +// Copyright (C) 2003, 2005, 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> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>('a')); + fb.close(); + + fb.open(name, ios_base::in); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff calls codecvt::length with the correct state. + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + VERIFY( pos != traits_type::pos_type(traits_type::off_type(-1)) ); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + fb.sbumpc(); + fb.sbumpc(); + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + c = fb.sbumpc(); + VERIFY( c == traits_type::eof() ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc new file mode 100644 index 000000000..64ada570c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-2.cc @@ -0,0 +1,86 @@ +// Copyright (C) 2003, 2005, 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> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>('a')); + fb.close(); + + fb.open(name, ios_base::in); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff resets the state when seeking to beginning. + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::beg); + VERIFY( pos != traits_type::pos_type(traits_type::off_type(-1)) ); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>(0xff)) ); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + fb.sbumpc(); + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + c = fb.sbumpc(); + VERIFY( c == traits_type::eof() ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc new file mode 100644 index 000000000..79cda63fe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-3.cc @@ -0,0 +1,81 @@ +// Copyright (C) 2003, 2005, 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> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from<char>('b')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>(0xfc)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + + fb.close(); + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff returns the correct state + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + fb.sbumpc(); + + fb.pubseekpos(pos); + + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc new file mode 100644 index 000000000..3bf4353d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/12790-4.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2003, 2005, 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekoff_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from<char>('b')); + fb.sputc(pod_uchar::from<char>(0xff)); + + // Check that seekoff sets the current state during output + fb.pubseekoff(0, ios_base::cur); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + + fb.pubseekoff(0, ios_base::beg); + fb.sbumpc(); + fb.sbumpc(); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc new file mode 100644 index 000000000..6e40a89aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc @@ -0,0 +1,103 @@ +// 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> +#include <testsuite_character.h> + +const char name_01[] = "tmp_seekoff_45628.tst"; + +unsigned underflows, overflows; + +class my_filebuf +: public std::basic_filebuf<__gnu_test::pod_uchar> +{ + virtual int_type + underflow() + { + ++underflows; + return std::basic_filebuf<__gnu_test::pod_uchar>::underflow(); + } + virtual int_type + overflow(int_type c) + { + ++overflows; + return std::basic_filebuf<__gnu_test::pod_uchar>::overflow(c); + } +}; + +// libstdc++/45628 +void test01() +{ + bool test __attribute__((unused)) = true; + + using __gnu_test::pod_uchar; + std::locale loc(std::locale::classic(), + new std::codecvt<my_filebuf::traits_type::char_type, char, + my_filebuf::traits_type::state_type>); + + my_filebuf::pos_type opos[3], ipos[3]; + my_filebuf q; + q.pubimbue(loc); + + q.open(name_01, std::ios_base::in | std::ios_base::out + | std::ios_base::trunc); + + q.sputc(pod_uchar::from<char>('a')); + opos[0] = q.pubseekoff(0, std::ios_base::cur); + q.sputc(pod_uchar::from<char>('b')); + opos[1] = q.pubseekoff(0, std::ios_base::cur); + q.sputc(pod_uchar::from<char>('c')); + opos[2] = q.pubseekoff(0, std::ios_base::cur); + + VERIFY( overflows <= 9 ); // pubseekoff calls overflow twice if converting. + // NB: checking opos==ipos is not very rigorous as long as it flushes, since + // all positions will be at initial state. + q.pubseekoff(0, std::ios_base::beg); + + q.sbumpc(); + VERIFY( underflows == 1 ); + + ipos[0] = q.pubseekoff(0, std::ios_base::cur); + VERIFY( ipos[0] == opos[0] ); + q.sbumpc(); + ipos[1] = q.pubseekoff(0, std::ios_base::cur); + VERIFY( ipos[1] == opos[1] ); + q.sbumpc(); + ipos[2] = q.pubseekoff(0, std::ios_base::cur); + VERIFY( ipos[2] == opos[2] ); + + VERIFY( underflows == 1 ); // pubseekoff never flushes get area + + // Bonus test: check automatic mode switches. + q.sputc(pod_uchar::from<char>('d')); + + q.pubseekpos( ipos[1] ); + q.sputc(pod_uchar::from<char>('e')); + + VERIFY( my_filebuf::traits_type::eq( + my_filebuf::traits_type::to_char_type(q.sgetc()), + pod_uchar::from<char>('d')) ); +} + +int main() +{ + test01(); + return 0; +} 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; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc new file mode 100644 index 000000000..c6f13dcd0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/1.cc @@ -0,0 +1,137 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-08 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 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 <locale> +#include <cstdio> +#include <testsuite_hooks.h> + +// Check that basic_filebuf::seekoff handles UTF-8 when open for input. +void test01() +{ + using namespace std; + typedef wfilebuf::pos_type pos_type; + typedef wfilebuf::int_type int_type; + + bool test __attribute__((unused)) = true; + const char name[] = "tmp_seekoff-1.tst"; + const int_type eof = wfilebuf::traits_type::eof(); + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + const int loops = 2 * BUFSIZ / wlen; + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + for (int i = 0; i < loops; ++i) + fwrite(cstr, 1, clen, file); + fclose(file); + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + + pos_type p1 = fb.pubseekoff(0, ios_base::cur); + pos_type end = fb.pubseekoff(0, ios_base::end); + pos_type beg = fb.pubseekoff(0, ios_base::beg); + VERIFY( p1 == beg ); + + const size_t limit = wlen * loops; + for (size_t index = 0; index < limit; ++index) + { + // Call seekoff at pseudo-random intervals. + if (index % 5 == 0 || index % 7 == 0) + { + pos_type p2 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p2 != pos_type(-1) ); + } + int_type c1 = fb.sbumpc(); + VERIFY( c1 != eof ); + VERIFY( static_cast<wchar_t>(c1) == wstr[index % wlen] ); + } + + pos_type p3 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p3 == end ); + + int_type c2 = fb.sbumpc(); + VERIFY( c2 == eof ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc new file mode 100644 index 000000000..fd0c19ea3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/11543.cc @@ -0,0 +1,141 @@ +// 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 <locale> +#include <testsuite_hooks.h> + +struct MyState +{ +}; + +struct MyCharTraits : std::char_traits<wchar_t> +{ + typedef std::fpos<MyState> pos_type; + typedef MyState state_type; +}; + +namespace std +{ + template <> + class codecvt<wchar_t, char, MyState> : + public locale::facet, public codecvt_base + { + public: + typedef wchar_t 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*, + const intern_type*, const intern_type*&, + extern_type*, extern_type*, extern_type*&) const + { return error; } + + virtual result do_in(state_type&, const extern_type*, const extern_type*, + const extern_type*&, intern_type*, intern_type*, + intern_type*&) const + { return error; } + + 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 false; } + + 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<wchar_t, char, MyState>::id; + + codecvt<wchar_t, char, MyState>::~codecvt() + { } +} + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc(std::locale::classic(), + new std::codecvt<wchar_t, char, MyState>); + std::basic_filebuf<wchar_t, 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/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc new file mode 100644 index 000000000..b889f1bf5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-1.cc @@ -0,0 +1,78 @@ +// 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'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/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc new file mode 100644 index 000000000..d38952586 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-2.cc @@ -0,0 +1,79 @@ +// 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'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/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc new file mode 100644 index 000000000..4057cd418 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-3.cc @@ -0,0 +1,78 @@ +// 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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); + + wfilebuf 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/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc new file mode 100644 index 000000000..c04b4e79b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/12790-4.cc @@ -0,0 +1,79 @@ +// 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + fb.sputc(L'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/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc new file mode 100644 index 000000000..cc9c4e22a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/2.cc @@ -0,0 +1,90 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-08 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 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 <locale> +#include <cstdio> +#include <testsuite_hooks.h> + +// Check that basic_filebuf::seekoff handles UTF-8 when open for input and +// output. +void test02() +{ + using namespace std; + typedef wfilebuf::int_type int_type; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_seekoff-2.tst"; + + locale loc = locale("se_NO.UTF-8"); + + const size_t size = 10; + wchar_t buf[size]; + streamsize n; + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + n = fb.sputn(L"\xa0st", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !wmemcmp(buf, L"\xa0s", 2) ); + + fb.pubseekoff(0, ios_base::cur); + n = fb.sputn(L"\xb2R", 2); + VERIFY( n == 2 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 4 ); + VERIFY( !wmemcmp(buf, L"\xa0s\xb2R", 4) ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sputn(L"\x90m\x92n\x94", 5); + VERIFY( n == 5 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !wmemcmp(buf, L"\x90m", 2) ); + + fb.pubseekoff(0, ios_base::end); + n = fb.sputn(L"I\xbfJ", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 8 ); + VERIFY( !wmemcmp(buf, L"\x90m\x92n\x94I\xbfJ", 8) ); + + fb.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc new file mode 100644 index 000000000..435ebcc3e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/3.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_seekoff_3"; + + wfilebuf fb; + + fb.open(name, ios_base::out); + fb.sputc(0xf001); + + try + { + // seekoff should flush the output sequence, which will fail + // if the output buffer contains illegal characters. + fb.pubseekoff(0, ios_base::cur); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc new file mode 100644 index 000000000..245f18f48 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/4.cc @@ -0,0 +1,94 @@ +// { dg-require-fileio "" } + +// Copyright (C) 2010, 2011 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 <cwchar> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef wfilebuf::pos_type pos_type; + const char name[] = "tmp_seekoff-4.tst"; + + const size_t size = 12; + wchar_t buf[size]; + streamsize n; + + wfilebuf fb; + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + + n = fb.sputn(L"abcd", 4); + VERIFY( n == 4 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 3); + VERIFY( n == 3 ); + VERIFY( !wmemcmp(buf, L"abc", 3) ); + + // Check read => write without pubseekoff(0, ios_base::cur) + + n = fb.sputn(L"ef", 2); + VERIFY( n == 2 ); + + fb.pubseekoff(0, ios_base::beg); + + n = fb.sgetn(buf, size); + VERIFY( n == 5 ); + VERIFY( !wmemcmp(buf, L"abcef", 5) ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sputn(L"gh", 2); + VERIFY( n == 2 ); + + // Check write => read without pubseekoff(0, ios_base::cur) + + n = fb.sgetn( buf, 3 ); + VERIFY( !memcmp(buf, L"cef", 3) ); + + n = fb.sputn(L"ijkl", 4); + VERIFY( n == 4 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, 2); + VERIFY( n == 2 ); + VERIFY( !wmemcmp(buf, L"gh", 2) ); + + fb.pubseekoff(0, ios_base::end); + n = fb.sputn(L"mno", 3); + VERIFY( n == 3 ); + + fb.pubseekoff(0, ios_base::beg); + n = fb.sgetn(buf, size); + VERIFY( n == 12 ); + VERIFY( !wmemcmp(buf, L"ghcefijklmno", 12) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc new file mode 100644 index 000000000..312386a24 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/wchar_t/9875_seekoff.cc @@ -0,0 +1,99 @@ +// 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 <locale> +#include <algorithm> +#include <cstring> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, char, mbstate_t> +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, + const wchar_t*& from_next, char* to, char* to_end, + char*& to_next) const + { + std::size_t from_len = from_end - from; + std::size_t to_len = (to_end - to) / sizeof(wchar_t); + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len; + to_next = to + len * sizeof(wchar_t); + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_in(std::mbstate_t&, const char* from, const char* from_end, + const char*& from_next, wchar_t* to, wchar_t* to_end, + wchar_t*& to_next) const + { + std::size_t from_len = + (from_end - from) / sizeof(wchar_t); + std::size_t to_len = to_end - to; + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len * sizeof(wchar_t); + to_next = to + len; + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(std::mbstate_t&, char*, char*, char*&) const + { return std::codecvt_base::noconv; } + + virtual int do_encoding() const throw() { return sizeof(wchar_t); } + virtual bool do_always_noconv() const throw() { return false; } + + virtual int + do_length(std::mbstate_t&, const char* from, const char* end, + std::size_t max) + { + std::size_t len = (end - from) / sizeof(wchar_t); + return std::min(len, max) * sizeof(wchar_t); + } + + virtual int do_max_length() const throw() { return sizeof(wchar_t); } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // seekoff + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_9875_seekoff", ios_base::out | ios_base::in | ios_base::trunc); + fb.sputn(L"0123456789", 10); + fb.pubseekoff(-3, ios_base::cur); + VERIFY( fb.sgetc() == L'7' ); + fb.pubseekoff(-3, ios_base::cur); + VERIFY( fb.sgetc() == L'4' ); + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc new file mode 100644 index 000000000..34d437925 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/10132-3.cc @@ -0,0 +1,54 @@ +// 2003-04-24 bkoz + +// Copyright (C) 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/10132, add on +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_filebuf<__gnu_test::pod_ushort> gnu_filebuf; + + try + { + // Need codecvt facet for width argument in seekpos. + gnu_filebuf obj; + obj.pubseekpos(0); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc new file mode 100644 index 000000000..ffe5aa726 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-1.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2003, 2005, 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> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + + // Check that seekpos restores the state correctly + fb.pubseekpos(pos); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc new file mode 100644 index 000000000..8b7050965 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-2.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2003, 2005, 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> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from<char>('b')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>(0xfc)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + + fb.close(); + fb.open(name, ios_base::in); + + fb.sbumpc(); + fb.sbumpc(); + traits_type::pos_type pos1 = fb.pubseekoff(0, ios_base::cur); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekpos returns the correct state + traits_type::pos_type pos2 = fb.pubseekpos(pos1); + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + fb.sbumpc(); + + fb.pubseekpos(pos2); + c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc new file mode 100644 index 000000000..79337d381 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/12790-3.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2005, 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> +#include <testsuite_character.h> + +// libstdc++/12790 +void test01() +{ + using namespace std; + using __gnu_test::pod_uchar; + typedef basic_filebuf<pod_uchar>::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + locale loc(locale::classic(), + new codecvt<traits_type::char_type, char, + traits_type::state_type>); + + basic_filebuf<pod_uchar> fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::in | ios_base::out | ios_base::trunc); + fb.sputc(pod_uchar::from<char>('b')); + fb.sputc(pod_uchar::from<char>(0xff)); + fb.sputc(pod_uchar::from<char>('c')); + fb.sputc(pod_uchar::from<char>(0xff)); + + fb.pubseekoff(0, ios_base::beg); + fb.sbumpc(); + fb.sbumpc(); + traits_type::pos_type pos = fb.pubseekoff(0, ios_base::cur); + fb.sbumpc(); + fb.sbumpc(); + + // Check that seekoff sets the current state for output + fb.pubseekpos(pos); + + fb.sputc(pod_uchar::from<char>('a')); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + fb.sputc(pod_uchar::from<char>(0)); + + fb.pubseekpos(pos); + + traits_type::int_type c = fb.sbumpc(); + VERIFY( c != traits_type::eof() ); + VERIFY( traits_type::eq(traits_type::to_char_type(c), + pod_uchar::from<char>('a')) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc new file mode 100644 index 000000000..da5a80b4b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-in.cc @@ -0,0 +1,103 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos.txt"; // file with data in it + +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; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in + { + constraint_filebuf fb; + fb.open(name_01, ios_base::in); + VERIFY( !fb.write_position() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == traits_type::eof() ); + VERIFY( c2 != c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( !fb.write_position() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc new file mode 100644 index 000000000..c90de5e31 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-io.cc @@ -0,0 +1,103 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-1io.tst"; // file with data in it + +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; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in | out + { + constraint_filebuf fb; + fb.open(name_01, ios_base::out | ios_base::in); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.write_position() ); + VERIFY( !fb.read_position() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc new file mode 100644 index 000000000..0b596a451 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/1-out.cc @@ -0,0 +1,105 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-1out.tst"; // file with data in it + +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; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // out + { + constraint_filebuf fb; + fb.open(name_01, ios_base::out); + VERIFY( !fb.write_position() ); + VERIFY( !fb.read_position() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 != c3 ); + VERIFY( c3 == traits_type::eof() ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.write_position() ); + VERIFY( !fb.read_position() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.cc new file mode 100644 index 000000000..1a024941f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-1.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::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc new file mode 100644 index 000000000..b0085e29e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-2.cc @@ -0,0 +1,82 @@ +// 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::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_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); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc('a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc new file mode 100644 index 000000000..0eb3ecf80 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-3.cc @@ -0,0 +1,79 @@ +// 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 <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::seekpos() should call codecvt::unshift(), +// but only if writing +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( !cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc new file mode 100644 index 000000000..506482bd6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/12790-4.cc @@ -0,0 +1,82 @@ +// 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::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + filebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc('a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc new file mode 100644 index 000000000..782fb6bb8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-in.cc @@ -0,0 +1,104 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos.txt"; // file with data in it + +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; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::in); + VERIFY( fb.unbuffered() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == traits_type::eof() ); + VERIFY( c2 != c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.unbuffered() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc new file mode 100644 index 000000000..4916d6059 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-io.cc @@ -0,0 +1,102 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-2io.tst"; // file with data in it + +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; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // in | out + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::out | ios_base::in); + VERIFY( fb.unbuffered() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == 't' ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 == c3 ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.unbuffered() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc new file mode 100644 index 000000000..9031bca6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/2-out.cc @@ -0,0 +1,104 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "seekpos-2out.tst"; // file with data in it + +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; + + int_type c1; + int_type c2; + int_type c3; + + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + pos_type pt_3; + off_type off_1 = 0; + off_type off_2 = 0; + + // seekpos + // pubseekpos(pos_type sp, ios_base::openmode) + // alters the stream position to sp + + // out + { + constraint_filebuf fb; + fb.pubsetbuf(0, 0); + fb.open(name_01, ios_base::out); + VERIFY( fb.unbuffered() ); + + // beg + pt_1 = fb.pubseekoff(78, ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 > 0 ); + c1 = fb.snextc(); //current in pointer +1 + VERIFY( c1 == traits_type::eof() ); + + // cur + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c2 = fb.sputc('\n'); //test current out pointer + pt_3 = fb.pubseekoff(0, ios_base::cur); + fb.pubseekpos(pt_3); + c3 = fb.sgetc(); + fb.pubsync(); //resets pointers + pt_2 = fb.pubseekpos(pt_1); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = fb.snextc(); //current in pointer +1 + VERIFY( c2 != c3 ); + VERIFY( c3 == traits_type::eof() ); + + // end + pt_1 = fb.pubseekoff(0, ios_base::end); + off_1 = off_type(pt_1); + VERIFY( off_1 > off_2 ); + fb.sputn("\nof the wonderful things he does!!\nok", 37); + fb.pubsync(); + VERIFY( fb.unbuffered() ); + fb.close(); + VERIFY( !fb.is_open() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-in.cc new file mode 100644 index 000000000..278d39e72 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/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; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + VERIFY( pass == (p != bad) ); + + p = in.pubseekpos(0, ios_base::out); + VERIFY( pass == (p != bad) ); // See libstdc++/12232 + + p = in.pubseekpos(0); + 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/seekpos/char/3-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-io.cc new file mode 100644 index 000000000..3f37a266a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/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; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekpos(0, ios_base::out); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekpos(0); + 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/seekpos/char/3-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/char/3-out.cc new file mode 100644 index 000000000..07bdc0cae --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/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; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + VERIFY( pass == (p != bad) ); // See libstdc++/12232 + + p = in.pubseekpos(0, ios_base::out); + VERIFY( pass == (p != bad) ); + + p = in.pubseekpos(0); + 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/seekpos/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/1.cc new file mode 100644 index 000000000..320938319 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/1.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_seekpos_1"; + + wfilebuf fb; + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(0xf001); + + try + { + fb.pubseekpos(pos); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc new file mode 100644 index 000000000..55325875a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-1.cc @@ -0,0 +1,79 @@ +// 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.cc new file mode 100644 index 000000000..e939050a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-2.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 + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(L'a'); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc new file mode 100644 index 000000000..a1afdcad2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-3.cc @@ -0,0 +1,79 @@ +// 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 <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::seekpos() should call codecvt::unshift(), +// but only if writing +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( !cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.cc new file mode 100644 index 000000000..57a9a3c02 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/12790-4.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 + +#include <locale> +#include <fstream> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, 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::seekpos() should call codecvt::unshift() +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_seekpos_12790"; + + Cvt* cvt = new Cvt; + locale loc(locale::classic(), cvt); + + wfilebuf fb; + fb.pubimbue(loc); + + fb.open(name, ios_base::out); + streampos pos = fb.pubseekoff(0, ios_base::beg); + fb.sputc(L'a'); + fb.pubsync(); // Does not call unshift() + + VERIFY( !cvt->unshift_called ); + fb.pubseekpos(pos); + VERIFY( cvt->unshift_called ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc new file mode 100644 index 000000000..e011f875d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9874.cc @@ -0,0 +1,139 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-10-07 Petur Runolfsson <peturr02@ru.is> +// +// Copyright (C) 2003, 2004, 2005, 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 <locale> +#include <vector> +#include <utility> +#include <testsuite_hooks.h> + +// libstdc++/9874 +void test01() +{ + using namespace std; + typedef wfilebuf::pos_type pos_type; + typedef wfilebuf::int_type int_type; + typedef vector<pair<pos_type, size_t> > vec_type; + + bool test __attribute__((unused)) = true; + const char name[] = "tmp_seekpos-9874.tst"; + const int_type eof = wfilebuf::traits_type::eof(); + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + const int loops = 2 * BUFSIZ / wlen; + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + for (int i = 0; i < loops; ++i) + fwrite(cstr, 1, clen, file); + fclose(file); + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + + vec_type vec; + + const size_t limit = wlen * loops; + for (size_t index = 0; index < limit; ++index) + { + // Call seekoff at pseudo-random intervals. + if (index % 5 == 0 || index % 7 == 0) + { + pos_type p1 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p1 != pos_type(-1) ); + vec.push_back(make_pair(p1, index)); + } + int_type c1 = fb.sbumpc(); + VERIFY( c1 != eof ); + } + + for (vec_type::iterator it = vec.begin(); it != vec.end(); ++it) + { + pos_type p2 = fb.pubseekpos(it->first); + VERIFY( p2 == it->first ); + int_type c2 = fb.sbumpc(); + VERIFY( c2 != eof ); + VERIFY( static_cast<wchar_t>(c2) == wstr[it->second % wlen] ); + } + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc new file mode 100644 index 000000000..501ce1fda --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/seekpos/wchar_t/9875_seekpos.cc @@ -0,0 +1,111 @@ +// 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 <locale> +#include <algorithm> +#include <cstring> +#include <testsuite_hooks.h> + +class Cvt : public std::codecvt<wchar_t, char, mbstate_t> +{ +protected: + virtual std::codecvt_base::result + do_out(std::mbstate_t&, const wchar_t* from, const wchar_t* from_end, + const wchar_t*& from_next, char* to, char* to_end, + char*& to_next) const + { + std::size_t from_len = from_end - from; + std::size_t to_len = (to_end - to) / sizeof(wchar_t); + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len; + to_next = to + len * sizeof(wchar_t); + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_in(std::mbstate_t&, const char* from, const char* from_end, + const char*& from_next, wchar_t* to, wchar_t* to_end, + wchar_t*& to_next) const + { + std::size_t from_len = + (from_end - from) / sizeof(wchar_t); + std::size_t to_len = to_end - to; + std::size_t len = std::min(from_len, to_len); + std::memcpy(to, from, len * sizeof(wchar_t)); + from_next = from + len * sizeof(wchar_t); + to_next = to + len; + return from_next == from_end ? std::codecvt_base::ok : + std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(std::mbstate_t&, char*, char*, char*&) const + { return std::codecvt_base::noconv; } + + virtual int do_encoding() const throw() { return sizeof(wchar_t); } + virtual bool do_always_noconv() const throw() { return false; } + + virtual int + do_length(std::mbstate_t&, const char* from, const char* end, + std::size_t max) + { + std::size_t len = (end - from) / sizeof(wchar_t); + return std::min(len, max) * sizeof(wchar_t); + } + + virtual int do_max_length() const throw() { return sizeof(wchar_t); } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // seekpos + wfilebuf fb; + fb.pubimbue(locale(locale::classic(), new Cvt)); + fb.open("tmp_9875_seekpos", ios_base::out | ios_base::in | ios_base::trunc); + fb.sputn(L"0123456789", 10); + + streampos p1 = fb.pubseekoff(0, ios_base::cur); + VERIFY( p1 != streampos(-1) ); + fb.sputc(L'a'); + + streampos p2 = fb.pubseekpos(p1); + VERIFY( p2 != streampos(-1) ); + VERIFY( p2 == p1 ); + VERIFY( fb.sgetc() == L'a' ); + + fb.pubseekoff(0, ios_base::beg); + wchar_t buf[11]; + streamsize s1 = fb.sgetn(buf, 11); + VERIFY( s1 == 11 ); + VERIFY( !wmemcmp(buf, L"0123456789a", 11) ); + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc new file mode 100644 index 000000000..42688e825 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/1.cc @@ -0,0 +1,89 @@ +// 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> + +class testbuf : public std::filebuf +{ +public: + + // Typedefs: + typedef std::filebuf base_type; + typedef base_type::traits_type traits_type; + typedef base_type::char_type char_type; + + testbuf(): base_type() + { _M_mode = (std::ios_base::in | std::ios_base::out); } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + test = (!this->pbase()); + test &= (!this->pptr()); + return test; + } +}; + +const char name_01[] = "filebuf_virtuals-1.txt"; + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + typedef std::filebuf::int_type int_type; + typedef std::filebuf::traits_type traits_type; + typedef std::filebuf::pos_type pos_type; + typedef std::filebuf::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + + { + testbuf f_tmp; + + // setbuf + // pubsetbuf(char_type* s, streamsize n) + f_tmp.pubsetbuf(0,0); + VERIFY( f_tmp.check_pointers() ); + } + + { + testbuf f_tmp; + + f_tmp.open(name_01, ios_base::out | ios_base::in); + f_tmp.sbumpc(); + + // setbuf + // pubsetbuf(char_type* s, streamsize n) + f_tmp.pubsetbuf(0, 0); + VERIFY( f_tmp.check_pointers() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc new file mode 100644 index 000000000..ed567de1b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-1.cc @@ -0,0 +1,58 @@ +// 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 <cstdio> +#include <cstring> +#include <testsuite_hooks.h> + +// libstdc++/12875 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_setbuf4"; + static char buf[1024]; + + FILE* out = fopen(name, "w"); + fputs("Hello, world", out); + fclose(out); + + filebuf in; + in.open(name, ios_base::in); + char str[256]; + streamsize r = in.sgetn(str, 6); + VERIFY( r == 6 ); + VERIFY( !memcmp(str, "Hello,", 6) ); + in.pubsetbuf(buf, 1024); + r = in.sgetn(str, 6); + VERIFY( r == 6 ); + VERIFY( !memcmp(str, " world", 6) ); + in.close(); +} + +// libstdc++/12875 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc new file mode 100644 index 000000000..b736b1460 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/12875-2.cc @@ -0,0 +1,56 @@ +// 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 <cstdio> +#include <cstring> +#include <testsuite_hooks.h> + +// libstdc++/12875 +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_setbuf5"; + static char buf[1024]; + + filebuf out; + out.open(name, ios_base::out); + streamsize r = out.sputn("Hello,", 6); + VERIFY( r == 6 ); + out.pubsetbuf(buf, 1024); + r = out.sputn(" world", 6); + VERIFY( r == 6 ); + VERIFY( out.close() ); + + FILE* in = fopen(name, "r"); + char str[256]; + VERIFY( fgets(str, 256, in) ); + VERIFY( !strcmp(str, "Hello, world") ); + fclose(in); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc new file mode 100644 index 000000000..768285d75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/2.cc @@ -0,0 +1,48 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + filebuf fbuf; + fbuf.pubsetbuf(buf, 512); + fbuf.open("tmp_setbuf2", ios_base::out); + fbuf.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc new file mode 100644 index 000000000..bdb3989c3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/setbuf/char/3.cc @@ -0,0 +1,51 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test03() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + filebuf fbuf01; + // NB: +2 otherwise sputn is optimized to a direct write, + // bypassing the buffer. + fbuf01.pubsetbuf(buf, strlitsize + 2); + fbuf01.open("tmp_setbuf3", ios_base::out); + + fbuf01.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc new file mode 100644 index 000000000..3defffccf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-in.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc new file mode 100644 index 000000000..306f93af7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-io.cc @@ -0,0 +1,87 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_03[] = "tmp_sgetc_1io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in | out 1 + { + constraint_filebuf fb_03; // in | out + fb_03.open(name_03, ios::out | ios::in | ios::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c1 = fb_03.sgetc(); + c2 = fb_03.sbumpc(); + VERIFY( c1 == traits_type::eof() ); + VERIFY( c1 == c2 ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; // in + fb_01.open(name_01, ios::in | ios::out); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc new file mode 100644 index 000000000..32bc8092d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/1-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // out + { + constraint_filebuf fb_02; // out + fb_02.open(name_02, ios::out | ios::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + fb_02.sbumpc(); + c1 = fb_02.sbumpc(); + c2 = fb_02.sgetc(); + VERIFY( c1 == c2 ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc new file mode 100644 index 000000000..d3c179786 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-in.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // 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.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc new file mode 100644 index 000000000..6f162c9f8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-io.cc @@ -0,0 +1,86 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_03[] = "tmp_sgetc_2io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // in | out 1 + { + constraint_filebuf fb_03; // in | out + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios::out | ios::in | ios::trunc); + VERIFY( fb_03.unbuffered() ); + c1 = fb_03.sgetc(); + c2 = fb_03.sbumpc(); + VERIFY( c1 == traits_type::eof() ); + VERIFY( c1 == c2 ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; // in + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios::in | ios::out); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sgetc(); + VERIFY( c1 == c2 ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sgetc(); + c3 = fb_01.sgetc(); + VERIFY( c1 == '/' ); + VERIFY( c2 == ' ' ); + VERIFY( c3 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc new file mode 100644 index 000000000..04ea095dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetc/char/2-out.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + + // out + { + constraint_filebuf fb_02; // out + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios::out | ios::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sgetc(); + VERIFY( c1 == traits_type::eof() ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + fb_02.sbumpc(); + c1 = fb_02.sbumpc(); + c2 = fb_02.sgetc(); + VERIFY( c1 == c2 ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc new file mode 100644 index 000000000..47c0597cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-in.cc @@ -0,0 +1,92 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 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[] = "sgetn.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + char buffer[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in + { + constraint_filebuf fb_01; + // Need this since BUFSIZ is only guaranteed >= 255 and we want + // to trigger the same underflow situation everywhere. + fb_01.pubsetbuf(buffer, 8192); + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.in_avail(); // 8261 + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc new file mode 100644 index 000000000..ffcdc2c14 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-io.cc @@ -0,0 +1,105 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 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[] = "sgetn.txt"; // file with data in it +const char name_03[] = "tmp_sgetn_1io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + char buffer[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + strmsz_1 = fb_03.sgetn(carray1, 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + // Need this since BUFSIZ is only guaranteed >= 255 and we want + // to trigger the same underflow situation everywhere. + fb_01.pubsetbuf(buffer, 8192); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //at the end of the actual file + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc new file mode 100644 index 000000000..c9da66539 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/1-out.cc @@ -0,0 +1,76 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetn_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray2[8192] = ""; + int_type c2, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + strmsz_2 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, 10); + VERIFY( strmsz_2 == 0 ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + strmsz_1 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == -1 ); + VERIFY( strmsz_2 == 0 ); + c4 = fb_02.sgetc(); + VERIFY( c4 == traits_type::eof() ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc new file mode 100644 index 000000000..dda7c67e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-in.cc @@ -0,0 +1,88 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 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[] = "sgetn.txt"; // file with data in it + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); // 8181 or 8250 depending on buffer + strmsz_2 = fb_01.sgetn(carray2, 8181 + 5); + VERIFY( 8181 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, 65 + 5); + VERIFY( 70 == strmsz_2 ); // at the end of the actual file + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc new file mode 100644 index 000000000..d401f8732 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-io.cc @@ -0,0 +1,100 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 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[] = "sgetn.txt"; // file with data in it +const char name_03[] = "tmp_sgetn_2io.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray1[13] = ""; + char carray2[8192] = ""; + int_type c1, c4; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + strmsz_1 = fb_03.sgetn(carray1, 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray1, 10); + VERIFY( strmsz_2 == 10 ); + strmsz_2 = fb_01.in_avail(); + VERIFY( strmsz_1 > strmsz_2 ); + c1 = fb_01.sgetc(); + VERIFY( c1 == 'b' ); + strmsz_1 = fb_01.in_avail(); + strmsz_2 = fb_01.sgetn(carray2, 8181 + 5); + VERIFY( 8181 == strmsz_2 - 5 ); + c4 = fb_01.sgetc(); // buffer should have underflowed from above. + VERIFY( c4 == 'e' ); + strmsz_1 = fb_01.in_avail(); + VERIFY( strmsz_1 > 0 ); + strmsz_2 = fb_01.sgetn(carray2, 65 + 5); + VERIFY( 70 == strmsz_2 ); //at the end of the actual file + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc new file mode 100644 index 000000000..fd332b683 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/2-out.cc @@ -0,0 +1,76 @@ +// 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 + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sgetn_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + + streamsize strmsz_1, strmsz_2; + char carray2[8192] = ""; + int_type c2; + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + strmsz_2 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, 10); + VERIFY( strmsz_2 == 0 ); + c2 = fb_02.sgetc(); + VERIFY( c2 == traits_type::eof() ); + strmsz_1 = fb_02.in_avail(); + strmsz_2 = fb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == -1 ); + VERIFY( strmsz_2 == 0 ); + fb_02.sgetc(); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc new file mode 100644 index 000000000..146a23ea7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sgetn/char/3.cc @@ -0,0 +1,47 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "sgetn.txt"; + +void test06() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buffer[] = "xxxxxxxxxx"; + typedef filebuf::int_type int_type; + filebuf fbuf01; + fbuf01.open(name_01, ios_base::in); + int_type len1 = fbuf01.sgetn(buffer, sizeof(buffer)); + VERIFY( len1 == sizeof(buffer) ); + VERIFY( buffer[0] == '/' ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc new file mode 100644 index 000000000..5aa31d78f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-1.cc @@ -0,0 +1,98 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// Copyright (C) 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +// libstdc++/9533 +void test_01() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + const char* name = "tmp_fifo1"; + + const int count = 10000; + + signal(SIGPIPE, SIG_IGN); + unlink(name); + + if (0 != mkfifo(name, S_IRWXU)) + { + VERIFY( false ); + } + + int fval = fork(); + if (fval == -1) + { + unlink(name); + VERIFY( false ); + } + else if (fval == 0) + { + filebuf ofbuf; + ofbuf.open(name, ios_base::in|ios_base::out); + VERIFY( ofbuf.is_open() ); + sleep(1); + + for (int i = 0; i < count; ++i) + ofbuf.sputc(i % 100); + + ofbuf.pubsync(); + sleep(1); + ofbuf.close(); + exit(0); + } + + filebuf ifbuf; + ifbuf.open(name, ios_base::in); + VERIFY( ifbuf.is_open() ); + + for (int j = 0; j < count; ++j) + { + filebuf::int_type c1 = ifbuf.sbumpc(); + VERIFY( c1 == j % 100 ); + } + + filebuf::int_type c6 = ifbuf.sbumpc(); + VERIFY( c6 == filebuf::traits_type::eof() ); + + sleep(2); + ifbuf.close(); + + unlink(name); +} + +int +main() +{ + test_01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc new file mode 100644 index 000000000..0cba3a8f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/showmanyc/char/9533-2.cc @@ -0,0 +1,58 @@ +// 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> + +// libstdc++/9533 +void test_02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_file1"; + const char* strlit = "0123456789"; + + filebuf fb; + + int written = 0; + fb.open(name, ios_base::out | ios_base::trunc); + for (int i = 0; i < BUFSIZ; ++i) + written += fb.sputn(strlit, 10); + fb.close(); + + int read = 0; + int n = 0; + char buf[10]; + fb.open(name, ios_base::in); + do + { + n = fb.sgetn(buf, sizeof(buf)); + read += n; + } + while (n); + + VERIFY( read == written ); +} + +int +main() +{ + test_02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc new file mode 100644 index 000000000..93a3771fc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-in.cc @@ -0,0 +1,85 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.snextc(); + VERIFY( c1 == '/' ); + c1 = fb_01.snextc(); + VERIFY( c1 == ' ' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc new file mode 100644 index 000000000..7d51c0c98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-io.cc @@ -0,0 +1,84 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c3 = fb_03.snextc(); + VERIFY( c3 == traits_type::eof() ); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( !fb_01.write_position() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc new file mode 100644 index 000000000..e993fc7fe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/1-out.cc @@ -0,0 +1,65 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <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 +const char name_02[] = "tmp_snextc_1out.tst"; // empty file, need to create +const char name_03[] = "tmp_snextc_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c2; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc new file mode 100644 index 000000000..77b40d4c4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-in.cc @@ -0,0 +1,83 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + c1 = fb_01.snextc(); + VERIFY( c1 == '/' ); // overflow + c1 = fb_01.snextc(); + VERIFY( c1 == ' ' ); + VERIFY( fb_01.unbuffered() ); + } + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc new file mode 100644 index 000000000..e0c6f71db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-io.cc @@ -0,0 +1,82 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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 +const char name_03[] = "tmp_snextc_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c3; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + c3 = fb_03.snextc(); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_03.unbuffered() ); + } + + // in | out 2 + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in | ios_base::out); + VERIFY( fb_01.unbuffered() ); + int_type c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sbumpc(); + VERIFY( c4 == '/' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == ' ' ); + c1 = fb_01.snextc(); + VERIFY( c1 == '9' ); + c4 = fb_01.sgetc(); + VERIFY( c4 == '9' ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc new file mode 100644 index 000000000..728b2867e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/snextc/char/2-out.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_snextc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c2; + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + c2 = fb_02.snextc(); + VERIFY( c2 == traits_type::eof() ); + VERIFY( fb_02.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} 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 000000000..f8190a9cd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-in.cc @@ -0,0 +1,93 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = 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() ); + } +} + +int 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 000000000..726947379 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-io.cc @@ -0,0 +1,103 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = 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); + fb_01.pubseekoff(0, std::ios_base::cur); + 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); + fb_01.sputc('m'); + fb_01.pubseekoff(0, std::ios_base::cur); + 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.pubseekoff(0, std::ios_base::cur); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.sputc('a'); + fb_01.pubseekoff(0, std::ios_base::end); + 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() ); + } +} + +int 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 000000000..2cd1fdfef --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/1-out.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // 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() ); + } +} + +int 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 000000000..a2aa792e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-in.cc @@ -0,0 +1,93 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = 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() ); + } +} + +int 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 000000000..588c6b9b7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-io.cc @@ -0,0 +1,102 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = 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); + fb_01.pubseekoff(0, std::ios_base::cur); + 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); + fb_01.sputc('m'); + fb_01.pubseekoff(0, std::ios_base::cur); + 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.pubseekoff(0, std::ios_base::cur); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.sputc('a'); + fb_01.pubseekoff(0, std::ios_base::end); + 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.unbuffered() ); + } +} + +int 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 000000000..f72ef3b67 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/2-out.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // 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() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc new file mode 100644 index 000000000..608f13260 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputbackc/char/9425.cc @@ -0,0 +1,49 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +// libstdc++/9439, libstdc++/9425 +// basic_filebuf<>::pbackfail calls basic_filebuf<>::seekoff, but +// fails to check the return value +void test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf; + fbuf.open(name_01, ios_base::in); + filebuf::int_type r = fbuf.sputbackc('a'); + fbuf.close(); + + VERIFY( r == filebuf::traits_type::eof() ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc new file mode 100644 index 000000000..53d8734e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-in.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + c3 = fb_01.sputc('a'); + VERIFY( c3 == traits_type::eof() ); + VERIFY( !fb_01.write_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc new file mode 100644 index 000000000..f0e446c70 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-io.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputc_1io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + c1 = fb_03.sputc('b'); + VERIFY( c1 == 'b' ); + c2 = fb_03.sputc('d'); + VERIFY( c2 == 'd' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_03.sputc(char(i)); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc new file mode 100644 index 000000000..1c7ee8237 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputc_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sputc('a'); + VERIFY( c1 == 'a' ); + c2 = fb_02.sputc('c'); + VERIFY( c2 == 'c' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_02.sputc(char(i)); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc new file mode 100644 index 000000000..a2368f932 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf + +#include <string> +#include <fstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::filebuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc('a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-in.cc new file mode 100644 index 000000000..e6a7f069f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-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.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[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c3; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + c3 = fb_01.sputc('a'); + VERIFY( c3 == traits_type::eof() ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc new file mode 100644 index 000000000..16645f8db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-io.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputc_2io.tst"; + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // in | out 1 + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + c1 = fb_03.sputc('b'); + VERIFY( c1 == 'b' ); + c2 = fb_03.sputc('d'); + VERIFY( c2 == 'd' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_03.sputc(char(i)); + VERIFY( fb_03.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc new file mode 100644 index 000000000..9572be161 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/2-out.cc @@ -0,0 +1,71 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputc_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sputc(char_type c) + // if out_cur not avail, return overflow(traits_type::to_int_type(c)) + // else, stores c at out_cur, + // increments out_cur, and returns c as int_type + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + c1 = fb_02.sputc('a'); + VERIFY( c1 == 'a' ); + c2 = fb_02.sputc('c'); + VERIFY( c2 == 'c' ); + for (int i = 50; i <= 90; ++i) + c2 = fb_02.sputc(char(i)); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc new file mode 100644 index 000000000..1fdf45955 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputc/char/9701-2.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create + +bool over_called; + +class Derived_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::filebuf::overflow(c); + } + + const char_type* pub_epptr() const + { return epptr(); } + + const char_type* pub_pptr() const + { return pptr(); } +}; + +// libstdc++/9701 (partial) +void test11() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputc + Derived_filebuf dfbuf_01; + dfbuf_01.open(name_05, std::ios_base::out); + over_called = false; + dfbuf_01.sputc('i'); + VERIFY( over_called ); + over_expected = dfbuf_01.pub_epptr() == dfbuf_01.pub_pptr(); + over_called = false; + dfbuf_01.sputc('v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dfbuf_01.close(); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc new file mode 100644 index 000000000..537ebe2ca --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-in.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios_base::in); + VERIFY( !fb_01.write_position() ); + strmsz_1 = fb_01.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( !fb_01.write_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc new file mode 100644 index 000000000..39f4fed71 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-io.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputn_1io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in | out + { + constraint_filebuf fb_03; + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( !fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" + VERIFY( strmsz_1 == 10 ); + strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); + VERIFY( strmsz_2 == 10 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_03.write_position() ); + VERIFY( !fb_03.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.cc new file mode 100644 index 000000000..7abd18be1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1-out.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.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_02[] = "tmp_sputn_1out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // out + { + constraint_filebuf fb_02; + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( !fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + strmsz_1 = fb_02.sputn("racadabras", 10); + VERIFY( strmsz_1 == 10 ); + VERIFY( fb_02.write_position() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc new file mode 100644 index 000000000..c84a079d2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf + +#include <string> +#include <fstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::filebuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-in.cc new file mode 100644 index 000000000..7c2a92151 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-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.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[] = "filebuf_virtuals-1.txt"; // file with data in it + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in + { + constraint_filebuf fb_01; + fb_01.pubsetbuf(0, 0); + fb_01.open(name_01, ios_base::in); + VERIFY( fb_01.unbuffered() ); + strmsz_1 = fb_01.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc new file mode 100644 index 000000000..d5a5fdae1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-io.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "filebuf_virtuals-1.txt"; // file with data in it +const char name_03[] = "tmp_sputn_2io.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // in | out + { + constraint_filebuf fb_03; + fb_03.pubsetbuf(0, 0); + fb_03.open(name_03, ios_base::out | ios_base::in | ios_base::trunc); + VERIFY( fb_03.unbuffered() ); + strmsz_1 = fb_03.sputn("racadabras", 10);//"abracadabras or what?" + VERIFY( strmsz_1 == 10 ); + strmsz_2 = fb_03.sputn(", i wanna reach out and", 10); + VERIFY( strmsz_2 == 10 ); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( fb_03.unbuffered() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc new file mode 100644 index 000000000..ab70def6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/2-out.cc @@ -0,0 +1,67 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_02[] = "tmp_sputn_2out.tst"; // empty file, need to create + +void test05() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1; + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + + // out + { + constraint_filebuf fb_02; + fb_02.pubsetbuf(0, 0); + fb_02.open(name_02, ios_base::out | ios_base::trunc); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + strmsz_1 = fb_02.sputn("racadabras", 10); + VERIFY( strmsz_1 == 10 ); + VERIFY( fb_02.unbuffered() ); + VERIFY( !fb_02.read_position() ); + } +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc new file mode 100644 index 000000000..154fdba9a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9339.cc @@ -0,0 +1,49 @@ +// 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/>. + +// { dg-require-fileio "" } + +#include <fstream> +#include <testsuite_hooks.h> + +// libstdc++/9339 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbuf01; + int len = 35; + fbuf01.pubsetbuf(0, 0); + fbuf01.open("tmp_9339", ios_base::out | ios_base::trunc); + streamsize s1 = fbuf01.sputn("Pete Goldlust @ Carl Hammer Gallery", len); + VERIFY( s1 == len ); + fbuf01.close(); + + filebuf fbuf02; + char buf[256]; + fbuf02.open("tmp_9339", ios_base::in); + streamsize s2 = fbuf02.sgetn(buf, 256); + VERIFY( s2 == len ); + fbuf02.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc new file mode 100644 index 000000000..1379fe004 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sputn/char/9701-1.cc @@ -0,0 +1,74 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> + +const char name_05[] = "filebuf_virtuals-5.txt"; // empty file, need to create + +bool over_called; + +class Derived_filebuf : public std::filebuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::filebuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9701 (partial) +void test11() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputn + Derived_filebuf dfbuf_02; + dfbuf_02.open(name_05, std::ios_base::out); + over_called = false; + dfbuf_02.sputn("sonne's", 7); + VERIFY( over_called ); + over_expected = dfbuf_02.pub_epptr() == dfbuf_02.pub_pptr(); + over_called = false; + dfbuf_02.sputn(" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dfbuf_02.close(); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc new file mode 100644 index 000000000..e4e17733b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-in.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // in + { + constraint_filebuf fb_01; + fb_01.open(name_01, ios::in); + VERIFY( !fb_01.write_position() ); + c1 = fb_01.sbumpc(); + VERIFY( c1 == '/' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == c1 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + fb_01.pubseekoff(2, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == traits_type::not_eof(traits_type::eof()) ); + VERIFY( !fb_01.write_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc new file mode 100644 index 000000000..54a1372b4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-io.cc @@ -0,0 +1,84 @@ +// 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[] = "tmp_sungetc_1io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*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() ); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.pubseekoff(-1, std::ios_base::end); + fb_01.sbumpc(); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); + VERIFY( c2 == 'v' ); // VERIFY( c2 != traits_type::eof() ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + //test for _in_cur == _in_end + fb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = fb_01.in_avail(); // -1 cuz at the end + c1 = fb_01.sgetc(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); // 1 + fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + VERIFY( !fb_01.write_position() ); + VERIFY( fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc new file mode 100644 index 000000000..759cb0039 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/1-out.cc @@ -0,0 +1,69 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sungetc_1out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*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.sungetc(); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sungetc(); + VERIFY( c1 == c2 ); + VERIFY( !fb_01.write_position() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc new file mode 100644 index 000000000..94e176a6a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-in.cc @@ -0,0 +1,73 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#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_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2, c3; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + + // in + { + constraint_filebuf fb_01; + 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.sungetc(); + VERIFY( c2 == c1 ); + c3 = fb_01.sgetc(); + VERIFY( c3 == c2 ); + fb_01.pubseekoff(2, ios_base::beg, ios_base::in); + c1 = fb_01.sgetc(); + VERIFY( c1 == ' ' ); + c2 = fb_01.sungetc(); + VERIFY( c2 == traits_type::not_eof(traits_type::eof()) ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc new file mode 100644 index 000000000..782a83db9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-io.cc @@ -0,0 +1,83 @@ +// 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[] = "tmp_sungetc_2io.tst"; // empty file, need to create + +void test01() +{ + using namespace std; + using namespace __gnu_test; + + typedef filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + streamsize strmsz_1, strmsz_2; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*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() ); + fb_01.sputc('u'); + fb_01.sputc('v'); + fb_01.pubseekoff(-1, std::ios_base::end); + fb_01.sbumpc(); + strmsz_1 = fb_01.in_avail(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); + VERIFY( c2 == 'v' ); // VERIFY( c2 != traits_type::eof() ); + VERIFY( strmsz_1 + 1 == strmsz_2 ); + //test for _in_cur == _in_end + fb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = fb_01.in_avail(); // -1 cuz at the end + c1 = fb_01.sgetc(); + c2 = fb_01.sungetc(); + strmsz_2 = fb_01.in_avail(); // 1 + fb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + VERIFY( fb_01.unbuffered() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc new file mode 100644 index 000000000..dbdd9ab45 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sungetc/char/2-out.cc @@ -0,0 +1,70 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %*.txt + +const char name_01[] = "tmp_sungetc_2out.tst"; // empty file, need to create + +// Test overloaded virtual functions. +void test01() +{ + using namespace std; + using namespace __gnu_test; + typedef std::filebuf::int_type int_type; + typedef filebuf::traits_type traits_type; + + bool test __attribute__((unused)) = true; + int_type c1, c2; + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*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.sungetc(); + VERIFY( c2 == traits_type::eof() ); + fb_01.sbumpc(); + c1 = fb_01.sbumpc(); + c2 = fb_01.sungetc(); + VERIFY( c1 == c2 ); + VERIFY( fb_01.unbuffered() ); + VERIFY( !fb_01.read_position() ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc new file mode 100644 index 000000000..832e29558 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/1057.cc @@ -0,0 +1,104 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <fstream> +#include <testsuite_hooks.h> + +class setpbuf : public std::filebuf +{ + char buffer[4]; + std::string result; + +public: + + std::string& + get_result() + { return result; } + + setpbuf() + { + this->open("tmp_1057", std::ios_base::out | std::ios_base::trunc); + char foo [32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { + sync(); + close(); + } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::string text = "abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::string::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc new file mode 100644 index 000000000..a2a262a0d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/sync/char/9182-1.cc @@ -0,0 +1,79 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +const char name_07[] = "filebuf_virtuals-7.txt"; // empty file, need to create + +class errorcvt : public std::codecvt<char, char, mbstate_t> +{ +protected: + std::codecvt_base::result + do_out(mbstate_t&, const char* from, const char*, + const char*& from_next, char* to, char*, + char*& to_next) const + { + from_next = from; + to_next = to; + return std::codecvt<char, char, mbstate_t>::error; + } + + virtual bool do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9182 +// basic_filebuf<>::sync and overflow do not write out any characters +// if codecvt<>::out returns error +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc = locale::classic(); + loc = locale(loc, new errorcvt); + + filebuf fbuf1; + fbuf1.pubimbue(loc); + fbuf1.open(name_07, ios_base::out | ios_base::trunc); + + try + { + fbuf1.sputn("ison", 4); + fbuf1.pubsync(); + VERIFY( false ); + } + catch (std::exception&) + { + } +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc new file mode 100644 index 000000000..fb8d2f615 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/10096.cc @@ -0,0 +1,71 @@ +// 2003-05-03 Petur Runolfsson <peturr02@ru.is> + +// 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 <string> +#include <testsuite_hooks.h> + +class MyTraits : public std::char_traits<char> +{ +}; + +// libstdc++/10096 +void test01() +{ + using namespace std; + + const char* name = "filebuf_virtuals-1.txt"; + + string str; + filebuf fb1; + fb1.open(name, ios_base::in); + + filebuf::int_type c1; + while ((c1 = fb1.sbumpc()) != filebuf::traits_type::eof()) + str.push_back(filebuf::traits_type::to_char_type(c1)); + fb1.close(); + + basic_filebuf<char, MyTraits> fb; + VERIFY( fb.sgetc() == MyTraits::eof() ); + + fb.open(name, ios_base::in); + VERIFY( fb.is_open() ); + + for (string::iterator i = str.begin(); i != str.end(); ++i) + { + MyTraits::int_type c2 = fb.sbumpc(); + VERIFY( c2 != MyTraits::eof() ); + VERIFY( c2 == MyTraits::to_int_type(*i) ); + } + + VERIFY( fb.sgetc() == MyTraits::eof() ); + fb.close(); + VERIFY( !fb.is_open() ); + VERIFY( fb.sgetc() == MyTraits::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc new file mode 100644 index 000000000..03fcd7d9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/1.cc @@ -0,0 +1,83 @@ +// 2003-05-03 Petur Runolfsson <peturr02@ru.is> + +// 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 <locale> +#include <string> +#include <testsuite_hooks.h> + +// Check that basic_filebuf::underflow() handles +// codecvt::always_noconv() == false and codecvt::in() == noconv. +class NoconvCvt : public std::codecvt<char, char, std::mbstate_t> +{ +protected: + virtual bool + do_always_noconv() const throw() + { return false; } + + virtual result + do_in(state_type&, const char* from, const char*, const char*& from_next, + char* to, char*, char*& to_next) + { + from_next = from; + to_next = to; + return noconv; + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + + string str; + filebuf fb; + filebuf::int_type c1; + + if (fb.open(name, ios_base::in)) + { + while ((c1 = fb.sbumpc()) != EOF) + str.push_back(filebuf::traits_type::to_char_type(c1)); + fb.close(); + } + + locale loc(locale::classic(), new NoconvCvt); + fb.pubimbue(loc); + + if (fb.open(name, ios_base::in)) + { + for (string::iterator i = str.begin(); i != str.end(); ++i) + { + c1 = fb.sbumpc(); + VERIFY( c1 != filebuf::traits_type::eof() ); + VERIFY( c1 == filebuf::traits_type::to_int_type(*i) ); + } + VERIFY( fb.sgetc() == filebuf::traits_type::eof() ); + fb.close(); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc new file mode 100644 index 000000000..af0e9141c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc @@ -0,0 +1,115 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <fstream> +#include <cstdlib> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +class UnderBuf : public std::filebuf +{ +public: + int_type + pub_underflow() + { return underflow(); } + + std::streamsize + pub_showmanyc() + { return showmanyc(); } +}; + +// libstdc++/10097 +// filebuf::underflow drops characters. +bool test16() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo1"; + + signal(SIGPIPE, SIG_IGN); + unlink(name); + + if (0 != mkfifo(name, S_IRWXU)) + { + VERIFY( false ); + } + + semaphore s1, s2; + int fval = fork(); + if (fval == -1) + { + unlink(name); + VERIFY( false ); + } + else if (fval == 0) + { + filebuf fbout; + fbout.open(name, ios_base::in|ios_base::out); + VERIFY( fbout.is_open() ); + fbout.sputn("0123456789", 10); + fbout.pubsync(); + s1.wait(); + fbout.close(); + s2.signal(); + exit(0); + } + + UnderBuf fb; + fb.open(name, ios_base::in); + + fb.sgetc(); + streamsize n = fb.pub_showmanyc(); + + while (n > 0) + { + --n; + + UnderBuf::int_type c = fb.pub_underflow(); + VERIFY( c != UnderBuf::traits_type::eof() ); + + fb.sbumpc(); + } + + fb.close(); + s1.signal(); + s2.wait(); + + return test; +} + +int main() +{ + return !test16(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc new file mode 100644 index 000000000..0d36be046 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/2.cc @@ -0,0 +1,49 @@ +// 2003-06-25 Paolo Carlini <pcarlini@unitus.it> + +// 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 <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb_out, fb_in_out; + + fb_out.open("tmp_underflow.tst", ios::out); + fb_out.sputc('S'); + fb_out.sputc('T'); + fb_out.close(); + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out); + while (fb_in_out.sbumpc() != filebuf::traits_type::eof()); + + VERIFY( fb_in_out.sputc('x') == 'x' ); + fb_in_out.close(); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc new file mode 100644 index 000000000..4de8a4d46 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/3.cc @@ -0,0 +1,84 @@ +// Copyright (C) 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/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-fileio "" } + +#include <fstream> +#include <cctype> +#include <locale> +#include <testsuite_hooks.h> + +class Mycvtcc +: public std::codecvt<char, char, std::mbstate_t> +{ +protected: + virtual result + do_in(state_type&, + 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 + { + from_next = from, to_next = to; + + if (from_next == from_end || to_next == to_limit) + return partial; + + if (std::islower(*from_next)) + *to_next = std::toupper(*from_next); + else + *to_next = *from_next; + ++from_next, ++to_next; + return ok; + } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// See Novell Bug 255122 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + const char* name = "tmp_underflow_3.tst"; + filebuf fbuf, fbufx; + + fbuf.open(name, ios_base::out | ios_base::trunc); + VERIFY( fbuf.sputc('a') == 'a' ); + VERIFY( fbuf.sputc('b') == 'b' ); + VERIFY( fbuf.sputc('\n') == '\n' ); + fbuf.close(); + + fbufx.pubimbue(locale(locale::classic(), new Mycvtcc)); + fbufx.open(name, ios_base::in); + VERIFY( fbufx.sbumpc() == 'A' ); + VERIFY( fbufx.sbumpc() == 'B' ); + VERIFY( fbufx.sbumpc() == '\n' ); + VERIFY( fbufx.sbumpc() == filebuf::traits_type::eof() ); + fbufx.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc new file mode 100644 index 000000000..a356d626e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/45841.cc @@ -0,0 +1,41 @@ +// 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + filebuf fb_in_out; + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc); + + VERIFY( fb_in_out.sputc('x') == 'x' ); + VERIFY( fb_in_out.sgetc() == filebuf::traits_type::eof() ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc new file mode 100644 index 000000000..25f55493d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/9027.cc @@ -0,0 +1,85 @@ +// 2003-05-03 Petur Runolfsson <peturr02@ru.is> + +// 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 <locale> +#include <fstream> +#include <cctype> +#include <testsuite_hooks.h> + +class Cvt_to_upper : public std::codecvt<char, char, std::mbstate_t> +{ + typedef std::codecvt<char, char, std::mbstate_t> Base; + +public: + explicit Cvt_to_upper(std::size_t refs = 0) + : Base(refs) + { } + +protected: + virtual result + do_in(state_type&, + const extern_type* from, const extern_type* from_end, + const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + while (from < from_end && to < to_end) + *to++ = std::toupper(*from++); + + to_next = to; + from_next = from; + return from == from_end ? ok : partial; + } + + virtual bool + do_always_noconv() const throw() + { + return false; + } +}; + +// libstdc++/9027 +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + locale loc (locale::classic(), new Cvt_to_upper); + + filebuf fbin; + fbin.pubimbue(loc); + fbin.open(name, ios_base::in); + + int c; + while ((c = fbin.sbumpc()) != EOF) + { + VERIFY( !islower(c) ); + } + + fbin.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc new file mode 100644 index 000000000..72c3ecb0a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/1.cc @@ -0,0 +1,111 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 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 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 <locale> +#include <fstream> +#include <cstdio> +#include <testsuite_hooks.h> + +// Test handing of UTF-8 in basic_filebuf::underflow +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_underflow-1.tst"; + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + fwrite(cstr, 1, clen, file); + fclose(file); + + wchar_t wbuf[wlen + 1]; + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + streamsize n = fb.sgetn(wbuf, wlen + 1); + fb.close(); + + VERIFY( n == static_cast<streamsize>(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); +} + +int main () +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc new file mode 100644 index 000000000..55e226705 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-1.cc @@ -0,0 +1,50 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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_01[] = "tmp_11389-1"; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_01, ios_base::out); + fbout.sputc('a'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.open(name_01, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc new file mode 100644 index 000000000..e4527ee69 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-2.cc @@ -0,0 +1,52 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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_02[] = "tmp_11389-2"; + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_02, ios_base::out); + fbout.sputc('a'); + fbout.sputc('b'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.open(name_02, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sbumpc() == L'b' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc new file mode 100644 index 000000000..45bb4bdf5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-3.cc @@ -0,0 +1,51 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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_03[] = "tmp_11389-3"; + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_03, ios_base::out); + fbout.sputc('a'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.pubsetbuf(0, 0); + fbin.open(name_03, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc new file mode 100644 index 000000000..637f89806 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11389-4.cc @@ -0,0 +1,53 @@ +// { dg-require-namedlocale "en_US.UTF-8" } + +// Copyright (C) 2003, 2005, 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_04[] = "tmp_11389-4"; + +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open(name_04, ios_base::out); + fbout.sputc('a'); + fbout.sputc('b'); + fbout.close(); + + wfilebuf fbin; + locale loc(locale("en_US.UTF-8")); + fbin.pubimbue(loc); + fbin.pubsetbuf(0, 0); + fbin.open(name_04, ios_base::in); + VERIFY( fbin.sbumpc() == L'a' ); + VERIFY( fbin.sbumpc() == L'b' ); + VERIFY( fbin.sgetc() == wfilebuf::traits_type::eof() ); + fbin.close(); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc new file mode 100644 index 000000000..7a27acd6f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-1.cc @@ -0,0 +1,184 @@ +// 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 <locale> +#include <cstdio> +#include <testsuite_hooks.h> + +template <typename InternT, typename StateT = mbstate_t> +class checksumcvt : public std::codecvt<InternT, char, StateT> +{ + typedef std::codecvt<InternT, char, StateT> Base; + static const size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(size_t refs = 0) + : Base(refs) + { } + +protected: + virtual typename std::codecvt<InternT, char, StateT>::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(from_end - from), + static_cast<size_t>(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast<const char*>(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast<unsigned char>(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt<InternT, char, StateT>::ok + : std::codecvt<InternT, char, StateT>::partial; + } + + virtual typename std::codecvt<InternT, char, StateT>::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt<InternT, char, StateT>::ok; + } + + virtual typename std::codecvt<InternT, char, StateT>::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(to_end - to), + static_cast<size_t>(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast<char*>(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast<unsigned char>(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt<InternT, char, StateT>::error : + (from_next == from_end ? std::codecvt<InternT, char, StateT>::ok + : std::codecvt<InternT, char, StateT>::partial); + } + + virtual int + do_encoding() const throw() + { return width; } + + virtual int + do_length(StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, static_cast<size_t>(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast<unsigned char>(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { return width; } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/11544 (incomplete character in file) +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new checksumcvt<wchar_t>); + + const char* name = "tmp_11544-1"; + + FILE* f = fopen(name, "w"); + putc('a', f); + fclose(f); + + wifstream in; + in.imbue(loc); + in.open(name); + + VERIFY( in.good() ); + in.get(); + VERIFY( !in.good() ); + VERIFY( in.bad() ); + VERIFY( !in.eof() ); + + in.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc new file mode 100644 index 000000000..f6a2eaca9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11544-2.cc @@ -0,0 +1,184 @@ +// 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 <locale> +#include <cstdio> +#include <testsuite_hooks.h> + +template <typename InternT, typename StateT = mbstate_t> +class checksumcvt : public std::codecvt<InternT, char, StateT> +{ + typedef std::codecvt<InternT, char, StateT> Base; + static const size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(size_t refs = 0) + : Base(refs) + { } + +protected: + virtual typename std::codecvt<InternT, char, StateT>::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(from_end - from), + static_cast<size_t>(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast<const char*>(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast<unsigned char>(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt<InternT, char, StateT>::ok + : std::codecvt<InternT, char, StateT>::partial; + } + + virtual typename std::codecvt<InternT, char, StateT>::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt<InternT, char, StateT>::ok; + } + + virtual typename std::codecvt<InternT, char, StateT>::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(to_end - to), + static_cast<size_t>(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast<char*>(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast<unsigned char>(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt<InternT, char, StateT>::error : + (from_next == from_end ? std::codecvt<InternT, char, StateT>::ok + : std::codecvt<InternT, char, StateT>::partial); + } + + virtual int + do_encoding() const throw() + { return width; } + + virtual int + do_length(StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, static_cast<size_t>(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast<unsigned char>(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { return width; } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +// libstdc++/11544 (invalid byte sequence in file) +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new checksumcvt<wchar_t>); + + const char* name = "tmp_11544-2"; + + FILE* f = fopen(name, "w"); + VERIFY( fwrite("aaaab", 1, 5, f) == 5 ); + fclose(f); + + wifstream in; + in.imbue(loc); + in.open(name); + + VERIFY( in.good() ); + in.get(); + VERIFY( !in.good() ); + VERIFY( in.bad() ); + VERIFY( !in.eof() ); + + in.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc new file mode 100644 index 000000000..116c404a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/11603.cc @@ -0,0 +1,201 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +// { dg-require-binary-io "" } + +#include <fstream> +#include <locale> +#include <testsuite_hooks.h> + +template <typename InternT, typename StateT = std::mbstate_t> +class checksumcvt : public std::codecvt<InternT, char, StateT> +{ + typedef std::codecvt<InternT, char, StateT> Base; + static const std::size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(std::size_t refs = 0) + : Base(refs) + { } + +protected: + virtual std::codecvt_base::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(from_end - from), + static_cast<size_t>(to_end - to) / width); + + while (len--) + { + const char* p = + reinterpret_cast<const char*>(from); + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast<unsigned char>(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt_base::ok + : std::codecvt_base::partial; + } + + virtual std::codecvt_base::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt_base::ok; + } + + virtual std::codecvt_base::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(to_end - to), + static_cast<size_t>(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast<char*>(&tmp); + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast<unsigned char>(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt_base::error : + (from_next == from_end ? std::codecvt_base::ok + : std::codecvt_base::partial); + } + + virtual int + do_encoding() const throw() + { return width; } + + virtual int + do_length(const StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, + static_cast<size_t>(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (std::size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast<unsigned char>(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { return width; } + + virtual bool + do_always_noconv() const throw() + { return false; } +}; + +class Buf : public std::wfilebuf +{ +public: + std::streamsize pub_showmanyc() + { return showmanyc(); } + std::wfilebuf::int_type pub_underflow() + { return underflow(); } +}; + +// libstdc++/11603 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + filebuf fbout; + fbout.open("tmp_11603", ios_base::out); + fbout.sputn("aaaab", 5); + fbout.close(); + + locale loc(locale::classic(), new checksumcvt<wchar_t>); + + Buf fb; + fb.pubimbue(loc); + fb.open("tmp_11603", ios_base::in); + VERIFY( fb.pub_showmanyc() == 1 ); + + try + { + wfilebuf::int_type ret = fb.pub_underflow(); + VERIFY( ret != wfilebuf::traits_type::eof() ); + fb.sbumpc(); + ret = fb.pub_underflow(); + VERIFY( ret == wfilebuf::traits_type::eof() ); + } + catch (...) + { } + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc new file mode 100644 index 000000000..c6f30442c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/2.cc @@ -0,0 +1,112 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 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 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 <locale> +#include <fstream> +#include <cstdio> +#include <testsuite_hooks.h> + +// Test handing of UTF-8 in unbuffered basic_filebuf::underflow +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_underflow-2.tst"; + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + fwrite(cstr, 1, clen, file); + fclose(file); + + wchar_t wbuf[wlen + 1]; + + wfilebuf fb; + fb.pubimbue(loc); + fb.pubsetbuf(0, 0); + fb.open(name, ios_base::in); + streamsize n = fb.sgetn(wbuf, wlen + 1); + fb.close(); + + VERIFY( n == static_cast<streamsize>(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); +} + +int main () +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc new file mode 100644 index 000000000..42892e4ac --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/3.cc @@ -0,0 +1,117 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 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 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 <locale> +#include <fstream> +#include <cstdio> +#include <testsuite_hooks.h> + +// Test handing of UTF-8 in basic_filebuf::underflow +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char name[] = "tmp_underflow-3.tst"; + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + const int loops = 2 * BUFSIZ / wlen; + locale loc = locale("se_NO.UTF-8"); + + FILE* file = fopen(name, "w"); + for (int i = 0; i < loops; ++i) + fwrite(cstr, 1, clen, file); + fclose(file); + + wchar_t wbuf[wlen]; + + wfilebuf fb; + fb.pubimbue(loc); + fb.open(name, ios_base::in); + for (int i = 0; i < loops; ++i) + { + streamsize n = fb.sgetn(wbuf, wlen); + VERIFY( n == static_cast<streamsize>(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); + } + + VERIFY( fb.sgetc() == wfilebuf::traits_type::eof() ); + fb.close(); +} + +int main () +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc new file mode 100644 index 000000000..6e63db09d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/4.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> +// Adapted from 27_io/basic_filebuf/underflow/char/2.cc + +// Copyright (C) 2003, 2005, 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 <locale> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale loc (locale("se_NO.UTF-8")); + wfilebuf fb_out, fb_in_out; + fb_out.pubimbue(loc); + fb_in_out.pubimbue(loc); + + fb_out.open("tmp_underflow.tst", ios::out); + fb_out.sputc(L'S'); + fb_out.sputc(L'T'); + fb_out.close(); + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out); + while (fb_in_out.sbumpc() != wfilebuf::traits_type::eof()); + + VERIFY( fb_in_out.sputc(L'x') == L'x' ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc new file mode 100644 index 000000000..2d7cb7af2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/45841.cc @@ -0,0 +1,41 @@ +// 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> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + wfilebuf fb_in_out; + + fb_in_out.open("tmp_underflow.tst", ios::in | ios::out | ios::trunc); + + VERIFY( fb_in_out.sputc(L'x') == L'x' ); + VERIFY( fb_in_out.sgetc() == wfilebuf::traits_type::eof() ); + fb_in_out.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc new file mode 100644 index 000000000..4c4b8d3b4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/5.cc @@ -0,0 +1,74 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 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 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 <locale> +#include <fstream> +#include <cstdio> +#include <testsuite_hooks.h> + +// Test that unbuffered really means unbuffered for UTF-8 +void test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* name = "tmp_underflow-5"; + + wfilebuf fb; + fb.pubsetbuf(0, 0); + fb.pubimbue(locale("se_NO.UTF-8")); + + FILE* file = fopen(name, "w"); + setvbuf(file, 0, _IONBF, 0); + fputs("abcde", file); + + fb.open(name, ios_base::in); + VERIFY( fb.sbumpc() == L'a' ); + + fseek(file, 1, SEEK_SET); + fputc('0', file); + + VERIFY( fb.sbumpc() == L'0' ); + VERIFY( fb.sbumpc() == L'c' ); + + fputc('1', file); + fputc('2', file); + + VERIFY( fb.sbumpc() == L'2' ); + VERIFY( fb.sbumpc() == L'e' ); + VERIFY( fb.sbumpc() == WEOF ); + + fputc('3', file); + fputc('4', file); + + VERIFY( fb.sbumpc() == L'4' ); + VERIFY( fb.sbumpc() == WEOF ); + + fb.close(); + fclose(file); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc new file mode 100644 index 000000000..344db32d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9178.cc @@ -0,0 +1,204 @@ +// 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 <string> +#include <iterator> +#include <algorithm> +#include <locale> +#include <testsuite_hooks.h> + +template <typename InternT, typename StateT = mbstate_t> +class checksumcvt : public std::codecvt<InternT, char, StateT> +{ + typedef std::codecvt<InternT, char, StateT> Base; + static const size_t width = sizeof(InternT) + 1; + +public: + typedef InternT intern_type; + typedef char extern_type; + + explicit checksumcvt(size_t refs = 0) + : Base(refs) + { } + +protected: + virtual typename std::codecvt<InternT, char, StateT>::result + do_out(StateT&, const intern_type* from, + const intern_type* from_end, const intern_type*& from_next, + extern_type* to, extern_type* to_end, + extern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(from_end - from), + static_cast<size_t>(to_end - to) / width); + + while (len--) + { + const char* p = reinterpret_cast<const char*>(from); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + *to++ = p[i]; + checksum ^= static_cast<unsigned char>(p[i]); + } + + *to++ = checksum; + ++from; + } + + from_next = from; + to_next = to; + return from_next == from_end ? std::codecvt<InternT, char, StateT>::ok + : std::codecvt<InternT, char, StateT>::partial; + } + + virtual typename std::codecvt<InternT, char, StateT>::result + do_unshift(StateT&, extern_type* to, + extern_type*, extern_type*& to_next) const + { + to_next = to; + return std::codecvt<InternT, char, StateT>::ok; + } + + virtual typename std::codecvt<InternT, char, StateT>::result + do_in(StateT&, const extern_type* from, + const extern_type* from_end, const extern_type*& from_next, + intern_type* to, intern_type* to_end, + intern_type*& to_next) const + { + size_t len = std::min(static_cast<size_t>(to_end - to), + static_cast<size_t>(from_end - from) / width); + + while (len) + { + const char* f = from; + intern_type tmp; + char* p = reinterpret_cast<char*>(&tmp); + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + p[i] = *f; + checksum ^= static_cast<unsigned char>(*f++); + } + + if (*f++ != checksum) + break; + + from = f; + *to++ = tmp; + len--; + } + + from_next = from; + to_next = to; + return len ? std::codecvt<InternT, char, StateT>::error : + (from_next == from_end ? std::codecvt<InternT, char, StateT>::ok + : std::codecvt<InternT, char, StateT>::partial); + } + + virtual int + do_encoding() const throw() + { + return width; + } + + virtual int + do_length(StateT&, const extern_type* from, + const extern_type* end, size_t max) const + { + size_t len = std::min(max, static_cast<size_t>(end - from) / width); + + int ret = 0; + while (len--) + { + unsigned char checksum = 0; + + for (size_t i = 0; i < sizeof(intern_type); ++i) + { + checksum ^= static_cast<unsigned char>(*from++); + } + + if (*from++ != checksum) + break; + + ret++; + } + + return ret; + } + + virtual int + do_max_length() const throw() + { + return width; + } + + virtual bool + do_always_noconv() const throw() + { + return false; + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc; + loc = locale(loc, new checksumcvt<wchar_t>); + + wfilebuf fbuf1; + fbuf1.pubimbue(loc); + fbuf1.open("tmp_9178", ios_base::out | ios_base::trunc); + + string tmpstr = "abcdefghijklmnopqrstuvwxyz0123456789 \t\n"; + + wifstream stream; + wstring str1; + + while (str1.length() < 20000) + { + transform(tmpstr.begin(), tmpstr.end(), + back_inserter(str1), + bind1st(std::mem_fun(&std::wios::widen), &stream)); + } + + fbuf1.sputn(str1.data(), str1.size()); + fbuf1.close(); + + wfilebuf fbuf2; + fbuf2.pubimbue(loc); + fbuf2.open("tmp_9178", std::ios_base::in); + + wstring str2; + copy(istreambuf_iterator<wchar_t>(&fbuf2), + istreambuf_iterator<wchar_t>(), + back_inserter(str2)); + + VERIFY( str1 == str2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc new file mode 100644 index 000000000..f791b86aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/wchar_t/9520.cc @@ -0,0 +1,61 @@ +// { dg-require-namedlocale "de_DE.ISO-8859-15@euro" } + +// 2003-05-03 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <testsuite_hooks.h> +#include <fstream> +#include <cstdio> + +// libstdc++/9520 +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_9520"; + + FILE* file = fopen(name, "w"); + for (int i = 1; i < 256; ++i) + putc(static_cast<unsigned char>(i), file); + fclose(file); + + locale loc (locale("de_DE.ISO-8859-15@euro")); + wchar_t buf[1]; + wfilebuf fb; + fb.pubimbue(loc); + fb.pubsetbuf(buf, 1); + fb.open(name, ios_base::in); + + for (int j = 1; j < 256; ++j) + { + wfilebuf::int_type c1 = fb.sgetc(); + VERIFY( c1 != wfilebuf::traits_type::eof() ); + wfilebuf::int_type c2 = fb.sbumpc(); + VERIFY( c1 == c2 ); + } + + fb.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/1.cc new file mode 100644 index 000000000..dd2bb077b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/1.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_fstream<__gnu_test::pod_ushort> gnu_fstr; + + try + { + gnu_fstr obj; + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/1.cc new file mode 100644 index 000000000..34d4a1695 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/cons/char/1.cc @@ -0,0 +1,27 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +void test01() +{ + const std::string name = "fstream_name.txt"; + std::fstream fs(name); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/1.cc new file mode 100644 index 000000000..d3bc11a2c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/open/char/1.cc @@ -0,0 +1,31 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +void test01() +{ + std::fstream fs; + + const std::string name = "fstream_name.txt"; + fs.open(name); + + fs.close(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..396fbcf68 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/rdbuf/char/2832.cc @@ -0,0 +1,68 @@ +// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 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.13 member functions (fstream_members) + +#include <fstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::filebuf fbuf; + std::streambuf* pbasebuf0 = &fbuf; + + std::fstream sstrm1; + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::filebuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &fbuf); + std::filebuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/base_classes.cc new file mode 100644 index 000000000..b9e0b3f55 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// 2003-03-26 Benjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <iostream> +#include <fstream> + +void test01() +{ + // Check for required base class. + typedef std::fstream test_type; + typedef std::iostream base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..24b1f2917 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/explicit_instantiation.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2004, 2005, 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.11 - Template class basic_fstream +// NB: This file is for testing basic_fstream with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_fstream<type_t, char_traits<type_t> >; + template class basic_fstream<pod_char, char_traits<pod_char> >; +} // test + diff --git a/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/typedefs.cc new file mode 100644 index 000000000..3fc6a93dd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_fstream/requirements/typedefs.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.8.1.11 - Template class basic_fstream +// NB: This file is for testing basic_fstream with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::fstream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/2020.cc new file mode 100644 index 000000000..be8945b34 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_ifstream<__gnu_test::pod_ushort> gnu_ifstr; + + try + { + gnu_ifstr obj; + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/1.cc new file mode 100644 index 000000000..932810171 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/1.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2000, 2001, 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.7 ifstream member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "ifstream_members-1.tst"; + +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00004.html +void test02() +{ + bool test __attribute__((unused)) = true; + const int more_than_max_open_files = 8200; + + for (int i = 0; ++i < more_than_max_open_files;) + { + std::ifstream ifs(name_01); + VERIFY( static_cast<bool>(ifs) ); + } +} + +int main() +{ + test02(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/2.cc new file mode 100644 index 000000000..062a6c301 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/cons/char/2.cc @@ -0,0 +1,27 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +void test01() +{ + const std::string name = "ifstream_name.txt"; + std::ifstream ifs(name); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc new file mode 100644 index 000000000..aaf5787e1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/1.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2000, 2001, 2003, 2005, 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.7 ifstream member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "ifstream_members-1.tst"; + +// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00136.html +void test01() +{ + bool test __attribute__((unused)) = true; + std::ifstream ifs1; + ifs1.close(); + + // false as expected: + VERIFY( !ifs1.is_open() ); + // this is now true: + VERIFY( !(ifs1) ); + + ifs1.open(name_01); + VERIFY( ifs1.is_open() ); + + // As per the resolution of DR 409. + VERIFY( (ifs1) ); + VERIFY( ifs1.rdstate() == std::ios_base::goodbit ); + + ifs1.close(); +} + +int main() +{ + test01(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/2.cc new file mode 100644 index 000000000..13d79984c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/open/char/2.cc @@ -0,0 +1,31 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +void test01() +{ + std::ifstream ifs; + + const std::string name = "ifstream_name.txt"; + ifs.open(name); + + ifs.close(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..c8556eedc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/rdbuf/char/2832.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2000, 2001, 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.7 ifstream member functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "ifstream_members-1.tst"; +const char name_02[] = "ifstream_members-1.txt"; + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test03() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::filebuf fbuf; + std::streambuf* pbasebuf0 = &fbuf; + + std::ifstream sstrm1; + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::filebuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &fbuf); + std::filebuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test03(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/base_classes.cc new file mode 100644 index 000000000..467b5c3e2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <istream> +#include <fstream> + +void test01() +{ + // Check for required base class. + typedef std::ifstream test_type; + typedef std::istream base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..689b2c347 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.8.1.5 - Template class basic_ifstream +// NB: This file is for testing basic_ifstream with NO OTHER INCLUDES. + +#include <fstream> + +namespace std +{ + typedef short type_t; + template class basic_ifstream<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/typedefs.cc new file mode 100644 index 000000000..d3a925f76 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ifstream/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.5 - Template class basic_ifstream +// NB: This file is for testing basic_ifstream with NO OTHER INCLUDES. + +#include <fstream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::ifstream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/clear/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/clear/char/1.cc new file mode 100644 index 000000000..b65d08900 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/clear/char/1.cc @@ -0,0 +1,68 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 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.4.4.2 basic_ios member functions + +// NB: Don't include any other headers in this file. +#include <ios> +#include <testsuite_hooks.h> + +// 27.4.4.3 basic_ios iostate flags function +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::ios_base::fmtflags fmtflags; + typedef std::ios_base::iostate iostate; + using std::ios_base; + + iostate iostate02, iostate03; + const iostate iostate01 = std::ios_base::badbit | std::ios_base::eofbit; + std::ios ios_01(0); + + // bool fail() const + VERIFY( ios_01.fail() ); + + // bool operator!() const + VERIFY( !ios_01 ); + + // iostate rdstate() const + iostate03 = ios_01.rdstate(); + VERIFY( static_cast<bool>(iostate03 & std::ios_base::badbit) ); + + // void clear(iostate state = goodbit) + try { + ios_01.clear(std::ios_base::eofbit); + iostate02 = ios_01.rdstate(); + VERIFY( static_cast<bool>(iostate02 & iostate01) ); + } + catch(std::ios_base::failure& fail) { + VERIFY( false ); + } + catch(...) { + VERIFY( false ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_ios/cons/2020.cc new file mode 100644 index 000000000..31f712166 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <ios> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +class gnu_ios: public std::basic_ios<__gnu_test::pod_ushort> +{ }; + +void test07() +{ + bool test __attribute__((unused)) = true; + + try + { gnu_ios obj; } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/1.cc new file mode 100644 index 000000000..0796ecfa5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/1.cc @@ -0,0 +1,79 @@ +// 1999-07-23 bkoz + +// Copyright (C) 1999, 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.4.4.1 basic_ios constructors + +#include <ios> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::string str_01("jade cove, big sur"); + std::string str_05; + std::stringbuf strb_01; + std::stringbuf strb_02(str_01, std::ios_base::in); + std::stringbuf strb_03(str_01, std::ios_base::out); + const std::ios_base::fmtflags flag01 = std::ios_base::skipws | + std::ios_base::dec; + std::ios_base::fmtflags flag02; + const std::locale glocale = std::locale(); + + // explicit basic_ios(streambuf* sb) + std::ios ios_00(0); + std::ios ios_01(&strb_01); + std::ios ios_02(&strb_02); + std::ios ios_03(&strb_03); + + // basic_ios() + // NB: This is protected so need to go through fstream + + // void init(sreambuf* sb) + // NB: This is protected so need to go through fstream/stringstream + // Can double-check the accuracy of the above initializations though. + VERIFY( ios_00.rdbuf() == 0 ); + VERIFY( ios_00.tie() == 0 ); + VERIFY( ios_00.rdstate() == std::ios_base::badbit ); + VERIFY( ios_00.exceptions() == std::ios_base::goodbit ); + flag02 = ios_00.flags(); + VERIFY( flag02 == flag01 ); + VERIFY( ios_00.width() == 0 ); + VERIFY( ios_00.precision() == 6 ); + VERIFY( ios_00.fill() == ios_00.widen(' ') ); + VERIFY( ios_00.getloc() == glocale ); + + VERIFY( ios_01.rdbuf() == &strb_01 ); + VERIFY( ios_01.tie() == 0 ); + VERIFY( ios_01.rdstate() == std::ios_base::goodbit ); + VERIFY( ios_01.exceptions() == std::ios_base::goodbit ); + flag02 = ios_01.flags(); + VERIFY( flag02 == flag01 ); + VERIFY( ios_01.width() == 0 ); + VERIFY( ios_01.precision() == 6 ); + VERIFY( ios_01.fill() == ios_01.widen(' ') ); + VERIFY( ios_01.getloc() == glocale ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/2.cc new file mode 100644 index 000000000..d498936f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/2.cc @@ -0,0 +1,52 @@ +// 2001-06-05 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.4.2.1.6 class ios_base::init + +#include <ios> +#include <testsuite_hooks.h> + +// Non-required instantiations don't have the required facets inbued, +// by default, into the locale object. +// See 27.4.4.1 +class gnu_ios: public std::basic_ios<char> { }; + +void test01() +{ + bool test __attribute__((unused)) = true; + + // 01: Doesn't call basic_ios::init, which uses ctype<char_type>.. + // This should be unambiguously correct. + try + { + gnu_ios gios; + } + catch(...) + { + test = false; + } + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/3.cc new file mode 100644 index 000000000..bcbe8b737 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/cons/char/3.cc @@ -0,0 +1,169 @@ +// 2001-06-05 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + + +// 27.4.2.1.6 class ios_base::init + +#include <sstream> +#include <typeinfo> +#include <cstring> +#include <testsuite_hooks.h> + +// char_traits specialization +namespace std +{ + template<> + struct char_traits<unsigned short> + { + typedef unsigned short char_type; + // Unsigned as wint_t in unsigned. + typedef unsigned long int_type; + typedef streampos pos_type; + typedef streamoff off_type; + typedef mbstate_t state_type; + + static void + assign(char_type& __c1, const char_type& __c2) + { __c1 = __c2; } + + static bool + eq(const char_type& __c1, const char_type& __c2) + { return __c1 == __c2; } + + static bool + lt(const char_type& __c1, const char_type& __c2) + { return __c1 < __c2; } + + static int + compare(const char_type* __s1, const char_type* __s2, size_t __n) + { + for (size_t __i = 0; __i < __n; ++__i) + if (!eq(__s1[__i], __s2[__i])) + return lt(__s1[__i], __s2[__i]) ? -1 : 1; + return 0; + } + + static size_t + length(const char_type* __s) + { + const char_type* __p = __s; + while (__p) + ++__p; + return (__p - __s); + } + + static const char_type* + find(const char_type* __s, size_t __n, const char_type& __a) + { + for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) + if (*__p == __a) return __p; + return 0; + } + + static char_type* + move(char_type* __s1, const char_type* __s2, size_t __n) + { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } + + static char_type* + copy(char_type* __s1, const char_type* __s2, size_t __n) + { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } + + static char_type* + assign(char_type* __s, size_t __n, char_type __a) + { + for (char_type* __p = __s; __p < __s + __n; ++__p) + assign(*__p, __a); + return __s; + } + + static char_type + to_char_type(const int_type&) + { return char_type(); } + + static int_type + to_int_type(const char_type&) { return int_type(); } + + static bool + eq_int_type(const int_type& __c1, const int_type& __c2) + { return __c1 == __c2; } + + static int_type + eof() { return static_cast<int_type>(-1); } + + static int_type + not_eof(const int_type& __c) + { return eq_int_type(__c, eof()) ? int_type(0) : __c; } + }; +} // namespace std + +// Non-required instantiations don't have the required facets inbued, +// by default, into the locale object. +// See 27.4.4.1 + +void test02() +{ + bool test __attribute__((unused)) = true; + + // 02: Calls basic_ios::init, which may call ctype<char_type>... + try + { + std::basic_string<unsigned short> str; + std::basic_ostringstream<unsigned short> oss(str); + + // Try each member functions for unformatted io. + // put + oss.put(324); + + // write + const unsigned short us[4] = {1246, 433, 520, 0}; + oss.write(us, 4); + + // flush + oss.flush(); + } + catch(const std::bad_cast& obj) + { + // Should be able to do the above without calling fill() and + // forcing a call to widen... + test = false; + } + catch(...) + { + test = false; + } + VERIFY( test ); +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<unsigned short>::size_type + std::basic_string<unsigned short>::_Rep::_S_max_size; + +template + const unsigned short + std::basic_string<unsigned short>::_Rep::_S_terminal; +#endif + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc new file mode 100644 index 000000000..0cf07f212 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/1.cc @@ -0,0 +1,74 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 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.4.4.2 basic_ios member functions + +// NB: Don't include any other headers in this file. +#include <ios> +#include <testsuite_hooks.h> + +// 27.4.4.3 basic_ios iostate flags function +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::ios_base::fmtflags fmtflags; + typedef std::ios_base::iostate iostate; + using std::ios_base; + + // basic_ios& copyfmt(const basic_ios& rhs) + { + std::ios ios_01(0); + std::ios ios_02(0); + ios_01.exceptions(std::ios_base::eofbit); + ios_02.exceptions(std::ios_base::eofbit); + + try { + ios_01.copyfmt(ios_02); + } + catch(...) { + VERIFY( false ); + } + } + + { + std::ios ios_01(0); + std::ios ios_02(0); + ios_01.clear(std::ios_base::eofbit); + ios_02.exceptions(std::ios_base::eofbit); + + try { + ios_01.copyfmt(ios_02); + VERIFY( false ); + } + catch(std::ios_base::failure& fail) { + VERIFY( true ); + } + catch(...) { + VERIFY( false ); + } + } +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/2.cc new file mode 100644 index 000000000..2f3fa49da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/copyfmt/char/2.cc @@ -0,0 +1,66 @@ +// { dg-require-namedlocale "de_DE" } + +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2003, 2005, 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.4.4.2 basic_ios member functions + +// NB: Don't include any other headers in this file. +#include <ios> +#include <testsuite_hooks.h> + +// copyfmt and locales. +void test03() +{ + bool test __attribute__((unused)) = true; + + using namespace std; + + typedef std::ios_base::fmtflags fmtflags; + typedef std::ios_base::iostate iostate; + locale loc_c = locale::classic(); + locale loc_de = locale("de_DE"); + std::ios ios_01(0); + std::ios ios_02(0); + ios_01.imbue(loc_c); + ios_02.imbue(loc_de); + ios_02.setstate(ios_base::badbit); + VERIFY( loc_c == ios_01.getloc() ); + VERIFY( loc_de == ios_02.getloc() ); + + iostate ios1 = ios_01.rdstate(); + iostate ios2 = ios_02.rdstate(); + streambuf* sb1 = ios_01.rdbuf(); + streambuf* sb2 = ios_02.rdbuf(); + ios_01.copyfmt(ios_02); + + VERIFY( loc_de == ios_01.getloc() ); + VERIFY( ios_01.getloc() == ios_02.getloc() ); + VERIFY( ios1 == ios_01.rdstate() ); + VERIFY( ios2 == ios_02.rdstate() ); + VERIFY( sb1 == ios_01.rdbuf() ); + VERIFY( sb2 == ios_02.rdbuf() ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc new file mode 100644 index 000000000..f0494bd45 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/1.cc @@ -0,0 +1,76 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 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.4.4.2 basic_ios member functions + +// NB: Don't include any other headers in this file. +#include <ios> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::ios_base::fmtflags fmtflags; + typedef std::ios_base::iostate iostate; + using std::ios_base; + + // iostate exceptions() const + iostate iostate02; + { + std::ios ios_01(0); + VERIFY( ios_01.exceptions() == std::ios_base::goodbit ); + } + + // void exceptions(iostate except) + { + std::ios ios_01(0); + try { + ios_01.exceptions(std::ios_base::eofbit); + } + catch(...) { + VERIFY( false ); + } + iostate02 = ios_01.exceptions(); + VERIFY( static_cast<bool>(iostate02 & std::ios_base::eofbit) ); + } + + { + std::ios ios_01(0); + ios_01.clear(std::ios_base::eofbit); + try { + ios_01.exceptions(std::ios_base::eofbit); + VERIFY( false ); + } + catch(std::ios_base::failure& fail) { + iostate02 = ios_01.exceptions(); + VERIFY( static_cast<bool>(iostate02 & std::ios_base::eofbit) ); + } + catch(...) { + VERIFY( false ); + } + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc new file mode 100644 index 000000000..11b7d76df --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/exceptions/char/2.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.4.4.2 basic_ios member functions + +#include <sstream> +#include <testsuite_hooks.h> + +int main() +{ + using namespace std; + ostringstream stream; + + try + { + stream.setstate(ios_base::failbit); + stream.exceptions(ios_base::failbit); + VERIFY( false ); + } + catch (...) + { + // Don't clear. + } + + try + { + // Calls clear(rdstate()), which throws in this case. + stream.setstate(ios_base::goodbit); + VERIFY( false ); + } + catch (...) + { } + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/imbue/14072.cc b/libstdc++-v3/testsuite/27_io/basic_ios/imbue/14072.cc new file mode 100644 index 000000000..823d620f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/imbue/14072.cc @@ -0,0 +1,83 @@ +// 2004-02-09 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2005, 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/>. + + +// 27.4.4.2 basic_ios member functions + +#include <sstream> +#include <locale> +#include <typeinfo> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/14072 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + locale loc; + loc = locale(loc, new ctype<__gnu_test::pod_uchar>()); + loc = locale(loc, new num_get<__gnu_test::pod_uchar>()); + loc = locale(loc, new num_put<__gnu_test::pod_uchar>()); + + locale::global(loc); + basic_stringstream<__gnu_test::pod_uchar> s; + s << "10\n"; + s.seekg(0, ios_base::beg); + s.imbue(locale::classic()); + locale::global(locale::classic()); + loc = locale::classic(); + + try + { + s.widen('\0'); + } + catch (bad_cast&) + { + } + + s.clear(); + + try + { + int i = 0; + s << i; + } + catch (bad_cast&) + { + } + + s.clear(); + + try + { + int i = 0; + s >> i; + } + catch (bad_cast&) + { + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/locales/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ios/locales/char/1.cc new file mode 100644 index 000000000..20de8a957 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/locales/char/1.cc @@ -0,0 +1,52 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 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.4.4.2 basic_ios member functions + +// NB: Don't include any other headers in this file. +#include <ios> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + const std::locale c_loc = std::locale::classic(); + + std::ios ios_01(0); + std::ios::char_type ct01; + std::ios::char_type ct02('x');; + + // 27.4.2.3 locales + ios_01.imbue(c_loc); + + // char narrow(char_type c, char dfault) const; + char c1 = ios_01.narrow(ct02, 0); + VERIFY( c1 == 'x' ); + + // char_type widen(char c) const; + ct01 = ios_01.widen('c'); + VERIFY( ct01 == 'c' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_ios/requirements/base_classes.cc new file mode 100644 index 000000000..7f2859753 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/requirements/base_classes.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// 2003-03-26 Benjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <ios> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::ios test_type; + typedef std::ios_base base_type; + + std::stringbuf buf; + const test_type& obj = *new test_type(&buf); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_ios/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..831370805 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.4.4 - Template class basic_ios +// NB: This file is for testing basic_ios with NO OTHER INCLUDES. + +#include <ios> + +namespace std +{ + typedef short type_t; + template class basic_ios<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_ios/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_ios/requirements/typedefs.cc new file mode 100644 index 000000000..093de91b2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ios/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.4.4 - Template class basic_ios +// NB: This file is for testing basic_ios with NO OTHER INCLUDES. + +#include <ios> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::ios test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_iostream/cons/16251.C b/libstdc++-v3/testsuite/27_io/basic_iostream/cons/16251.C new file mode 100644 index 000000000..3e86c43d9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_iostream/cons/16251.C @@ -0,0 +1,41 @@ +// Copyright (C) 2008, 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.6.1.5 - Template class basic_iostream + +#include <iostream> + +class mystream +: public std::iostream +{ +public: + mystream () { }; +}; + +// libstdc++/16251 +void test01() +{ + mystream x; + x.rdbuf(std::cout.rdbuf()); + x << std::endl; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_iostream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_iostream/cons/2020.cc new file mode 100644 index 000000000..44fe41323 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_iostream/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 2008, 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.6.1.5 - Template class basic_iostream + +#include <iostream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_iostream<__gnu_test::pod_ushort> gnu_iostr; + + try + { + gnu_iostr obj(0); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/base_classes.cc new file mode 100644 index 000000000..bd3bd81d4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/base_classes.cc @@ -0,0 +1,48 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <iostream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::iostream test_type; + typedef std::istream base_type1; + typedef std::ostream base_type2; + + std::stringbuf buf; + const test_type& obj = *new test_type(&buf); + const base_type1* base1 __attribute__((unused)) = &obj; + const base_type2* base2 __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..2622d9a7f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-01-08 bkoz + +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.5 - Template class basic_iostream +// NB: This file is for testing iostream with NO OTHER INCLUDES. + +#include <istream> + +namespace std +{ + typedef short type_t; + template class basic_iostream<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/typedefs.cc new file mode 100644 index 000000000..35f76abcf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_iostream/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-01-08 bkoz + +// Copyright (C) 2002, 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.6.1.5 - Template class basic_iostream +// NB: This file is for testing iostream with NO OTHER INCLUDES. + +#include <istream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::iostream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/cons/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/cons/3.cc new file mode 100644 index 000000000..3b2cb845e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/cons/3.cc @@ -0,0 +1,53 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, +// 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <istream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_istream<__gnu_test::pod_ushort> gnu_istr; + + try + { gnu_istr obj(0); } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc new file mode 100644 index 000000000..3c8b37952 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/char/9561.cc @@ -0,0 +1,60 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// 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/>. + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_streambuf b; + std::istream strm (&b); + strm.exceptions (std::ios::badbit); + int i = 0; + + try + { + i = strm.get(); + i = strm.get(); + i = strm.get(); + } + catch (__gnu_test::underflow_error&) + { + // strm should throw facet_error and not do anything else + VERIFY(strm.bad()); + } + catch (...) + { + VERIFY(false); + } + + VERIFY(i == 's'); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/wchar_t/9561.cc b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/wchar_t/9561.cc new file mode 100644 index 000000000..a05228411 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/exceptions/wchar_t/9561.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_wstreambuf b; + std::wistream strm (&b); + strm.exceptions (std::wios::badbit); + wchar_t i = 0; + + try + { + i = strm.get(); + i = strm.get(); + i = strm.get(); + } + catch (__gnu_test::underflow_error&) + { + // strm should throw facet_error and not do anything else + VERIFY(strm.bad()); + } + catch (...) + { + VERIFY( false ); + } + + VERIFY( i == L's' ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc new file mode 100644 index 000000000..a8d91695b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/01.cc @@ -0,0 +1,123 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 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.6.1.2.2 arithmetic extractors + +#include <cstdio> // for printf +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +std::string str_01; +std::string str_02("true false 0 1 110001"); +std::string str_03("-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"); +std::string str_04("0123"); + +std::stringbuf isbuf_01(std::ios_base::in); +std::stringbuf isbuf_02(str_02, std::ios_base::in); +std::stringbuf isbuf_03(str_03, std::ios_base::in); +std::stringbuf isbuf_04(str_04, std::ios_base::in); + +std::istream is_01(0); +std::istream is_02(&isbuf_02); +std::istream is_03(&isbuf_03); +std::istream is_04(&isbuf_04); +std::stringstream ss_01(str_01); + +// minimal sanity check +bool test01() { + + bool test __attribute__((unused)) = true; + + // Integral Types: + bool b1 = false; + short s1 = 0; + int i1 = 0; + long l1 = 0; + unsigned short us1 = 0; + unsigned int ui1 = 0; + unsigned long ul1 = 0; + + // Floating-point Types: + float f1 = 0; + double d1 = 0; + long double ld1 = 0; + + // process alphanumeric versions of bool values + is_02.setf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 1 ); + is_02 >> b1; + VERIFY( b1 == 0 ); + + // process numeric versions of of bool values + is_02.unsetf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 0 ); + is_02 >> b1; + VERIFY( b1 == 1 ); + + // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5" + is_03 >> l1; + VERIFY( l1 == -19999999 ); + is_03 >> ul1; + VERIFY( ul1 == 777777 ); + is_03 >> i1; + VERIFY( i1 == -234234 ); + is_03 >> ui1; + VERIFY( ui1 == 233 ); + is_03 >> s1; + VERIFY( s1 == -234 ); + is_03 >> us1; + VERIFY( us1 == 33 ); + is_03 >> b1; + VERIFY( b1 == 1 ); + is_03 >> ld1; + VERIFY( ld1 == 66300.25 ); + is_03 >> d1; + VERIFY( d1 == .315 ); + is_03 >> f1; + VERIFY( f1 == 1.5 ); + + is_04 >> std::hex >> i1; + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + VERIFY( i1 == 0x123 ); + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + + // test void pointers + int i = 55; + void* po = &i; + void* pi; + + ss_01 << po; + ss_01 >> pi; + std::printf ("%p %p\n", pi, po); + VERIFY( po == pi ); + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc new file mode 100644 index 000000000..3c82f3b91 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/02.cc @@ -0,0 +1,47 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +// elaborated test for ints +bool test02() +{ + bool test __attribute__((unused)) = true; + const std::string str_01("20000AB"); + std::stringbuf strb_01(str_01, std::ios_base::in); + std::istream is(&strb_01); + + int n = 15; + is >> n; + VERIFY( n == 20000 ); + char c = is.peek(); + VERIFY( c == 65 ); + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc new file mode 100644 index 000000000..a2d983573 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/03.cc @@ -0,0 +1,46 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +bool test03() +{ + std::stringbuf sbuf; + std::istream istr(&sbuf); + std::ostream ostr(&sbuf); + + bool test __attribute__((unused)) = true; + long l01; + ostr << "12220101"; + istr >> l01; // _M_in_end set completely incorrectly here. + VERIFY( l01 == 12220101 ); + VERIFY( istr.rdstate() == std::ios_base::eofbit ); + return test; +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc new file mode 100644 index 000000000..bfe7042f3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/06.cc @@ -0,0 +1,60 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00081.html +// Jim Parsons +void test06() +{ + // default locale, grouping is turned off + bool test __attribute__((unused)) = true; + unsigned int h4; + char c; + std::string s("205,199,144"); + std::istringstream is(s); + + is >> h4; // 205 + VERIFY( h4 == 205 ); + is >> c; // ',' + VERIFY( c == ',' ); + + is >> h4; // 199 + VERIFY( h4 == 199 ); + is >> c; // ',' + VERIFY( c == ',' ); + + is >> h4; // 144 + VERIFY( is.rdstate() == std::ios_base::eofbit ); + VERIFY( h4 == 144 ); + is >> c; // EOF + VERIFY( c == ',' ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc new file mode 100644 index 000000000..45975870c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/07.cc @@ -0,0 +1,148 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +namespace std { + class test_numpunct1 : public numpunct<char> + { + protected: + string + do_grouping() const + { return string(1, '\003'); } + }; +} // namespace std + +void test07() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + float f1 = 0.0; + const std::string s1("205,199 23,445.25 1,024,365 123,22,24"); + std::istringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct1)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 205199 ); + VERIFY( is.good() ); + + is.clear(); + is >> f1; + VERIFY( f1 == 23445.25 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 1024365 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 1232224 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); + + // Stress tests for explicit errors in grouping corner cases. The + // validity of these tests and results have been hammered out in + // private email between bkoz and ncm between Jan 25 and Jan 27, 2000. + // Thanks nate -- benjamin + const std::string s2(",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567"); + h3 = h4 = h2 = 0; + f1 = 0.0; + const char c_control = '?'; + char c = c_control; + is.clear(); + is.str(s2); + + is >> h4; + VERIFY( h4 == 0 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == ',' ); + VERIFY( is.good() ); + + is.ignore(3); + is >> f1; + VERIFY( f1 == 0.0 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == ',' ); + is >> c; + VERIFY( c == '4' ); + VERIFY( is.good() ); + + is >> f1; + VERIFY( f1 == 0.25 ); + VERIFY( is.good() ); + is >> c; + VERIFY( c == ',' ); + is >> h2; + VERIFY( h2 == 345 ); + VERIFY( is.good() ); + f1 = 0.0; + h2 = 0; + + is >> f1; + VERIFY( f1 == 5.0 ); + VERIFY( is.good() ); + is >> f1; + VERIFY( f1 == .25 ); + VERIFY( is.good() ); + + is >> h3; + VERIFY( h3 == 0 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == ',' ); // second one + VERIFY( is.good() ); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + h2 = 0; + is.clear(); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( is.good() ); + h2 = 0; + + is >> h2; + VERIFY( h2 == 1234567 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); + is.clear(); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc new file mode 100644 index 000000000..99c017aa5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/08.cc @@ -0,0 +1,67 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +namespace std { + class test_numpunct2 : public numpunct<char> + { + protected: + string + do_grouping() const + { return string("\002\003"); } + }; +} // namespace std + +void test08() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + const std::string s1("1,22 205,19 22,123,22"); + + std::istringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct2)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 122 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 20519 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 2212322 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc new file mode 100644 index 000000000..bf64448bf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/09.cc @@ -0,0 +1,51 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 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.6.1.2.2 arithmetic extractors + +// { dg-do run { xfail lax_strtofp } } + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +bool test09() +{ + bool test __attribute__((unused)) = true; + + std::string st("2.456e3-+0.567e-2"); + std::stringbuf sb(st); + std::istream is(&sb); + double f1 = 0, f2 = 0; + char c; + (is>>std::ws) >> f1; + (is>>std::ws) >> c; + (is>>std::ws) >> f2; + test = f1 == 2456; + VERIFY( f2 == 0.00567 ); + VERIFY( c == '-' ); + return test; +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc new file mode 100644 index 000000000..bd7241b38 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/10.cc @@ -0,0 +1,134 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, +// 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +bool test10() +{ + std::string str_01("0 00 000 +0 +0 -0"); + std::stringbuf isbuf_01(str_01); + std::istream is_01(&isbuf_01); + + bool test __attribute__((unused)) = true; + + int n = 365; + is_01 >> n; + VERIFY( n == 0 ); + n = 364; + is_01 >> n; + VERIFY( n == 0 ); + n = 363; + is_01 >> n; + VERIFY( n == 0 ); + n = 362; + is_01 >> n; + VERIFY( n == 0 ); + n = 361; + is_01 >> n; + VERIFY( n == 0 ); + n = 360; + is_01 >> n; + VERIFY( n == 0 ); + VERIFY( is_01.rdstate() == std::ios_base::eofbit ); + + std::string str_02("0x32 0X33 033 33"); + std::stringbuf isbuf_02(str_02); + std::istream is_02(&isbuf_02); + is_02.unsetf(std::ios_base::basefield); + is_02 >> n; + VERIFY( n == 50 ); + is_02 >> n; + VERIFY( n == 51 ); + is_02 >> n; + VERIFY( n == 27 ); + is_02 >> n; + VERIFY( n == 33 ); + VERIFY( is_02.rdstate() == std::ios_base::eofbit ); + + std::stringbuf isbuf_03(str_02); + std::istream is_03(&isbuf_03); + char c; + int m; + + is_03 >> std::dec >> n >> c >> m; + VERIFY( n == 0 ); + VERIFY( c == 'x' ); + VERIFY( m == 32 ); + + is_03 >> std::oct >> m >> c >> n; + VERIFY( m == 0 ); + VERIFY( c == 'X' ); + VERIFY( n == 27 ); + + is_03 >> std::dec >> m >> n; + VERIFY( m == 33 ); + VERIFY( n == 33 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::string str_04("3. 4.5E+2a5E-3 .6E1"); + std::stringbuf isbuf_04(str_04); + std::istream is_04(&isbuf_04); + + double f; + is_04 >> f; + VERIFY( f == 3.0 ); + is_04 >> f; + VERIFY( f == 450.0 ); + is_04.ignore(); + is_04 >> f; + VERIFY( f == 0.005 ); + is_04 >> f; + VERIFY( f == 6 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::string str_05("0E20 5Ea E16"); + std::stringbuf isbuf_05(str_05); + std::istream is_05(&isbuf_05); + + is_05 >> f; + VERIFY( f == 0 ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05 >> c; + VERIFY( c == 'a' ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05.ignore(); + is_05 >> n; + VERIFY( n == 16 ); + return test; +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc new file mode 100644 index 000000000..cffb39a76 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/11.cc @@ -0,0 +1,56 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <cstdlib> +#include <testsuite_hooks.h> + +// In the presence of no fmtflags, the input operator should behave +// like strtol(x, y, 0) +// libstdc++/90 +bool test11() +{ + bool test __attribute__((unused)) = true; + const char* cstrlit = "0x2a"; + + // sanity check via 'C' library call + char* err; + long l = std::strtol(cstrlit, &err, 0); + + std::istringstream iss(cstrlit); + iss.setf(std::ios::fmtflags(0), std::ios::basefield); + int i; + iss >> i; + + VERIFY (!iss.fail()); + VERIFY (l == i); + + return test; +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc new file mode 100644 index 000000000..70f74fd7a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/12.cc @@ -0,0 +1,77 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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.6.1.2.2 arithmetic extractors + +// XXX This test fails on Solaris 8 and 9 because of a bug in libc +// XXX sscanf for very long input. See: +// XXX http://gcc.gnu.org/ml/gcc/2002-12/msg01422.html +// { dg-do run { xfail { { *-*-solaris2.[89] } || lax_strtofp } } } + +#include <istream> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/3720 +// excess input should not cause a core dump +template<typename T> +bool test12_aux(bool integer_type) +{ + bool test __attribute__((unused)) = true; + + int digits_overflow; + if (integer_type) + // This many digits will overflow integer types in base 10. + digits_overflow = std::numeric_limits<T>::digits10 + 2; + else + // This might do it, unsure. + digits_overflow = std::numeric_limits<T>::max_exponent10 + 1; + + std::string st; + std::string part = "1234567890123456789012345678901234567890"; + for (std::size_t i = 0; i < digits_overflow / part.size() + 1; ++i) + st += part; + std::stringbuf sb(st); + std::istream is(&sb); + T t; + is >> t; + VERIFY(is.fail()); + return test; +} + +bool test12() +{ + bool test __attribute__((unused)) = true; + VERIFY(test12_aux<short>(true)); + VERIFY(test12_aux<int>(true)); + VERIFY(test12_aux<long>(true)); + VERIFY(test12_aux<float>(false)); + VERIFY(test12_aux<double>(false)); + VERIFY(test12_aux<long double>(false)); + return test; +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc new file mode 100644 index 000000000..ac5533a49 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/13.cc @@ -0,0 +1,70 @@ +// 1999-04-12 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/3720 part two +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const char* l2 = "1.2345678901234567890123456789012345678901234567890123456" + " " + "1246.9"; + + // 1 + // used to core. + double d; + istringstream iss1(l2); + iss1 >> d; + iss1 >> d; + VERIFY (d > 1246 && d < 1247); + + // 2 + // quick test for failbit on maximum length extraction. + int i; + int max_digits = numeric_limits<int>::digits10 + 1; + string digits; + for (int j = 0; j < max_digits; ++j) + digits += '1'; + istringstream iss2(digits); + iss2 >> i; + VERIFY( !iss2.fail() ); + + digits += '1'; + i = 0; + iss2.str(digits); + iss2.clear(); + iss2 >> i; + VERIFY( i == numeric_limits<int>::max() ); + VERIFY( iss2.fail() ); +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc new file mode 100644 index 000000000..44a695def --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/9555-ia.cc @@ -0,0 +1,77 @@ +// 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/>. + + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::istream is(&b); + is.exceptions(std::ios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc new file mode 100644 index 000000000..a1a71cc57 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/dr696.cc @@ -0,0 +1,101 @@ +// 2009-07-15 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 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.6.1.2.2 arithmetic extractors + +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// DR 696. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + short s1 = 0; + ostringstream oss1; + oss1 << numeric_limits<short>::max(); + istringstream iss1(oss1.str()); + iss1 >> s1; + VERIFY( s1 == numeric_limits<short>::max() ); + VERIFY( !iss1.fail() && iss1.eof() ); + + short s2 = 0; + ostringstream oss2; + oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1; + istringstream iss2(oss2.str()); + iss2 >> s2; + VERIFY( s2 == numeric_limits<short>::max() ); + VERIFY( iss2.fail() && iss2.eof() ); + + short s3 = 0; + ostringstream oss3; + oss3 << numeric_limits<short>::min(); + istringstream iss3(oss3.str()); + iss3 >> s3; + VERIFY( s3 == numeric_limits<short>::min() ); + VERIFY( !iss3.fail() && iss3.eof() ); + + short s4 = 0; + ostringstream oss4; + oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1; + istringstream iss4(oss4.str()); + iss4 >> s4; + VERIFY( s4 == numeric_limits<short>::min() ); + VERIFY( iss4.fail() && iss4.eof() ); + + int i1 = 0; + ostringstream oss5; + oss5 << numeric_limits<int>::max(); + istringstream iss5(oss5.str()); + iss5 >> i1; + VERIFY( i1 == numeric_limits<int>::max() ); + VERIFY( !iss5.fail() && iss5.eof() ); + + int i2 = 0; + ostringstream oss6; + oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1; + istringstream iss6(oss6.str()); + iss6 >> i2; + VERIFY( i1 == numeric_limits<int>::max() ); + VERIFY( iss6.fail() && iss6.eof() ); + + int i3 = 0; + ostringstream oss7; + oss7 << numeric_limits<int>::min(); + istringstream iss7(oss7.str()); + iss7 >> i3; + VERIFY( i3 == numeric_limits<int>::min() ); + VERIFY( !iss7.fail() && iss7.eof() ); + + int i4 = 0; + ostringstream oss8; + oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1; + istringstream iss8(oss8.str()); + iss8 >> i4; + VERIFY( i4 == numeric_limits<int>::min() ); + VERIFY( iss8.fail() && iss8.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..30bfa334a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_badbit_throw.cc @@ -0,0 +1,75 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_char); + istringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + test_badbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc new file mode 100644 index 000000000..b14647126 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit.cc @@ -0,0 +1,66 @@ +// 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/>. + + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream stream("jaylib - champion sound"); + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const ios_base::failure&) + { + // stream should set failbit and throw ios_base::failure. + VERIFY( stream.fail() ); + VERIFY( !stream.bad() ); + VERIFY( !stream.eof() ); + } + catch(...) + { VERIFY( false ); } +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + test_failbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc new file mode 100644 index 000000000..23237ccf1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/char/exceptions_failbit_throw.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_char); + istringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + test_failbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc new file mode 100644 index 000000000..311b4d410 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/pod/3983-1.cc @@ -0,0 +1,68 @@ +// 2001-06-05 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 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.4.2.1.6 class ios_base::init + +#include <sstream> +#include <typeinfo> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/3983 +// Sentry uses locale info, so have to try one formatted input/output. +void test03() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_istream<pod_ushort> istream_type; + + stringbuf_type strbuf01; + istream_type iss(&strbuf01); + + bool test __attribute__((unused)) = true; + + try + { + int i; + iss >> i; + } + catch (std::bad_cast& obj) + { } + catch (std::exception& obj) + { VERIFY( false ); } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc new file mode 100644 index 000000000..5d7ec97a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/01.cc @@ -0,0 +1,120 @@ +// Copyright (C) 2004, 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.6.1.2.2 arithmetic extractors + +#include <cstdio> // for printf +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +std::wstring str_01; +std::wstring str_02(L"true false 0 1 110001"); +std::wstring str_03(L"-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5"); +std::wstring str_04(L"0123"); + +std::wstringbuf isbuf_01(std::ios_base::in); +std::wstringbuf isbuf_02(str_02, std::ios_base::in); +std::wstringbuf isbuf_03(str_03, std::ios_base::in); +std::wstringbuf isbuf_04(str_04, std::ios_base::in); + +std::wistream is_01(0); +std::wistream is_02(&isbuf_02); +std::wistream is_03(&isbuf_03); +std::wistream is_04(&isbuf_04); +std::wstringstream ss_01(str_01); + +// minimal sanity check +bool test01() { + + bool test __attribute__((unused)) = true; + + // Integral Types: + bool b1 = false; + short s1 = 0; + int i1 = 0; + long l1 = 0; + unsigned short us1 = 0; + unsigned int ui1 = 0; + unsigned long ul1 = 0; + + // Floating-point Types: + float f1 = 0; + double d1 = 0; + long double ld1 = 0; + + // process alphanumeric versions of bool values + is_02.setf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 1 ); + is_02 >> b1; + VERIFY( b1 == 0 ); + + // process numeric versions of of bool values + is_02.unsetf(std::ios_base::boolalpha); + is_02.flags(); + is_02 >> b1; + VERIFY( b1 == 0 ); + is_02 >> b1; + VERIFY( b1 == 1 ); + + // is_03 == "-19999999 777777 -234234 233 -234 33 1 66300.25 .315 1.5" + is_03 >> l1; + VERIFY( l1 == -19999999 ); + is_03 >> ul1; + VERIFY( ul1 == 777777 ); + is_03 >> i1; + VERIFY( i1 == -234234 ); + is_03 >> ui1; + VERIFY( ui1 == 233 ); + is_03 >> s1; + VERIFY( s1 == -234 ); + is_03 >> us1; + VERIFY( us1 == 33 ); + is_03 >> b1; + VERIFY( b1 == 1 ); + is_03 >> ld1; + VERIFY( ld1 == 66300.25 ); + is_03 >> d1; + VERIFY( d1 == .315 ); + is_03 >> f1; + VERIFY( f1 == 1.5 ); + + is_04 >> std::hex >> i1; + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + VERIFY( i1 == 0x123 ); + std::printf ("%d %d %d\n", i1, i1 == 0x123, test); + + // test void pointers + int i = 55; + void* po = &i; + void* pi; + + ss_01 << po; + ss_01 >> pi; + std::printf ("%p %p\n", pi, po); + VERIFY( po == pi ); + return test; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc new file mode 100644 index 000000000..86c43afcd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/02.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +// elaborated test for ints +bool test02() +{ + bool test __attribute__((unused)) = true; + const std::wstring str_01(L"20000AB"); + std::wstringbuf strb_01(str_01, std::ios_base::in); + std::wistream is(&strb_01); + + int n = 15; + is >> n; + VERIFY( n == 20000 ); + wchar_t c = is.peek(); + VERIFY( c == L'A' ); + return test; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc new file mode 100644 index 000000000..a357814c2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/03.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +bool test03() +{ + std::wstringbuf sbuf; + std::wistream istr(&sbuf); + std::wostream ostr(&sbuf); + + bool test __attribute__((unused)) = true; + long l01; + ostr << L"12220101"; + istr >> l01; // _M_in_end set completely incorrectly here. + VERIFY( l01 == 12220101 ); + VERIFY( istr.rdstate() == std::ios_base::eofbit ); + return test; +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc new file mode 100644 index 000000000..52c25a5bd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/06.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00081.html +// Jim Parsons +void test06() +{ + // default locale, grouping is turned off + bool test __attribute__((unused)) = true; + unsigned int h4; + wchar_t c; + std::wstring s(L"205,199,144"); + std::wistringstream is(s); + + is >> h4; // 205 + VERIFY( h4 == 205 ); + is >> c; // L',' + VERIFY( c == L',' ); + + is >> h4; // 199 + VERIFY( h4 == 199 ); + is >> c; // L',' + VERIFY( c == L',' ); + + is >> h4; // 144 + VERIFY( is.rdstate() == std::ios_base::eofbit ); + VERIFY( h4 == 144 ); + is >> c; // EOF + VERIFY( c == L',' ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc new file mode 100644 index 000000000..8e56816cf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/07.cc @@ -0,0 +1,145 @@ +// Copyright (C) 2004, 2005, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +namespace std { + class test_numpunct1 : public numpunct<wchar_t> + { + protected: + string + do_grouping() const + { return string(1, '\003'); } + }; +} // namespace std + +void test07() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + float f1 = 0.0; + const std::wstring s1(L"205,199 23,445.25 1,024,365 123,22,24"); + std::wistringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct1)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 205199 ); + VERIFY( is.good() ); + + is.clear(); + is >> f1; + VERIFY( f1 == 23445.25 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 1024365 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 1232224 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); + + // Stress tests for explicit errors in grouping corner cases. The + // validity of these tests and results have been hammered out in + // private email between bkoz and ncm between Jan 25 and Jan 27, 2000. + // Thanks nate -- benjamin + const std::wstring s2(L",111 4,,4 0.25,345 5..25 156,, 1,000000 1000000 1234,567"); + h3 = h4 = h2 = 0; + f1 = 0.0; + const wchar_t c_control = L'?'; + wchar_t c = c_control; + is.clear(); + is.str(s2); + + is >> h4; + VERIFY( h4 == 0 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == L',' ); + VERIFY( is.good() ); + + is.ignore(3); + is >> f1; + VERIFY( f1 == 0.0 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == L',' ); + is >> c; + VERIFY( c == L'4' ); + VERIFY( is.good() ); + + is >> f1; + VERIFY( f1 == 0.25 ); + VERIFY( is.good() ); + is >> c; + VERIFY( c == L',' ); + is >> h2; + VERIFY( h2 == 345 ); + VERIFY( is.good() ); + f1 = 0.0; + h2 = 0; + + is >> f1; + VERIFY( f1 == 5.0 ); + VERIFY( is.good() ); + is >> f1; + VERIFY( f1 == .25 ); + VERIFY( is.good() ); + + is >> h3; + VERIFY( h3 == 0 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + is.clear(); + is >> c; + VERIFY( c == L',' ); // second one + VERIFY( is.good() ); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + h2 = 0; + is.clear(); + + is >> h2; + VERIFY( h2 == 1000000 ); + VERIFY( is.good() ); + h2 = 0; + + is >> h2; + VERIFY( h2 == 1234567 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::failbit) ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); + is.clear(); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc new file mode 100644 index 000000000..c5d78cfb2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/08.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +namespace std { + class test_numpunct2 : public numpunct<wchar_t> + { + protected: + string + do_grouping() const + { return string("\002\003"); } + }; +} // namespace std + +void test08() +{ + // manufactured locale, grouping is turned on + bool test __attribute__((unused)) = true; + unsigned int h4 = 0, h3 = 0, h2 = 0; + const std::wstring s1(L"1,22 205,19 22,123,22"); + + std::wistringstream is(s1); + is.imbue(std::locale(std::locale(), new std::test_numpunct2)); + + // Basic operation. + is >> h4; + VERIFY( h4 == 122 ); + VERIFY( is.good() ); + + is.clear(); + is >> h3; + VERIFY( h3 == 20519 ); + VERIFY( is.good() ); + + is.clear(); + is >> h2; + VERIFY( h2 == 2212322 ); + VERIFY( static_cast<bool>(is.rdstate() & std::ios_base::eofbit) ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc new file mode 100644 index 000000000..fbf6e5db5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/09.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.1.2.2 arithmetic extractors + +// { dg-do run { xfail lax_strtofp } } + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +bool test09() +{ + bool test __attribute__((unused)) = true; + + std::wstring st(L"2.456e3-+0.567e-2"); + std::wstringbuf sb(st); + std::wistream is(&sb); + double f1 = 0, f2 = 0; + wchar_t c; + (is >> std::ws) >> f1; + (is >> std::ws) >> c; + (is >> std::ws) >> f2; + test = f1 == 2456; + VERIFY( f2 == 0.00567 ); + VERIFY( c == L'-' ); + return test; +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc new file mode 100644 index 000000000..f960f0cfb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/10.cc @@ -0,0 +1,132 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2008, 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.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +bool test10() +{ + std::wstring str_01(L"0 00 000 +0 +0 -0"); + std::wstringbuf isbuf_01(str_01); + std::wistream is_01(&isbuf_01); + + bool test __attribute__((unused)) = true; + + int n = 365; + is_01 >> n; + VERIFY( n == 0 ); + n = 364; + is_01 >> n; + VERIFY( n == 0 ); + n = 363; + is_01 >> n; + VERIFY( n == 0 ); + n = 362; + is_01 >> n; + VERIFY( n == 0 ); + n = 361; + is_01 >> n; + VERIFY( n == 0 ); + n = 360; + is_01 >> n; + VERIFY( n == 0 ); + VERIFY( is_01.rdstate() == std::ios_base::eofbit ); + + std::wstring str_02(L"0x32 0X33 033 33"); + std::wstringbuf isbuf_02(str_02); + std::wistream is_02(&isbuf_02); + is_02.unsetf(std::ios_base::basefield); + is_02 >> n; + VERIFY( n == 50 ); + is_02 >> n; + VERIFY( n == 51 ); + is_02 >> n; + VERIFY( n == 27 ); + is_02 >> n; + VERIFY( n == 33 ); + VERIFY( is_02.rdstate() == std::ios_base::eofbit ); + + std::wstringbuf isbuf_03(str_02); + std::wistream is_03(&isbuf_03); + wchar_t c; + int m; + + is_03 >> std::dec >> n >> c >> m; + VERIFY( n == 0 ); + VERIFY( c == L'x' ); + VERIFY( m == 32 ); + + is_03 >> std::oct >> m >> c >> n; + VERIFY( m == 0 ); + VERIFY( c == L'X' ); + VERIFY( n == 27 ); + + is_03 >> std::dec >> m >> n; + VERIFY( m == 33 ); + VERIFY( n == 33 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::wstring str_04(L"3. 4.5E+2a5E-3 .6E1"); + std::wstringbuf isbuf_04(str_04); + std::wistream is_04(&isbuf_04); + + double f; + is_04 >> f; + VERIFY( f == 3.0 ); + is_04 >> f; + VERIFY( f == 450.0 ); + is_04.ignore(); + is_04 >> f; + VERIFY( f == 0.005 ); + is_04 >> f; + VERIFY( f == 6 ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + std::wstring str_05(L"0E20 5Ea E16"); + std::wstringbuf isbuf_05(str_05); + std::wistream is_05(&isbuf_05); + + is_05 >> f; + VERIFY( f == 0 ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05 >> c; + VERIFY( c == L'a' ); + f = 1; + is_05 >> f; + VERIFY( f == 0 ); + VERIFY( is_05.rdstate() == std::ios_base::failbit ); + is_05.clear(); + is_05.ignore(); + is_05 >> n; + VERIFY( n == 16 ); + return test; +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc new file mode 100644 index 000000000..5eb256ef9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/11.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <cwchar> +#include <testsuite_hooks.h> + +// In the presence of no fmtflags, the input operator should behave +// like strtol(x, y, 0) +// libstdc++/90 +bool test11() +{ + bool test __attribute__((unused)) = true; + const wchar_t* cstrlit = L"0x2a"; + + // sanity check via 'C' library call + wchar_t* err; + long l = std::wcstol(cstrlit, &err, 0); + + std::wistringstream iss(cstrlit); + iss.setf(std::wios::fmtflags(0), std::ios::basefield); + int i; + iss >> i; + + VERIFY( !iss.fail() ); + VERIFY( l == i ); + + return test; +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc new file mode 100644 index 000000000..dcadf8669 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/12.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 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.6.1.2.2 arithmetic extractors + +// XXX This test fails on Solaris 8 and 9 because of a bug in libc +// XXX sscanf for very long input. See: +// XXX http://gcc.gnu.org/ml/gcc/2002-12/msg01422.html +// { dg-do run { xfail { { *-*-solaris2.[89] } || lax_strtofp } } } + +#include <istream> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/3720 +// excess input should not cause a core dump +template<typename T> +bool test12_aux(bool integer_type) +{ + bool test __attribute__((unused)) = true; + + int digits_overflow; + if (integer_type) + // This many digits will overflow integer types in base 10. + digits_overflow = std::numeric_limits<T>::digits10 + 2; + else + // This might do it, unsure. + digits_overflow = std::numeric_limits<T>::max_exponent10 + 1; + + std::wstring st; + std::wstring part = L"1234567890123456789012345678901234567890"; + for (std::size_t i = 0; i < digits_overflow / part.size() + 1; ++i) + st += part; + std::wstringbuf sb(st); + std::wistream is(&sb); + T t; + is >> t; + VERIFY( is.fail() ); + return test; +} + +bool test12() +{ + bool test __attribute__((unused)) = true; + VERIFY( test12_aux<short>(true) ); + VERIFY( test12_aux<int>(true) ); + VERIFY( test12_aux<long>(true) ); + VERIFY( test12_aux<float>(false) ); + VERIFY( test12_aux<double>(false) ); + VERIFY( test12_aux<long double>(false) ); + return test; +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc new file mode 100644 index 000000000..0a44b1ffb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/13.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2004, 2005, 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/>. + +// 27.6.1.2.2 arithmetic extractors + +#include <istream> +#include <sstream> +#include <locale> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/3720 part two +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + const wchar_t* l2 = L"1.2345678901234567890123456789012345678901234567890123456" + L" " + L"1246.9"; + + // 1 + // used to core. + double d; + wistringstream iss1(l2); + iss1 >> d; + iss1 >> d; + VERIFY ( d > 1246 && d < 1247 ); + + // 2 + // quick test for failbit on maximum length extraction. + int i; + int max_digits = numeric_limits<int>::digits10 + 1; + wstring digits; + for (int j = 0; j < max_digits; ++j) + digits += L'1'; + wistringstream iss2(digits); + iss2 >> i; + VERIFY( !iss2.fail() ); + + digits += L'1'; + i = 0; + iss2.str(digits); + iss2.clear(); + iss2 >> i; + VERIFY( i == numeric_limits<int>::max() ); + VERIFY( iss2.fail() ); +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc new file mode 100644 index 000000000..8ae2f09ed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/9555-ia.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wistream is(&b); + is.exceptions(std::ios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc new file mode 100644 index 000000000..2ed5b309b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/dr696.cc @@ -0,0 +1,101 @@ +// 2009-07-15 Paolo Carlini <paolo.carlini@oracle.com> +// +// Copyright (C) 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.6.1.2.2 arithmetic extractors + +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// DR 696. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + short s1 = 0; + wostringstream oss1; + oss1 << numeric_limits<short>::max(); + wistringstream iss1(oss1.str()); + iss1 >> s1; + VERIFY( s1 == numeric_limits<short>::max() ); + VERIFY( !iss1.fail() && iss1.eof() ); + + short s2 = 0; + wostringstream oss2; + oss2 << static_cast<long long>(numeric_limits<short>::max()) + 1; + wistringstream iss2(oss2.str()); + iss2 >> s2; + VERIFY( s2 == numeric_limits<short>::max() ); + VERIFY( iss2.fail() && iss2.eof() ); + + short s3 = 0; + wostringstream oss3; + oss3 << numeric_limits<short>::min(); + wistringstream iss3(oss3.str()); + iss3 >> s3; + VERIFY( s3 == numeric_limits<short>::min() ); + VERIFY( !iss3.fail() && iss3.eof() ); + + short s4 = 0; + wostringstream oss4; + oss4 << static_cast<long long>(numeric_limits<short>::min()) - 1; + wistringstream iss4(oss4.str()); + iss4 >> s4; + VERIFY( s4 == numeric_limits<short>::min() ); + VERIFY( iss4.fail() && iss4.eof() ); + + int i1 = 0; + wostringstream oss5; + oss5 << numeric_limits<int>::max(); + wistringstream iss5(oss5.str()); + iss5 >> i1; + VERIFY( i1 == numeric_limits<int>::max() ); + VERIFY( !iss5.fail() && iss5.eof() ); + + int i2 = 0; + wostringstream oss6; + oss6 << static_cast<long long>(numeric_limits<int>::max()) + 1; + wistringstream iss6(oss6.str()); + iss6 >> i2; + VERIFY( i1 == numeric_limits<int>::max() ); + VERIFY( iss6.fail() && iss6.eof() ); + + int i3 = 0; + wostringstream oss7; + oss7 << numeric_limits<int>::min(); + wistringstream iss7(oss7.str()); + iss7 >> i3; + VERIFY( i3 == numeric_limits<int>::min() ); + VERIFY( !iss7.fail() && iss7.eof() ); + + int i4 = 0; + wostringstream oss8; + oss8 << static_cast<long long>(numeric_limits<int>::min()) - 1; + wistringstream iss8(oss8.str()); + iss8 >> i4; + VERIFY( i4 == numeric_limits<int>::min() ); + VERIFY( iss8.fail() && iss8.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..983aac745 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_wchar_t); + wistringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + test_badbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc new file mode 100644 index 000000000..0a31e91dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wistringstream stream(L"jaylib - champion sound"); + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + VERIFY( false ); + } + catch (const ios_base::failure&) + { + // stream should set failbit and throw ios_base::failure. + VERIFY( stream.fail() ); + VERIFY( !stream.bad() ); + VERIFY( !stream.eof() ); + } + catch(...) + { VERIFY( false ); } +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + test_failbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..b3a1b7614 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_arithmetic/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,68 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_get_wchar_t); + wistringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i; + stream >> i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + test_failbit<void*>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/1.cc new file mode 100644 index 000000000..7e4387d31 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/1.cc @@ -0,0 +1,109 @@ +// 1999-07-26 bkoz + +// Copyright (C) 1999, 2003, 2005, 2009, 2010 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::string str_01; + const std::string str_02("coltrane playing 'softly as a morning sunrise'"); + const std::string str_03("coltrane"); + + std::stringbuf isbuf_01(std::ios_base::in); + std::stringbuf isbuf_02(str_02, std::ios_base::in); + std::istream is_01(0); + std::istream is_02(&isbuf_02); + + std::ios_base::iostate state1, state2, statefail; + statefail = std::ios_base::failbit; + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, _CharT*) + const int n = 20; + char array1[n]; + array1[0] = '\0'; + typedef std::ios::traits_type ctraits_type; + ctraits_type::int_type i1, i2; + + state1 = is_01.rdstate(); + i1 = ctraits_type::length(array1); + is_01 >> array1; // should snake 0 characters, not alter stream state + i2 = ctraits_type::length(array1); + state2 = is_01.rdstate(); + VERIFY( i1 == i2 ); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + + state1 = is_02.rdstate(); + is_02 >> array1; // should snake "coltrane" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + VERIFY( array1[str_03.size() - 1] == 'e' ); + array1[str_03.size()] = '\0'; + VERIFY( !str_03.compare(0, str_03.size(), array1) ); + std::istream::int_type int1 = is_02.peek(); // should be ' ' + VERIFY( int1 == ' ' ); + + state1 = is_02.rdstate(); + is_02 >> array1; // should snake "playing" as sentry "eats" ws + state2 = is_02.rdstate(); + int1 = is_02.peek(); // should be ' ' + VERIFY( int1 == ' ' ); + VERIFY( state1 == state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, unsigned char*) + unsigned char array2[n]; + state1 = is_02.rdstate(); + is_02 >> array2; // should snake 'softly + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + VERIFY( array2[0] == '\'' ); + VERIFY( array2[1] == 's' ); + VERIFY( array2[6] == 'y' ); + int1 = is_02.peek(); // should be ' ' + VERIFY( int1 == ' ' ); + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, signed char*) + signed char array3[n]; + state1 = is_02.rdstate(); + is_02 >> array3; // should snake "as" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + VERIFY( array3[0] == 'a' ); + VERIFY( array3[1] == 's' ); + int1 = is_02.peek(); // should be ' ' + VERIFY( int1 == ' ' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc new file mode 100644 index 000000000..0462df0c9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/11095-i.cc @@ -0,0 +1,54 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator>>(basic_istream&, _CharT*) +void test01() +{ + bool test __attribute__((unused)) = true; + const std::string str_01("Consoli "); + + std::stringbuf isbuf_01(str_01, std::ios_base::in); + std::istream is_01(&isbuf_01); + + std::ios_base::iostate state1, state2; + + char array1[10]; + typedef std::ios::traits_type ctraits_type; + + is_01.width(-60); + state1 = is_01.rdstate(); + is_01 >> array1; + state2 = is_01.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !ctraits_type::compare(array1, "Consoli", 7) ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/2.cc new file mode 100644 index 000000000..812d54134 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/2.cc @@ -0,0 +1,91 @@ +// 1999-07-26 bkoz + +// Copyright (C) 1999, 2003, 2009, 2010 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test02() +{ + typedef std::ios::traits_type ctraits_type; + + bool test __attribute__((unused)) = true; + std::string str_01; + const std::string str_02("or coltrane playing tunji with jimmy garrison"); + const std::string str_03("coltrane"); + + std::stringbuf isbuf_01(std::ios_base::in); + std::stringbuf isbuf_02(str_02, std::ios_base::in); + std::istream is_01(0); + std::istream is_02(&isbuf_02); + std::ios_base::iostate state1, state2, statefail; + statefail = std::ios_base::failbit; + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, _CharT&) + char c1 = 'c', c2 = 'c'; + state1 = is_01.rdstate(); + is_01 >> c1; + state2 = is_01.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( c1 == c2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + + state1 = is_02.rdstate(); + is_02 >> c1; + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( c1 == 'o' ); + is_02 >> c1; + is_02 >> c1; + VERIFY( c1 == 'c' ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, unsigned char&) + unsigned char uc1 = 'c'; + state1 = is_02.rdstate(); + is_02 >> uc1; + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( uc1 == 'o' ); + is_02 >> uc1; + is_02 >> uc1; + VERIFY( uc1 == 't' ); + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, signed char&) + signed char sc1 = 'c'; + state1 = is_02.rdstate(); + is_02 >> sc1; + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( sc1 == 'r' ); + is_02 >> sc1; + is_02 >> sc1; + VERIFY( sc1 == 'n' ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/3.cc new file mode 100644 index 000000000..551cb111a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/3.cc @@ -0,0 +1,93 @@ +// 1999-07-26 bkoz + +// Copyright (C) 1999, 2003, 2009, 2010 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::string str_01; + const std::string str_02("coltrane playing 'softly as a morning sunrise'"); + const std::string str_03("coltrane"); + + std::stringbuf isbuf_01(std::ios_base::in); + std::stringbuf isbuf_02(str_02, std::ios_base::in); + std::istream is_01(0); + std::istream is_02(&isbuf_02); + + std::ios_base::iostate state1, state2, statefail; + statefail = std::ios_base::failbit; + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, _CharT*) + int n = 20; + char array1[n]; + typedef std::ios::traits_type ctraits_type; + + // testing with width() control enabled. + is_02.width(8); + state1 = is_02.rdstate(); + is_02 >> array1; // should snake "coltran" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !ctraits_type::compare(array1, "coltran", 7) ); + + is_02.width(1); + state1 = is_02.rdstate(); + is_02 >> array1; // should snake nothing, set failbit + state2 = is_02.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( state2 == statefail ); + VERIFY( array1[0] == '\0' ); + + is_02.width(8); + is_02.clear(); + state1 = is_02.rdstate(); + VERIFY( !state1 ); + is_02 >> array1; // should snake "e" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !ctraits_type::compare(array1, "e", 1) ); + + // testing for correct exception setting + const std::string str_04(" impulse!!"); + std::stringbuf isbuf_03(str_04, std::ios_base::in); + std::stringbuf isbuf_04(str_04, std::ios_base::in); + std::istream is_03(&isbuf_03); + std::istream is_04(&isbuf_04); + + is_03 >> array1; + VERIFY( !ctraits_type::compare(array1,"impulse!!", 10) ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + is_04.width(9); + is_04 >> array1; + VERIFY( ! std::ios::traits_type::compare(array1,"impulse!", 9) ); + VERIFY( !is_04.rdstate() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/4.cc new file mode 100644 index 000000000..68aefcbf3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/4.cc @@ -0,0 +1,93 @@ +// 2005-07-22 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2009 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 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.6.1.2.3 basic_istream::operator>> + +// { dg-require-fileio "" } + +#include <istream> +#include <string> +#include <fstream> +#include <cstdlib> +#include <cstring> +#include <testsuite_hooks.h> + +using namespace std; + +string prepare(string::size_type len, unsigned nchunks) +{ + string ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (string::size_type j = 0; j < len; ++j) + ret.push_back('a' + rand() % 26); + len *= 2; + ret.push_back(' '); + } + return ret; +} + +void check(istream& stream, const string& str, unsigned nchunks) +{ + bool test __attribute__((unused)) = true; + + char* chunk = new char[str.size()]; + memset(chunk, 'X', str.size()); + + string::size_type index = 0, index_new = 0; + unsigned n = 0; + + while (stream >> chunk) + { + index_new = str.find(' ', index); + VERIFY( !str.compare(index, index_new - index, chunk) ); + index = index_new + 1; + ++n; + memset(chunk, 'X', str.size()); + } + VERIFY( stream.eof() ); + VERIFY( n == nchunks ); + + delete[] chunk; +} + +// istream& operator>>(istream&, charT*) +void test01() +{ + const char filename[] = "inserters_extractors-4.txt"; + + const unsigned nchunks = 10; + const string data = prepare(666, nchunks); + + ofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + ifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, nchunks); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/9555-ic.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/9555-ic.cc new file mode 100644 index 000000000..41eb6e3f7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/9555-ic.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::istream is(&b); + is.exceptions(std::ios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + char c = 'a'; + unsigned char uc = 'a'; + signed char sc = 'a'; + char* cp = &c; + signed char* scp = ≻ + unsigned char* ucp = &uc; + + testthrow(c); + testthrow(uc); + testthrow(sc); + testthrow(cp); + testthrow(scp); + testthrow(ucp); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/9826.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/9826.cc new file mode 100644 index 000000000..a2e480ebc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/char/9826.cc @@ -0,0 +1,53 @@ +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2005, 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.7.4 - Template class basic_stringstream +// NB: This file is for testing basic_stringstream with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// { dg-do compile } + +// libstdc++/9826 +void test02() +{ + using namespace std; + using __gnu_test::pod_char; + + basic_stringstream<pod_char, char_traits<pod_char> > sstr; + // 1 + basic_string<pod_char, char_traits<pod_char> > str; + sstr >> str; + + // 2 + pod_char* chr = 0; + sstr >> chr; + + // 3 + sstr >> ws; +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/pod/3983-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/pod/3983-2.cc new file mode 100644 index 000000000..ff70fda76 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/pod/3983-2.cc @@ -0,0 +1,74 @@ +// 2001-06-05 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 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.4.2.1.6 class ios_base::init + +#include <sstream> +#include <typeinfo> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/3983 +// Sentry uses locale info, so have to try one formatted input/output. +void test03() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef pod_ushort::value_type value_type; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_istream<pod_ushort> istream_type; + + stringbuf_type strbuf01; + istream_type iss(&strbuf01); + + bool test __attribute__((unused)) = true; + + // input streams + pod_ushort arr[6] = { { value_type('a') }, { value_type('b') }, + { value_type('c') }, { value_type('d') }, + { value_type('e') } }; + + try + { + iss >> arr; + } + catch (std::bad_cast& obj) + { } + catch (std::exception& obj) + { VERIFY( false ); } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/1.cc new file mode 100644 index 000000000..f7b749a5d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/1.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2004, 2005, 2009, 2010 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::wstring str_01; + const std::wstring str_02(L"coltrane playing 'softly as a morning sunrise'"); + const std::wstring str_03(L"coltrane"); + + std::wstringbuf isbuf_01(std::ios_base::in); + std::wstringbuf isbuf_02(str_02, std::ios_base::in); + std::wistream is_01(0); + std::wistream is_02(&isbuf_02); + + std::ios_base::iostate state1, state2, statefail; + statefail = std::ios_base::failbit; + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, _CharT*) + const int n = 20; + wchar_t array1[n]; + array1[0] = L'\0'; + typedef std::wios::traits_type ctraits_type; + ctraits_type::int_type i1, i2; + + state1 = is_01.rdstate(); + i1 = ctraits_type::length(array1); + is_01 >> array1; // should snake 0 characters, not alter stream state + i2 = ctraits_type::length(array1); + state2 = is_01.rdstate(); + VERIFY( i1 == i2 ); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + + state1 = is_02.rdstate(); + is_02 >> array1; // should snake L"coltrane" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + VERIFY( array1[str_03.size() - 1] == L'e' ); + array1[str_03.size()] = L'\0'; + VERIFY( !str_03.compare(0, str_03.size(), array1) ); + std::wistream::int_type int1 = is_02.peek(); // should be L' ' + VERIFY( int1 == L' ' ); + + state1 = is_02.rdstate(); + is_02 >> array1; // should snake L"playing" as sentry "eats" ws + state2 = is_02.rdstate(); + int1 = is_02.peek(); // should be L' ' + VERIFY( int1 == L' ' ); + VERIFY( state1 == state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/11095-i.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/11095-i.cc new file mode 100644 index 000000000..334311e9f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/11095-i.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2004, 2009 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator>>(basic_istream&, _CharT*) +void test01() +{ + bool test __attribute__((unused)) = true; + const std::wstring str_01(L"Consoli "); + + std::wstringbuf isbuf_01(str_01, std::ios_base::in); + std::wistream is_01(&isbuf_01); + + std::ios_base::iostate state1, state2; + + wchar_t array1[10]; + typedef std::wios::traits_type ctraits_type; + + is_01.width(-60); + state1 = is_01.rdstate(); + is_01 >> array1; + state2 = is_01.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !ctraits_type::compare(array1, L"Consoli", 7) ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/2.cc new file mode 100644 index 000000000..a697ef2b2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/2.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + std::wstring str_01; + const std::wstring str_02(L"or coltrane playing tunji with jimmy garrison"); + const std::wstring str_03(L"coltrane"); + + std::wstringbuf isbuf_01(std::ios_base::in); + std::wstringbuf isbuf_02(str_02, std::ios_base::in); + std::wistream is_01(0); + std::wistream is_02(&isbuf_02); + std::ios_base::iostate state1, state2, statefail; + statefail = std::ios_base::failbit; + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, _CharT&) + wchar_t c1 = L'c', c2 = L'c'; + state1 = is_01.rdstate(); + is_01 >> c1; + state2 = is_01.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( c1 == c2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + + state1 = is_02.rdstate(); + is_02 >> c1; + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( c1 == L'o' ); + is_02 >> c1; + is_02 >> c1; + VERIFY( c1 == L'c' ); + VERIFY( !static_cast<bool>(state2 & statefail) ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/3.cc new file mode 100644 index 000000000..6ea22e395 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/3.cc @@ -0,0 +1,91 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.2.3 character extractors + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::wstring str_01; + const std::wstring str_02(L"coltrane playing 'softly as a morning sunrise'"); + const std::wstring str_03(L"coltrane"); + + std::wstringbuf isbuf_01(std::ios_base::in); + std::wstringbuf isbuf_02(str_02, std::ios_base::in); + std::wistream is_01(0); + std::wistream is_02(&isbuf_02); + + std::ios_base::iostate state1, state2, statefail; + statefail = std::ios_base::failbit; + + // template<_CharT, _Traits> + // basic_istream& operator>>(istream&, _CharT*) + int n = 20; + wchar_t array1[n]; + typedef std::wios::traits_type ctraits_type; + + // testing with width() control enabled. + is_02.width(8); + state1 = is_02.rdstate(); + is_02 >> array1; // should snake L"coltran" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !ctraits_type::compare(array1, L"coltran", 7) ); + + is_02.width(1); + state1 = is_02.rdstate(); + is_02 >> array1; // should snake nothing, set failbit + state2 = is_02.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( state2 == statefail ); + VERIFY( array1[0] == L'\0' ); + + is_02.width(8); + is_02.clear(); + state1 = is_02.rdstate(); + VERIFY( !state1 ); + is_02 >> array1; // should snake L"e" + state2 = is_02.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !ctraits_type::compare(array1, L"e", 1) ); + + // testing for correct exception setting + const std::wstring str_04(L" impulse!!"); + std::wstringbuf isbuf_03(str_04, std::ios_base::in); + std::wstringbuf isbuf_04(str_04, std::ios_base::in); + std::wistream is_03(&isbuf_03); + std::wistream is_04(&isbuf_04); + + is_03 >> array1; + VERIFY( !ctraits_type::compare(array1, L"impulse!!", 10) ); + VERIFY( is_03.rdstate() == std::ios_base::eofbit ); + + is_04.width(9); + is_04 >> array1; + VERIFY( !ctraits_type::compare(array1, L"impulse!", 9) ); + VERIFY( !is_04.rdstate() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc new file mode 100644 index 000000000..2e27c800e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc @@ -0,0 +1,90 @@ +// 2005-07-22 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2006, 2007, 2009 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 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.6.1.2.3 basic_istream::operator>> + +#include <istream> +#include <string> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +wstring prepare(wstring::size_type len, unsigned nchunks) +{ + wstring ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (wstring::size_type j = 0; j < len; ++j) + ret.push_back(L'a' + rand() % 26); + len *= 2; + ret.push_back(L' '); + } + return ret; +} + +void check(wistream& stream, const wstring& str, unsigned nchunks) +{ + bool test __attribute__((unused)) = true; + + wchar_t* chunk = new wchar_t[str.size()]; + wmemset(chunk, L'X', str.size()); + + wstring::size_type index = 0, index_new = 0; + unsigned n = 0; + + while (stream >> chunk) + { + index_new = str.find(' ', index); + VERIFY( !str.compare(index, index_new - index, chunk) ); + index = index_new + 1; + ++n; + wmemset(chunk, L'X', str.size()); + } + VERIFY( stream.eof() ); + VERIFY( n == nchunks ); + + delete[] chunk; +} + +// istream& operator>>(istream&, charT*) +void test01() +{ + const char filename[] = "inserters_extractors-4.txt"; + + const unsigned nchunks = 10; + const wstring data = prepare(666, nchunks); + + wofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + wifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, nchunks); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/9555-ic.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/9555-ic.cc new file mode 100644 index 000000000..a7ba5cd91 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/9555-ic.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wistream is(&b); + is.exceptions(std::wios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + wchar_t c = L'a'; + wchar_t* cp = &c; + + testthrow(c); + testthrow(cp); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/1.cc new file mode 100644 index 000000000..854dc7c85 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/1.cc @@ -0,0 +1,141 @@ +// 1999-07-28 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +// 2009, 2010 +// 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 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.6.1.2.3 basic_istream::operator>> + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// stringbufs. +void test01() +{ + typedef std::ios::traits_type ctraits_type; + + bool test __attribute__((unused)) = true; + const std::string str_01; + const std::string str_02("art taylor kickin it on DAKAR"); + std::string strtmp; + + std::stringbuf isbuf_00(std::ios_base::in); + std::stringbuf isbuf_01(std::ios_base::in | std::ios_base::out); + std::stringbuf isbuf_02(str_01, std::ios_base::in); + std::stringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out); + std::stringbuf isbuf_04(str_02, std::ios_base::in); + std::stringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out); + + std::istream is_00(0); + std::istream is_01(&isbuf_01); + std::istream is_02(&isbuf_02); + std::istream is_03(&isbuf_03); + std::istream is_04(&isbuf_04); + std::istream is_05(&isbuf_05); + std::ios_base::iostate state1, state2, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + + + // template<_CharT, _Traits> + // basic_istream& operator>>(basic_streambuf*) + + // null istream to empty in_buf + state1 = is_00.rdstate(); + is_00 >> &isbuf_00; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_00.str() == str_01 ); + + // null istream to empty in_out_buf + is_00.clear(std::ios_base::goodbit); + state1 = is_00.rdstate(); + is_00 >> &isbuf_01; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_01.str() == str_01 ); + + // null istream to full in_buf + is_00.clear(std::ios_base::goodbit); + state1 = is_00.rdstate(); + is_00 >> &isbuf_04; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_04.str() == str_02 ); + + // null istream to full in_out_buf + is_00.clear(std::ios_base::goodbit); + state1 = is_00.rdstate(); + is_00 >> &isbuf_05; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_05.str() == str_02 ); + + // empty but non-null istream to full in_buf + state1 = is_02.rdstate(); + is_02 >> &isbuf_04; + state2 = is_02.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer + VERIFY( isbuf_04.sgetc() == 'a' ); + + // empty but non-null istream to full in_out_buf + is_02.clear(std::ios_base::goodbit); + state1 = is_02.rdstate(); + is_02 >> &isbuf_05; + state2 = is_02.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer + VERIFY( isbuf_05.sgetc() == 'a' ); + + // full istream to empty in_buf (need out_buf, you know?) + state1 = is_04.rdstate(); + is_04 >> &isbuf_02; + state2 = is_04.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer + VERIFY( isbuf_02.sgetc() == ctraits_type::eof() ); + VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed + + // full istream to empty in_out_buf + is_04.clear(std::ios_base::goodbit); + state1 = is_04.rdstate(); + is_04 >> &isbuf_03; + state2 = is_04.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + VERIFY( state2 == stateeof ); + strtmp = isbuf_03.str(); + VERIFY( strtmp == str_02 ); // as only an "in" buffer + VERIFY( isbuf_03.sgetc() == 'a' ); + VERIFY( is_04.peek() == ctraits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc new file mode 100644 index 000000000..8a71b88ee --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/2.cc @@ -0,0 +1,60 @@ +// 1999-07-28 bkoz + +// Copyright (C) 1999, 2001, 2003, 2004, 2009 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 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.6.1.2.3 basic_istream::operator>> +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +// filebufs. +void test02() +{ + bool test __attribute__((unused)) = true; + const char name_01[] = "istream_extractor_other-1.txt"; //read + const char name_02[] = "istream_extractor_other-2.txt"; //write + + std::filebuf fbin, fbout; + fbin.open(name_01, std::ios_base::in); + fbout.open(name_02, std::ios_base::out | std::ios_base::trunc); + VERIFY( fbin.is_open() ); + VERIFY( fbout.is_open() ); + + if (test) + { + std::istream is(&fbin); + is.unsetf(std::ios_base::skipws); + is >> &fbout; + } + + fbout.close(); + fbin.close(); + VERIFY( !fbin.is_open() ); + VERIFY( !fbout.is_open() ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/26181.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/26181.cc new file mode 100644 index 000000000..8ad53480e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/26181.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2006, 2009 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/26181 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istringstream::pos_type pos_type; + + istringstream iss("Territoires de l'Oubli"); + ostringstream oss; + + VERIFY( iss.tellg() == pos_type(0) ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + + iss.clear(); + VERIFY( iss.tellg() == pos_type(22) ); + + iss.get(); + VERIFY( iss.tellg() == pos_type(-1) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/3.cc new file mode 100644 index 000000000..01c1645b5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/3.cc @@ -0,0 +1,51 @@ +// 1999-07-28 bkoz + +// Copyright (C) 1999, 2001, 2003, 2009 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 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.6.1.2.3 basic_istream::operator>> + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // template<_CharT, _Traits> + // basic_istream& operator>>(ios_base& (*pf) (ios_base&)) + { + int i = 0; + std::istringstream iss(" 43"); + iss >> std::noskipws >> i; + VERIFY ( !iss ); //should set failbit + } + + // template<_CharT, _Traits> + // basic_istream& operator>>(basic_ios& (*pf) (basic_ios&)) + + // template<_CharT, _Traits> + // basic_istream& operator>>(basic_istream& (*pf) (basic_istream&)) +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9318-in.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9318-in.cc new file mode 100644 index 000000000..d82ec5604 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9318-in.cc @@ -0,0 +1,63 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <istream> +#include <testsuite_hooks.h> + +// libstdc++/9318 +class Outbuf : public std::streambuf +{ +public: + typedef std::streambuf::traits_type traits_type; + + std::string result() const { return str; } + +protected: + virtual int_type overflow(int_type c = traits_type::eof()) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) + str.push_back(traits_type::to_char_type(c)); + return traits_type::not_eof(c); + } + +private: + std::string str; +}; + +void test09() +{ + bool test __attribute__((unused)) = true; + + std::istringstream stream("Bad Moon Rising"); + Outbuf buf; + stream >> &buf; + + VERIFY( buf.result() == "Bad Moon Rising" ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9424-in.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9424-in.cc new file mode 100644 index 000000000..ee630b3f1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9424-in.cc @@ -0,0 +1,105 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <cstring> // for memset, memcmp +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9424 +class Outbuf_2 : public std::streambuf +{ + char buf[1]; + +public: + Outbuf_2() + { + setp(buf, buf + 1); + } + + int_type overflow(int_type c) + { + int_type eof = traits_type::eof(); + + if (pptr() < epptr()) + { + if (traits_type::eq_int_type(c, eof)) + return traits_type::not_eof(c); + + *pptr() = traits_type::to_char_type(c); + pbump(1); + return c; + } + + return eof; + } +}; + +class Inbuf_2 : public std::streambuf +{ + static const char buf[]; + const char* current; + int size; + +public: + Inbuf_2() + { + current = buf; + size = std::strlen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const char Inbuf_2::buf[] = "Atteivlis"; + +void test11() +{ + bool test __attribute__((unused)) = true; + + Inbuf_2 inbuf1; + std::istream is(&inbuf1); + Outbuf_2 outbuf1; + is >> &outbuf1; + VERIFY( inbuf1.sgetc() == 't' ); + VERIFY( is.good() ); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9555-io.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9555-io.cc new file mode 100644 index 000000000..248193c43 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/9555-io.cc @@ -0,0 +1,59 @@ +// 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/>. + + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::istream is(&b); + is.exceptions(std::ios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + buf b; + + testthrow(&b); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc new file mode 100644 index 000000000..cc92d486d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/error_failbit.cc @@ -0,0 +1,58 @@ +// 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/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test6() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stringbuf sbuf("", ios_base::out); + + stream >> &sbuf; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test8() +{ + bool test __attribute__((unused)) = true; + istringstream stream("foo, bar, qux"); + __gnu_test::fail_streambuf bob; + + stream >> &bob; + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test6(); + test8(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..0b0ae2318 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_badbit_throw.cc @@ -0,0 +1,70 @@ +// 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/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test14() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + stringbuf sbuf("", ios_base::out); + + try + { + stream >> &sbuf; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test16() +{ + bool test __attribute__((unused)) = true; + istringstream stream("foo, bar, qux"); + stream.exceptions(ios_base::badbit); + __gnu_test::fail_streambuf bob; + + try + { + stream >> &bob; + } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test14(); + test16(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.cc new file mode 100644 index 000000000..d35587077 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_failbit_throw.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/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test10() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::failbit); + stringbuf sbuf("", ios_base::out); + + try + { + stream >> &sbuf; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +void test12() +{ + bool test __attribute__((unused)) = true; + istringstream stream("foo, bar, qux"); + stream.exceptions(ios_base::failbit); + __gnu_test::fail_streambuf bob; + + try + { + stream >> &bob; + VERIFY(false); + } + catch (ios_base::failure&) + { VERIFY(false); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY(false); } + + VERIFY(stream.rdstate() & ios_base::failbit); + VERIFY((stream.rdstate() & ios_base::badbit) == 0); +} + +// libstdc++/9371 +int main() +{ + test10(); + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc new file mode 100644 index 000000000..96ba71930 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/char/exceptions_null.cc @@ -0,0 +1,59 @@ +// Copyright (C) 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/>. + + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +using namespace std; + +void test2() +{ + bool test __attribute__((unused)) = true; + istringstream stream; + stream >> static_cast<streambuf*>(0); + VERIFY(stream.rdstate() & ios_base::failbit); +} + +void test4() +{ + bool test __attribute__((unused)) = true; + istringstream stream; + stream.exceptions(ios_base::failbit); + + try + { + stream >> static_cast<streambuf*>(0); + VERIFY(false); + } + catch (ios_base::failure&) + { + } + + VERIFY(stream.rdstate() & ios_base::failbit); +} + +// libstdc++/9371 +int main() +{ + test2(); + test4(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/pod/3983-3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/pod/3983-3.cc new file mode 100644 index 000000000..ac799b794 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/pod/3983-3.cc @@ -0,0 +1,67 @@ +// 2001-06-05 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 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.4.2.1.6 class ios_base::init + +#include <sstream> +#include <typeinfo> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/3983 +// Sentry uses locale info, so have to try one formatted input/output. +void test03() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_istream<pod_ushort> istream_type; + + stringbuf_type strbuf01; + istream_type iss(&strbuf01); + + bool test __attribute__((unused)) = true; + + try + { + iss >> std::ws; + } + catch (std::bad_cast& obj) + { } + catch (std::exception& obj) + { VERIFY( false ); } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/1.cc new file mode 100644 index 000000000..eab6650b1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/1.cc @@ -0,0 +1,137 @@ +// Copyright (C) 2004, 2005, 2006, 2009, 2010 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 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.6.1.2.3 basic_istream::operator>> + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// stringbufs. +void test01() +{ + typedef std::wios::traits_type ctraits_type; + + bool test __attribute__((unused)) = true; + const std::wstring str_01; + const std::wstring str_02(L"art taylor kickin it on DAKAR"); + std::wstring strtmp; + + std::wstringbuf isbuf_00(std::ios_base::in); + std::wstringbuf isbuf_01(std::ios_base::in | std::ios_base::out); + std::wstringbuf isbuf_02(str_01, std::ios_base::in); + std::wstringbuf isbuf_03(str_01, std::ios_base::in | std::ios_base::out); + std::wstringbuf isbuf_04(str_02, std::ios_base::in); + std::wstringbuf isbuf_05(str_02, std::ios_base::in | std::ios_base::out); + + std::wistream is_00(0); + std::wistream is_01(&isbuf_01); + std::wistream is_02(&isbuf_02); + std::wistream is_03(&isbuf_03); + std::wistream is_04(&isbuf_04); + std::wistream is_05(&isbuf_05); + std::ios_base::iostate state1, state2, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + + + // template<_CharT, _Traits> + // basic_istream& operator>>(basic_streambuf*) + + // null istream to empty in_buf + state1 = is_00.rdstate(); + is_00 >> &isbuf_00; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_00.str() == str_01 ); + + // null istream to empty in_out_buf + is_00.clear(std::ios_base::goodbit); + state1 = is_00.rdstate(); + is_00 >> &isbuf_01; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_01.str() == str_01 ); + + // null istream to full in_buf + is_00.clear(std::ios_base::goodbit); + state1 = is_00.rdstate(); + is_00 >> &isbuf_04; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_04.str() == str_02 ); + + // null istream to full in_out_buf + is_00.clear(std::ios_base::goodbit); + state1 = is_00.rdstate(); + is_00 >> &isbuf_05; + state2 = is_00.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_05.str() == str_02 ); + + // empty but non-null istream to full in_buf + state1 = is_02.rdstate(); + is_02 >> &isbuf_04; + state2 = is_02.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_04.str() == str_02 ); // as only an "in" buffer + VERIFY( isbuf_04.sgetc() == L'a' ); + + // empty but non-null istream to full in_out_buf + is_02.clear(std::ios_base::goodbit); + state1 = is_02.rdstate(); + is_02 >> &isbuf_05; + state2 = is_02.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_05.str() == str_02 ); // as only an "in" buffer + VERIFY( isbuf_05.sgetc() == L'a' ); + + // full istream to empty in_buf (need out_buf, you know?) + state1 = is_04.rdstate(); + is_04 >> &isbuf_02; + state2 = is_04.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( isbuf_02.str() == str_01 ); // as only an "in" buffer + VERIFY( isbuf_02.sgetc() == ctraits_type::eof() ); + VERIFY( is_04.peek() == ctraits_type::eof() ); // as failed + + // full istream to empty in_out_buf + is_04.clear(std::ios_base::goodbit); + state1 = is_04.rdstate(); + is_04 >> &isbuf_03; + state2 = is_04.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( !static_cast<bool>(state2 & statefail) ); + VERIFY( state2 == stateeof ); + strtmp = isbuf_03.str(); + VERIFY( strtmp == str_02 ); // as only an "in" buffer + VERIFY( isbuf_03.sgetc() == L'a' ); + VERIFY( is_04.peek() == ctraits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc new file mode 100644 index 000000000..b4f3c9a60 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/2.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2004, 2009 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 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.6.1.2.3 basic_istream::operator>> +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +// filebufs. +void test02() +{ + bool test __attribute__((unused)) = true; + const char name_01[] = "wistream_extractor_other-1.txt"; //read + const char name_02[] = "wistream_extractor_other-2.txt"; //write + + std::wfilebuf fbin, fbout; + fbin.open(name_01, std::ios_base::in); + fbout.open(name_02, std::ios_base::out | std::ios_base::trunc); + VERIFY( fbin.is_open() ); + VERIFY( fbout.is_open() ); + + if (test) + { + std::wistream is(&fbin); + is.unsetf(std::ios_base::skipws); + is >> &fbout; + } + + fbout.close(); + fbin.close(); + VERIFY( !fbin.is_open() ); + VERIFY( !fbout.is_open() ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/26181.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/26181.cc new file mode 100644 index 000000000..4e54e2296 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/26181.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2006, 2009 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/26181 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef wistringstream::pos_type pos_type; + + wistringstream iss(L"Territoires de l'Oubli"); + wostringstream oss; + + VERIFY( iss.tellg() == pos_type(0) ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + + iss.clear(); + VERIFY( iss.tellg() == pos_type(22) ); + + iss.get(); + VERIFY( iss.tellg() == pos_type(-1) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/3.cc new file mode 100644 index 000000000..1918f9bb6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/3.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 2009 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 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.6.1.2.3 basic_istream::operator>> + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test03() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // template<_CharT, _Traits> + // basic_istream& operator>>(ios_base& (*pf) (ios_base&)) + { + int i = 0; + std::wistringstream iss(L" 43"); + iss >> std::noskipws >> i; + VERIFY ( !iss ); //should set failbit + } + + // template<_CharT, _Traits> + // basic_istream& operator>>(basic_ios& (*pf) (basic_ios&)) + + // template<_CharT, _Traits> + // basic_istream& operator>>(basic_istream& (*pf) (basic_istream&)) +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9318-in.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9318-in.cc new file mode 100644 index 000000000..c2925f24c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9318-in.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <istream> +#include <testsuite_hooks.h> + +// libstdc++/9318 +class Outbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + std::wstring result() const { return str; } + +protected: + virtual int_type overflow(int_type c = traits_type::eof()) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) + str.push_back(traits_type::to_char_type(c)); + return traits_type::not_eof(c); + } + +private: + std::wstring str; +}; + +void test09() +{ + bool test __attribute__((unused)) = true; + + std::wistringstream stream(L"Bad Moon Rising"); + Outbuf buf; + stream >> &buf; + + VERIFY( buf.result() == L"Bad Moon Rising" ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9424-in.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9424-in.cc new file mode 100644 index 000000000..38b345715 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9424-in.cc @@ -0,0 +1,103 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <cstring> +#include <cwchar> +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9424 +class Outbuf_2 : public std::wstreambuf +{ + wchar_t buf[1]; + +public: + Outbuf_2() + { + setp(buf, buf + 1); + } + + int_type overflow(int_type c) + { + int_type eof = traits_type::eof(); + + if (pptr() < epptr()) + { + if (traits_type::eq_int_type(c, eof)) + return traits_type::not_eof(c); + + *pptr() = traits_type::to_char_type(c); + pbump(1); + return c; + } + + return eof; + } +}; + +class Inbuf_2 : public std::wstreambuf +{ + static const wchar_t buf[]; + const wchar_t* current; + int size; + +public: + Inbuf_2() + { + current = buf; + size = std::wcslen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const wchar_t Inbuf_2::buf[] = L"Atteivlis"; + +void test11() +{ + bool test __attribute__((unused)) = true; + + Inbuf_2 inbuf1; + std::wistream is(&inbuf1); + Outbuf_2 outbuf1; + is >> &outbuf1; + VERIFY( inbuf1.sgetc() == L't' ); + VERIFY( is.good() ); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9555-io.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9555-io.cc new file mode 100644 index 000000000..a46c2b91f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/9555-io.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wistream is(&b); + is.exceptions(std::wios::badbit); + + try + { + is >> arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( is.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + buf b; + + testthrow(&b); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/error_failbit.cc new file mode 100644 index 000000000..bbac2413d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/error_failbit.cc @@ -0,0 +1,58 @@ +// 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/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test6() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wistream stream(&bib); + wstringbuf sbuf(L"", ios_base::out); + + stream >> &sbuf; + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test8() +{ + bool test __attribute__((unused)) = true; + wistringstream stream(L"foo, bar, qux"); + __gnu_test::fail_wstreambuf bob; + + stream >> &bob; + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test6(); + test8(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..d7e16905b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test14() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wistream stream(&bib); + stream.exceptions(ios_base::badbit); + wstringbuf sbuf(L"", ios_base::out); + + try + { + stream >> &sbuf; + } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test16() +{ + bool test __attribute__((unused)) = true; + wistringstream stream(L"foo, bar, qux"); + stream.exceptions(ios_base::badbit); + __gnu_test::fail_wstreambuf bob; + + try + { + stream >> &bob; + } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test14(); + test16(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..a9f4b9734 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test10() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wistream stream(&bib); + stream.exceptions(ios_base::failbit); + wstringbuf sbuf(L"", ios_base::out); + + try + { + stream >> &sbuf; + VERIFY( false ); + } + catch (ios_base::failure&) + { VERIFY( false ); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test12() +{ + bool test __attribute__((unused)) = true; + wistringstream stream(L"foo, bar, qux"); + stream.exceptions(ios_base::failbit); + __gnu_test::fail_wstreambuf bob; + + try + { + stream >> &bob; + VERIFY( false ); + } + catch (ios_base::failure&) + { VERIFY( false ); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test10(); + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc new file mode 100644 index 000000000..bc04b7d9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/extractors_other/wchar_t/exceptions_null.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2004, 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/>. + + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +using namespace std; + +void test2() +{ + bool test __attribute__((unused)) = true; + wistringstream stream; + stream >> static_cast<wstreambuf*>(0); + VERIFY( stream.rdstate() & ios_base::failbit ); +} + +void test4() +{ + bool test __attribute__((unused)) = true; + wistringstream stream; + stream.exceptions(ios_base::failbit); + + try + { + stream >> static_cast<wstreambuf*>(0); + VERIFY( false ); + } + catch (ios_base::failure&) + { + } + + VERIFY( stream.rdstate() & ios_base::failbit ); +} + +// libstdc++/9371 +int main() +{ + test2(); + test4(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/1.cc new file mode 100644 index 000000000..f7957d8a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/1.cc @@ -0,0 +1,123 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test03() +{ + typedef std::char_traits<char> traits_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = + " sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n" + " " + "jazz in silhouette: images and forecasts of tomorrow"; + + std::string str01(str_lit01); + std::string strtmp; + + std::stringbuf sbuf_03; + std::stringbuf sbuf_04(str01, std::ios_base::in); + std::stringbuf sbuf_05(str01, std::ios_base::in); + + std::istream is_00(0); + std::istream is_04(&sbuf_04); + std::istream is_05(&sbuf_05); + std::ios_base::iostate statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + char carray1[400] = ""; + + // int_type get() + // istream& get(char*, streamsize, char delim) + // istream& get(char*, streamsize) + // istream& get(streambuf&, char delim) + // istream& get(streambuf&) + is_00.get(carray1, 2); + VERIFY( static_cast<bool>(is_00.rdstate() & statefail) ); + VERIFY( is_00.gcount() == 0 ); + + is_04.get(carray1, 4); + VERIFY( !(is_04.rdstate() & statefail) ); + VERIFY( !traits_type::compare(carray1, " ", 4) ); + VERIFY( is_04.gcount() == 3 ); + + is_04.clear(); + is_04.get(carray1 + 3, 200); + VERIFY( !(is_04.rdstate() & statefail) ); + VERIFY( !(is_04.rdstate() & stateeof) ); + VERIFY( !traits_type::compare(carray1, str_lit01, 10) ); + VERIFY( is_04.gcount() == 7 ); + + is_04.clear(); + is_04.get(carray1, 200); + VERIFY( !(is_04.rdstate() & stateeof) ); + VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); // delimiter + VERIFY( is_04.gcount() == 0 ); + is_04.clear(); + is_04.get(carray1, 200, '['); + VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) ); + VERIFY( !(is_04.rdstate() & statefail) ); + VERIFY( is_04.gcount() == 125 ); + is_04.clear(); + is_04.get(carray1, 200); + VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) ); + VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); + VERIFY( is_04.gcount() == 0 ); + + std::stringbuf sbuf_02(std::ios_base::in); + is_05.clear(); + is_05.get(sbuf_02); + VERIFY( is_05.gcount() == 0 ); + VERIFY( static_cast<bool>(is_05.rdstate() & statefail) ); + VERIFY( !(is_05.rdstate() & stateeof) ); + + is_05.clear(); + is_05.get(sbuf_03); + VERIFY( is_05.gcount() == 10 ); + VERIFY( sbuf_03.str() == " sun*ra " ); + VERIFY( !(is_05.rdstate() & statefail) ); + VERIFY( !(is_05.rdstate() & stateeof) ); + + is_05.clear(); + is_05.get(sbuf_03, '|'); + VERIFY( is_05.gcount() == 125 ); + VERIFY( sbuf_03.str() == str_lit01 ); + VERIFY( !(is_05.rdstate() & statefail) ); + VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) ); + + is_05.clear(); + is_05.get(sbuf_03, '|'); + VERIFY( is_05.gcount() == 0 ); + VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) ); + VERIFY( static_cast<bool>(is_05.rdstate() & statefail) ); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc new file mode 100644 index 000000000..c677b4334 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/2.cc @@ -0,0 +1,59 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +//libstdc++/92: Bug in istream::get(basic_streambuf*) +// bug reported by bgarcia@laurelnetworks.com +// http://gcc.gnu.org/ml/libstdc++-prs/2000-q3/msg00041.html +void +test07() +{ + bool test __attribute__((unused)) = true; + const char* tfn = "istream_unformatted-1.txt"; + std::ifstream infile; + infile.open(tfn); + VERIFY( !(!infile) ); + while (infile) + { + std::string line; + std::ostringstream line_ss; + while (infile.peek() == '\n') + infile.get(); + infile.get(*(line_ss.rdbuf())); + line = line_ss.str(); + VERIFY( line == "1234567890" || line == "" ); + } +} + +int +main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/3.cc new file mode 100644 index 000000000..5804fd7b8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/3.cc @@ -0,0 +1,57 @@ +// 2004-11-26 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <sstream> +#include <testsuite_hooks.h> + +// DR 243. get and getline when sentry reports failure. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf strbuf01; + stringbuf strbuf02; + istream istr01(&strbuf01); + istream istr02(&strbuf02); + char buf02[2] = "*" ; + + istr01.peek(); + VERIFY( istr01.eof() ); + + istr01.get(0, 0); + VERIFY( istr01.gcount() == 0 ); + VERIFY( istr01.fail() ); + + istr02.peek(); + VERIFY( istr02.eof() ); + + istr02.get(buf02, 1); + VERIFY( istr02.gcount() == 0 ); + VERIFY( istr02.fail() ); + VERIFY( buf02[0] == char() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/1.cc new file mode 100644 index 000000000..b3027c3af --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/1.cc @@ -0,0 +1,120 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test03() +{ + typedef std::char_traits<wchar_t> traits_type; + + bool test __attribute__((unused)) = true; + const wchar_t str_lit01[] = + L" sun*ra \n\t\t\t & his arkestra, featuring john gilmore: \n" + L" " + L"jazz in silhouette: images and forecasts of tomorrow"; + + std::wstring str01(str_lit01); + std::wstring strtmp; + + std::wstringbuf sbuf_03; + std::wstringbuf sbuf_04(str01, std::ios_base::in); + std::wstringbuf sbuf_05(str01, std::ios_base::in); + + std::wistream is_00(0); + std::wistream is_04(&sbuf_04); + std::wistream is_05(&sbuf_05); + std::ios_base::iostate statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + wchar_t carray1[400] = L""; + + // int_type get() + // istream& get(wchar_t*, streamsize, wchar_t delim) + // istream& get(wchar_t*, streamsize) + // istream& get(streambuf&, wchar_t delim) + // istream& get(streambuf&) + is_00.get(carray1, 2); + VERIFY( static_cast<bool>(is_00.rdstate() & statefail) ); + VERIFY( is_00.gcount() == 0 ); + + is_04.get(carray1, 4); + VERIFY( !(is_04.rdstate() & statefail) ); + VERIFY( !traits_type::compare(carray1, L" ", 4) ); + VERIFY( is_04.gcount() == 3 ); + + is_04.clear(); + is_04.get(carray1 + 3, 200); + VERIFY( !(is_04.rdstate() & statefail) ); + VERIFY( !(is_04.rdstate() & stateeof) ); + VERIFY( !traits_type::compare(carray1, str_lit01, 10) ); + VERIFY( is_04.gcount() == 7 ); + + is_04.clear(); + is_04.get(carray1, 200); + VERIFY( !(is_04.rdstate() & stateeof) ); + VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); // delimiter + VERIFY( is_04.gcount() == 0 ); + is_04.clear(); + is_04.get(carray1, 200, L'['); + VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) ); + VERIFY( !(is_04.rdstate() & statefail) ); + VERIFY( is_04.gcount() == 125 ); + is_04.clear(); + is_04.get(carray1, 200); + VERIFY( static_cast<bool>(is_04.rdstate() & stateeof) ); + VERIFY( static_cast<bool>(is_04.rdstate() & statefail) ); + VERIFY( is_04.gcount() == 0 ); + + std::wstringbuf sbuf_02(std::ios_base::in); + is_05.clear(); + is_05.get(sbuf_02); + VERIFY( is_05.gcount() == 0 ); + VERIFY( static_cast<bool>(is_05.rdstate() & statefail) ); + VERIFY( !(is_05.rdstate() & stateeof) ); + + is_05.clear(); + is_05.get(sbuf_03); + VERIFY( is_05.gcount() == 10 ); + VERIFY( sbuf_03.str() == L" sun*ra " ); + VERIFY( !(is_05.rdstate() & statefail) ); + VERIFY( !(is_05.rdstate() & stateeof) ); + + is_05.clear(); + is_05.get(sbuf_03, L'|'); + VERIFY( is_05.gcount() == 125 ); + VERIFY( sbuf_03.str() == str_lit01 ); + VERIFY( !(is_05.rdstate() & statefail) ); + VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) ); + + is_05.clear(); + is_05.get(sbuf_03, L'|'); + VERIFY( is_05.gcount() == 0 ); + VERIFY( static_cast<bool>(is_05.rdstate() & stateeof) ); + VERIFY( static_cast<bool>(is_05.rdstate() & statefail) ); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc new file mode 100644 index 000000000..9cfb004cc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/2.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +//libstdc++/92: Bug in istream::get(basic_streambuf*) +// bug reported by bgarcia@laurelnetworks.com +// http://gcc.gnu.org/ml/libstdc++-prs/2000-q3/msg00041.html +void +test07() +{ + bool test __attribute__((unused)) = true; + const char* tfn = "istream_unformatted-1.txt"; + std::wifstream infile; + infile.open(tfn); + VERIFY( !(!infile) ); + while (infile) + { + std::wstring line; + std::wostringstream line_ss; + while (infile.peek() == L'\n') + infile.get(); + infile.get(*(line_ss.rdbuf())); + line = line_ss.str(); + VERIFY( line == L"1234567890" || line == L"" ); + } +} + +int +main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/3.cc new file mode 100644 index 000000000..f1a2718be --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/wchar_t/3.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <sstream> +#include <testsuite_hooks.h> + +// DR 243. get and getline when sentry reports failure. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf strbuf01; + wstringbuf strbuf02; + wistream istr01(&strbuf01); + wistream istr02(&strbuf02); + wchar_t buf02[2] = L"*" ; + + istr01.peek(); + VERIFY( istr01.eof() ); + + istr01.get(0, 0); + VERIFY( istr01.gcount() == 0 ); + VERIFY( istr01.fail() ); + + istr02.peek(); + VERIFY( istr02.eof() ); + + istr02.get(buf02, 1); + VERIFY( istr02.gcount() == 0 ); + VERIFY( istr02.fail() ); + VERIFY( buf02[0] == wchar_t() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc new file mode 100644 index 000000000..48b245f9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/1.cc @@ -0,0 +1,120 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test02() +{ + typedef std::char_traits<char> traits_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "\t\t\t sun*ra \n" + " " + "and his myth science arkestra present\n" + " " + "angles and demons @ play\n" + " " + "the nubians of plutonia"; + std::string str01(str_lit01); + std::string strtmp; + + std::stringbuf sbuf_04(str01, std::ios_base::in); + + std::istream is_00(0); + std::istream is_04(&sbuf_04); + std::ios_base::iostate state1, state2, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + char carray1[400] = ""; + + // istream& getline(char* s, streamsize n, char delim) + // istream& getline(char* s, streamsize n) + state1 = is_00.rdstate(); + is_00.getline(carray1, 20, '*'); + state2 = is_00.rdstate(); + // make sure failbit was set, since we couldn't extract + // from the null streambuf... + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + + VERIFY( is_04.gcount() == 0 ); + state1 = is_04.rdstate(); + is_04.getline(carray1, 1, '\t'); // extracts, throws away + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 1 ); + VERIFY( state1 == state2 ); + VERIFY( state1 == 0 ); + VERIFY( !traits_type::compare("", carray1, 1) ); + + state1 = is_04.rdstate(); + is_04.getline(carray1, 20, '*'); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 10 ); + VERIFY( state1 == state2 ); + VERIFY( state1 == 0 ); + VERIFY( !traits_type::compare("\t\t sun", carray1, 10) ); + + state1 = is_04.rdstate(); + is_04.getline(carray1, 20); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 4 ); + VERIFY( state1 == state2 ); + VERIFY( state1 == 0 ); + VERIFY( !traits_type::compare("ra ", carray1, 4) ); + + state1 = is_04.rdstate(); + is_04.getline(carray1, 65); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 64 ); + VERIFY( state1 != state2 ); + VERIFY( state2 == statefail ); + VERIFY( !traits_type::compare( + " and his myth science arkestra presen", + carray1, 65) ); + + is_04.clear(); + state1 = is_04.rdstate(); + is_04.getline(carray1, 120, '|'); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 106 ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is_04.clear(); + state1 = is_04.rdstate(); + is_04.getline(carray1, 100, '|'); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 0 ); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & stateeof) ); + VERIFY( static_cast<bool>(state2 & statefail) ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc new file mode 100644 index 000000000..486e0e5fc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/2.cc @@ -0,0 +1,99 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <cstring> // for strlen +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type) +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html +void +test05() +{ + const char* charray = "\n" +"a\n" +"aa\n" +"aaa\n" +"aaaa\n" +"aaaaa\n" +"aaaaaa\n" +"aaaaaaa\n" +"aaaaaaaa\n" +"aaaaaaaaa\n" +"aaaaaaaaaa\n" +"aaaaaaaaaaa\n" +"aaaaaaaaaaaa\n" +"aaaaaaaaaaaaa\n" +"aaaaaaaaaaaaaa\n"; + + bool test __attribute__((unused)) = true; + const std::streamsize it = 5; + std::streamsize br = 0; + char tmp[it]; + std::stringbuf sb(charray, std::ios_base::in); + std::istream ifs(&sb); + std::streamsize blen = std::strlen(charray); + VERIFY(!(!ifs)); + while(ifs.getline(tmp, it) || ifs.gcount()) + { + br += ifs.gcount(); + if(ifs.eof()) + { + // Just sanity checks to make sure we've extracted the same + // number of chars that were in the streambuf + VERIFY(br == blen); + // Also, we should only set the failbit if we could + // _extract_ no chars from the stream, i.e. the first read + // returned EOF. + VERIFY(ifs.fail() && ifs.gcount() == 0); + } + else if(ifs.fail()) + { + // delimiter not read + // + // either + // -> extracted no characters + // or + // -> n - 1 characters are stored + ifs.clear(ifs.rdstate() & ~std::ios::failbit); + VERIFY((ifs.gcount() == 0) || (std::strlen(tmp) == it - 1)); + VERIFY(!(!ifs)); + continue; + } + else + { + // delimiter was read. + // + // -> strlen(__s) < n - 1 + // -> delimiter was seen -> gcount() > strlen(__s) + VERIFY(ifs.gcount() == static_cast<std::streamsize>(std::strlen(tmp) + 1) ); + continue; + } + } +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc new file mode 100644 index 000000000..f71e1ca16 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/3.cc @@ -0,0 +1,60 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <cstring> // for strlen +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// [bug] istream::getline(char*,streamsize) still broken +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00126.html +// brent verner <brent at rcfile dot org +void +test06() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const streamsize it = 5; + char tmp[it]; + const char* str_lit = "abcd\n"; + + stringbuf strbuf(str_lit, std::ios_base::in); + istream istr(&strbuf); + + istr.getline(tmp,it); + VERIFY( istr.gcount() == it ); // extracted whole string + VERIFY( strlen(tmp) == 4 ); // stored all but '\n' + VERIFY( !istr.eof() ); // extracted up to but not eof + VERIFY( !istr.fail() ); // failbit not set + + char c = 'z'; + istr.get(c); + VERIFY( c == 'z' ); + VERIFY( istr.eof() ); +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc new file mode 100644 index 000000000..4f2909232 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.3 unformatted input functions + +#include <cstring> // for strlen +#include <istream> +#include <testsuite_hooks.h> + +class Inbuf : public std::streambuf +{ + static const char buf[]; + const char* current; + int size; + +public: + Inbuf() + { + current = buf; + size = std::strlen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const char Inbuf::buf[] = "1234567890abcdefghij"; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef char_traits<char> traits_type; + + Inbuf inbuf1; + istream is(&inbuf1); + + char buffer[10]; + traits_type::assign(buffer, sizeof(buffer), 'X'); + + is.getline(buffer, sizeof(buffer), '0'); + VERIFY( is.rdstate() == ios_base::goodbit ); + VERIFY( !traits_type::compare(buffer, "123456789\0", sizeof(buffer)) ); + VERIFY( is.gcount() == 10 ); + + is.clear(); + traits_type::assign(buffer, sizeof(buffer), 'X'); + is.getline(buffer, sizeof(buffer)); + VERIFY( is.rdstate() == ios_base::failbit ); + VERIFY( !traits_type::compare(buffer, "abcdefghi\0", sizeof(buffer)) ); + VERIFY( is.gcount() == 9 ); + + is.clear(); + traits_type::assign(buffer, sizeof(buffer), 'X'); + is.getline(buffer, sizeof(buffer)); + VERIFY( is.rdstate() == ios_base::eofbit ); + VERIFY( !traits_type::compare(buffer, "j\0XXXXXXXX", sizeof(buffer)) ); + VERIFY( is.gcount() == 1 ); + + is.clear(); + traits_type::assign(buffer, sizeof(buffer), 'X'); + is.getline(buffer, sizeof(buffer)); + VERIFY( is.rdstate() == (ios_base::eofbit | ios_base::failbit) ); + VERIFY( !traits_type::compare(buffer, "\0XXXXXXXXX", sizeof(buffer)) ); + VERIFY( is.gcount() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc new file mode 100644 index 000000000..310f637f9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/5.cc @@ -0,0 +1,88 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2009 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 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.6.1.3 unformatted input functions + +// { dg-require-fileio "" } + +#include <istream> +#include <string> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +string prepare(string::size_type len, unsigned nchunks, char delim) +{ + string ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (string::size_type j = 0; j < len; ++j) + ret.push_back('a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void check(istream& stream, const string& str, unsigned nchunks, char delim) +{ + bool test __attribute__((unused)) = true; + + char buf[1000000]; + string::size_type index = 0, index_new = 0; + unsigned n = 0; + + while (stream.getline(buf, sizeof(buf), delim)) + { + index_new = str.find(delim, index); + VERIFY( static_cast<string::size_type>(stream.gcount()) == + index_new - index + 1 ); + VERIFY( !str.compare(index, index_new - index, buf) ); + index = index_new + 1; + ++n; + } + VERIFY( stream.gcount() == 0 ); + VERIFY( stream.eof() ); + VERIFY( n == nchunks ); +} + +void test01() +{ + const char filename[] = "istream_getline.txt"; + + const char delim = '|'; + const unsigned nchunks = 10; + const string data = prepare(777, nchunks, delim); + + ofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + ifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, nchunks, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc new file mode 100644 index 000000000..0a129ecbf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc @@ -0,0 +1,57 @@ +// 2004-11-26 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <sstream> +#include <testsuite_hooks.h> + +// DR 243. get and getline when sentry reports failure. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf strbuf01; + stringbuf strbuf02; + istream istr01(&strbuf01); + istream istr02(&strbuf02); + char buf02[2] = "*" ; + + istr01.peek(); + VERIFY( istr01.eof() ); + + istr01.getline(0, 0); + VERIFY( istr01.gcount() == 0 ); + VERIFY( istr01.fail() ); + + istr02.peek(); + VERIFY( istr02.eof() ); + + istr02.getline(buf02, 1); + VERIFY( istr02.gcount() == 0 ); + VERIFY( istr02.fail() ); + VERIFY( buf02[0] == char() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc new file mode 100644 index 000000000..2445dd4f7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc @@ -0,0 +1,117 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test02() +{ + typedef std::char_traits<wchar_t> traits_type; + + bool test __attribute__((unused)) = true; + const wchar_t str_lit01[] = L"\t\t\t sun*ra \n" + L" " + L"and his myth science arkestra present\n" + L" " + L"angles and demons @ play\n" + L" " + L"the nubians of plutonia"; + std::wstring str01(str_lit01); + std::wstring strtmp; + + std::wstringbuf sbuf_04(str01, std::ios_base::in); + + std::wistream is_00(0); + std::wistream is_04(&sbuf_04); + std::ios_base::iostate state1, state2, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + wchar_t carray1[400] = L""; + + // istream& getline(wchar_t* s, streamsize n, wchar_t delim) + // istream& getline(wchar_t* s, streamsize n) + state1 = is_00.rdstate(); + is_00.getline(carray1, 20, L'*'); + state2 = is_00.rdstate(); + // make sure failbit was set, since we couldn't extract + // from the null streambuf... + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & statefail) ); + + VERIFY( is_04.gcount() == 0 ); + state1 = is_04.rdstate(); + is_04.getline(carray1, 1, L'\t'); // extracts, throws away + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 1 ); + VERIFY( state1 == state2 ); + VERIFY( state1 == 0 ); + VERIFY( !traits_type::compare(L"", carray1, 1) ); + + state1 = is_04.rdstate(); + is_04.getline(carray1, 20, L'*'); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 10 ); + VERIFY( state1 == state2 ); + VERIFY( state1 == 0 ); + VERIFY( !traits_type::compare(L"\t\t sun", carray1, 10) ); + + state1 = is_04.rdstate(); + is_04.getline(carray1, 20); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 4 ); + VERIFY( state1 == state2 ); + VERIFY( state1 == 0 ); + VERIFY( !traits_type::compare(L"ra ", carray1, 4) ); + + state1 = is_04.rdstate(); + is_04.getline(carray1, 65); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 64 ); + VERIFY( state1 != state2 ); + VERIFY( state2 == statefail ); + VERIFY( !traits_type::compare( + L" and his myth science arkestra presen", + carray1, 65) ); + + is_04.clear(); + state1 = is_04.rdstate(); + is_04.getline(carray1, 120, L'|'); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 106 ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is_04.clear(); + state1 = is_04.rdstate(); + is_04.getline(carray1, 100, L'|'); + state2 = is_04.rdstate(); + VERIFY( is_04.gcount() == 0 ); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & stateeof) ); + VERIFY( static_cast<bool>(state2 & statefail) ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc new file mode 100644 index 000000000..192de56a2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <cwchar> // for wcslen +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type) +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html +void +test05() +{ + const wchar_t* charray = L"\n" +L"a\n" +L"aa\n" +L"aaa\n" +L"aaaa\n" +L"aaaaa\n" +L"aaaaaa\n" +L"aaaaaaa\n" +L"aaaaaaaa\n" +L"aaaaaaaaa\n" +L"aaaaaaaaaa\n" +L"aaaaaaaaaaa\n" +L"aaaaaaaaaaaa\n" +L"aaaaaaaaaaaaa\n" +L"aaaaaaaaaaaaaa\n"; + + bool test __attribute__((unused)) = true; + const std::streamsize it = 5; + std::streamsize br = 0; + wchar_t tmp[it]; + std::wstringbuf sb(charray, std::ios_base::in); + std::wistream ifs(&sb); + std::streamsize blen = std::wcslen(charray); + VERIFY(!(!ifs)); + while(ifs.getline(tmp, it) || ifs.gcount()) + { + br += ifs.gcount(); + if(ifs.eof()) + { + // Just sanity checks to make sure we've extracted the same + // number of chars that were in the streambuf + VERIFY( br == blen ); + // Also, we should only set the failbit if we could + // _extract_ no chars from the stream, i.e. the first read + // returned EOF. + VERIFY( ifs.fail() && ifs.gcount() == 0 ); + } + else if(ifs.fail()) + { + // delimiter not read + // + // either + // -> extracted no characters + // or + // -> n - 1 characters are stored + ifs.clear(ifs.rdstate() & ~std::ios::failbit); + VERIFY( (ifs.gcount() == 0) || (std::wcslen(tmp) == it - 1) ); + VERIFY( !(!ifs) ); + continue; + } + else + { + // delimiter was read. + // + // -> wcslen(__s) < n - 1 + // -> delimiter was seen -> gcount() > wcslen(__s) + VERIFY( ifs.gcount() == static_cast<std::streamsize>(std::wcslen(tmp) + + 1) ); + continue; + } + } +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc new file mode 100644 index 000000000..af7033ddd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <cwchar> // for wcslen +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// [bug] istream::getline(char*,streamsize) still broken +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00126.html +// brent verner <brent at rcfile dot org +void +test06() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const streamsize it = 5; + wchar_t tmp[it]; + const wchar_t* str_lit = L"abcd\n"; + + wstringbuf strbuf(str_lit, std::ios_base::in); + wistream istr(&strbuf); + + istr.getline(tmp,it); + VERIFY( istr.gcount() == it ); // extracted whole string + VERIFY( wcslen(tmp) == 4 ); // stored all but '\n' + VERIFY( !istr.eof() ); // extracted up to but not eof + VERIFY( !istr.fail() ); // failbit not set + + wchar_t c = L'z'; + istr.get(c); + VERIFY( c == L'z' ); + VERIFY( istr.eof() ); +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc new file mode 100644 index 000000000..1e147c748 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc @@ -0,0 +1,103 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.3 unformatted input functions + +#include <cwchar> // for wcslen +#include <istream> +#include <testsuite_hooks.h> + +class Inbuf : public std::wstreambuf +{ + static const wchar_t buf[]; + const wchar_t* current; + int size; + +public: + Inbuf() + { + current = buf; + size = std::wcslen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const wchar_t Inbuf::buf[] = L"1234567890abcdefghij"; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef char_traits<wchar_t> traits_type; + + Inbuf inbuf1; + wistream is(&inbuf1); + + wchar_t buffer[10]; + traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X'); + + is.getline(buffer, sizeof(buffer) / sizeof(wchar_t), L'0'); + VERIFY( is.rdstate() == ios_base::goodbit ); + VERIFY( !traits_type::compare(buffer, L"123456789\0", + sizeof(buffer) / sizeof(wchar_t)) ); + VERIFY( is.gcount() == 10 ); + + is.clear(); + traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X'); + is.getline(buffer, sizeof(buffer) / sizeof(wchar_t)); + VERIFY( is.rdstate() == ios_base::failbit ); + VERIFY( !traits_type::compare(buffer, L"abcdefghi\0", + sizeof(buffer) / sizeof(wchar_t)) ); + VERIFY( is.gcount() == 9 ); + + is.clear(); + traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X'); + is.getline(buffer, sizeof(buffer) / sizeof(wchar_t)); + VERIFY( is.rdstate() == ios_base::eofbit ); + VERIFY( !traits_type::compare(buffer, L"j\0XXXXXXXX", + sizeof(buffer) / sizeof(wchar_t)) ); + VERIFY( is.gcount() == 1 ); + + is.clear(); + traits_type::assign(buffer, sizeof(buffer) / sizeof(wchar_t), L'X'); + is.getline(buffer, sizeof(buffer) / sizeof(wchar_t)); + VERIFY( is.rdstate() == (ios_base::eofbit | ios_base::failbit) ); + VERIFY( !traits_type::compare(buffer, L"\0XXXXXXXXX", + sizeof(buffer) / sizeof(wchar_t)) ); + VERIFY( is.gcount() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc new file mode 100644 index 000000000..39fb59572 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc @@ -0,0 +1,88 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <string> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +wstring +prepare(wstring::size_type len, unsigned nchunks, wchar_t delim) +{ + wstring ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (wstring::size_type j = 0; j < len; ++j) + ret.push_back(L'a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void +check(wistream& stream, const wstring& str, unsigned nchunks, wchar_t delim) +{ + bool test __attribute__((unused)) = true; + + static wchar_t buf[1000000]; + wstring::size_type index = 0, index_new = 0; + unsigned n = 0; + + while (stream.getline(buf, sizeof(buf) / sizeof(wchar_t), delim)) + { + index_new = str.find(delim, index); + VERIFY( static_cast<string::size_type>(stream.gcount()) == + index_new - index + 1 ); + VERIFY( !str.compare(index, index_new - index, buf) ); + index = index_new + 1; + ++n; + } + VERIFY( stream.gcount() == 0 ); + VERIFY( stream.eof() ); + VERIFY( n == nchunks ); +} + +void test01() +{ + const char filename[] = "wistream_getline.txt"; + + const wchar_t delim = L'|'; + const unsigned nchunks = 10; + const wstring data = prepare(777, nchunks, delim); + + wofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + wifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, nchunks, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc new file mode 100644 index 000000000..0a4376c88 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc @@ -0,0 +1,57 @@ +// 2004-11-26 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <sstream> +#include <testsuite_hooks.h> + +// DR 243. get and getline when sentry reports failure. +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf strbuf01; + wstringbuf strbuf02; + wistream istr01(&strbuf01); + wistream istr02(&strbuf02); + wchar_t buf02[2] = L"*" ; + + istr01.peek(); + VERIFY( istr01.eof() ); + + istr01.getline(0, 0); + VERIFY( istr01.gcount() == 0 ); + VERIFY( istr01.fail() ); + + istr02.peek(); + VERIFY( istr02.eof() ); + + istr02.getline(buf02, 1); + VERIFY( istr02.gcount() == 0 ); + VERIFY( istr02.fail() ); + VERIFY( buf02[0] == wchar_t() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/1.cc new file mode 100644 index 000000000..4e0ce25aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/1.cc @@ -0,0 +1,78 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + typedef std::ios::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const std::string str_01; + const std::string str_02("soul eyes: john coltrane quartet"); + std::string strtmp; + + std::stringbuf isbuf_03(str_02, std::ios_base::in); + std::stringbuf isbuf_04(str_02, std::ios_base::in); + + std::istream is_00(0); + std::istream is_03(&isbuf_03); + std::istream is_04(&isbuf_04); + std::ios_base::iostate state1, state2; + + // istream& read(char_type* s, streamsize n) + char carray[60] = ""; + is_04.read(carray, 9); + VERIFY( is_04.peek() == ':' ); + + // istream& ignore(streamsize n = 1, int_type delim = traits::eof()) + state1 = is_04.rdstate(); + is_04.ignore(); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == ' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(0); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == ' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(5, traits_type::to_int_type(' ')); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == 'j' ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/2.cc new file mode 100644 index 000000000..05236fd57 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/2.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2009 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 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.6.1.3 unformatted input functions + +// { dg-require-fileio "" } + +#include <istream> +#include <string> +#include <fstream> +#include <limits> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +string prepare(string::size_type len, unsigned nchunks, char delim) +{ + string ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (string::size_type j = 0; j < len; ++j) + ret.push_back('a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void check(istream& stream, const string& str, unsigned nchunks, char delim) +{ + bool test __attribute__((unused)) = true; + + string::size_type index = 0, index_new = 0; + unsigned n = 0; + + while (stream.ignore(numeric_limits<streamsize>::max(), delim).good()) + { + index_new = str.find(delim, index); + VERIFY( static_cast<string::size_type>(stream.gcount()) == + index_new - index + 1 ); + index = index_new + 1; + ++n; + } + VERIFY( stream.gcount() == 0 ); + VERIFY( !stream.fail() ); + VERIFY( n == nchunks ); +} + +void test01() +{ + const char filename[] = "istream_ignore.txt"; + + const char delim = '|'; + const unsigned nchunks = 10; + const string data = prepare(555, nchunks, delim); + + ofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + ifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, nchunks, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc new file mode 100644 index 000000000..218a21b54 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/3.cc @@ -0,0 +1,98 @@ +// 2004-06-20 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <fstream> +#include <limits> +#include <testsuite_hooks.h> + +// istream& ignore(streamsize n) +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char filename[] ="istream_unformatted-1.txt"; + ios_base::iostate state1, state2; + + ifstream ifstrm; + ifstrm.open(filename); + + state1 = ifstrm.rdstate(); + VERIFY( state1 == ios_base::goodbit ); + VERIFY( ifstrm.peek() == '1' ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(1); + VERIFY( ifstrm.gcount() == 1 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == '2' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(10); + VERIFY( ifstrm.gcount() == 10 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == '1' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(100); + VERIFY( ifstrm.gcount() == 100 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == '2' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(1000); + VERIFY( ifstrm.gcount() == 1000 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == '1' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(10000); + VERIFY( ifstrm.gcount() == 10000 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == '2' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(numeric_limits<streamsize>::max()); + VERIFY( ifstrm.gcount() == 5389 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( state2 == ios_base::eofbit ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/6360.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/6360.cc new file mode 100644 index 000000000..04f72a6b1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/6360.cc @@ -0,0 +1,47 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// 2002-04-19 PR libstdc++ 6360 +void +test08() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringstream ss("abcd" "\xFF" "1234ina donna coolbrith"); + char c; + ss >> c; + VERIFY( c == 'a' ); + ss.ignore(8); + ss >> c; + VERIFY( c == 'i' ); +} + +int +main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/7220.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/7220.cc new file mode 100644 index 000000000..141832692 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/char/7220.cc @@ -0,0 +1,67 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/70220 +void +test10() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef string string_type; + typedef stringbuf stringbuf_type; + typedef istream istream_type; + + streamsize n; + string_type input("abcdefg\n"); + stringbuf_type sbuf(input); + istream_type istr(&sbuf); + + istr.ignore(0); + if (istr.gcount() != 0) + test = false; + VERIFY( test ); + + istr.ignore(0, 'b'); + if (istr.gcount() != 0) + test = false; + VERIFY( test ); + + istr.ignore(); // Advance to next position. + istr.ignore(0, 'b'); + if ((n=istr.gcount()) != 0) + test = false; + VERIFY( test ); + + if (istr.peek() != 'b') + test = false; + VERIFY( test ); +} + +int +main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/1.cc new file mode 100644 index 000000000..c4a7a33d0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/1.cc @@ -0,0 +1,75 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + typedef std::ios::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const std::wstring str_01; + const std::wstring str_02(L"soul eyes: john coltrane quartet"); + std::wstring strtmp; + + std::wstringbuf isbuf_03(str_02, std::ios_base::in); + std::wstringbuf isbuf_04(str_02, std::ios_base::in); + + std::wistream is_00(0); + std::wistream is_03(&isbuf_03); + std::wistream is_04(&isbuf_04); + std::ios_base::iostate state1, state2; + + // istream& read(char_type* s, streamsize n) + wchar_t carray[60] = L""; + is_04.read(carray, 9); + VERIFY( is_04.peek() == L':' ); + + // istream& ignore(streamsize n = 1, int_type delim = traits::eof()) + state1 = is_04.rdstate(); + is_04.ignore(); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(0); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(5, traits_type::to_int_type(' ')); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L'j' ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/2.cc new file mode 100644 index 000000000..8a2421041 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/2.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <string> +#include <fstream> +#include <limits> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +wstring +prepare(wstring::size_type len, unsigned nchunks, wchar_t delim) +{ + wstring ret; + for (unsigned i = 0; i < nchunks; ++i) + { + for (wstring::size_type j = 0; j < len; ++j) + ret.push_back(L'a' + rand() % 26); + len *= 2; + ret.push_back(delim); + } + return ret; +} + +void +check(wistream& stream, const wstring& str, unsigned nchunks, wchar_t delim) +{ + bool test __attribute__((unused)) = true; + + wstring::size_type index = 0, index_new = 0; + unsigned n = 0; + + while (stream.ignore(numeric_limits<streamsize>::max(), delim).good()) + { + index_new = str.find(delim, index); + VERIFY( static_cast<string::size_type>(stream.gcount()) == + index_new - index + 1 ); + index = index_new + 1; + ++n; + } + VERIFY( stream.gcount() == 0 ); + VERIFY( !stream.fail() ); + VERIFY( n == nchunks ); +} + +void test01() +{ + const char filename[] = "wistream_ignore.txt"; + + const wchar_t delim = L'|'; + const unsigned nchunks = 10; + const wstring data = prepare(555, nchunks, delim); + + wofstream ofstrm; + ofstrm.open(filename); + ofstrm.write(data.data(), data.size()); + ofstrm.close(); + + wifstream ifstrm; + ifstrm.open(filename); + check(ifstrm, data, nchunks, delim); + ifstrm.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc new file mode 100644 index 000000000..edd822df4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/3.cc @@ -0,0 +1,94 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <fstream> +#include <limits> +#include <testsuite_hooks.h> + +// istream& ignore(streamsize n) +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char filename[] ="istream_unformatted-1.txt"; + ios_base::iostate state1, state2; + + wifstream ifstrm; + ifstrm.open(filename); + + state1 = ifstrm.rdstate(); + VERIFY( state1 == ios_base::goodbit ); + VERIFY( ifstrm.peek() == L'1' ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(1); + VERIFY( ifstrm.gcount() == 1 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == L'2' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(10); + VERIFY( ifstrm.gcount() == 10 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == L'1' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(100); + VERIFY( ifstrm.gcount() == 100 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == L'2' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(1000); + VERIFY( ifstrm.gcount() == 1000 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == L'1' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(10000); + VERIFY( ifstrm.gcount() == 10000 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( ifstrm.peek() == L'2' ); + + state1 = ifstrm.rdstate(); + ifstrm.ignore(numeric_limits<streamsize>::max()); + VERIFY( ifstrm.gcount() == 5389 ); + state2 = ifstrm.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( state2 == ios_base::eofbit ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/6360.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/6360.cc new file mode 100644 index 000000000..3e837e8b7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/6360.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// 2002-04-19 PR libstdc++ 6360 +void +test08() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringstream ss(L"abcd" L"\xFF" L"1234ina donna coolbrith"); + wchar_t c; + ss >> c; + VERIFY( c == L'a' ); + ss.ignore(8); + ss >> c; + VERIFY( c == L'i' ); +} + +int +main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/7220.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/7220.cc new file mode 100644 index 000000000..d3d7f1ec0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ignore/wchar_t/7220.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/70220 +void +test10() +{ + using namespace std; + bool test __attribute__((unused)) = true; + typedef wstring string_type; + typedef wstringbuf stringbuf_type; + typedef wistream istream_type; + + streamsize n; + string_type input(L"abcdefg\n"); + stringbuf_type sbuf(input); + istream_type istr(&sbuf); + + istr.ignore(0); + if (istr.gcount() != 0) + test = false; + VERIFY( test ); + + istr.ignore(0, L'b'); + if (istr.gcount() != 0) + test = false; + VERIFY( test ); + + istr.ignore(); // Advance to next position. + istr.ignore(0, L'b'); + if ((n=istr.gcount()) != 0) + test = false; + VERIFY( test ); + + if (istr.peek() != L'b') + test = false; + VERIFY( test ); +} + +int +main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc new file mode 100644 index 000000000..39a3fdff3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/1.cc @@ -0,0 +1,92 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + typedef std::ios::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const std::string str_01; + const std::string str_02("soul eyes: john coltrane quartet"); + std::string strtmp; + + std::stringbuf isbuf_03(str_02, std::ios_base::in); + std::stringbuf isbuf_04(str_02, std::ios_base::in); + + std::istream is_00(0); + std::istream is_03(&isbuf_03); + std::istream is_04(&isbuf_04); + std::ios_base::iostate state1, state2; + + char carray[60] = ""; + + // istream& ignore(streamsize n = 1, int_type delim = traits::eof()) + is_04.read(carray, 9); + VERIFY( is_04.peek() == ':' ); + + state1 = is_04.rdstate(); + is_04.ignore(); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == ' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(0); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == ' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(5, traits_type::to_int_type(' ')); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == 'j' ); + + // int_type peek() + state1 = is_04.rdstate(); + VERIFY( is_04.peek() == 'j' ); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + + is_04.ignore(30); + state1 = is_04.rdstate(); + VERIFY( is_04.peek() == traits_type::eof() ); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 != state2 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc new file mode 100644 index 000000000..7263c7c42 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/12296.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/12296 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream stream; + VERIFY( stream.rdstate() == ios_base::goodbit ); + istringstream::int_type c = stream.peek(); + VERIFY( c == istringstream::traits_type::eof() ); + VERIFY( stream.rdstate() == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc new file mode 100644 index 000000000..5d02fc912 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/char/6414.cc @@ -0,0 +1,49 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +// fstreams +void test04(void) +{ + bool test __attribute__((unused)) = true; + std::istream::pos_type pos01, pos02; + const char str_lit01[] = "istream_seeks-1.txt"; + std::ifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); + + // libstdc++/6414 + if01.seekg(0, std::ios_base::beg); + pos01 = if01.tellg(); + if01.peek(); + pos02 = if01.tellg(); + VERIFY( pos02 == pos01 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc new file mode 100644 index 000000000..612e60600 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/1.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + typedef std::wios::traits_type traits_type; + + bool test __attribute__((unused)) = true; + const std::wstring str_01; + const std::wstring str_02(L"soul eyes: john coltrane quartet"); + std::wstring strtmp; + + std::wstringbuf isbuf_03(str_02, std::ios_base::in); + std::wstringbuf isbuf_04(str_02, std::ios_base::in); + + std::wistream is_00(0); + std::wistream is_03(&isbuf_03); + std::wistream is_04(&isbuf_04); + std::ios_base::iostate state1, state2; + + wchar_t carray[60] = L""; + + // istream& ignore(streamsize n = 1, int_type delim = traits::eof()) + is_04.read(carray, 9); + VERIFY( is_04.peek() == L':' ); + + state1 = is_04.rdstate(); + is_04.ignore(); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(0); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L' ' ); + + state1 = is_04.rdstate(); + is_04.ignore(5, traits_type::to_int_type(' ')); + VERIFY( is_04.gcount() == 1 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L'j' ); + + // int_type peek() + state1 = is_04.rdstate(); + VERIFY( is_04.peek() == L'j' ); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + + is_04.ignore(30); + state1 = is_04.rdstate(); + VERIFY( is_04.peek() == traits_type::eof() ); + VERIFY( is_04.gcount() == 0 ); + state2 = is_04.rdstate(); + VERIFY( state1 != state2 ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc new file mode 100644 index 000000000..c1fcce837 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/12296.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 2009 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 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.6.1.3 unformatted input functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/12296 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wistringstream stream; + VERIFY( stream.rdstate() == ios_base::goodbit ); + wistringstream::int_type c = stream.peek(); + VERIFY( c == wistringstream::traits_type::eof() ); + VERIFY( stream.rdstate() == ios_base::eofbit ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc new file mode 100644 index 000000000..9c74fa3f4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/peek/wchar_t/6414.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +// fstreams +void test04(void) +{ + bool test __attribute__((unused)) = true; + std::wistream::pos_type pos01, pos02; + const char str_lit01[] = "wistream_seeks-1.txt"; + std::wifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); + + // libstdc++/6414 + if01.seekg(0, std::ios_base::beg); + pos01 = if01.tellg(); + if01.peek(); + pos02 = if01.tellg(); + VERIFY( pos02 == pos01 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc new file mode 100644 index 000000000..123d488fd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/putback/char/1.cc @@ -0,0 +1,75 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + const std::string str_01; + const std::string str_02("soul eyes: john coltrane quartet"); + std::string strtmp; + + std::stringbuf isbuf_03(str_02, std::ios_base::in); + std::stringbuf isbuf_04(str_02, std::ios_base::in); + std::stringbuf isbuf_05(str_02, std::ios_base::in); + + std::istream is_00(&isbuf_05); + std::istream is_03(&isbuf_03); + std::istream is_04(&isbuf_04); + std::ios_base::iostate state1, state2; + + // istream& putback(char c) + is_04.ignore(30); + is_04.clear(); + state1 = is_04.rdstate(); + is_04.putback('t'); + VERIFY( is_04.gcount() == 0 ); // DR 60 + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == 't' ); + + // istream& unget() + is_04.clear(); + state1 = is_04.rdstate(); + is_04.unget(); + VERIFY( is_04.gcount() == 0 ); // DR 60 + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == 'r' ); + + // int sync() + is_00.ignore(10); + int count1 = is_00.gcount(); + is_00.sync(); + int count2 = is_00.gcount(); + VERIFY (count1 == count2 ); // DR 60 +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/putback/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/putback/wchar_t/1.cc new file mode 100644 index 000000000..3cd981b36 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/putback/wchar_t/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + const std::wstring str_01; + const std::wstring str_02(L"soul eyes: john coltrane quartet"); + std::wstring strtmp; + + std::wstringbuf isbuf_03(str_02, std::ios_base::in); + std::wstringbuf isbuf_04(str_02, std::ios_base::in); + std::wstringbuf isbuf_05(str_02, std::ios_base::in); + + std::wistream is_00(&isbuf_05); + std::wistream is_03(&isbuf_03); + std::wistream is_04(&isbuf_04); + std::ios_base::iostate state1, state2; + + // istream& putback(char_type c) + is_04.ignore(30); + is_04.clear(); + state1 = is_04.rdstate(); + is_04.putback(L't'); + VERIFY( is_04.gcount() == 0 ); // DR 60 + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L't' ); + + // istream& unget() + is_04.clear(); + state1 = is_04.rdstate(); + is_04.unget(); + VERIFY( is_04.gcount() == 0 ); // DR 60 + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( is_04.peek() == L'r' ); + + // int sync() + is_00.ignore(10); + int count1 = is_00.gcount(); + is_00.sync(); + int count2 = is_00.gcount(); + VERIFY (count1 == count2 ); // DR 60 +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/1.cc new file mode 100644 index 000000000..3879f7b42 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/1.cc @@ -0,0 +1,72 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009, 2010 +// 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 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.6.1.3 unformatted input functions + +#include <cstring> // for strncmp,... +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + const std::string str_02("soul eyes: john coltrane quartet"); + + std::stringbuf isbuf_03(str_02, std::ios_base::in); + std::stringbuf isbuf_04(str_02, std::ios_base::in); + + std::istream is_00(0); + std::istream is_03(&isbuf_03); + std::istream is_04(&isbuf_04); + std::ios_base::iostate state1, state2, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + + // istream& read(char_type* s, streamsize n) + char carray[60] = ""; + state1 = is_04.rdstate(); + is_04.read(carray, 0); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + + state1 = is_04.rdstate(); + is_04.read(carray, 9); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !std::strncmp(carray, "soul eyes", 9) ); + VERIFY( is_04.peek() == ':' ); + + state1 = is_03.rdstate(); + is_03.read(carray, 60); + state2 = is_03.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & stateeof) ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( !std::strncmp(carray, "soul eyes: john coltrane quartet", 35) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/2.cc new file mode 100644 index 000000000..acb1b800a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/2.cc @@ -0,0 +1,58 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// Jim Parsons <parsons at clearway dot com> +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00177.html +void +test04() +{ + bool test __attribute__((unused)) = true; + + const std::string str_00("Red_Garland_Qunitet-Soul_Junction"); + char c_array[str_00.size() + 4]; + + std::stringbuf isbuf_00(str_00, std::ios_base::in); + std::istream is_00(&isbuf_00); + std::ios_base::iostate state1, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + + state1 = stateeof | statefail; + VERIFY( is_00.gcount() == 0 ); + is_00.read(c_array, str_00.size() + 1); + VERIFY( is_00.gcount() == static_cast<std::streamsize>(str_00.size()) ); + VERIFY( is_00.rdstate() == state1 ); + + is_00.read(c_array, str_00.size()); + VERIFY( is_00.rdstate() == state1 ); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/3.cc new file mode 100644 index 000000000..c3c7769d4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/char/3.cc @@ -0,0 +1,46 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// Theodore Papadopoulo +void +test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream iss("Juana Briones"); + char tab[13]; + iss.read(tab, 13); + if (!iss) + test = false; + VERIFY( test ); +} + +int +main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/1.cc new file mode 100644 index 000000000..508e0c8cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/1.cc @@ -0,0 +1,69 @@ +// Copyright (C) 2004, 2009, 2010 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 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.6.1.3 unformatted input functions + +#include <cwchar> // for wcsncmp,... +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void +test01() +{ + bool test __attribute__((unused)) = true; + const std::wstring str_02(L"soul eyes: john coltrane quartet"); + + std::wstringbuf isbuf_03(str_02, std::ios_base::in); + std::wstringbuf isbuf_04(str_02, std::ios_base::in); + + std::wistream is_00(0); + std::wistream is_03(&isbuf_03); + std::wistream is_04(&isbuf_04); + std::ios_base::iostate state1, state2, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + + // istream& read(char_type* s, streamsize n) + wchar_t carray[60] = L""; + state1 = is_04.rdstate(); + is_04.read(carray, 0); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + + state1 = is_04.rdstate(); + is_04.read(carray, 9); + state2 = is_04.rdstate(); + VERIFY( state1 == state2 ); + VERIFY( !std::wcsncmp(carray, L"soul eyes", 9) ); + VERIFY( is_04.peek() == L':' ); + + state1 = is_03.rdstate(); + is_03.read(carray, 60); + state2 = is_03.rdstate(); + VERIFY( state1 != state2 ); + VERIFY( static_cast<bool>(state2 & stateeof) ); + VERIFY( static_cast<bool>(state2 & statefail) ); + VERIFY( !std::wcsncmp(carray, L"soul eyes: john coltrane quartet", 35) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/2.cc new file mode 100644 index 000000000..2ea0b663d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/2.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// Jim Parsons <parsons at clearway dot com> +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00177.html +void +test04() +{ + bool test __attribute__((unused)) = true; + + const std::wstring str_00(L"Red_Garland_Qunitet-Soul_Junction"); + wchar_t c_array[str_00.size() + 4]; + + std::wstringbuf isbuf_00(str_00, std::ios_base::in); + std::wistream is_00(&isbuf_00); + std::ios_base::iostate state1, statefail, stateeof; + statefail = std::ios_base::failbit; + stateeof = std::ios_base::eofbit; + + state1 = stateeof | statefail; + VERIFY( is_00.gcount() == 0 ); + is_00.read(c_array, str_00.size() + 1); + VERIFY( is_00.gcount() == static_cast<std::streamsize>(str_00.size()) ); + VERIFY( is_00.rdstate() == state1 ); + + is_00.read(c_array, str_00.size()); + VERIFY( is_00.rdstate() == state1 ); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/3.cc new file mode 100644 index 000000000..0de14bdd8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/read/wchar_t/3.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// Theodore Papadopoulo +void +test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wistringstream iss(L"Juana Briones"); + wchar_t tab[13]; + iss.read(tab, 13); + if (!iss) + test = false; + VERIFY( test ); +} + +int +main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-1.cc new file mode 100644 index 000000000..4e126da30 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-1.cc @@ -0,0 +1,55 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/6746 +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + streamsize sum = 0; + istringstream iss("shamma shamma"); + + // test01 + size_t i = iss.rdbuf()->in_avail(); + VERIFY( i != 0 ); + + // test02 + streamsize extracted; + do + { + char buf[1024]; + extracted = iss.readsome(buf, sizeof buf); + sum += extracted; + } + while (iss.good() && extracted); + VERIFY( sum != 0 ); +} + +int +main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc new file mode 100644 index 000000000..ed74751dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/6746-2.cc @@ -0,0 +1,64 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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/>. + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// 27.6.1.3 unformatted input functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +// libstdc++/6746 +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + streamsize sum = 0; + ifstream ifs("istream_unformatted-1.tst"); + + // test01 + size_t i = ifs.rdbuf()->in_avail(); + VERIFY( i != 0 ); + + // test02 + streamsize extracted; + do + { + char buf[1024]; + extracted = ifs.readsome(buf, sizeof buf); + sum += extracted; + } + while (ifs.good() && extracted); + VERIFY( sum != 0 ); +} + +int +main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/8258.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/8258.cc new file mode 100644 index 000000000..fad9ea233 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/char/8258.cc @@ -0,0 +1,48 @@ +// 1999-08-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/8258 +class mybuf : public std::basic_streambuf<char> +{ }; + +void test11() +{ + bool test __attribute__((unused)) = true; + using namespace std; + char arr[10]; + mybuf sbuf; + basic_istream<char, char_traits<char> > istr(&sbuf); + + VERIFY(istr.rdstate() == ios_base::goodbit); + VERIFY(istr.readsome(arr, 10) == 0); + VERIFY(istr.rdstate() == ios_base::goodbit); +} + +int +main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-1.cc new file mode 100644 index 000000000..a710aea39 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-1.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/6746 +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + streamsize sum = 0; + wistringstream iss(L"shamma shamma"); + + // test01 + size_t i = iss.rdbuf()->in_avail(); + VERIFY( i != 0 ); + + // test02 + streamsize extracted; + do + { + wchar_t buf[1024]; + extracted = iss.readsome(buf, sizeof(buf) / sizeof(wchar_t)); + sum += extracted; + } + while (iss.good() && extracted); + VERIFY( sum != 0 ); +} + +int +main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc new file mode 100644 index 000000000..c77031322 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/6746-2.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2004, 2009 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 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/>. + +// The ARM simulator does not provide support for "fstat", which +// causes "in_avail" to return an incorrect value. +// { dg-do run { xfail arm*-*-elf arm*-*-eabi } } + +// { dg-require-binary-io "" } + +// 27.6.1.3 unformatted input functions +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <fstream> +#include <testsuite_hooks.h> + +// libstdc++/6746 +void test13() +{ + using namespace std; + bool test __attribute__((unused)) = true; + streamsize sum = 0; + wifstream ifs("wistream_unformatted-1.tst"); + + // test01 + size_t i = ifs.rdbuf()->in_avail(); + VERIFY( i != 0 ); + + // test02 + streamsize extracted; + do + { + wchar_t buf[1024]; + extracted = ifs.readsome(buf, sizeof(buf) / sizeof(wchar_t)); + sum += extracted; + } + while (ifs.good() && extracted); + VERIFY( sum != 0 ); +} + +int +main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/8258.cc b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/8258.cc new file mode 100644 index 000000000..725c90259 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/readsome/wchar_t/8258.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions + +#include <istream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/8258 +class mybuf : public std::basic_streambuf<wchar_t> +{ }; + +void test11() +{ + bool test __attribute__((unused)) = true; + using namespace std; + wchar_t arr[10]; + mybuf sbuf; + basic_istream<wchar_t, char_traits<wchar_t> > istr(&sbuf); + + VERIFY( istr.rdstate() == ios_base::goodbit ); + VERIFY( istr.readsome(arr, 10) == 0 ); + VERIFY( istr.rdstate() == ios_base::goodbit ); +} + +int +main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_istream/requirements/base_classes.cc new file mode 100644 index 000000000..6454081f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/requirements/base_classes.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <istream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::istream test_type; + typedef std::ios base_type; + + std::stringbuf buf; + const test_type& obj = *new test_type(&buf); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_istream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6118eb137 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/requirements/explicit_instantiation.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.6.1.1 basic_istream +// NB: This file is for testing istream with NO OTHER INCLUDES. + +#include <istream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_istream<type_t, char_traits<type_t> >; + template class basic_istream<pod_char, char_traits<pod_char> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_istream/requirements/typedefs.cc new file mode 100644 index 000000000..f6167c070 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/requirements/typedefs.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.1 basic_istream +// NB: This file is for testing istream with NO OTHER INCLUDES. + +#include <istream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::istream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2.cc new file mode 100644 index 000000000..56800531d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/2.cc @@ -0,0 +1,48 @@ +// 2003-04-22 pme + +// Copyright (C) 2003, 2009 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 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.6.1.3 unformatted input functions +// DR 60 -- seekg does not effect calls to gcount + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream ist("the lamb lies down on broadway"); + ios::pos_type pos = ist.tellg(); + ist.ignore(4); + int count1 = ist.gcount(); + ist.seekg(pos); + int count2 = ist.gcount(); + VERIFY( count1 == count2 ); + ist.seekg(ios::off_type(pos), ios::beg); + count2 = ist.gcount(); + VERIFY( count1 == count2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/26211.cc new file mode 100644 index 000000000..be2865078 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/26211.cc @@ -0,0 +1,63 @@ +// 2010-11-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/26211 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istringstream::pos_type pos_type; + + istringstream iss("Duos for Doris"); + ostringstream oss; + + const pos_type p0 = iss.tellg(); + VERIFY( p0 == pos_type(0) ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + + iss.seekg(0, ios_base::beg); + VERIFY( iss.good() ); + + iss.seekg(0, ios_base::beg); + VERIFY( !iss.fail() ); + VERIFY( iss.tellg() == p0 ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + + iss.seekg(p0); + VERIFY( iss.good() ); + + iss.seekg(p0); + VERIFY( !iss.fail() ); + VERIFY( iss.tellg() == p0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-1.cc new file mode 100644 index 000000000..1c28cf369 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-1.cc @@ -0,0 +1,52 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 +// 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8348 +void test06(void) +{ + using namespace std; + bool test __attribute__((unused)) = true; + string num1("555"); + + // seekg + { + istringstream iss(num1); + istream::pos_type pos1 = iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(pos1); + VERIFY( test = !iss.fail() ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-2.cc new file mode 100644 index 000000000..899a48d78 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/8348-2.cc @@ -0,0 +1,52 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 +// 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8348 +void test06(void) +{ + using namespace std; + bool test __attribute__((unused)) = true; + string num1("555"); + + // seekg + { + istringstream iss(num1); + iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(0, ios_base::beg); + VERIFY( test = !iss.fail() ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..3d66ce70b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/exceptions_badbit_throw.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + + istream::pos_type pos; + + try + { + stream.seekg(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + + istream::off_type off(5); + + try + { + stream.seekg(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc new file mode 100644 index 000000000..503841a75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/fstream.cc @@ -0,0 +1,128 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// fstreams +void test04(void) +{ + typedef std::istream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "istream_seeks-1.txt"; + const char str_lit02[] = "istream_seeks-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); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( if03.good() ); + + std::istream is01(if01.rdbuf()); + std::istream is02(if02.rdbuf()); + std::istream is03(if03.rdbuf()); + + pos01 = is01.tellg(); + pos02 = is01.tellg(); + pos03 = is02.tellg(); + pos04 = is02.tellg(); + pos05 = is03.tellg(); + pos06 = is03.tellg(); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 + off_type(10) ); + VERIFY( state01 == state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 + off_type(10) ); + VERIFY( state01 == state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/sstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/sstream.cc new file mode 100644 index 000000000..183decc9e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/char/sstream.cc @@ -0,0 +1,136 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// stringstreams +void test05(void) +{ + typedef std::istream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "istream_seeks-1.tst"; + std::ifstream if01(str_lit01); + std::ifstream if02(str_lit01); + std::ifstream if03(str_lit01); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( 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(); + pos03 = is02.tellg(); + pos04 = is02.tellg(); + pos05 = is03.tellg(); + pos06 = is03.tellg(); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 ); // as only out buffer + VERIFY( state01 != state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 ); // as only out buffer + VERIFY( state01 == state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/2.cc new file mode 100644 index 000000000..c4088d8e6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/2.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// DR 60 -- seekg does not effect calls to gcount + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wistringstream ist(L"the lamb lies down on broadway"); + wios::pos_type pos = ist.tellg(); + ist.ignore(4); + int count1 = ist.gcount(); + ist.seekg(pos); + int count2 = ist.gcount(); + VERIFY( count1 == count2 ); + ist.seekg(wios::off_type(pos), wios::beg); + count2 = ist.gcount(); + VERIFY( count1 == count2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc new file mode 100644 index 000000000..2a73e1ec7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/26211.cc @@ -0,0 +1,63 @@ +// 2010-11-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/26211 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef wistringstream::pos_type pos_type; + + wistringstream iss(L"Duos for Doris"); + wostringstream oss; + + const pos_type p0 = iss.tellg(); + VERIFY( p0 == pos_type(0) ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + + iss.seekg(0, ios_base::beg); + VERIFY( iss.good() ); + + iss.seekg(0, ios_base::beg); + VERIFY( !iss.fail() ); + VERIFY( iss.tellg() == p0 ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + + iss.seekg(p0); + VERIFY( iss.good() ); + + iss.seekg(p0); + VERIFY( !iss.fail() ); + VERIFY( iss.tellg() == p0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc new file mode 100644 index 000000000..f2d323744 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-1.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 2005, 2006, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8348 +void test06(void) +{ + using namespace std; + bool test __attribute__((unused)) = true; + wstring num1(L"555"); + + // seekg + { + wistringstream iss(num1); + wistream::pos_type pos1 = iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(pos1); + VERIFY( test = !iss.fail() ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-2.cc new file mode 100644 index 000000000..d428a88ba --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/8348-2.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 2005, 2006, 2009, 2010 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8348 +void test06(void) +{ + using namespace std; + bool test __attribute__((unused)) = true; + wstring num1(L"555"); + + // seekg + { + wistringstream iss(num1); + iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(0, ios_base::beg); + VERIFY( test = !iss.fail() ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..849e26863 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wistream stream(&bib); + stream.exceptions(ios_base::badbit); + + wistream::pos_type pos; + + try + { + stream.seekg(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +void test02() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wistream stream(&bib); + stream.exceptions(ios_base::badbit); + + wistream::off_type off(5); + + try + { + stream.seekg(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc new file mode 100644 index 000000000..2aa7260e7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/fstream.cc @@ -0,0 +1,124 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// fstreams +void test04(void) +{ + typedef std::wistream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::wistream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "wistream_seeks-1.txt"; + const char str_lit02[] = "wistream_seeks-2.txt"; + std::wifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); + std::wifstream if02(str_lit01, std::ios_base::in); + std::wifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( if03.good() ); + + std::wistream is01(if01.rdbuf()); + std::wistream is02(if02.rdbuf()); + std::wistream is03(if03.rdbuf()); + + pos01 = is01.tellg(); + pos02 = is01.tellg(); + pos03 = is02.tellg(); + pos04 = is02.tellg(); + pos05 = is03.tellg(); + pos06 = is03.tellg(); + + // istream& seekg(pos_type) + // istream& seekg(off_type, ios_base::seekdir) + + // cur + // NB: see library issues list 136. It's the v3 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 + off_type(10) ); + VERIFY( state01 == state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 + off_type(10) ); + VERIFY( state01 == state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/sstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/sstream.cc new file mode 100644 index 000000000..dcc196b8b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/seekg/wchar_t/sstream.cc @@ -0,0 +1,134 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// stringstreams +void test05(void) +{ + typedef std::istream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::wistream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "wistream_seeks-1.tst"; + std::wifstream if01(str_lit01); + std::wifstream if02(str_lit01); + std::wifstream if03(str_lit01); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( if03.good() ); + + std::wstringbuf strbuf01(std::ios_base::in | std::ios_base::out); + if01 >> &strbuf01; + // initialize stringbufs that are ios_base::out + std::wstringbuf strbuf03(strbuf01.str(), std::ios_base::out); + // initialize stringbufs that are ios_base::in + std::wstringbuf strbuf02(strbuf01.str(), std::ios_base::in); + + std::wistream is01(&strbuf01); + std::wistream is02(&strbuf02); + std::wistream is03(&strbuf03); + + // pos_type tellg() + // in | out + pos01 = is01.tellg(); + pos02 = is01.tellg(); + pos03 = is02.tellg(); + pos04 = is02.tellg(); + pos05 = is03.tellg(); + pos06 = is03.tellg(); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(10, std::ios_base::cur); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(10, std::ios_base::cur); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 ); // as only out buffer + VERIFY( state01 != state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // beg + state01 = is01.rdstate(); + is01.seekg(20, std::ios_base::beg); + state02 = is01.rdstate(); + pos01 = is01.tellg(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); + + state01 = is02.rdstate(); + is02.seekg(20, std::ios_base::beg); + state02 = is02.rdstate(); + pos03 = is02.tellg(); + VERIFY( pos03 == pos04 + off_type(10) ); + VERIFY( state01 == state02 ); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + state01 = is03.rdstate(); + is03.seekg(20, std::ios_base::beg); + state02 = is03.rdstate(); + pos05 = is03.tellg(); + VERIFY( pos05 == pos06 ); // as only out buffer + VERIFY( state01 == state02 ); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/1.cc new file mode 100644 index 000000000..e91d151fb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/1.cc @@ -0,0 +1,57 @@ +// 1999-10-14 bkoz + +// Copyright (C) 1999, 2001, 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.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + const char* lit01 = "stereolab on the bolsinga tip"; + const std::string str01(lit01); + + std::stringbuf strbuf01; + std::stringbuf strbuf02(str01); + std::istream istr01(&strbuf01); + std::istream istr02(&strbuf02); + + // test negatives + std::istream::sentry sentry01(istr01); + VERIFY( bool(sentry01) == false ); + + std::istream::sentry sentry02(istr01, true); + VERIFY( bool(sentry02) == false ); + + // positive tests + std::istream::sentry sentry03(istr02); + VERIFY( bool(sentry03) == true ); + + std::istream::sentry sentry04(istr02, true); + VERIFY( bool(sentry04) == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc new file mode 100644 index 000000000..48ce9df6f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/12297.cc @@ -0,0 +1,41 @@ +// 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.6.1.1.2 class basic_istream::sentry + +#include <sstream> +#include <testsuite_hooks.h> + +int main() +{ + using namespace std; + istringstream stream; + stream.exceptions(ios_base::eofbit); + + try + { + istream::sentry sentry(stream, false); + VERIFY( false ); + } + catch (ios_base::failure&) + { + VERIFY( stream.rdstate() == (ios_base::eofbit | ios_base::failbit) ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/2.cc new file mode 100644 index 000000000..4c21fe089 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/2.cc @@ -0,0 +1,51 @@ +// 1999-10-14 bkoz + +// Copyright (C) 1999, 2001, 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.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/944 +void +test02() +{ + using namespace std; + istringstream in("80.21 56.89 12.3"); + bool test __attribute__((unused)) = true; + int i = 0; + double x; + + // ios_base::eof == 2 + while (in >> x) + { + ++i; + if (i > 3) + break; + } + VERIFY( i == 3 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/3.cc new file mode 100644 index 000000000..c46103464 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/char/3.cc @@ -0,0 +1,44 @@ +// 1999-10-14 bkoz + +// Copyright (C) 1999, 2001, 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.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9562 +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf strbuf01; + std::istream strm1(&strbuf01); + const std::istream::sentry sentry1(strm1); + + VERIFY( bool(sentry1) == false ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/pod/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/pod/1.cc new file mode 100644 index 000000000..e995f9528 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/pod/1.cc @@ -0,0 +1,166 @@ +// 1999-10-14 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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/>. + + +// 27.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <typeinfo> +#include <ext/pod_char_traits.h> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +void test01() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef basic_string<pod_ushort> string_type; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_istream<pod_ushort> istream_type; + + bool test __attribute__((unused)) = true; + + + const string_type str01; + stringbuf_type strbuf01; + stringbuf_type strbuf02(str01); + istream_type istr01(&strbuf01); + istream_type istr02(&strbuf02); + + // test negatives + try + { + istream_type::sentry sentry01(istr01); + } + catch (std::bad_cast& obj) + { + // Ok, throws bad_cast because locale has no ctype facet. + } + catch (...) + { + VERIFY( false ); + } + + try + { + istream_type::sentry sentry02(istr01, true); + } + catch (std::bad_cast& obj) + { + // Ok, throws bad_cast because locale has no ctype facet. + } + catch (...) + { + VERIFY( false ); + } + + // imbued. + const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>); + istr01.imbue(loc); + try + { + istream_type::sentry sentry01(istr01); + VERIFY( bool(sentry01) == false ); + } + catch (...) + { + VERIFY( false ); + } + + try + { + istream_type::sentry sentry02(istr01, true); + VERIFY( bool(sentry02) == false ); + } + catch (...) + { + VERIFY( false ); + } + + // test positive + try + { + istream_type::sentry sentry03(istr02); + } + catch (std::bad_cast& obj) + { + // Ok, throws bad_cast because locale has no ctype facet. + } + catch (...) + { + VERIFY( false ); + } + + try + { + istream_type::sentry sentry04(istr02, true); + } + catch (std::bad_cast& obj) + { + // Ok, throws bad_cast because locale has no ctype facet. + } + catch (...) + { + VERIFY( false ); + } + + // imbued. + istr02.imbue(loc); + try + { + istr02.clear(); + istream_type::sentry sentry03(istr02); + // ... as eofbit set. + VERIFY( bool(sentry03) == false ); + } + catch (...) + { + VERIFY( false ); + } + + try + { + istr02.clear(); + istream_type::sentry sentry04(istr02, true); + VERIFY( bool(sentry04) == true ); + } + catch (...) + { + VERIFY( false ); + } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/1.cc new file mode 100644 index 000000000..1e4b11723 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/1.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + const wchar_t* lit01 = L"stereolab on the bolsinga tip"; + const std::wstring str01(lit01); + + std::wstringbuf strbuf01; + std::wstringbuf strbuf02(str01); + std::wistream istr01(&strbuf01); + std::wistream istr02(&strbuf02); + + // test negatives + std::wistream::sentry sentry01(istr01); + VERIFY( bool(sentry01) == false ); + + std::wistream::sentry sentry02(istr01, true); + VERIFY( bool(sentry02) == false ); + + // positive tests + std::wistream::sentry sentry03(istr02); + VERIFY( bool(sentry03) == true ); + + std::wistream::sentry sentry04(istr02, true); + VERIFY( bool(sentry04) == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc new file mode 100644 index 000000000..3ce0854d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/12297.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.1.2 class basic_istream::sentry + +#include <sstream> +#include <testsuite_hooks.h> + +int main() +{ + using namespace std; + wistringstream stream; + stream.exceptions(ios_base::eofbit); + + try + { + wistream::sentry sentry(stream, false); + VERIFY( false ); + } + catch (ios_base::failure&) + { + VERIFY( stream.rdstate() == (ios_base::eofbit | ios_base::failbit) ); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/2.cc new file mode 100644 index 000000000..8266ea6f9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/2.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/944 +void +test02() +{ + using namespace std; + wistringstream in(L"80.21 56.89 12.3"); + bool test __attribute__((unused)) = true; + int i = 0; + double x; + + // ios_base::eof == 2 + while (in >> x) + { + ++i; + if (i > 3) + break; + } + VERIFY( i == 3 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/3.cc new file mode 100644 index 000000000..e325678c9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/sentry/wchar_t/3.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.1.1.2 class basic_istream::sentry + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9562 +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf strbuf01; + std::wistream strm1(&strbuf01); + const std::wistream::sentry sentry1(strm1); + + VERIFY( bool(sentry1) == false ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc new file mode 100644 index 000000000..b2680d563 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/1.cc @@ -0,0 +1,68 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef ios::off_type off_type; + typedef ios::pos_type pos_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "istream_seeks-1.tst"; + + // in + istringstream ist1; + pos_type p3 = ist1.tellg(); + + ifstream ifs1; + pos_type p4 = ifs1.tellg(); + + // N.B. We implement the resolution of DR 453 and + // istringstream::tellg() doesn't fail. + VERIFY( p3 == pos_type(off_type(0)) ); + VERIFY( p4 == pos_type(off_type(-1)) ); + + // in + // test ctors leave things in the same positions... + istringstream ist2("bob_marley:kaya"); + p3 = ist2.tellg(); + + ifstream ifs2(str_lit01); + p4 = ifs2.tellg(); + + VERIFY( p3 == p4 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/2.cc new file mode 100644 index 000000000..08cdee697 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/2.cc @@ -0,0 +1,44 @@ +// 2003-04-22 pme + +// Copyright (C) 2003, 2009 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 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.6.1.3 unformatted input functions +// DR 60 -- tellg does not effect calls to gcount + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + istringstream ist("three sides live"); + ist.ignore(4); + int count1 = ist.gcount(); + ist.tellg(); + int count2 = ist.gcount(); + VERIFY( count1 == count2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/26211.cc new file mode 100644 index 000000000..6677f9410 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/26211.cc @@ -0,0 +1,49 @@ +// 2010-11-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/26211 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istringstream::pos_type pos_type; + + istringstream iss("Duos for Doris"); + ostringstream oss; + + VERIFY( iss.tellg() == pos_type(0) ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + VERIFY( iss.tellg() == pos_type(-1) ); + + iss.clear(); + VERIFY( iss.tellg() == pos_type(14) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/8348.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/8348.cc new file mode 100644 index 000000000..62bdd5025 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/8348.cc @@ -0,0 +1,77 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 +// 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8348 +void test06(void) +{ + using namespace std; + bool test __attribute__((unused)) = true; + string num1("555"); + + // tellg + { + istringstream iss(num1); + iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.clear(); + iss.tellg(); + VERIFY( test = !iss.fail() ); + } + + // seekg + { + istringstream iss(num1); + iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(0, ios_base::beg); + VERIFY( test = !iss.fail() ); + } + + // seekg + { + istringstream iss(num1); + istream::pos_type pos1 = iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(pos1); + VERIFY( test = !iss.fail() ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..9e58be998 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// 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/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + istream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellg(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc new file mode 100644 index 000000000..da57149c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/fstream.cc @@ -0,0 +1,88 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// fstreams +void test04(void) +{ + typedef std::istream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "istream_seeks-1.txt"; + const char str_lit02[] = "istream_seeks-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); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( 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(); + VERIFY( pos01 == pos02 ); + + // in + pos03 = is02.tellg(); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + // out + pos05 = is03.tellg(); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/sstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/sstream.cc new file mode 100644 index 000000000..4db3fc124 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/char/sstream.cc @@ -0,0 +1,94 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// stringstreams +void test05(void) +{ + typedef std::istream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::istream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "istream_seeks-1.tst"; + std::ifstream if01(str_lit01); + std::ifstream if02(str_lit01); + std::ifstream if03(str_lit01); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( 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(); + VERIFY( pos01 == pos02 ); + + // in + pos03 = is02.tellg(); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + // out + pos05 = is03.tellg(); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/1.cc new file mode 100644 index 000000000..798b7fe6f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/1.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef ios::off_type off_type; + typedef ios::pos_type pos_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "wistream_seeks-1.tst"; + + // in + wistringstream ist1; + pos_type p3 = ist1.tellg(); + + wifstream ifs1; + pos_type p4 = ifs1.tellg(); + + // N.B. We implement the resolution of DR 453 and + // istringstream::tellg() doesn't fail. + VERIFY( p3 == pos_type(off_type(0)) ); + VERIFY( p4 == pos_type(off_type(-1)) ); + + // in + // test ctors leave things in the same positions... + wistringstream ist2(L"bob_marley:kaya"); + p3 = ist2.tellg(); + + wifstream ifs2(str_lit01); + p4 = ifs2.tellg(); + + VERIFY( p3 == p4 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/2.cc new file mode 100644 index 000000000..439f3ae33 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/2.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// DR 60 -- tellg does not effect calls to gcount + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wistringstream ist(L"three sides live"); + ist.ignore(4); + int count1 = ist.gcount(); + ist.tellg(); + int count2 = ist.gcount(); + VERIFY( count1 == count2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc new file mode 100644 index 000000000..7d88d5c1f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/26211.cc @@ -0,0 +1,49 @@ +// 2010-11-18 Paolo Carlini <paolo.carlini@oracle.com> + +// Copyright (C) 2010 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/26211 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef wistringstream::pos_type pos_type; + + wistringstream iss(L"Duos for Doris"); + wostringstream oss; + + VERIFY( iss.tellg() == pos_type(0) ); + + iss >> oss.rdbuf(); + VERIFY( iss.rdstate() == iss.eofbit ); + VERIFY( iss.tellg() == pos_type(-1) ); + + iss.clear(); + VERIFY( iss.tellg() == pos_type(14) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc new file mode 100644 index 000000000..6979b9c06 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/8348.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2004, 2005, 2006, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. + +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8348 +void test06(void) +{ + using namespace std; + bool test __attribute__((unused)) = true; + wstring num1(L"555"); + + // tellg + { + wistringstream iss(num1); + iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.clear(); + iss.tellg(); + VERIFY( test = !iss.fail() ); + } + + // seekg + { + wistringstream iss(num1); + iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(0, ios_base::beg); + VERIFY( test = !iss.fail() ); + } + + // seekg + { + wistringstream iss(num1); + wistream::pos_type pos1 = iss.tellg(); + int asNum = 0; + iss >> asNum; + VERIFY( test = iss.eof() ); + VERIFY( test = !iss.fail() ); + iss.seekg(pos1); + VERIFY( test = !iss.fail() ); + } +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..1b7c96224 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <istream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wistream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellg(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc new file mode 100644 index 000000000..9878e4772 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/fstream.cc @@ -0,0 +1,84 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// fstreams +void test04(void) +{ + typedef std::wistream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::wistream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "wistream_seeks-1.txt"; + const char str_lit02[] = "wistream_seeks-2.txt"; + std::wifstream if01(str_lit01, std::ios_base::in | std::ios_base::out); + std::wifstream if02(str_lit01, std::ios_base::in); + std::wifstream if03(str_lit02, std::ios_base::out | std::ios_base::trunc); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( if03.good() ); + + std::wistream is01(if01.rdbuf()); + std::wistream is02(if02.rdbuf()); + std::wistream is03(if03.rdbuf()); + + // pos_type tellg() + // in | out + pos01 = is01.tellg(); + pos02 = is01.tellg(); + VERIFY( pos01 == pos02 ); + + // in + pos03 = is02.tellg(); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + // out + pos05 = is03.tellg(); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/sstream.cc b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/sstream.cc new file mode 100644 index 000000000..e440a22cf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/tellg/wchar_t/sstream.cc @@ -0,0 +1,90 @@ +// Copyright (C) 2004, 2009 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 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.6.1.3 unformatted input functions +// NB: ostream has a particular "seeks" category. Adopt this for istreams too. +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <istream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +// stringstreams +void test05(void) +{ + typedef std::wistream::off_type off_type; + + bool test __attribute__((unused)) = true; + std::wistream::pos_type pos01, pos02, pos03, pos04, pos05, pos06; + std::ios_base::iostate state01, state02; + const char str_lit01[] = "wistream_seeks-1.tst"; + std::wifstream if01(str_lit01); + std::wifstream if02(str_lit01); + std::wifstream if03(str_lit01); + VERIFY( if01.good() ); + VERIFY( if02.good() ); + VERIFY( if03.good() ); + + std::wstringbuf strbuf01(std::ios_base::in | std::ios_base::out); + if01 >> &strbuf01; + // initialize stringbufs that are ios_base::out + std::wstringbuf strbuf03(strbuf01.str(), std::ios_base::out); + // initialize stringbufs that are ios_base::in + std::wstringbuf strbuf02(strbuf01.str(), std::ios_base::in); + + std::wistream is01(&strbuf01); + std::wistream is02(&strbuf02); + std::wistream is03(&strbuf03); + + // pos_type tellg() + // in | out + pos01 = is01.tellg(); + pos02 = is01.tellg(); + VERIFY( pos01 == pos02 ); + + // in + pos03 = is02.tellg(); + pos04 = is02.tellg(); + VERIFY( pos03 == pos04 ); + + // out + pos05 = is03.tellg(); + pos06 = is03.tellg(); + VERIFY( pos05 == pos06 ); + + // 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(); + VERIFY( pos01 == pos02 + off_type(10) ); + VERIFY( state01 == state02 ); + pos02 = is01.tellg(); + VERIFY( pos02 == pos01 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ws/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ws/char/1.cc new file mode 100644 index 000000000..b59d08839 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ws/char/1.cc @@ -0,0 +1,77 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2001, 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.6.1.4 standard basic_istream manipulators + +#include <istream> +#include <sstream> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const char str_lit01[] = " venice "; + const std::string str01(" santa barbara "); + std::string str02(str_lit01); + std::string str04; + std::string str05; + + // template<_CharT, _Traits> + // basic_istream<_CharT, _Traits>& ws(basic_istream<_Char, _Traits>& is) + std::istringstream iss01(str01); + std::istringstream iss02(str01); + + iss01 >> str04; + VERIFY( str04.size() != str01.size() ); + VERIFY( str04 == "santa" ); + + iss02 >> std::ws; + iss02 >> str05; + VERIFY( str05.size() != str01.size() ); + VERIFY( str05 == "santa" ); + VERIFY( str05 == str04 ); + + iss01 >> str04; + VERIFY( str04.size() != str01.size() ); + VERIFY( str04 == "barbara" ); + + iss02 >> std::ws; + iss02 >> str05; + VERIFY( str05.size() != str01.size() ); + VERIFY( str05 == "barbara" ); + VERIFY( str05 == str04 ); + + VERIFY( !iss01.fail() ); + VERIFY( !iss02.fail() ); + VERIFY( !iss01.eof() ); + VERIFY( !iss02.eof() ); + + iss01 >> std::ws; + VERIFY( !iss01.fail() ); + VERIFY( iss01.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/1.cc new file mode 100644 index 000000000..8e60163c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/ws/wchar_t/1.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2004, 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.6.1.4 standard basic_istream manipulators + +#include <istream> +#include <sstream> +#include <stdexcept> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const wchar_t str_lit01[] = L" venice "; + const std::wstring str01(L" santa barbara "); + std::wstring str02(str_lit01); + std::wstring str04; + std::wstring str05; + + // template<_CharT, _Traits> + // basic_istream<_CharT, _Traits>& ws(basic_istream<_Char, _Traits>& is) + std::wistringstream iss01(str01); + std::wistringstream iss02(str01); + + iss01 >> str04; + VERIFY( str04.size() != str01.size() ); + VERIFY( str04 == L"santa" ); + + iss02 >> std::ws; + iss02 >> str05; + VERIFY( str05.size() != str01.size() ); + VERIFY( str05 == L"santa" ); + VERIFY( str05 == str04 ); + + iss01 >> str04; + VERIFY( str04.size() != str01.size() ); + VERIFY( str04 == L"barbara" ); + + iss02 >> std::ws; + iss02 >> str05; + VERIFY( str05.size() != str01.size() ); + VERIFY( str05 == L"barbara" ); + VERIFY( str05 == str04 ); + + VERIFY( !iss01.fail() ); + VERIFY( !iss02.fail() ); + VERIFY( !iss01.eof() ); + VERIFY( !iss02.eof() ); + + iss01 >> std::ws; + VERIFY( !iss01.fail() ); + VERIFY( iss01.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/2020.cc new file mode 100644 index 000000000..9eb4ca7a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_istringstream<__gnu_test::pod_ushort> gnu_isstr; + + try + { + gnu_isstr obj; + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..02f2e268f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/char/2832.cc @@ -0,0 +1,74 @@ +// 2000-01-10 bkoz + +// Copyright (C) 2000, 2001, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::stringbuf sbuf(str01); + std::streambuf* pbasebuf0 = &sbuf; + + std::istringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::stringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::stringbuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc new file mode 100644 index 000000000..14a659aac --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/rdbuf/wchar_t/2832.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::wios& stream, std::wstreambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::wstreambuf* +active_buffer(std::wios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const wchar_t* strlit01 = L"fuck war"; + const std::wstring str00; + const std::wstring str01(strlit01); + std::wstring str02; + std::wstringbuf sbuf(str01); + std::wstreambuf* pbasebuf0 = &sbuf; + + std::wistringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::wstringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::wstreambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::wstringbuf* const buf2 = sstrm1.rdbuf(); + std::wstreambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::wstringbuf* psbuf = dynamic_cast<std::wstringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/base_classes.cc new file mode 100644 index 000000000..77625a2d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <istream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::istringstream test_type; + typedef std::istream base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..194dc9e8e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.7.2 - Template class basic_istringstream +// NB: This file is for testing basic_istringstream with NO OTHER INCLUDES. + +#include <sstream> + +namespace std +{ + typedef short type_t; + template class basic_istringstream<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/typedefs.cc new file mode 100644 index 000000000..379e64dd9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.2 - Template class basic_istringstream +// NB: This file is for testing basic_istringstream with NO OTHER INCLUDES. + +#include <sstream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::istringstream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/str/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/char/1.cc new file mode 100644 index 000000000..3a3529eb1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/char/1.cc @@ -0,0 +1,76 @@ +// 2000-01-10 bkoz + +// Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::istringstream is01; + const std::string str00; + const std::string str01 = "123"; + std::string str02; + const int i01 = 123; + int a = 0, b = 0; + + std::ios_base::iostate state1, state2, stateeof; + stateeof = std::ios_base::eofbit; + + // string str() const + str02 = is01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + is01.str(str01); + str02 = is01.str(); + VERIFY( str01 == str02 ); + state1 = is01.rdstate(); + is01 >> a; + state2 = is01.rdstate(); + VERIFY( a == i01 ); + // 22.2.2.1.2 num_get virtual functions + // p 13 + // in any case, if stage 2 processing was terminated by the test for + // in == end then err != ios_base::eofbit is performed. + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is01.str(str01); + is01 >> b; + VERIFY( b != a ); + // as is01.good() is false, istream::sentry blocks extraction. + + is01.clear(); + state1 = is01.rdstate(); + is01 >> b; + state2 = is01.rdstate(); + VERIFY( b == a ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/str/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/wchar_t/1.cc new file mode 100644 index 000000000..2548610d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/str/wchar_t/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.2.2 member functions (istringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::wistringstream is01; + const std::wstring str00; + const std::wstring str01 = L"123"; + std::wstring str02; + const int i01 = 123; + int a = 0, b = 0; + + std::ios_base::iostate state1, state2, stateeof; + stateeof = std::ios_base::eofbit; + + // string str() const + str02 = is01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + is01.str(str01); + str02 = is01.str(); + VERIFY( str01 == str02 ); + state1 = is01.rdstate(); + is01 >> a; + state2 = is01.rdstate(); + VERIFY( a == i01 ); + // 22.2.2.1.2 num_get virtual functions + // p 13 + // in any case, if stage 2 processing was terminated by the test for + // in == end then err != ios_base::eofbit is performed. + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is01.str(str01); + is01 >> b; + VERIFY( b != a ); + // as is01.good() is false, istream::sentry blocks extraction. + + is01.clear(); + state1 = is01.rdstate(); + is01 >> b; + state2 = is01.rdstate(); + VERIFY( b == a ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/2020.cc new file mode 100644 index 000000000..b1594112e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_ofstream<__gnu_test::pod_ushort> gnu_ofstr; + + try + { + gnu_ofstr obj; + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/1.cc new file mode 100644 index 000000000..6b84f36d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/1.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2000, 2001, 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.10 ofstream member functions +// @require@ %-*.tst +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +const char name_02[] = "ofstream_members-1.txt"; + +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00004.html +void test02() +{ + bool test __attribute__((unused)) = true; + const int more_than_max_open_files = 8200; + + for(int i = 0; ++i < more_than_max_open_files;) + { + std::ofstream ifs(name_02); + VERIFY( static_cast<bool>(ifs) ); + } +} + +int main() +{ + test02(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/2.cc new file mode 100644 index 000000000..ecdb5c1af --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/cons/char/2.cc @@ -0,0 +1,27 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +void test01() +{ + const std::string name = "ofstream_name.txt"; + std::ofstream ofs(name); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc new file mode 100644 index 000000000..f7805c28c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/1.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2000, 2001, 2003, 2005, 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.10 ofstream member functions +// @require@ %-*.tst +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "ofstream_members-1.tst"; +const char name_02[] = "ofstream_members-1.txt"; + +// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00136.html +void test01() +{ + bool test __attribute__((unused)) = true; + std::ofstream ofs1; + ofs1.close(); + + // false as expected: + VERIFY( !ofs1.is_open() ); + // this is now true: + VERIFY( !(ofs1) ); + + ofs1.open(name_02); + VERIFY( ofs1.is_open() ); + + // As per the resolution of DR 409. + VERIFY( (ofs1) ); + VERIFY( ofs1.rdstate() == std::ios_base::goodbit ); + + ofs1.close(); +} + +int main() +{ + test01(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/2.cc new file mode 100644 index 000000000..395d84952 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/open/char/2.cc @@ -0,0 +1,31 @@ +// Copyright (C) 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/>. + +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +#include <fstream> + +void test01() +{ + std::ofstream ofs; + + const std::string name = "ofstream_name.txt"; + ofs.open(name); + + ofs.close(); +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/pthread2.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/pthread2.cc new file mode 100644 index 000000000..cb683666c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/pthread2.cc @@ -0,0 +1,60 @@ +// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org> +// Adpated from libstdc++/5347 submitted by markus.breuer@materna.de +// +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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/>. + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } + +#include <fstream> +#include <pthread.h> + +const int max_thread_count = 2; +const int max_loop_count = 1000000; + +void* +thread_main (void *) +{ + for (int i = 0; i < max_loop_count; i++) + { + std::ofstream* pos1 = new std::ofstream; + delete pos1; + } + + return 0; +} + +int +main() +{ + pthread_t tid[max_thread_count]; + +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (max_thread_count); +#endif + + for (int i = 0; i < max_thread_count; i++) + pthread_create (&tid[i], 0, thread_main, 0); + + for (int i = 0; i < max_thread_count; i++) + pthread_join (tid[i], 0); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..7bed0d25e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/rdbuf/char/2832.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2000, 2001, 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.10 ofstream member functions +// @require@ %-*.tst +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +const char name_01[] = "ofstream_members-1.tst"; + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test03() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::filebuf fbuf; + std::streambuf* pbasebuf0 = &fbuf; + + std::ofstream sstrm1; + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::filebuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &fbuf); + std::filebuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test03(); + return 0; +} + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/base_classes.cc new file mode 100644 index 000000000..30380f8f2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <ostream> +#include <fstream> + +void test01() +{ + // Check for required base class. + typedef std::ofstream test_type; + typedef std::ostream base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..54a9e80f8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.8.1.8 - Template class basic_ofstream +// NB: This file is for testing basic_ofstream with NO OTHER INCLUDES. + +#include <fstream> + +namespace std +{ + typedef short type_t; + template class basic_ifstream<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/typedefs.cc new file mode 100644 index 000000000..22b20f4ea --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ofstream/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.8 - Template class basic_ofstream +// NB: This file is for testing basic_ofstream with NO OTHER INCLUDES. + +#include <fstream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::ifstream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/2020.cc new file mode 100644 index 000000000..07fb7b82e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/2020.cc @@ -0,0 +1,55 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_ostream<__gnu_test::pod_ushort> gnu_ostr; + + try + { + gnu_ostr obj(0); + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/cons/char/9827.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/char/9827.cc new file mode 100644 index 000000000..c5283236b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/char/9827.cc @@ -0,0 +1,45 @@ +// 2003-02-24 Petur Runolfsson <peturr02 at ru dot is> + +// 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/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9827 +class Buf : public std::streambuf +{ +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + Buf buf; + ostream stream(&buf); + + stream << 1; + VERIFY(!stream.good()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/cons/wchar_t/9827.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/wchar_t/9827.cc new file mode 100644 index 000000000..8397c690b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/cons/wchar_t/9827.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9827 +class Buf : public std::wstreambuf +{ +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + Buf buf; + wostream stream(&buf); + + stream << 1; + VERIFY(!stream.good()); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/endl/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/char/1.cc new file mode 100644 index 000000000..7ebc2fe62 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/char/1.cc @@ -0,0 +1,54 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::string str01(" santa barbara "); + std::string str04; + std::string str05; + + std::ostringstream oss01(str01); + std::ostringstream oss02; + typedef std::ostringstream::traits_type traits_type; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::endl; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::endl; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/endl/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/wchar_t/1.cc new file mode 100644 index 000000000..6a8b16373 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/endl/wchar_t/1.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::wstring str01(L" santa barbara "); + std::wstring str04; + std::wstring str05; + + std::wostringstream oss01(str01); + std::wostringstream oss02; + typedef std::wostringstream::traits_type traits_type; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::endl; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::endl; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/1.cc new file mode 100644 index 000000000..4c2af14b2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/1.cc @@ -0,0 +1,54 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::string str01(" santa barbara "); + std::string str04; + std::string str05; + + std::ostringstream oss01(str01); + std::ostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::ends; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::ends; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); + VERIFY( str05[0] == char() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/2.cc new file mode 100644 index 000000000..c2e4c614a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/char/2.cc @@ -0,0 +1,63 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// based vaguely on this: +// http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00109.html +void test02() +{ + using namespace std; + typedef ostringstream::int_type int_type; + + bool test __attribute__((unused)) = true; + ostringstream osst_01; + const string str_00("herbie_hancock"); + int_type len1 = str_00.size(); + osst_01 << str_00; + VERIFY( static_cast<int_type>(osst_01.str().size()) == len1 ); + + osst_01 << ends; + + const string str_01("speak like a child"); + int_type len2 = str_01.size(); + osst_01 << str_01; + int_type len3 = osst_01.str().size(); + VERIFY( len1 < len3 ); + VERIFY( len3 == len1 + len2 + 1 ); + + osst_01 << ends; + + const string str_02("+ inventions and dimensions"); + int_type len4 = str_02.size(); + osst_01 << str_02; + int_type len5 = osst_01.str().size(); + VERIFY( len3 < len5 ); + VERIFY( len5 == len3 + len4 + 1 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/1.cc new file mode 100644 index 000000000..118488132 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/1.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::wstring str01(L" santa barbara "); + std::wstring str04; + std::wstring str05; + + std::wostringstream oss01(str01); + std::wostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& ends(basic_ostream<_Char, _Traits>& os) + oss01 << std::ends; + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02 << std::ends; + str05 = oss02.str(); + VERIFY( str05.size() == 1 ); + VERIFY( str05[0] == wchar_t() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/2.cc new file mode 100644 index 000000000..d05c105c0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/ends/wchar_t/2.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// based vaguely on this: +// http://gcc.gnu.org/ml/libstdc++/2000-q2/msg00109.html +void test02() +{ + using namespace std; + typedef wostringstream::int_type int_type; + + bool test __attribute__((unused)) = true; + wostringstream osst_01; + const wstring str_00(L"herbie_hancock"); + int_type len1 = str_00.size(); + osst_01 << str_00; + VERIFY( static_cast<int_type>(osst_01.str().size()) == len1 ); + + osst_01 << ends; + + const wstring str_01(L"speak like a child"); + int_type len2 = str_01.size(); + osst_01 << str_01; + int_type len3 = osst_01.str().size(); + VERIFY( len1 < len3 ); + VERIFY( len3 == len1 + len2 + 1 ); + + osst_01 << ends; + + const wstring str_02(L"+ inventions and dimensions"); + int_type len4 = str_02.size(); + osst_01 << str_02; + int_type len5 = osst_01.str().size(); + VERIFY( len3 < len5 ); + VERIFY( len5 == len3 + len4 + 1 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/char/9561.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/char/9561.cc new file mode 100644 index 000000000..b7cf707e9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/char/9561.cc @@ -0,0 +1,69 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9561 +struct foobar: std::exception { }; + +struct buf: std::streambuf +{ + virtual int_type + overflow(int_type) + { + throw foobar(); + return int_type(); + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + buf b; + std::ostream strm (&b); + strm.exceptions(std::ios::badbit); + + try + { + strm << std::endl; + } + catch(foobar) + { + // strm should throw foobar and not do anything else + VERIFY(strm.bad()); + return; + } + catch(...) + { + VERIFY( false ); + return; + } + + VERIFY( false ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc new file mode 100644 index 000000000..c528eccab --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/exceptions/wchar_t/9561.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +// libstdc++/9561 +struct foobar: std::exception { }; + +struct buf: std::wstreambuf +{ + virtual int_type + overflow(int_type) + { + throw foobar(); + return int_type(); + } +}; + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + buf b; + std::wostream strm(&b); + strm.exceptions(std::wios::badbit); + + try + { + strm << std::endl; + } + catch(foobar) + { + // strm should throw foobar and not do anything else + VERIFY(strm.bad()); + return; + } + catch(...) + { + VERIFY( false ); + return; + } + VERIFY( false ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/1.cc new file mode 100644 index 000000000..810c92084 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/1.cc @@ -0,0 +1,53 @@ +// 1999-07-22 bkoz + +// Copyright (C) 1994, 1999, 2000, 2003, 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::string str01(" santa barbara "); + std::string str04; + std::string str05; + + std::ostringstream oss01(str01); + std::ostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& flush(basic_ostream<_Char, _Traits>& os) + oss01.flush(); + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02.flush(); + str05 = oss02.str(); + VERIFY( str05.size() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/2.cc new file mode 100644 index 000000000..c830a39f1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/2.cc @@ -0,0 +1,65 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 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.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::flush() does not behave as an unformatted output function. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_streambuf buf; + std::ostream os(&buf); + + __gnu_test::sync_streambuf buf_tie; + std::ostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + os.flush(); + + VERIFY( os.good() ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); + + // os.rdbuf()->pubsync() should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + os.flush(); + + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); +} + +int main() +{ + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..0a494c552 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/char/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.flush(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/1.cc new file mode 100644 index 000000000..f6d3fb71d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/1.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2005, 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.6.2.7 standard basic_ostream manipulators + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test01(void) +{ + bool test __attribute__((unused)) = true; + + const std::wstring str01(L" santa barbara "); + std::wstring str04; + std::wstring str05; + + std::wostringstream oss01(str01); + std::wostringstream oss02; + + // template<_CharT, _Traits> + // basic_ostream<_CharT, _Traits>& flush(basic_ostream<_Char, _Traits>& os) + oss01.flush(); + str04 = oss01.str(); + VERIFY( str04.size() == str01.size() ); + + oss02.flush(); + str05 = oss02.str(); + VERIFY( str05.size() == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc new file mode 100644 index 000000000..a6d235ae1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/2.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2005, 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.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::flush() does not behave as an unformatted output function. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_wstreambuf buf; + std::wostream os(&buf); + + __gnu_test::sync_wstreambuf buf_tie; + std::wostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + os.flush(); + + VERIFY( os.good() ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); + + // os.rdbuf()->pubsync() should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + os.flush(); + + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( buf.sync_called() ); + VERIFY( !buf_tie.sync_called() ); +} + +int main() +{ + test02(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..d06858208 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/flush/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.flush(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc new file mode 100644 index 000000000..35fe23287 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/1.cc @@ -0,0 +1,190 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +using namespace std; + +#ifndef _GLIBCXX_ASSERT +# define TEST_NUMPUT_VERBOSE 1 +#endif + +struct _TestCase +{ + double val; + + int precision; + int width; + char decimal; + char fill; + + bool fixed; + bool scientific; + bool showpos; + bool showpoint; + bool uppercase; + bool internal; + bool left; + bool right; + + const char* result; +}; + +static bool T=true; +static bool F=false; + +static _TestCase testcases[] = +{ + // standard output (no formatting applied) + { 1.2, 6,0,'.',' ', F,F,F,F,F,F,F,F, "1.2" }, + { 54, 6,0,'.',' ', F,F,F,F,F,F,F,F, "54" }, + { -.012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-0.012" }, + { -.00000012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-1.2e-07" }, + + // fixed formatting + { 10.2345, 0,0,'.',' ', T,F,F,F,F,F,F,F, "10" }, + { 10.2345, 0,0,'.',' ', T,F,F,T,F,F,F,F, "10." }, + { 10.2345, 1,0,'.',' ', T,F,F,F,F,F,F,F, "10.2" }, + { 10.2345, 4,0,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 6,0,'.',' ', T,F,T,F,F,F,F,F, "+10.234500" }, + { -10.2345, 6,0,'.',' ', T,F,F,F,F,F,F,F, "-10.234500" }, + { -10.2345, 6,0,',',' ', T,F,F,F,F,F,F,F, "-10,234500" }, + + // fixed formatting with width + { 10.2345, 4,5,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 4,6,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 4,7,'.',' ', T,F,F,F,F,F,F,F, "10.2345" }, + { 10.2345, 4,8,'.',' ', T,F,F,F,F,F,F,F, " 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,F, " 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,T,F, "10.2345 " }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,T, " 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, " 10.2345" }, + { -10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, "- 10.2345" }, + { -10.2345, 4,10,'.','A', T,F,F,F,F,T,F,F, "-AA10.2345" }, + { 10.2345, 4,10,'.','#', T,F,T,F,F,T,F,F, "+##10.2345" }, + + // scientific formatting + { 1.23e+12, 1,0,'.',' ', F,T,F,F,F,F,F,F, "1.2e+12" }, + { 1.23e+12, 1,0,'.',' ', F,T,F,F,T,F,F,F, "1.2E+12" }, + { 1.23e+12, 2,0,'.',' ', F,T,F,F,F,F,F,F, "1.23e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "1.230e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,T,F,F,F,F,F, "+1.230e+12" }, + { -1.23e-12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "-1.230e-12" }, + { 1.23e+12, 3,0,',',' ', F,T,F,F,F,F,F,F, "1,230e+12" }, +}; + +template<typename _CharT> +class testpunct : public numpunct<_CharT> +{ +public: + typedef _CharT char_type; + const char_type dchar; + + explicit + testpunct(char_type decimal_char) : numpunct<_CharT>(), dchar(decimal_char) + { } + +protected: + char_type + do_decimal_point() const + { return dchar; } + + char_type + do_thousands_sep() const + { return ','; } + + string + do_grouping() const + { return string(); } +}; + +template<typename _CharT> +void apply_formatting(const _TestCase & tc, basic_ostream<_CharT> & os) +{ + os.precision(tc.precision); + os.width(tc.width); + os.fill(static_cast<_CharT>(tc.fill)); + if (tc.fixed) + os.setf(ios::fixed); + if (tc.scientific) + os.setf(ios::scientific); + if (tc.showpos) + os.setf(ios::showpos); + if (tc.showpoint) + os.setf(ios::showpoint); + if (tc.uppercase) + os.setf(ios::uppercase); + if (tc.internal) + os.setf(ios::internal); + if (tc.left) + os.setf(ios::left); + if (tc.right) + os.setf(ios::right); +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + for (std::size_t j = 0; j<sizeof(testcases)/sizeof(testcases[0]); j++) + { + _TestCase & tc = testcases[j]; +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << tc.result << endl; +#endif + // test double with char type + { + testpunct<char>* __tp = new testpunct<char>(tc.decimal); + ostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << tc.val; +#ifdef TEST_NUMPUT_VERBOSE + cout << j << "result 1: " << os.str() << endl; +#endif + VERIFY( os && os.str() == tc.result ); + } + // test long double with char type + { + testpunct<char>* __tp = new testpunct<char>(tc.decimal); + ostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << (long double)tc.val; +#ifdef TEST_NUMPUT_VERBOSE + cout << j << "result 2: " << os.str() << endl; +#endif + VERIFY( os && os.str() == tc.result ); + } + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/2.cc new file mode 100644 index 000000000..d0ffa2c2a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/2.cc @@ -0,0 +1,57 @@ +// { dg-require-namedlocale "de_DE" } + +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <locale> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = 3.5e230; + + ostringstream os2; + os2.precision(3); + os2.setf(ios::fixed); + + // Check it can be done in a locale with grouping on. + locale loc2 = locale("de_DE"); + os2.imbue(loc2); + os2 << fixed << setprecision(3) << val2 << endl; + os2 << endl; + os2 << fixed << setprecision(1) << val2 << endl; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc new file mode 100644 index 000000000..88b55ad9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/23871.cc @@ -0,0 +1,37 @@ +// 2005-09-15 Janis Johnson <janis187@us.ibm.com> + +// Copyright (C) 2005, 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/>. + +// { dg-do compile } + +// libstdc++/23871 + +#include <iostream> + +class mytest { +public: + mytest (int); + unsigned char operator|| (const mytest&) const; + friend unsigned char operator|| (const int&, const mytest&); +}; + +inline unsigned char operator|| (const int& lhs, const mytest& rhs) +{ + std::cout << 1 << std::endl; + return (mytest)lhs || rhs; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/3.cc new file mode 100644 index 000000000..fd1d14955 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/3.cc @@ -0,0 +1,68 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +template<typename T> +bool +test03_check(T n) +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf strbuf; + ostream o(&strbuf); + const char *expect; + + if (numeric_limits<T>::digits + 1 == 16) + expect = "177777 ffff"; + else if (numeric_limits<T>::digits + 1 == 32) + expect = "37777777777 ffffffff"; + else if (numeric_limits<T>::digits + 1 == 64) + expect = "1777777777777777777777 ffffffffffffffff"; + else + expect = "wow, you've got some big numbers here"; + + o << oct << n << ' ' << hex << n; + VERIFY ( strbuf.str() == expect ); + + return test; +} + +void +test03() +{ + short s = -1; + int i = -1; + long l = -1; + + test03_check (s); + test03_check (i); + test03_check (l); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/31031.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/31031.cc new file mode 100644 index 000000000..1f34663a9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/31031.cc @@ -0,0 +1,51 @@ +// { dg-do compile } + +// 2007-03-03 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 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/>. + +#include <sstream> + +class MyClass +{ + double x; + +public: + MyClass(double X) : x(X) {} + friend bool operator&&(int i, const MyClass& Z); +}; + +inline bool +operator&&(int i, const MyClass& Z) +{ return int(Z.x) == i; } + +// libstdc++/31031 +void test01() +{ + int k =3; + MyClass X(3.1); + std::ostringstream oss; + + oss << (k && X); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4.cc new file mode 100644 index 000000000..a2b686ae7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4.cc @@ -0,0 +1,50 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iomanip> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3655 +int +test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf strbuf1, strbuf2; + ostream o1(&strbuf1), o2(&strbuf2); + + o1 << hex << showbase << setw(6) << internal << 0xff; + VERIFY( strbuf1.str() == "0x ff" ); + + // ... vs internal-adjusted const char*-type objects + o2 << hex << showbase << setw(6) << internal << "0xff"; + VERIFY( strbuf2.str() == " 0xff" ); + + return 0; +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4402.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4402.cc new file mode 100644 index 000000000..fe1c3b6f2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/4402.cc @@ -0,0 +1,74 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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/>. + +#include <cstdio> // for sprintf +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // make sure we can output a very long float + long double val = numeric_limits<long double>::max(); + int prec = numeric_limits<long double>::digits10; + + ostringstream os; + os.precision(prec); + os.setf(ios::scientific); + os << val; + + char largebuf[512]; + sprintf(largebuf, "%.*Le", prec, val); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os.str() << endl; +#endif + VERIFY( os && os.str() == largebuf ); + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = numeric_limits<double>::max(); + + ostringstream os2; + os2.precision(3); + os2.setf(ios::fixed); + os2 << val2; + + sprintf(largebuf, "%.*f", 3, val2); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os2.str() << endl; +#endif + VERIFY( os2 && os2.str() == largebuf ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/5.cc new file mode 100644 index 000000000..ba0e6a390 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/5.cc @@ -0,0 +1,49 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + double pi = 3.14159265358979323846; + ostringstream ostr; + ostr.precision(20); + ostr << pi; + string sval = ostr.str(); + istringstream istr (sval); + double d; + istr >> d; + VERIFY( abs(pi-d)/pi < DBL_EPSILON ); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/6.cc new file mode 100644 index 000000000..2a3d1542b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/6.cc @@ -0,0 +1,54 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2005, 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/>. + +// { dg-do run { xfail lax_strtofp } } + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/9151 +void +test06() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + int prec = numeric_limits<double>::digits10 + 2; + double oval = numeric_limits<double>::min(); + + stringstream ostr; + ostr.precision(prec); + ostr << oval; + string sval = ostr.str(); + istringstream istr (sval); + double ival; + istr >> ival; + VERIFY( abs(oval-ival)/oval < DBL_EPSILON ); +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc new file mode 100644 index 000000000..d3e3213dd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/7.cc @@ -0,0 +1,67 @@ +// 2005-07-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 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 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.6.2.5.2 Arithmetic inserters + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringstream ostr1, ostr2, ostr3, ostr4; + + ostr1.setf(ios_base::oct); + ostr1.setf(ios_base::hex); + + short s = -1; + ostr1 << s; + VERIFY( ostr1.str() == "-1" ); + + ostr2.setf(ios_base::oct); + ostr2.setf(ios_base::hex); + + int i = -1; + ostr2 << i; + VERIFY( ostr2.str() == "-1" ); + + ostr3.setf(ios_base::oct); + ostr3.setf(ios_base::hex); + + long l = -1; + ostr3 << l; + VERIFY( ostr3.str() == "-1" ); + +#ifdef _GLIBCXX_USE_LONG_LONG + ostr4.setf(ios_base::oct); + ostr4.setf(ios_base::hex); + + long long ll = -1LL; + ostr4 << ll; + VERIFY( ostr4.str() == "-1" ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/9555-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/9555-oa.cc new file mode 100644 index 000000000..ed1e34b77 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/9555-oa.cc @@ -0,0 +1,77 @@ +// 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/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::ostream os(&b); + os.exceptions(std::ios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..6c917ad84 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_badbit_throw.cc @@ -0,0 +1,73 @@ +// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_char); + ostringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i = T(); + stream << i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc new file mode 100644 index 000000000..19b1fcd84 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/char/exceptions_failbit_throw.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_char); + ostringstream stream("jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i = T(); + stream << i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/pod/23875.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/pod/23875.cc new file mode 100644 index 000000000..ac4042194 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/pod/23875.cc @@ -0,0 +1,84 @@ +// 2005-09-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 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 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.6.2.5.2 Arithmetic inserters + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +bool test __attribute__((unused)) = true; +using __gnu_test::pod_ushort; + +namespace std +{ + template<> + basic_ostream<pod_ushort>& + basic_ostream<pod_ushort>:: + operator<<(long) + { + VERIFY( false ); + return *this; + } + + template<> + basic_ostream<pod_ushort>& + basic_ostream<pod_ushort>:: + operator<<(unsigned long) + { + VERIFY( false ); + return *this; + } + + template<> + basic_ostream<pod_ushort>& + basic_ostream<pod_ushort>:: + operator<<(double) + { + VERIFY( false ); + return *this; + } +} + +// libstdc++/23875 +void test01() +{ + std::basic_ostringstream<pod_ushort> ostr; + + short s = 1; + ostr << s; + + unsigned short us = 1; + ostr << us; + + int i = 1; + ostr << i; + + unsigned int ui = 1; + ostr << ui; + + float f = 1.0f; + ostr << f; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc new file mode 100644 index 000000000..0108fd067 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/1.cc @@ -0,0 +1,185 @@ +// 1999-11-15 Kevin Ediger <kediger@licor.com> +// test the floating point inserters (facet num_put) + +// Copyright (C) 1999, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +using namespace std; + +#ifndef _GLIBCXX_ASSERT +# define TEST_NUMPUT_VERBOSE 1 +#endif + +struct _TestCase +{ + double val; + + int precision; + int width; + char decimal; + char fill; + + bool fixed; + bool scientific; + bool showpos; + bool showpoint; + bool uppercase; + bool internal; + bool left; + bool right; + + const char* result; + const wchar_t* wresult; +}; + +static bool T=true; +static bool F=false; + +static _TestCase testcases[] = +{ + // standard output (no formatting applied) 1-4 + { 1.2, 6,0,'.',' ', F,F,F,F,F,F,F,F, "1.2",L"1.2" }, + { 54, 6,0,'.',' ', F,F,F,F,F,F,F,F, "54",L"54" }, + { -.012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-0.012",L"-0.012" }, + { -.00000012, 6,0,'.',' ', F,F,F,F,F,F,F,F, "-1.2e-07",L"-1.2e-07" }, + + // fixed formatting 5-11 + { 10.2345, 0,0,'.',' ', T,F,F,F,F,F,F,F, "10",L"10" }, + { 10.2345, 0,0,'.',' ', T,F,F,T,F,F,F,F, "10.",L"10." }, + { 10.2345, 1,0,'.',' ', T,F,F,F,F,F,F,F, "10.2",L"10.2" }, + { 10.2345, 4,0,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 6,0,'.',' ', T,F,T,F,F,F,F,F, "+10.234500",L"+10.234500" }, + { -10.2345, 6,0,'.',' ', T,F,F,F,F,F,F,F, "-10.234500",L"-10.234500" }, + { -10.2345, 6,0,',',' ', T,F,F,F,F,F,F,F, "-10,234500",L"-10,234500" }, + + // fixed formatting with width 12-22 + { 10.2345, 4,5,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 4,6,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 4,7,'.',' ', T,F,F,F,F,F,F,F, "10.2345",L"10.2345" }, + { 10.2345, 4,8,'.',' ', T,F,F,F,F,F,F,F, " 10.2345",L" 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,F, " 10.2345",L" 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,T,F, "10.2345 ",L"10.2345 " }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,F,F,T, " 10.2345",L" 10.2345" }, + { 10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, " 10.2345",L" 10.2345" }, + { -10.2345, 4,10,'.',' ', T,F,F,F,F,T,F,F, "- 10.2345",L"- 10.2345" }, + { -10.2345, 4,10,'.','A', T,F,F,F,F,T,F,F, "-AA10.2345",L"-AA10.2345" }, + { 10.2345, 4,10,'.','#', T,F,T,F,F,T,F,F, "+##10.2345",L"+##10.2345" }, + + // scientific formatting 23-29 + { 1.23e+12, 1,0,'.',' ', F,T,F,F,F,F,F,F, "1.2e+12",L"1.2e+12" }, + { 1.23e+12, 1,0,'.',' ', F,T,F,F,T,F,F,F, "1.2E+12",L"1.2E+12" }, + { 1.23e+12, 2,0,'.',' ', F,T,F,F,F,F,F,F, "1.23e+12",L"1.23e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "1.230e+12",L"1.230e+12" }, + { 1.23e+12, 3,0,'.',' ', F,T,T,F,F,F,F,F, "+1.230e+12",L"+1.230e+12" }, + { -1.23e-12, 3,0,'.',' ', F,T,F,F,F,F,F,F, "-1.230e-12",L"-1.230e-12" }, + { 1.23e+12, 3,0,',',' ', F,T,F,F,F,F,F,F, "1,230e+12",L"1,230e+12" }, +}; + +template<typename _CharT> +class testpunct : public numpunct<_CharT> +{ +public: + typedef _CharT char_type; + const char_type dchar; + + explicit + testpunct(char_type decimal_char) : numpunct<_CharT>(), dchar(decimal_char) + { } + +protected: + char_type + do_decimal_point() const + { return dchar; } + + char_type + do_thousands_sep() const + { return ','; } + + string + do_grouping() const + { return string(); } +}; + +template<typename _CharT> +void apply_formatting(const _TestCase & tc, basic_ostream<_CharT> & os) +{ + os.precision(tc.precision); + os.width(tc.width); + os.fill(static_cast<_CharT>(tc.fill)); + if (tc.fixed) + os.setf(ios::fixed); + if (tc.scientific) + os.setf(ios::scientific); + if (tc.showpos) + os.setf(ios::showpos); + if (tc.showpoint) + os.setf(ios::showpoint); + if (tc.uppercase) + os.setf(ios::uppercase); + if (tc.internal) + os.setf(ios::internal); + if (tc.left) + os.setf(ios::left); + if (tc.right) + os.setf(ios::right); +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + for (std::size_t j = 0; j<sizeof(testcases)/sizeof(testcases[0]); j++) + { + _TestCase & tc = testcases[j]; +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << tc.result << endl; +#endif + // test double with wchar_t type + { + testpunct<wchar_t>* __tp = new testpunct<wchar_t>(tc.decimal); + wostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << tc.val; + VERIFY( os && os.str() == tc.wresult ); + } + // test long double with wchar_t type + { + testpunct<wchar_t>* __tp = new testpunct<wchar_t>(tc.decimal); + wostringstream os; + locale __loc(os.getloc(), __tp); + os.imbue(__loc); + apply_formatting(tc, os); + os << (long double)tc.val; + VERIFY( os && os.str() == tc.wresult ); + } + } +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc new file mode 100644 index 000000000..e786f7589 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/2.cc @@ -0,0 +1,54 @@ +// { dg-require-namedlocale "de_DE" } + +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <iomanip> +#include <locale> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = 3.5e230; + + wostringstream os2; + os2.precision(3); + os2.setf(wios::fixed); + + // Check it can be done in a locale with grouping on. + locale loc2 = locale("de_DE"); + os2.imbue(loc2); + os2 << fixed << setprecision(3) << val2 << endl; + os2 << endl; + os2 << fixed << setprecision(1) << val2 << endl; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc new file mode 100644 index 000000000..436fae353 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/3.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +template<typename T> +bool +test03_check(T n) +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf strbuf; + wostream o(&strbuf); + const wchar_t *expect; + + if (numeric_limits<T>::digits + 1 == 16) + expect = L"177777 ffff"; + else if (numeric_limits<T>::digits + 1 == 32) + expect = L"37777777777 ffffffff"; + else if (numeric_limits<T>::digits + 1 == 64) + expect = L"1777777777777777777777 ffffffffffffffff"; + else + expect = L"wow, you've got some big numbers here"; + + o << oct << n << L' ' << hex << n; + VERIFY ( strbuf.str() == expect ); + + return test; +} + +void +test03() +{ + short s = -1; + int i = -1; + long l = -1; + + test03_check(s); + test03_check(i); + test03_check(l); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/31031.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/31031.cc new file mode 100644 index 000000000..bb5aedadd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/31031.cc @@ -0,0 +1,51 @@ +// { dg-do compile } + +// 2007-03-03 Paolo Carlini <pcarlini@suse.de> +// +// Copyright (C) 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/>. + +#include <sstream> + +class MyClass +{ + double x; + +public: + MyClass(double X) : x(X) {} + friend bool operator&&(int i, const MyClass& Z); +}; + +inline bool +operator&&(int i, const MyClass& Z) +{ return int(Z.x) == i; } + +// libstdc++/31031 +void test01() +{ + int k =3; + MyClass X(3.1); + std::wostringstream oss; + + oss << (k && X); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc new file mode 100644 index 000000000..9592d9482 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iomanip> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3655 +int +test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf strbuf1, strbuf2; + wostream o1(&strbuf1), o2(&strbuf2); + + o1 << hex << showbase << setw(6) << internal << 0xff; + VERIFY( strbuf1.str() == L"0x ff" ); + + // ... vs internal-adjusted const char*-type objects + o2 << hex << showbase << setw(6) << internal << L"0xff"; + VERIFY( strbuf2.str() == L" 0xff" ); + + return 0; +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc new file mode 100644 index 000000000..54b339e99 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/4402.cc @@ -0,0 +1,72 @@ +// { dg-require-swprintf "" } + +// Copyright (C) 2005, 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/>. + +#include <cstdio> // for swprintf +#include <iostream> +#include <iomanip> +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + // make sure we can output a very long float + long double val = numeric_limits<long double>::max(); + int prec = numeric_limits<long double>::digits10; + + wostringstream os; + os.precision(prec); + os.setf(wios::scientific); + os << val; + + wchar_t largebuf[512]; + swprintf(largebuf, 512, L"%.*Le", prec, val); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os.str() << endl; +#endif + VERIFY( os && os.str() == largebuf ); + + // Make sure we can output a long float in fixed format + // without seg-faulting (libstdc++/4402) + double val2 = numeric_limits<double>::max(); + + wostringstream os2; + os2.precision(3); + os2.setf(wios::fixed); + os2 << val2; + + swprintf(largebuf, 512, L"%.*f", 3, val2); +#ifdef TEST_NUMPUT_VERBOSE + cout << "expect: " << largebuf << endl; + cout << "result: " << os2.str() << endl; +#endif + VERIFY( os2 && os2.str() == largebuf ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc new file mode 100644 index 000000000..d48fee3b9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/5.cc @@ -0,0 +1,46 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +void +test05() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + double pi = 3.14159265358979323846; + wostringstream ostr; + ostr.precision(20); + ostr << pi; + wstring sval = ostr.str(); + wistringstream istr(sval); + double d; + istr >> d; + VERIFY( abs(pi-d)/pi < DBL_EPSILON ); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc new file mode 100644 index 000000000..96f34ccb5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/6.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2005, 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/>. + +// { dg-do run { xfail lax_strtofp } } + +#include <cmath> // for abs +#include <cfloat> // for DBL_EPSILON +#include <sstream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/9151 +void +test06() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + int prec = numeric_limits<double>::digits10 + 2; + double oval = numeric_limits<double>::min(); + + wstringstream ostr; + ostr.precision(prec); + ostr << oval; + wstring sval = ostr.str(); + wistringstream istr(sval); + double ival; + istr >> ival; + VERIFY( abs(oval-ival)/oval < DBL_EPSILON ); +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc new file mode 100644 index 000000000..41e230ca7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/7.cc @@ -0,0 +1,67 @@ +// 2005-07-11 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2005, 2009 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 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.6.2.5.2 Arithmetic inserters + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringstream ostr1, ostr2, ostr3, ostr4; + + ostr1.setf(ios_base::oct); + ostr1.setf(ios_base::hex); + + short s = -1; + ostr1 << s; + VERIFY( ostr1.str() == L"-1" ); + + ostr2.setf(ios_base::oct); + ostr2.setf(ios_base::hex); + + int i = -1; + ostr2 << i; + VERIFY( ostr2.str() == L"-1" ); + + ostr3.setf(ios_base::oct); + ostr3.setf(ios_base::hex); + + long l = -1; + ostr3 << l; + VERIFY( ostr3.str() == L"-1" ); + +#ifdef _GLIBCXX_USE_LONG_LONG + ostr4.setf(ios_base::oct); + ostr4.setf(ios_base::hex); + + long long ll = -1LL; + ostr4 << ll; + VERIFY( ostr4.str() == L"-1" ); +#endif +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc new file mode 100644 index 000000000..0acd426a2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/9555-oa.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wostream os(&b); + os.exceptions(std::wios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + bool b = true; + short s = -4; + unsigned short us = 4; + int i = -45; + unsigned int ui = 45; + long l = -456; + unsigned long ul = 456; + float f = 3.4; + double d = 3.45; + long double ld = 3.456; + + testthrow(b); + testthrow(s); + testthrow(us); + testthrow(i); + testthrow(ui); + testthrow(l); + testthrow(ul); + testthrow(f); + testthrow(d); + testthrow(ld); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..86b0884da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <locale> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/9561 +template<typename T> +void test_badbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_wchar_t); + wostringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::badbit); + VERIFY( stream.rdstate() == ios_base::goodbit ); + + try + { + T i = T(); + stream << i; + VERIFY( false ); + } + catch (const __gnu_test::facet_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + + +int main() +{ + test_badbit<bool>(); + test_badbit<short>(); + test_badbit<unsigned short>(); + test_badbit<int>(); + test_badbit<unsigned int>(); + test_badbit<long>(); + test_badbit<unsigned long>(); + + test_badbit<float>(); + test_badbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..1cf29cba4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_arithmetic/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// libstdc++/10093 +template<typename T> +void test_failbit() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale loc(locale::classic(), new __gnu_test::fail_num_put_wchar_t); + wostringstream stream(L"jaylib - champion sound"); + stream.imbue(loc); + + stream.exceptions(ios_base::failbit); + + try + { + T i = T(); + stream << i; + } + catch (const ios_base::failure&) + { VERIFY( false ); } + catch(...) + { VERIFY( false ); } + + // stream should set badbit. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); +} + +int main() +{ + test_failbit<bool>(); + test_failbit<short>(); + test_failbit<unsigned short>(); + test_failbit<int>(); + test_failbit<unsigned int>(); + test_failbit<long>(); + test_failbit<unsigned long>(); + + test_failbit<float>(); + test_failbit<double>(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/1.cc new file mode 100644 index 000000000..926b68bc7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/1.cc @@ -0,0 +1,57 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// ofstream +void test01() +{ + std::string str01; + const int size = 1000; + const char name_02[] = "ostream_inserter_char-1.txt"; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += '1'; + str01 += '2'; + str01 += '3'; + str01 += '4'; + str01 += '5'; + str01 += '6'; + str01 += '7'; + str01 += '8'; + str01 += '9'; + str01 += '\n'; + } + std::ofstream f(name_02); + + f << str01; + f.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc new file mode 100644 index 000000000..aeec2d51c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oa.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, char) +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream oss_01; + + oss_01.width(-60); + oss_01 << 'C'; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == "C" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc new file mode 100644 index 000000000..80ef77595 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-ob.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream<char, _Traits>&, const char*) +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream oss_01; + + oss_01.width(-60); + oss_01 << "Consoli"; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == "Consoli" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc new file mode 100644 index 000000000..43e1e0db0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/11095-oc.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, const basic_string&) +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream oss_01; + + oss_01.width(-60); + oss_01 << std::string("Consoli"); + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == "Consoli" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/2.cc new file mode 100644 index 000000000..988da4491 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/2.cc @@ -0,0 +1,67 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream width() != zero +// left +void +test02(void) +{ + bool test __attribute__((unused)) = true; + std::string tmp; + + std::string str01 = ""; + std::ostringstream oss01; + oss01.width(5); + oss01.fill('0'); + oss01.flags(std::ios_base::left); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == "00000" ); + + std::string str02 = "1"; + std::ostringstream oss02; + oss02.width(5); + oss02.fill('0'); + oss02.flags(std::ios_base::left); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == "10000" ); + + std::string str03 = "909909"; + std::ostringstream oss03; + oss03.width(5); + oss03.fill('0'); + oss03.flags(std::ios_base::left); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == "909909" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc new file mode 100644 index 000000000..0d1c2f483 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-3.cc @@ -0,0 +1,53 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2008, 2009 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 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-options "-DWIDTH=200000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 20000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << 'a'; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == string::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc new file mode 100644 index 000000000..fe80c76ba --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/28277-4.cc @@ -0,0 +1,54 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2008, 2009 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 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-options "-DWIDTH=200000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 20000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == string::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/3.cc new file mode 100644 index 000000000..87e299db5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/3.cc @@ -0,0 +1,66 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// width() != zero +// right +void test03(void) +{ + bool test __attribute__((unused)) = true; + std::string tmp; + + std::string str01 = ""; + std::ostringstream oss01; + oss01.width(5); + oss01.fill('0'); + oss01.flags(std::ios_base::right); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == "00000" ); + + std::string str02 = "1"; + std::ostringstream oss02; + oss02.width(5); + oss02.fill('0'); + oss02.flags(std::ios_base::right); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == "00001" ); + + std::string str03 = "909909"; + std::ostringstream oss03; + oss03.width(5); + oss03.fill('0'); + oss03.flags(std::ios_base::right); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == "909909" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/4.cc new file mode 100644 index 000000000..5ec21367b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/4.cc @@ -0,0 +1,54 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2005, 2009, 2010 +// 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// stringstream and large strings +void +test04() +{ + bool test __attribute__((unused)) = true; + std::string str_01; + std::string str_tmp; + const int i_max=250; + + std::ostringstream oss_02(str_01, std::ios_base::out); + + // template<_CharT, _Traits> + // basic_ostream& operator<<(ostream&, const char*) + for (int i = 0; i < i_max; ++i) + oss_02 << "Test: " << i << std::endl; + str_tmp = oss_02.str(); + VERIFY( !oss_02.bad() ); + VERIFY( oss_02.good() ); + VERIFY( str_tmp != str_01 ); + VERIFY( str_tmp.size() == 2390 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/5.cc new file mode 100644 index 000000000..6b6cbb38d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/5.cc @@ -0,0 +1,76 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and large strings number 2 +void +test05() +{ + bool test __attribute__((unused)) = true; + std::string str05, str10; + + typedef std::ostream::pos_type pos_type; + typedef std::ostream::off_type off_type; + std::string str01; + const int size = 1000; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += '1'; + str01 += '2'; + str01 += '3'; + str01 += '4'; + str01 += '5'; + str01 += '6'; + str01 += '7'; + str01 += '8'; + str01 += '9'; + str01 += '\n'; + } + + // test 1: out + std::ostringstream sstr01(str01, std::ios_base::out); + std::ostringstream sstr02; + sstr02 << str01; + str05 = sstr01.str(); + str10 = sstr02.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); + + // test 2: in | out + std::ostringstream sstr04(str01, std::ios_base::out | std::ios_base::in); + std::ostringstream sstr05(std::ios_base::in | std::ios_base::out); + sstr05 << str01; + str05 = sstr04.str(); + str10 = sstr05.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/6.cc new file mode 100644 index 000000000..25aad8a04 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/6.cc @@ -0,0 +1,57 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and positioning, multiple writes +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00326.html +void test06() +{ + bool test __attribute__((unused)) = true; + const char carray01[] = "mos def & talib kweli are black star"; + + // normal + std::ostringstream ostr1("mos def"); + VERIFY( ostr1.str() == "mos def" ); + ostr1 << " & talib kweli"; // should overwrite first part of buffer + VERIFY( ostr1.str() == " & talib kweli" ); + ostr1 << " are black star"; // should append to string from above + VERIFY( ostr1.str() != carray01 ); + VERIFY( ostr1.str() == " & talib kweli are black star" ); + + // appending + std::ostringstream ostr2("blackalicious", + std::ios_base::out | std::ios_base::ate); + VERIFY( ostr2.str() == "blackalicious" ); + ostr2 << " NIA "; // should not overwrite first part of buffer + VERIFY( ostr2.str() == "blackalicious NIA " ); + ostr2 << "4: deception (5:19)"; // should append to full string from above + VERIFY( ostr2.str() == "blackalicious NIA 4: deception (5:19)" ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/8.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/8.cc new file mode 100644 index 000000000..f38e2e703 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/8.cc @@ -0,0 +1,47 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test08() +{ + bool test __attribute__((unused)) = true; + char* pt = 0; + + // 1 + std::ostringstream oss; + oss << pt; + VERIFY( oss.bad() ); + VERIFY( oss.str().size() == 0 ); + + oss.clear(); + oss << ""; + VERIFY( oss.good() ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/9555-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/9555-oc.cc new file mode 100644 index 000000000..b46b2aede --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/char/9555-oc.cc @@ -0,0 +1,69 @@ +// 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/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::ostream os(&b); + os.exceptions(std::ios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + char c = 'a'; + unsigned char uc = 'a'; + signed char sc = 'a'; + const char* ccp = "governor ann richards"; + const signed char* cscp = reinterpret_cast<const signed char*>(ccp); + const unsigned char* cucp = reinterpret_cast<const unsigned char*>(ccp); + + testthrow(c); + testthrow(uc); + testthrow(sc); + testthrow(ccp); + testthrow(cscp); + testthrow(cucp); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/1.cc new file mode 100644 index 000000000..863590677 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/1.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// ofstream +void test01() +{ + std::wstring str01; + const int size = 1000; + const char name_02[] = "wostream_inserter_char-1.txt"; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += L'1'; + str01 += L'2'; + str01 += L'3'; + str01 += L'4'; + str01 += L'5'; + str01 += L'6'; + str01 += L'7'; + str01 += L'8'; + str01 += L'9'; + str01 += L'\n'; + } + std::wofstream f(name_02); + + f << str01; + f.close(); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc new file mode 100644 index 000000000..8fd1d1167 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-od.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, _CharT) +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream oss_01; + + oss_01.width(-60); + oss_01 << L'C'; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == L"C" ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc new file mode 100644 index 000000000..64e630302 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-oe.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream&, const _CharT*) +void +test02() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream oss_01; + + oss_01.width(-60); + oss_01 << L"Consoli"; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == L"Consoli" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc new file mode 100644 index 000000000..783027d0e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/11095-of.cc @@ -0,0 +1,45 @@ +// 2003-06-05 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/11095 +// operator<<(basic_ostream<_CharT, _Traits>&, const char*) +void +test03() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream oss_01; + + oss_01.width(-60); + oss_01 << "Consoli"; + VERIFY( oss_01.good() ); + VERIFY( oss_01.str() == L"Consoli" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/2.cc new file mode 100644 index 000000000..361e82938 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/2.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream width() != zero +// left +void +test02(void) +{ + bool test __attribute__((unused)) = true; + std::wstring tmp; + + std::wstring str01 = L""; + std::wostringstream oss01; + oss01.width(5); + oss01.fill(L'0'); + oss01.flags(std::ios_base::left); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == L"00000" ); + + std::wstring str02 = L"1"; + std::wostringstream oss02; + oss02.width(5); + oss02.fill(L'0'); + oss02.flags(std::ios_base::left); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == L"10000" ); + + std::wstring str03 = L"909909"; + std::wostringstream oss03; + oss03.width(5); + oss03.fill(L'0'); + oss03.flags(std::ios_base::left); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == L"909909" ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc new file mode 100644 index 000000000..d2658641d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-1.cc @@ -0,0 +1,45 @@ +// 2006-07-15 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const string str_01(5000000, 'a'); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == str_01.size() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc new file mode 100644 index 000000000..6280fa1d7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-2.cc @@ -0,0 +1,48 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const string str_01(50, 'a'); + + oss_01.width(5000000); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == wstring::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc new file mode 100644 index 000000000..ea0afa7f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-3.cc @@ -0,0 +1,53 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2009 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 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-options "-DWIDTH=500000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 50000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << L'a'; + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == wstring::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc new file mode 100644 index 000000000..d3563a308 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/28277-4.cc @@ -0,0 +1,54 @@ +// 2006-10-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2007, 2008, 2009 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 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-options "-DWIDTH=500000" { target simulator } } + +// 27.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +#ifndef WIDTH +#define WIDTH 50000000 +#endif + +// libstdc++/28277 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream oss_01; + const wstring str_01(50, L'a'); + + oss_01.width(WIDTH); + const streamsize width = oss_01.width(); + + oss_01 << str_01.c_str(); + + VERIFY( oss_01.good() ); + VERIFY( oss_01.str().size() == wstring::size_type(width) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/3.cc new file mode 100644 index 000000000..f4a2a9766 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/3.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// width() != zero +// right +void test03(void) +{ + bool test __attribute__((unused)) = true; + std::wstring tmp; + + std::wstring str01 = L""; + std::wostringstream oss01; + oss01.width(5); + oss01.fill(L'0'); + oss01.flags(std::ios_base::right); + oss01 << str01; + tmp = oss01.str(); + VERIFY( tmp == L"00000" ); + + std::wstring str02 = L"1"; + std::wostringstream oss02; + oss02.width(5); + oss02.fill(L'0'); + oss02.flags(std::ios_base::right); + oss02 << str02; + tmp = oss02.str(); + VERIFY( tmp == L"00001" ); + + std::wstring str03 = L"909909"; + std::wostringstream oss03; + oss03.width(5); + oss03.fill(L'0'); + oss03.flags(std::ios_base::right); + oss03 << str03; + tmp = oss03.str(); + VERIFY( tmp == L"909909" ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/4.cc new file mode 100644 index 000000000..902539e8c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/4.cc @@ -0,0 +1,53 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// stringstream and large strings +void +test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_01; + std::wstring str_tmp; + const int i_max=250; + + std::wostringstream oss_02(str_01, std::ios_base::out); + + // template<_CharT, _Traits> + // basic_ostream& operator<<(ostream&, const wchar_t*) + for (int i = 0; i < i_max; ++i) + oss_02 << L"Test: " << i << std::endl; + str_tmp = oss_02.str(); + VERIFY( !oss_02.bad() ); + VERIFY( oss_02.good() ); + VERIFY( str_tmp != str_01 ); + VERIFY( str_tmp.size() == 2390 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/5.cc new file mode 100644 index 000000000..80f6e475a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/5.cc @@ -0,0 +1,74 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and large strings number 2 +void +test05() +{ + bool test __attribute__((unused)) = true; + std::wstring str05, str10; + + typedef std::wostream::pos_type pos_type; + typedef std::wostream::off_type off_type; + std::wstring str01; + const int size = 1000; + + // initialize string + for(int i=0 ; i < size; i++) { + str01 += L'1'; + str01 += L'2'; + str01 += L'3'; + str01 += L'4'; + str01 += L'5'; + str01 += L'6'; + str01 += L'7'; + str01 += L'8'; + str01 += L'9'; + str01 += L'\n'; + } + + // test 1: out + std::wostringstream sstr01(str01, std::ios_base::out); + std::wostringstream sstr02; + sstr02 << str01; + str05 = sstr01.str(); + str10 = sstr02.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); + + // test 2: in | out + std::wostringstream sstr04(str01, std::ios_base::out | std::ios_base::in); + std::wostringstream sstr05(std::ios_base::in | std::ios_base::out); + sstr05 << str01; + str05 = sstr04.str(); + str10 = sstr05.str(); + VERIFY( str05 == str01 ); + VERIFY( str10 == str01 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/6.cc new file mode 100644 index 000000000..b3d6c203f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/6.cc @@ -0,0 +1,55 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// ostringstream and positioning, multiple writes +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00326.html +void test06() +{ + bool test __attribute__((unused)) = true; + const wchar_t carray01[] = L"mos def & talib kweli are black star"; + + // normal + std::wostringstream ostr1(L"mos def"); + VERIFY( ostr1.str() == L"mos def" ); + ostr1 << L" & talib kweli"; // should overwrite first part of buffer + VERIFY( ostr1.str() == L" & talib kweli" ); + ostr1 << L" are black star"; // should append to string from above + VERIFY( ostr1.str() != carray01 ); + VERIFY( ostr1.str() == L" & talib kweli are black star" ); + + // appending + std::wostringstream ostr2(L"blackalicious", + std::ios_base::out | std::ios_base::ate); + VERIFY( ostr2.str() == L"blackalicious" ); + ostr2 << L" NIA "; // should not overwrite first part of buffer + VERIFY( ostr2.str() == L"blackalicious NIA " ); + ostr2 << L"4: deception (5:19)"; // should append to full string from above + VERIFY( ostr2.str() == L"blackalicious NIA 4: deception (5:19)" ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/7.cc new file mode 100644 index 000000000..3c588ecfc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/7.cc @@ -0,0 +1,91 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +// Global counter, needs to be reset after use. +bool used; + +class gnu_ctype : public std::ctype<wchar_t> +{ +protected: + char_type + do_widen(char c) const + { + used = true; + return std::ctype<wchar_t>::do_widen(c); + } + + const char* + do_widen(const char* low, const char* high, char_type* dest) const + { + used = true; + return std::ctype<wchar_t>::do_widen(low, high, dest); + } +}; + +// 27.6.2.5.4 - Character inserter template functions +// [lib.ostream.inserters.character] +void test07() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const char* buffer = "SFPL 5th floor, outside carrol, the Asian side"; + + wostringstream oss; + oss.imbue(locale(locale::classic(), new gnu_ctype)); + + // 1 + // template<class charT, class traits> + // basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, + // const char* s); + used = false; + oss << buffer; + VERIFY( used ); // Only required for char_type != char + wstring str = oss.str(); + wchar_t c1 = oss.widen(buffer[0]); + VERIFY( str[0] == c1 ); + wchar_t c2 = oss.widen(buffer[1]); + VERIFY( str[1] == c2 ); + + // 2 + // template<class charT, class traits> + // basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& out, + // char c); + used = false; + oss.str(wstring()); + oss << 'b'; + VERIFY( used ); // Only required for char_type != char + str = oss.str(); + wchar_t c3 = oss.widen('b'); + VERIFY( str[0] == c3 ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/8.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/8.cc new file mode 100644 index 000000000..76490b3c5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/8.cc @@ -0,0 +1,58 @@ +// 1999-08-16 bkoz + +// Copyright (C) 1999, 2000, 2002, 2003, 2009, 2010 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 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.6.2.5.4 basic_ostream character inserters + +#include <string> +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +void test08() +{ + bool test __attribute__((unused)) = true; + char* pt = 0; + + // 2 + std::wostringstream woss; + woss << pt; + VERIFY( woss.bad() ); + VERIFY( woss.str().size() == 0 ); + + woss.clear(); + woss << ""; + VERIFY( woss.good() ); + + // 3 + wchar_t* wt = 0; + woss.clear(); + woss << wt; + VERIFY( woss.bad() ); + VERIFY( woss.str().size() == 0 ); + + woss.clear(); + woss << L""; + VERIFY( woss.good() ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/9555-oc.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/9555-oc.cc new file mode 100644 index 000000000..86fa18c4f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_character/wchar_t/9555-oc.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wostream os(&b); + os.exceptions(std::wios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + wchar_t c = L'a'; + const wchar_t* ccp = L"governor ann richards"; + + testthrow(c); + testthrow(ccp); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc new file mode 100644 index 000000000..0c94c6815 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc @@ -0,0 +1,84 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009, 2010 +// 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 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.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +const int size = 1000; +const char name_01[] = "ostream_inserter_other-1.tst"; +const char name_02[] = "ostream_inserter_other-1.txt"; +const char name_03[] = "ostream_inserter_other-2.tst"; +const char name_04[] = "ostream_inserter_other-2.txt"; + +// fstream +void +test02() +{ + typedef std::ios_base::iostate iostate; + bool test __attribute__((unused)) = true; + + // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb) + // filebuf-> NULL + std::ifstream f_in1(name_01); + std::ofstream f_out1(name_02); + std::stringbuf* strbuf01 = 0; + iostate state01 = f_in1.rdstate(); + f_in1 >> strbuf01; + iostate state02 = f_in1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::failbit) != 0 ); + state01 = f_out1.rdstate(); + f_out1 << strbuf01; + state02 = f_out1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::badbit) != 0 ); + + // filebuf->filebuf + std::ifstream f_in(name_01); + std::ofstream f_out(name_02); + f_out << f_in.rdbuf(); + f_in.close(); + f_out.close(); + + // filebuf->stringbuf->filebuf + std::ifstream f_in2(name_03); + std::ofstream f_out2(name_04); // should be different name + std::stringbuf strbuf02; + f_in2 >> &strbuf02; + f_out2 << &strbuf02; + f_in2.close(); + f_out2.close(); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc new file mode 100644 index 000000000..d49251b2c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/2.cc @@ -0,0 +1,69 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2009 +// 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 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.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// via Brent Verner <brent@rcfile.org> +// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html +void +test03(void) +{ + using namespace std; + + typedef ios::pos_type pos_type; + + const char* TEST_IN = "ostream_inserter_other_in"; + const char* TEST_OUT = "ostream_inserter_other_out"; + pos_type i_read, i_wrote, rs, ws; + double tf_size = BUFSIZ * 2.5; + ofstream testfile(TEST_IN); + + for (int i = 0; i < tf_size; ++i) + testfile.put('.'); + testfile.close(); + + ifstream in(TEST_IN); + ofstream out(TEST_OUT); + out << in.rdbuf(); + in.seekg(0, ios_base::beg); + out.seekp(0, ios_base::beg); + rs = in.tellg(); + ws = out.tellp(); + in.seekg(0, ios_base::end); + out.seekp(0, ios_base::end); + i_read = in.tellg() - rs; + i_wrote = out.tellp() - ws; + in.close(); + out.close(); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc new file mode 100644 index 000000000..ba84d7b61 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/3.cc @@ -0,0 +1,47 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3272 +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + istringstream istr("inside betty carter"); + ostringstream ostr; + ostr << istr.rdbuf() << endl; + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + + VERIFY( test ); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc new file mode 100644 index 000000000..dcbd629e5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc @@ -0,0 +1,152 @@ +// 1999-08-16 bkoz +// 1999-11-01 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, +// 2008, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <cstdio> +#include <testsuite_hooks.h> + +class test_buffer_1 : public std::streambuf +{ +public: + test_buffer_1(const std::string& s) : str(s), it(str.begin()) { } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + +private: + const std::string str; + std::string::const_iterator it; +}; + + +class test_buffer_2 : public std::streambuf +{ +public: + test_buffer_2(const std::string& s) : str(s), it(str.begin()) { } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + virtual std::streamsize showmanyc() { return std::distance(it, str.end()); } +private: + const std::string str; + std::string::const_iterator it; +}; + + +class test_buffer_3 : public std::streambuf +{ +public: + test_buffer_3(const std::string& s) : str(s), it(str.begin()) { } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + virtual std::streamsize showmanyc() + { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } +private: + const std::string str; + std::string::const_iterator it; +}; + +class test_buffer_4 : public std::streambuf { +public: + test_buffer_4(const std::string& s) : str(s), it(str.begin()) + { + if (it != str.end()) { + buf[0] = *it++; + setg(buf, buf, buf+1); + } + } + +protected: + virtual int underflow() { return (it != str.end() ? *it : EOF); } + virtual int uflow() { return (it != str.end() ? *it++ : EOF); } + virtual std::streamsize showmanyc() { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } +private: + const std::string str; + std::string::const_iterator it; + char buf[1]; +}; + +void test(const std::string& str, std::streambuf& buf) +{ + bool test __attribute__((unused)) = true; + + std::ostringstream out; + std::istream in(&buf); + + out << in.rdbuf(); + + if (out.str() != str) + VERIFY( false ); +} + +// libstdc++/6745 +// libstdc++/8071 +// libstdc++/8127 +// Jonathan Lennox <lennox@cs.columbia.edu> +void test05() +{ + std::string string_a("Hello, world!"); + std::string string_b(""); + + test_buffer_1 buf1a(string_a); + test_buffer_1 buf1b(string_b); + + test_buffer_2 buf2a(string_a); + test_buffer_2 buf2b(string_b); + + test_buffer_3 buf3a(string_a); + test_buffer_3 buf3b(string_b); + + test_buffer_4 buf4a(string_a); + test_buffer_4 buf4b(string_b); + + test(string_a, buf1a); + test(string_b, buf1b); + + test(string_a, buf2a); + test(string_b, buf2b); + + test(string_a, buf3a); + test(string_b, buf3b); + + test(string_a, buf4a); + test(string_b, buf4b); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc new file mode 100644 index 000000000..1c93f0982 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/5.cc @@ -0,0 +1,98 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2009 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 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.6.2.5.3 basic_ostream manipulator inserters +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// Inserters for manipulators do not behave as formatted output functions. + +#include <ostream> +#include <stdexcept> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +std::ostream& func1(std::ostream&) +{ throw std::runtime_error(""); } + +std::ios& func2(std::ios&) +{ throw std::runtime_error(""); } + +std::ios_base& func3(std::ios_base&) +{ throw std::runtime_error(""); } + +template<typename T> +void test(T& (*f)(T&)) +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_streambuf buf; + std::ostream os(&buf); + + __gnu_test::sync_streambuf buf_tie; + std::ostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.good() ); + VERIFY( !buf_tie.sync_called() ); + + // The manipulator should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( !buf_tie.sync_called() ); +} + +void test05() +{ + test(&func1); + test(&func2); + test(&func3); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc new file mode 100644 index 000000000..8ba8a9b64 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9318-out.cc @@ -0,0 +1,65 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9318 +class Outbuf : public std::streambuf +{ +public: + typedef std::streambuf::traits_type traits_type; + + std::string result() const { return str; } + +protected: + virtual int_type overflow(int_type c = traits_type::eof()) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) + str.push_back(traits_type::to_char_type(c)); + return traits_type::not_eof(c); + } + +private: + std::string str; +}; + +void test10() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf sbuf("Bad Moon Rising", std::ios::in); + Outbuf buf; + std::ostream stream(&buf); + stream << &sbuf; + + VERIFY( buf.result() == "Bad Moon Rising" ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc new file mode 100644 index 000000000..753c95a72 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9424-out.cc @@ -0,0 +1,105 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <cstring> // for memset, memcmp +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9424 +class Outbuf_2 : public std::streambuf +{ + char buf[1]; + +public: + Outbuf_2() + { + setp(buf, buf + 1); + } + + int_type overflow(int_type c) + { + int_type eof = traits_type::eof(); + + if (pptr() < epptr()) + { + if (traits_type::eq_int_type(c, eof)) + return traits_type::not_eof(c); + + *pptr() = traits_type::to_char_type(c); + pbump(1); + return c; + } + + return eof; + } +}; + +class Inbuf_2 : public std::streambuf +{ + static const char buf[]; + const char* current; + int size; + +public: + Inbuf_2() + { + current = buf; + size = std::strlen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const char Inbuf_2::buf[] = "Atteivlis"; + +void test12() +{ + bool test __attribute__((unused)) = true; + + Outbuf_2 outbuf2; + std::ostream os (&outbuf2); + Inbuf_2 inbuf2; + os << &inbuf2; + VERIFY( inbuf2.sgetc() == 't' ); + VERIFY( os.good() ); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc new file mode 100644 index 000000000..80e9dc060 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/9555-oo.cc @@ -0,0 +1,59 @@ +// 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/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::streambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::ostream os(&b); + os.exceptions(std::ios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + buf b; + + testthrow(&b); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc new file mode 100644 index 000000000..d25337453 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_code.cc @@ -0,0 +1,74 @@ +// { dg-options "-std=gnu++0x" } + +// Copyright (C) 2007, 2008, 2009 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <sstream> +#include <system_error> +#include <algorithm> +#include <cstdio> +#include <testsuite_hooks.h> + +// Effects: os << ec.category().name() << ':' << ec.value(); +void test() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + char buf[64]; + error_code e1; + error_code e2(make_error_code(errc::bad_address)); + string s, s1, s2; + + { + ostringstream ostr; + ostr << e1 << endl; + s1 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s1.begin(), s1.end(), ':') != s1.end() ); + + sprintf(buf, "%i", e1.value()); + s = buf; + VERIFY( s1.find(s) != string::npos); + + { + ostringstream ostr; + ostr << e2 << endl; + s2 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s2.begin(), s2.end(), ':') != s2.end() ); + + sprintf(buf, "%i", e2.value()); + s = buf; + VERIFY( s2.find(s) != string::npos); +} + +int +main() +{ + test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc new file mode 100644 index 000000000..5f2373fc5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/error_failbit.cc @@ -0,0 +1,58 @@ +// 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/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test5() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + stream << &sbuf; + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test7() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + __gnu_test::fail_streambuf bib; + + stream << &bib; + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test5(); + test7(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..822763b33 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_badbit_throw.cc @@ -0,0 +1,70 @@ +// 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/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test13() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stream.exceptions(ios_base::badbit); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + } + catch (...) + { VERIFY(false); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test15() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::badbit); + __gnu_test::fail_streambuf bib; + + try + { + stream << &bib; + } + catch (...) + { VERIFY(false); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test13(); + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc new file mode 100644 index 000000000..55d5c47c7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_failbit_throw.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test9() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bob; + ostream stream(&bob); + stream.exceptions(ios_base::failbit); + stringbuf sbuf("Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + VERIFY( false ); + } + catch (ios_base::failure&) + { VERIFY( false ); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test11() +{ + bool test __attribute__((unused)) = true; + ostringstream stream; + stream.exceptions(ios_base::failbit); + __gnu_test::fail_streambuf bib; + + try + { + stream << &bib; + VERIFY( false ); + } + catch (ios_base::failure&) + { VERIFY( false ); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test9(); + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc new file mode 100644 index 000000000..6d28c5f04 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/exceptions_null.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2003, 2005, 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/>. + + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +void test1() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream stream; + stream << static_cast<streambuf*>(0); + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +void test3() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + ostringstream stream; + stream.exceptions(ios_base::badbit); + + try + { + stream << static_cast<streambuf*>(0); + VERIFY( false ); + } + catch (ios_base::failure&) + { + } + + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +// libstdc++/9371 +int main() +{ + test1(); + test3(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc new file mode 100644 index 000000000..6e12a65bf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/1.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2005, 2009, 2010 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 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.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +const int size = 1000; +const char name_01[] = "wostream_inserter_other-1.tst"; +const char name_02[] = "wostream_inserter_other-1.txt"; +const char name_03[] = "wostream_inserter_other-2.tst"; +const char name_04[] = "wostream_inserter_other-2.txt"; + +// fstream +void +test02() +{ + typedef std::ios_base::iostate iostate; + bool test __attribute__((unused)) = true; + + // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb) + // filebuf-> NULL + std::wifstream f_in1(name_01); + std::wofstream f_out1(name_02); + std::wstringbuf* strbuf01 = 0; + iostate state01 = f_in1.rdstate(); + f_in1 >> strbuf01; + iostate state02 = f_in1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::failbit) != 0 ); + state01 = f_out1.rdstate(); + f_out1 << strbuf01; + state02 = f_out1.rdstate(); + VERIFY( state01 != state02 ); + VERIFY( (state02 & std::ios_base::badbit) != 0 ); + + // filebuf->filebuf + std::wifstream f_in(name_01); + std::wofstream f_out(name_02); + f_out << f_in.rdbuf(); + f_in.close(); + f_out.close(); + + // filebuf->stringbuf->filebuf + std::wifstream f_in2(name_03); + std::wofstream f_out2(name_04); // should be different name + std::wstringbuf strbuf02; + f_in2 >> &strbuf02; + f_out2 << &strbuf02; + f_in2.close(); + f_out2.close(); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc new file mode 100644 index 000000000..bb12a7cc4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/2.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <fstream> +#include <testsuite_hooks.h> + +// via Brent Verner <brent@rcfile.org> +// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html +void +test03(void) +{ + using namespace std; + + typedef wios::pos_type pos_type; + + const char* TEST_IN = "wostream_inserter_other_in.txt"; + const char* TEST_OUT = "wostream_inserter_other_out.txt"; + pos_type i_read, i_wrote, rs, ws; + double tf_size = BUFSIZ * 2.5; + ofstream testfile(TEST_IN); + + for (int i = 0; i < tf_size; ++i) + testfile.put(L'.'); + testfile.close(); + + wifstream in(TEST_IN); + wofstream out(TEST_OUT); + out << in.rdbuf(); + in.seekg(0, ios_base::beg); + out.seekp(0, ios_base::beg); + rs = in.tellg(); + ws = out.tellp(); + in.seekg(0, ios_base::end); + out.seekp(0, ios_base::end); + i_read = in.tellg() - rs; + i_wrote = out.tellp() - ws; + in.close(); + out.close(); +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc new file mode 100644 index 000000000..51e329b5d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/3.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3272 +void test04() +{ + using namespace std; + bool test __attribute__((unused)) = true; + wistringstream istr(L"inside betty carter"); + wostringstream ostr; + ostr << istr.rdbuf() << endl; + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + + VERIFY( test ); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc new file mode 100644 index 000000000..3cd771c7f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc @@ -0,0 +1,184 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.4 basic_ostream character inserters + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +class test_buffer_1 : public std::wstreambuf +{ +public: + test_buffer_1(const std::wstring& s) + : str(s), it(str.begin()) { } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + +private: + const std::wstring str; + std::wstring::const_iterator it; +}; + + +class test_buffer_2 : public std::wstreambuf +{ +public: + test_buffer_2(const std::wstring& s) + : str(s), it(str.begin()) { } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + + virtual std::streamsize + showmanyc() + { return std::distance(it, str.end()); } + +private: + const std::wstring str; + std::wstring::const_iterator it; +}; + + +class test_buffer_3 : public std::wstreambuf +{ +public: + test_buffer_3(const std::wstring& s) + : str(s), it(str.begin()) { } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + + virtual std::streamsize + showmanyc() + { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } + +private: + const std::wstring str; + std::wstring::const_iterator it; +}; + +class test_buffer_4 : public std::wstreambuf +{ +public: + test_buffer_4(const std::wstring& s) + : str(s), it(str.begin()) + { + if (it != str.end()) + { + buf[0] = *it++; + setg(buf, buf, buf+1); + } + } + +protected: + virtual int_type + underflow() + { return (it != str.end() ? *it : WEOF); } + + virtual int_type + uflow() + { return (it != str.end() ? *it++ : WEOF); } + + virtual std::streamsize + showmanyc() + { + std::streamsize ret = std::distance(it, str.end()); + return ret > 0 ? ret : -1; + } + +private: + const std::wstring str; + std::wstring::const_iterator it; + wchar_t buf[1]; +}; + +void test(const std::wstring& str, std::wstreambuf& buf) +{ + bool test __attribute__((unused)) = true; + + std::wostringstream out; + std::wistream in(&buf); + + out << in.rdbuf(); + + if (out.str() != str) + VERIFY( false ); +} + +// libstdc++/6745 +// libstdc++/8071 +// libstdc++/8127 +// Jonathan Lennox <lennox@cs.columbia.edu> +void test05() +{ + std::wstring string_a(L"Hello, world!"); + std::wstring string_b(L""); + + test_buffer_1 buf1a(string_a); + test_buffer_1 buf1b(string_b); + + test_buffer_2 buf2a(string_a); + test_buffer_2 buf2b(string_b); + + test_buffer_3 buf3a(string_a); + test_buffer_3 buf3b(string_b); + + test_buffer_4 buf4a(string_a); + test_buffer_4 buf4b(string_b); + + test(string_a, buf1a); + test(string_b, buf1b); + + test(string_a, buf2a); + test(string_b, buf2b); + + test(string_a, buf3a); + test(string_b, buf3b); + + test(string_a, buf4a); + test(string_b, buf4b); +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc new file mode 100644 index 000000000..e8818f542 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/5.cc @@ -0,0 +1,96 @@ +// Copyright (C) 2005, 2009 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 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.6.2.5.3 basic_ostream manipulator inserters +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// Inserters for manipulators do not behave as formatted output functions. + +#include <ostream> +#include <stdexcept> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +std::wostream& func1(std::wostream&) +{ throw std::runtime_error(""); } + +std::wios& func2(std::wios&) +{ throw std::runtime_error(""); } + +std::ios_base& func3(std::ios_base&) +{ throw std::runtime_error(""); } + +template<typename T> +void test(T& (*f)(T&)) +{ + bool test __attribute__((unused)) = true; + + __gnu_test::sync_wstreambuf buf; + std::wostream os(&buf); + + __gnu_test::sync_wstreambuf buf_tie; + std::wostream os_tie(&buf_tie); + + // No sentry should be constructed so os.tie()->flush() should not be + // called. + os.tie(&os_tie); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.good() ); + VERIFY( !buf_tie.sync_called() ); + + // The manipulator should be called even if !os.good(). + os.setstate(std::ios_base::eofbit); + + try + { + os << f; + // Exceptions thrown by f should not be caught + VERIFY( false ); + } + catch (std::runtime_error&) + { + } + + // Exceptions thrown by f should not cause badbit to be set + VERIFY( os.rdstate() == std::ios_base::eofbit ); + VERIFY( !buf_tie.sync_called() ); +} + +void test05() +{ + test(&func1); + test(&func2); + test(&func3); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc new file mode 100644 index 000000000..a02ed488b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9318-out.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9318 +class Outbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + std::wstring result() const { return str; } + +protected: + virtual int_type + overflow(int_type c = traits_type::eof()) + { + if (!traits_type::eq_int_type(c, traits_type::eof())) + str.push_back(traits_type::to_char_type(c)); + return traits_type::not_eof(c); + } + +private: + std::wstring str; +}; + +void test10() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf sbuf(L"Bad Moon Rising", std::wios::in); + Outbuf buf; + std::wostream stream(&buf); + stream << &sbuf; + + VERIFY( buf.result() == L"Bad Moon Rising" ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc new file mode 100644 index 000000000..7b89d26df --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9424-out.cc @@ -0,0 +1,105 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <cwchar> +#include <streambuf> +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/9424 +class Outbuf_2 : public std::wstreambuf +{ + wchar_t buf[1]; + +public: + Outbuf_2() + { + setp(buf, buf + 1); + } + + int_type overflow(int_type c) + { + int_type eof = traits_type::eof(); + + if (pptr() < epptr()) + { + if (traits_type::eq_int_type(c, eof)) + return traits_type::not_eof(c); + + *pptr() = traits_type::to_char_type(c); + pbump(1); + return c; + } + + return eof; + } +}; + +class Inbuf_2 : public std::wstreambuf +{ + static const wchar_t buf[]; + const wchar_t* current; + int size; + +public: + Inbuf_2() + { + current = buf; + size = std::wcslen(buf); + } + + int_type underflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current); + return traits_type::eof(); + } + + int_type uflow() + { + if (current < buf + size) + return traits_type::to_int_type(*current++); + return traits_type::eof(); + } +}; + +const wchar_t Inbuf_2::buf[] = L"Atteivlis"; + +void test12() +{ + bool test __attribute__((unused)) = true; + + Outbuf_2 outbuf2; + std::wostream os (&outbuf2); + Inbuf_2 inbuf2; + os << &inbuf2; + VERIFY( inbuf2.sgetc() == L't' ); + VERIFY( os.good() ); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc new file mode 100644 index 000000000..89a5d361e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/9555-oo.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +struct buf: std::wstreambuf +{ + virtual int_type overflow(int_type) + { throw 0; } +}; + +template<typename T> +void testthrow(T arg) +{ + bool test __attribute__((unused)) = true; + buf b; + std::wostream os(&b); + os.exceptions(std::wios::badbit); + + try + { + os << arg; + } + catch(int) + { + // Expected return is zero. + VERIFY( os.bad() ); + } + catch(...) + { + VERIFY( false ); + } +} + +int main() +{ + buf b; + + testthrow(&b); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc new file mode 100644 index 000000000..16f9108a3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_code.cc @@ -0,0 +1,75 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-swprintf "" } + +// Copyright (C) 2007, 2008, 2009, 2010 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ostream> +#include <sstream> +#include <system_error> +#include <algorithm> +#include <cwchar> +#include <testsuite_hooks.h> + +// Effects: os << ec.category().name() << ':' << ec.value(); +void test() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wchar_t buf[64]; + error_code e1; + error_code e2(make_error_code(errc::bad_address)); + wstring s, s1, s2; + + { + wostringstream ostr; + ostr << e1 << endl; + s1 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s1.begin(), s1.end(), L':') != s1.end() ); + + swprintf(buf, 64, L"%i", e1.value()); + s = buf; + VERIFY( s1.find(s) != string::npos); + + { + wostringstream ostr; + ostr << e2 << endl; + s2 = ostr.str(); + + if (ostr.rdstate() & ios_base::eofbit) + test = false; + } + VERIFY( test ); + VERIFY( find(s2.begin(), s2.end(), L':') != s2.end() ); + + swprintf(buf, 64, L"%i", e2.value()); + s = buf; + VERIFY( s2.find(s) != string::npos); +} + +int +main() +{ + test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc new file mode 100644 index 000000000..3df90b873 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/error_failbit.cc @@ -0,0 +1,58 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test5() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bob; + wostream stream(&bob); + wstringbuf sbuf(L"Foo, bar, qux", ios_base::in); + + stream << &sbuf; + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test7() +{ + bool test __attribute__((unused)) = true; + wostringstream stream; + __gnu_test::fail_wstreambuf bib; + + stream << &bib; + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test5(); + test7(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..954d56790 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test13() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bob; + wostream stream(&bob); + stream.exceptions(ios_base::badbit); + wstringbuf sbuf(L"Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + } + catch (...) + { VERIFY(false); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test15() +{ + bool test __attribute__((unused)) = true; + wostringstream stream; + stream.exceptions(ios_base::badbit); + __gnu_test::fail_wstreambuf bib; + + try + { + stream << &bib; + } + catch (...) + { VERIFY(false); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test13(); + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc new file mode 100644 index 000000000..789d3cc3c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_failbit_throw.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test9() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bob; + wostream stream(&bob); + stream.exceptions(ios_base::failbit); + wstringbuf sbuf(L"Foo, bar, qux", ios_base::in); + + try + { + stream << &sbuf; + VERIFY( false ); + } + catch (ios_base::failure&) + { VERIFY( false ); } + catch (__gnu_test::overflow_error&) + { } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +void test11() +{ + bool test __attribute__((unused)) = true; + wostringstream stream; + stream.exceptions(ios_base::failbit); + __gnu_test::fail_wstreambuf bib; + + try + { + stream << &bib; + VERIFY( false ); + } + catch (ios_base::failure&) + { VERIFY( false ); } + catch (__gnu_test::underflow_error&) + { } + catch (...) + { VERIFY( false ); } + + VERIFY( stream.rdstate() & ios_base::failbit ); + VERIFY( (stream.rdstate() & ios_base::badbit) == 0 ); +} + +// libstdc++/9371 +int main() +{ + test9(); + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc new file mode 100644 index 000000000..076aece64 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/exceptions_null.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 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/>. + + +#include <istream> +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> + +void test1() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream stream; + stream << static_cast<wstreambuf*>(0); + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +void test3() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wostringstream stream; + stream.exceptions(ios_base::badbit); + + try + { + stream << static_cast<wstreambuf*>(0); + VERIFY( false ); + } + catch (ios_base::failure&) + { + } + + VERIFY( stream.rdstate() & ios_base::badbit ); +} + +// libstdc++/9371 +int main() +{ + test1(); + test3(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/put/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/put/char/1.cc new file mode 100644 index 000000000..8db9012f3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/put/char/1.cc @@ -0,0 +1,72 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 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.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::put(char_type) is an unformatted output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::streambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::ostream os(&buf); + + VERIFY( os.good() ); + + os.put('a'); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.put('b'); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/put/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/put/wchar_t/1.cc new file mode 100644 index 000000000..d9b135d75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/put/wchar_t/1.cc @@ -0,0 +1,70 @@ +// Copyright (C) 2005, 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.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::put(char_type) is an unformatted output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::wstreambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::wostream os(&buf); + + VERIFY( os.good() ); + + os.put(L'a'); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.put(L'b'); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/base_classes.cc new file mode 100644 index 000000000..08727f3c5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/base_classes.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <ostream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::ostream test_type; + typedef std::ios base_type; + + std::stringbuf buf; + const test_type& obj = *new test_type(&buf); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..fd7ad18fd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/explicit_instantiation.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.6.2.1 basic_ostream +// NB: This file is for testing ostream with NO OTHER INCLUDES. + +#include <ostream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_ostream<type_t, char_traits<type_t> >; + template class basic_ostream<pod_char, char_traits<pod_char> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/typedefs.cc new file mode 100644 index 000000000..21e8ed99c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/requirements/typedefs.cc @@ -0,0 +1,39 @@ +// { dg-do compile } +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.6.2.1 basic_ostream +// NB: This file is for testing ostream with NO OTHER INCLUDES. + +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::ostream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc new file mode 100644 index 000000000..36fa2c03e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc @@ -0,0 +1,92 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// 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 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.6.2.4 basic_ostream seek members [lib.ostream.seeks] +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +// { dg-require-fileio "" } + +#include <ostream> +#include <istream> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << '-' << i << s << '\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::ios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, '\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// fstream +// libstdc++/2346 +void test02() +{ + std::fstream ofstrm; + ofstrm.open("istream_seeks-3.txt", std::ios::out); + if (!ofstrm) + std::abort(); + write_rewind(ofstrm); + ofstrm.close(); + + std::fstream ifstrm; + ifstrm.open("istream_seeks-3.txt", std::ios::in); + check_contents(ifstrm); + ifstrm.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc new file mode 100644 index 000000000..d0030eaf7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-sstream.cc @@ -0,0 +1,80 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2009 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 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.6.2.4 basic_ostream seek members [lib.ostream.seeks] + +#include <ostream> +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << '-' << i << s << '\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::iostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::ios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, '\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// stringstream +// libstdc++/2346 +// N.B. The original testcase was broken, using tellg/seekg in write_rewind. +void test03() +{ + std::stringstream sstrm; + + write_rewind(sstrm); + check_contents(sstrm); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..fac361e14 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/exceptions_badbit_throw.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + ostream::pos_type pos = ostream::pos_type(); + + try + { + stream.seekp(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + ostream::off_type off(5); + + try + { + stream.seekp(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc new file mode 100644 index 000000000..e37cec8f6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2005, 2006, 2007, 2009 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 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.6.2.4 basic_ostream seek members [lib.ostream.seeks] +// @require@ %-*.tst %-*.txt +// @diff@ %-*.tst %-*.txt + +#include <ostream> +#include <istream> +#include <fstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << L'-' << i << s << L'\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::wios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, L'\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// fstream +// libstdc++/2346 +void test02() +{ + std::wfstream ofstrm; + ofstrm.open("wistream_seeks-3.txt", std::wios::out); + if (!ofstrm) + std::abort(); + write_rewind(ofstrm); + ofstrm.close(); + + std::wfstream ifstrm; + ifstrm.open("wistream_seeks-3.txt", std::wios::in); + check_contents(ifstrm); + ifstrm.close(); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc new file mode 100644 index 000000000..4120c8827 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc @@ -0,0 +1,78 @@ +// Copyright (C) 2005, 2009 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 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.6.2.4 basic_ostream seek members [lib.ostream.seeks] + +#include <ostream> +#include <istream> +#include <sstream> +#include <testsuite_hooks.h> + +const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; +const int times = 10; + +void write_rewind(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + for (int j = 0; j < times; j++) + { + std::streampos begin = stream.tellp(); + + for (int i = 0; i < times; ++i) + stream << j << L'-' << i << s << L'\n'; + + stream.seekp(begin); + } + VERIFY( stream.good() ); +} + +void check_contents(std::wiostream& stream) +{ + bool test __attribute__((unused)) = true; + + stream.clear(); + stream.seekg(0, std::wios::beg); + int i = 0; + int loop = times * times + 2; + while (i < loop) + { + stream.ignore(80, L'\n'); + if (stream.good()) + ++i; + else + break; + } + VERIFY( i == times ); +} + +// stringstream +// libstdc++/2346 +// N.B. The original testcase was broken, using tellg/seekg in write_rewind. +void test03() +{ + std::wstringstream sstrm; + + write_rewind(sstrm); + check_contents(sstrm); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..737691f2e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,89 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + wostream::pos_type pos = wostream::pos_type(); + + try + { + stream.seekp(pos); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +void test02() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + wostream::off_type off(5); + + try + { + stream.seekp(off, ios_base::cur); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY( false ); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/1.cc new file mode 100644 index 000000000..d7a4812e1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/1.cc @@ -0,0 +1,44 @@ +// 2003-02-06 Paolo Carlini <pcarlini@unitus.it> + +// 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.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9562 +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf strbuf01; + std::ostream strm1(&strbuf01); + const std::ostream::sentry sentry1(strm1); + + VERIFY( bool(sentry1) == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/2.cc new file mode 100644 index 000000000..1a68b1d9b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/char/2.cc @@ -0,0 +1,64 @@ +// 2003-02-06 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2005, 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.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9563 +struct buf : std::streambuf +{ + std::ios *io_; + + buf(std::ios *io) + : io_(io) { } + + virtual int + sync() + { + io_->setstate (std::ios::failbit); + return 0; + } +}; + +void +test02() +{ + bool test __attribute__((unused)) = true; + + buf b(0); + std::ostream strm(&b); + + buf tb(&strm); + std::ostream tied(&tb); + + strm.tie(&tied); + std::ostream::sentry s(strm); + + VERIFY( !s ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/pod/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/pod/1.cc new file mode 100644 index 000000000..00becef25 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/pod/1.cc @@ -0,0 +1,123 @@ +// 1999-10-14 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, +// 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.6.1.1.2 class basic_istream::sentry + +#include <ostream> +#include <sstream> +#include <typeinfo> +#include <ext/pod_char_traits.h> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +void test01() +{ + using namespace std; + using __gnu_test::pod_ushort; + typedef basic_string<pod_ushort> string_type; + typedef basic_stringbuf<pod_ushort> stringbuf_type; + typedef basic_ostream<pod_ushort> ostream_type; + + bool test __attribute__((unused)) = true; + + + const string_type str01; + stringbuf_type* strbuf01 = 0; + stringbuf_type strbuf02(str01); + ostream_type ostr01(strbuf01); + ostream_type ostr02(&strbuf02); + + // test negatives + try + { + ostream_type::sentry sentry01(ostr01); + } + catch (std::bad_cast& obj) + { + // Not ok, throws bad_cast because locale has no ctype facet, + // but none is needed for ostream::sentry. + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + // imbued. + const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>); + ostr01.imbue(loc); + try + { + ostream_type::sentry sentry01(ostr01); + VERIFY( bool(sentry01) == false ); + } + catch (...) + { + VERIFY( false ); + } + + // test positive + try + { + ostream_type::sentry sentry03(ostr02); + } + catch (std::bad_cast& obj) + { + // Not ok, throws bad_cast because locale has no ctype facet, + // but none is needed for ostream::sentry. + VERIFY( false ); + } + catch (...) + { + VERIFY( false ); + } + + // imbued. + ostr02.clear(); + ostr02.imbue(loc); + try + { + ostream_type::sentry sentry03(ostr02); + VERIFY( bool(sentry03) == true ); + } + catch (...) + { + VERIFY( false ); + } +} + +#if !__GXX_WEAK__ +// Explicitly instantiate for systems with no COMDAT or weak support. +template + const std::basic_string<__gnu_test::pod_ushort>::size_type + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; + +template + const __gnu_test::pod_ushort + std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; +#endif + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/1.cc new file mode 100644 index 000000000..aeac11f6d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/1.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2005, 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.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9562 +void +test01() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf strbuf01; + std::wostream strm1(&strbuf01); + const std::wostream::sentry sentry1(strm1); + + VERIFY( bool(sentry1) == true ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/2.cc new file mode 100644 index 000000000..ad8174811 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/sentry/wchar_t/2.cc @@ -0,0 +1,62 @@ +// Copyright (C) 2005, 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.6.2.3 class basic_ostream::sentry + +#include <ostream> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9563 +struct buf : std::wstreambuf +{ + std::wios *io_; + + buf(std::wios *io) + : io_(io) { } + + virtual int + sync() + { + io_->setstate (std::wios::failbit); + return 0; + } +}; + +void +test02() +{ + bool test __attribute__((unused)) = true; + + buf b(0); + std::wostream strm(&b); + + buf tb(&strm); + std::wostream tied(&tb); + + strm.tie(&tied); + std::wostream::sentry s(strm); + + VERIFY( !s ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc new file mode 100644 index 000000000..ab492e17e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/1.cc @@ -0,0 +1,65 @@ +// 2000-06-29 bkoz + +// Copyright (C) 2000, 2003, 2004, 2009 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 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.6.2.4 basic_ostream seek members + +// { dg-require-fileio "" } + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef ios::off_type off_type; + typedef ios::pos_type pos_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "ostream_seeks-1.txt"; + + // out + ostringstream ost1; + pos_type p1 = ost1.tellp(); + + ofstream ofs1; + pos_type p2 = ofs1.tellp(); + + // N.B. We implement the resolution of DR 453 and + // ostringstream::tellp() doesn't fail. + VERIFY( p1 == pos_type(off_type(0)) ); + VERIFY( p2 == pos_type(off_type(-1)) ); + + // out + // test ctors leave things in the same positions... + ostringstream ost2("bob_marley:kaya"); + p1 = ost2.tellp(); + + ofstream ofs2(str_lit01); + p2 = ofs2.tellp(); + + VERIFY( p1 == p2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc new file mode 100644 index 000000000..abfa2ff27 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/2.cc @@ -0,0 +1,49 @@ +// 2000-03-23 bkoz + +// Copyright (C) 2000, 2003, 2004, 2009 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. +// + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef std::stringbuf::pos_type pos_type; + typedef std::stringbuf::off_type off_type; + bool test __attribute__((unused)) = true; + + // tellp + ostringstream ost; + pos_type pos1; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(0)) ); + ost << "RZA "; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(4)) ); + ost << "ghost dog: way of the samurai"; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(33)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc new file mode 100644 index 000000000..30cbc1714 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/char/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// 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/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_streambuf bib; + ostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellp(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/1.cc new file mode 100644 index 000000000..65affb91e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/1.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2005, 2009 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 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.6.2.4 basic_ostream seek members + +#include <ostream> +#include <sstream> +#include <fstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef wios::off_type off_type; + typedef wios::pos_type pos_type; + + bool test __attribute__((unused)) = true; + const char str_lit01[] = "wostream_seeks-1.txt"; + + // out + wostringstream ost1; + pos_type p1 = ost1.tellp(); + + wofstream ofs1; + pos_type p2 = ofs1.tellp(); + + // N.B. We implement the resolution of DR 453 and + // ostringstream::tellp() doesn't fail. + VERIFY( p1 == pos_type(off_type(0)) ); + VERIFY( p2 == pos_type(off_type(-1)) ); + + // out + // test ctors leave things in the same positions... + wostringstream ost2(L"bob_marley:kaya"); + p1 = ost2.tellp(); + + wofstream ofs2(str_lit01); + p2 = ofs2.tellp(); + + VERIFY( p1 == p2 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/2.cc new file mode 100644 index 000000000..98287f439 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/2.cc @@ -0,0 +1,47 @@ +// Copyright (C) 2005, 2009 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 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. +// + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + bool test __attribute__((unused)) = true; + + // tellp + wostringstream ost; + pos_type pos1; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(0)) ); + ost << L"RZA "; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(4)) ); + ost << L"ghost dog: way of the samurai"; + pos1 = ost.tellp(); + VERIFY( pos1 == pos_type(off_type(33)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc new file mode 100644 index 000000000..434485b92 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/tellp/wchar_t/exceptions_badbit_throw.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ostream> +#include <streambuf> +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +using namespace std; + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::fail_wstreambuf bib; + wostream stream(&bib); + stream.exceptions(ios_base::badbit); + + try + { + stream.tellp(); + VERIFY( false ); + } + catch (const __gnu_test::positioning_error&) + { + // stream should set badbit and rethrow facet_error. + VERIFY( stream.bad() ); + VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); + VERIFY( !stream.eof() ); + } + catch (...) + { + VERIFY(false); + } +} + +// libstdc++/9546 +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/1.cc new file mode 100644 index 000000000..49b712de2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/write/char/1.cc @@ -0,0 +1,73 @@ +// 2003-09-22 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 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.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::write(const char_type*, streamsize) is an unformatted +// output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::streambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::ostream os(&buf); + + VERIFY( os.good() ); + + os.write("a", 1); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.write("b", 1); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/1.cc new file mode 100644 index 000000000..0bdd4d989 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostream/write/wchar_t/1.cc @@ -0,0 +1,71 @@ +// Copyright (C) 2005, 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.6.2.6 Unformatted output functions +// +// _GLIBCXX_RESOLVE_LIB_DEFECTS +// DR 60. What is a formatted input function? +// basic_ostream::write(const char_type*, streamsize) is an unformatted +// output function. +// DR 63. Exception-handling policy for unformatted output. +// Unformatted output functions should catch exceptions thrown +// from streambuf members. + +#include <ostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Buf : public std::wstreambuf +{ +protected: + virtual int_type + overflow(int_type = traits_type::eof()) + { throw 0; } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf buf; + std::wostream os(&buf); + + VERIFY( os.good() ); + + os.write(L"a", 1); + + VERIFY( os.rdstate() == std::ios_base::badbit ); + + os.clear(); + os.exceptions(std::ios_base::badbit); + + try + { + os.write(L"b", 1); + VERIFY( false ); + } + catch (int) + { + VERIFY( os.rdstate() == std::ios_base::badbit ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/2020.cc new file mode 100644 index 000000000..da6bb68cd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_ostringstream<__gnu_test::pod_ushort> gnu_osstr; + + try + { + gnu_osstr obj; + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/3.cc new file mode 100644 index 000000000..156433f67 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/3.cc @@ -0,0 +1,63 @@ +// 2001-05-23 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.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +// 03: sanity checks for strings, stringbufs +void +test03() +{ + bool test __attribute__((unused)) = false; + + // Empty string sanity check. + std::string str01; + std::string::iterator __i_start = str01.begin(); + std::string::iterator __i_end = str01.end(); + std::string::size_type len = str01.size(); + test = __i_start == __i_end; + VERIFY( len == 0 ); + + // Full string sanity check. + std::string str02("these golden days, i spend waiting for you:\n" + "Betty Carter on Verve with I'm Yours and You're Mine."); + __i_start = str02.begin(); + __i_end = str02.end(); + len = str02.size(); + VERIFY( __i_start != __i_end ); + VERIFY( len != 0 ); + + // Test an empty ostringstream for sanity. + std::ostringstream ostrstream0; + std::string str03 = ostrstream0.str(); + __i_start = str03.begin(); + __i_end = str03.end(); + len = str03.size(); + VERIFY( __i_start == __i_end ); + VERIFY( len == 0 ); + VERIFY( str01 == str03 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/3.cc new file mode 100644 index 000000000..91b799741 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/3.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +// 03: sanity checks for strings, stringbufs +void +test03() +{ + bool test __attribute__((unused)) = false; + + // Empty string sanity check. + std::wstring str01; + std::wstring::iterator __i_start = str01.begin(); + std::wstring::iterator __i_end = str01.end(); + std::wstring::size_type len = str01.size(); + test = __i_start == __i_end; + VERIFY( len == 0 ); + + // Full string sanity check. + std::wstring str02(L"these golden days, i spend waiting for you:\n" + L"Betty Carter on Verve with I'm Yours and You're Mine."); + __i_start = str02.begin(); + __i_end = str02.end(); + len = str02.size(); + VERIFY( __i_start != __i_end ); + VERIFY( len != 0 ); + + // Test an empty ostringstream for sanity. + std::wostringstream ostrstream0; + std::wstring str03 = ostrstream0.str(); + __i_start = str03.begin(); + __i_end = str03.end(); + len = str03.size(); + VERIFY( __i_start == __i_end ); + VERIFY( len == 0 ); + VERIFY( str01 == str03 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/pthread3.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/pthread3.cc new file mode 100644 index 000000000..5b87d84c0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/pthread3.cc @@ -0,0 +1,57 @@ +// 2002-01-23 Loren J. Rittle <rittle@labs.mot.com> <ljrittle@acm.org> +// Adpated from libstdc++/5347 submitted by markus.breuer@materna.de +// +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 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/>. + +// { dg-do run { target *-*-freebsd* *-*-netbsd* *-*-linux* *-*-solaris* *-*-cygwin *-*-darwin* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthread" { target *-*-freebsd* *-*-netbsd* *-*-linux* alpha*-*-osf* mips-sgi-irix6* } } +// { dg-options "-pthreads" { target *-*-solaris* } } + +#include <sstream> +#include <pthread.h> + +const int max_thread_count = 2; +const int max_loop_count = 1000000; + +void* +thread_main (void *) +{ + for (int i = 0; i < max_loop_count; i++) + std::ostringstream oss; + + return 0; +} + +int +main() +{ + pthread_t tid[max_thread_count]; + +#if defined(__sun) && defined(__svr4__) && _XOPEN_VERSION >= 500 + pthread_setconcurrency (max_thread_count); +#endif + + for (int i = 0; i < max_thread_count; i++) + pthread_create (&tid[i], 0, thread_main, 0); + + for (int i = 0; i < max_thread_count; i++) + pthread_join (tid[i], 0); + + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..51f5547b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/char/2832.cc @@ -0,0 +1,74 @@ +// 2001-05-23 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.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::stringbuf sbuf(str01); + std::streambuf* pbasebuf0 = &sbuf; + + std::ostringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::stringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::stringbuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc new file mode 100644 index 000000000..b89464043 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/rdbuf/wchar_t/2832.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::wios& stream, std::wstreambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::wstreambuf* +active_buffer(std::wios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const wchar_t* strlit01 = L"fuck war"; + const std::wstring str00; + const std::wstring str01(strlit01); + std::wstring str02; + std::wstringbuf sbuf(str01); + std::wstreambuf* pbasebuf0 = &sbuf; + + std::wostringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::wstringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::wstreambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::wstringbuf* const buf2 = sstrm1.rdbuf(); + std::wstreambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::wstringbuf* psbuf = dynamic_cast<std::wstringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/base_classes.cc new file mode 100644 index 000000000..d0b643afb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <ostream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::ostringstream test_type; + typedef std::ostream base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..819998914 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/explicit_instantiation.cc @@ -0,0 +1,31 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.7.3 - Class basic_ostringstream +// NB: This file is for testing basic_ostringstream with NO OTHER INCLUDES. + +#include <sstream> + +namespace std +{ + typedef short type_t; + template class basic_ostringstream<type_t, char_traits<type_t> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/typedefs.cc new file mode 100644 index 000000000..4772560f2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/requirements/typedefs.cc @@ -0,0 +1,37 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 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.3 - Class basic_ostringstream +// NB: This file is for testing basic_ostringstream with NO OTHER INCLUDES. + +#include <sstream> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::ostringstream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/char/1.cc new file mode 100644 index 000000000..5fe718868 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/char/1.cc @@ -0,0 +1,47 @@ +// 2001-05-23 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.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::ostringstream os01; + const std::string str00; + const std::string str01 = "123"; + std::string str02; + + // string str() const + str02 = os01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + os01.str(str01); + str02 = os01.str(); + VERIFY( str01 == str02 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/char/2.cc new file mode 100644 index 000000000..c1bb1fc83 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/char/2.cc @@ -0,0 +1,45 @@ +// 2001-05-23 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.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +// user-reported error +class derived_oss: public std::ostringstream +{ +public: + derived_oss() : std::ostringstream() { } +}; + +void +test04() +{ + bool test __attribute__((unused)) = true; + derived_oss yy; + yy << "buena vista social club\n"; + VERIFY( yy.str() == std::string("buena vista social club\n") ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/wchar_t/1.cc new file mode 100644 index 000000000..b66d8fa25 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/wchar_t/1.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2004, 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.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::wostringstream os01; + const std::wstring str00; + const std::wstring str01 = L"123"; + std::wstring str02; + + // string str() const + str02 = os01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + os01.str(str01); + str02 = os01.str(); + VERIFY( str01 == str02 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/wchar_t/2.cc new file mode 100644 index 000000000..d34b05895 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/str/wchar_t/2.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.3.2 member functions (ostringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +// user-reported error +class derived_oss: public std::wostringstream +{ +public: + derived_oss() : std::wostringstream() { } +}; + +void +test04() +{ + bool test __attribute__((unused)) = true; + derived_oss yy; + yy << L"buena vista social club\n"; + VERIFY( yy.str() == std::wstring(L"buena vista social club\n") ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/2020.cc new file mode 100644 index 000000000..eae9453a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <fstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +class gnu_sbuf: public std::basic_streambuf<__gnu_test::pod_ushort> +{ }; + +void test07() +{ + bool test __attribute__((unused)) = true; + + try + { gnu_sbuf obj; } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc new file mode 100644 index 000000000..6308318f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/char/1.cc @@ -0,0 +1,45 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::constraint_streambuf buf01; + + // 27.5.2.1 basic_streambuf ctors + // default ctor initializes + // - all pointer members to null pointers + // - locale to current global locale + VERIFY( buf01.check_pointers() ); + VERIFY( buf01.getloc() == std::locale() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc new file mode 100644 index 000000000..0fb1f5cbd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/cons/wchar_t/1.cc @@ -0,0 +1,45 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + __gnu_test::constraint_wstreambuf buf01; + + // 27.5.2.1 basic_streambuf ctors + // default ctor initializes + // - all pointer members to null pointers + // - locale to current global locale + VERIFY( buf01.check_pointers() ); + VERIFY( buf01.getloc() == std::locale() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc new file mode 100644 index 000000000..6e2a4a4a0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/1.cc @@ -0,0 +1,52 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class testbuf : public std::streambuf +{ +public: + typedef std::streambuf::traits_type traits_type; + + testbuf() : std::streambuf() { } +}; + +// test the streambuf locale settings +void test02() +{ + testbuf buf; + std::locale loc_c = std::locale::classic(); + loc_c = buf.getloc(); + buf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = buf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc new file mode 100644 index 000000000..5b54ebc36 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc @@ -0,0 +1,50 @@ +// { dg-require-namedlocale "is_IS.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.5.2.4.1 Locales + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class Buf1 : public std::streambuf +{ +protected: + void imbue(const std::locale&) + { } +}; + +// libstdc++/13007 +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf1 buf; + std::locale loc(std::locale("is_IS.UTF-8")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc new file mode 100644 index 000000000..4b3c903c1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc @@ -0,0 +1,62 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.5.2.4.1 Locales + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class Buf2 : public std::streambuf +{ +public: + std::locale before; + std::locale after; + +protected: + void imbue(const std::locale& loc) + { + before = getloc(); + + std::streambuf::imbue(loc); + + after = getloc(); + } +}; + +// libstdc++/13007 +void test02() +{ + bool test __attribute__((unused)) = true; + + Buf2 buf; + std::locale loc(std::locale("en_US")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); + VERIFY( buf.before == std::locale::classic() ); + VERIFY( buf.after == std::locale::classic() ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc new file mode 100644 index 000000000..dcc42ee7a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/char/9322.cc @@ -0,0 +1,65 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class testbuf : public std::streambuf +{ +public: + typedef std::streambuf::traits_type traits_type; + + testbuf() : std::streambuf() { } +}; + +// libstdc++/9322 +void test08() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + testbuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc new file mode 100644 index 000000000..f8448912a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/1.cc @@ -0,0 +1,52 @@ +// 981208 bkoz test functionality of basic_streambuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class testbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + testbuf() : std::wstreambuf() { } +}; + +// test the streambuf locale settings +void test02() +{ + testbuf buf; + std::locale loc_c = std::locale::classic(); + loc_c = buf.getloc(); + buf.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = buf.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc new file mode 100644 index 000000000..b0e7a61b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc @@ -0,0 +1,50 @@ +// { dg-require-namedlocale "is_IS.UTF-8" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.5.2.4.1 Locales + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class Buf1 : public std::wstreambuf +{ +protected: + void imbue(const std::locale&) + { } +}; + +// libstdc++/13007 +void test01() +{ + bool test __attribute__((unused)) = true; + + Buf1 buf; + std::locale loc(std::locale("is_IS.UTF-8")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc new file mode 100644 index 000000000..15007de2a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc @@ -0,0 +1,62 @@ +// { dg-require-namedlocale "en_US" } + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.5.2.4.1 Locales + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class Buf2 : public std::wstreambuf +{ +public: + std::locale before; + std::locale after; + +protected: + void imbue(const std::locale& loc) + { + before = getloc(); + + std::wstreambuf::imbue(loc); + + after = getloc(); + } +}; + +// libstdc++/13007 +void test02() +{ + bool test __attribute__((unused)) = true; + + Buf2 buf; + std::locale loc(std::locale("en_US")); + + buf.pubimbue(loc); + + VERIFY( buf.getloc() == loc ); + VERIFY( buf.before == std::locale::classic() ); + VERIFY( buf.after == std::locale::classic() ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc new file mode 100644 index 000000000..1d4d494c4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/imbue/wchar_t/9322.cc @@ -0,0 +1,65 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <locale> +#include <testsuite_hooks.h> + +class testbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + testbuf() : std::wstreambuf() { } +}; + +// libstdc++/9322 +void test08() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc; + testbuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/1.cc new file mode 100644 index 000000000..ed9e7f15f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/char/1.cc @@ -0,0 +1,53 @@ +// 2005-06-07 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2005, 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> + +typedef std::basic_streambuf<char> streambuf_type; + +struct testbuf : streambuf_type +{ + testbuf() { } +}; + +void test05() +{ + typedef streambuf_type::int_type int_type; + typedef streambuf_type::traits_type traits_type; + typedef streambuf_type::pos_type pos_type; + typedef streambuf_type::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::streamoff strmof_1; + testbuf sb01; + + // int in_avail() + strmof_1 = sb01.in_avail(); + VERIFY( strmof_1 == 0 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/1.cc new file mode 100644 index 000000000..ba978f676 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/in_avail/wchar_t/1.cc @@ -0,0 +1,53 @@ +// 2005-06-07 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2005, 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> + +typedef std::basic_streambuf<wchar_t> streambuf_type; + +struct testbuf : streambuf_type +{ + testbuf() { } +}; + +void test05() +{ + typedef streambuf_type::int_type int_type; + typedef streambuf_type::traits_type traits_type; + typedef streambuf_type::pos_type pos_type; + typedef streambuf_type::off_type off_type; + typedef size_t size_type; + + bool test __attribute__((unused)) = true; + std::streamoff strmof_1; + testbuf sb01; + + // int in_avail() + strmof_1 = sb01.in_avail(); + VERIFY( strmof_1 == 0 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/1.cc new file mode 100644 index 000000000..65aff09ec --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/1.cc @@ -0,0 +1,111 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +// 2007, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cstring> +#include <testsuite_hooks.h> + +class testbuf : public std::streambuf +{ +public: + + // Typedefs: + typedef std::streambuf::traits_type traits_type; + typedef std::streambuf::char_type char_type; + + testbuf(): std::streambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(char* beg, char* cur, char *end) + { this->setg(beg, cur, end); } + + void + pub_setp(char* beg, char* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + char lit01[52]; + std::strcpy(lit01, "chicago underground trio/possible cube on delmark"); + testbuf buf01; + + // pbackfail + int i01 = 3; + buf01.pub_setg(lit01, lit01, (lit01 + i01)); + VERIFY( i01 == buf01.in_avail() ); + int_type intt01 = traits_type::to_int_type('b'); + VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) ); + + // overflow + VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) ); + VERIFY( traits_type::eof() == buf01.pub_overflow() ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc new file mode 100644 index 000000000..2544d3398 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/2.cc @@ -0,0 +1,73 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <ostream> +#include <string> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_streambuf<charT, traits> + { + protected: + typedef typename + std::basic_streambuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<char> nullbuf; + +template<typename T> + char + print(const T& x) + { + nullbuf ob; + std::ostream out(&ob); + out << x << std::endl; + return (!out ? '0' : '1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::string control01("11111"); + std::string test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print('x'); + test01 += print("pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc new file mode 100644 index 000000000..16d117eed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/char/3599.cc @@ -0,0 +1,60 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/3599 +class testbuf : public std::streambuf +{ +public: + typedef std::streambuf::traits_type traits_type; + + testbuf() : std::streambuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::ostream out(&ob); + + out << "gasp"; + VERIFY( out.good() ); + + out << std::endl; + VERIFY( out.good() ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc new file mode 100644 index 000000000..30b67e4e6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/1.cc @@ -0,0 +1,110 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cwchar> +#include <testsuite_hooks.h> + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + wchar_t lit01[52]; + std::wcscpy(lit01, L"chicago underground trio/possible cube on delmark"); + testbuf buf01; + + // pbackfail + int i01 = 3; + buf01.pub_setg(lit01, lit01, (lit01 + i01)); + VERIFY( i01 == buf01.in_avail() ); + int_type intt01 = traits_type::to_int_type(L'b'); + VERIFY( traits_type::eof() == buf01.pub_pbackfail(intt01) ); + + // overflow + VERIFY( traits_type::eof() == buf01.pub_overflow(intt01) ); + VERIFY( traits_type::eof() == buf01.pub_overflow() ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[0]) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc new file mode 100644 index 000000000..be1cb29fe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/2.cc @@ -0,0 +1,73 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <ostream> +#include <string> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_streambuf<charT, traits> + { + protected: + typedef typename + std::basic_streambuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<wchar_t> nullbuf; + +template<typename T> + wchar_t + print(const T& x) + { + nullbuf ob; + std::wostream out(&ob); + out << x << std::endl; + return (!out ? L'0' : L'1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::wstring control01(L"11111"); + std::wstring test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print(L'x'); + test01 += print(L"pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc new file mode 100644 index 000000000..7ddca960d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/overflow/wchar_t/3599.cc @@ -0,0 +1,60 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/3599 +class testbuf : public std::wstreambuf +{ +public: + typedef std::wstreambuf::traits_type traits_type; + + testbuf() : std::wstreambuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::wostream out(&ob); + + out << L"gasp"; + VERIFY( out.good() ); + + out << std::endl; + VERIFY( out.good() ); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/requirements/base_classes.cc new file mode 100644 index 000000000..8c4fe079d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/requirements/base_classes.cc @@ -0,0 +1,36 @@ +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2004, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 - Template class basic_streambuf +// NB: This file is for testing basic_streambuf with NO OTHER INCLUDES. + +#include <streambuf> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// { dg-do compile } + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_streambuf<type_t, char_traits<type_t> >; + template class basic_streambuf<pod_char, char_traits<pod_char> >; +} // test diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/requirements/typedefs.cc new file mode 100644 index 000000000..fefed2913 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/requirements/typedefs.cc @@ -0,0 +1,39 @@ +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 - Template class basic_streambuf +// NB: This file is for testing basic_streambuf with NO OTHER INCLUDES. + +#include <streambuf> +#include <testsuite_hooks.h> + +// { dg-do compile } + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::streambuf test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/char/1.cc new file mode 100644 index 000000000..cbf17820f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/char/1.cc @@ -0,0 +1,113 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +// 2007, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cstring> +#include <testsuite_hooks.h> + +class testbuf : public std::streambuf +{ +public: + + // Typedefs: + typedef std::streambuf::traits_type traits_type; + typedef std::streambuf::char_type char_type; + + testbuf(): std::streambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(char* beg, char* cur, char *end) + { this->setg(beg, cur, end); } + + void + pub_setp(char* beg, char* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + char lit01[52]; + std::strcpy(lit01, "chicago underground trio/possible cube on delmark"); + testbuf buf01; + + // 27.5.2.3.1 get area + // 27.5.2.2.3 get area + // 27.5.2.4.3 get area + int i01 = 3; + buf01.pub_setg(lit01, lit01, (lit01 + i01)); + VERIFY( i01 == buf01.in_avail() ); + + VERIFY( buf01.pub_uflow() == traits_type::to_int_type(lit01[0]) ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) ); + VERIFY( buf01.pub_uflow() == traits_type::to_int_type(lit01[1]) ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) ); + VERIFY( buf01.pub_uflow() == traits_type::to_int_type(lit01[2]) ); + VERIFY( buf01.sgetc() == traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc new file mode 100644 index 000000000..0c5c63f33 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetc/wchar_t/1.cc @@ -0,0 +1,112 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cwchar> +#include <testsuite_hooks.h> + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + wchar_t lit01[52]; + std::wcscpy(lit01, L"chicago underground trio/possible cube on delmark"); + testbuf buf01; + + // 27.5.2.3.1 get area + // 27.5.2.2.3 get area + // 27.5.2.4.3 get area + int i01 = 3; + buf01.pub_setg(lit01, lit01, (lit01 + i01)); + VERIFY( i01 == buf01.in_avail() ); + + VERIFY( buf01.pub_uflow() == traits_type::to_int_type(lit01[0]) ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[1]) ); + VERIFY( buf01.pub_uflow() == traits_type::to_int_type(lit01[1]) ); + VERIFY( buf01.sgetc() == traits_type::to_int_type(lit01[2]) ); + VERIFY( buf01.pub_uflow() == traits_type::to_int_type(lit01[2]) ); + VERIFY( buf01.sgetc() == traits_type::eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/char/1.cc new file mode 100644 index 000000000..d1530b18f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/char/1.cc @@ -0,0 +1,123 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +// 2007, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cstring> +#include <testsuite_hooks.h> + +class testbuf : public std::streambuf +{ +public: + + // Typedefs: + typedef std::streambuf::traits_type traits_type; + typedef std::streambuf::char_type char_type; + + testbuf(): std::streambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(char* beg, char* cur, char *end) + { this->setg(beg, cur, end); } + + void + pub_setp(char* beg, char* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test02() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + + char lit01[] = "chicago underground trio/possible cube on delmark"; + size_t i01 = traits_type::length(lit01); + + testbuf buf01; + + // 27.5.2.1 basic_streambuf ctors + // default ctor initializes + // - all pointer members to null pointers + // - locale to current global locale + VERIFY( buf01.check_pointers() ); + VERIFY( buf01.getloc() == std::locale() ); + + // 27.5.2.2.5 Put area + + char carray01[i01]; + std::memset(carray01, 0, i01); + + buf01.pub_setg(lit01, lit01, lit01 + i01); + buf01.sgetn(carray01, 0); + VERIFY( carray01[0] == 0 ); + buf01.sgetn(carray01, 1); + VERIFY( carray01[0] == 'c' ); + buf01.sgetn(carray01 + 1, i01 - 1); + VERIFY( carray01[0] == 'c' ); + VERIFY( carray01[1] == 'h' ); + VERIFY( carray01[i01 - 1] == 'k' ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc new file mode 100644 index 000000000..66b4af5d3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sgetn/wchar_t/1.cc @@ -0,0 +1,122 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cwchar> +#include <testsuite_hooks.h> + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test02() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + + wchar_t lit01[] = L"chicago underground trio/possible cube on delmark"; + size_t i01 = traits_type::length(lit01); + + testbuf buf01; + + // 27.5.2.1 basic_streambuf ctors + // default ctor initializes + // - all pointer members to null pointers + // - locale to current global locale + VERIFY( buf01.check_pointers() ); + VERIFY( buf01.getloc() == std::locale() ); + + // 27.5.2.2.5 Put area + + wchar_t carray01[i01]; + std::wmemset(carray01, 0, i01); + + buf01.pub_setg(lit01, lit01, lit01 + i01); + buf01.sgetn(carray01, 0); + VERIFY( carray01[0] == 0 ); + buf01.sgetn(carray01, 1); + VERIFY( carray01[0] == L'c' ); + buf01.sgetn(carray01 + 1, i01 - 1); + VERIFY( carray01[0] == L'c' ); + VERIFY( carray01[1] == L'h' ); + VERIFY( carray01[i01 - 1] == L'k' ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/char/9538.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/char/9538.cc new file mode 100644 index 000000000..bd632aba1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/char/9538.cc @@ -0,0 +1,66 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <streambuf> +#include <locale> +#include <cstring> +#include <testsuite_hooks.h> + +class MyTraits : public std::char_traits<char> +{ +public: + static bool eq(char c1, char c2) + { + bool test __attribute__((unused)) = true; + VERIFY( c1 != 'X' ); + VERIFY( c2 != 'X' ); + return std::char_traits<char>::eq(c1, c2); + } +}; + +class MyBuf : public std::basic_streambuf<char, MyTraits> +{ + char buffer[8]; + +public: + MyBuf() + { + std::memset(buffer, 'X', sizeof(buffer)); + std::memset(buffer + 2, 'f', 4); + setg(buffer + 2, buffer + 2, buffer + 6); + } +}; + +// libstdc++/9538 +void test08() +{ + bool test __attribute__((unused)) = true; + + MyBuf mb; + mb.sputbackc('a'); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc new file mode 100644 index 000000000..f72f61778 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputbackc/wchar_t/9538.cc @@ -0,0 +1,65 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <streambuf> +#include <locale> +#include <cwchar> +#include <testsuite_hooks.h> + +class MyTraits : public std::char_traits<wchar_t> +{ +public: + static bool eq(wchar_t c1, wchar_t c2) + { + bool test __attribute__((unused)) = true; + VERIFY( c1 != L'X' ); + VERIFY( c2 != L'X' ); + return std::char_traits<wchar_t>::eq(c1, c2); + } +}; + +class MyBuf : public std::basic_streambuf<wchar_t, MyTraits> +{ + wchar_t buffer[8]; + +public: + MyBuf() + { + std::wmemset(buffer, L'X', sizeof(buffer) / sizeof(buffer[0])); + std::wmemset(buffer + 2, L'f', 4); + setg(buffer + 2, buffer + 2, buffer + 6); + } +}; + +// libstdc++/9538 +void test08() +{ + bool test __attribute__((unused)) = true; + + MyBuf mb; + mb.sputbackc(L'a'); +} + +int main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/char/1057.cc new file mode 100644 index 000000000..440d82b5a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf + +#include <string> +#include <streambuf> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::streambuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc('a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc new file mode 100644 index 000000000..5e7166fdd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputc/wchar_t/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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.5.2 template class basic_streambuf + +#include <string> +#include <streambuf> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::wstreambuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::wstring text1 = L"abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc(L'a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1.cc new file mode 100644 index 000000000..2874b0eea --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1.cc @@ -0,0 +1,117 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +// 2007, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cstring> +#include <testsuite_hooks.h> + +class testbuf : public std::streambuf +{ +public: + + // Typedefs: + typedef std::streambuf::traits_type traits_type; + typedef std::streambuf::char_type char_type; + + testbuf(): std::streambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(char* beg, char* cur, char *end) + { this->setg(beg, cur, end); } + + void + pub_setp(char* beg, char* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + testbuf buf01; + + // sputn/xsputn + char lit02[] = "isotope 217: the unstable molecule on thrill jockey"; + const int i02 = std::strlen(lit02); + + char carray[i02 + 1]; + std::memset(carray, 0, i02 + 1); + + buf01.pub_setp(carray, (carray + i02)); + buf01.sputn(lit02, 0); + VERIFY( carray[0] == 0 ); + VERIFY( lit02[0] == 'i' ); + buf01.sputn(lit02, 1); + VERIFY( lit02[0] == carray[0] ); + VERIFY( lit02[1] == 's' ); + VERIFY( carray[1] == 0 ); + buf01.sputn(lit02 + 1, 10); + VERIFY( std::memcmp(lit02, carray, 10) == 0 ); + buf01.sputn(lit02 + 11, 20); + VERIFY( std::memcmp(lit02, carray, 30) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc new file mode 100644 index 000000000..dda78bde4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <string> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::streambuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc new file mode 100644 index 000000000..09b263b6c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1.cc @@ -0,0 +1,118 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +// 2007, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <cwchar> +#include <cstring> +#include <testsuite_hooks.h> + +class testbuf : public std::wstreambuf +{ +public: + + // Typedefs: + typedef std::wstreambuf::traits_type traits_type; + typedef std::wstreambuf::char_type char_type; + + testbuf(): std::wstreambuf() + { } + + bool + check_pointers() + { + bool test __attribute__((unused)) = true; + VERIFY( !this->eback() ); + VERIFY( !this->gptr() ); + VERIFY( !this->egptr() ); + VERIFY( !this->pbase() ); + VERIFY( !this->pptr() ); + VERIFY( !this->epptr() ); + return test; + } + + int_type + pub_uflow() + { return (this->uflow()); } + + int_type + pub_overflow(int_type __c = traits_type::eof()) + { return (this->overflow(__c)); } + + int_type + pub_pbackfail(int_type __c) + { return (this->pbackfail(__c)); } + + void + pub_setg(wchar_t* beg, wchar_t* cur, wchar_t* end) + { this->setg(beg, cur, end); } + + void + pub_setp(wchar_t* beg, wchar_t* end) + { this->setp(beg, end); } + +protected: + int_type + underflow() + { + int_type __retval = traits_type::eof(); + if (this->gptr() < this->egptr()) + __retval = traits_type::not_eof(0); + return __retval; + } +}; + +void test01() +{ + typedef testbuf::traits_type traits_type; + typedef testbuf::int_type int_type; + + bool test __attribute__((unused)) = true; + testbuf buf01; + + // sputn/xsputn + wchar_t lit02[] = L"isotope 217: the unstable molecule on thrill jockey"; + const int i02 = std::wcslen(lit02); + + wchar_t carray[i02 + 1]; + std::wmemset(carray, 0, i02 + 1); + + buf01.pub_setp(carray, (carray + i02)); + buf01.sputn(lit02, 0); + VERIFY( carray[0] == 0 ); + VERIFY( lit02[0] == L'i' ); + buf01.sputn(lit02, 1); + VERIFY( lit02[0] == carray[0] ); + VERIFY( lit02[1] == L's' ); + VERIFY( carray[1] == 0 ); + buf01.sputn(lit02 + 1, 10); + VERIFY( std::memcmp(lit02, carray, 10) == 0 ); + buf01.sputn(lit02 + 11, 20); + VERIFY( std::memcmp(lit02, carray, 30) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc new file mode 100644 index 000000000..9b148bab9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sputn/wchar_t/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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.5.2 template class basic_streambuf + +#include <streambuf> +#include <string> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::wstreambuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::wstring text1 = L"abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc new file mode 100644 index 000000000..08fd18f02 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/char/1057.cc @@ -0,0 +1,101 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <string> +#include <testsuite_hooks.h> + +class setpbuf : public std::streambuf +{ + char buffer[4]; + std::string result; + +public: + + std::string& + get_result() + { return result; } + + setpbuf() + { + char foo [32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { sync(); } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::string text = "abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::string::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc new file mode 100644 index 000000000..7da657528 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_streambuf/sync/wchar_t/1057.cc @@ -0,0 +1,101 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <streambuf> +#include <string> +#include <testsuite_hooks.h> + +class setpbuf : public std::wstreambuf +{ + wchar_t buffer[4]; + std::wstring result; + +public: + + std::wstring& + get_result() + { return result; } + + setpbuf() + { + wchar_t foo[32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { sync(); } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring text = L"abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::wstring::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/2020.cc new file mode 100644 index 000000000..aa4c669cb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/2020.cc @@ -0,0 +1,52 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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 - Template class basic_stringbuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_stringbuf<__gnu_test::pod_ushort> gnu_ssbuf; + + try + { gnu_ssbuf obj; } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc new file mode 100644 index 000000000..d2bfe7a9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/char/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.1 basic_stringbuf constructors [lib.stringbuf.cons] + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_stringbuf sbuf; + VERIFY( sbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc new file mode 100644 index 000000000..ba512f98f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/cons/wchar_t/1.cc @@ -0,0 +1,39 @@ +// 2004-09-29 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.1 basic_stringbuf constructors [lib.stringbuf.cons] + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_io.h> + +// http://gcc.gnu.org/ml/libstdc++/2004-09/msg00243.html +void test01() +{ + bool test __attribute__((unused)) = true; + + __gnu_test::constraint_wstringbuf sbuf; + VERIFY( sbuf.check_pointers() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/1.cc new file mode 100644 index 000000000..6fe9c64aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/1.cc @@ -0,0 +1,47 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::stringbuf strb_01(str_01); + +// test the streambuf/stringbuf locale settings +void test02() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_c = std::locale::classic(); + loc_c = strb_01.getloc(); + strb_01.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = strb_01.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/9322.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/9322.cc new file mode 100644 index 000000000..bfc864351 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/char/9322.cc @@ -0,0 +1,55 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2005, 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 + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9322 +void test03() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc = std::locale::classic(); + std::stringbuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + using namespace std; + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc new file mode 100644 index 000000000..a3f4fac51 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/1.cc @@ -0,0 +1,47 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test the streambuf/stringbuf locale settings +void test02() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_c = std::locale::classic(); + loc_c = strb_01.getloc(); + strb_01.pubimbue(loc_c); //This should initialize _M_init to true + std::locale loc_tmp = strb_01.getloc(); + VERIFY( loc_tmp == loc_c ); +} + +int main() +{ + test02(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc new file mode 100644 index 000000000..7182fd912 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/imbue/wchar_t/9322.cc @@ -0,0 +1,56 @@ +// { dg-require-namedlocale "en_US" } +// { dg-require-namedlocale "de_DE" } + +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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 + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9322 +void test03() +{ + using std::locale; + bool test __attribute__((unused)) = true; + + locale loc = std::locale::classic(); + std::wstringbuf ob; + VERIFY( ob.getloc() == loc ); + + locale::global(locale("en_US")); + VERIFY( ob.getloc() == loc ); + + locale loc_de = locale("de_DE"); + locale ret = ob.pubimbue(loc_de); + VERIFY( ob.getloc() == loc_de ); + VERIFY( ret == loc ); + + locale::global(loc); + VERIFY( ob.getloc() == loc_de ); +} + +int main() +{ + using namespace std; + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/1.cc new file mode 100644 index 000000000..2925b8447 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/1.cc @@ -0,0 +1,57 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <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::streamoff strmof_1(-1), strmof_2; + + // GET + // int in_avail() + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + VERIFY( strmof_1 != strmof_2 ); + VERIFY( strmof_1 == static_cast<std::streamoff>(str_01.length()) ); + VERIFY( strmof_2 == static_cast<std::streamoff>(str_02.length()) ); + strmof_1 = strb_03.in_avail(); + // zero cuz write-only, or eof() to match basic_filebuf + VERIFY( strmof_1 == -1 ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/21955.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/21955.cc new file mode 100644 index 000000000..8fa7044ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/char/21955.cc @@ -0,0 +1,53 @@ +// 2005-06-07 Benjamin Kosnik + +// Copyright (C) 2005, 2006, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> +#include <stdexcept> + +double +test_stringstream() +{ + double result; + const char* source = "1918"; + std::stringstream s; + s << source; + + std::string tmp = s.str(); + std::streambuf* sb = s.rdbuf(); + int i = sb->in_avail(); + + if (i) + { + s >> result; + } + else + { + throw std::runtime_error("conversion failed"); + } + return result; +} + + +int main () +{ + test_stringstream(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc new file mode 100644 index 000000000..1700f3a82 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/in_avail/wchar_t/1.cc @@ -0,0 +1,57 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <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::streamoff strmof_1(-1), strmof_2; + + // GET + // int in_avail() + strmof_1 = strb_01.in_avail(); + strmof_2 = strb_02.in_avail(); + VERIFY( strmof_1 != strmof_2 ); + VERIFY( strmof_1 == static_cast<std::streamoff>(str_01.length()) ); + VERIFY( strmof_2 == static_cast<std::streamoff>(str_02.length()) ); + strmof_1 = strb_03.in_avail(); + // zero cuz write-only, or eof() to match basic_filebuf + VERIFY( strmof_1 == -1 ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc new file mode 100644 index 000000000..cdf84ef91 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc @@ -0,0 +1,62 @@ +// 2004-07-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 basic_stringbuf overridden virtual functions. + +#include <sstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +string +data(unsigned len) +{ + string ret; + for (unsigned i = 0; i < len; ++i) + ret.push_back('a' + rand() % 26); + return ret; +} + +void +test01(unsigned iter) +{ + bool test __attribute__((unused)) = true; + + for (unsigned n = 1; n <= iter; n *= 10) + { + const string str = data(n); + stringbuf sstr; + for (unsigned i = 0; i < n; ++i) + sstr.sputc(str[i]); + VERIFY( str == sstr.str() ); + } +} + +// This can take long on simulators, timing out the test. +// { dg-options "-DITERATIONS=10000" { target simulator } } +#ifndef ITERATIONS +#define ITERATIONS 10000000 +#endif + +int main() +{ + test01(ITERATIONS); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc new file mode 100644 index 000000000..3328e5520 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/2.cc @@ -0,0 +1,72 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_stringbuf<charT, traits> + { + protected: + typedef typename + std::basic_stringbuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<char> nullbuf; + +template<typename T> + char + print(const T& x) + { + nullbuf ob; + std::ostream out(&ob); + out << x << std::endl; + return (!out ? '0' : '1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::string control01("11111"); + std::string test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print('x'); + test01 += print("pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc new file mode 100644 index 000000000..a16fabc8c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/26250.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +struct pubbuf +: std::stringbuf +{ + using std::stringbuf::eback; + using std::stringbuf::egptr; + using std::stringbuf::pbase; + using std::stringbuf::pptr; + using std::stringbuf::epptr; + using std::stringbuf::overflow; +}; + +// libstdc++/26250 +void test01() +{ + bool test __attribute__((unused)) = true; + + pubbuf buf; + + VERIFY( buf.overflow('x') == 'x' ); + VERIFY( buf.pptr() - buf.pbase() == 1 ); + + // not required but good for efficiency + // NB: we are implementing DR 169 and DR 432 + const int write_positions = buf.epptr() - buf.pbase(); + VERIFY( write_positions > 1 ); + + // 27.7.1.3, p8: + VERIFY( buf.egptr() - buf.eback() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc new file mode 100644 index 000000000..b9d86a6ec --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/3599.cc @@ -0,0 +1,58 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/3599 +class testbuf : public std::stringbuf +{ +public: + typedef std::stringbuf::traits_type traits_type; + + testbuf() : std::stringbuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::ostream out(&ob); + + out << "gasp"; + VERIFY(out.good()); + + out << std::endl; + VERIFY(out.good()); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc new file mode 100644 index 000000000..cf1653073 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/9988.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +class OverBuf : public std::stringbuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::stringbuf::overflow(c); } +}; + +// libstdc++/9988 +// filebuf::overflow writes EOF to file +void test15() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + OverBuf sb; + + sb.sputc('a'); + sb.pub_overflow('b'); + sb.pub_overflow(); + sb.sputc('c'); + + stringbuf sbin(sb.str(), ios_base::in); + stringbuf::int_type c; + c = sbin.sbumpc(); + VERIFY( c == 'a' ); + c = sbin.sbumpc(); + VERIFY( c == 'b' ); + c = sbin.sbumpc(); + VERIFY( c == 'c' ); + c = sbin.sbumpc(); + VERIFY( c == stringbuf::traits_type::eof() ); +} + +int main() +{ + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc new file mode 100644 index 000000000..0d3ea89e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/1.cc @@ -0,0 +1,56 @@ +// 2004-07-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 basic_stringbuf overridden virtual functions. + +#include <sstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +wstring +data(unsigned len) +{ + wstring ret; + for (unsigned i = 0; i < len; ++i) + ret.push_back(L'a' + rand() % 26); + return ret; +} + +void +test01(unsigned iter) +{ + bool test __attribute__((unused)) = true; + + for (unsigned n = 1; n <= iter; n *= 10) + { + const wstring str = data(n); + wstringbuf sstr; + for (unsigned i = 0; i < n; ++i) + sstr.sputc(str[i]); + VERIFY( str == sstr.str() ); + } +} + +int main() +{ + test01(10000000); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc new file mode 100644 index 000000000..ff5c00744 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/2.cc @@ -0,0 +1,72 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// test03 +// http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00151.html +template<typename charT, typename traits = std::char_traits<charT> > + class basic_nullbuf : public std::basic_stringbuf<charT, traits> + { + protected: + typedef typename + std::basic_stringbuf<charT, traits>::int_type int_type; + virtual int_type + overflow(int_type c) + { return traits::not_eof(c); } + }; + +typedef basic_nullbuf<wchar_t> nullbuf; + +template<typename T> + wchar_t + print(const T& x) + { + nullbuf ob; + std::wostream out(&ob); + out << x << std::endl; + return (!out ? L'0' : L'1'); + } + +void test03() +{ + bool test __attribute__((unused)) = true; + const std::wstring control01(L"11111"); + std::wstring test01; + + test01 += print(true); + test01 += print(3.14159); + test01 += print(10); + test01 += print(L'x'); + test01 += print(L"pipo"); + + VERIFY( test01 == control01 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/26250.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/26250.cc new file mode 100644 index 000000000..152b54912 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/26250.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +struct pubbuf +: std::wstringbuf +{ + using std::wstringbuf::eback; + using std::wstringbuf::egptr; + using std::wstringbuf::pbase; + using std::wstringbuf::pptr; + using std::wstringbuf::epptr; + using std::wstringbuf::overflow; +}; + +// libstdc++/26250 +void test01() +{ + bool test __attribute__((unused)) = true; + + pubbuf buf; + + VERIFY( buf.overflow(L'x') == L'x' ); + VERIFY( buf.pptr() - buf.pbase() == 1 ); + + // not required but good for efficiency + // NB: we are implementing DR 169 and DR 432 + const int write_positions = buf.epptr() - buf.pbase(); + VERIFY( write_positions > 1 ); + + // 27.7.1.3, p8: + VERIFY( buf.egptr() - buf.eback() == 1 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc new file mode 100644 index 000000000..54c33f425 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/3599.cc @@ -0,0 +1,58 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <ostream> +#include <testsuite_hooks.h> + +// libstdc++/3599 +class testbuf : public std::wstringbuf +{ +public: + typedef std::wstringbuf::traits_type traits_type; + + testbuf() : std::wstringbuf() { } + +protected: + int_type + overflow(int_type c __attribute__((unused)) = traits_type::eof()) + { return traits_type::not_eof(0); } +}; + +void +test07() +{ + bool test __attribute__((unused)) = true; + testbuf ob; + std::wostream out(&ob); + + out << L"gasp"; + VERIFY(out.good()); + + out << std::endl; + VERIFY(out.good()); +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc new file mode 100644 index 000000000..e0d51b91b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/wchar_t/9988.cc @@ -0,0 +1,62 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +class OverBuf : public std::wstringbuf +{ +public: + int_type pub_overflow(int_type c = traits_type::eof()) + { return std::wstringbuf::overflow(c); } +}; + +// libstdc++/9988 +// filebuf::overflow writes EOF to file +void test15() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + OverBuf sb; + + sb.sputc(L'a'); + sb.pub_overflow(L'b'); + sb.pub_overflow(); + sb.sputc(L'c'); + + wstringbuf sbin(sb.str(), ios_base::in); + wstringbuf::int_type c; + c = sbin.sbumpc(); + VERIFY( c == L'a' ); + c = sbin.sbumpc(); + VERIFY( c == L'b' ); + c = sbin.sbumpc(); + VERIFY( c == L'c' ); + c = sbin.sbumpc(); + VERIFY( c == wstringbuf::traits_type::eof() ); +} + +int main() +{ + test15(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc new file mode 100644 index 000000000..a8be7b69a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/1.cc @@ -0,0 +1,75 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::stringbuf +{ +public: + my_stringbuf(const std::string& str, std::ios_base::openmode mode) + : std::stringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type c) + { return this->pbackfail(c); } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf("any", ios_base::in | ios_base::out); + + int_type c = sbuf.sgetc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('z'); + VERIFY( c == traits_type::eof() ); + c = sbuf.sbumpc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('a'); + VERIFY( c == 'a' ); + c = sbuf.sbumpc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('x'); + VERIFY( c == 'x' ); + c = sbuf.sbumpc(); + VERIFY( c == 'x' ); + + const int_type eof = traits_type::eof(); + c = sbuf.pub_pbackfail(eof); + VERIFY( c == traits_type::not_eof(eof) ); + c = sbuf.sgetc(); + VERIFY( c == 'x' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc new file mode 100644 index 000000000..abe8bb0e7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/char/2.cc @@ -0,0 +1,63 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::stringbuf +{ +public: + my_stringbuf(const std::string& str, std::ios_base::openmode mode) + : std::stringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type __c) + { return this->pbackfail(__c); } +}; + +// We weren't enforcing 27.7.1.3/2, bullet 2: "... and if +// mode & ios_base::out is nonzero, ..." +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf("any", ios_base::in); + + int_type c = sbuf.sbumpc(); + VERIFY( c == 'a' ); + + c = sbuf.pub_pbackfail('x'); + VERIFY( c == traits_type::eof() ); + VERIFY( sbuf.str() == "any" ); + c = sbuf.sgetc(); + VERIFY( c == 'n' ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc new file mode 100644 index 000000000..9854db5c6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/1.cc @@ -0,0 +1,75 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::wstringbuf +{ +public: + my_stringbuf(const std::wstring& str, std::ios_base::openmode mode) + : std::wstringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type c) + { return this->pbackfail(c); } +}; + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf(L"any", ios_base::in | ios_base::out); + + int_type c = sbuf.sgetc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'z'); + VERIFY( c == traits_type::eof() ); + c = sbuf.sbumpc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'a'); + VERIFY( c == L'a' ); + c = sbuf.sbumpc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'x'); + VERIFY( c == L'x' ); + c = sbuf.sbumpc(); + VERIFY( c == L'x' ); + + const int_type eof = traits_type::eof(); + c = sbuf.pub_pbackfail(eof); + VERIFY( c == traits_type::not_eof(eof) ); + c = sbuf.sgetc(); + VERIFY( c == L'x' ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc new file mode 100644 index 000000000..7063b7d27 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/pbackfail/wchar_t/2.cc @@ -0,0 +1,63 @@ +// 2004-10-01 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions [lib.stringbuf.virtuals] + +#include <sstream> +#include <testsuite_hooks.h> + +class my_stringbuf : public std::wstringbuf +{ +public: + my_stringbuf(const std::wstring& str, std::ios_base::openmode mode) + : std::wstringbuf(str, mode) { } + + int_type + pub_pbackfail(int_type __c) + { return this->pbackfail(__c); } +}; + +// We weren't enforcing 27.7.1.3/2, bullet 2: "... and if +// mode & ios_base::out is nonzero, ..." +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + typedef my_stringbuf::int_type int_type; + typedef my_stringbuf::traits_type traits_type; + + my_stringbuf sbuf(L"any", ios_base::in); + + int_type c = sbuf.sbumpc(); + VERIFY( c == L'a' ); + + c = sbuf.pub_pbackfail(L'x'); + VERIFY( c == traits_type::eof() ); + VERIFY( sbuf.str() == L"any" ); + c = sbuf.sgetc(); + VERIFY( c == L'n' ); +} + + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/base_classes.cc new file mode 100644 index 000000000..0d33d4e82 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/base_classes.cc @@ -0,0 +1,43 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.7.1 - Template class basic_stringbuf + +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::stringbuf test_type; + typedef std::streambuf base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/2.cc new file mode 100644 index 000000000..681757b95 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/2.cc @@ -0,0 +1,49 @@ +// { dg-do compile } +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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 - Template class basic_stringbuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// test05 +// libstdc++/1886 +// should be able to instantiate basic_stringbuf for non-standard types. +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_stringbuf<type_t, char_traits<type_t> >; + template class basic_stringbuf<pod_char, char_traits<pod_char> >; +} // std + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/4.cc new file mode 100644 index 000000000..8477035e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/explicit_instantiation/4.cc @@ -0,0 +1,45 @@ +// { dg-do compile } +// 2003-04-07 bkoz + +// Copyright (C) 2003, 2004, 2005, 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 - Template class basic_stringbuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_allocator.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef __gnu_test::tracker_allocator<char> alloc_type; + template class basic_stringbuf<char, char_traits<char>, alloc_type>; +} // test + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/typedefs.cc new file mode 100644 index 000000000..0039f96a5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/requirements/typedefs.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 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 - Template class basic_stringbuf +// NB: This file is for testing basic_stringbuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::stringbuf test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/1.cc new file mode 100644 index 000000000..f60911bdc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/1.cc @@ -0,0 +1,68 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 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/>. + +#include <sstream> +#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; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + // int_type sbumpc() + // if read_cur not avail, return uflow(), else return *read_cur & increment + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + VERIFY( c1 != c2 ); + VERIFY( c1 == traits_type::to_int_type(str_01[0]) ); + VERIFY( c2 == traits_type::to_int_type(str_02[0]) ); //should equal first letter at this point + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + VERIFY( c1 != c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 != c4 ); + int_type c5 = strb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/9825.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/9825.cc new file mode 100644 index 000000000..bd4c41129 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/char/9825.cc @@ -0,0 +1,49 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9825 +// filebuf::sputbackc breaks sbumpc +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf sbuf; + sbuf.sputn("crazy bees!", 11); + sbuf.pubseekoff(0, ios_base::beg); + sbuf.sbumpc(); + sbuf.sputbackc('x'); + stringbuf::int_type c = sbuf.sbumpc(); + VERIFY( c == 'x' ); + c = sbuf.sbumpc(); + VERIFY( c == 'r' ); + c = sbuf.sbumpc(); + VERIFY( c == 'a' ); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc new file mode 100644 index 000000000..3ec279a19 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/1.cc @@ -0,0 +1,67 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + // int_type sbumpc() + // if read_cur not avail, return uflow(), else return *read_cur & increment + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + VERIFY( c1 != c2 ); + VERIFY( c1 == traits_type::to_int_type(str_01[0]) ); + VERIFY( c2 == traits_type::to_int_type(str_02[0]) ); //should equal first letter at this point + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + VERIFY( c1 != c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 != c4 ); + int_type c5 = strb_03.sbumpc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc new file mode 100644 index 000000000..93ca56f09 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sbumpc/wchar_t/9825.cc @@ -0,0 +1,49 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9825 +// filebuf::sputbackc breaks sbumpc +void test12() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf sbuf; + sbuf.sputn(L"crazy bees!", 11); + sbuf.pubseekoff(0, ios_base::beg); + sbuf.sbumpc(); + sbuf.sputbackc(L'x'); + stringbuf::int_type c = sbuf.sbumpc(); + VERIFY( c == L'x' ); + c = sbuf.sbumpc(); + VERIFY( c == L'r' ); + c = sbuf.sbumpc(); + VERIFY( c == L'a' ); +} + +int main() +{ + test12(); + return 0; +} 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 new file mode 100644 index 000000000..142cde9c7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/1.cc @@ -0,0 +1,110 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::stringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + std::streamsize strmsz_1, strmsz_2; + 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; + + // BUFFER MANAGEMENT & POSITIONING + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + strb_01.str(str_01); //in|out ("mykonos. . . or what?"); + + //IN|OUT + //beg + pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 >= 0 ); + c1 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == 'o' ); + c2 = strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + //cur + pt_1 = strb_01.pubseekoff(2, std::ios_base::cur); + off_1 = off_type(pt_1); + VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams + pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); + off_1 = off_type(pt_1); + pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); + off_2 = off_type(pt_2); + VERIFY( off_2 == off_1 + 2 ); + c1 = strb_01.snextc(); //current in pointer + 1 + VERIFY( c1 == ' ' ); + c2 = strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("myxxnos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + //end + pt_2 = strb_01.pubseekoff(2, std::ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 == -1 ); // not a valid position + VERIFY( strb_01.str() == str_tmp ); + // end part two (from the filebuf tests) + strb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = strb_01.in_avail(); // 0 cuz at the end + c1 = strb_01.sgetc(); + c2 = strb_01.sungetc(); + strmsz_2 = strb_01.in_avail(); // 1 + strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + // end part three + strmsz_1 = strb_01.str().size(); + strmsz_2 = strb_01.sputn(" ravi shankar meets carlos santana in LoHa", 90); + strb_01.pubseekoff(0, std::ios_base::end); + strb_01.sputc('<'); + str_tmp = strb_01.str(); + VERIFY(static_cast<std::streamsize>(str_tmp.size()) == strmsz_1 + strmsz_2 + 1); + // IN + // OUT +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc new file mode 100644 index 000000000..9638f788c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/10975.cc @@ -0,0 +1,56 @@ +// 2004-09-30 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10975 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef streambuf::pos_type pos_type; + typedef streambuf::off_type off_type; + + const pos_type good = pos_type(off_type(0)); + const pos_type bad = pos_type(off_type(-1)); + pos_type p; + + stringbuf sbuf; + + p = sbuf.pubseekoff(0, ios_base::cur, ios_base::in); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::end); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::cur); + VERIFY( p == bad ); +} + +int main() +{ + test01(); + return 0; +} 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 000000000..724a12d2d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/16956.cc @@ -0,0 +1,60 @@ +// 2004-08-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 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/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/2.cc new file mode 100644 index 000000000..a1d05d72a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/char/2.cc @@ -0,0 +1,58 @@ +// 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 + +#include <sstream> +#include <testsuite_hooks.h> + +void test02(std::stringbuf& 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); + VERIFY( p == bad ); + + p = in.pubseekoff(0, ios_base::beg); + VERIFY( p == bad ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + stringbuf in1("Hedy Lamarr", ios_base::in); + stringbuf in2(ios_base::in); + stringbuf in3("", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + 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 new file mode 100644 index 000000000..1b0ee5fe5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/1.cc @@ -0,0 +1,110 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + std::streamsize strmsz_1, strmsz_2; + 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; + + // BUFFER MANAGEMENT & POSITIONING + + // seekoff + // pubseekoff(off_type off, ios_base::seekdir way, ios_base::openmode which) + // alters the stream position to off + pos_type pt_1(off_type(-1)); + pos_type pt_2(off_type(0)); + off_type off_1 = 0; + off_type off_2 = 0; + strb_01.str(str_01); //in|out ("mykonos. . . or what?"); + + //IN|OUT + //beg + pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 >= 0 ); + c1 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == L'o' ); + c2 = strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + //cur + pt_1 = strb_01.pubseekoff(2, std::ios_base::cur); + off_1 = off_type(pt_1); + VERIFY( off_1 == -1 ); // can't seekoff for in and out + cur in sstreams + pt_1 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); + off_1 = off_type(pt_1); + pt_2 = strb_01.pubseekoff(2, std::ios_base::cur, std::ios_base::in); + off_2 = off_type(pt_2); + VERIFY( off_2 == off_1 + 2 ); + c1 = strb_01.snextc(); //current in pointer + 1 + VERIFY( c1 == L' ' ); + c2 = strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxxnos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + //end + pt_2 = strb_01.pubseekoff(2, std::ios_base::end); + off_1 = off_type(pt_2); + VERIFY( off_1 == -1 ); // not a valid position + VERIFY( strb_01.str() == str_tmp ); + // end part two (from the filebuf tests) + strb_01.pubseekoff(0, std::ios_base::end); + strmsz_1 = strb_01.in_avail(); // 0 cuz at the end + c1 = strb_01.sgetc(); + c2 = strb_01.sungetc(); + strmsz_2 = strb_01.in_avail(); // 1 + strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( strmsz_2 != strmsz_1 ); + VERIFY( strmsz_2 == 1 ); + // end part three + strmsz_1 = strb_01.str().size(); + strmsz_2 = strb_01.sputn(L" ravi shankar meets carlos santana in LoHa", 90); + strb_01.pubseekoff(0, std::ios_base::end); + strb_01.sputc(L'<'); + str_tmp = strb_01.str(); + VERIFY(static_cast<std::streamsize>(str_tmp.size()) == strmsz_1 + strmsz_2 + 1); + // IN + // OUT +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc new file mode 100644 index 000000000..b83f07e13 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/10975.cc @@ -0,0 +1,56 @@ +// 2004-09-30 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/10975 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstreambuf::pos_type pos_type; + typedef wstreambuf::off_type off_type; + + const pos_type good = pos_type(off_type(0)); + const pos_type bad = pos_type(off_type(-1)); + pos_type p; + + wstringbuf sbuf; + + p = sbuf.pubseekoff(0, ios_base::cur, ios_base::in); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::beg, ios_base::out); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::end); + VERIFY( p == good ); + + p = sbuf.pubseekoff(0, ios_base::cur); + VERIFY( p == bad ); +} + +int main() +{ + test01(); + return 0; +} 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 000000000..4e79b97cd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/16956.cc @@ -0,0 +1,60 @@ +// 2004-08-12 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 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/seekoff/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc new file mode 100644 index 000000000..7aefcac93 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekoff/wchar_t/2.cc @@ -0,0 +1,58 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test02(std::wstringbuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstreambuf::pos_type pos_type; + typedef wstreambuf::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); + VERIFY( p == bad ); + + p = in.pubseekoff(0, ios_base::beg); + VERIFY( p == bad ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + wstringbuf in1(L"Hedy Lamarr", ios_base::in); + wstringbuf in2(ios_base::in); + wstringbuf in3(L"", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + 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 new file mode 100644 index 000000000..53f98bf98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/1.cc @@ -0,0 +1,82 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 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/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::stringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::string str_tmp; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::pos_type pos_type; + typedef std::stringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + 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; + + // 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?"); + + //IN|OUT + //beg + pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 >= 0 ); + pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out); + off_1 = off_type(pt_1); + c1 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == 'o' ); + strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + strb_01.pubsync(); //resets pointers + pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == c3 ); + strb_01.sputc('x'); //test current out pointer + str_tmp = std::string("myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/2.cc new file mode 100644 index 000000000..484fac826 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/2.cc @@ -0,0 +1,59 @@ +// 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 + +#include <sstream> +#include <testsuite_hooks.h> + +void test02(std::stringbuf& 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; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekpos(0, ios_base::out); + VERIFY( p == bad ); + + p = in.pubseekpos(0); + if (pass) + VERIFY( p != bad ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + stringbuf in1("Hedy Lamarr", ios_base::in); + stringbuf in2(ios_base::in); + stringbuf in3("", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/29354.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/29354.cc new file mode 100644 index 000000000..e23f8664d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/29354.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/29354 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + stringbuf strb_01(ios_base::out); + + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::cur, ios_base::out); + VERIFY( pt_1 == pos_type(off_type(0)) ); + + pos_type pt_2 = strb_01.pubseekpos(pt_1, ios_base::out); + VERIFY( pt_2 == pos_type(off_type(0)) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/3.cc new file mode 100644 index 000000000..8c3ff42db --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/char/3.cc @@ -0,0 +1,47 @@ +// 2003-05-30 Paolo Carlini <pcarlini@unitus.it> + +// 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/>. + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + stringbuf strb_01(ios_base::out); + + strb_01.sputn("broken peak", 11); + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::end, ios_base::out); + + // In general, according to 27.7.1.3,14, the below has undefined + // behaviour since pt_1 + off_type(1) doesn't come from a + // previous pubseekpos or pubseekoff. However, given v3 implementation, + // this was useful to expose a bug in pubseekpos checks. + pos_type pt_2 = strb_01.pubseekpos(pt_1 + off_type(1), ios_base::out); + VERIFY( pt_2 == pos_type(off_type(-1)) ); +} + +int main() +{ + test01(); + return 0; +} 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 new file mode 100644 index 000000000..bc01ea640 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/1.cc @@ -0,0 +1,82 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstringbuf strb_01(str_01); + +// test overloaded virtual functions +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring str_tmp; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::pos_type pos_type; + typedef std::wstringbuf::off_type off_type; + + int_type c1 = strb_01.sbumpc(); + 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; + + // 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?"); + + //IN|OUT + //beg + pt_1 = strb_01.pubseekoff(2, std::ios_base::beg); + off_1 = off_type(pt_1); + VERIFY( off_1 >= 0 ); + pt_1 = strb_01.pubseekoff(0, std::ios_base::cur, std::ios_base::out); + off_1 = off_type(pt_1); + c1 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == L'o' ); + strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); + strb_01.pubsync(); //resets pointers + pt_2 = strb_01.pubseekpos(pt_1, std::ios_base::in|std::ios_base::out); + off_2 = off_type(pt_2); + VERIFY( off_1 == off_2 ); + c3 = strb_01.snextc(); //current in pointer +1 + VERIFY( c1 == c3 ); + strb_01.sputc(L'x'); //test current out pointer + str_tmp = std::wstring(L"myxonos. . . or what?"); + VERIFY( strb_01.str() == str_tmp ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc new file mode 100644 index 000000000..b95b19331 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/2.cc @@ -0,0 +1,59 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test02(std::wstringbuf& in, bool pass) +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstreambuf::pos_type pos_type; + typedef wstreambuf::off_type off_type; + pos_type bad = pos_type(off_type(-1)); + pos_type p = 0; + + // seekpos + p = in.pubseekpos(0, ios_base::in); + if (pass) + VERIFY( p != bad ); + + p = in.pubseekpos(0, ios_base::out); + VERIFY( p == bad ); + + p = in.pubseekpos(0); + if (pass) + VERIFY( p != bad ); +} + +int main() +{ + using namespace std; + + // movie star, submarine scientist! + wstringbuf in1(L"Hedy Lamarr", ios_base::in); + wstringbuf in2(ios_base::in); + wstringbuf in3(L"", ios_base::in); + test02(in1, true); + test02(in2, false); + test02(in3, false); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/29354.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/29354.cc new file mode 100644 index 000000000..d89d02dae --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/29354.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/29354 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef stringbuf::pos_type pos_type; + typedef stringbuf::off_type off_type; + + wstringbuf strb_01(ios_base::out); + + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::cur, ios_base::out); + VERIFY( pt_1 == pos_type(off_type(0)) ); + + pos_type pt_2 = strb_01.pubseekpos(pt_1, ios_base::out); + VERIFY( pt_2 == pos_type(off_type(0)) ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc new file mode 100644 index 000000000..bb0963244 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/seekpos/wchar_t/3.cc @@ -0,0 +1,47 @@ +// 2003-05-30 Paolo Carlini <pcarlini@unitus.it> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + typedef wstringbuf::pos_type pos_type; + typedef wstringbuf::off_type off_type; + + wstringbuf strb_01(ios_base::out); + + strb_01.sputn(L"broken peak", 11); + pos_type pt_1 = strb_01.pubseekoff(0, ios_base::end, ios_base::out); + + // In general, according to 27.7.1.3,14, the below has undefined + // behaviour since pt_1 + off_type(1) doesn't come from a + // previous pubseekpos or pubseekoff. However, given v3 implementation, + // this was useful to expose a bug in pubseekpos checks. + pos_type pt_2 = strb_01.pubseekpos(pt_1 + off_type(1), ios_base::out); + VERIFY( pt_2 == pos_type(off_type(-1)) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/1.cc new file mode 100644 index 000000000..728256154 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/1.cc @@ -0,0 +1,56 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::string str_01("mykonos. . . or what?"); +std::string str_03; +std::stringbuf strb_01(str_01); +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; + + // PUT + strb_03.str(str_01); //reset + + // BUFFER MANAGEMENT & POSITIONING + // setbuf + // pubsetbuf(char_type* s, streamsize n) + str_tmp = std::string("naaaah, go to cebu"); + strb_01.pubsetbuf(const_cast<char*> (str_tmp.c_str()), str_tmp.size()); + VERIFY( strb_01.str() == str_tmp ); + strb_01.pubsetbuf(0,0); + VERIFY( strb_01.str() == str_tmp ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/2.cc new file mode 100644 index 000000000..e870d592c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/2.cc @@ -0,0 +1,46 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + stringbuf sbuf; + + sbuf.pubsetbuf(buf, 512); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/3.cc new file mode 100644 index 000000000..8e5912910 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/3.cc @@ -0,0 +1,46 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test02() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + char buf[512]; + const char* strlit = "how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::strlen(strlit); + string s("tmp"); + stringbuf sbuf(s, ios_base::out); + sbuf.pubsetbuf(buf, strlitsize); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::strncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/4.cc new file mode 100644 index 000000000..f069db50f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/char/4.cc @@ -0,0 +1,58 @@ +// 2004-10-06 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2005, 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/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const unsigned max_size = 1 << 18; + + char ref[max_size]; + memset(ref, '\0', max_size); + + char src[max_size * 2]; + memset(src, '\1', max_size * 2); + + for (unsigned i = 128; i <= max_size; i *= 2) + { + char* dest = new char[i * 2]; + memset(dest, '\0', i * 2); + + stringbuf sbuf; + sbuf.pubsetbuf(dest, i); + + sbuf.sputn(src, i * 2); + VERIFY( !memcmp(dest + i, ref, i) ); + + delete[] dest; + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc new file mode 100644 index 000000000..62da6db10 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/1.cc @@ -0,0 +1,56 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +std::wstring str_01(L"mykonos. . . or what?"); +std::wstring str_03; +std::wstringbuf strb_01(str_01); +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; + + // PUT + strb_03.str(str_01); //reset + + // BUFFER MANAGEMENT & POSITIONING + // setbuf + // pubsetbuf(char_type* s, streamsize n) + str_tmp = std::wstring(L"naaaah, go to cebu"); + strb_01.pubsetbuf(const_cast<wchar_t*> (str_tmp.c_str()), str_tmp.size()); + VERIFY( strb_01.str() == str_tmp ); + strb_01.pubsetbuf(0,0); + VERIFY( strb_01.str() == str_tmp ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc new file mode 100644 index 000000000..06b8bef4c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/2.cc @@ -0,0 +1,44 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + wchar_t buf[512]; + const wchar_t* strlit = L"how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::wcslen(strlit); + wstringbuf sbuf; + + sbuf.pubsetbuf(buf, 512); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::wcsncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc new file mode 100644 index 000000000..ebaea1f9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/3.cc @@ -0,0 +1,44 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test02() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + wchar_t buf[512]; + const wchar_t* strlit = L"how to tell a story and other essays: mark twain"; + const size_t strlitsize = std::wcslen(strlit); + wstring s(L"tmp"); + wstringbuf sbuf(s, ios_base::out); + sbuf.pubsetbuf(buf, strlitsize); + sbuf.sputn(strlit, strlitsize); + VERIFY( std::wcsncmp(strlit, buf, strlitsize) == 0 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/4.cc new file mode 100644 index 000000000..c6c966db7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/setbuf/wchar_t/4.cc @@ -0,0 +1,57 @@ +// 2004-10-06 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + const unsigned max_size = 1 << 18; + + static wchar_t ref[max_size]; + wmemset(ref, L'\0', max_size); + + static wchar_t src[max_size * 2]; + wmemset(src, L'\1', max_size * 2); + + for (unsigned i = 128; i <= max_size; i *= 2) + { + wchar_t* dest = new wchar_t[i * 2]; + wmemset(dest, L'\0', i * 2); + + wstringbuf sbuf; + sbuf.pubsetbuf(dest, i); + + sbuf.sputn(src, i * 2); + VERIFY( !wmemcmp(dest + i, ref, i) ); + + delete[] dest; + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/char/1.cc new file mode 100644 index 000000000..f26ec85c5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/char/1.cc @@ -0,0 +1,69 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + VERIFY( c6 != c3 ); + VERIFY( c7 != c4 ); + int_type c8 = strb_01.sgetc(); + int_type c9 = strb_02.sgetc(); + VERIFY( c6 == c8 ); + VERIFY( c7 == c9 ); + c5 = strb_03.sgetc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc new file mode 100644 index 000000000..98ca73d75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetc/wchar_t/1.cc @@ -0,0 +1,69 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + VERIFY( c6 != c3 ); + VERIFY( c7 != c4 ); + int_type c8 = strb_01.sgetc(); + int_type c9 = strb_02.sgetc(); + VERIFY( c6 == c8 ); + VERIFY( c7 == c9 ); + c5 = strb_03.sgetc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/char/1.cc new file mode 100644 index 000000000..2f077a508 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/char/1.cc @@ -0,0 +1,104 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// 2006, 2007, 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/>. + +#include <sstream> +#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::streamsize strmsz_1, strmsz_2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + strb_01.sgetc(); + strb_02.sgetc(); + strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + strb_03.snextc(); + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + strmsz_1 = strb_01.in_avail(); + strmsz_2 = strb_02.in_avail(); + test = strmsz_1 != strmsz_2; + VERIFY( strmsz_1 != static_cast<std::streamsize>(str_01.length()) ); + // because now we've moved into string + VERIFY( strmsz_2 != static_cast<std::streamsize>(str_02.length()) ); + char carray1[11] = ""; + strmsz_1 = strb_01.sgetn(carray1, 10); + char carray2[20] = ""; + strmsz_2 = strb_02.sgetn(carray2, 10); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( strmsz_1 == 10 ); + c1 = strb_01.sgetc(); + c2 = strb_02.sgetc(); + VERIFY( c6 == c1 ); //just by co-incidence both o's + VERIFY( c7 != c2 ); // n != i + VERIFY( c1 == traits_type::to_int_type(str_01[13]) ); + VERIFY( c2 == traits_type::to_int_type(str_02[13]) ); //should equal fourteenth letter at this point + strmsz_1 = strb_03.sgetn(carray1, 10); + VERIFY( !strmsz_1 ); //zero + strmsz_1 = strb_02.in_avail(); + strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //write off the end + c4 = strb_02.sgetc(); // should be EOF + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc new file mode 100644 index 000000000..5c917e109 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sgetn/wchar_t/1.cc @@ -0,0 +1,104 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 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/>. + +#include <sstream> +#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::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + strb_01.sgetc(); + strb_02.sgetc(); + strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + strb_03.snextc(); + + // streamsize sgetn(char_type *s, streamsize n) + // streamsize xsgetn(char_type *s, streamsize n) + // assign up to n chars to s from input sequence, indexing in_cur as + // approp and returning the number of chars assigned + strmsz_1 = strb_01.in_avail(); + strmsz_2 = strb_02.in_avail(); + test = strmsz_1 != strmsz_2; + VERIFY( strmsz_1 != static_cast<std::streamsize>(str_01.length()) ); + // because now we've moved into string + VERIFY( strmsz_2 != static_cast<std::streamsize>(str_02.length()) ); + wchar_t carray1[11] = L""; + strmsz_1 = strb_01.sgetn(carray1, 10); + wchar_t carray2[20] = L""; + strmsz_2 = strb_02.sgetn(carray2, 10); + VERIFY( strmsz_1 == strmsz_2 ); + VERIFY( strmsz_1 == 10 ); + c1 = strb_01.sgetc(); + c2 = strb_02.sgetc(); + VERIFY( c6 == c1 ); //just by co-incidence both o's + VERIFY( c7 != c2 ); // n != i + VERIFY( c1 == traits_type::to_int_type(str_01[13]) ); + VERIFY( c2 == traits_type::to_int_type(str_02[13]) ); //should equal fourteenth letter at this point + strmsz_1 = strb_03.sgetn(carray1, 10); + VERIFY( !strmsz_1 ); //zero + strmsz_1 = strb_02.in_avail(); + strmsz_2 = strb_02.sgetn(carray2, strmsz_1 + 5); + VERIFY( strmsz_1 == strmsz_2 ); //write off the end + c4 = strb_02.sgetc(); // should be EOF + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/char/1.cc new file mode 100644 index 000000000..afe1dfa57 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/char/1.cc @@ -0,0 +1,78 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, +// 2006, 2007, 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/>. + +#include <sstream> +#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; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + strb_01.sbumpc(); + strb_02.sbumpc(); + strb_01.sbumpc(); + strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + int_type c8 = strb_01.sgetc(); + int_type c9 = strb_02.sgetc(); + c5 = strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + VERIFY( c6 != c8 ); + VERIFY( c7 != c9 ); + VERIFY( c6 == traits_type::to_int_type(str_01[3]) ); + VERIFY( c7 == traits_type::to_int_type(str_02[3]) ); //should equal fourth letter at this point + c5 = strb_03.snextc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc new file mode 100644 index 000000000..0154594b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/snextc/wchar_t/1.cc @@ -0,0 +1,78 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 +// 2006, 2007, 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/>. + +#include <sstream> +#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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // GET + strb_01.in_avail(); + strb_02.in_avail(); + strb_03.in_avail(); + + strb_01.sbumpc(); + strb_02.sbumpc(); + strb_01.sbumpc(); + strb_02.sbumpc(); + int_type c5 = strb_03.sbumpc(); + + // int_type sgetc() + // if read_cur not avail, return uflow(), else return *read_cur + int_type c6 = strb_01.sgetc(); + int_type c7 = strb_02.sgetc(); + int_type c8 = strb_01.sgetc(); + int_type c9 = strb_02.sgetc(); + c5 = strb_03.sgetc(); + + // int_type snextc() + // calls sbumpc and if sbumpc != eof, return sgetc + c6 = strb_01.snextc(); + c7 = strb_02.snextc(); + VERIFY( c6 != c8 ); + VERIFY( c7 != c9 ); + VERIFY( c6 == traits_type::to_int_type(str_01[3]) ); + VERIFY( c7 == traits_type::to_int_type(str_02[3]) ); //should equal fourth letter at this point + c5 = strb_03.snextc(); + VERIFY( c5 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc new file mode 100644 index 000000000..67358a3b9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/1.cc @@ -0,0 +1,115 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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, str_tmp2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + strb_03.str().length(); + strb_03.str().length(); + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + str_tmp = strb_03.str(); + str_tmp.length(); + strb_03.sputn("racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + strb_02.sputn("racadabra", 10); + + // PUTBACK + + // 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() + strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?" + c3 = strb_01.sgetc(); + str_tmp2 = strb_01.str(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( str_tmp2 == std::string("mzkonos. . . or what?") ); + VERIFY( str_tmp.size() == str_tmp2.size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc('z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 != c2 ); + VERIFY( c1 == c3 ); + VERIFY( c2 == traits_type::eof() ); + VERIFY( strb_01.str() == str_tmp ); + VERIFY( str_tmp.size() == strb_01.str().size() ); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc('y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sputbackc('x'); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/9425.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/9425.cc new file mode 100644 index 000000000..5e56378e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/char/9425.cc @@ -0,0 +1,42 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9439, libstdc++/9425 +// basic_filebuf<>::pbackfail calls basic_filebuf<>::seekoff, but +// fails to check the return value +void test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + stringbuf sbuf; + stringbuf::int_type r = sbuf.sputbackc('a'); + VERIFY( r == stringbuf::traits_type::eof() ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc new file mode 100644 index 000000000..e0c91a3b2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/1.cc @@ -0,0 +1,115 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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, str_tmp2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + strb_03.str().length(); + strb_03.str().length(); + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + str_tmp = strb_03.str(); + str_tmp.length(); + strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(L", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + strb_02.sputn(L"racadabra", 10); + + // PUTBACK + + // 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() + strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sputbackc(L'z');//"mykonos. . .zor what?" + c3 = strb_01.sgetc(); + str_tmp2 = strb_01.str(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( str_tmp2 == std::wstring(L"mzkonos. . . or what?") ); + VERIFY( str_tmp.size() == str_tmp2.size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 != c2 ); + VERIFY( c1 == c3 ); + VERIFY( c2 == traits_type::eof() ); + VERIFY( strb_01.str() == str_tmp ); + VERIFY( str_tmp.size() == strb_01.str().size() ); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sputbackc(L'x'); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc new file mode 100644 index 000000000..87b4c64b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputbackc/wchar_t/9425.cc @@ -0,0 +1,42 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.8.1.4 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/9439, libstdc++/9425 +// basic_filebuf<>::pbackfail calls basic_filebuf<>::seekoff, but +// fails to check the return value +void test09() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstringbuf sbuf; + wstringbuf::int_type r = sbuf.sputbackc(L'a'); + VERIFY( r == wstringbuf::traits_type::eof() ); +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1.cc new file mode 100644 index 000000000..b7b76da0d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1.cc @@ -0,0 +1,66 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#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; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + + // PUT + // int_type sputc(char_type c) + // if out_cur not avail, return overflow. Else, stores c at out_cur, + // increments out_cur, and returns c as int_type + strb_03.str(str_01); //reset + std::string::size_type sz1 = strb_03.str().length(); + c1 = strb_03.sputc('a'); + std::string::size_type sz2 = strb_03.str().length(); + VERIFY( sz1 == sz2 ); //cuz inserting at out_cur, which is at beg to start + c2 = strb_03.sputc('b'); + VERIFY( c1 != c2 ); + VERIFY( strb_03.str() != str_01 ); + c3 = strb_02.sputc('a'); // should be EOF because this is read-only + VERIFY( c3 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1057.cc new file mode 100644 index 000000000..f88f28e39 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::stringbuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc('a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/9404-1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/9404-1.cc new file mode 100644 index 000000000..3521c0454 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/char/9404-1.cc @@ -0,0 +1,72 @@ +// 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 + +#include <sstream> +#include <testsuite_hooks.h> + +bool over_called; + +class Derived_stringbuf : public std::stringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::stringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputc + Derived_stringbuf dsbuf_01; + over_called = false; + dsbuf_01.sputc('i'); + VERIFY( over_called ); + over_expected = dsbuf_01.pub_epptr() == dsbuf_01.pub_pptr(); + over_called = false; + dsbuf_01.sputc('v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dsbuf_01.sputc('i'); + VERIFY( dsbuf_01.str() == "ivi" ); // Sanity check. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc new file mode 100644 index 000000000..e9c7fb174 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1.cc @@ -0,0 +1,66 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + + // PUT + // int_type sputc(char_type c) + // if out_cur not avail, return overflow. Else, stores c at out_cur, + // increments out_cur, and returns c as int_type + strb_03.str(str_01); //reset + std::wstring::size_type sz1 = strb_03.str().length(); + c1 = strb_03.sputc(L'a'); + std::wstring::size_type sz2 = strb_03.str().length(); + VERIFY( sz1 == sz2 ); //cuz inserting at out_cur, which is at beg to start + c2 = strb_03.sputc(L'b'); + VERIFY( c1 != c2 ); + VERIFY( strb_03.str() != str_01 ); + c3 = strb_02.sputc(L'a'); // should be EOF because this is read-only + VERIFY( c3 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc new file mode 100644 index 000000000..ae07ebf30 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::wstringbuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::wstring text1 = L"abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as sputc writes to null pointer + nsp.sputc(L'a'); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc new file mode 100644 index 000000000..693af97aa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputc/wchar_t/9404-1.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +bool over_called; + +class Derived_stringbuf : public std::wstringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::wstringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + + // sputc + Derived_stringbuf dsbuf_01; + over_called = false; + dsbuf_01.sputc(L'i'); + VERIFY( over_called ); + over_expected = dsbuf_01.pub_epptr() == dsbuf_01.pub_pptr(); + over_called = false; + dsbuf_01.sputc(L'v'); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + dsbuf_01.sputc(L'i'); + VERIFY( dsbuf_01.str() == L"ivi" ); // Sanity check. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1.cc new file mode 100644 index 000000000..b9a96641f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1.cc @@ -0,0 +1,76 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#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::streamsize strmsz_1, strmsz_2; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + // PUT + strb_03.str(str_01); //reset + std::string::size_type sz1 = strb_03.str().length(); + std::string::size_type sz2 = strb_03.str().length(); + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + str_tmp = strb_03.str(); + sz1 = str_tmp.length(); + strmsz_1 = strb_03.sputn("racadabras", 10);//"abracadabras or what?" + sz2 = strb_03.str().length(); + VERIFY( sz1 == sz2 ); //shouldn't have changed length + VERIFY( strmsz_1 == 10 ); + VERIFY( str_tmp != strb_03.str() ); + strmsz_2 = strb_03.sputn(", i wanna reach out and", 23); + VERIFY( strmsz_1 != strmsz_2 ); // should re-allocate, copy 10 chars. + VERIFY( strmsz_1 == 10 ); + VERIFY( strmsz_2 == 23 ); + sz2 = strb_03.str().length(); + VERIFY( sz1 != sz2 ); // need to change length + VERIFY( str_tmp != strb_03.str() ); + str_tmp = strb_02.str(); + strmsz_1 = strb_02.sputn("racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( str_tmp == strb_02.str() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1057.cc new file mode 100644 index 000000000..c51f47a8d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 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.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::stringbuf +{ + char foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::string text1 = "abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/9404-2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/9404-2.cc new file mode 100644 index 000000000..a532f203a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/char/9404-2.cc @@ -0,0 +1,72 @@ +// 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 + +#include <sstream> +#include <testsuite_hooks.h> + +bool over_called; + +class Derived_stringbuf : public std::stringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::stringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + Derived_stringbuf dsbuf_01; + + // sputn + Derived_stringbuf dsbuf_02; + over_called = false; + dsbuf_02.sputn("sonne's", 7); + VERIFY( over_called ); + over_expected = dsbuf_02.pub_epptr() == dsbuf_02.pub_pptr(); + over_called = false; + dsbuf_02.sputn(" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + VERIFY( dsbuf_02.str() == "sonne's peak" ); // Sanity check. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc new file mode 100644 index 000000000..c62ba3678 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1.cc @@ -0,0 +1,76 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#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::streamsize strmsz_1, strmsz_2; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + // PUT + strb_03.str(str_01); //reset + std::wstring::size_type sz1 = strb_03.str().length(); + std::wstring::size_type sz2 = strb_03.str().length(); + + // streamsize sputn(const char_type* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + str_tmp = strb_03.str(); + sz1 = str_tmp.length(); + strmsz_1 = strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + sz2 = strb_03.str().length(); + VERIFY( sz1 == sz2 ); //shouldn't have changed length + VERIFY( strmsz_1 == 10 ); + VERIFY( str_tmp != strb_03.str() ); + strmsz_2 = strb_03.sputn(L", i wanna reach out and", 23); + VERIFY( strmsz_1 != strmsz_2 ); // should re-allocate, copy 10 chars. + VERIFY( strmsz_1 == 10 ); + VERIFY( strmsz_2 == 23 ); + sz2 = strb_03.str().length(); + VERIFY( sz1 != sz2 ); // need to change length + VERIFY( str_tmp != strb_03.str() ); + str_tmp = strb_02.str(); + strmsz_1 = strb_02.sputn(L"racadabra", 10); + VERIFY( strmsz_1 == 0 ); + VERIFY( str_tmp == strb_02.str() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc new file mode 100644 index 000000000..99f7a5509 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/1057.cc @@ -0,0 +1,53 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 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.5.2 template class basic_streambuf + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +class nullsetpbuf : public std::wstringbuf +{ + wchar_t foo[64]; +public: + nullsetpbuf() + { + setp(foo, foo + 64); + setp(0, 0); + } +}; + +// libstdc++/1057 +void test05() +{ + std::wstring text1 = L"abcdefghijklmn"; + + nullsetpbuf nsp; + // Immediate crash as xsputn writes to null pointer + nsp.sputn(text1.c_str(), text1.length()); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc new file mode 100644 index 000000000..7e7adbea4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sputn/wchar_t/9404-2.cc @@ -0,0 +1,72 @@ +// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.1.3 Overridden virtual functions + +#include <sstream> +#include <testsuite_hooks.h> + +bool over_called; + +class Derived_stringbuf : public std::wstringbuf +{ +public: + int_type overflow(int_type c) + { + over_called = true; + return std::wstringbuf::overflow(c); + } + + const char_type* pub_epptr() const + { + return epptr(); + } + + const char_type* pub_pptr() const + { + return pptr(); + } +}; + +// libstdc++/9404 +void test04() +{ + bool test __attribute__((unused)) = true; + + bool over_expected; + Derived_stringbuf dsbuf_01; + + // sputn + Derived_stringbuf dsbuf_02; + over_called = false; + dsbuf_02.sputn(L"sonne's", 7); + VERIFY( over_called ); + over_expected = dsbuf_02.pub_epptr() == dsbuf_02.pub_pptr(); + over_called = false; + dsbuf_02.sputn(L" peak", 5); + VERIFY( (!over_expected && !over_called) + || (over_expected && over_called) ); + VERIFY( dsbuf_02.str() == L"sonne's peak" ); // Sanity check. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/1.cc new file mode 100644 index 000000000..cc0d0bd79 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/1.cc @@ -0,0 +1,73 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <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 member functions +void test03() +{ + bool test __attribute__((unused)) = true; + + //stringbuf::str() + VERIFY( strb_01.str() == str_01 ); + VERIFY( strb_02.str() == str_02 ); + VERIFY( strb_03.str() == str_03 ); + + //stringbuf::str(string&) + strb_03.str("none of the above, go to the oberoi in cairo, egypt."); + strb_03.str(str_01); + std::streamsize d1 = strb_01.in_avail(); + std::streamsize d2 = strb_03.in_avail(); + VERIFY( d1 ); // non-zero + VERIFY( d2 == -1 ); // -1, cuz ios_base::out + VERIFY( d1 != d2 ); //these should be the same + VERIFY( static_cast<std::streamsize>(str_01.length()) == d1 ); + VERIFY( strb_01.str() == strb_03.str() ); //ditto + + // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the + // string in question contains embedded NUL characters. Note that in this + // embedded-NUL situation, the size must be passed to the string ctor. + std::string str_nulls ("eschew \0 obfuscation", 20); // tested in 21_strings + std::stringbuf strb_normal (str_01); + std::stringbuf strb_nulls (str_nulls); + strb_normal.str(str_nulls); // tried using 'strb_01' rather than declaring + // another variable, but then test04 broke! + VERIFY( strb_nulls.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); + VERIFY( strb_nulls.str().size() == 20 ); + VERIFY( strb_normal.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); +} + +int main() +{ + test03(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/2.cc new file mode 100644 index 000000000..c367d3810 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/2.cc @@ -0,0 +1,54 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2003-02/msg00269.html +// Growing and then seeking to ios_base::beg triggered a bug in str(), +// which didn't notice the grow. +void test07() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf strb_01; + strb_01.sputc('s'); + strb_01.pubseekoff(0, std::ios_base::beg); + std::string tmp = strb_01.str(); + VERIFY( tmp == "s" ); + + std::string str("strivi,"); + std::stringbuf strb_02(str); + strb_02.pubseekoff(0, std::ios_base::end); + strb_02.sputn(" no better!", 11); + strb_02.pubseekoff(0, std::ios_base::beg); + tmp = strb_02.str(); + VERIFY( tmp == "strivi, no better!" ); +} + +int main() +{ + test07(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3.cc new file mode 100644 index 000000000..973a7c843 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3.cc @@ -0,0 +1,42 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +void test06() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream os ("foo", std::ios_base::app); + os << "bar"; + + VERIFY( os.str() == "foobar" ); +} + +int main() +{ + test06(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3955.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3955.cc new file mode 100644 index 000000000..113235738 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/char/3955.cc @@ -0,0 +1,43 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3955 -- ios_base::app overwrites from the beginning +void test05() +{ + bool test __attribute__((unused)) = true; + + std::ostringstream os ("foo"); + os << "bar"; + + VERIFY( os.str() == "bar" ); +} + +int main() +{ + test05(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc new file mode 100644 index 000000000..7369b18ee --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/1.cc @@ -0,0 +1,73 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <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 member functions +void test03() +{ + bool test __attribute__((unused)) = true; + + // stringbuf::str() + VERIFY( strb_01.str() == str_01 ); + VERIFY( strb_02.str() == str_02 ); + VERIFY( strb_03.str() == str_03 ); + + // stringbuf::str(string&) + strb_03.str(L"none of the above, go to the oberoi in cairo, egypt."); + strb_03.str(str_01); + std::streamsize d1 = strb_01.in_avail(); + std::streamsize d2 = strb_03.in_avail(); + VERIFY( d1 ); // non-zero + VERIFY( d2 == -1 ); // -1, cuz ios_base::out + VERIFY( d1 != d2 ); //these should be the same + VERIFY( static_cast<std::streamsize>(str_01.length()) == d1 ); + VERIFY( strb_01.str() == strb_03.str() ); //ditto + + // stringbuf::str(string&) and stringbuf::stringbuf(string&), where the + // string in question contains embedded NUL characters. Note that in this + // embedded-NUL situation, the size must be passed to the string ctor. + std::wstring str_nulls(L"eschew \0 obfuscation", 20); // tested in 21_strings + std::wstringbuf strb_normal(str_01); + std::wstringbuf strb_nulls(str_nulls); + strb_normal.str(str_nulls); // tried using 'strb_01' rather than declaring + // another variable, but then test04 broke! + VERIFY( strb_nulls.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); + VERIFY( strb_nulls.str().size() == 20 ); + VERIFY( strb_normal.in_avail() == static_cast<std::streamsize>(str_nulls.size()) ); +} + +int main() +{ + test03(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc new file mode 100644 index 000000000..5b028e551 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/2.cc @@ -0,0 +1,54 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/libstdc++/2003-02/msg00269.html +// Growing and then seeking to ios_base::beg triggered a bug in str(), +// which didn't notice the grow. +void test07() +{ + bool test __attribute__((unused)) = true; + + std::wstringbuf strb_01; + strb_01.sputc(L's'); + strb_01.pubseekoff(0, std::ios_base::beg); + std::wstring tmp = strb_01.str(); + VERIFY( tmp == L"s" ); + + std::wstring str(L"strivi,"); + std::wstringbuf strb_02(str); + strb_02.pubseekoff(0, std::ios_base::end); + strb_02.sputn(L" no better!", 11); + strb_02.pubseekoff(0, std::ios_base::beg); + tmp = strb_02.str(); + VERIFY( tmp == L"strivi, no better!" ); +} + +int main() +{ + test07(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc new file mode 100644 index 000000000..710789cb7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3.cc @@ -0,0 +1,42 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +void test06() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream os (L"foo", std::ios_base::app); + os << L"bar"; + + VERIFY( os.str() == L"foobar" ); +} + +int main() +{ + test06(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc new file mode 100644 index 000000000..3a1179ccb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/str/wchar_t/3955.cc @@ -0,0 +1,43 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/3955 -- ios_base::app overwrites from the beginning +void test05() +{ + bool test __attribute__((unused)) = true; + + std::wostringstream os (L"foo"); + os << L"bar"; + + VERIFY( os.str() == L"bar" ); +} + +int main() +{ + test05(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc new file mode 100644 index 000000000..ae038e518 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/char/1.cc @@ -0,0 +1,144 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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; + typedef std::stringbuf::int_type int_type; + typedef std::stringbuf::traits_type traits_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + strb_03.str().length(); + strb_03.str().length(); + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + str_tmp = strb_03.str(); + str_tmp.length(); + strb_03.sputn("racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + strb_02.sputn("racadabra", 10); + + // PUTBACK + + // 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() + strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?" + c3 = strb_01.sgetc(); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc('z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc('y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sputbackc('x'); + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + for (int i = 0; i<12; ++i) + strb_01.sbumpc(); + strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == ' ' ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 != c2 ); + VERIFY( c1 == c3 ); + VERIFY( c2 == traits_type::eof() ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sungetc(); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc new file mode 100644 index 000000000..767b7eac5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sungetc/wchar_t/1.cc @@ -0,0 +1,144 @@ +// 981208 bkoz test functionality of basic_stringbuf for char_type == wchar_t + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 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/>. + +#include <sstream> +#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; + typedef std::wstringbuf::int_type int_type; + typedef std::wstringbuf::traits_type traits_type; + + int_type c1 = strb_01.sbumpc(); + int_type c2 = strb_02.sbumpc(); + int_type c3 = strb_01.sbumpc(); + int_type c4 = strb_02.sbumpc(); + + // PUT + strb_03.str(str_01); //reset + strb_03.str().length(); + strb_03.str().length(); + + // streamsize sputn(const char_typs* s, streamsize n) + // write up to n chars to out_cur from s, returning number assigned + // NB *sputn will happily put '\0' into your stream if you give it a chance* + str_tmp = strb_03.str(); + str_tmp.length(); + strb_03.sputn(L"racadabras", 10);//"abracadabras or what?" + strb_03.str().length(); + strb_03.sputn(L", i wanna reach out and", 10); + strb_03.str().length(); + str_tmp = strb_02.str(); + strb_02.sputn(L"racadabra", 10); + + // PUTBACK + + // 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() + strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sputbackc('z');//"mykonos. . .zor what?" + c3 = strb_01.sgetc(); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sputbackc(L'z');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sputbackc(L'y');//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sputbackc(L'x'); + + // int_type sungetc() + // if in_cur not avail, return pbackfail(), else decrement and + // return to_int_type(*gptr()) + for (int i = 0; i<12; ++i) + strb_01.sbumpc(); + strb_01.in_avail(); + str_tmp = strb_01.str(); + c1 = strb_01.sgetc(); //"mykonos. . . 'o'r what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( c2 == L' ' ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for _in_cur == _in_beg + strb_01.str(str_tmp); + strb_01.in_avail(); + c1 = strb_01.sgetc(); //"'m'ykonos. . . or what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 != c2 ); + VERIFY( c1 == c3 ); + VERIFY( c2 == traits_type::eof() ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + // test for replacing char with identical one + strb_01.str(str_01); //reset + strb_01.in_avail(); + strb_01.sbumpc(); + strb_01.sbumpc(); + c1 = strb_01.sgetc(); //"my'k'onos. . . or what?" + c2 = strb_01.sungetc();//"mykonos. . . or what?" + c3 = strb_01.sgetc(); + VERIFY( c1 != c2 ); + VERIFY( c3 == c2 ); + VERIFY( c1 != c3 ); + VERIFY( strb_01.str() == str_01 ); + VERIFY( str_01.size() == strb_01.str().size() ); + //test for ios_base::out + strb_03.in_avail(); + c4 = strb_03.sungetc(); + VERIFY( c4 == traits_type::eof() ); +} + +int main() +{ + test04(); + return 0; +} + + + +// more candy!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/char/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/char/1057.cc new file mode 100644 index 000000000..baa93fbfd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/char/1057.cc @@ -0,0 +1,100 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <testsuite_hooks.h> + +class setpbuf : public std::stringbuf +{ + char buffer[4]; + std::string result; + +public: + + std::string& + get_result() + { return result; } + + setpbuf() + { + char foo [32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { sync(); } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::string text = "abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::string::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc new file mode 100644 index 000000000..25cf5b0da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/sync/wchar_t/1057.cc @@ -0,0 +1,100 @@ +// 1999-10-11 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.5.2 template class basic_streambuf + +#include <sstream> +#include <testsuite_hooks.h> + +class setpbuf : public std::wstringbuf +{ + wchar_t buffer[4]; + std::wstring result; + +public: + + std::wstring& + get_result() + { return result; } + + setpbuf() + { + wchar_t foo [32]; + setp(foo, foo + 32); + setp(buffer, buffer + 4); + } + + ~setpbuf() + { sync(); } + + virtual int_type + overflow(int_type n) + { + if (sync() != 0) + return traits_type::eof(); + + result += traits_type::to_char_type(n); + + return n; + } + + virtual int + sync() + { + result.append(pbase(), pptr()); + setp(buffer, buffer + 4); + return 0; + } +}; + +// libstdc++/1057 +void test04() +{ + bool test __attribute__((unused)) = true; + std::wstring text = L"abcdefghijklmn"; + + // 01 + setpbuf sp1; + // Here xsputn writes over sp1.result + sp1.sputn(text.c_str(), text.length()); + + // This crashes when result is accessed + sp1.pubsync(); + VERIFY( sp1.get_result() == text ); + + // 02 + setpbuf sp2; + for (std::wstring::size_type i = 0; i < text.length(); ++i) + { + // sputc also writes over result + sp2.sputc(text[i]); + } + + // Crash here + sp2.pubsync(); + VERIFY( sp2.get_result() == text ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/2020.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/2020.cc new file mode 100644 index 000000000..3f04bbd71 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/2020.cc @@ -0,0 +1,54 @@ +// 1999-01-17 bkoz test functionality of basic_filebuf for char_type == char + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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.1 - Template class basic_filebuf +// NB: This file is for testing basic_filebuf with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// libstdc++/2020 +// should be able to use custom char_type, custom traits type +void test07() +{ + bool test __attribute__((unused)) = true; + typedef std::basic_stringstream<__gnu_test::pod_ushort> gnu_sstr; + + try + { + gnu_sstr obj; + } + catch(std::exception& obj) + { + test = false; + VERIFY( test ); + } +} + +int main() +{ + test07(); + return 0; +} + + + +// more surf!!! diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/rdbuf/char/2832.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/rdbuf/char/2832.cc new file mode 100644 index 000000000..5fd832be2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/rdbuf/char/2832.cc @@ -0,0 +1,61 @@ +// 2003-04-01 Benjamin Kosnik <bkoz@redhat.com> + +// 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.7.6 - Member functions [lib.stringstream.members] + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + std::stringbuf sbuf; + std::streambuf* pbasebuf0 = &sbuf; + + std::stringstream sstrm1; + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::stringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::stringbuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/rdbuf/wchar_t/2832.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/rdbuf/wchar_t/2832.cc new file mode 100644 index 000000000..df1b1e868 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/rdbuf/wchar_t/2832.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 - Member functions [lib.stringstream.members] + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::wios& stream, std::wstreambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::wstreambuf* +active_buffer(std::wios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + std::wstringbuf sbuf; + std::wstreambuf* pbasebuf0 = &sbuf; + + std::wstringstream sstrm1; + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::wstringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::wstreambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::wstringbuf* const buf2 = sstrm1.rdbuf(); + std::wstreambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/base_classes.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/base_classes.cc new file mode 100644 index 000000000..a68f5eb1d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/base_classes.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// 2003-03-26 B enjamin Kosnik <bkoz@redhat.com> + +// 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.1 - Template class basic_filebuf + +#include <iostream> +#include <sstream> + +void test01() +{ + // Check for required base class. + typedef std::stringstream test_type; + typedef std::iostream base_type; + const test_type& obj = *new test_type(); + const base_type* base __attribute__((unused)) = &obj; +} + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..ae134cd62 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/explicit_instantiation.cc @@ -0,0 +1,35 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2002, 2003, 2004, 2005, 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.4 - Template class basic_stringstream +// NB: This file is for testing basic_stringstream with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class basic_stringstream<type_t, char_traits<type_t> >; + template class basic_stringstream<pod_char, char_traits<pod_char> >; +} // std diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/typedefs.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/typedefs.cc new file mode 100644 index 000000000..1fa4eb718 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/requirements/typedefs.cc @@ -0,0 +1,38 @@ +// { dg-do compile } +// 2002-07-25 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 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.4 - Template class basic_stringstream +// NB: This file is for testing basic_stringstream with NO OTHER INCLUDES. + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/7216 +void test01() +{ + // Check for required typedefs + typedef std::stringstream test_type; + typedef test_type::char_type char_type; + typedef test_type::traits_type traits_type; + typedef test_type::int_type int_type; + typedef test_type::pos_type pos_type; + typedef test_type::off_type off_type; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/1.cc new file mode 100644 index 000000000..f8f3ef129 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/1.cc @@ -0,0 +1,76 @@ +// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::stringstream is01; + const std::string str00; + const std::string str01 = "123"; + std::string str02; + const int i01 = 123; + int a = 0, b = 0; + + std::ios_base::iostate state1, state2, stateeof; + stateeof = std::ios_base::eofbit; + + // string str() const + str02 = is01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + is01.str(str01); + str02 = is01.str(); + VERIFY( str01 == str02 ); + state1 = is01.rdstate(); + is01 >> a; + state2 = is01.rdstate(); + VERIFY( a == i01 ); + // 22.2.2.1.2 num_get virtual functions + // p 13 + // in any case, if stage 2 processing was terminated by the test for + // in == end then err != ios_base::eofbit is performed. + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is01.str(str01); + is01 >> b; + VERIFY( b != a ); + // as is01.good() is false, istream::sentry blocks extraction. + + is01.clear(); + state1 = is01.rdstate(); + is01 >> b; + state2 = is01.rdstate(); + VERIFY( b == a ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/2.cc new file mode 100644 index 000000000..46418e648 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/2.cc @@ -0,0 +1,74 @@ +// 2001-05-24 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.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::ios& stream, std::streambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::streambuf* +active_buffer(std::ios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const char* strlit01 = "fuck war"; + const std::string str00; + const std::string str01(strlit01); + std::string str02; + std::stringbuf sbuf(str01); + std::streambuf* pbasebuf0 = &sbuf; + + std::stringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::stringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::streambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::stringbuf* const buf2 = sstrm1.rdbuf(); + std::streambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::stringbuf* psbuf = dynamic_cast<std::stringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/3.cc new file mode 100644 index 000000000..b6137878c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/3.cc @@ -0,0 +1,58 @@ +// 2001-05-24 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +test03() +{ + bool test __attribute__((unused)) = true; + + // + // 1: Automatic formatting of a compound string + // + int i = 1024; + int *pi = &i; + double d = 3.14159; + double *pd = &d; + std::string blank; + std::ostringstream ostrst01; + std::ostringstream ostrst02(blank); + + // No buffer, so should be created. + ostrst01 << "i: " << i << " i's address: " << pi << '\n' + << "d: " << d << " d's address: " << pd << std::endl; + // Buffer, so existing buffer should be overwritten. + ostrst02 << "i: " << i << " i's address: " << pi << '\n' + << "d: " << d << " d's address: " << pd << std::endl; + + std::string msg01 = ostrst01.str(); + std::string msg02 = ostrst02.str(); + VERIFY( msg01 == msg02 ); + VERIFY( msg02 != blank ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/4.cc new file mode 100644 index 000000000..6bd9b1d03 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/char/4.cc @@ -0,0 +1,44 @@ +// 2001-05-24 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.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8466 +void test04() +{ + bool test __attribute__((unused)) = true; + + const char* strlit00 = "orvieto"; + const std::string str00 = strlit00; + + std::ostringstream oss; + + oss.str(str00); + oss << "cortona"; + VERIFY( str00 == strlit00 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/1.cc new file mode 100644 index 000000000..c8b4b4d48 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/1.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + std::wstringstream is01; + const std::wstring str00; + const std::wstring str01 = L"123"; + std::wstring str02; + const int i01 = 123; + int a = 0, b = 0; + + std::ios_base::iostate state1, state2, stateeof; + stateeof = std::ios_base::eofbit; + + // string str() const + str02 = is01.str(); + VERIFY( str00 == str02 ); + + // void str(const basic_string&) + is01.str(str01); + str02 = is01.str(); + VERIFY( str01 == str02 ); + state1 = is01.rdstate(); + is01 >> a; + state2 = is01.rdstate(); + VERIFY( a == i01 ); + // 22.2.2.1.2 num_get virtual functions + // p 13 + // in any case, if stage 2 processing was terminated by the test for + // in == end then err != ios_base::eofbit is performed. + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); + + is01.str(str01); + is01 >> b; + VERIFY( b != a ); + // as is01.good() is false, istream::sentry blocks extraction. + + is01.clear(); + state1 = is01.rdstate(); + is01 >> b; + state2 = is01.rdstate(); + VERIFY( b == a ); + VERIFY( state1 != state2 ); + VERIFY( state2 == stateeof ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/2.cc new file mode 100644 index 000000000..b7ab009ad --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/2.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +redirect_buffer(std::wios& stream, std::wstreambuf* new_buf) +{ stream.rdbuf(new_buf); } + +std::wstreambuf* +active_buffer(std::wios& stream) +{ return stream.rdbuf(); } + +// libstdc++/2832 +void test02() +{ + bool test __attribute__((unused)) = true; + const wchar_t* strlit01 = L"fuck war"; + const std::wstring str00; + const std::wstring str01(strlit01); + std::wstring str02; + std::wstringbuf sbuf(str01); + std::wstreambuf* pbasebuf0 = &sbuf; + + std::wstringstream sstrm1; + VERIFY( sstrm1.str() == str00 ); + // derived rdbuf() always returns original streambuf, even though + // it's no longer associated with the stream. + std::wstringbuf* const buf1 = sstrm1.rdbuf(); + // base rdbuf() returns the currently associated streambuf + std::wstreambuf* pbasebuf1 = active_buffer(sstrm1); + redirect_buffer(sstrm1, &sbuf); + std::wstringbuf* const buf2 = sstrm1.rdbuf(); + std::wstreambuf* pbasebuf2 = active_buffer(sstrm1); + VERIFY( buf1 == buf2 ); + VERIFY( pbasebuf1 != pbasebuf2 ); + VERIFY( pbasebuf2 == pbasebuf0 ); + + // derived rdbuf() returns the original buf, so str() doesn't change. + VERIFY( sstrm1.str() != str01 ); + VERIFY( sstrm1.str() == str00 ); + // however, casting the active streambuf to a stringbuf shows what's up: + std::wstringbuf* psbuf = dynamic_cast<std::wstringbuf*>(pbasebuf2); + str02 = psbuf->str(); + VERIFY( str02 == str01 ); + + // How confusing and non-intuitive is this? + // These semantics are a joke, a serious defect, and incredibly lame. +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/3.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/3.cc new file mode 100644 index 000000000..ffcf3eaed --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/3.cc @@ -0,0 +1,56 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +void +test03() +{ + bool test __attribute__((unused)) = true; + + // + // 1: Automatic formatting of a compound string + // + int i = 1024; + int *pi = &i; + double d = 3.14159; + double *pd = &d; + std::wstring blank; + std::wostringstream ostrst01; + std::wostringstream ostrst02(blank); + + // No buffer, so should be created. + ostrst01 << L"i: " << i << L" i's address: " << pi << L'\n' + << L"d: " << d << L" d's address: " << pd << std::endl; + // Buffer, so existing buffer should be overwritten. + ostrst02 << L"i: " << i << L" i's address: " << pi << L'\n' + << L"d: " << d << L" d's address: " << pd << std::endl; + + std::wstring msg01 = ostrst01.str(); + std::wstring msg02 = ostrst02.str(); + VERIFY( msg01 == msg02 ); + VERIFY( msg02 != blank ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/4.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/4.cc new file mode 100644 index 000000000..4c6590cd8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/str/wchar_t/4.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.7.6 member functions (stringstream_members) + +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/8466 +void test04() +{ + bool test __attribute__((unused)) = true; + + const wchar_t* strlit00 = L"orvieto"; + const std::wstring str00 = strlit00; + + std::wostringstream oss; + + oss.str(str00); + oss << L"cortona"; + VERIFY( str00 == strlit00 ); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/11450.cc b/libstdc++-v3/testsuite/27_io/fpos/11450.cc new file mode 100644 index 000000000..768c0aa3b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/11450.cc @@ -0,0 +1,42 @@ +// 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.4.3 fpos + +#include <ios> +#include <testsuite_hooks.h> + +// libstdc++/11450 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::fpos<int> p; + VERIFY( p.state() == 0 ); + p.state(42); + VERIFY( p.state() == 42 ); + + std::fpos<int> q = p + static_cast<std::streamoff>(1); + VERIFY( q.state() == 42 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14252.cc b/libstdc++-v3/testsuite/27_io/fpos/14252.cc new file mode 100644 index 000000000..c114ff0fa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14252.cc @@ -0,0 +1,53 @@ +// 2004-02-24 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.4.3 template class fpos + +#include <ios> +#include <testsuite_hooks.h> + +// libstdc++/14252 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::streamoff off01 = 10; + std::streamoff off02 = 2; + std::streamoff off03 = 2004; + std::streamoff off04 = 1; + + VERIFY( off01++ == 10 ); + VERIFY( off01 == 11 ); + + VERIFY( ++off02 == 3 ); + VERIFY( off02 == 3 ); + + VERIFY( off03-- == 2004 ); + VERIFY( off03 == 2003 ); + + VERIFY( --off04 == 0 ); + VERIFY( off04 == 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc new file mode 100644 index 000000000..a90741294 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-1.cc @@ -0,0 +1,65 @@ +// 2004-03-02 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.4.3 fpos + +// { dg-do run } + +#include <typeinfo> +#include <limits> +#include <iterator> +#include <testsuite_hooks.h> + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char>::difference_type Distance; + + bool found = false; + // The C++ standard didn't originally have "long long", however that + // type will be in the C++0x standard and testing for it allows + // ilp32 targets to pass this test when `Distance' is 64 bits. + if (typeid(Distance) == typeid(long long int)) + found = true; + if (typeid(Distance) == typeid(long int)) + found = true; + if (typeid(Distance) == typeid(int)) + found = true; + if (typeid(Distance) == typeid(short int)) + found = true; + if (typeid(Distance) == typeid(signed char)) + found = true; + if (numeric_limits<char>::is_signed && + typeid(Distance) == typeid(char)) + found = true; + if (numeric_limits<wchar_t>::is_signed && + typeid(Distance) == typeid(wchar_t)) + found = true; + + VERIFY( found ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-2.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-2.cc new file mode 100644 index 000000000..23a9854a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-2.cc @@ -0,0 +1,41 @@ +// 2004-03-02 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.4.3 fpos + +#include <iterator> +#include <limits> +#include <testsuite_hooks.h> + +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char>::difference_type Distance; + typedef numeric_limits<Distance> Limits; + + VERIFY( Limits::is_specialized ); + VERIFY( Limits::is_signed ); +} + +int main() +{ + test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-3.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-3.cc new file mode 100644 index 000000000..dc9891143 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-3.cc @@ -0,0 +1,42 @@ +// 2004-03-02 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.4.3 fpos + +#include <iterator> +#include <testsuite_hooks.h> + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef std::istreambuf_iterator<char>::difference_type Distance; + Distance d = 2; + Distance e = 3; + d *= e; + VERIFY( static_cast<int>(d) == 6 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-4.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-4.cc new file mode 100644 index 000000000..37c0ad60b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-4.cc @@ -0,0 +1,51 @@ +// 2004-03-02 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.4.3 fpos + +#include <iterator> +#include <testsuite_hooks.h> + +class Fred +{ +public: + Fred(bool) + { } +}; + +void barney(Fred) +{ } + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char>::difference_type Distance; + + Distance d = 0; + barney(d); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14320-5.cc b/libstdc++-v3/testsuite/27_io/fpos/14320-5.cc new file mode 100644 index 000000000..eb142e98a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14320-5.cc @@ -0,0 +1,44 @@ +// 2004-03-02 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.4.3 fpos + +#include <iterator> +#include <sstream> +#include <testsuite_hooks.h> + +// libstdc++/14320 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + typedef istreambuf_iterator<char>::difference_type Distance; + + Distance d; + istringstream in("5"); + in >> d; + VERIFY( d == 5 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/14775.cc b/libstdc++-v3/testsuite/27_io/fpos/14775.cc new file mode 100644 index 000000000..83a7410ad --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/14775.cc @@ -0,0 +1,54 @@ +// 2004-03-31 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.4.3 fpos + +#include <fstream> +#include <testsuite_hooks.h> + +#define TWO_GB 2147483648UL + +// Basic test for LFS support. +void test01() +{ +#ifdef _GLIBCXX_USE_LFS + using namespace std; + bool test __attribute__((unused)) = true; + + typedef filebuf::pos_type pos_type; + typedef filebuf::off_type off_type; + + __gnu_test::set_file_limit(TWO_GB + 200); + + basic_filebuf<char> fb; + fb.open("tmp_14775", ios_base::out | ios_base::in | ios_base::trunc); + + pos_type ret = fb.pubseekoff(TWO_GB + 100, ios_base::beg); + VERIFY( ret != pos_type(off_type(-1)) ); + + fb.close(); +#endif +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/1.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/1.cc new file mode 100644 index 000000000..be3e478e8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/1.cc @@ -0,0 +1,59 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 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/>. + + +// 27.4.3 template class fpos + +#include <cwchar> // for mbstate_t +#include <ios> +#include <cstring> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::mbstate_t state_type; + state_type state01 = state_type(); + state_type state02 = state_type(); + + std::streampos pos01(0); + std::streampos pos02(0); + + // 27.4.3.1 fpos members + // void state(state_type s); + // state_type state(); + + // XXX Need to have better sanity checking for the mbstate_t type, + // or whatever the insantiating type for class fpos happens to be + // for streampos, as things like equality operators and assignment + // operators, increment and deincrement operators need to be in + // place. + pos01.state(state02); + state01 = pos01.state(); + test = std::memcmp(&state01, &state02, sizeof(state_type)) == 0; + VERIFY( test ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc new file mode 100644 index 000000000..c7f1167ba --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/12065.cc @@ -0,0 +1,46 @@ +// 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.4.3 fpos + +#include <typeinfo> +#include <ios> +#include <testsuite_hooks.h> + +// libstdc++/12065 +void test01() +{ + bool test __attribute__((unused)) = true; + + std::streampos p(0); + const std::streampos q(0); + std::streamoff o(0); + + VERIFY( typeid(p + o) == typeid(std::streampos) ); + VERIFY( typeid(q + o) == typeid(std::streampos) ); + VERIFY( typeid(p - o) == typeid(std::streampos) ); + VERIFY( typeid(q - o) == typeid(std::streampos) ); + VERIFY( typeid(p - q) == typeid(std::streamoff) ); + VERIFY( typeid(q - p) == typeid(std::streamoff) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/2.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/2.cc new file mode 100644 index 000000000..accb56535 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/2.cc @@ -0,0 +1,88 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2001, 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.4.3 template class fpos + +#include <cwchar> // for mbstate_t +#include <ios> +#include <testsuite_hooks.h> + +// 27.4.3.2 fpos requirements/invariants +void test02() +{ + bool test __attribute__((unused)) = true; + + typedef std::mbstate_t state_type; + + std::streamoff off01; + std::streamoff off02 = 997; + int i02 = 999; + + // p(i), p = i + std::streampos pos01(i02); + std::streampos pos02 = i02; + VERIFY( pos01 == pos02 ); + + // p(o), p = o + // NB: P(o) is only required. + std::streampos pos03(off02); + std::streampos pos04 = off02; + VERIFY( pos03 == pos04 ); + + // O(p) + std::streamoff off03(pos04); + VERIFY( off03 == off02 ); + + // p == q, p!= q + VERIFY( pos01 == pos02 ); + VERIFY( pos02 != pos03 ); + + // q = p + o + // p += o + pos03 = pos03 + off02; + pos04 += off02; + VERIFY( pos03 == pos04 ); + std::streampos pos05 = pos03; + VERIFY ( pos05 == pos03 ); + + // q = p - o + // p -= o + pos03 = pos03 - off02; + pos04 -= off02; + VERIFY( pos03 == pos04 ); + std::streampos pos07 = pos03; + VERIFY ( pos07 == pos03 ); + + // o = p - q + VERIFY( 0 == pos03 - pos04 ); + + // streamsize -> streamoff + // streamoff -> streamsize + off01 = off02; + std::streamsize size01(off02); + std::streamoff off04(size01); + VERIFY( off01 == off04 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/3.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/3.cc new file mode 100644 index 000000000..34c557bfb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/3.cc @@ -0,0 +1,56 @@ +// 1999-09-20 bkoz + +// Copyright (C) 1999, 2001, 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.4.3 template class fpos + +#include <cwchar> // for mbstate_t +#include <ios> +#include <testsuite_hooks.h> + +void test03() +{ + bool test __attribute__((unused)) = true; + + typedef std::mbstate_t state_type; + std::streamoff off01; + + // casts to const streamoff + const std::streampos pos01 = 0; + off01 = std::streamoff(pos01); + off01 = off01; // Suppress unused warning. + + // equality/inequality with const args + const std::streampos pos02(54); + std::streampos pos03(44); + VERIFY( !(pos03 == pos02) ); + VERIFY( pos03 != pos02 ); + VERIFY( !(pos02 == pos03) ); + VERIFY( pos02 != pos03 ); + + // default values + std::streampos pos04; + VERIFY( std::streamoff(pos04) == 0 ); +} + +int main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc new file mode 100644 index 000000000..9e3cad5d5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/4_neg.cc @@ -0,0 +1,43 @@ +// Copyright (C) 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.4.3 fpos + +// { dg-do compile } + +#include <ios> + +void test04() +{ + std::streampos pos; + long n; + + // Implicit conversion + n = pos; // { dg-error "cannot convert" "" { xfail *-*-* } } + + // Explicit conversion + n = static_cast<long>(pos); // { dg-error "invalid static_cast" "" { xfail *-*-* } } + + n = n; // Suppress unused warning. +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/5.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/5.cc new file mode 100644 index 000000000..a32e34adf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/5.cc @@ -0,0 +1,40 @@ +// { dg-do compile } + +// 2006-03-13 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 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.4.3 template class fpos + +#include <ios> + +void test01() +{ + bool test01, test02; + + std::streampos pos01(-1), pos02(0); + + test01 = pos01 == -1; + test01 = -1 == pos01; + test01 = test01; // Suppress unused warning. + + test02 = pos02 != -1; + test02 = -1 != pos02; + test02 = test02; // Suppress unused warning. +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/6.cc b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/6.cc new file mode 100644 index 000000000..0cf651a5c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/mbstate_t/6.cc @@ -0,0 +1,41 @@ +// { dg-do compile } + +// 2006-06-21 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 27.4.3 template class fpos + +#include <ios> + +class +octave_int +{ + template<class U> + octave_int(U i); +}; + +bool +operator==(const octave_int& lhs, const octave_int& rhs); + +bool +Fsave(void) +{ + return std::streampos(0) == std::streampos(0); +} diff --git a/libstdc++-v3/testsuite/27_io/fpos/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/27_io/fpos/requirements/explicit_instantiation.cc new file mode 100644 index 000000000..6140d3278 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/fpos/requirements/explicit_instantiation.cc @@ -0,0 +1,45 @@ +// Copyright (C) 2003, 2004, 2005, 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.4.3 fpos +// NB: This file is for testing fpos with NO OTHER INCLUDES. + +#include <ios> +#include <testsuite_hooks.h> +#include <testsuite_character.h> + +// { dg-do compile } + +namespace std +{ + using __gnu_test::pod_char; + typedef short type_t; + template class fpos<type_t>; + template class fpos<pod_char>; +} // std + +// more surf!!! + + + + + + + + + diff --git a/libstdc++-v3/testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc b/libstdc++-v3/testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc new file mode 100644 index 000000000..21da0770b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=gnu++98" } + +// Copyright (C) 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/>. + +#include <cinttypes> + +// { dg-error "upcoming ISO" "" { target *-*-* } 32 } + + + diff --git a/libstdc++-v3/testsuite/27_io/headers/cinttypes/types_std_c++0x.cc b/libstdc++-v3/testsuite/27_io/headers/cinttypes/types_std_c++0x.cc new file mode 100644 index 000000000..f2958a090 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/cinttypes/types_std_c++0x.cc @@ -0,0 +1,30 @@ +// { dg-options "-std=gnu++0x" } +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <cinttypes> + +void test01() +{ +#if _GLIBCXX_USE_C99_INTTYPES_TR1 + + typedef std::imaxdiv_t my_imaxdiv_t; + +#endif +} diff --git a/libstdc++-v3/testsuite/27_io/headers/cstdio/functions_std.cc b/libstdc++-v3/testsuite/27_io/headers/cstdio/functions_std.cc new file mode 100644 index 000000000..4a0468618 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/cstdio/functions_std.cc @@ -0,0 +1,65 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <cstdio> + +namespace gnu +{ + using std::clearerr; + using std::tmpfile; + using std::fgets; + using std::fscanf; + using std::gets; + using std::rename; + using std::fclose; + using std::fopen; + using std::fseek; + using std::perror; + using std::rewind; + using std::tmpnam; + using std::feof; + using std::fprintf; + using std::fsetpos; + using std::printf; + using std::scanf; + using std::ungetc; + using std::ferror; + using std::vfprintf; + using std::fputc; + using std::ftell; + using std::putc; + using std::setbuf; + using std::fflush; + using std::vprintf; + using std::fputs; + using std::fwrite; + using std::putchar; + using std::setvbuf; + using std::fgetc; + using std::vsprintf; + using std::fread; + using std::getc; + using std::puts; + using std::sprintf; + using std::fgetpos; + using std::freopen; + using std::getchar; + using std::remove; + using std::sscanf; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/cstdio/macros.cc b/libstdc++-v3/testsuite/27_io/headers/cstdio/macros.cc new file mode 100644 index 000000000..8a036b48d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/cstdio/macros.cc @@ -0,0 +1,87 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <cstdio> + +namespace gnu +{ +#ifndef NULL + #error "NULL_must_be_a_macro" +#endif + +#ifndef BUFSIZ + #error "BUFSIZ_must_be_a_macro" +#endif + +#ifndef EOF + #error "EOF_must_be_a_macro" +#endif + +#ifndef FILENAME_MAX + #error "FILENAME_MAX_must_be_a_macro" +#endif + +#ifndef L_tmpnam + #error "L_tmpnam_must_be_a_macro" +#endif + +#ifndef FOPEN_MAX + #error "FOPEN_MAX_must_be_a_macro" +#endif + +#ifndef SEEK_CUR + #error "SEEK_CUR_must_be_a_macro" +#endif + +#ifndef SEEK_END + #error "SEEK_END_must_be_a_macro" +#endif + +#ifndef SEEK_SET + #error "SEEK_SET_must_be_a_macro" +#endif + +#ifndef TMP_MAX + #error "TMP_MAX_must_be_a_macro" +#endif + +#ifndef _IOFBF + #error "_IOFBF_must_be_a_macro" +#endif + +#ifndef _IOLBF + #error "_IOLBF_must_be_a_macro" +#endif + +#ifndef _IONBF + #error "_IONBF_must_be_a_macro" +#endif + +#ifndef stderr + #error "stderr_must_be_a_macro" +#endif + +#ifndef stdin + #error "stdin_must_be_a_macro" +#endif + +#ifndef stdout + #error "stdout_must_be_a_macro" +#endif +} diff --git a/libstdc++-v3/testsuite/27_io/headers/cstdio/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/cstdio/types_std.cc new file mode 100644 index 000000000..f3c15d1f1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/cstdio/types_std.cc @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <cstdio> + +namespace gnu +{ + std::size_t s; + std::FILE f; + std::FILE fpos_t; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc new file mode 100644 index 000000000..f65c4d793 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/fstream/synopsis.cc @@ -0,0 +1,42 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <fstream> + +namespace std { + template <class charT, class traits> + class basic_filebuf; + typedef basic_filebuf<char> filebuf; + typedef basic_filebuf<wchar_t> wfilebuf; + + template <class charT, class traits> + class basic_ifstream; + typedef basic_ifstream<char> ifstream; + typedef basic_ifstream<wchar_t> wifstream; + + template <class charT, class traits> + class basic_ofstream; + typedef basic_ofstream<char> ofstream; + typedef basic_ofstream<wchar_t> wofstream; + + template <class charT, class traits> + class basic_fstream; + typedef basic_fstream<char> fstream; + typedef basic_fstream<wchar_t> wfstream; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/fstream/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/fstream/types_std.cc new file mode 100644 index 000000000..2a66f5ff5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/fstream/types_std.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <fstream> + +namespace gnu +{ + typedef std::filebuf t1; + typedef std::wfilebuf t2; + + typedef std::ifstream t3; + typedef std::wifstream t4; + + typedef std::ofstream t5; + typedef std::wofstream t6; + + typedef std::fstream t7; + typedef std::wfstream t8; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/iomanip/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/iomanip/synopsis.cc new file mode 100644 index 000000000..9071beaf1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/iomanip/synopsis.cc @@ -0,0 +1,32 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <iomanip> + +namespace std { +#if 0 + // Types T1, T2, ... are unspecified implementation types + T1 resetiosflags(ios_base::fmtflags mask); + T2 setiosflags (ios_base::fmtflags mask); + T3 setbase(int base); + template<charT> T4 setfill(charT c); + T5 setprecision(int n); + T6 setw(int n); +#endif +} diff --git a/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc new file mode 100644 index 000000000..577aa677f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/ios/synopsis.cc @@ -0,0 +1,59 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <ios> + +namespace std { +#if 0 + typedef OFF_T streamoff; + typedef SZ_T streamsize; +#endif + + template <class stateT> class fpos; + class ios_base; + template <class charT, class traits> + class basic_ios; + + // 27.4.5, manipulators: + ios_base& boolalpha (ios_base& str); + ios_base& noboolalpha(ios_base& str); + ios_base& showbase (ios_base& str); + ios_base& noshowbase (ios_base& str); + ios_base& showpoint (ios_base& str); + ios_base& noshowpoint(ios_base& str); + ios_base& showpos (ios_base& str); + ios_base& noshowpos (ios_base& str); + ios_base& skipws (ios_base& str); + ios_base& noskipws (ios_base& str); + ios_base& uppercase (ios_base& str); + ios_base& nouppercase(ios_base& str); + ios_base& unitbuf (ios_base& str); + ios_base& nounitbuf (ios_base& str); + // 27.4.5.2 adjustfield: + ios_base& internal (ios_base& str); + ios_base& left (ios_base& str); + ios_base& right (ios_base& str); + // 27.4.5.3 basefield: + ios_base& dec (ios_base& str); + ios_base& hex (ios_base& str); + ios_base& oct (ios_base& str); + // 27.4.5.4 floatfield: + ios_base& fixed (ios_base& str); + ios_base& scientific (ios_base& str); +} diff --git a/libstdc++-v3/testsuite/27_io/headers/ios/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/ios/types_std.cc new file mode 100644 index 000000000..000c2046e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/ios/types_std.cc @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <ios> + +namespace gnu +{ + typedef std::streamoff t1; + typedef std::streamsize t2; + typedef std::ios_base t3; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/iostream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/iostream/synopsis.cc new file mode 100644 index 000000000..10fc7072b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/iostream/synopsis.cc @@ -0,0 +1,32 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <iostream> + +namespace std { + extern istream cin; + extern ostream cout; + extern ostream cerr; + extern ostream clog; + extern wistream wcin; + extern wostream wcout; + extern wostream wcerr; + extern wostream wclog; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/iostream/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/iostream/types_std.cc new file mode 100644 index 000000000..54b4eab83 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/iostream/types_std.cc @@ -0,0 +1,34 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <iostream> + +namespace gnu +{ + using std::cout; + using std::cerr; + using std::cin; + using std::clog; + + using std::wcout; + using std::wcerr; + using std::wcin; + using std::wclog; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc new file mode 100644 index 000000000..a76135a69 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/istream/synopsis.cc @@ -0,0 +1,33 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <istream> + +namespace std { + template <class charT, class traits > + class basic_istream; + typedef basic_istream<char> istream; + typedef basic_istream<wchar_t> wistream; + template <class charT, class traits > + class basic_iostream; + typedef basic_iostream<char> iostream; + typedef basic_iostream<wchar_t> wiostream; + template <class charT, class traits> + basic_istream<charT,traits>& ws(basic_istream<charT,traits>& is); +} diff --git a/libstdc++-v3/testsuite/27_io/headers/istream/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/istream/types_std.cc new file mode 100644 index 000000000..71df8a492 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/istream/types_std.cc @@ -0,0 +1,30 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <istream> + +namespace gnu +{ + typedef std::istream t1; + typedef std::wistream t2; + + typedef std::iostream t3; + typedef std::wiostream t4; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc new file mode 100644 index 000000000..405feaa30 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/ostream/synopsis.cc @@ -0,0 +1,33 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <ostream> + +namespace std { + template <class charT, class traits> + class basic_ostream; + typedef basic_ostream<char> ostream; + typedef basic_ostream<wchar_t> wostream; + template <class charT, class traits> + basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os); + template <class charT, class traits> + basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os); + template <class charT, class traits> + basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os); +} diff --git a/libstdc++-v3/testsuite/27_io/headers/ostream/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/ostream/types_std.cc new file mode 100644 index 000000000..31358bab1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/ostream/types_std.cc @@ -0,0 +1,27 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <ostream> + +namespace gnu +{ + typedef std::ostream t1; + typedef std::wostream t2; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc new file mode 100644 index 000000000..cb8437cfc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/sstream/synopsis.cc @@ -0,0 +1,42 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <sstream> + +namespace std { + template <class charT, class traits, class Allocator> + class basic_stringbuf; + typedef basic_stringbuf<char> stringbuf; + typedef basic_stringbuf<wchar_t> wstringbuf; + + template <class charT, class traits, class Allocator> + class basic_istringstream; + typedef basic_istringstream<char> istringstream; + typedef basic_istringstream<wchar_t> wistringstream; + + template <class charT, class traits, class Allocator> + class basic_ostringstream; + typedef basic_ostringstream<char> ostringstream; + typedef basic_ostringstream<wchar_t> wostringstream; + + template <class charT, class traits, class Allocator> + class basic_stringstream; + typedef basic_stringstream<char> stringstream; + typedef basic_stringstream<wchar_t> wstringstream; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/sstream/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/sstream/types_std.cc new file mode 100644 index 000000000..6e46a2203 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/sstream/types_std.cc @@ -0,0 +1,36 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <sstream> + +namespace gnu +{ + typedef std::stringbuf t1; + typedef std::wstringbuf t2; + + typedef std::istringstream t3; + typedef std::wistringstream t4; + + typedef std::ostringstream t5; + typedef std::wostringstream t6; + + typedef std::stringstream t7; + typedef std::wstringstream t8; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc b/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc new file mode 100644 index 000000000..d0a38ef78 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/streambuf/synopsis.cc @@ -0,0 +1,27 @@ +// { dg-do compile } + +// Copyright (C) 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/>. + +#include <streambuf> + +namespace std { + template <class charT, class traits> + class basic_streambuf; + typedef basic_streambuf<char> streambuf; + typedef basic_streambuf<wchar_t> wstreambuf; +} diff --git a/libstdc++-v3/testsuite/27_io/headers/streambuf/types_std.cc b/libstdc++-v3/testsuite/27_io/headers/streambuf/types_std.cc new file mode 100644 index 000000000..2ad2fb82c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/headers/streambuf/types_std.cc @@ -0,0 +1,27 @@ +// { dg-do compile } +// { dg-require-c-std "" } + +// Copyright (C) 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/>. + +#include <streambuf> + +namespace gnu +{ + typedef std::streambuf t1; + typedef std::wstreambuf t2; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/callbacks/1.cc b/libstdc++-v3/testsuite/27_io/ios_base/callbacks/1.cc new file mode 100644 index 000000000..01b2af053 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/callbacks/1.cc @@ -0,0 +1,61 @@ +// 1999-11-10 bkoz + +// Copyright (C) 1999, 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.4.2.6 ios_base callbacks + +#include <string> +#include <sstream> +#include <testsuite_hooks.h> + +const std::string str01("the nubians of plutonia"); +std::string str02; + +void +callb01(std::ios_base::event, std::ios_base&, int) +{ str02 += "the nubians"; } + +void +callb02(std::ios_base::event, std::ios_base&, int) +{ str02 += " of "; } + +void +callb03(std::ios_base::event, std::ios_base&, int) +{ str02 += "plutonia"; } + +void test01() +{ + bool test __attribute__((unused)) = true; + std::locale loc("C"); + std::stringbuf strbuf01; + std::ios ios01(&strbuf01); + + ios01.register_callback(callb03, 1); + ios01.register_callback(callb02, 1); + ios01.register_callback(callb01, 1); + ios01.imbue(loc); + VERIFY( str01 == str02 ); +} + + +int main(void) +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc b/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc new file mode 100644 index 000000000..4bbe5b119 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/cons/assign_neg.cc @@ -0,0 +1,38 @@ +// { dg-do compile } + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ios> + +// Library defect report +//50. Copy constructor and assignment operator of ios_base +class test_base : public std::ios_base { }; + +void test01() +{ + // assign + test_base io1; + test_base io2; + io1 = io2; +} +// { dg-error "synthesized" "" { target *-*-* } 33 } +// { dg-error "within this context" "" { target *-*-* } 26 } +// { dg-error "is private" "" { target *-*-* } 791 } +// { dg-error "operator=" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc b/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc new file mode 100644 index 000000000..6f453736e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/cons/copy_neg.cc @@ -0,0 +1,38 @@ +// { dg-do compile } + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <ios> + +// Library defect report +//50. Copy constructor and assignment operator of ios_base +struct test_base : public std::ios_base +{ }; + +void test02() +{ + // copy ctor + test_base io1; + test_base io2 = io1; +} +// { dg-error "within this context" "" { target *-*-* } 26 } +// { dg-error "synthesized" "" { target *-*-* } 33 } +// { dg-error "is private" "" { target *-*-* } 788 } +// { dg-error "copy constructor" "" { target *-*-* } 0 } diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/cons_virtual_derivation.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/cons_virtual_derivation.cc new file mode 100644 index 000000000..fbf52b0fa --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/cons_virtual_derivation.cc @@ -0,0 +1,28 @@ +// 2007-05-29 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <ios> +#include <testsuite_api.h> + +int main() +{ + typedef std::ios_base::failure test_type; + __gnu_test::diamond_derivation<test_type, false>::test(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/what-1.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-1.cc new file mode 100644 index 000000000..7b5e1945c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-1.cc @@ -0,0 +1,59 @@ +// 2001-02-26 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 19.1 Exception classes + +#include <string> +#include <ios> +#include <stdexcept> +#include <cstring> +#include <testsuite_hooks.h> + +// libstdc++/1972 +void test01() +{ + bool test __attribute__((unused)) = true; + std::string s("lack of sunlight, no water error"); + + // 1 + std::ios_base::failure obj1 = std::ios_base::failure(s); + + // 2 + std::ios_base::failure obj2(s); + + VERIFY( std::strcmp(obj1.what(), s.data()) == 0 ); + VERIFY( std::strcmp(obj2.what(), s.data()) == 0 ); +} + +void test02() +{ + bool test __attribute__((unused)) = true; + std::string s("lack of sunlight error"); + std::range_error x(s); + + VERIFY( std::strcmp(x.what(), s.data()) == 0 ); +} + +int main(void) +{ + test01(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/what-2.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-2.cc new file mode 100644 index 000000000..50e30a260 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-2.cc @@ -0,0 +1,50 @@ +// 2001-02-26 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 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/>. + +// 19.1 Exception classes + +#include <string> +#include <ios> +#include <cstring> +#include <testsuite_hooks.h> + +// libstdc++/2089 +class fuzzy_logic : public std::ios_base::failure +{ +public: + fuzzy_logic() : std::ios_base::failure("whoa") { } +}; + +void test03() +{ + bool test __attribute__((unused)) = true; + try + { throw fuzzy_logic(); } + catch(const fuzzy_logic& obj) + { VERIFY( std::strcmp("whoa", obj.what()) == 0 ); } + catch(...) + { VERIFY( false ); } +} + +int main(void) +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/what-3.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-3.cc new file mode 100644 index 000000000..ddb29c5ef --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-3.cc @@ -0,0 +1,72 @@ +// 2001-02-26 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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/>. + +// 19.1 Exception classes + +#include <string> +#include <ios> +#include <cstring> +#include <testsuite_hooks.h> + +// test copy ctors, assignment operators, and persistence of member string data +// libstdc++/1972 +// via Greg Bumgardner <bumgard@roguewave.com> +void allocate_on_stack(void) +{ + const size_t num = 512; + __extension__ char array[num]; + for (size_t i = 0; i < num; i++) + array[i]=0; + for (size_t i = 0; i < num; i++) + array[i]=array[i]; // Suppress unused warning. +} + +void test04() +{ + bool test __attribute__((unused)) = true; + const std::string s("CA ISO emergency once again:immediate power down"); + const char* strlit1 = "wish I lived in Palo Alto"; + const char* strlit2 = "...or Santa Barbara"; + std::ios_base::failure obj1(s); + + // block 01 + { + const std::string s2(strlit1); + std::ios_base::failure obj2(s2); + obj1 = obj2; + } + allocate_on_stack(); + VERIFY( std::strcmp(strlit1, obj1.what()) == 0 ); + + // block 02 + { + const std::string s3(strlit2); + std::ios_base::failure obj3 = std::ios_base::failure(s3); + obj1 = obj3; + } + allocate_on_stack(); + VERIFY( std::strcmp(strlit2, obj1.what()) == 0 ); +} + +int main(void) +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/failure/what-big.cc b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-big.cc new file mode 100644 index 000000000..18f5a6a94 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/failure/what-big.cc @@ -0,0 +1,40 @@ +// 2007-05-29 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 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/>. + +#include <cstring> +#include <string> +#include <ios> +#include <testsuite_hooks.h> + +// Can construct and return 10k character error string. +void test01() +{ + typedef std::ios_base::failure test_type; + + bool test __attribute__((unused)) = true; + const std::string xxx(10000, 'x'); + test_type t(xxx); + VERIFY( std::strcmp(t.what(), xxx.c_str()) == 0 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/state/1.cc b/libstdc++-v3/testsuite/27_io/ios_base/state/1.cc new file mode 100644 index 000000000..70eb9d6e3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/state/1.cc @@ -0,0 +1,53 @@ +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <testsuite_hooks.h> + +void +test02() +{ + bool test __attribute__((unused)) = true; + const std::string strue("true"); + const std::string sfalse("false"); + std::string str01; + std::string str02; + + std::locale loc_c = std::locale::classic(); + std::ostringstream ostr01; + ostr01.imbue(loc_c); + ostr01.flags(std::ios_base::boolalpha); + + ostr01 << true; + str02 = ostr01.str(); + VERIFY( str02 == strue ); + + ostr01.str(str01); + ostr01 << false; + str02 = ostr01.str(); + VERIFY( str02 == sfalse ); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/1.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/1.cc new file mode 100644 index 000000000..6203a727c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/1.cc @@ -0,0 +1,53 @@ +// 2000-12-19 bkoz + +// Copyright (C) 2000, 2002, 2003, 2004, 2009 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 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.4.2.5 ios_base storage functions + +// XXX This test will not work for some versions of irix6 because of +// XXX bug(s) in libc malloc for very large allocations. However +// XXX -lmalloc seems to work. +// See http://gcc.gnu.org/ml/gcc/2002-05/msg01012.html +// { dg-options "-lmalloc" { target mips*-*-irix6* } } + +#include <sstream> +#include <iostream> +#include <testsuite_hooks.h> + +// http://gcc.gnu.org/ml/gcc-bugs/2000-12/msg00413.html +void test01() +{ + bool test __attribute__((unused)) = true; + + using namespace std; + + ios::xalloc(); + ios::xalloc(); + ios::xalloc(); + long x4 = ios::xalloc(); + + ostringstream out("the element of crime, lars von trier"); + out.pword(++x4); // should not crash +} + +int main(void) +{ + __gnu_test::set_memory_limits(); + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc new file mode 100644 index 000000000..95d3496ac --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/11584.cc @@ -0,0 +1,63 @@ +// 2004-01-25 jlquinn@gcc.gnu.org + +// Copyright (C) 2004, 2005, 2009 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 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.4.2.5 ios_base storage functions + +#include <cstdlib> +#include <new> +#include <iostream> +#include <testsuite_hooks.h> + +int new_fails; + +void* operator new(std::size_t n) throw (std::bad_alloc) +{ + if (new_fails) + throw std::bad_alloc(); + return malloc(n); +} +void* operator new[] (std::size_t n) throw (std::bad_alloc) +{ return operator new(n); } + +void operator delete (void *p) throw() { free(p); } +void operator delete[] (void *p) throw() { operator delete(p); } + +int main () +{ + bool test __attribute__((unused)) = true; + const int i = std::ios::xalloc(); + VERIFY( i >= 0 ); + + new_fails = 1; + + // Successive accesses to failure storage clears to zero. + std::cout.iword(100) = 69; + VERIFY( std::cout.iword(100) == 0 ); + + // Access to pword failure storage shouldn't clear iword pword storage. + long& lr = std::cout.iword(100); + lr = 69; + + void* pv = std::cout.pword(100); + VERIFY( pv == 0 ); + VERIFY( lr == 69 ); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc new file mode 100644 index 000000000..5c695973a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc @@ -0,0 +1,143 @@ +// 2000-12-19 bkoz + +// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 +// 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 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.4.2.5 ios_base storage functions + +// XXX This test will not work for some versions of irix6 because of +// XXX bug(s) in libc malloc for very large allocations. However +// XXX -lmalloc seems to work. +// See http://gcc.gnu.org/ml/gcc/2002-05/msg01012.html +// { dg-options "-lmalloc" { target mips*-*-irix6* } } + +// This fails on some versions of Darwin 8 because malloc doesn't return +// NULL even if an allocation fails (filed as Radar 3884894). +// { dg-do run { xfail *-*-darwin8.[0-4].* } } + +// Skip test at -m64 on Darwin because RLIMITS are not being honored. +// Radar 6467883: 10.4/10.5 setrlimits are not honored by memory allocators +// Radar 6467884: 10.X systems are not robust when paging space is exceeded +// { dg-skip-if "" { *-*-darwin* && lp64 } { "*" } { "" } } + +#include <sstream> +#include <iostream> +#include <limits> +#include <testsuite_hooks.h> + +// libstdc++/3129 +void test02() +{ + bool test __attribute__((unused)) = true; + int max = std::numeric_limits<int>::max() - 1; + std::stringbuf strbuf; + std::ios ios(&strbuf); + + ios.exceptions(std::ios::badbit); + + long l = 0; + void* v = 0; + + // pword + ios.pword(1) = v; + VERIFY( ios.pword(1) == v ); + + try + { + v = ios.pword(max); + } + catch(std::ios_base::failure& obj) + { + // Ok. + VERIFY( ios.bad() ); + } + catch(...) + { + test = false; + VERIFY( test ); + } + VERIFY( v == 0 ); + + VERIFY( ios.pword(1) == v ); + + // max is different code path from max-1 + v = &test; + try + { + v = ios.pword(std::numeric_limits<int>::max()); + } + catch(std::ios_base::failure& obj) + { + // Ok. + VERIFY( ios.bad() ); + } + catch(...) + { + test = false; + VERIFY( test ); + } + VERIFY( v == &test ); + + // iword + ios.iword(1) = 1; + VERIFY( ios.iword(1) == 1 ); + + try + { + l = ios.iword(max); + } + catch(std::ios_base::failure& obj) + { + // Ok. + VERIFY( ios.bad() ); + } + catch(...) + { + test = false; + VERIFY( test ); + } + VERIFY( l == 0 ); + + VERIFY( ios.iword(1) == 1 ); + + // max is different code path from max-1 + l = 1; + try + { + l = ios.iword(std::numeric_limits<int>::max()); + } + catch(std::ios_base::failure& obj) + { + // Ok. + VERIFY( ios.bad() ); + } + catch(...) + { + test = false; + VERIFY( test ); + } + VERIFY( l == 1 ); + +} + +int main(void) +{ + __gnu_test::set_memory_limits(); + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/storage/3.cc b/libstdc++-v3/testsuite/27_io/ios_base/storage/3.cc new file mode 100644 index 000000000..aedf2bcc7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/storage/3.cc @@ -0,0 +1,51 @@ +// 2000-12-19 bkoz + +// Copyright (C) 2000, 2002, 2003, 2004, 2009 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 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.4.2.5 ios_base storage functions + +// XXX This test will not work for some versions of irix6 because of +// XXX bug(s) in libc malloc for very large allocations. However +// XXX -lmalloc seems to work. +// See http://gcc.gnu.org/ml/gcc/2002-05/msg01012.html +// { dg-options "-lmalloc" { target mips*-*-irix6* } } + +#include <sstream> +#include <iostream> +#include <testsuite_hooks.h> + +class derived : public std::ios_base +{ +public: + derived() {} +}; + +void test03() +{ + derived d; + + d.pword(0) = &d; + d.iword(0) = 1; +} + +int main(void) +{ + __gnu_test::set_memory_limits(); + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc new file mode 100644 index 000000000..29ec97548 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/1.cc @@ -0,0 +1,64 @@ +// 1999-05-21 bkoz +// 2000-05-21 Benjamin Kosnik <bkoz@redhat.com> +// 2001-01-17 Loren J. Rittle <ljrittle@acm.org> + +// Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 +// 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 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.4.2.4 ios_base static members +// @require@ %-*.tst +// @diff@ %-*.tst %-*.txt + +// This test fails on platforms using a wrapper, because this test +// redirects stdout to a file and so the exit status printed by the +// wrapper is not visibile to DejaGNU. DejaGNU then assumes that the +// test exited with a non-zero exit status. +// { dg-do run { xfail { ! unwrapped } } } + +#include <cstdio> +#include <sstream> +#include <iostream> +#include <testsuite_hooks.h> + +// N.B. Once we have called sync_with_stdio(false), we can never go back. + +void +test01() +{ + std::ios_base::sync_with_stdio(); + VERIFY( std::freopen("ios_base_members_static-1.txt", "w", stderr) ); + + for (int i = 0; i < 2; i++) + { + std::fprintf(stderr, "1"); + std::cerr << "2"; + std::putc('3', stderr); + std::cerr << '4'; + std::fputs("5", stderr); + std::cerr << 6; + std::putc('7', stderr); + std::cerr << 8 << '9'; + std::fprintf(stderr, "0\n"); + } +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/16959.cc b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/16959.cc new file mode 100644 index 000000000..e2fc2991e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/16959.cc @@ -0,0 +1,32 @@ +// Copyright (C) 2004, 2009 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 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.4.2.4 ios_base static members + +#include <ios> + +// libstdc++/16959 +void test01() +{ + std::ios_base::sync_with_stdio(false); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/2.cc b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/2.cc new file mode 100644 index 000000000..8c10c3fe9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/2.cc @@ -0,0 +1,56 @@ +// 1999-05-21 bkoz +// 2000-05-21 Benjamin Kosnik <bkoz@redhat.com> +// 2001-01-17 Loren J. Rittle <ljrittle@acm.org> + +// Copyright (C) 1999, 2000, 2001, 2003, 2009 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 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.4.2.4 ios_base static members +// @require@ %-*.tst +// @diff@ %-*.tst %-*.txt + +#include <cstdio> +#include <sstream> +#include <iostream> +#include <testsuite_hooks.h> + +// N.B. Once we have called sync_with_stdio(false), we can never go back. + +void test02() +{ + bool test __attribute__((unused)) = true; + + std::stringbuf strbuf01; + std::ios ios01(&strbuf01); + + // 1: basic invocation + VERIFY( ios01.sync_with_stdio() ); + VERIFY( ios01.sync_with_stdio(false) ); //returns previous state + + // 2: need to test interleaving of C and C++ io on a file object. + VERIFY( std::cout.good() ); + VERIFY( !std::cout.sync_with_stdio(0) ); + VERIFY( std::cout.good() ); + VERIFY( !std::cout.sync_with_stdio(0) ); + VERIFY( std::cout.good() ); +} + +int main(void) +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/9523.cc b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/9523.cc new file mode 100644 index 000000000..517d96d9c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/sync_with_stdio/9523.cc @@ -0,0 +1,50 @@ +// 2003-04-26 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2009 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 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.4.2.4 ios_base static members + +#include <testsuite_hooks.h> +#include <iostream> + +// libstdc++/9523 +void test01() +{ + using namespace std; + + int index = ios_base::xalloc(); + + cin.iword(index) = 5; + cout.iword(index) = 6; + cerr.iword(index) = 7; + clog.iword(index) = 8; + + ios_base::sync_with_stdio(false); + + VERIFY( cin.iword(index) == 5 ); + VERIFY( cout.iword(index) == 6 ); + VERIFY( cerr.iword(index) == 7 ); + VERIFY( clog.iword(index) == 8 ); +} + +int main() +{ + test01(); + return 0; +} + diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc new file mode 100644 index 000000000..671a1f1ff --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/bitmask_operators.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// -*- C++ -*- + +// Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::bitmask_operators<std::ios_base::fmtflags>(); +}; diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/case_label.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/case_label.cc new file mode 100644 index 000000000..eb470318b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/case_label.cc @@ -0,0 +1,74 @@ +// { dg-do compile } +// { dg-options "-Wall" { target *-*-* } } +// -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> + +// PR libstdc++/17922 +// -Wall +typedef std::ios_base::fmtflags bitmask_type; + +void +case_labels(bitmask_type b) +{ + switch (b) + { + case std::ios_base::boolalpha: + break; + case std::ios_base::dec: + break; + case std::ios_base::fixed: + break; + case std::ios_base::hex: + break; + case std::ios_base::internal: + break; + case std::ios_base::left: + break; + case std::ios_base::oct: + break; + case std::ios_base::right: + break; + case std::ios_base::scientific: + break; + case std::ios_base::showbase: + break; + case std::ios_base::showpoint: + break; + case std::ios_base::showpos: + break; + case std::ios_base::skipws: + break; + case std::ios_base::unitbuf: + break; + case std::ios_base::uppercase: + break; + case std::ios_base::adjustfield: + break; + case std::ios_base::basefield: + break; + case std::ios_base::floatfield: + break; + case std::_S_ios_fmtflags_end: + break; + } +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/constexpr_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/constexpr_operators.cc new file mode 100644 index 000000000..349f7f9f2 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/fmtflags/constexpr_operators.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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/>. + +#include <ios> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_bitwise_operators<std::ios_base::fmtflags>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc new file mode 100644 index 000000000..00ad1be19 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/bitmask_operators.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// -*- C++ -*- + +// Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::bitmask_operators<std::ios_base::iostate>(); +}; diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/case_label.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/case_label.cc new file mode 100644 index 000000000..8fe23b665 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/case_label.cc @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-options "-Wall" { target *-*-* } } +// -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> + +// PR libstdc++/17922 +// -Wall +typedef std::ios_base::iostate bitmask_type; + +void +case_labels(bitmask_type b) +{ + switch (b) + { + case std::ios_base::goodbit: + break; + case std::ios_base::badbit: + break; + case std::ios_base::eofbit: + break; + case std::ios_base::failbit: + break; + case std::_S_ios_iostate_end: + break; + } +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/constexpr_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/constexpr_operators.cc new file mode 100644 index 000000000..fd3ce1055 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/iostate/constexpr_operators.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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/>. + +#include <ios> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_bitwise_operators<std::ios_base::iostate>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc new file mode 100644 index 000000000..76114c275 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/bitmask_operators.cc @@ -0,0 +1,29 @@ +// { dg-do compile } +// -*- C++ -*- + +// Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::bitmask_operators<std::ios_base::openmode>(); +}; diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc new file mode 100644 index 000000000..f2e3e54dc --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/case_label.cc @@ -0,0 +1,50 @@ +// { dg-do compile } +// { dg-options "-Wall" { target *-*-* } } +// -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> + +// PR libstdc++/17922 +// -Wall +typedef std::ios_base::openmode bitmask_type; + +void +case_labels(bitmask_type b) +{ + switch (b) + { + case std::ios_base::app: + break; + case std::ios_base::ate: + break; + case std::ios_base::binary: + break; + case std::ios_base::in: + break; + case std::ios_base::out: + break; + case std::ios_base::trunc: + break; + case std::_S_ios_openmode_end: + break; + } +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/constexpr_operators.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/constexpr_operators.cc new file mode 100644 index 000000000..66041b87e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/openmode/constexpr_operators.cc @@ -0,0 +1,28 @@ +// { dg-do compile } +// { dg-options "-std=gnu++0x" } + +// 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/>. + +#include <ios> +#include <testsuite_common_types.h> + +int main() +{ + __gnu_test::constexpr_bitwise_operators<std::ios_base::openmode>(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/ios_base/types/seekdir/case_label.cc b/libstdc++-v3/testsuite/27_io/ios_base/types/seekdir/case_label.cc new file mode 100644 index 000000000..2047a78b6 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/ios_base/types/seekdir/case_label.cc @@ -0,0 +1,44 @@ +// { dg-do compile } +// { dg-options "-Wall" { target *-*-* } } +// -*- C++ -*- + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. + +// 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/>. + + +// Benjamin Kosnik <bkoz@redhat.com> + +#include <ios> + +// PR libstdc++/17922 +// -Wall +typedef std::ios_base::seekdir test_type; + +void +case_labels(test_type b) +{ + switch (b) + { + case std::ios_base::beg: + break; + case std::ios_base::cur: + break; + case std::ios_base::end: + break; + case std::_S_ios_fmtflags_end: + break; + } +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/1.cc new file mode 100644 index 000000000..eb3fa3576 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/1.cc @@ -0,0 +1,96 @@ +// 981027 ncm work with libstdc++v3 + +// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <iomanip> +#include <testsuite_hooks.h> + +struct MyNP : std::numpunct<char> +{ + std::string do_truename() const; + std::string do_falsename() const; +}; + +std::string +MyNP::do_truename() const +{ + std::string s("yea"); + return s; +} + +std::string +MyNP::do_falsename() const +{ + std::string s("nay"); + return s; +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + const char lit[] = "1 0\n" + "true false\n" + ": true:\n" + ":true :\n" + ": false:\n" + ": 1:\n" + ":1 :\n" + ": 0:\n" + "yea nay\n" + ": yea:\n" + ":yea :\n" + ": nay:\n"; + + std::ostringstream oss; + oss << true << " " << false << std::endl; + oss << std::boolalpha; + oss << true << " " << false << std::endl; + + oss << ":" << std::setw(6) << std::internal << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::left << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::right << false << ":" << std::endl; + oss << std::noboolalpha; + oss << ":" << std::setw(3) << std::internal << true << ":" << std::endl; + oss << ":" << std::setw(3) << std::left << true << ":" << std::endl; + oss << ":" << std::setw(3) << std::right << false << ":" << std::endl; + + std::locale loc = std::locale(std::locale::classic(), new MyNP); + oss.imbue(loc); + + oss << std::boolalpha; + oss << true << " " << false << std::endl; + + oss << ":" << std::setw(6) << std::internal << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::left << true << ":" << std::endl; + oss << ":" << std::setw(6) << std::right << false << ":" << std::endl; + + VERIFY( oss.good() ); + VERIFY( oss.str() == lit ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/2.cc new file mode 100644 index 000000000..e533cebfe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/char/2.cc @@ -0,0 +1,51 @@ +// Copyright (C) 1997, 1998, 1999, 2002, 2004, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <iomanip> +#include <testsuite_hooks.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + const std::string str_blank; + std::string str_tmp; + std::stringbuf strbuf; + std::ostream o(&strbuf); + + o << std::setw(6) << std::right << "san"; + VERIFY( strbuf.str() == " san" ); + strbuf.str(str_blank); + + o << std::setw(6) << std::internal << "fran"; + VERIFY( strbuf.str() == " fran" ); + strbuf.str(str_blank); + + o << std::setw(6) << std::left << "cisco"; + VERIFY( strbuf.str() == "cisco " ); + strbuf.str(str_blank); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/wchar_t/1.cc new file mode 100644 index 000000000..7a0d0024d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/wchar_t/1.cc @@ -0,0 +1,93 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <iomanip> +#include <testsuite_hooks.h> + +struct MyNP : std::numpunct<wchar_t> +{ + std::wstring do_truename() const; + std::wstring do_falsename() const; +}; + +std::wstring +MyNP::do_truename() const +{ + std::wstring s(L"yea"); + return s; +} + +std::wstring +MyNP::do_falsename() const +{ + std::wstring s(L"nay"); + return s; +} + +void +test01() +{ + bool test __attribute__((unused)) = true; + const wchar_t lit[] = L"1 0\n" + L"true false\n" + L": true:\n" + L":true :\n" + L": false:\n" + L": 1:\n" + L":1 :\n" + L": 0:\n" + L"yea nay\n" + L": yea:\n" + L":yea :\n" + L": nay:\n"; + + std::wostringstream oss; + oss << true << L" " << false << std::endl; + oss << std::boolalpha; + oss << true << L" " << false << std::endl; + + oss << L":" << std::setw(6) << std::internal << true << L":" << std::endl; + oss << L":" << std::setw(6) << std::left << true << L":" << std::endl; + oss << L":" << std::setw(6) << std::right << false << L":" << std::endl; + oss << std::noboolalpha; + oss << L":" << std::setw(3) << std::internal << true << L":" << std::endl; + oss << L":" << std::setw(3) << std::left << true << L":" << std::endl; + oss << L":" << std::setw(3) << std::right << false << L":" << std::endl; + + std::locale loc = std::locale(std::locale::classic(), new MyNP); + oss.imbue(loc); + + oss << std::boolalpha; + oss << true << L" " << false << std::endl; + + oss << L":" << std::setw(6) << std::internal << true << L":" << std::endl; + oss << L":" << std::setw(6) << std::left << true << L":" << std::endl; + oss << L":" << std::setw(6) << std::right << false << L":" << std::endl; + + VERIFY( oss.good() ); + VERIFY( oss.str() == lit ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/wchar_t/2.cc new file mode 100644 index 000000000..49ca6e062 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/adjustfield/wchar_t/2.cc @@ -0,0 +1,50 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <iomanip> +#include <testsuite_hooks.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + const std::wstring str_blank; + std::wstring str_tmp; + std::wstringbuf strbuf; + std::wostream o(&strbuf); + + o << std::setw(6) << std::right << L"san"; + VERIFY( strbuf.str() == L" san" ); + strbuf.str(str_blank); + + o << std::setw(6) << std::internal << L"fran"; + VERIFY( strbuf.str() == L" fran" ); + strbuf.str(str_blank); + + o << std::setw(6) << std::left << L"cisco"; + VERIFY( strbuf.str() == L"cisco " ); + strbuf.str(str_blank); +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/basefield/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/basefield/char/1.cc new file mode 100644 index 000000000..a0c1bd24f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/basefield/char/1.cc @@ -0,0 +1,117 @@ +// 981027 ncm work with libstdc++v3 + +// Copyright (C) 1997, 1998, 1999, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <iomanip> +#include <testsuite_hooks.h> + +struct MyNP : std::numpunct<char> +{ + std::string do_grouping() const; + char do_thousands_sep() const; +}; + +std::string +MyNP::do_grouping() const +{ + std::string s("\3"); + return s; +} + +char +MyNP::do_thousands_sep() const +{ return ' '; } + +void test01() +{ + bool test __attribute__((unused)) = true; + const char lit[] = "0123 456\n" + ": 01 234 567:\n" + ":0123 456 :\n" + ": 012 345:\n" + ": 01 234:\n" + ":0726 746 425:\n" + ":04 553 207 :\n" + ": 0361 100:\n" + ": 0173:\n" + "0x12 345 678\n" + "|0x000012 345 678|\n" + "|0x12 345 6780000|\n" + "|00000x12 345 678|\n" + "|0x000012 345 678|\n"; + + std::ostringstream oss; + oss.imbue(std::locale(std::locale(), new MyNP)); + + // Octals + oss << std::oct << std::showbase; + oss << 0123456l << std::endl; + + oss << ":" << std::setw(11); + oss << 01234567l << ":" << std::endl; + + oss << ":" << std::setw(11) << std::left; + oss << 0123456l << ":" << std::endl; + + oss << ":" << std::setw(11) << std::right; + oss << 012345l << ":" << std::endl; + + oss << ":" << std::setw(11) << std::internal; + oss << 01234l << ":" << std::endl; + + oss << ":" << std::setw(11); + oss << 123456789l << ":" << std::endl; + + oss << ":" << std::setw(11) << std::left; + oss << 1234567l << ":" << std::endl; + + oss << ":" << std::setw(11) << std::right; + oss << 123456l << ":" << std::endl; + + oss << ":" << std::setw(11) << std::internal; + oss << 123l << ":" << std::endl; + + // Hexadecimals + oss << std::hex << std::setfill('0'); + oss << 0x12345678l << std::endl; + + oss << "|" << std::setw(16); + oss << 0x12345678l << "|" << std::endl; + + oss << "|" << std::setw(16) << std::left; + oss << 0x12345678l << "|" << std::endl; + + oss << "|" << std::setw(16) << std::right; + oss << 0x12345678l << "|" << std::endl; + + oss << "|" << std::setw(16) << std::internal; + oss << 0x12345678l << "|" << std::endl; + + VERIFY( oss.good() ); + VERIFY( oss.str() == lit ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/basefield/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/basefield/wchar_t/1.cc new file mode 100644 index 000000000..03f67102d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/basefield/wchar_t/1.cc @@ -0,0 +1,115 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <sstream> +#include <locale> +#include <iomanip> +#include <testsuite_hooks.h> + +struct MyNP : std::numpunct<wchar_t> +{ + std::string do_grouping() const; + wchar_t do_thousands_sep() const; +}; + +std::string +MyNP::do_grouping() const +{ + std::string s("\3"); + return s; +} + +wchar_t +MyNP::do_thousands_sep() const +{ return L' '; } + +void test01() +{ + bool test __attribute__((unused)) = true; + const wchar_t lit[] = L"0123 456\n" + L": 01 234 567:\n" + L":0123 456 :\n" + L": 012 345:\n" + L": 01 234:\n" + L":0726 746 425:\n" + L":04 553 207 :\n" + L": 0361 100:\n" + L": 0173:\n" + L"0x12 345 678\n" + L"|0x000012 345 678|\n" + L"|0x12 345 6780000|\n" + L"|00000x12 345 678|\n" + L"|0x000012 345 678|\n"; + + std::wostringstream oss; + oss.imbue(std::locale(std::locale(), new MyNP)); + + // Octals + oss << std::oct << std::showbase; + oss << 0123456l << std::endl; + + oss << L":" << std::setw(11); + oss << 01234567l << L":" << std::endl; + + oss << L":" << std::setw(11) << std::left; + oss << 0123456l << L":" << std::endl; + + oss << L":" << std::setw(11) << std::right; + oss << 012345l << L":" << std::endl; + + oss << L":" << std::setw(11) << std::internal; + oss << 01234l << L":" << std::endl; + + oss << L":" << std::setw(11); + oss << 123456789l << L":" << std::endl; + + oss << L":" << std::setw(11) << std::left; + oss << 1234567l << L":" << std::endl; + + oss << L":" << std::setw(11) << std::right; + oss << 123456l << L":" << std::endl; + + oss << L":" << std::setw(11) << std::internal; + oss << 123l << L":" << std::endl; + + // Hexadecimals + oss << std::hex << std::setfill(L'0'); + oss << 0x12345678l << std::endl; + + oss << L"|" << std::setw(16); + oss << 0x12345678l << L"|" << std::endl; + + oss << L"|" << std::setw(16) << std::left; + oss << 0x12345678l << L"|" << std::endl; + + oss << L"|" << std::setw(16) << std::right; + oss << 0x12345678l << L"|" << std::endl; + + oss << L"|" << std::setw(16) << std::internal; + oss << 0x12345678l << L"|" << std::endl; + + VERIFY( oss.good() ); + VERIFY( oss.str() == lit ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/1.cc new file mode 100644 index 000000000..681bac56f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/char/1.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-namedlocale "de_DE@euro" } + +// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com> + +// 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/>. + +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_de = std::locale("de_DE@euro"); + + std::istringstream iss; + iss.imbue(loc_de); + + iss.str("7200000000,00 "); + + std::string str; + iss >> std::get_money(str); + + VERIFY( str == "720000000000" ); + VERIFY( iss.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/1.cc new file mode 100644 index 000000000..a288f2e2b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/get_money/wchar_t/1.cc @@ -0,0 +1,49 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-namedlocale "de_DE@euro" } + +// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com> + +// 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/>. + +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_de = std::locale("de_DE@euro"); + + std::wistringstream iss; + iss.imbue(loc_de); + + iss.str(L"7200000000,00 "); + + std::wstring str; + iss >> get_money(str); + + VERIFY( str == L"720000000000" ); + VERIFY( iss.eof() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/1.cc new file mode 100644 index 000000000..2e6775364 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/char/1.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-namedlocale "de_DE@euro" } + +// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com> + +// 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/>. + +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_de = std::locale("de_DE@euro"); + + std::ostringstream oss; + oss.imbue(loc_de); + + const std::string str("720000000000"); + oss << std::put_money(str); + + VERIFY( oss.str() == "7.200.000.000,00 " ); + VERIFY( oss.good() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/1.cc new file mode 100644 index 000000000..38348687a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/extended/put_money/wchar_t/1.cc @@ -0,0 +1,47 @@ +// { dg-options "-std=gnu++0x" } +// { dg-require-namedlocale "de_DE@euro" } + +// 2010-03-01 Paolo Carlini <paolo.carlini@oracle.com> + +// 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/>. + +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void test01() +{ + bool test __attribute__((unused)) = true; + + std::locale loc_de = std::locale("de_DE@euro"); + + std::wostringstream oss; + oss.imbue(loc_de); + + const std::wstring str(L"720000000000"); + oss << std::put_money(str); + + VERIFY( oss.str() == L"7.200.000.000,00 " ); + VERIFY( oss.good() ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/standard/char/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/standard/char/1.cc new file mode 100644 index 000000000..ac7d9a0d8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/standard/char/1.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.3 - Standard manipulators + +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + string s("john coltrane, a love supreme"); + istringstream iss(s); + ostringstream oss; + + // resetiosflags + resetiosflags(ios_base::boolalpha); + iss >> resetiosflags(ios_base::boolalpha); + VERIFY(iss.good()); + oss << resetiosflags(ios_base::boolalpha); + VERIFY(oss.good()); + + // setiosflags + setiosflags(ios_base::skipws); + iss >> setiosflags(ios_base::skipws); + VERIFY(iss.good()); + oss << setiosflags(ios_base::skipws); + VERIFY(oss.good()); + + // setbase + setbase(8); + iss >> setbase(8); + VERIFY(iss.good()); + oss << setbase(8); + VERIFY(oss.good()); + + // setfil + setfill('a'); + iss >> setfill('a'); + VERIFY(iss.good()); + oss << setfill('a'); + VERIFY(oss.good()); + + // setprecision + setprecision(4); + iss >> setprecision(4); + VERIFY(iss.good()); + oss << setprecision(4); + VERIFY(oss.good()); + + // setprecision + setw(7); + iss >> setw(7); + VERIFY(iss.good()); + oss << setw(7); + VERIFY(oss.good()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/standard/char/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/standard/char/2.cc new file mode 100644 index 000000000..8eb4bede1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/standard/char/2.cc @@ -0,0 +1,65 @@ +// { dg-options "-fno-implicit-templates" } + +// Copyright (C) 2001, 2002, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Some members need to be explicitly instantiated, so that users can build +// their own code with -fno-implicit-templates and not suffer from a zillion +// link errors. + +#include <istream> +#include <ostream> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// PR libstdc++/3829 +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + string x (" this is text"); + istringstream sin(x); + ostringstream sout; + + // same order as in bits/std_iomanip.h + sin >> resetiosflags(ios_base::dec) + >> setiosflags(ios_base::dec) + >> setbase(ios_base::dec) + >> setfill('c') + >> setprecision(5) + >> setw(20) + >> ws; + VERIFY(sin.good()); + + sout << resetiosflags(ios_base::dec) + << setiosflags(ios_base::dec) + << setbase(ios_base::dec) + << setfill('c') + << setprecision(5) + << setw(20) + << ends << flush << endl; + VERIFY(sout.good()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/standard/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/manipulators/standard/wchar_t/1.cc new file mode 100644 index 000000000..d71b0cfe3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/standard/wchar_t/1.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// 27.6.3 - Standard manipulators + +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + wstring s(L"john coltrane, a love supreme"); + wistringstream iss(s); + wostringstream oss; + + // resetiosflags + resetiosflags(ios_base::boolalpha); + iss >> resetiosflags(ios_base::boolalpha); + VERIFY(iss.good()); + oss << resetiosflags(ios_base::boolalpha); + VERIFY(oss.good()); + + // setiosflags + setiosflags(ios_base::skipws); + iss >> setiosflags(ios_base::skipws); + VERIFY(iss.good()); + oss << setiosflags(ios_base::skipws); + VERIFY(oss.good()); + + // setbase + setbase(8); + iss >> setbase(8); + VERIFY(iss.good()); + oss << setbase(8); + VERIFY(oss.good()); + + // setfil + setfill(L'a'); + iss >> setfill(L'a'); + VERIFY(iss.good()); + oss << setfill(L'a'); + VERIFY(oss.good()); + + // setprecision + setprecision(4); + iss >> setprecision(4); + VERIFY(iss.good()); + oss << setprecision(4); + VERIFY(oss.good()); + + // setprecision + setw(7); + iss >> setw(7); + VERIFY(iss.good()); + oss << setw(7); + VERIFY(oss.good()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/manipulators/standard/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/manipulators/standard/wchar_t/2.cc new file mode 100644 index 000000000..69f8e3ca9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/manipulators/standard/wchar_t/2.cc @@ -0,0 +1,65 @@ +// { dg-options "-fno-implicit-templates" } + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Some members need to be explicitly instantiated, so that users can build +// their own code with -fno-implicit-templates and not suffer from a zillion +// link errors. + +#include <istream> +#include <ostream> +#include <sstream> +#include <iomanip> +#include <testsuite_hooks.h> + +// PR libstdc++/3829 +void +test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + wstring x(L" this is text"); + wistringstream sin(x); + wostringstream sout; + + // same order as in bits/std_iomanip.h + sin >> resetiosflags(ios_base::dec) + >> setiosflags(ios_base::dec) + >> setbase(ios_base::dec) + >> setfill(L'c') + >> setprecision(5) + >> setw(20) + >> ws; + VERIFY(sin.good()); + + sout << resetiosflags(ios_base::dec) + << setiosflags(ios_base::dec) + << setbase(ios_base::dec) + << setfill(L'c') + << setprecision(5) + << setw(20) + << ends << flush << endl; + VERIFY(sout.good()); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/1.cc b/libstdc++-v3/testsuite/27_io/objects/char/1.cc new file mode 100644 index 000000000..ea57f0892 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/1.cc @@ -0,0 +1,97 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Include all the headers except for iostream. +#include <algorithm> +#include <bitset> +#include <complex> +#include <deque> +#include <exception> +#include <fstream> +#include <functional> +#include <iomanip> +#include <ios> +#include <iosfwd> +#include <istream> +#include <iterator> +#include <limits> +#include <list> +#include <locale> +#include <map> +#include <memory> +#include <new> +#include <numeric> +#include <ostream> +#include <queue> +#include <set> +#include <sstream> +#include <stack> +#include <stdexcept> +#include <streambuf> +#include <string> +#include <typeinfo> +#include <utility> +#include <valarray> +#include <vector> +#include <cassert> +#include <cctype> +#include <cerrno> +#include <cfloat> +#include <ciso646> +#include <climits> +#include <clocale> +#include <cmath> +#include <csetjmp> +#include <csignal> +#include <cstdarg> +#include <cstddef> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctime> +#include <testsuite_hooks.h> + +// Include iostream last, just to make is as difficult as possible to +// properly initialize the standard iostream objects. +#include <iostream> + +// Make sure all the standard streams are defined. +void test01() +{ + bool test __attribute__((unused)) = true; + + char array1[20]; + typedef std::ios::traits_type ctraits_type; + ctraits_type::int_type i = 15; + ctraits_type::copy(array1, "testing istream", i); + array1[i] = '\0'; + std::cout << "testing cout" << std::endl; + std::cerr << "testing cerr" << std::endl; + VERIFY( std::cerr.flags() & std::ios_base::unitbuf ); + std::clog << "testing clog" << std::endl; + // std::cin >> array1; // requires somebody to type something in. + VERIFY( std::cin.tie() == &std::cout ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/10.cc b/libstdc++-v3/testsuite/27_io/objects/char/10.cc new file mode 100644 index 000000000..eebebc20e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/10.cc @@ -0,0 +1,75 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 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/>. + +// { dg-require-fileio "" } +// { dg-require-binary-io "" } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void test10() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "filebuf_virtuals-1.txt"; + + FILE* ret = freopen(name, "r", stdin); + VERIFY( ret ); + + streampos p1 = cin.tellg(); + VERIFY( p1 != streampos(-1) ); + VERIFY( streamoff(p1) == 0 ); + + cin.seekg(0, ios::end); + VERIFY( cin.good() ); + + streampos p2 = cin.tellg(); + VERIFY( p2 != streampos(-1) ); + VERIFY( p2 != p1 ); + VERIFY( streamoff(p2) == ftell(stdin) ); + + cin.seekg(p1); + VERIFY( cin.good() ); + + streamoff n = p2 - p1; + VERIFY( n > 0 ); + + for (int i = 0; i < n; ++i) + { + streampos p3 = cin.tellg(); + VERIFY( streamoff(p3) == i ); + VERIFY( ftell(stdin) == i ); + cin.get(); + VERIFY( cin.good() ); + } + + streampos p4 = cin.tellg(); + VERIFY( streamoff(p4) == n ); + VERIFY( ftell(stdin) == n ); + cin.get(); + VERIFY( cin.eof() ); +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc new file mode 100644 index 000000000..e4982c5e7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc @@ -0,0 +1,46 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 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/>. + +// { dg-require-fileio "" } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + char c1; + char c2; + std::cin.get(c1); + std::cin.unget(); + std::cin.get(c2); + VERIFY( std::cin.good() ); + VERIFY( c1 == c2 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc new file mode 100644 index 000000000..f18e5d393 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc @@ -0,0 +1,42 @@ +// 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/>. + +// { dg-require-fileio "" } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + char c1; + int c2; + std::cin.get(c1); + std::cin.unget(); + VERIFY( std::cin.good() ); + c2 = std::fgetc(stdin); + VERIFY( c2 == std::char_traits<char>::to_int_type(c1) ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc new file mode 100644 index 000000000..3b83ef176 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 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/>. + +// { dg-require-fileio "" } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + char buf[2]; + VERIFY( std::cin.rdbuf()->sgetn(buf, 2) == 2 ); + int c1 = std::cin.rdbuf()->sungetc(); + int c2 = std::cin.rdbuf()->sbumpc(); + VERIFY( c1 == std::char_traits<char>::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc new file mode 100644 index 000000000..0f8600dbb --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc @@ -0,0 +1,41 @@ +// 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/>. + +// { dg-require-fileio "" } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + char buf[2]; + VERIFY( std::cin.rdbuf()->sgetn(buf, 2) == 2 ); + int c1 = std::cin.rdbuf()->sungetc(); + int c2 = std::fgetc(stdin); + VERIFY( c1 == std::char_traits<char>::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc new file mode 100644 index 000000000..dd544b737 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc @@ -0,0 +1,56 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// 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/>. + +// DR 49 states that cin.rdbuf()->sbumpc() and fgetc(stdin) should be +// equivalent and interchangable. Currently however, cin.rdbuf()->sungetc() +// only returns characters that were read with cin.rdbuf()->sbumpc() + +// { dg-require-fileio "" } + +// { dg-do run { xfail *-*-* } } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + char c1; + int c2; + char c3; + std::cin.get(c1); + c2 = std::fgetc(stdin); + std::cin.unget(); + if (std::cin.good()) + { + std::cin.get(c3); + VERIFY( std::cin.good() ); + VERIFY( c3 == std::char_traits<char>::to_char_type(c2) ); + } +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/2.cc b/libstdc++-v3/testsuite/27_io/objects/char/2.cc new file mode 100644 index 000000000..286ba4fd9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/2.cc @@ -0,0 +1,46 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// Interactive test, to be exercised as follows: +// assign stderr to stdout in shell command line, +// pipe stdout to cat process and/or redirect stdout to file. +// a.out >& output +// "hello fine world\n" should be written to stdout, and output, in +// proper order. This is a version of the scott snyder test taken +// from: http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html +void test04() +{ + using namespace std; + + cout << "hello "; + cout.flush(); + cerr << "fine "; + cerr.flush(); + cout << "world" << endl; + cout.flush(); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/2523-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/2523-1_xin.cc new file mode 100644 index 000000000..cc9516a95 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/2523-1_xin.cc @@ -0,0 +1,88 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Include all the headers except for iostream. +#include <algorithm> +#include <bitset> +#include <complex> +#include <deque> +#include <exception> +#include <fstream> +#include <functional> +#include <iomanip> +#include <ios> +#include <iosfwd> +#include <istream> +#include <iterator> +#include <limits> +#include <list> +#include <locale> +#include <map> +#include <memory> +#include <new> +#include <numeric> +#include <ostream> +#include <queue> +#include <set> +#include <sstream> +#include <stack> +#include <stdexcept> +#include <streambuf> +#include <string> +#include <typeinfo> +#include <utility> +#include <valarray> +#include <vector> +#include <cassert> +#include <cctype> +#include <cerrno> +#include <cfloat> +#include <ciso646> +#include <climits> +#include <clocale> +#include <cmath> +#include <csetjmp> +#include <csignal> +#include <cstdarg> +#include <cstddef> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctime> +#include <testsuite_hooks.h> + +// Include iostream last, just to make is as difficult as possible to +// properly initialize the standard iostream objects. +#include <iostream> + +// libstdc++/2523 +void test02() +{ + using namespace std; + int i; + cin >> i; + cout << "i == " << i << endl; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/2523-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/2523-1_xin.in new file mode 100644 index 000000000..ec308096e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/2523-1_xin.in @@ -0,0 +1 @@ +5588885 diff --git a/libstdc++-v3/testsuite/27_io/objects/char/2523-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/2523-2_xin.cc new file mode 100644 index 000000000..302f158ea --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/2523-2_xin.cc @@ -0,0 +1,38 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// libstdc++/2523 +void test03() +{ + using namespace std; + ios_base::sync_with_stdio(false); + + int i; + cin >> i; + cout << "i == " << i << endl; +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/2523-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/2523-2_xin.in new file mode 100644 index 000000000..aaee5e562 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/2523-2_xin.in @@ -0,0 +1 @@ +33332 diff --git a/libstdc++-v3/testsuite/27_io/objects/char/3045.cc b/libstdc++-v3/testsuite/27_io/objects/char/3045.cc new file mode 100644 index 000000000..9720e9634 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/3045.cc @@ -0,0 +1,77 @@ +// 2001-06-05 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/>. + + +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +class gnu_filebuf: public std::filebuf +{ + int i; +public: + gnu_filebuf(int j = 1): i(j) { } + ~gnu_filebuf() { --i; } + int get_i() { return i;} +}; + +const int initial = 4; +gnu_filebuf buf(initial); + +// libstdc++/3045, in a vague way. +void test01() +{ + bool test __attribute__((unused)) = true; + int k1; + + // 1 normal + k1 = buf.get_i(); + VERIFY( k1 == initial ); + { + std::cout.rdbuf(&buf); + } + k1 = buf.get_i(); + VERIFY( k1 == initial ); + + // 2 syncd off + k1 = buf.get_i(); + VERIFY( k1 == initial ); + { + std::cout.rdbuf(&buf); + std::ios_base::sync_with_stdio(false); // make sure doesn't clobber buf + } + k1 = buf.get_i(); + VERIFY( k1 == initial ); + + // 3 callling init + k1 = buf.get_i(); + VERIFY( k1 == initial ); + { + std::cout.rdbuf(&buf); + std::ios_base::Init make_sure_initialized; + } + k1 = buf.get_i(); + VERIFY( k1 == initial ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/3647.cc b/libstdc++-v3/testsuite/27_io/objects/char/3647.cc new file mode 100644 index 000000000..506fb3130 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/3647.cc @@ -0,0 +1,37 @@ +// 2002-01-08 bkoz + +// Copyright (C) 2002, 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.6.1.5 - Template class basic_iostream +// NB: This file is for testing iostream with NO OTHER INCLUDES. + +#include <iostream> + +// libstdc++/3647 +void test07() +{ + // Should not block. + std::cout << std::cin.rdbuf()->in_avail() << std::endl; +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/3_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/3_xin.cc new file mode 100644 index 000000000..b09f58b8c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/3_xin.cc @@ -0,0 +1,41 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// Interactive test, to be exercised as follows: +// run test under truss(1) or strace(1). Look at +// size and pattern of write system calls. +// Should be 2 or 3 write(1,[...]) calls when run interactively +// depending upon buffering mode enforced. +void test05() +{ + std::cout << "hello" << ' ' << "world" << std::endl; + std::cout << "Enter your name: "; + std::string s; + std::cin >> s; + std::cout << "hello " << s << std::endl; +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/3_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/3_xin.in new file mode 100644 index 000000000..a26c12687 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/3_xin.in @@ -0,0 +1 @@ +JOHN HUME and DAVID TRIMBLE diff --git a/libstdc++-v3/testsuite/27_io/objects/char/41037.cc b/libstdc++-v3/testsuite/27_io/objects/char/41037.cc new file mode 100644 index 000000000..a38221cab --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/41037.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// PR libstdc++/41037 +void test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::cerr.flags() & std::ios_base::dec ); + VERIFY( std::cerr.flags() & std::ios_base::skipws ); + VERIFY( std::cerr.flags() & std::ios_base::unitbuf ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/4_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/4_xin.cc new file mode 100644 index 000000000..dbeb9e049 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/4_xin.cc @@ -0,0 +1,38 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// http://gcc.gnu.org/ml/libstdc++/2002-08/msg00060.html +// Should only have to hit enter once. +void +test10() +{ + using namespace std; + cout << "Press ENTER once\n"; + cin.ignore(1); + cout << "_M_gcount: "<< cin.gcount() << endl; +} + +int +main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/4_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/4_xin.in new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/4_xin.in @@ -0,0 +1 @@ + diff --git a/libstdc++-v3/testsuite/27_io/objects/char/5.cc b/libstdc++-v3/testsuite/27_io/objects/char/5.cc new file mode 100644 index 000000000..c5bf54654 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/5.cc @@ -0,0 +1,84 @@ +// 2003-04-26 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2009 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 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.3 Standard iostream objects + +// Check that standard streams can be used from constructors and +// destructors of static objects, provided that an instance of +// ios_base::Init has been constructed. + +void init_standard_streams(); +int use_standard_streams(); + +struct Strange +{ + int i; + + Strange() + { + init_standard_streams(); + i = use_standard_streams(); + } + + ~Strange() + { + use_standard_streams(); + init_standard_streams(); + } +}; + +static Strange static_ob; + +#include <testsuite_hooks.h> +#include <iostream> + +void init_standard_streams() +{ + std::ios_base::Init init; +} + +int use_standard_streams() +{ + std::cout << "Hello, world!" << std::endl; + std::cerr << "World, hello!" << std::endl; + + int ret = std::ios_base::xalloc(); + std::cin.iword(ret) = ret + 1; + std::cout.iword(ret) = ret + 2; + std::cerr.iword(ret) = ret + 3; + std::clog.iword(ret) = ret + 4; + return ret; +} + +void test05() +{ + bool test __attribute__((unused)) = true; + int i = static_ob.i; + + VERIFY( std::cin.iword(i) == i + 1 ); + VERIFY( std::cout.iword(i) == i + 2 ); + VERIFY( std::cerr.iword(i) == i + 3 ); + VERIFY( std::clog.iword(i) == i + 4 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/5268.cc b/libstdc++-v3/testsuite/27_io/objects/char/5268.cc new file mode 100644 index 000000000..b7c0ac1df --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/5268.cc @@ -0,0 +1,37 @@ +// 2001-06-05 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/>. + + +#include <sstream> +#include <iostream> + +// libstdc++/5268 +void test04() +{ + std::stringbuf b1; + std::cout.rdbuf( &b1 ); + std::cout << "hello\n"; + std::cout.rdbuf(0); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/5280_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/5280_xin.cc new file mode 100644 index 000000000..791959e7d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/5280_xin.cc @@ -0,0 +1,47 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// libstdc++/5280 +// Interactive test: input "1234^D^D" for i should terminate for EOF. +void test06() +{ + using namespace std; + int i; + cin >> i; + if (!cin.good()) + { + cerr << endl; + cerr << "i == " << i << endl; + cerr << "cin.rdstate() == " << cin.rdstate() << endl; + cerr << "cin.bad() == " << cin.bad() << endl; + cerr << "cin.fail() == " << cin.fail() << endl; + cerr << "cin.eof() == " << cin.eof() << endl; + } + else + cerr << "i == " << i << endl; +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/5280_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/5280_xin.in new file mode 100644 index 000000000..274c0052d --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/5280_xin.in @@ -0,0 +1 @@ +1234
\ No newline at end of file diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6.cc b/libstdc++-v3/testsuite/27_io/objects/char/6.cc new file mode 100644 index 000000000..8cf2e8d22 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6.cc @@ -0,0 +1,59 @@ +// 2003-04-26 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2009 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 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.3 Standard iostream objects + +// ios_base::Init::~Init() calls cout.flush(), which may call +// cout.setstate(badbit), which may throw an exception. Check that +// the exception doesn't escape from the destructor. + +#include <iostream> +#include <streambuf> +#include <testsuite_hooks.h> + +class Badbuf : public std::streambuf +{ +protected: + virtual int sync() + { return -1; } +}; + +void test06() +{ + bool test __attribute__((unused)) = true; + + try + { + // No-op in current code. + std::ios_base::Init init; + std::cout.rdbuf(new Badbuf); + std::cout.exceptions(std::ios_base::badbit); + } + catch(...) + { + test = false; + } + VERIFY( test ); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6548_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/6548_xin.cc new file mode 100644 index 000000000..10cf7177c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6548_xin.cc @@ -0,0 +1,38 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// libstdc++/6548 +void test07() +{ + bool test __attribute__((unused)) = true; + std::cout << "Enter 'test':"; + std::string s; + std::getline(std::cin, s, '\n'); + VERIFY( s == "test" ); +} + +int +main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6548_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/6548_xin.in new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6548_xin.in @@ -0,0 +1 @@ +test diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6648-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/6648-1_xin.cc new file mode 100644 index 000000000..a69bdf5b3 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6648-1_xin.cc @@ -0,0 +1,37 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// libstdc++/6648 +// Interactive tests: each one (run alone) must terminate upon a single '\n'. +void test08() +{ + bool test __attribute__((unused)) = true; + char buff[2048]; + std::cout << "Enter name: "; + std::cin.getline(buff, 2048); +} + +int +main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6648-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/6648-1_xin.in new file mode 100644 index 000000000..9dd5f1f2e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6648-1_xin.in @@ -0,0 +1 @@ +Kofi A. Annan diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6648-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/6648-2_xin.cc new file mode 100644 index 000000000..a6b6e71f8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6648-2_xin.cc @@ -0,0 +1,34 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +void test09() +{ + bool test __attribute__((unused)) = true; + std::cout << "Enter favorite beach: "; + std::cin.ignore(2048, '\n'); +} + +int +main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/6648-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/6648-2_xin.in new file mode 100644 index 000000000..0b2c7cf28 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/6648-2_xin.in @@ -0,0 +1 @@ +Oak St. Beach, Chicago diff --git a/libstdc++-v3/testsuite/27_io/objects/char/7.cc b/libstdc++-v3/testsuite/27_io/objects/char/7.cc new file mode 100644 index 000000000..fcb6e21e9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/7.cc @@ -0,0 +1,86 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2003-04-26 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 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/>. + +// 27.3 Standard iostream objects + +#include <fstream> +#include <iostream> +#include <cstdlib> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphore if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +// Check that cout.flush() is called when last ios_base::Init is destroyed. +bool test07() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo4"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + filebuf fbout; + fbout.open(name, ios_base::in|ios_base::out); + VERIFY( fbout.is_open() ); + s1.wait(); + cout.rdbuf(&fbout); + fbout.sputc('a'); + // NB: fbout is *not* destroyed here! + exit(0); + } + + filebuf fbin; + fbin.open(name, ios_base::in); + s1.signal(); + filebuf::int_type c = fbin.sbumpc(); + VERIFY( c != filebuf::traits_type::eof() ); + VERIFY( c == filebuf::traits_type::to_int_type('a') ); + + fbin.close(); + + return test; +} + +int +main() +{ + return !test07(); +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/7744_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/7744_xin.cc new file mode 100644 index 000000000..b2577f9bf --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/7744_xin.cc @@ -0,0 +1,41 @@ +// 2000-08-02 bkoz + +// Copyright (C) 2000, 2001, 2002, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// libstdc++/7744 +void test11() +{ + bool test __attribute__((unused)) = true; + std::ios::sync_with_stdio(false); + + std::cout << "Type in the characters 'abc' and press <ENTER>: "; + std::cin.peek(); + + // The number of unread characters should be 4 (a, b, c, \\n) + VERIFY( 4 == std::cin.rdbuf()->in_avail() ); +} + +int +main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/7744_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/7744_xin.in new file mode 100644 index 000000000..8baef1b4a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/7744_xin.in @@ -0,0 +1 @@ +abc diff --git a/libstdc++-v3/testsuite/27_io/objects/char/8.cc b/libstdc++-v3/testsuite/27_io/objects/char/8.cc new file mode 100644 index 000000000..8c22690f7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/8.cc @@ -0,0 +1,50 @@ +// 2003-04-28 Benjamin Kosnik <bkoz@redhat.com> + +// Copyright (C) 2003, 2009 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 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.3 - Standard iostream objects p 2 + +#include <iostream> +#include <testsuite_hooks.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + + // 27.3 - Standard iostream objects p 2 + // The objects are not destroyed during program execution. + void* p1 = &std::cout; + void* p2 = &std::cin; + void* p3 = &std::cerr; + void* p4 = &std::clog; + std::ios_base::sync_with_stdio(false); + void* p1s = &std::cout; + void* p2s = &std::cin; + void* p3s = &std::cerr; + void* p4s = &std::clog; + VERIFY( p1 == p1s ); + VERIFY( p2 == p2s ); + VERIFY( p3 == p3s ); + VERIFY( p4 == p4s ); +} + +int main(void) +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9.cc b/libstdc++-v3/testsuite/27_io/objects/char/9.cc new file mode 100644 index 000000000..e4905bb46 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/9.cc @@ -0,0 +1,48 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// { dg-require-fileio "" } + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void test09() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_09"; + + FILE* fout = fopen(name, "w"); + fputs("abc\n", fout); + fclose(fout); + + VERIFY( freopen(name, "r", stdin) ); + + // basic_streambuf::showmanyc returns 0. + VERIFY( 0 == std::cin.rdbuf()->in_avail() ); +} + +int +main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc b/libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc new file mode 100644 index 000000000..8ca77c76e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc @@ -0,0 +1,99 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2003-04-30 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 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/>. + +// No asserts, avoid leaking the semaphores if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> +#include <cstdio> +#include <cstdlib> +#include <iostream> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// Check that cin.rdbuf()->sputbackc() puts characters back to stdin. +// If cin.rdbuf() is a filebuf, this succeeds when stdin is a regular +// file, but fails otherwise, hence the named fifo. +bool test01() +{ + using namespace std; + using namespace __gnu_test; + + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo5"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1, s2; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + FILE* file = fopen(name, "r+"); + VERIFY( file != 0 ); + fputs("Whatever\n", file); + fflush(file); + s1.signal(); + s2.wait(); + fclose(file); + s1.signal(); + exit(0); + } + + VERIFY( freopen(name, "r", stdin) ); + s1.wait(); + + int c1 = fgetc(stdin); + VERIFY( c1 != EOF ); + int c2 = cin.rdbuf()->sputbackc('a'); + VERIFY( c2 != EOF ); + VERIFY( c2 == 'a' ); + + int c3 = fgetc(stdin); + VERIFY( c3 != EOF ); + VERIFY( c3 == c2 ); + int c4 = ungetc('b', stdin); + VERIFY( c4 != EOF ); + VERIFY( c4 == 'b' ); + + int c5 = cin.rdbuf()->sgetc(); + VERIFY( c5 != EOF ); + VERIFY( c5 == c4 ); + s2.signal(); + s1.wait(); + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.cc new file mode 100644 index 000000000..f91f9508e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.cc @@ -0,0 +1,46 @@ +// 2003-04-30 Petur Runolfsson <peturr02@ru.is> + +// 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/>. + +#include <testsuite_hooks.h> +#include <cstdio> +#include <iostream> + +void test02() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + + int c1 = fgetc(stdin); + int c2 = cin.rdbuf()->sputbackc(c1); + VERIFY( c2 == c1 ); + + int c3 = fgetc(stdin); + VERIFY( c3 == c1 ); + ungetc(c3, stdin); + + int c4 = cin.rdbuf()->sgetc(); + VERIFY( c4 == c3 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.in new file mode 100644 index 000000000..ad9013028 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/9661-2_xin.in @@ -0,0 +1 @@ +For what you dream of diff --git a/libstdc++-v3/testsuite/27_io/objects/char/dr455.cc b/libstdc++-v3/testsuite/27_io/objects/char/dr455.cc new file mode 100644 index 000000000..ac464eca7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/dr455.cc @@ -0,0 +1,36 @@ +// 2006-03-08 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// DR 455. cerr::tie() and wcerr::tie() are overspecified. +void test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::cerr.tie() == &std::cout ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/1.cc new file mode 100644 index 000000000..d05762d89 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/1.cc @@ -0,0 +1,100 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Include all the headers except for iostream. +#include <algorithm> +#include <bitset> +#include <complex> +#include <deque> +#include <exception> +#include <fstream> +#include <functional> +#include <iomanip> +#include <ios> +#include <iosfwd> +#include <istream> +#include <iterator> +#include <limits> +#include <list> +#include <locale> +#include <map> +#include <memory> +#include <new> +#include <numeric> +#include <ostream> +#include <queue> +#include <set> +#include <sstream> +#include <stack> +#include <stdexcept> +#include <streambuf> +#include <string> +#include <typeinfo> +#include <utility> +#include <valarray> +#include <vector> +#include <cassert> +#include <cctype> +#include <cerrno> +#include <cfloat> +#include <ciso646> +#include <climits> +#include <clocale> +#include <cmath> +#include <csetjmp> +#include <csignal> +#include <cstdarg> +#include <cstddef> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctime> +#include <cwchar> +#include <cwctype> +#include <testsuite_hooks.h> + +// Include iostream last, just to make is as difficult as possible to +// properly initialize the standard iostream objects. +#include <iostream> + +// Make sure all the standard streams are defined. +void +test01() +{ + bool test __attribute__((unused)) = true; + + wchar_t array2[20]; + typedef std::wios::traits_type wtraits_type; + wtraits_type::int_type wi = 15; + wtraits_type::copy(array2, L"testing istream", wi); + std::wcout << L"testing wcout" << std::endl; + std::wcerr << L"testing wcerr" << std::endl; + VERIFY( std::wcerr.flags() & std::ios_base::unitbuf ); + std::wclog << L"testing wclog" << std::endl; + // std::wcin >> array2; // requires somebody to type something in. + VERIFY( std::wcin.tie() == &std::wcout ); +} + + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc new file mode 100644 index 000000000..1030e75be --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/10.cc @@ -0,0 +1,115 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 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/>. + +#include <iostream> +#include <cstdio> +#include <cstring> +#include <testsuite_hooks.h> + +// Test handling of UTF-8 in wcin +void test10() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_10"; + + locale loc(locale("se_NO.UTF-8")); + locale::global(loc); + wcin.imbue(loc); + wcout.imbue(loc); + + const char* e_lit = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + size_t e_size = strlen(e_lit); + + const wchar_t i_lit[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + size_t i_size = wcslen(i_lit); + + FILE* file = fopen(name, "w"); + size_t n = fwrite(e_lit, 1, e_size, file); + VERIFY( n == e_size ); + fclose(file); + + VERIFY( freopen(name, "r", stdin) ); + + wchar_t* wbuf = new wchar_t[i_size + 10]; + wcin.read(wbuf, i_size + 10); + n = wcin.gcount(); + VERIFY( n == i_size ); + VERIFY( !wmemcmp(wbuf, i_lit, i_size) ); + VERIFY( wcin.eof() ); + VERIFY( wcin.fail() ); + VERIFY( !wcin.bad() ); + delete[] wbuf; +} + +int main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/11.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/11.cc new file mode 100644 index 000000000..7799591f4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/11.cc @@ -0,0 +1,112 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 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/>. + +#include <iostream> +#include <cstdio> +#include <cstring> +#include <testsuite_hooks.h> + +// Test handling of UTF-8 in wcout +void test11() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_11"; + + locale loc(locale("se_NO.UTF-8")); + locale::global(loc); + wcin.imbue(loc); + wcout.imbue(loc); + + const char* e_lit = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + size_t e_size = strlen(e_lit); + + const wchar_t i_lit[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + size_t i_size = wcslen(i_lit); + + VERIFY( freopen(name, "w", stdout) ); + + wcout.write(i_lit, i_size); + wcout.flush(); + VERIFY( wcout.good() ); + + FILE* file = fopen(name, "r"); + char* buf = new char[e_size + 10]; + size_t n = fread(buf, 1, e_size + 10, file); + VERIFY( n == e_size ); + VERIFY( !memcmp(buf, e_lit, e_size) ); + delete[] buf; + fclose(file); +} + +int main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12.cc new file mode 100644 index 000000000..e94abdd62 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12.cc @@ -0,0 +1,122 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 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/>. + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include <iostream> +#include <cstdio> +#include <cstring> +#include <testsuite_hooks.h> + +// Test handling of UTF-8 in wcout +void test12() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_12"; + + locale loc(locale("se_NO.UTF-8")); + locale::global(loc); + std::ios_base::sync_with_stdio(false); + wcout.imbue(loc); + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + int fd = open(name, + O_WRONLY | O_CREAT | O_TRUNC, + 0666); + VERIFY( fd != -1 ); + VERIFY( dup2(fd, 1) == 1 ); + close(fd); + + wcout.write(wstr, wlen); + wcout.flush(); + VERIFY( wcout.good() ); + + FILE* file = fopen(name, "r"); + char buf[clen + 10]; + size_t n = fread(buf, 1, clen + 10, file); + VERIFY( n == clen ); + VERIFY( !memcmp(buf, cstr, clen) ); + fclose(file); +} + +int main() +{ + test12(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc new file mode 100644 index 000000000..58a40ce91 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc @@ -0,0 +1,44 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + wchar_t c1; + wchar_t c2; + std::wcin.get(c1); + std::wcin.unget(); + std::wcin.get(c2); + VERIFY( std::wcin.good() ); + VERIFY( c1 == c2 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc new file mode 100644 index 000000000..7eaef212f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc @@ -0,0 +1,41 @@ +// 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/>. + +#include <iostream> +#include <cstdio> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + wchar_t c1; + std::wint_t c2; + std::wcin.get(c1); + std::wcin.unget(); + VERIFY( std::wcin.good() ); + c2 = std::fgetwc(stdin); + VERIFY( c2 == std::char_traits<wchar_t>::to_int_type(c1) ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc new file mode 100644 index 000000000..8e236ab30 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc @@ -0,0 +1,44 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 +// Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <cwchar> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + wchar_t buf[2]; + VERIFY( std::wcin.rdbuf()->sgetn(buf, 2) == 2 ); + std::wint_t c1 = std::wcin.rdbuf()->sungetc(); + std::wint_t c2 = std::wcin.rdbuf()->sbumpc(); + VERIFY( c1 == std::char_traits<wchar_t>::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc new file mode 100644 index 000000000..3649e7e22 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc @@ -0,0 +1,40 @@ +// 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/>. + +#include <iostream> +#include <cstdio> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + wchar_t buf[2]; + VERIFY( std::wcin.rdbuf()->sgetn(buf, 2) == 2 ); + wint_t c1 = std::wcin.rdbuf()->sungetc(); + wint_t c2 = std::fgetwc(stdin); + VERIFY( c1 == std::char_traits<wchar_t>::to_int_type(buf[1]) ); + VERIFY( c2 == c1 ); +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc new file mode 100644 index 000000000..49486e3c4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc @@ -0,0 +1,52 @@ +// 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/>. + +// DR 49 states that cin.rdbuf()->sbumpc() and fgetc(stdin) should be +// equivalent and interchangable. Currently however, cin.rdbuf()->sungetc() +// only returns characters that were read with cin.rdbuf()->sbumpc() + +// { dg-do run { xfail *-*-* } } + +#include <iostream> +#include <cstdio> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + VERIFY( std::freopen("cin_unget-1.txt", "r", stdin) ); + + wchar_t c1; + std::wint_t c2; + wchar_t c3; + std::wcin.get(c1); + c2 = std::fgetwc(stdin); + std::wcin.unget(); + if (std::wcin.good()) + { + std::wcin.get(c3); + VERIFY( std::wcin.good() ); + VERIFY( c3 == std::char_traits<wchar_t>::to_char_type(c2) ); + } +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/13.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/13.cc new file mode 100644 index 000000000..43b660246 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/13.cc @@ -0,0 +1,119 @@ +// { dg-require-namedlocale "se_NO.UTF-8" } + +// 2003-09-04 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <unistd.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +// Test handling of UTF-8 in wcin +void test13() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_13"; + + locale loc(locale("se_NO.UTF-8")); + locale::global(loc); + std::ios_base::sync_with_stdio(false); + wcin.imbue(loc); + + const char cstr[] = + "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10\x11\x12\x13" + "\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20!\"#$%&" + "'()*+,-./0123456789:;<=>?@}~\x7f\xc2\x80\xc2\x81\xc2\x82\xc2" + "\x83\xc2\x84\xc2\x85\xc2\x86\xc2\x87\xc2\x88\xc2\x89\xc2\x8a" + "\xc2\x8b\xc2\x8c\xc2\x8d\xc2\x8e\xc2\x8f\xc2\x90\xc2\x91\xc2" + "\x92\xc2\x93\xc2\x94\xc2\x95\xc2\x96\xc2\x97\xc2\x98\xc2\x99" + "\xc2\x9a\xc2\x9b\xc2\x9c\xc3\xba\xc3\xbb\xc3\xbc\xc3\xbd\xc3" + "\xbe\xc3\xbf\xc4\x80\xc4\x81\xc4\x82\xc4\x83\xc4\x84\xc4\x85" + "\xc4\x86\xc4\x87\xc4\x88\xc4\x89\xc4\x8a\xc4\x8b\xc4\x8c\xc4" + "\x8d\xc4\x8e\xc4\x8f\xc4\x90\xc4\x91\xc4\x92\xc4\x93\xc4\x94" + "\xc4\x95\xc4\x96\xc4\x97\xc4\x98\xc4\x99\xdf\xb8\xdf\xb9\xdf" + "\xba\xdf\xbb\xdf\xbc\xdf\xbd\xdf\xbe\xdf\xbf\xe0\xa0\x80\xe0" + "\xa0\x81\xe0\xa0\x82\xe0\xa0\x83\xe0\xa0\x84\xe0\xa0\x85\xe0" + "\xa0\x86\xe0\xa0\x87\xe0\xa0\x88\xe0\xa0\x89\xe0\xa0\x8a\xe0" + "\xa0\x8b\xe0\xa0\x8c\xe0\xa0\x8d\xe0\xa0\x8e\xe0\xa0\x8f\xe0" + "\xa0\x90\xe0\xa0\x91\xe0\xa0\x92\xe0\xa0\x93\xe0\xa0\x94\xe0" + "\xa0\x95\xe0\xa0\x96\xe0\xa0\x97\x1\x2\x4\x8\x10\x20@\xc2\x80" + "\xc4\x80\xc8\x80\xd0\x80\xe0\xa0\x80\xe1\x80\x80\xe2\x80\x80" + "\xe4\x80\x80\xe8\x80\x80\xf0\x90\x80\x80\xf0\xa0\x80\x80\xf1" + "\x80\x80\x80\xf2\x80\x80\x80\xf4\x80\x80\x80\xf8\x88\x80\x80" + "\x80\xf8\x90\x80\x80\x80\xf8\xa0\x80\x80\x80\xf9\x80\x80\x80" + "\x80\xfa\x80\x80\x80\x80\xfc\x84\x80\x80\x80\x80\xfc\x88\x80" + "\x80\x80\x80\xfc\x90\x80\x80\x80\x80\xfc\xa0\x80\x80\x80\x80" + "\xfd\x80\x80\x80\x80\x80"; + + const wchar_t wstr[] = { + 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, + 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, L'!', + L'"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'*', L'+', + L',', L'-', L'.', L'/', L'0', L'1', L'2', L'3', L'4', L'5', + L'6', L'7', L'8', L'9', L':', L';', L'<', L'=', L'>', L'?', + L'@', L'}', L'~', 0x7f, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, + 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, + 0x9a, 0x9b, 0x9c, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x100, + 0x101, 0x102, 0x103, 0x104, 0x105, 0x106, 0x107, 0x108, 0x109, + 0x10a, 0x10b, 0x10c, 0x10d, 0x10e, 0x10f, 0x110, 0x111, 0x112, + 0x113, 0x114, 0x115, 0x116, 0x117, 0x118, 0x119, 0x7f8, 0x7f9, + 0x7fa, 0x7fb, 0x7fc, 0x7fd, 0x7fe, 0x7ff, 0x800, 0x801, 0x802, + 0x803, 0x804, 0x805, 0x806, 0x807, 0x808, 0x809, 0x80a, 0x80b, + 0x80c, 0x80d, 0x80e, 0x80f, 0x810, 0x811, 0x812, 0x813, 0x814, + 0x815, 0x816, 0x817, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, L'@', + 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000, + 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, + 0x800000, 0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, + 0x20000000, 0x40000000, 0x0 + }; + + const size_t clen = sizeof(cstr) / sizeof(cstr[0]); + const size_t wlen = sizeof(wstr) / sizeof(wstr[0]); + + FILE* file = fopen(name, "w"); + fwrite(cstr, 1, clen, file); + fclose(file); + + int fd = open(name, O_RDONLY); + dup2(fd, 0); + close(fd); + + wchar_t wbuf[wlen + 10]; + wcin.read(wbuf, wlen + 10); + streamsize n = wcin.gcount(); + VERIFY( n == static_cast<streamsize>(wlen) ); + VERIFY( !wmemcmp(wbuf, wstr, wlen) ); + VERIFY( wcin.eof() ); + VERIFY( wcin.fail() ); + VERIFY( !wcin.bad() ); +} + +int main() +{ + test13(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/13582-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/13582-1_xin.cc new file mode 100644 index 000000000..44a6ca5b8 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/13582-1_xin.cc @@ -0,0 +1,60 @@ +// 2004-01-11 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2004, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <string> +#include <locale> + +// libstdc++/13582 +void test01() +{ + bool test __attribute__((unused)) = true; + using namespace std; + + ios_base::sync_with_stdio(false); + wcout << "Type in 12345\n"; + + wstring str; + wchar_t c; + + if (wcin.get(c) && !isspace(c, wcin.getloc())) + { + str.push_back(c); + wcin.imbue(locale("en_US")); + } + + if (wcin.get(c) && !isspace(c, wcin.getloc())) + { + str.push_back(c); + wcin.imbue(locale("fr_FR")); + } + + while (wcin.get(c) && !isspace(c, wcin.getloc())) + { + str.push_back(c); + } + + wcout << str << endl; +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/13582-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/13582-1_xin.in new file mode 100644 index 000000000..e56e15bb7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/13582-1_xin.in @@ -0,0 +1 @@ +12345 diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2.cc new file mode 100644 index 000000000..b5b8c4e7c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2.cc @@ -0,0 +1,46 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// Interactive test, to be exercised as follows: +// assign stderr to stdout in shell command line, +// pipe stdout to cat process and/or redirect stdout to file. +// a.out >& output +// "hello fine world\n" should be written to stdout, and output, in +// proper order. This is a version of the scott snyder test taken +// from: http://gcc.gnu.org/ml/libstdc++/1999-q4/msg00108.html +void test04() +{ + using namespace std; + + wcout << L"hello "; + wcout.flush(); + wcerr << L"fine "; + wcerr.flush(); + wcout << L"world" << endl; + wcout.flush(); +} + +int +main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.cc new file mode 100644 index 000000000..d423ceb30 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.cc @@ -0,0 +1,88 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +// Include all the headers except for iostream. +#include <algorithm> +#include <bitset> +#include <complex> +#include <deque> +#include <exception> +#include <fstream> +#include <functional> +#include <iomanip> +#include <ios> +#include <iosfwd> +#include <istream> +#include <iterator> +#include <limits> +#include <list> +#include <locale> +#include <map> +#include <memory> +#include <new> +#include <numeric> +#include <ostream> +#include <queue> +#include <set> +#include <sstream> +#include <stack> +#include <stdexcept> +#include <streambuf> +#include <string> +#include <typeinfo> +#include <utility> +#include <valarray> +#include <vector> +#include <cassert> +#include <cctype> +#include <cerrno> +#include <cfloat> +#include <ciso646> +#include <climits> +#include <clocale> +#include <cmath> +#include <csetjmp> +#include <csignal> +#include <cstdarg> +#include <cstddef> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <ctime> +#include <testsuite_hooks.h> + +// Include iostream last, just to make is as difficult as possible to +// properly initialize the standard iostream objects. +#include <iostream> + +// libstdc++/2523 +void test02() +{ + using namespace std; + int i; + wcin >> i; + wcout << "i == " << i << endl; +} + +int +main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.in new file mode 100644 index 000000000..ec308096e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-1_xin.in @@ -0,0 +1 @@ +5588885 diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.cc new file mode 100644 index 000000000..2697e78e5 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.cc @@ -0,0 +1,38 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// libstdc++/2523 +void test03() +{ + using namespace std; + ios_base::sync_with_stdio(false); + + int i; + wcin >> i; + wcout << "i == " << i << endl; +} + +int +main() +{ + test03(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.in new file mode 100644 index 000000000..aaee5e562 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/2523-2_xin.in @@ -0,0 +1 @@ +33332 diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3045.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3045.cc new file mode 100644 index 000000000..9cec1b143 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3045.cc @@ -0,0 +1,77 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// 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/>. + + +#include <fstream> +#include <iostream> +#include <testsuite_hooks.h> + +class gnu_filebuf: public std::wfilebuf +{ + int i; +public: + gnu_filebuf(int j = 1): i(j) { } + ~gnu_filebuf() { --i; } + int get_i() { return i;} +}; + +const int initial = 4; +gnu_filebuf buf(initial); + +// libstdc++/3045, in a vague way. +void test01() +{ + bool test __attribute__((unused)) = true; + int k1; + + // 1 normal + k1 = buf.get_i(); + VERIFY( k1 == initial ); + { + std::wcout.rdbuf(&buf); + } + k1 = buf.get_i(); + VERIFY( k1 == initial ); + + // 2 syncd off + k1 = buf.get_i(); + VERIFY( k1 == initial ); + { + std::wcout.rdbuf(&buf); + std::ios_base::sync_with_stdio(false); // make sure doesn't clobber buf + } + k1 = buf.get_i(); + VERIFY( k1 == initial ); + + // 3 callling init + k1 = buf.get_i(); + VERIFY( k1 == initial ); + { + std::wcout.rdbuf(&buf); + std::ios_base::Init make_sure_initialized; + } + k1 = buf.get_i(); + VERIFY( k1 == initial ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3647.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3647.cc new file mode 100644 index 000000000..1aff3f74b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3647.cc @@ -0,0 +1,37 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 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.6.1.5 - Template class basic_iostream +// NB: This file is for testing iostream with NO OTHER INCLUDES. + +#include <iostream> + +// libstdc++/3647 +void test07() +{ + // Should not block. + std::wcout << std::wcin.rdbuf()->in_avail() << std::endl; +} + +int main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.cc new file mode 100644 index 000000000..c481373be --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.cc @@ -0,0 +1,41 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// Interactive test, to be exercised as follows: +// run test under truss(1) or strace(1). Look at +// size and pattern of write system calls. +// Should be 2 or 3 write(1,[...]) calls when run interactively +// depending upon buffering mode enforced. +void test05() +{ + std::wcout << L"hello" << L' ' << L"world" << std::endl; + std::wcout << L"Enter your name: "; + std::wstring s; + std::wcin >> s; + std::wcout << L"hello " << s << std::endl; +} + +int +main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.in new file mode 100644 index 000000000..a26c12687 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/3_xin.in @@ -0,0 +1 @@ +JOHN HUME and DAVID TRIMBLE diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/41037.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/41037.cc new file mode 100644 index 000000000..b3c01a0b7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/41037.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// PR libstdc++/41037 +void test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::wcerr.flags() & std::ios_base::dec ); + VERIFY( std::wcerr.flags() & std::ios_base::skipws ); + VERIFY( std::wcerr.flags() & std::ios_base::unitbuf ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.cc new file mode 100644 index 000000000..0e4f9ca18 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.cc @@ -0,0 +1,38 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// http://gcc.gnu.org/ml/libstdc++/2002-08/msg00060.html +// Should only have to hit enter once. +void +test10() +{ + using namespace std; + wcout << L"Press ENTER once\n"; + wcin.ignore(1); + wcout << L"_M_gcount: " << wcin.gcount() << endl; +} + +int +main() +{ + test10(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.in new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/4_xin.in @@ -0,0 +1 @@ + diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5.cc new file mode 100644 index 000000000..4bafef34e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5.cc @@ -0,0 +1,84 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2009 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 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.3 Standard iostream objects + +// Check that standard streams can be used from constructors and +// destructors of static objects, provided that an instance of +// ios_base::Init has been constructed. + +void init_standard_streams(); +int use_standard_streams(); + +struct Strange +{ + int i; + + Strange() + { + init_standard_streams(); + i = use_standard_streams(); + } + + ~Strange() + { + use_standard_streams(); + init_standard_streams(); + } +}; + +static Strange static_ob; + +#include <testsuite_hooks.h> +#include <iostream> + +void init_standard_streams() +{ + std::ios_base::Init init; +} + +int use_standard_streams() +{ + std::wcout << L"Hello, world!" << std::endl; + std::wcerr << L"World, hello!" << std::endl; + + int ret = std::ios_base::xalloc(); + std::wcin.iword(ret) = ret + 1; + std::wcout.iword(ret) = ret + 2; + std::wcerr.iword(ret) = ret + 3; + std::wclog.iword(ret) = ret + 4; + return ret; +} + +void test05() +{ + bool test __attribute__((unused)) = true; + int i = static_ob.i; + + VERIFY( std::wcin.iword(i) == i + 1 ); + VERIFY( std::wcout.iword(i) == i + 2 ); + VERIFY( std::wcerr.iword(i) == i + 3 ); + VERIFY( std::wclog.iword(i) == i + 4 ); +} + +int main() +{ + test05(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5268.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5268.cc new file mode 100644 index 000000000..04571cc63 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5268.cc @@ -0,0 +1,37 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// 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/>. + + +#include <sstream> +#include <iostream> + +// libstdc++/5268 +void test04() +{ + std::wstringbuf b1; + std::wcout.rdbuf( &b1 ); + std::wcout << L"hello\n"; + std::wcout.rdbuf(0); +} + +int main() +{ + test04(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.cc new file mode 100644 index 000000000..18d33855f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.cc @@ -0,0 +1,47 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// libstdc++/5280 +// Interactive test: input "1234^D^D" for i should terminate for EOF. +void test06() +{ + using namespace std; + int i; + wcin >> i; + if (!wcin.good()) + { + wcerr << endl; + wcerr << L"i == " << i << endl; + wcerr << L"wcin.rdstate() == " << wcin.rdstate() << endl; + wcerr << L"wcin.bad() == " << wcin.bad() << endl; + wcerr << L"wcin.fail() == " << wcin.fail() << endl; + wcerr << L"wcin.eof() == " << wcin.eof() << endl; + } + else + wcerr << L"i == " << i << endl; +} + +int +main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.in new file mode 100644 index 000000000..81c545efe --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/5280_xin.in @@ -0,0 +1 @@ +1234 diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6.cc new file mode 100644 index 000000000..d3de3e899 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6.cc @@ -0,0 +1,49 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2009 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 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.3 Standard iostream objects + +// ios_base::Init::~Init() calls wcout.flush(), which may call +// wcout.setstate(badbit), which may throw an exception. Check that +// the exception doesn't escape from the destructor. + +#include <iostream> +#include <streambuf> + +class Badbuf : public std::wstreambuf +{ +protected: + virtual int sync() + { + return -1; + } +}; + +void test06() +{ + std::ios_base::Init init; + std::wcout.rdbuf(new Badbuf); + std::wcout.exceptions(std::ios_base::badbit); +} + +int main() +{ + test06(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.cc new file mode 100644 index 000000000..1a6588681 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.cc @@ -0,0 +1,38 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// libstdc++/6548 +void test07() +{ + bool test __attribute__((unused)) = true; + std::wcout << L"Enter 'test':"; + std::wstring s; + std::getline(std::wcin, s, L'\n'); + VERIFY( s == L"test" ); +} + +int +main() +{ + test07(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.in new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6548_xin.in @@ -0,0 +1 @@ +test diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.cc new file mode 100644 index 000000000..5a3adf410 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.cc @@ -0,0 +1,37 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +// libstdc++/6648 +// Interactive tests: each one (run alone) must terminate upon a single '\n'. +void test08() +{ + bool test __attribute__((unused)) = true; + wchar_t buff[2048]; + std::wcout << "Enter name: "; + std::wcin.getline(buff, 2048); +} + +int +main() +{ + test08(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.in new file mode 100644 index 000000000..9dd5f1f2e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-1_xin.in @@ -0,0 +1 @@ +Kofi A. Annan diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.cc new file mode 100644 index 000000000..7f89a035b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.cc @@ -0,0 +1,34 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> + +void test09() +{ + bool test __attribute__((unused)) = true; + std::wcout << L"Enter favorite beach: "; + std::wcin.ignore(2048, '\n'); +} + +int +main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.in new file mode 100644 index 000000000..0b2c7cf28 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/6648-2_xin.in @@ -0,0 +1 @@ +Oak St. Beach, Chicago diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc new file mode 100644 index 000000000..33e74617a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc @@ -0,0 +1,85 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 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/>. + +// 27.3 Standard iostream objects + +#include <fstream> +#include <iostream> +#include <cstdlib> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// No asserts, avoid leaking the semaphore if a VERIFY fails. +#undef _GLIBCXX_ASSERT + +#include <testsuite_hooks.h> + +// Check that wcout.flush() is called when last ios_base::Init is destroyed. +bool test07() +{ + using namespace std; + using namespace __gnu_test; + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo4"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + wfilebuf fbout; + fbout.open(name, ios_base::out); + s1.wait(); + wcout.rdbuf(&fbout); + fbout.sputc(L'a'); + // NB: fbout is *not* destroyed here! + exit(0); + } + + wfilebuf fbin; + fbin.open(name, ios_base::in); + s1.signal(); + wfilebuf::int_type c = fbin.sbumpc(); + VERIFY( c != wfilebuf::traits_type::eof() ); + VERIFY( c == wfilebuf::traits_type::to_int_type(L'a') ); + + fbin.close(); + + return test; +} + +int +main() +{ + return !test07(); +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.cc new file mode 100644 index 000000000..839adae5f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.cc @@ -0,0 +1,41 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2000, 2001, 2002, 2003, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// libstdc++/7744 +void test11() +{ + bool test __attribute__((unused)) = true; + std::ios::sync_with_stdio(false); + + std::wcout << "Type in the characters 'abc' and press <ENTER>: "; + std::wcin.peek(); + + // The number of unread characters should be 4 (a, b, c, \\n) + VERIFY( 4 == std::wcin.rdbuf()->in_avail() ); +} + +int +main() +{ + test11(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.in new file mode 100644 index 000000000..8baef1b4a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/7744_xin.in @@ -0,0 +1 @@ +abc diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/8.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/8.cc new file mode 100644 index 000000000..852a020f0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/8.cc @@ -0,0 +1,50 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2009 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 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.3 - Standard iostream objects p 2 + +#include <iostream> +#include <testsuite_hooks.h> + +void test02() +{ + bool test __attribute__((unused)) = true; + + // 27.3 - Standard iostream objects p 2 + // The objects are not destroyed during program execution. + void* p1 = &std::wcout; + void* p2 = &std::wcin; + void* p3 = &std::wcerr; + void* p4 = &std::wclog; + std::ios_base::sync_with_stdio(false); + void* p1s = &std::wcout; + void* p2s = &std::wcin; + void* p3s = &std::wcerr; + void* p4s = &std::wclog; + VERIFY( p1 == p1s ); + VERIFY( p2 == p2s ); + VERIFY( p3 == p3s ); + VERIFY( p4 == p4s ); +} + +int main(void) +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc new file mode 100644 index 000000000..717bbc12a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9520.cc @@ -0,0 +1,58 @@ +// { dg-require-namedlocale "de_DE.ISO-8859-15@euro" } + +// 2003-04-30 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <testsuite_hooks.h> +#include <iostream> +#include <cstdio> + +void test01() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + const char* name = "tmp_9520"; + + FILE* file = fopen(name, "w"); + for (int i = 1; i < 256; ++i) + putc(static_cast<unsigned char>(i), file); + fclose(file); + + locale loc (locale("de_DE.ISO-8859-15@euro")); + locale::global(loc); // Set locale for stdin + + VERIFY( freopen(name, "r", stdin) ); + + wcin.imbue(loc); + + for (int j = 1; j < 256; ++j) + { + wint_t c1 = wcin.rdbuf()->sgetc(); + VERIFY( c1 != WEOF ); + wint_t c2 = wcin.rdbuf()->sbumpc(); + VERIFY( c1 == c2 ); + } +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc new file mode 100644 index 000000000..ca470dac9 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc @@ -0,0 +1,98 @@ +// { dg-require-fork "" } +// { dg-require-mkfifo "" } + +// 2003-04-30 Petur Runolfsson <peturr02@ru.is> + +// Copyright (C) 2003, 2004, 2005, 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 <cstdio> +#include <cstdlib> +#include <iostream> +#include <unistd.h> +#include <signal.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> + +// Check that wcin.rdbuf()->sputbackc() puts characters back to stdin. +// If wcin.rdbuf() is a filebuf, this succeeds when stdin is a regular +// file, but fails otherwise, hence the named fifo. +bool test01() +{ + using namespace std; + using namespace __gnu_test; + + bool test __attribute__((unused)) = true; + + const char* name = "tmp_fifo5"; + + signal(SIGPIPE, SIG_IGN); + + unlink(name); + mkfifo(name, S_IRWXU); + semaphore s1, s2; + + int child = fork(); + VERIFY( child != -1 ); + + if (child == 0) + { + FILE* file = fopen(name, "w"); + fputs("Whatever\n", file); + fflush(file); + s1.signal(); + s2.wait(); + fclose(file); + s1.signal(); + exit(0); + } + + VERIFY( freopen(name, "r", stdin) ); + s1.wait(); + + wint_t c1 = fgetwc(stdin); + VERIFY( c1 != WEOF ); + wint_t c2 = wcin.rdbuf()->sputbackc(L'a'); + VERIFY( c2 != WEOF ); + VERIFY( c2 == L'a' ); + + wint_t c3 = fgetwc(stdin); + VERIFY( c3 != WEOF ); + VERIFY( c3 == c2 ); + wint_t c4 = ungetwc(L'b', stdin); + VERIFY( c4 != WEOF ); + VERIFY( c4 == L'b' ); + + wint_t c5 = wcin.rdbuf()->sgetc(); + VERIFY( c5 != WEOF ); + VERIFY( c5 == c4 ); + s2.signal(); + s1.wait(); + + return test; +} + +int main() +{ + return !test01(); +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.cc new file mode 100644 index 000000000..ee3732b2e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.cc @@ -0,0 +1,47 @@ +// 2003-04-30 Petur Runolfsson <peturr02@ru.is> + +// 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/>. + +#include <testsuite_hooks.h> +#include <cstdio> +#include <iostream> +#include <cwchar> + +void test02() +{ + using namespace std; + + bool test __attribute__((unused)) = true; + + wint_t c1 = fgetwc(stdin); + wint_t c2 = wcin.rdbuf()->sputbackc(c1); + VERIFY( c2 == c1 ); + + wint_t c3 = fgetwc(stdin); + VERIFY( c3 == c1 ); + ungetwc(c3, stdin); + + wint_t c4 = wcin.rdbuf()->sgetc(); + VERIFY( c4 == c3 ); +} + +int main() +{ + test02(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.in new file mode 100644 index 000000000..ad9013028 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-2_xin.in @@ -0,0 +1 @@ +For what you dream of diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9662.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9662.cc new file mode 100644 index 000000000..425f7db75 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9662.cc @@ -0,0 +1,41 @@ +// 2003-04-30 Petur Runolfsson <peturr02@ru.is> + +// 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/>. + +#include <testsuite_hooks.h> +#include <iostream> +#include <cstdio> +#include <cwchar> + +// Check that operations on wcout can be mixed with wide operations +// on stdout. +void test01() +{ + bool test __attribute__((unused)) = true; + + std::wcout << L"Hello, "; + VERIFY( std::fwide(stdout, 0) >= 0 ); + int ret = std::fputws(L"world!\n", stdout); + VERIFY( ret >= 0 ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.cc new file mode 100644 index 000000000..a57c3afc7 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.cc @@ -0,0 +1,64 @@ +// 2003-05-01 Petur Runolfsson <peturr02@ru.is> + +// 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/>. + +#include <iostream> +#include <locale> +#include <string> +#include <cwchar> +#include <cwctype> +#include <iterator> +#include <algorithm> +#include <testsuite_hooks.h> + +// This tests the handling of multibyte characters by wcin and wcout. +void test09() +{ + using namespace std; + + locale loc(""); + locale::global(loc); + + wcout.imbue(loc); + wcin.imbue(loc); + + wcout << L"Current locale is: \'" << loc.name().c_str() << L"\'\n"; + wcout << L"Please enter your name: "; + + wstring str; + getline(wcin, str); + + wcout << str << endl; + wcout << str.size() << endl; + + transform(str.begin(), str.end(), + ostream_iterator<wchar_t, wchar_t>(wcout), towupper); + wcout << endl; + transform(str.begin(), str.end(), + ostream_iterator<wchar_t, wchar_t>(wcout), towlower); + wcout << endl << hex << showbase; + copy(str.begin(), str.end(), + ostream_iterator<wint_t, wchar_t>(wcout, L" ")); + wcout << endl; +} + +int main() +{ + test09(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.in b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.in new file mode 100644 index 000000000..a26c12687 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/9_xin.in @@ -0,0 +1 @@ +JOHN HUME and DAVID TRIMBLE diff --git a/libstdc++-v3/testsuite/27_io/objects/wchar_t/dr455.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/dr455.cc new file mode 100644 index 000000000..8055d967b --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/dr455.cc @@ -0,0 +1,36 @@ +// 2006-03-08 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#include <iostream> +#include <testsuite_hooks.h> + +// DR 455. cerr::tie() and wcerr::tie() are overspecified. +void test01() +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::wcerr.tie() == &std::wcout ); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/rvalue_streams.cc b/libstdc++-v3/testsuite/27_io/rvalue_streams.cc new file mode 100644 index 000000000..245633a8f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/rvalue_streams.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2008, 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/>. + +// { dg-do run } + +#include <sstream> +#include <string> +#include <testsuite_hooks.h> + +void +test01() +{ + int i = 1742; + // This usage isn't supported by the current draft. + // std::string result = (std::ostringstream() << i).str(); + std::ostringstream() << i; + std::string result ("1742"); + int i2; + std::istringstream(result) >> i2; + VERIFY (i == i2); +} + +int +main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/types/1.cc b/libstdc++-v3/testsuite/27_io/types/1.cc new file mode 100644 index 000000000..66f2c195c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/types/1.cc @@ -0,0 +1,35 @@ +// Copyright (C) 2002, 2003, 2004, 2005, 2009 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 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.4.2.1 - Types [lib.ios.types] + +#include <ios> +#include <testsuite_hooks.h> + +// libstdc++/7219 +// Annex D, deprecated. +void test01() +{ + typedef std::ios_base::streampos streampos_type; + typedef std::ios_base::streamoff streamoff_type; +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/types/2.cc b/libstdc++-v3/testsuite/27_io/types/2.cc new file mode 100644 index 000000000..33db5fed1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/types/2.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2003, 2004, 2009, 2010 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 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.4.2.1 - Types [lib.ios.types] + +#include <ios> +#include <testsuite_hooks.h> + +void test01() +{ + std::streamsize ssize = 0; + std::streamoff soff; + + // No signed/unsigned warnings. + long l __attribute__((unused)) = ssize; + + // Wrapped in pos_type is EOF. + soff = -1; + soff = soff; // Suppress unused warning. +} + +int main(void) +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/27_io/types/3.cc b/libstdc++-v3/testsuite/27_io/types/3.cc new file mode 100644 index 000000000..9684a5778 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/types/3.cc @@ -0,0 +1,49 @@ +// 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.4.3 streamoff + +#include <ios> +#include <limits> +#include <testsuite_hooks.h> + +void check(std::streamsize n) +{ + bool test __attribute__((unused)) = true; + + VERIFY( std::streamsize(std::streamoff(n)) == n ); +} + +void test03() +{ + check(0); + check(-1); + check(1); + check(std::numeric_limits<std::streamsize>::min()); + check(std::numeric_limits<std::streamsize>::min() + 1); + check(std::numeric_limits<std::streamsize>::min() / 2); + check(std::numeric_limits<std::streamsize>::max()); + check(std::numeric_limits<std::streamsize>::max() - 1); + check(std::numeric_limits<std::streamsize>::max() / 2); +} + +int main() +{ + test03(); + return 0; +} |