]>
Commit | Line | Data |
---|---|---|
23cac885 BK |
1 | // 2000-06-29 bkoz |
2 | ||
8d9254fc | 3 | // Copyright (C) 2000-2020 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 | 21 | |
9c9e97bd | 22 | #include <ostream> |
23cac885 BK |
23 | #include <istream> |
24 | #include <sstream> | |
23cac885 BK |
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 | { | |
9c9e97bd | 34 | std::streampos begin = stream.tellp(); |
23cac885 BK |
35 | |
36 | for (int i = 0; i < times; ++i) | |
37 | stream << j << '-' << i << s << '\n'; | |
38 | ||
9c9e97bd | 39 | stream.seekp(begin); |
23cac885 | 40 | } |
9c9e97bd | 41 | VERIFY( stream.good() ); |
23cac885 BK |
42 | } |
43 | ||
44 | void check_contents(std::iostream& stream) | |
45 | { | |
23cac885 BK |
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 | |
9c9e97bd | 63 | // N.B. The original testcase was broken, using tellg/seekg in write_rewind. |
23cac885 BK |
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 | } |