1 // Copyright (C) 2005 Free Software Foundation
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 2, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // 27.6.2.5.4 basic_ostream character inserters
23 #include <testsuite_hooks.h>
25 class test_buffer_1
: public std::wstreambuf
28 test_buffer_1(const std::wstring
& s
)
29 : str(s
), it(str
.begin()) { }
34 { return (it
!= str
.end() ? *it
: WEOF
); }
38 { return (it
!= str
.end() ? *it
++ : WEOF
); }
41 const std::wstring str
;
42 std::wstring::const_iterator it
;
46 class test_buffer_2
: public std::wstreambuf
49 test_buffer_2(const std::wstring
& s
)
50 : str(s
), it(str
.begin()) { }
55 { return (it
!= str
.end() ? *it
: WEOF
); }
59 { return (it
!= str
.end() ? *it
++ : WEOF
); }
61 virtual std::streamsize
63 { return std::distance(it
, str
.end()); }
66 const std::wstring str
;
67 std::wstring::const_iterator it
;
71 class test_buffer_3
: public std::wstreambuf
74 test_buffer_3(const std::wstring
& s
)
75 : str(s
), it(str
.begin()) { }
80 { return (it
!= str
.end() ? *it
: WEOF
); }
84 { return (it
!= str
.end() ? *it
++ : WEOF
); }
86 virtual std::streamsize
89 std::streamsize ret
= std::distance(it
, str
.end());
90 return ret
> 0 ? ret
: -1;
94 const std::wstring str
;
95 std::wstring::const_iterator it
;
98 class test_buffer_4
: public std::wstreambuf
101 test_buffer_4(const std::wstring
& s
)
102 : str(s
), it(str
.begin())
107 setg(buf
, buf
, buf
+1);
114 { return (it
!= str
.end() ? *it
: WEOF
); }
118 { return (it
!= str
.end() ? *it
++ : WEOF
); }
120 virtual std::streamsize
123 std::streamsize ret
= std::distance(it
, str
.end());
124 return ret
> 0 ? ret
: -1;
128 const std::wstring str
;
129 std::wstring::const_iterator it
;
133 void test(const std::wstring
& str
, std::wstreambuf
& buf
)
135 bool test
__attribute__((unused
)) = true;
137 std::wostringstream out
;
138 std::wistream
in(&buf
);
142 if (out
.str() != str
)
149 // Jonathan Lennox <lennox@cs.columbia.edu>
152 std::wstring
string_a(L
"Hello, world!");
153 std::wstring
string_b(L
"");
155 test_buffer_1
buf1a(string_a
);
156 test_buffer_1
buf1b(string_b
);
158 test_buffer_2
buf2a(string_a
);
159 test_buffer_2
buf2b(string_b
);
161 test_buffer_3
buf3a(string_a
);
162 test_buffer_3
buf3b(string_b
);
164 test_buffer_4
buf4a(string_a
);
165 test_buffer_4
buf4b(string_b
);
167 test(string_a
, buf1a
);
168 test(string_b
, buf1b
);
170 test(string_a
, buf2a
);
171 test(string_b
, buf2b
);
173 test(string_a
, buf3a
);
174 test(string_b
, buf3b
);
176 test(string_a
, buf4a
);
177 test(string_b
, buf4b
);