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>& read(char_type* s, streamsize n);
20 #include "test_macros.h"
22 template <class CharT
>
24 : public std::basic_streambuf
<CharT
>
26 typedef std::basic_string
<CharT
> string_type
;
27 typedef std::basic_streambuf
<CharT
> base
;
33 testbuf(const string_type
& str
)
36 base::setg(const_cast<CharT
*>(str_
.data()),
37 const_cast<CharT
*>(str_
.data()),
38 const_cast<CharT
*>(str_
.data()) + str_
.size());
41 CharT
* eback() const {return base::eback();}
42 CharT
* gptr() const {return base::gptr();}
43 CharT
* egptr() const {return base::egptr();}
49 testbuf
<char> sb(" 123456789");
55 assert(std::string(s
, 5) == " 1234");
56 assert(is
.gcount() == 5);
60 assert(std::string(s
, 5) == "56789");
61 assert(is
.gcount() == 5);
65 assert(is
.gcount() == 0);
67 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
69 testbuf
<wchar_t> sb(L
" 123456789");
70 std::wistream
is(&sb
);
75 assert(std::wstring(s
, 5) == L
" 1234");
76 assert(is
.gcount() == 5);
80 assert(std::wstring(s
, 5) == L
"56789");
81 assert(is
.gcount() == 5);
85 assert(is
.gcount() == 0);
88 #ifndef TEST_HAS_NO_EXCEPTIONS
91 std::basic_istream
<char> is(&sb
);
92 is
.exceptions(std::ios_base::eofbit
);
97 } catch (std::ios_base::failure
&) {
105 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
108 std::basic_istream
<wchar_t> is(&sb
);
109 is
.exceptions(std::ios_base::eofbit
);
114 } catch (std::ios_base::failure
&) {
123 #endif // TEST_HAS_NO_EXCEPTIONS