diff options
author | Petur Runolfsson <peturr02@ru.is> | 2003-09-03 14:57:04 +0000 |
---|---|---|
committer | Benjamin Kosnik <bkoz@gcc.gnu.org> | 2003-09-03 14:57:04 +0000 |
commit | 4c620c398ef5e70e2fe3c6aa7b210b8416d460df (patch) | |
tree | 057dcd9e4f0a7b45d37e2a156328ee83c523b147 | |
parent | 149639d4f14ae921b4d14f6e35a840755b29f098 (diff) | |
download | gcc-4c620c398ef5e70e2fe3c6aa7b210b8416d460df.zip gcc-4c620c398ef5e70e2fe3c6aa7b210b8416d460df.tar.gz gcc-4c620c398ef5e70e2fe3c6aa7b210b8416d460df.tar.bz2 |
re PR libstdc++/12048 (unget does not work)
2003-09-03 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/12048
* include/ext/stdio_sync_filebuf.h
(stdio_sync_filebuf::_M_unget_buf): Declare it.
(stdio_sync_filebuf::stdio_sync_filebuf): Initialize _M_unget_buf.
(stdio_sync_filebuf::uflow): Store the returned character in
_M_unget_buf.
(stdio_sync_filebuf::pbackfail): If argument is eof(), pass
_M_unget_buf to syncungetc(). Set _M_unget_buf to eof().
(stdio_sync_filebuf<char>::xsgetn): Store last read character in
_M_unget_buf, if any, else eof().
(stdio_sync_filebuf<wchar_t>::xsgetn: Store last read character in
_M_unget_buf, if any, else eof().
* testsuite/27_io/objects/char/12048.cc: Rename to...
* testsuite/27_io/objects/char/12048-1.cc: ...this.
* testsuite/27_io/objects/char/12048-2.cc: New test.
* testsuite/27_io/objects/char/12048-3.cc: New test.
* testsuite/27_io/objects/char/12048-4.cc: New test.
* testsuite/27_io/objects/char/12048-5.cc: New test. XFAIL.
* testsuite/27_io/objects/wchar_t/12048-1.cc: New test.
* testsuite/27_io/objects/wchar_t/12048-2.cc: New test.
* testsuite/27_io/objects/wchar_t/12048-3.cc: New test.
* testsuite/27_io/objects/wchar_t/12048-4.cc: New test.
* testsuite/27_io/objects/wchar_t/12048-5.cc: New test. XFAIL.
* testsuite/ext/stdio_sync_filebuf_char.cc
(test02, test03, test04, test05): New tests.
* testsuite/ext/stdio_sync_filebuf_wchar_t.cc
(test02, test03, test04, test05): New tests.
From-SVN: r71027
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc (renamed from libstdc++-v3/testsuite/27_io/objects/char/12048.cc) | 3 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc | 41 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc | 39 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc | 40 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc | 55 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc | 43 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc | 42 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc | 43 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc | 41 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc | 53 |
10 files changed, 399 insertions, 1 deletions
diff --git a/libstdc++-v3/testsuite/27_io/objects/char/12048.cc b/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc index 575fe35..7ad336d 100644 --- a/libstdc++-v3/testsuite/27_io/objects/char/12048.cc +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc @@ -32,7 +32,8 @@ test01() std::cin.get(c1); std::cin.unget(); std::cin.get(c2); - VERIFY (c1 == c2); + VERIFY( std::cin.good() ); + VERIFY( c1 == c2 ); } int main(void) 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 0000000..d544d64 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..2f69b07 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..6c0b28f --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <cstdio> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..884f49e --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/char/12048-5.cc @@ -0,0 +1,55 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 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 <testsuite_hooks.h> + +void +test01() +{ + 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/wchar_t/12048-1.cc b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc new file mode 100644 index 0000000..dbdf1d1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-1.cc @@ -0,0 +1,43 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..f96302a --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-2.cc @@ -0,0 +1,42 @@ +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <cstdio> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..568b6a1 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-3.cc @@ -0,0 +1,43 @@ +// Derived from libstdc++/12048 by LJR <ljrittle@acm.org> with +// reminder from Petur Runolfsson <peturr02@ru.is>. + +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..5096cd0 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-4.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +#include <iostream> +#include <cstdio> +#include <cwchar> +#include <testsuite_hooks.h> + +void +test01() +{ + 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 0000000..bc965fd --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/objects/wchar_t/12048-5.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2003 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 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() +{ + 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; +} |