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 // <strstream> 10 11 // class strstreambuf 12 13 // strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*)); 14 15 #include <strstream> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 int called = 0; 21 my_alloc(std::size_t)22void* my_alloc(std::size_t) 23 { 24 static char buf[10000]; 25 ++called; 26 return buf; 27 } 28 my_free(void *)29void my_free(void*) 30 { 31 ++called; 32 } 33 34 struct test 35 : std::strstreambuf 36 { testtest37 test(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*)) 38 : std::strstreambuf(palloc_arg, pfree_arg) {} overflowtest39 virtual int_type overflow(int_type c) 40 {return std::strstreambuf::overflow(c);} 41 }; 42 main(int,char **)43int main(int, char**) 44 { 45 { 46 test s(my_alloc, my_free); 47 assert(called == 0); 48 s.overflow('a'); 49 assert(called == 1); 50 } 51 assert(called == 2); 52 53 return 0; 54 } 55