1193323Sed// Copyright (C) 2005, 2009 Free Software Foundation
2193323Sed//
3193323Sed// This file is part of the GNU ISO C++ Library.  This library is free
4193323Sed// software; you can redistribute it and/or modify it under the
5193323Sed// terms of the GNU General Public License as published by the
6193323Sed// Free Software Foundation; either version 3, or (at your option)
7193323Sed// any later version.
8193323Sed
9193323Sed// This library is distributed in the hope that it will be useful,
10193323Sed// but WITHOUT ANY WARRANTY; without even the implied warranty of
11193323Sed// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12193323Sed// GNU General Public License for more details.
13193323Sed
14193323Sed// You should have received a copy of the GNU General Public License along
15193323Sed// with this library; see the file COPYING3.  If not see
16239462Sdim// <http://www.gnu.org/licenses/>.
17193323Sed
18193323Sed// 27.6.2.4  basic_ostream seek members  [lib.ostream.seeks]
19193323Sed
20193323Sed#include <ostream>
21193323Sed#include <istream>
22193323Sed#include <sstream>
23193323Sed#include <testsuite_hooks.h>
24193323Sed
25193323Sedconst wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
26193323Sedconst int times = 10;
27193323Sed
28193323Sedvoid write_rewind(std::wiostream& stream)
29193323Sed{
30193323Sed  bool test __attribute__((unused)) = true;
31193323Sed
32193323Sed  for (int j = 0; j < times; j++)
33193323Sed    {
34193323Sed      std::streampos begin = stream.tellp();
35199989Srdivacky
36200581Srdivacky      for (int i = 0; i < times; ++i)
37200581Srdivacky	stream << j << L'-' << i << s << L'\n';
38199989Srdivacky
39193323Sed      stream.seekp(begin);
40193323Sed    }
41193323Sed  VERIFY( stream.good() );
42193323Sed}
43193323Sed
44193323Sedvoid check_contents(std::wiostream& stream)
45193323Sed{
46193323Sed  bool test __attribute__((unused)) = true;
47193323Sed
48198090Srdivacky  stream.clear();
49193323Sed  stream.seekg(0, std::wios::beg);
50193323Sed  int i = 0;
51200581Srdivacky  int loop = times * times + 2;
52200581Srdivacky  while (i < loop)
53200581Srdivacky    {
54200581Srdivacky      stream.ignore(80, L'\n');
55200581Srdivacky      if (stream.good())
56193323Sed	++i;
57199989Srdivacky      else
58199989Srdivacky	break;
59193323Sed    }
60193323Sed  VERIFY( i == times );
61193323Sed}
62193323Sed
63193323Sed// stringstream
64193323Sed// libstdc++/2346
65193323Sed// N.B. The original testcase was broken, using tellg/seekg in write_rewind.
66193323Sedvoid test03()
67193323Sed{
68193323Sed  std::wstringstream sstrm;
69193323Sed
70193323Sed  write_rewind(sstrm);
71193323Sed  check_contents(sstrm);
72193323Sed}
73193323Sed
74193323Sedint main()
75193323Sed{
76193323Sed  test03();
77193323Sed  return 0;
78193323Sed}
79193323Sed