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 //===----------------------------------------------------------------------===//
11 // streamsize readsome(char_type* s, streamsize n);
16 #include "test_macros.h"
18 template <class CharT
>
20 : public std::basic_streambuf
<CharT
>
22 typedef std::basic_string
<CharT
> string_type
;
23 typedef std::basic_streambuf
<CharT
> base
;
29 testbuf(const string_type
& str
)
32 base::setg(const_cast<CharT
*>(str_
.data()),
33 const_cast<CharT
*>(str_
.data()),
34 const_cast<CharT
*>(str_
.data()) + str_
.size());
37 CharT
* eback() const {return base::eback();}
38 CharT
* gptr() const {return base::gptr();}
39 CharT
* egptr() const {return base::egptr();}
45 testbuf
<char> sb(" 1234567890");
48 assert(is
.readsome(s
, 5) == 5);
51 assert(std::string(s
, 5) == " 1234");
52 assert(is
.gcount() == 5);
56 assert(std::string(s
, 5) == "56789");
57 assert(is
.gcount() == 5);
61 assert(is
.gcount() == 1);
62 assert(std::string(s
, 1) == "0");
63 assert(is
.readsome(s
, 5) == 0);
65 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
67 testbuf
<wchar_t> sb(L
" 1234567890");
68 std::wistream
is(&sb
);
70 assert(is
.readsome(s
, 5) == 5);
73 assert(std::wstring(s
, 5) == L
" 1234");
74 assert(is
.gcount() == 5);
78 assert(std::wstring(s
, 5) == L
"56789");
79 assert(is
.gcount() == 5);
83 assert(is
.gcount() == 1);
84 assert(std::wstring(s
, 1) == L
"0");
85 assert(is
.readsome(s
, 5) == 0);