Blender V4.3
BLI_memory_counter_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
7
8#include "testing/testing.h"
9
10#include "BLI_strict_flags.h" /* Keep last. */
11
12namespace blender::tests {
13
14TEST(memory_counter, Simple)
15{
16 MemoryCount memory_count;
17 MemoryCounter memory{memory_count};
18 EXPECT_EQ(memory_count.total_bytes, 0);
19 memory.add(10);
20 EXPECT_EQ(memory_count.total_bytes, 10);
21 memory.add(10);
22 EXPECT_EQ(memory_count.total_bytes, 20);
23
24 const int alloc_size = 100;
25 void *data1 = MEM_mallocN(alloc_size, __func__);
26 void *data2 = MEM_mallocN(alloc_size, __func__);
29
30 memory.add_shared(sharing_info1.get(), alloc_size);
31 EXPECT_EQ(memory_count.total_bytes, 120);
32
33 memory.add_shared(sharing_info1.get(), [&](MemoryCounter & /*shared_memory*/) { FAIL(); });
34 EXPECT_EQ(memory_count.total_bytes, 120);
35
36 memory.add_shared(sharing_info2.get(),
37 [&](MemoryCounter &shared_memory) { shared_memory.add(alloc_size); });
38 EXPECT_EQ(memory_count.total_bytes, 220);
39
40 memory.add_shared(nullptr, 1000);
41 EXPECT_EQ(memory_count.total_bytes, 1220);
42
43 memory.add_shared(nullptr, 1000);
44 EXPECT_EQ(memory_count.total_bytes, 2220);
45}
46
47} // namespace blender::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
const ImplicitSharingInfo * info_for_mem_free(void *data)
TEST(any, DefaultConstructor)