]>
Commit | Line | Data |
---|---|---|
ceed88b1 PC |
1 | // 2005-07-22 Paolo Carlini <pcarlini@suse.de> |
2 | ||
8d9254fc | 3 | // Copyright (C) 2005-2020 Free Software Foundation, Inc. |
ceed88b1 PC |
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) |
ceed88b1 PC |
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/>. | |
ceed88b1 PC |
19 | |
20 | // 27.6.1.2.3 basic_istream::operator>> | |
21 | ||
0c20e4ec NS |
22 | // { dg-require-fileio "" } |
23 | ||
ceed88b1 PC |
24 | #include <istream> |
25 | #include <string> | |
26 | #include <fstream> | |
debac9f4 | 27 | #include <cstdlib> |
1b716e90 | 28 | #include <cstring> |
ceed88b1 PC |
29 | #include <testsuite_hooks.h> |
30 | ||
31 | using namespace std; | |
32 | ||
33 | string prepare(string::size_type len, unsigned nchunks) | |
34 | { | |
35 | string ret; | |
36 | for (unsigned i = 0; i < nchunks; ++i) | |
37 | { | |
38 | for (string::size_type j = 0; j < len; ++j) | |
39 | ret.push_back('a' + rand() % 26); | |
40 | len *= 2; | |
41 | ret.push_back(' '); | |
42 | } | |
43 | return ret; | |
44 | } | |
45 | ||
46 | void check(istream& stream, const string& str, unsigned nchunks) | |
47 | { | |
ceed88b1 PC |
48 | char* chunk = new char[str.size()]; |
49 | memset(chunk, 'X', str.size()); | |
50 | ||
51 | string::size_type index = 0, index_new = 0; | |
52 | unsigned n = 0; | |
53 | ||
54 | while (stream >> chunk) | |
55 | { | |
56 | index_new = str.find(' ', index); | |
57 | VERIFY( !str.compare(index, index_new - index, chunk) ); | |
58 | index = index_new + 1; | |
59 | ++n; | |
60 | memset(chunk, 'X', str.size()); | |
61 | } | |
62 | VERIFY( stream.eof() ); | |
63 | VERIFY( n == nchunks ); | |
64 | ||
65 | delete[] chunk; | |
66 | } | |
67 | ||
68 | // istream& operator>>(istream&, charT*) | |
69 | void test01() | |
70 | { | |
71 | const char filename[] = "inserters_extractors-4.txt"; | |
72 | ||
73 | const unsigned nchunks = 10; | |
74 | const string data = prepare(666, nchunks); | |
75 | ||
76 | ofstream ofstrm; | |
77 | ofstrm.open(filename); | |
78 | ofstrm.write(data.data(), data.size()); | |
79 | ofstrm.close(); | |
80 | ||
81 | ifstream ifstrm; | |
82 | ifstrm.open(filename); | |
83 | check(ifstrm, data, nchunks); | |
84 | ifstrm.close(); | |
85 | } | |
86 | ||
87 | int main() | |
88 | { | |
89 | test01(); | |
90 | return 0; | |
91 | } |