1// 2000-06-29 bkoz
2
3// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2009 Free Software Foundation
4//
5// This file is part of the GNU ISO C++ Library.  This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING3.  If not see
18// <http://www.gnu.org/licenses/>.
19
20// 27.6.2.4  basic_ostream seek members  [lib.ostream.seeks]
21
22#include <ostream>
23#include <istream>
24#include <sstream>
25#include <testsuite_hooks.h>
26
27const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
28const int times = 10;
29
30void write_rewind(std::iostream& stream)
31{
32  bool test __attribute__((unused)) = true;
33
34  for (int j = 0; j < times; j++)
35    {
36      std::streampos begin = stream.tellp();
37
38      for (int i = 0; i < times; ++i)
39	stream << j << '-' << i << s << '\n';
40
41      stream.seekp(begin);
42    }
43  VERIFY( stream.good() );
44}
45
46void check_contents(std::iostream& stream)
47{
48  bool test __attribute__((unused)) = true;
49
50  stream.clear();
51  stream.seekg(0, std::ios::beg);
52  int i = 0;
53  int loop = times * times + 2;
54  while (i < loop)
55    {
56      stream.ignore(80, '\n');
57      if (stream.good())
58	++i;
59      else
60	break;
61    }
62  VERIFY( i == times );
63}
64
65// stringstream
66// libstdc++/2346
67// N.B. The original testcase was broken, using tellg/seekg in write_rewind.
68void test03()
69{
70  std::stringstream sstrm;
71
72  write_rewind(sstrm);
73  check_contents(sstrm);
74}
75
76int main()
77{
78  test03();
79  return 0;
80}
81