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 pbackfail(int_type c = EOF); 15 16#include <strstream> 17#include <cassert> 18 19struct test 20 : public std::strstreambuf 21{ 22 typedef std::strstreambuf base; 23 test(char* gnext_arg, std::streamsize n, char* pbeg_arg = 0) 24 : base(gnext_arg, n, pbeg_arg) {} 25 test(const char* gnext_arg, std::streamsize n) 26 : base(gnext_arg, n) {} 27 28 virtual int_type pbackfail(int_type c = EOF) {return base::pbackfail(c);} 29}; 30 31int main() 32{ 33 { 34 const char buf[] = "123"; 35 test sb(buf, 0); 36 assert(sb.sgetc() == '1'); 37 assert(sb.snextc() == '2'); 38 assert(sb.snextc() == '3'); 39 assert(sb.sgetc() == '3'); 40 assert(sb.snextc() == EOF); 41 assert(sb.pbackfail('3') == '3'); 42 assert(sb.pbackfail('3') == EOF); 43 assert(sb.pbackfail('2') == '2'); 44 assert(sb.pbackfail(EOF) != EOF); 45 assert(sb.pbackfail(EOF) == EOF); 46 assert(sb.str() == std::string("123")); 47 } 48 { 49 char buf[] = "123"; 50 test sb(buf, 0); 51 assert(sb.sgetc() == '1'); 52 assert(sb.snextc() == '2'); 53 assert(sb.snextc() == '3'); 54 assert(sb.sgetc() == '3'); 55 assert(sb.snextc() == EOF); 56 assert(sb.pbackfail('3') == '3'); 57 assert(sb.pbackfail('3') == '3'); 58 assert(sb.pbackfail(EOF) != EOF); 59 assert(sb.pbackfail(EOF) == EOF); 60 assert(sb.str() == std::string("133")); 61 } 62} 63