1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx10.{{9|10|11|12|13|14}}
13 // basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb);
18 #include "test_macros.h"
20 template <class CharT
>
22 : public std::basic_streambuf
<CharT
>
24 typedef std::basic_streambuf
<CharT
> base
;
25 std::basic_string
<CharT
> str_
;
30 testbuf(const std::basic_string
<CharT
>& str
)
33 base::setg(const_cast<CharT
*>(str_
.data()),
34 const_cast<CharT
*>(str_
.data()),
35 const_cast<CharT
*>(str_
.data() + str_
.size()));
38 std::basic_string
<CharT
> str() const
39 {return std::basic_string
<CharT
>(base::pbase(), base::pptr());}
43 virtual typename
base::int_type
44 overflow(typename
base::int_type ch
= base::traits_type::eof())
46 if (ch
!= base::traits_type::eof())
48 int n
= static_cast<int>(str_
.size());
49 str_
.push_back(static_cast<CharT
>(ch
));
50 str_
.resize(str_
.capacity());
51 base::setp(const_cast<CharT
*>(str_
.data()),
52 const_cast<CharT
*>(str_
.data() + str_
.size()));
62 testbuf
<char> sb("testing\n...");
66 assert(sb2
.str() == "testing");
68 assert(is
.gcount() == 7);
69 assert(is
.get() == '\n');
71 assert(sb2
.str() == "testing...");
74 assert(is
.gcount() == 3);
76 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
78 testbuf
<wchar_t> sb(L
"testing\n...");
79 std::wistream
is(&sb
);
82 assert(sb2
.str() == L
"testing");
84 assert(is
.gcount() == 7);
85 assert(is
.get() == L
'\n');
87 assert(sb2
.str() == L
"testing...");
90 assert(is
.gcount() == 3);
93 #ifndef TEST_HAS_NO_EXCEPTIONS
95 testbuf
<char> sb(" ");
96 std::basic_istream
<char> is(&sb
);
98 is
.exceptions(std::ios_base::eofbit
);
102 } catch (std::ios_base::failure
&) {
110 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
112 testbuf
<wchar_t> sb(L
" ");
113 std::basic_istream
<wchar_t> is(&sb
);
114 testbuf
<wchar_t> sb2
;
115 is
.exceptions(std::ios_base::eofbit
);
119 } catch (std::ios_base::failure
&) {
131 std::basic_istream
<char> is(&sb
);
133 is
.exceptions(std::ios_base::eofbit
);
137 } catch (std::ios_base::failure
&) {
145 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
148 std::basic_istream
<wchar_t> is(&sb
);
149 testbuf
<wchar_t> sb2
;
150 is
.exceptions(std::ios_base::eofbit
);
154 } catch (std::ios_base::failure
&) {
163 #endif // TEST_HAS_NO_EXCEPTIONS