1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <sstream>
11 
12 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
13 // class basic_stringbuf
14 
15 // int_type underflow();
16 
17 #include <sstream>
18 #include <cassert>
19 
20 template <class CharT>
21 struct testbuf
22     : public std::basic_stringbuf<CharT>
23 {
24     typedef std::basic_stringbuf<CharT> base;
testbuftestbuf25     explicit testbuf(const std::basic_string<CharT>& str)
26         : base(str) {}
27 
underflowtestbuf28     typename base::int_type underflow() {return base::underflow();}
pbumptestbuf29     void pbump(int n) {base::pbump(n);}
30 };
31 
main()32 int main()
33 {
34     {
35         testbuf<char> sb("123");
36         sb.pbump(3);
37         assert(sb.underflow() == '1');
38         assert(sb.underflow() == '1');
39         assert(sb.snextc() == '2');
40         assert(sb.underflow() == '2');
41         assert(sb.underflow() == '2');
42         assert(sb.snextc() == '3');
43         assert(sb.underflow() == '3');
44         assert(sb.underflow() == '3');
45         assert(sb.snextc() == std::char_traits<char>::eof());
46         assert(sb.underflow() == std::char_traits<char>::eof());
47         assert(sb.underflow() == std::char_traits<char>::eof());
48         sb.sputc('4');
49         assert(sb.underflow() == '4');
50         assert(sb.underflow() == '4');
51     }
52     {
53         testbuf<wchar_t> sb(L"123");
54         sb.pbump(3);
55         assert(sb.underflow() == L'1');
56         assert(sb.underflow() == L'1');
57         assert(sb.snextc() == L'2');
58         assert(sb.underflow() == L'2');
59         assert(sb.underflow() == L'2');
60         assert(sb.snextc() == L'3');
61         assert(sb.underflow() == L'3');
62         assert(sb.underflow() == L'3');
63         assert(sb.snextc() == std::char_traits<wchar_t>::eof());
64         assert(sb.underflow() == std::char_traits<wchar_t>::eof());
65         assert(sb.underflow() == std::char_traits<wchar_t>::eof());
66         sb.sputc(L'4');
67         assert(sb.underflow() == L'4');
68         assert(sb.underflow() == L'4');
69     }
70 }
71