]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/char/4.cc
4 // Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
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)
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.
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,
22 // 27.6.2.5.4 basic_ostream character inserters
23 // @require@ %-*.tst %-*.txt
24 // @diff@ %-*.tst %-*.txt
29 #include <testsuite_hooks.h>
31 class test_buffer_1
: public std::streambuf
34 test_buffer_1(const std::string
& s
) : str(s
), it(str
.begin()) { }
37 virtual int underflow() { return (it
!= str
.end() ? *it
: EOF
); }
38 virtual int uflow() { return (it
!= str
.end() ? *it
++ : EOF
); }
41 const std::string str
;
42 std::string::const_iterator it
;
46 class test_buffer_2
: public std::streambuf
49 test_buffer_2(const std::string
& s
) : str(s
), it(str
.begin()) { }
52 virtual int underflow() { return (it
!= str
.end() ? *it
: EOF
); }
53 virtual int uflow() { return (it
!= str
.end() ? *it
++ : EOF
); }
54 virtual std::streamsize
showmanyc() { return std::distance(it
, str
.end()); }
56 const std::string str
;
57 std::string::const_iterator it
;
61 class test_buffer_3
: public std::streambuf
64 test_buffer_3(const std::string
& s
) : str(s
), it(str
.begin()) { }
67 virtual int underflow() { return (it
!= str
.end() ? *it
: EOF
); }
68 virtual int uflow() { return (it
!= str
.end() ? *it
++ : EOF
); }
69 virtual std::streamsize
showmanyc()
71 std::streamsize ret
= std::distance(it
, str
.end());
72 return ret
> 0 ? ret
: -1;
75 const std::string str
;
76 std::string::const_iterator it
;
79 class test_buffer_4
: public std::streambuf
{
81 test_buffer_4(const std::string
& s
) : str(s
), it(str
.begin())
83 if (it
!= str
.end()) {
85 setg(buf
, buf
, buf
+1);
90 virtual int underflow() { return (it
!= str
.end() ? *it
: EOF
); }
91 virtual int uflow() { return (it
!= str
.end() ? *it
++ : EOF
); }
92 virtual std::streamsize
showmanyc() {
93 std::streamsize ret
= std::distance(it
, str
.end());
94 return ret
> 0 ? ret
: -1;
97 const std::string str
;
98 std::string::const_iterator it
;
102 void test(const std::string
& str
, std::streambuf
& buf
)
104 bool test
__attribute__((unused
)) = true;
106 std::ostringstream out
;
107 std::istream
in(&buf
);
111 if (out
.str() != str
)
118 // Jonathan Lennox <lennox@cs.columbia.edu>
121 std::string
string_a("Hello, world!");
122 std::string
string_b("");
124 test_buffer_1
buf1a(string_a
);
125 test_buffer_1
buf1b(string_b
);
127 test_buffer_2
buf2a(string_a
);
128 test_buffer_2
buf2b(string_b
);
130 test_buffer_3
buf3a(string_a
);
131 test_buffer_3
buf3b(string_b
);
133 test_buffer_4
buf4a(string_a
);
134 test_buffer_4
buf4b(string_b
);
136 test(string_a
, buf1a
);
137 test(string_b
, buf1b
);
139 test(string_a
, buf2a
);
140 test(string_b
, buf2b
);
142 test(string_a
, buf3a
);
143 test(string_b
, buf3b
);
145 test(string_a
, buf4a
);
146 test(string_b
, buf4b
);