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 // Requires 396145d in the built library.
10 // XFAIL: using-built-library-before-llvm-9
14 // basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb);
20 #include "test_macros.h"
22 template <class CharT
>
24 : public std::basic_streambuf
<CharT
>
26 typedef std::basic_streambuf
<CharT
> base
;
27 std::basic_string
<CharT
> str_
;
32 testbuf(const std::basic_string
<CharT
>& str
)
35 base::setg(const_cast<CharT
*>(str_
.data()),
36 const_cast<CharT
*>(str_
.data()),
37 const_cast<CharT
*>(str_
.data() + str_
.size()));
40 std::basic_string
<CharT
> str() const
41 {return std::basic_string
<CharT
>(base::pbase(), base::pptr());}
45 virtual typename
base::int_type
46 overflow(typename
base::int_type ch
= base::traits_type::eof())
48 if (ch
!= base::traits_type::eof())
50 int n
= static_cast<int>(str_
.size());
51 str_
.push_back(static_cast<CharT
>(ch
));
52 str_
.resize(str_
.capacity());
53 base::setp(const_cast<CharT
*>(str_
.data()),
54 const_cast<CharT
*>(str_
.data() + str_
.size()));
64 testbuf
<char> sb("testing\n...");
68 assert(sb2
.str() == "testing");
70 assert(is
.gcount() == 7);
71 assert(is
.get() == '\n');
73 assert(sb2
.str() == "testing...");
76 assert(is
.gcount() == 3);
78 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
80 testbuf
<wchar_t> sb(L
"testing\n...");
81 std::wistream
is(&sb
);
84 assert(sb2
.str() == L
"testing");
86 assert(is
.gcount() == 7);
87 assert(is
.get() == L
'\n');
89 assert(sb2
.str() == L
"testing...");
92 assert(is
.gcount() == 3);
95 #ifndef TEST_HAS_NO_EXCEPTIONS
97 testbuf
<char> sb(" ");
98 std::basic_istream
<char> is(&sb
);
100 is
.exceptions(std::ios_base::eofbit
);
104 } catch (std::ios_base::failure
&) {
112 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
114 testbuf
<wchar_t> sb(L
" ");
115 std::basic_istream
<wchar_t> is(&sb
);
116 testbuf
<wchar_t> sb2
;
117 is
.exceptions(std::ios_base::eofbit
);
121 } catch (std::ios_base::failure
&) {
133 std::basic_istream
<char> is(&sb
);
135 is
.exceptions(std::ios_base::eofbit
);
139 } catch (std::ios_base::failure
&) {
147 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
150 std::basic_istream
<wchar_t> is(&sb
);
151 testbuf
<wchar_t> sb2
;
152 is
.exceptions(std::ios_base::eofbit
);
156 } catch (std::ios_base::failure
&) {
165 #endif // TEST_HAS_NO_EXCEPTIONS