1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <sstream>
10 
11 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12 // class basic_stringbuf
13 
14 // int_type underflow();
15 
16 #include <sstream>
17 #include <cassert>
18 
19 template <class CharT>
20 struct testbuf
21     : public std::basic_stringbuf<CharT>
22 {
23     typedef std::basic_stringbuf<CharT> base;
24     explicit testbuf(const std::basic_string<CharT>& str)
25         : base(str) {}
26 
27     typename base::int_type underflow() {return base::underflow();}
28     void pbump(int n) {base::pbump(n);}
29 };
30 
31 int main()
32 {
33     {
34         testbuf<char> sb("123");
35         sb.pbump(3);
36         assert(sb.underflow() == '1');
37         assert(sb.underflow() == '1');
38         assert(sb.snextc() == '2');
39         assert(sb.underflow() == '2');
40         assert(sb.underflow() == '2');
41         assert(sb.snextc() == '3');
42         assert(sb.underflow() == '3');
43         assert(sb.underflow() == '3');
44         assert(sb.snextc() == std::char_traits<char>::eof());
45         assert(sb.underflow() == std::char_traits<char>::eof());
46         assert(sb.underflow() == std::char_traits<char>::eof());
47         sb.sputc('4');
48         assert(sb.underflow() == '4');
49         assert(sb.underflow() == '4');
50     }
51     {
52         testbuf<wchar_t> sb(L"123");
53         sb.pbump(3);
54         assert(sb.underflow() == L'1');
55         assert(sb.underflow() == L'1');
56         assert(sb.snextc() == L'2');
57         assert(sb.underflow() == L'2');
58         assert(sb.underflow() == L'2');
59         assert(sb.snextc() == L'3');
60         assert(sb.underflow() == L'3');
61         assert(sb.underflow() == L'3');
62         assert(sb.snextc() == std::char_traits<wchar_t>::eof());
63         assert(sb.underflow() == std::char_traits<wchar_t>::eof());
64         assert(sb.underflow() == std::char_traits<wchar_t>::eof());
65         sb.sputc(L'4');
66         assert(sb.underflow() == L'4');
67         assert(sb.underflow() == L'4');
68     }
69 }
70