acinclude.m4 (GLIBCPP_CONFIGURE_TESTSUITE): New macro, calls...
[gcc.git] / libstdc++-v3 / testsuite / 27_io / ostream_inserter_other.cc
1 // 1999-08-16 bkoz
2 // 1999-11-01 bkoz
3
4 // Copyright (C) 1999, 2000, 2001 Free Software Foundation
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
23 // @require@ %-*.tst %-*.txt
24 // @diff@ %-*.tst %-*.txt
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[] = "ostream_inserter_other-1.tst";
33 const char name_02[] = "ostream_inserter_other-1.txt";
34 const char name_03[] = "ostream_inserter_other-2.tst";
35 const char name_04[] = "ostream_inserter_other-2.txt";
36
37
38 // stringstream
39 int
40 test01()
41 {
42 bool test = true;
43 #ifdef DEBUG_ASSERT
44 assert(test);
45 #endif
46 return 0;
47 }
48
49 // fstream
50 int
51 test02()
52 {
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();
64 VERIFY( state01 != state02 );
65 VERIFY( (state02 & std::ios_base::failbit) != 0 );
66 state01 = f_out1.rdstate();
67 f_out1 << strbuf01;
68 state02 = f_out1.rdstate();
69 VERIFY( state01 != state02 );
70 VERIFY( (state02 & std::ios_base::failbit) != 0 );
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
93
94 return 0;
95 }
96
97 // via Brent Verner <brent@rcfile.org>
98 // http://gcc.gnu.org/ml/libstdc++/2000-06/msg00005.html
99 int
100 test03(void)
101 {
102 using namespace std;
103
104 typedef ios::pos_type pos_type;
105
106 const char* TEST_IN = "ostream_inserter_other_in";
107 const char* TEST_OUT = "ostream_inserter_other_out";
108 pos_type i_read, i_wrote, rs, ws;
109 double tf_size = BUFSIZ * 2.5;
110 ofstream testfile(TEST_IN);
111
112 for (int i = 0; i < tf_size; ++i)
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
137 // libstdc++/3272
138 void test04()
139 {
140 using namespace std;
141 bool test = true;
142 istringstream istr("inside betty carter");
143 ostringstream ostr;
144 ostr << istr.rdbuf() << endl;
145
146 if (ostr.rdstate() & ios_base::eofbit)
147 test = false;
148
149 VERIFY( test );
150 }
151
152 int
153 main()
154 {
155 test01();
156 test02();
157 test03();
158
159 return 0;
160 }