]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / seekp / wchar_t / 2346-sstream.cc
CommitLineData
748086b7 1// Copyright (C) 2005, 2009 Free Software Foundation
ba4b172f
PC
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
748086b7 6// Free Software Foundation; either version 3, or (at your option)
ba4b172f
PC
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
748086b7
JJ
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
ba4b172f
PC
17
18// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks]
19
20#include <ostream>
21#include <istream>
22#include <sstream>
23#include <testsuite_hooks.h>
24
25const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
26const int times = 10;
27
28void write_rewind(std::wiostream& stream)
29{
30 bool test __attribute__((unused)) = true;
31
32 for (int j = 0; j < times; j++)
33 {
34 std::streampos begin = stream.tellp();
35
36 for (int i = 0; i < times; ++i)
37 stream << j << L'-' << i << s << L'\n';
38
39 stream.seekp(begin);
40 }
41 VERIFY( stream.good() );
42}
43
44void check_contents(std::wiostream& stream)
45{
46 bool test __attribute__((unused)) = true;
47
48 stream.clear();
49 stream.seekg(0, std::wios::beg);
50 int i = 0;
51 int loop = times * times + 2;
52 while (i < loop)
53 {
54 stream.ignore(80, L'\n');
55 if (stream.good())
56 ++i;
57 else
58 break;
59 }
60 VERIFY( i == times );
61}
62
63// stringstream
64// libstdc++/2346
65// N.B. The original testcase was broken, using tellg/seekg in write_rewind.
66void test03()
67{
68 std::wstringstream sstrm;
69
70 write_rewind(sstrm);
71 check_contents(sstrm);
72}
73
74int main()
75{
76 test03();
77 return 0;
78}