Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 21 | void* my_alloc(std::size_t n) |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | { |
| 23 | static char buf[10000]; |
| 24 | ++called; |
| 25 | return buf; |
| 26 | } |
| 27 | |
| 28 | void my_free(void*) |
| 29 | { |
| 30 | ++called; |
| 31 | } |
| 32 | |
| 33 | struct 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 | |
| 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 | } |