| 1 |
// 2000-06-29 bkoz |
| 2 |
|
| 3 |
// Copyright (C) 2000-2025 Free Software Foundation, Inc. |
| 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 |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 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 |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// 27.6.2.4 basic_ostream seek members [lib.ostream.seeks] |
| 21 |
// @require@ %-*.tst %-*.txt |
| 22 |
// @diff@ %-*.tst %-*.txt |
| 23 |
|
| 24 |
// { dg-require-fileio "" } |
| 25 |
|
| 26 |
#include <ostream> |
| 27 |
#include <istream> |
| 28 |
#include <fstream> |
| 29 |
#include <cstdlib> |
| 30 |
#include <testsuite_hooks.h> |
| 31 |
|
| 32 |
const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; |
| 33 |
const int times = 10; |
| 34 |
|
| 35 |
void write_rewind(std::iostream& stream) |
| 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 << '-' << i << s << '\n'; |
| 43 |
|
| 44 |
stream.seekp(begin); |
| 45 |
} |
| 46 |
VERIFY( stream.good() ); |
| 47 |
} |
| 48 |
|
| 49 |
void check_contents(std::iostream& stream) |
| 50 |
{ |
| 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 |
| 68 |
void 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 |
|
| 83 |
int main() |
| 84 |
{ |
| 85 |
test02(); |
| 86 |
return 0; |
| 87 |
} |