blob: 12a1fb874c301d67e54fbcd33bd4a2d222644526 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <strstream>
11
12// class strstreambuf
13
14// strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
15
16#include <strstream>
17#include <cassert>
18
19int called = 0;
20
Dan Albert1d4a1ed2016-05-25 22:36:09 -070021void* my_alloc(std::size_t n)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022{
23 static char buf[10000];
24 ++called;
25 return buf;
26}
27
28void my_free(void*)
29{
30 ++called;
31}
32
33struct test
34 : std::strstreambuf
35{
36 test(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*))
37 : std::strstreambuf(palloc_arg, pfree_arg) {}
38 virtual int_type overflow(int_type c)
39 {return std::strstreambuf::overflow(c);}
40};
41
42int main()
43{
44 {
45 test s(my_alloc, my_free);
46 assert(called == 0);
47 s.overflow('a');
48 assert(called == 1);
49 }
50 assert(called == 2);
51}