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();
17 #include "test_macros.h"
19 template <class CharT
>
21 : public std::basic_streambuf
<CharT
>
23 typedef std::basic_string
<CharT
> string_type
;
24 typedef std::basic_streambuf
<CharT
> base
;
30 testbuf(const string_type
& str
)
33 base::setg(const_cast<CharT
*>(str_
.data()),
34 const_cast<CharT
*>(str_
.data()),
35 const_cast<CharT
*>(str_
.data()) + str_
.size());
38 CharT
* eback() const {return base::eback();}
39 CharT
* gptr() const {return base::gptr();}
40 CharT
* egptr() const {return base::egptr();}
46 testbuf
<char> sb(" 123456789");
53 assert(is
.gcount() == 0);
56 assert(is
.gcount() == 0);
59 assert(is
.gcount() == 0);
62 assert(is
.gcount() == 0);
64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
66 testbuf
<wchar_t> sb(L
" 123456789");
67 std::wistream
is(&sb
);
73 assert(is
.gcount() == 0);
76 assert(is
.gcount() == 0);
79 assert(is
.gcount() == 0);
82 assert(is
.gcount() == 0);
85 #ifndef TEST_HAS_NO_EXCEPTIONS
88 std::basic_istream
<char> is(&sb
);
89 is
.exceptions(std::ios_base::badbit
);
93 } catch (std::ios_base::failure
&) {
101 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
104 std::basic_istream
<wchar_t> is(&sb
);
105 is
.exceptions(std::ios_base::badbit
);
109 } catch (std::ios_base::failure
&) {
118 #endif // TEST_HAS_NO_EXCEPTIONS