/work/toxcore/mem_test_util.hh
Line | Count | Source |
1 | | #ifndef C_TOXCORE_TOXCORE_MEM_TEST_UTIL_H |
2 | | #define C_TOXCORE_TOXCORE_MEM_TEST_UTIL_H |
3 | | |
4 | | #include "mem.h" |
5 | | #include "test_util.hh" |
6 | | |
7 | | struct Memory_Class { |
8 | | static Memory_Funcs const vtable; |
9 | | Memory const self; |
10 | | |
11 | 480 | operator Memory const *() const { return &self; } |
12 | | |
13 | 404 | Memory_Class(Memory_Class const &) = default; |
14 | | Memory_Class() |
15 | | : self{&vtable, this} |
16 | 247 | { |
17 | 247 | } |
18 | | |
19 | | virtual ~Memory_Class(); |
20 | | virtual mem_malloc_cb malloc = 0; |
21 | | virtual mem_calloc_cb calloc = 0; |
22 | | virtual mem_realloc_cb realloc = 0; |
23 | | virtual mem_free_cb free = 0; |
24 | | }; |
25 | | |
26 | | /** |
27 | | * Base test Memory class that just forwards to os_memory. Can be |
28 | | * subclassed to override individual (or all) functions. |
29 | | */ |
30 | | class Test_Memory : public Memory_Class { |
31 | | const Memory *mem = REQUIRE_NOT_NULL(os_memory()); |
32 | | |
33 | | void *malloc(void *obj, uint32_t size) override; |
34 | | void *calloc(void *obj, uint32_t nmemb, uint32_t size) override; |
35 | | void *realloc(void *obj, void *ptr, uint32_t size) override; |
36 | | void free(void *obj, void *ptr) override; |
37 | | }; |
38 | | |
39 | | #endif // C_TOXCORE_TOXCORE_MEM_TEST_UTIL_H |