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