]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_ostream/inserters_other/wchar_t/4.cc
1 // Copyright (C) 2005-2013 Free Software Foundation, Inc.
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 3, 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 COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // 27.6.2.5.4 basic_ostream character inserters
22 #include <testsuite_hooks.h>
24 class test_buffer_1
: public std::wstreambuf
27 test_buffer_1(const std::wstring
& s
)
28 : str(s
), it(str
.begin()) { }
33 { return (it
!= str
.end() ? *it
: WEOF
); }
37 { return (it
!= str
.end() ? *it
++ : WEOF
); }
40 const std::wstring str
;
41 std::wstring::const_iterator it
;
45 class test_buffer_2
: public std::wstreambuf
48 test_buffer_2(const std::wstring
& s
)
49 : str(s
), it(str
.begin()) { }
54 { return (it
!= str
.end() ? *it
: WEOF
); }
58 { return (it
!= str
.end() ? *it
++ : WEOF
); }
60 virtual std::streamsize
62 { return std::distance(it
, str
.end()); }
65 const std::wstring str
;
66 std::wstring::const_iterator it
;
70 class test_buffer_3
: public std::wstreambuf
73 test_buffer_3(const std::wstring
& s
)
74 : str(s
), it(str
.begin()) { }
79 { return (it
!= str
.end() ? *it
: WEOF
); }
83 { return (it
!= str
.end() ? *it
++ : WEOF
); }
85 virtual std::streamsize
88 std::streamsize ret
= std::distance(it
, str
.end());
89 return ret
> 0 ? ret
: -1;
93 const std::wstring str
;
94 std::wstring::const_iterator it
;
97 class test_buffer_4
: public std::wstreambuf
100 test_buffer_4(const std::wstring
& s
)
101 : str(s
), it(str
.begin())
106 setg(buf
, buf
, buf
+1);
113 { return (it
!= str
.end() ? *it
: WEOF
); }
117 { return (it
!= str
.end() ? *it
++ : WEOF
); }
119 virtual std::streamsize
122 std::streamsize ret
= std::distance(it
, str
.end());
123 return ret
> 0 ? ret
: -1;
127 const std::wstring str
;
128 std::wstring::const_iterator it
;
132 void test(const std::wstring
& str
, std::wstreambuf
& buf
)
134 bool test
__attribute__((unused
)) = true;
136 std::wostringstream out
;
137 std::wistream
in(&buf
);
141 if (out
.str() != str
)
148 // Jonathan Lennox <lennox@cs.columbia.edu>
151 std::wstring
string_a(L
"Hello, world!");
152 std::wstring
string_b(L
"");
154 test_buffer_1
buf1a(string_a
);
155 test_buffer_1
buf1b(string_b
);
157 test_buffer_2
buf2a(string_a
);
158 test_buffer_2
buf2b(string_b
);
160 test_buffer_3
buf3a(string_a
);
161 test_buffer_3
buf3b(string_b
);
163 test_buffer_4
buf4a(string_a
);
164 test_buffer_4
buf4b(string_b
);
166 test(string_a
, buf1a
);
167 test(string_b
, buf1b
);
169 test(string_a
, buf2a
);
170 test(string_b
, buf2b
);
172 test(string_a
, buf3a
);
173 test(string_b
, buf3b
);
175 test(string_a
, buf4a
);
176 test(string_b
, buf4b
);