]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / extractors_character / wchar_t / 4.cc
CommitLineData
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
5a0727d9 22// { dg-options "-DMAX_SIZE=466" { target simulator } }
6cec3c81 23// { dg-require-fileio "" }
5a0727d9
SE
24
25#ifndef MAX_SIZE
26#define MAX_SIZE 666
27#endif
28
ceed88b1
PC
29#include <istream>
30#include <string>
31#include <fstream>
debac9f4 32#include <cstdlib>
ceed88b1
PC
33#include <testsuite_hooks.h>
34
35using namespace std;
36
37wstring prepare(wstring::size_type len, unsigned nchunks)
38{
39 wstring ret;
40 for (unsigned i = 0; i < nchunks; ++i)
41 {
42 for (wstring::size_type j = 0; j < len; ++j)
43 ret.push_back(L'a' + rand() % 26);
44 len *= 2;
45 ret.push_back(L' ');
46 }
47 return ret;
48}
49
50void check(wistream& stream, const wstring& str, unsigned nchunks)
51{
ceed88b1
PC
52 wchar_t* chunk = new wchar_t[str.size()];
53 wmemset(chunk, L'X', str.size());
54
55 wstring::size_type index = 0, index_new = 0;
56 unsigned n = 0;
57
58 while (stream >> chunk)
59 {
60 index_new = str.find(' ', index);
61 VERIFY( !str.compare(index, index_new - index, chunk) );
62 index = index_new + 1;
63 ++n;
64 wmemset(chunk, L'X', str.size());
65 }
66 VERIFY( stream.eof() );
67 VERIFY( n == nchunks );
68
69 delete[] chunk;
70}
71
72// istream& operator>>(istream&, charT*)
73void test01()
74{
75 const char filename[] = "inserters_extractors-4.txt";
76
77 const unsigned nchunks = 10;
5a0727d9 78 const wstring data = prepare(MAX_SIZE, nchunks);
ceed88b1
PC
79
80 wofstream ofstrm;
81 ofstrm.open(filename);
82 ofstrm.write(data.data(), data.size());
83 ofstrm.close();
84
85 wifstream ifstrm;
86 ifstrm.open(filename);
87 check(ifstrm, data, nchunks);
88 ifstrm.close();
89}
90
91int main()
92{
93 test01();
94 return 0;
95}