1// Copyright (C) 2005 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.2.4 basic_ostream seek members [lib.ostream.seeks] 20 21#include <ostream> 22#include <istream> 23#include <sstream> 24#include <testsuite_hooks.h> 25 26const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; 27const int times = 10; 28 29void write_rewind(std::wiostream& stream) 30{ 31 bool test __attribute__((unused)) = true; 32 33 for (int j = 0; j < times; j++) 34 { 35 std::streampos begin = stream.tellp(); 36 37 for (int i = 0; i < times; ++i) 38 stream << j << L'-' << i << s << L'\n'; 39 40 stream.seekp(begin); 41 } 42 VERIFY( stream.good() ); 43} 44 45void check_contents(std::wiostream& stream) 46{ 47 bool test __attribute__((unused)) = true; 48 49 stream.clear(); 50 stream.seekg(0, std::wios::beg); 51 int i = 0; 52 int loop = times * times + 2; 53 while (i < loop) 54 { 55 stream.ignore(80, L'\n'); 56 if (stream.good()) 57 ++i; 58 else 59 break; 60 } 61 VERIFY( i == times ); 62} 63 64// stringstream 65// libstdc++/2346 66// N.B. The original testcase was broken, using tellg/seekg in write_rewind. 67void test03() 68{ 69 std::wstringstream sstrm; 70 71 write_rewind(sstrm); 72 check_contents(sstrm); 73} 74 75int main() 76{ 77 test03(); 78 return 0; 79} 80