]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / seekp / char / 2346-fstream.cc
CommitLineData
23cac885
BK
1// 2000-06-29 bkoz
2
a945c346 3// Copyright (C) 2000-2024 Free Software Foundation, Inc.
23cac885
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
23cac885
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
23cac885 19
9c9e97bd 20// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks]
23cac885
BK
21// @require@ %-*.tst %-*.txt
22// @diff@ %-*.tst %-*.txt
23
0c20e4ec
NS
24// { dg-require-fileio "" }
25
9c9e97bd 26#include <ostream>
23cac885 27#include <istream>
23cac885 28#include <fstream>
debac9f4 29#include <cstdlib>
23cac885
BK
30#include <testsuite_hooks.h>
31
32const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
33const int times = 10;
34
35void write_rewind(std::iostream& stream)
36{
37 for (int j = 0; j < times; j++)
38 {
9c9e97bd 39 std::streampos begin = stream.tellp();
23cac885
BK
40
41 for (int i = 0; i < times; ++i)
42 stream << j << '-' << i << s << '\n';
43
9c9e97bd 44 stream.seekp(begin);
23cac885 45 }
9c9e97bd 46 VERIFY( stream.good() );
23cac885
BK
47}
48
49void check_contents(std::iostream& stream)
50{
23cac885
BK
51 stream.clear();
52 stream.seekg(0, std::ios::beg);
53 int i = 0;
54 int loop = times * times + 2;
55 while (i < loop)
56 {
57 stream.ignore(80, '\n');
58 if (stream.good())
59 ++i;
60 else
61 break;
62 }
63 VERIFY( i == times );
64}
65
66// fstream
67// libstdc++/2346
68void test02()
69{
70 std::fstream ofstrm;
71 ofstrm.open("istream_seeks-3.txt", std::ios::out);
72 if (!ofstrm)
73 std::abort();
74 write_rewind(ofstrm);
75 ofstrm.close();
76
77 std::fstream ifstrm;
78 ifstrm.open("istream_seeks-3.txt", std::ios::in);
79 check_contents(ifstrm);
80 ifstrm.close();
81}
82
83int main()
84{
85 test02();
86 return 0;
87}