| 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 |
|
| 22 |
#include <ostream> |
| 23 |
#include <istream> |
| 24 |
#include <sstream> |
| 25 |
#include <testsuite_hooks.h> |
| 26 |
|
| 27 |
const char* s = " lootpack, peanut butter wolf, rob swift, madlib, quasimoto"; |
| 28 |
const int times = 10; |
| 29 |
|
| 30 |
void write_rewind(std::iostream& stream) |
| 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 << '-' << i << s << '\n'; |
| 38 |
|
| 39 |
stream.seekp(begin); |
| 40 |
} |
| 41 |
VERIFY( stream.good() ); |
| 42 |
} |
| 43 |
|
| 44 |
void check_contents(std::iostream& stream) |
| 45 |
{ |
| 46 |
stream.clear(); |
| 47 |
stream.seekg(0, std::ios::beg); |
| 48 |
int i = 0; |
| 49 |
int loop = times * times + 2; |
| 50 |
while (i < loop) |
| 51 |
{ |
| 52 |
stream.ignore(80, '\n'); |
| 53 |
if (stream.good()) |
| 54 |
++i; |
| 55 |
else |
| 56 |
break; |
| 57 |
} |
| 58 |
VERIFY( i == times ); |
| 59 |
} |
| 60 |
|
| 61 |
// stringstream |
| 62 |
// libstdc++/2346 |
| 63 |
// N.B. The original testcase was broken, using tellg/seekg in write_rewind. |
| 64 |
void test03() |
| 65 |
{ |
| 66 |
std::stringstream sstrm; |
| 67 |
|
| 68 |
write_rewind(sstrm); |
| 69 |
check_contents(sstrm); |
| 70 |
} |
| 71 |
|
| 72 |
int main() |
| 73 |
{ |
| 74 |
test03(); |
| 75 |
return 0; |
| 76 |
} |