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 // basic_istream<charT,traits>& unget();
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(" 123456789");
52 assert(is
.gcount() == 0);
55 assert(is
.gcount() == 0);
58 assert(is
.gcount() == 0);
61 assert(is
.gcount() == 0);
63 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
65 testbuf
<wchar_t> sb(L
" 123456789");
66 std::wistream
is(&sb
);
72 assert(is
.gcount() == 0);
75 assert(is
.gcount() == 0);
78 assert(is
.gcount() == 0);
81 assert(is
.gcount() == 0);
84 #ifndef TEST_HAS_NO_EXCEPTIONS
87 std::basic_istream
<char> is(&sb
);
88 is
.exceptions(std::ios_base::badbit
);
92 } catch (std::ios_base::failure
&) {
100 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
103 std::basic_istream
<wchar_t> is(&sb
);
104 is
.exceptions(std::ios_base::badbit
);
108 } catch (std::ios_base::failure
&) {
117 #endif // TEST_HAS_NO_EXCEPTIONS