]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/seekp/wchar_t/2346-sstream.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / seekp / wchar_t / 2346-sstream.cc
1 // Copyright (C) 2005-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 27.6.2.4 basic_ostream seek members [lib.ostream.seeks]
19
20 #include <ostream>
21 #include <istream>
22 #include <sstream>
23 #include <testsuite_hooks.h>
24
25 const wchar_t* s = L" lootpack, peanut butter wolf, rob swift, madlib, quasimoto";
26 const int times = 10;
27
28 void write_rewind(std::wiostream& stream)
29 {
30 for (int j = 0; j < times; j++)
31 {
32 std::streampos begin = stream.tellp();
33
34 for (int i = 0; i < times; ++i)
35 stream << j << L'-' << i << s << L'\n';
36
37 stream.seekp(begin);
38 }
39 VERIFY( stream.good() );
40 }
41
42 void check_contents(std::wiostream& stream)
43 {
44 stream.clear();
45 stream.seekg(0, std::wios::beg);
46 int i = 0;
47 int loop = times * times + 2;
48 while (i < loop)
49 {
50 stream.ignore(80, L'\n');
51 if (stream.good())
52 ++i;
53 else
54 break;
55 }
56 VERIFY( i == times );
57 }
58
59 // stringstream
60 // libstdc++/2346
61 // N.B. The original testcase was broken, using tellg/seekg in write_rewind.
62 void test03()
63 {
64 std::wstringstream sstrm;
65
66 write_rewind(sstrm);
67 check_contents(sstrm);
68 }
69
70 int main()
71 {
72 test03();
73 return 0;
74 }