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 //===----------------------------------------------------------------------===//
16 #include "test_macros.h"
20 template <class CharT
>
22 : public std::basic_streambuf
<CharT
>
24 typedef std::basic_string
<CharT
> string_type
;
25 typedef std::basic_streambuf
<CharT
> base
;
31 testbuf(const string_type
& str
)
34 base::setg(const_cast<CharT
*>(str_
.data()),
35 const_cast<CharT
*>(str_
.data()),
36 const_cast<CharT
*>(str_
.data()) + str_
.size());
39 CharT
* eback() const {return base::eback();}
40 CharT
* gptr() const {return base::gptr();}
41 CharT
* egptr() const {return base::egptr();}
51 #ifndef TEST_HAS_NO_EXCEPTIONS
52 struct testbuf_exception
{ };
54 template <class CharT
>
55 struct throwing_testbuf
56 : public std::basic_streambuf
<CharT
>
58 typedef std::basic_string
<CharT
> string_type
;
59 typedef std::basic_streambuf
<CharT
> base
;
65 throwing_testbuf(const string_type
& str
)
68 base::setg(const_cast<CharT
*>(str_
.data()),
69 const_cast<CharT
*>(str_
.data()),
70 const_cast<CharT
*>(str_
.data()) + str_
.size());
73 CharT
* eback() const {return base::eback();}
74 CharT
* gptr() const {return base::gptr();}
75 CharT
* egptr() const {return base::egptr();}
80 throw testbuf_exception();
84 #endif // TEST_HAS_NO_EXCEPTIONS
89 testbuf
<char> sb(" 123456789");
91 assert(is
.sync() == 0);
92 assert(sync_called
== 1);
94 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
96 testbuf
<wchar_t> sb(L
" 123456789");
97 std::wistream
is(&sb
);
98 assert(is
.sync() == 0);
99 assert(sync_called
== 2);
102 #ifndef TEST_HAS_NO_EXCEPTIONS
104 throwing_testbuf
<char> sb(" 123456789");
105 std::basic_istream
<char> is(&sb
);
106 is
.exceptions(std::ios_base::badbit
);
110 } catch (testbuf_exception
const&) {
118 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
120 throwing_testbuf
<wchar_t> sb(L
" 123456789");
121 std::basic_istream
<wchar_t> is(&sb
);
122 is
.exceptions(std::ios_base::badbit
);
126 } catch (testbuf_exception
const&) {
135 #endif // TEST_HAS_NO_EXCEPTIONS