diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-11-26 20:34:27 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-11-26 20:34:27 +0000 |
commit | f45ab9781532f6d0792421f2fc6dba997c994d90 (patch) | |
tree | b5be3c1e292bc1d5153f23e0b397d3ec01a857d4 | |
parent | 6ce57611c71db9c99791f7f293ab0593e2cbc61d (diff) | |
download | gcc-f45ab9781532f6d0792421f2fc6dba997c994d90.tar.gz |
2004-11-26 Paolo Carlini <pcarlini@suse.de>
DR 243. get and getline when sentry reports failure [WP]
* include/bits/istream.tcc (istream<>::get, istream<>::getline):
Store a null character only if the array has a non-zero size.
* src/istream.cc (istream<char>::getline, istream<wchar_t>::getline):
Likewise.
* testsuite/27_io/basic_istream/get/char/3.cc: New.
* testsuite/27_io/basic_istream/getline/char/6.cc: New.
* testsuite/27_io/basic_istream/getline/wchar_t/6.cc: New.
* docs/html/ext/howto.html: Add an entry for DR 243.
* testsuite/27_io/basic_istream/getline/wchar_t/1.cc: New.
* testsuite/27_io/basic_istream/getline/wchar_t/2.cc: New.
* testsuite/27_io/basic_istream/getline/wchar_t/3.cc: New.
* testsuite/27_io/basic_istream/getline/wchar_t/4.cc: New.
* testsuite/27_io/basic_istream/getline/wchar_t/5.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@91348 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | libstdc++-v3/ChangeLog | 80 | ||||
-rw-r--r-- | libstdc++-v3/docs/html/ext/howto.html | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/istream.tcc | 10 | ||||
-rw-r--r-- | libstdc++-v3/src/istream.cc | 10 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/get/char/3.cc | 58 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc | 58 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc | 118 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc | 99 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc | 59 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc | 112 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc | 87 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc | 58 |
12 files changed, 690 insertions, 67 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cad9107643f..feff7c4a28f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,21 @@ +2004-11-26 Paolo Carlini <pcarlini@suse.de> + + DR 243. get and getline when sentry reports failure [WP] + * include/bits/istream.tcc (istream<>::get, istream<>::getline): + Store a null character only if the array has a non-zero size. + * src/istream.cc (istream<char>::getline, istream<wchar_t>::getline): + Likewise. + * testsuite/27_io/basic_istream/get/char/3.cc: New. + * testsuite/27_io/basic_istream/getline/char/6.cc: New. + * testsuite/27_io/basic_istream/getline/wchar_t/6.cc: New. + * docs/html/ext/howto.html: Add an entry for DR 243. + + * testsuite/27_io/basic_istream/getline/wchar_t/1.cc: New. + * testsuite/27_io/basic_istream/getline/wchar_t/2.cc: New. + * testsuite/27_io/basic_istream/getline/wchar_t/3.cc: New. + * testsuite/27_io/basic_istream/getline/wchar_t/4.cc: New. + * testsuite/27_io/basic_istream/getline/wchar_t/5.cc: New. + 2004-11-25 Kelley Cook <kcook@gcc.gnu.org> * configure: Regenerate for libtool reversion. @@ -16,7 +34,6 @@ * src/Makefile.in: Likewise. * testsuite/Makefile.in: Likewise. - 2004-11-24 Jonathan Wakely <redi@kayari.org> * docs/html/ext/howto.html: Fix incorrect link. @@ -101,67 +118,6 @@ * docs/doxygen/run_doxygen: Print arguments. * docs/doxygen/user.cfg.in: Tweaks. - -2004-11-19 Jonathan Wakely <redi@gcc.gnu.org> - - * include/bits/basic_string.h, include/bits/locale_classes.h, - include/bits/valarray_after.h, include/bits/valarray_before.h, - include/ext/stdio_sync_filebuf.h, include/std/std_algorithm.h, - include/std/std_functional.h, include/std/std_memory.h, - include/std/std_numeric.h: Doxygen fixes. - -2004-11-19 Paolo Carlini <pcarlini@suse.de> - - * testsuite/22_locale/time_get/get_date/char/1.cc: In the checks - use, more correctly (and consistently with other testcases) the - return value of the facet (the iterator arguments are by value). - * testsuite/22_locale/time_get/get_date/char/12791.cc: Likewise. - * testsuite/22_locale/time_get/get_date/wchar_t/1.cc: Likewise. - * testsuite/22_locale/time_get/get_date/wchar_t/12791.cc: Likewise. - * testsuite/22_locale/time_get/get_monthname/char/1.cc: Likewise. - * testsuite/22_locale/time_get/get_monthname/wchar_t/1.cc: Likewise. - * testsuite/22_locale/time_get/get_time/char/1.cc: Likewise. - * testsuite/22_locale/time_get/get_time/wchar_t/1.cc: Likewise. - * testsuite/22_locale/time_get/get_weekday/char/1.cc: Likewise. - * testsuite/22_locale/time_get/get_weekday/wchar_t/1.cc: Likewise. - * testsuite/22_locale/time_get/get_year/char/1.cc: Likewise. - * testsuite/22_locale/time_get/get_year/wchar_t/1.cc: Likewise. - -2004-11-19 Jonathan Wakely <redi@gcc.gnu.org> - - * Makefile.am (doxygen, doxygen-maint, doxygen-man): Remove extra '$' - from host_alias variable. - * Makefile.in: Regenerate. - -2004-11-19 Chris Jefferson <chris@bubblescope.net> - - * include/bits/stl_list.h (list::back, list::back const): - Don't decrement temporary. - -2004-11-19 Paolo Carlini <pcarlini@suse.de> - - * include/bits/stl_deque.h (deque::front, deque::front const, - deque::back, deque::back const): Slightly tweak for stylistic - consistency. - -2004-11-18 Paolo Carlini <pcarlini@suse.de> - - * testsuite/26_numerics/numeric/sum_diff.cc: Use VERIFY. - * testsuite/ext/array_allocator/1.cc: Likewise. - * testsuite/ext/array_allocator/2.cc: Likewise. - * testsuite/ext/array_allocator/3.cc: Likewise. - * testsuite/ext/enc_filebuf/char/13598.cc: Likewise. - -2004-11-18 Paolo Carlini <pcarlini@suse.de> - - * include/bits/locale_facets.tcc (num_get<>::do_get(void*&)): - If the failbit is set, don't set it again. - (money_get<>::_M_extract): Minor stylistic tweak: consistently - with the other functions, take care of eofbit at the end. - -2004-11-18 Paolo Carlini <pcarlini@suse.de> - - DR 434. bitset::to_string() hard to use [Ready] 2004-11-19 Jonathan Wakely <redi@gcc.gnu.org> diff --git a/libstdc++-v3/docs/html/ext/howto.html b/libstdc++-v3/docs/html/ext/howto.html index b35ba9ec081..fff775e165a 100644 --- a/libstdc++-v3/docs/html/ext/howto.html +++ b/libstdc++-v3/docs/html/ext/howto.html @@ -406,10 +406,16 @@ However, no specification is given what this constructor should do. </dd> + <dt><a href="lwg-defects.html#243">243</a>: + <em>get and getline when sentry reports failure</em> + </dt> + <dd>Store a null character only if the character array has a non-zero size. + </dd> + <dt><a href="lwg-defects.html#251">251</a>: <em>basic_stringbuf missing allocator_type</em> </dt> - <dd>This nested typdef was originally not specified. + <dd>This nested typedef was originally not specified. </dd> <dt><a href="lwg-defects.html#253">253</a>: diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index 68451adbfbe..b363d52091d 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -533,7 +533,10 @@ namespace std catch(...) { this->_M_setstate(ios_base::badbit); } } - *__s = char_type(); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 243. get and getline when sentry reports failure. + if (__n > 0) + *__s = char_type(); if (!_M_gcount) __err |= ios_base::failbit; if (__err) @@ -621,7 +624,10 @@ namespace std catch(...) { this->_M_setstate(ios_base::badbit); } } - *__s = char_type(); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 243. get and getline when sentry reports failure. + if (__n > 0) + *__s = char_type(); if (!_M_gcount) __err |= ios_base::failbit; if (__err) diff --git a/libstdc++-v3/src/istream.cc b/libstdc++-v3/src/istream.cc index 462824dada9..39de7538f0d 100644 --- a/libstdc++-v3/src/istream.cc +++ b/libstdc++-v3/src/istream.cc @@ -94,7 +94,10 @@ namespace std catch(...) { this->_M_setstate(ios_base::badbit); } } - *__s = char_type(); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 243. get and getline when sentry reports failure. + if (__n > 0) + *__s = char_type(); if (!_M_gcount) __err |= ios_base::failbit; if (__err) @@ -358,7 +361,10 @@ namespace std catch(...) { this->_M_setstate(ios_base::badbit); } } - *__s = char_type(); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 243. get and getline when sentry reports failure. + if (__n > 0) + *__s = char_type(); if (!_M_gcount) __err |= ios_base::failbit; if (__err) 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 00000000000..ea831742c67 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/get/char/3.cc @@ -0,0 +1,58 @@ +// 2004-11-26 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#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/getline/char/6.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc new file mode 100644 index 00000000000..e4066136765 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/6.cc @@ -0,0 +1,58 @@ +// 2004-11-26 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#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 00000000000..4e1efffb7da --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/1.cc @@ -0,0 +1,118 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#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(NULL); + 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 00000000000..2b25483ca45 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/2.cc @@ -0,0 +1,99 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#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() > strlen(__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 00000000000..dbfc1a950a4 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/3.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#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 00000000000..5f290ffdb43 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/4.cc @@ -0,0 +1,112 @@ +// Copyright (C) 2004 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can 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. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +// 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), '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 00000000000..999befe2082 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/5.cc @@ -0,0 +1,87 @@ +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#include <istream> +#include <string> +#include <fstream> +#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; + + 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( 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 00000000000..658ca9a7a1c --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/wchar_t/6.cc @@ -0,0 +1,58 @@ +// 2004-11-26 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.6.1.3 unformatted input functions + +#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; +} |