Blender V4.3
BLI_pool_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
8#include "BLI_pool.hh"
9
10#include "BLI_strict_flags.h" /* Keep last. */
11
12namespace blender::tests {
13
14TEST(pool, DefaultConstructor)
15{
16 Pool<int> pool;
17 EXPECT_EQ(pool.size(), 0);
18}
19
20TEST(pool, Allocation)
21{
22 Vector<int *> ptrs;
23 Pool<int> pool;
24 for (int i = 0; i < 100; i++) {
25 ptrs.append(&pool.construct(i));
26 }
27 EXPECT_EQ(pool.size(), 100);
28
29 for (int *ptr : ptrs) {
30 pool.destruct(*ptr);
31 }
32 EXPECT_EQ(pool.size(), 0);
33}
34
35TEST(pool, Reuse)
36{
37 Vector<int *> ptrs;
38 Pool<int> pool;
39 for (int i = 0; i < 32; i++) {
40 ptrs.append(&pool.construct(i));
41 }
42
43 int *freed_ptr = ptrs[6];
44 pool.destruct(*freed_ptr);
45
46 ptrs[6] = &pool.construct(0);
47
48 EXPECT_EQ(ptrs[6], freed_ptr);
49
50 for (int *ptr : ptrs) {
51 pool.destruct(*ptr);
52 }
53}
54
55} // namespace blender::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void append(const T &value)
TEST(any, DefaultConstructor)
PointerRNA * ptr
Definition wm_files.cc:4126