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 // <strstream>
11 
12 // class strstreambuf
13 
14 // int_type underflow();
15 
16 #include <strstream>
17 #include <cassert>
18 
19 struct test
20     : public std::strstreambuf
21 {
22     typedef std::strstreambuf base;
testtest23     test(char* gnext_arg, std::streamsize n, char* pbeg_arg = 0)
24         : base(gnext_arg, n, pbeg_arg) {}
testtest25     test(const char* gnext_arg, std::streamsize n)
26         : base(gnext_arg, n) {}
27 
underflowtest28     base::int_type underflow() {return base::underflow();}
29 };
30 
main()31 int main()
32 {
33     {
34         char buf[10] = "123";
35         test sb(buf, 0, buf + 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() == EOF);
45         assert(sb.underflow() == EOF);
46         assert(sb.underflow() == EOF);
47         sb.sputc('4');
48         assert(sb.underflow() == '4');
49         assert(sb.underflow() == '4');
50     }
51 }
52