]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/ostream_inserter_char.cc
3 // Copyright (C) 2000, 1999 Free Software Foundation
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 27.6.2.5.4 basic_ostream character inserters
27 #include <testsuite_hooks.h>
34 const int size
= 1000;
35 const char name_02
[] = "ostream_inserter_char-1.txt";
38 for(int i
=0 ; i
< size
; i
++) {
50 std::ofstream
f(name_02
);
62 // ostringstream width() != zero
69 std::string str01
= "";
70 std::ostringstream oss01
;
73 oss01
.flags(std::ios_base::left
);
76 VERIFY( tmp
== "00000" );
78 std::string str02
= "1";
79 std::ostringstream oss02
;
82 oss02
.flags(std::ios_base::left
);
85 VERIFY( tmp
== "10000" );
87 std::string str03
= "909909";
88 std::ostringstream oss03
;
91 oss03
.flags(std::ios_base::left
);
94 VERIFY( tmp
== "909909" );
110 std::string str01
= "";
111 std::ostringstream oss01
;
114 oss01
.flags(std::ios_base::right
);
117 VERIFY( tmp
== "00000" );
119 std::string str02
= "1";
120 std::ostringstream oss02
;
123 oss02
.flags(std::ios_base::right
);
126 VERIFY( tmp
== "00001" );
128 std::string str03
= "909909";
129 std::ostringstream oss03
;
132 oss03
.flags(std::ios_base::right
);
135 VERIFY( tmp
== "909909" );
144 // stringstream and large strings
149 const std::string
str_02("coltrane playing 'softly as a morning sunrise'");
150 const std::string
str_03("coltrane");
154 std::ostringstream
oss_01(std::ios_base::out
);
155 std::ostringstream
oss_02(str_01
, std::ios_base::out
);
157 std::ios_base::iostate state1
, state2
, statefail
;
158 statefail
= std::ios_base::failbit
;
160 // template<_CharT, _Traits>
161 // basic_ostream& operator<<(ostream&, const char*)
162 for (int i
= 0; i
< i_max
; ++i
)
163 oss_02
<< "Test: " << i
<< std::endl
;
164 str_tmp
= oss_02
.str();
165 VERIFY( !oss_02
.bad() );
166 VERIFY( oss_02
.good() );
167 VERIFY( str_tmp
!= str_01
);
168 VERIFY( str_tmp
.size() == 2390 );
177 // ostringstream and large strings number 2
181 std::string str05
, str10
;
183 typedef std::ostream::pos_type pos_type
;
184 typedef std::ostream::off_type off_type
;
186 const int size
= 1000;
189 for(int i
=0 ; i
< size
; i
++) {
203 std::ostringstream
sstr01(str01
, std::ios_base::out
);
204 std::ostringstream sstr02
;
206 str05
= sstr01
.str();
207 str10
= sstr02
.str();
208 VERIFY( str05
== str01
);
209 VERIFY( str10
== str01
);
212 std::ostringstream
sstr04(str01
, std::ios_base::out
| std::ios_base::in
);
213 std::ostringstream
sstr05(std::ios_base::in
| std::ios_base::out
);
215 str05
= sstr04
.str();
216 str10
= sstr05
.str();
217 VERIFY( str05
== str01
);
218 VERIFY( str10
== str01
);
228 // ostringstream and positioning, multiple writes
229 // http://gcc.gnu.org/ml/libstdc++/2000-q1/msg00326.html
233 const char carray01
[] = "mos def & talib kweli are black star";
236 std::ostringstream
ostr1("mos def");
237 VERIFY( ostr1
.str() == "mos def" );
238 ostr1
<< " & talib kweli"; // should overwrite first part of buffer
239 VERIFY( ostr1
.str() == " & talib kweli" );
240 ostr1
<< " are black star"; // should append to string from above
241 VERIFY( ostr1
.str() != carray01
);
242 VERIFY( ostr1
.str() == " & talib kweli are black star" );
245 std::ostringstream
ostr2("blackalicious",
246 std::ios_base::out
| std::ios_base::ate
);
247 VERIFY( ostr2
.str() == "blackalicious" );
248 ostr2
<< " NIA "; // should not overwrite first part of buffer
249 VERIFY( ostr2
.str() == "blackalicious NIA " );
250 ostr2
<< "4: deception (5:19)"; // should append to full string from above
251 VERIFY( ostr2
.str() == "blackalicious NIA 4: deception (5:19)" );