1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // streamsize readsome(char_type* s, streamsize n);
17 template <class CharT>
19 : public std::basic_streambuf<CharT>
21 typedef std::basic_string<CharT> string_type;
22 typedef std::basic_streambuf<CharT> base;
28 testbuf(const string_type& str)
31 base::setg(const_cast<CharT*>(str_.data()),
32 const_cast<CharT*>(str_.data()),
33 const_cast<CharT*>(str_.data()) + str_.size());
36 CharT* eback() const {return base::eback();}
37 CharT* gptr() const {return base::gptr();}
38 CharT* egptr() const {return base::egptr();}
44 testbuf<char> sb(" 1234567890");
47 assert(is.readsome(s, 5) == 5);
50 assert(std::string(s, 5) == " 1234");
51 assert(is.gcount() == 5);
55 assert(std::string(s, 5) == "56789");
56 assert(is.gcount() == 5);
60 assert(is.gcount() == 1);
61 assert(std::string(s, 1) == "0");
62 assert(is.readsome(s, 5) == 0);
65 testbuf<wchar_t> sb(L" 1234567890");
66 std::wistream is(&sb);
68 assert(is.readsome(s, 5) == 5);
71 assert(std::wstring(s, 5) == L" 1234");
72 assert(is.gcount() == 5);
76 assert(std::wstring(s, 5) == L"56789");
77 assert(is.gcount() == 5);
81 assert(is.gcount() == 1);
82 assert(std::wstring(s, 1) == L"0");
83 assert(is.readsome(s, 5) == 0);