From: paolo Date: Fri, 26 Nov 2004 20:34:27 +0000 (+0000) Subject: 2004-11-26 Paolo Carlini X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=f45ab9781532f6d0792421f2fc6dba997c994d90 2004-11-26 Paolo Carlini 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::getline, istream::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 --- 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 + + 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::getline, istream::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 * configure: Regenerate for libtool reversion. @@ -16,7 +34,6 @@ * src/Makefile.in: Likewise. * testsuite/Makefile.in: Likewise. - 2004-11-24 Jonathan Wakely * 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 - - * 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 - - * 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 - - * Makefile.am (doxygen, doxygen-maint, doxygen-man): Remove extra '$' - from host_alias variable. - * Makefile.in: Regenerate. - -2004-11-19 Chris Jefferson - - * include/bits/stl_list.h (list::back, list::back const): - Don't decrement temporary. - -2004-11-19 Paolo Carlini - - * 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 - - * 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 - - * 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 - - DR 434. bitset::to_string() hard to use [Ready] 2004-11-19 Jonathan Wakely 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. +
243: + get and getline when sentry reports failure +
+
Store a null character only if the character array has a non-zero size. +
+
251: basic_stringbuf missing allocator_type
-
This nested typdef was originally not specified. +
This nested typedef was originally not specified.
253: 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 + +// 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 +#include + +// 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 + +// 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 +#include + +// 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 +#include +#include + +void +test02() +{ + typedef std::char_traits 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(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(state2 & stateeof) ); + VERIFY( static_cast(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 // for wcslen +#include +#include +#include + +// [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::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 // for wcslen +#include +#include +#include + +// [bug] istream::getline(char*,streamsize) still broken +// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00126.html +// brent verner // for wcslen +#include +#include + +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 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 +#include +#include +#include + +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 + +// 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 +#include + +// 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; +}