Coverage Report

Created: 2025-10-08 19:34

/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 "os_memory.h"
6
#include "test_util.hh"
7
#include "tox_memory_impl.h"
8
9
struct Memory_Class {
10
    static Tox_Memory_Funcs const vtable;
11
    Tox_Memory const self;
12
13
3.65k
    operator Tox_Memory const *() const { return &self; }
14
15
462
    Memory_Class(Memory_Class const &) = default;
16
    Memory_Class()
17
        : self{&vtable, this}
18
398
    {
19
398
    }
20
21
    virtual ~Memory_Class();
22
    virtual tox_memory_malloc_cb malloc = 0;
23
    virtual tox_memory_realloc_cb realloc = 0;
24
    virtual tox_memory_dealloc_cb dealloc = 0;
25
};
26
27
/**
28
 * Base test Memory class that just forwards to os_memory. Can be
29
 * subclassed to override individual (or all) functions.
30
 */
31
class Test_Memory : public Memory_Class {
32
    const Tox_Memory *mem = REQUIRE_NOT_NULL(os_memory());
33
34
    void *malloc(void *obj, uint32_t size) override;
35
    void *realloc(void *obj, void *ptr, uint32_t size) override;
36
    void dealloc(void *obj, void *ptr) override;
37
};
38
39
#endif  // C_TOXCORE_TOXCORE_MEM_TEST_UTIL_H