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 // template <class charT, class traits = char_traits<charT> >
12 // class basic_ostream;
14 // basic_ostream& write(const char_type* s, streamsize n);
19 #include "test_macros.h"
21 template <class CharT
>
23 : public std::basic_streambuf
<CharT
>
25 typedef std::basic_streambuf
<CharT
> base
;
26 std::basic_string
<CharT
> str_
;
32 std::basic_string
<CharT
> str() const
33 {return std::basic_string
<CharT
>(base::pbase(), base::pptr());}
37 virtual typename
base::int_type
38 overflow(typename
base::int_type ch
= base::traits_type::eof())
40 if (ch
!= base::traits_type::eof())
42 int n
= static_cast<int>(str_
.size());
43 str_
.push_back(static_cast<CharT
>(ch
));
44 str_
.resize(str_
.capacity());
45 base::setp(const_cast<CharT
*>(str_
.data()),
46 const_cast<CharT
*>(str_
.data() + str_
.size()));
56 std::ostream
os((std::streambuf
*)0);
57 const char s
[] = "123456790";
58 os
.write(s
, sizeof(s
)/sizeof(s
[0])-1);
64 const char s
[] = "123456790";
65 os
.write(s
, sizeof(s
)/sizeof(s
[0])-1);
66 assert(sb
.str() == s
);
69 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
71 std::wostream
os((std::wstreambuf
*)0);
72 const wchar_t s
[] = L
"123456790";
73 os
.write(s
, sizeof(s
)/sizeof(s
[0])-1);
78 std::wostream
os(&sb
);
79 const wchar_t s
[] = L
"123456790";
80 os
.write(s
, sizeof(s
)/sizeof(s
[0])-1);
82 assert(sb
.str() == s
);