]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/extractors_character/wchar_t/4.cc
1 // 2005-07-22 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2020 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 27.6.1.2.3 basic_istream::operator>>
22 // { dg-options "-DMAX_SIZE=466" { target simulator } }
23 // { dg-require-fileio "" }
33 #include <testsuite_hooks.h>
37 wstring
prepare(wstring::size_type len
, unsigned nchunks
)
40 for (unsigned i
= 0; i
< nchunks
; ++i
)
42 for (wstring::size_type j
= 0; j
< len
; ++j
)
43 ret
.push_back(L
'a' + rand() % 26);
50 void check(wistream
& stream
, const wstring
& str
, unsigned nchunks
)
52 wchar_t* chunk
= new wchar_t[str
.size()];
53 wmemset(chunk
, L
'X', str
.size());
55 wstring::size_type index
= 0, index_new
= 0;
58 while (stream
>> chunk
)
60 index_new
= str
.find(' ', index
);
61 VERIFY( !str
.compare(index
, index_new
- index
, chunk
) );
62 index
= index_new
+ 1;
64 wmemset(chunk
, L
'X', str
.size());
66 VERIFY( stream
.eof() );
67 VERIFY( n
== nchunks
);
72 // istream& operator>>(istream&, charT*)
75 const char filename
[] = "inserters_extractors-4.txt";
77 const unsigned nchunks
= 10;
78 const wstring data
= prepare(MAX_SIZE
, nchunks
);
81 ofstrm
.open(filename
);
82 ofstrm
.write(data
.data(), data
.size());
86 ifstrm
.open(filename
);
87 check(ifstrm
, data
, nchunks
);