]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-fstream.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / seekp / wchar_t / 2346-fstream.cc
CommitLineData
aa118a03 1// Copyright (C) 2005-2014 Free Software Foundation, Inc.
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 17
a76be469
RS
18// { dg-require-fileio "" }
19
ba4b172f
PC
20// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks]
21// @require@ %-*.tst %-*.txt
22// @diff@ %-*.tst %-*.txt
23
24#include <ostream>
25#include <istream>
26#include <fstream>
debac9f4 27#include <cstdlib>
ba4b172f
PC
28#include <testsuite_hooks.h>
29
30const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
31const int times = 10;
32
33void write_rewind(std::wiostream& stream)
34{
35 bool test __attribute__((unused)) = true;
36
37 for (int j = 0; j < times; j++)
38 {
39 std::streampos begin = stream.tellp();
40
41 for (int i = 0; i < times; ++i)
42 stream << j << L'-' << i << s << L'\n';
43
44 stream.seekp(begin);
45 }
46 VERIFY( stream.good() );
47}
48
49void check_contents(std::wiostream& stream)
50{
51 bool test __attribute__((unused)) = true;
52
53 stream.clear();
54 stream.seekg(0, std::wios::beg);
55 int i = 0;
56 int loop = times * times + 2;
57 while (i < loop)
58 {
59 stream.ignore(80, L'\n');
60 if (stream.good())
61 ++i;
62 else
63 break;
64 }
65 VERIFY( i == times );
66}
67
68// fstream
69// libstdc++/2346
70void test02()
71{
72 std::wfstream ofstrm;
73 ofstrm.open("wistream_seeks-3.txt", std::wios::out);
74 if (!ofstrm)
75 std::abort();
76 write_rewind(ofstrm);
77 ofstrm.close();
78
79 std::wfstream ifstrm;
80 ifstrm.open("wistream_seeks-3.txt", std::wios::in);
81 check_contents(ifstrm);
82 ifstrm.close();
83}
84
85int main()
86{
87 test02();
88 return 0;
89}