| 1 |
// Copyright (C) 2005-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 |
// C++98 27.6.2.5.3 basic_ostream inserters |
| 19 |
|
| 20 |
// { dg-require-fileio "" } |
| 21 |
// { dg-additional-files "wostream_inserter_other-1.tst" } |
| 22 |
// { dg-additional-files "wostream_inserter_other-2.tst" } |
| 23 |
// { dg-final { file-io-diff "wostream_inserter_other-1" } } |
| 24 |
// { dg-final { file-io-diff "wostream_inserter_other-2" } } |
| 25 |
|
| 26 |
#include <ostream> |
| 27 |
#include <sstream> |
| 28 |
#include <fstream> |
| 29 |
#include <testsuite_hooks.h> |
| 30 |
|
| 31 |
const int size = 1000; |
| 32 |
const char name_01[] = "wostream_inserter_other-1.tst"; |
| 33 |
const char name_02[] = "wostream_inserter_other-1.txt"; |
| 34 |
const char name_03[] = "wostream_inserter_other-2.tst"; |
| 35 |
const char name_04[] = "wostream_inserter_other-2.txt"; |
| 36 |
|
| 37 |
// fstream |
| 38 |
void |
| 39 |
test02() |
| 40 |
{ |
| 41 |
typedef std::ios_base::iostate iostate; |
| 42 |
|
| 43 |
// basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb) |
| 44 |
// filebuf-> NULL |
| 45 |
std::wifstream f_in1(name_01); |
| 46 |
std::wofstream f_out1(name_02); |
| 47 |
std::wstringbuf* strbuf01 = 0; |
| 48 |
iostate state01 = f_in1.rdstate(); |
| 49 |
f_in1 >> strbuf01; |
| 50 |
iostate state02 = f_in1.rdstate(); |
| 51 |
VERIFY( state01 != state02 ); |
| 52 |
VERIFY( (state02 & std::ios_base::failbit) != 0 ); |
| 53 |
state01 = f_out1.rdstate(); |
| 54 |
f_out1 << strbuf01; |
| 55 |
state02 = f_out1.rdstate(); |
| 56 |
VERIFY( state01 != state02 ); |
| 57 |
VERIFY( (state02 & std::ios_base::badbit) != 0 ); |
| 58 |
|
| 59 |
// filebuf->filebuf |
| 60 |
std::wifstream f_in(name_01); |
| 61 |
std::wofstream f_out(name_02); |
| 62 |
f_out << f_in.rdbuf(); |
| 63 |
f_in.close(); |
| 64 |
f_out.close(); |
| 65 |
|
| 66 |
// filebuf->stringbuf->filebuf |
| 67 |
std::wifstream f_in2(name_03); |
| 68 |
std::wofstream f_out2(name_04); // should be different name |
| 69 |
std::wstringbuf strbuf02; |
| 70 |
f_in2 >> &strbuf02; |
| 71 |
f_out2 << &strbuf02; |
| 72 |
f_in2.close(); |
| 73 |
f_out2.close(); |
| 74 |
} |
| 75 |
|
| 76 |
int |
| 77 |
main() |
| 78 |
{ |
| 79 |
test02(); |
| 80 |
return 0; |
| 81 |
} |