]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/seekp/char/2346-fstream.cc
libstdc++.exp (check_v3_target_fileio, [...]): New.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / seekp / char / 2346-fstream.cc
1 // 2000-06-29 bkoz
2
3 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // 27.6.2.4 basic_ostream seek members [lib.ostream.seeks]
23 // @require@ %-*.tst %-*.txt
24 // @diff@ %-*.tst %-*.txt
25
26 // { dg-require-fileio "" }
27
28 #include <ostream>
29 #include <istream>
30 #include <fstream>
31 #include <cstdlib>
32 #include <testsuite_hooks.h>
33
34 const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
35 const int times = 10;
36
37 void write_rewind(std::iostream& stream)
38 {
39 bool test __attribute__((unused)) = true;
40
41 for (int j = 0; j < times; j++)
42 {
43 std::streampos begin = stream.tellp();
44
45 for (int i = 0; i < times; ++i)
46 stream << j << '-' << i << s << '\n';
47
48 stream.seekp(begin);
49 }
50 VERIFY( stream.good() );
51 }
52
53 void check_contents(std::iostream& stream)
54 {
55 bool test __attribute__((unused)) = true;
56
57 stream.clear();
58 stream.seekg(0, std::ios::beg);
59 int i = 0;
60 int loop = times * times + 2;
61 while (i < loop)
62 {
63 stream.ignore(80, '\n');
64 if (stream.good())
65 ++i;
66 else
67 break;
68 }
69 VERIFY( i == times );
70 }
71
72 // fstream
73 // libstdc++/2346
74 void test02()
75 {
76 std::fstream ofstrm;
77 ofstrm.open("istream_seeks-3.txt", std::ios::out);
78 if (!ofstrm)
79 std::abort();
80 write_rewind(ofstrm);
81 ofstrm.close();
82
83 std::fstream ifstrm;
84 ifstrm.open("istream_seeks-3.txt", std::ios::in);
85 check_contents(ifstrm);
86 ifstrm.close();
87 }
88
89 int main()
90 {
91 test02();
92 return 0;
93 }