Debian Codegraph @

libstdc++-v3/testsuite/25_algorithms/advance/istreambuf_iterators/char/2.cc

raw
1 // Copyright (C) 2017-2025 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 // { dg-require-fileio "" }
19 // { dg-additional-files "istream_unformatted-1.txt" }
20
21 #include <iterator>
22 #include <fstream>
23 #include <algorithm>
24
25 #include <testsuite_hooks.h>
26
27 void test01()
28 {
29 using namespace std;
30
31 typedef istreambuf_iterator<char> in_iterator_type;
32
33 unsigned found = 0;
34
35 {
36 ifstream fbuf("istream_unformatted-1.txt");
37
38 in_iterator_type beg(fbuf);
39 in_iterator_type end;
40
41 for (;;)
42 {
43 beg = find(beg, end, '1');
44 if (beg == end)
45 break;
46
47 ++found;
48 VERIFY( *beg == '1' );
49
50 advance(beg, 9);
51 VERIFY( *beg == '0' );
52 }
53 }
54
55 {
56 ifstream fbuf("istream_unformatted-1.txt");
57
58 in_iterator_type beg(fbuf);
59 in_iterator_type end;
60
61 beg = find(beg, end, '1');
62 VERIFY( beg != end );
63 VERIFY( *beg == '1' );
64
65 advance(beg, 9);
66 VERIFY( *beg == '0' );
67
68 unsigned line_length = 10;
69 while (*++beg != '1')
70 ++line_length;
71
72 // Try to jump directly to the end through advance.
73 advance(beg, (found - 2) * line_length + 9);
74 VERIFY( *beg == '0' );
75 VERIFY( find(beg, end, '1') == end );
76 }
77 }
78
79 int main()
80 {
81 test01();
82 return 0;
83 }