• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
15 
16 #include <strstream>
17 #include <cassert>
18 
19 int called = 0;
20 
my_alloc(std::size_t)21 void* my_alloc(std::size_t)
22 {
23     static char buf[10000];
24     ++called;
25     return buf;
26 }
27 
my_free(void *)28 void my_free(void*)
29 {
30     ++called;
31 }
32 
33 struct test
34     : std::strstreambuf
35 {
testtest36     test(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*))
37         : std::strstreambuf(palloc_arg, pfree_arg) {}
overflowtest38     virtual int_type overflow(int_type c)
39         {return std::strstreambuf::overflow(c);}
40 };
41 
main()42 int 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 }
52