diff options
Diffstat (limited to 'libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char')
6 files changed, 457 insertions, 0 deletions
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; +} |