1// Copyright (C) 2004 Free Software Foundation 2// 3// This file is part of the GNU ISO C++ Library. This library is free 4// software; you can redistribute it and/or modify it under the 5// terms of the GNU General Public License as published by the 6// Free Software Foundation; either version 2, or (at your option) 7// any later version. 8 9// This library is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13 14// You should have received a copy of the GNU General Public License along 15// with this library; see the file COPYING. If not, write to the Free 16// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17// USA. 18 19// 27.6.1.3 unformatted input functions 20 21#include <cwchar> // for wcslen 22#include <istream> 23#include <sstream> 24#include <testsuite_hooks.h> 25 26// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type) 27// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html 28void 29test05() 30{ 31 const wchar_t* charray = L"\n" 32L"a\n" 33L"aa\n" 34L"aaa\n" 35L"aaaa\n" 36L"aaaaa\n" 37L"aaaaaa\n" 38L"aaaaaaa\n" 39L"aaaaaaaa\n" 40L"aaaaaaaaa\n" 41L"aaaaaaaaaa\n" 42L"aaaaaaaaaaa\n" 43L"aaaaaaaaaaaa\n" 44L"aaaaaaaaaaaaa\n" 45L"aaaaaaaaaaaaaa\n"; 46 47 bool test __attribute__((unused)) = true; 48 const std::streamsize it = 5; 49 std::streamsize br = 0; 50 wchar_t tmp[it]; 51 std::wstringbuf sb(charray, std::ios_base::in); 52 std::wistream ifs(&sb); 53 std::streamsize blen = std::wcslen(charray); 54 VERIFY(!(!ifs)); 55 while(ifs.getline(tmp, it) || ifs.gcount()) 56 { 57 br += ifs.gcount(); 58 if(ifs.eof()) 59 { 60 // Just sanity checks to make sure we've extracted the same 61 // number of chars that were in the streambuf 62 VERIFY( br == blen ); 63 // Also, we should only set the failbit if we could 64 // _extract_ no chars from the stream, i.e. the first read 65 // returned EOF. 66 VERIFY( ifs.fail() && ifs.gcount() == 0 ); 67 } 68 else if(ifs.fail()) 69 { 70 // delimiter not read 71 // 72 // either 73 // -> extracted no characters 74 // or 75 // -> n - 1 characters are stored 76 ifs.clear(ifs.rdstate() & ~std::ios::failbit); 77 VERIFY( (ifs.gcount() == 0) || (std::wcslen(tmp) == it - 1) ); 78 VERIFY( !(!ifs) ); 79 continue; 80 } 81 else 82 { 83 // delimiter was read. 84 // 85 // -> wcslen(__s) < n - 1 86 // -> delimiter was seen -> gcount() > wcslen(__s) 87 VERIFY( ifs.gcount() == static_cast<std::streamsize>(std::wcslen(tmp) 88 + 1) ); 89 continue; 90 } 91 } 92} 93 94int 95main() 96{ 97 test05(); 98 return 0; 99} 100