OSDN Git Service

2000-04-21 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.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 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
24 #include <ostream>
25 #include <sstream>
26 #include <fstream>
27 #ifdef DEBUG_ASSERT
28   #include <assert.h>
29 #endif
30
31 const int size = 1000;
32 const char name_01[] = "testsuite/ostream_inserter_other-1.tst";
33 const char name_02[] = "testsuite/ostream_inserter_other-1.txt";
34 const char name_03[] = "testsuite/ostream_inserter_other-2.tst";
35 const char name_04[] = "testsuite/ostream_inserter_other-2.txt";
36
37
38 // stringstream
39 bool test01() {
40   bool test = true;
41 #ifdef DEBUG_ASSERT
42   assert(test);
43 #endif
44   return test;
45 }
46
47 // fstream
48 bool test02() {
49   typedef std::ios_base::iostate iostate;
50   bool test = true;
51
52   // basic_ostream<_CharT, _Traits>::operator<<(__streambuf_type* __sb)
53   // filebuf-> NULL 
54   std::ifstream f_in1(name_01);
55   std::ofstream f_out1(name_02);
56   std::stringbuf* strbuf01 = NULL;
57   iostate state01 = f_in1.rdstate();
58   f_in1 >> strbuf01;
59   iostate state02 = f_in1.rdstate();
60   test &= state01 != state02;
61   test &= (state02 & std::ios_base::failbit) != 0;
62   state01 = f_out1.rdstate();
63   f_out1 << strbuf01;
64   state02 = f_out1.rdstate();
65   test &= state01 != state02;
66   test &= (state02 & std::ios_base::failbit) != 0;
67
68   // filebuf->filebuf
69   std::ifstream f_in(name_01);
70   std::ofstream f_out(name_02);
71   f_out << f_in.rdbuf();
72   f_in.close();
73   f_out.close();
74
75   // filebuf->stringbuf->filebuf
76   std::ifstream f_in2(name_03);
77   std::ofstream f_out2(name_04); // should be different name
78   std::stringbuf strbuf02;
79   f_in2 >> &strbuf02;
80   f_out2 << &strbuf02;
81   f_in2.close();
82   f_out2.close();
83
84   // no characters inserted
85
86 #ifdef DEBUG_ASSERT
87   assert(test);
88 #endif
89  
90   return test;
91 }
92
93 int main()
94 {
95   test01();
96   test02();
97
98   return 0;
99 }
100