]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/ostream_inserter_other.cc
*.cc: Remove spaces, make sure testcases return zero.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / ostream_inserter_other.cc
CommitLineData
b2dad0e3
BK
1// 1999-08-16 bkoz
2// 1999-11-01 bkoz
3
96cbf48b 4// Copyright (C) 1999, 2000 Free Software Foundation
b2dad0e3
BK
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 2, 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 COPYING. If not, write to the Free
19// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20// USA.
21
22// 27.6.2.5.4 basic_ostream character inserters
db353c2c
GDR
23// @require@ %-*.tst %-*.txt
24// @diff@ %-*.tst %-*.txt
b2dad0e3
BK
25
26#include <ostream>
27#include <sstream>
28#include <fstream>
aa1b2f7d 29#include <debug_assert.h>
b2dad0e3
BK
30
31const int size = 1000;
db353c2c
GDR
32const char name_01[] = "ostream_inserter_other-1.tst";
33const char name_02[] = "ostream_inserter_other-1.txt";
34const char name_03[] = "ostream_inserter_other-2.tst";
35const char name_04[] = "ostream_inserter_other-2.txt";
b2dad0e3
BK
36
37
38// stringstream
aa1b2f7d
BV
39int
40test01()
41{
b2dad0e3
BK
42 bool test = true;
43#ifdef DEBUG_ASSERT
44 assert(test);
45#endif
aa1b2f7d 46 return 0;
b2dad0e3
BK
47}
48
49// fstream
aa1b2f7d
BV
50int
51test02()
52{
b2dad0e3
BK
53 typedef std::ios_base::iostate iostate;
54 bool test = true;
55
56 // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb)
57 // filebuf-> NULL
58 std::ifstream f_in1(name_01);
59 std::ofstream f_out1(name_02);
60 std::stringbuf* strbuf01 = NULL;
61 iostate state01 = f_in1.rdstate();
62 f_in1 >> strbuf01;
63 iostate state02 = f_in1.rdstate();
aa1b2f7d
BV
64 VERIFY( state01 != state02 );
65 VERIFY( (state02 & std::ios_base::failbit) != 0 );
b2dad0e3
BK
66 state01 = f_out1.rdstate();
67 f_out1 << strbuf01;
68 state02 = f_out1.rdstate();
aa1b2f7d
BV
69 VERIFY( state01 != state02 );
70 VERIFY( (state02 & std::ios_base::failbit) != 0 );
b2dad0e3
BK
71
72 // filebuf->filebuf
73 std::ifstream f_in(name_01);
74 std::ofstream f_out(name_02);
75 f_out << f_in.rdbuf();
76 f_in.close();
77 f_out.close();
78
79 // filebuf->stringbuf->filebuf
80 std::ifstream f_in2(name_03);
81 std::ofstream f_out2(name_04); // should be different name
82 std::stringbuf strbuf02;
83 f_in2 >> &strbuf02;
84 f_out2 << &strbuf02;
85 f_in2.close();
86 f_out2.close();
87
88 // no characters inserted
89
90#ifdef DEBUG_ASSERT
91 assert(test);
92#endif
aa1b2f7d
BV
93
94 return 0;
b2dad0e3
BK
95}
96
96cbf48b 97// via Brent Verner <brent@rcfile.org>
a9ab8db1 98// http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html
96cbf48b
BV
99int
100test03(void)
101{
102 using namespace std;
103
104 typedef ios::pos_type pos_type;
105
db353c2c
GDR
106 const char* TEST_IN = "ostream_inserter_other_in";
107 const char* TEST_OUT = "ostream_inserter_other_out";
96cbf48b
BV
108 pos_type i_read, i_wrote, rs, ws;
109 double tf_size = BUFSIZ * 2.5;
110 ofstream testfile(TEST_IN);
111
8901ac21 112 for (int i = 0; i < tf_size; ++i)
96cbf48b
BV
113 testfile.put('.');
114 testfile.close();
115
116 ifstream in(TEST_IN);
117 ofstream out(TEST_OUT);
118 out << in.rdbuf();
119 in.seekg(0,ios_base::beg);
120 out.seekp(0,ios_base::beg);
121 rs = in.tellg();
122 ws = out.tellp();
123 in.seekg(0,ios_base::end);
124 out.seekp(0,ios_base::end);
125 i_read = in.tellg() - rs;
126 i_wrote = out.tellp() - ws;
127 in.close();
128 out.close();
129
130#ifdef DEBUG_ASSERT
131 assert(i_read == i_wrote);
132#endif
133
134 return 0;
135}
136
aa1b2f7d
BV
137int
138main()
b2dad0e3
BK
139{
140 test01();
141 test02();
96cbf48b 142 test03();
b2dad0e3
BK
143
144 return 0;
145}