Debian Codegraph @

libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/1.cc

raw
1 // 1999-08-16 bkoz
2 // 1999-11-01 bkoz
3
4 // Copyright (C) 1999-2025 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
20
21 // C++98 27.6.2.5.3 basic_ostream inserters
22
23 // { dg-require-fileio "" }
24 // { dg-additional-files "ostream_inserter_other-1.tst" }
25 // { dg-additional-files "ostream_inserter_other-2.tst" }
26 // { dg-final { file-io-diff "ostream_inserter_other-1" } }
27 // { dg-final { file-io-diff "ostream_inserter_other-2" } }
28
29 #include <ostream>
30 #include <sstream>
31 #include <fstream>
32 #include <testsuite_hooks.h>
33
34 const int size = 1000;
35 const char name_01[] = "ostream_inserter_other-1.tst";
36 const char name_02[] = "ostream_inserter_other-1.txt";
37 const char name_03[] = "ostream_inserter_other-2.tst";
38 const char name_04[] = "ostream_inserter_other-2.txt";
39
40 // fstream
41 void
42 test02()
43 {
44 typedef std::ios_base::iostate iostate;
45
46 // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb)
47 // filebuf-> NULL
48 std::ifstream f_in1(name_01);
49 std::ofstream f_out1(name_02);
50 std::stringbuf* strbuf01 = 0;
51 iostate state01 = f_in1.rdstate();
52 f_in1 >> strbuf01;
53 iostate state02 = f_in1.rdstate();
54 VERIFY( state01 != state02 );
55 VERIFY( (state02 & std::ios_base::failbit) != 0 );
56 state01 = f_out1.rdstate();
57 f_out1 << strbuf01;
58 state02 = f_out1.rdstate();
59 VERIFY( state01 != state02 );
60 VERIFY( (state02 & std::ios_base::badbit) != 0 );
61
62 // filebuf->filebuf
63 std::ifstream f_in(name_01);
64 std::ofstream f_out(name_02);
65 f_out << f_in.rdbuf();
66 f_in.close();
67 f_out.close();
68
69 // filebuf->stringbuf->filebuf
70 std::ifstream f_in2(name_03);
71 std::ofstream f_out2(name_04); // should be different name
72 std::stringbuf strbuf02;
73 f_in2 >> &strbuf02;
74 f_out2 << &strbuf02;
75 f_in2.close();
76 f_out2.close();
77 }
78
79 int
80 main()
81 {
82 test02();
83 return 0;
84 }