Blender
V5.0
source
blender
blenlib
tests
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
7
#include "
BLI_exception_safety_test_utils.hh
"
8
#include "
BLI_pool.hh
"
9
10
#include "
BLI_strict_flags.h
"
/* IWYU pragma: keep. Keep last. */
11
12
namespace
blender::tests
{
13
14
TEST
(pool, DefaultConstructor)
15
{
16
Pool<int>
pool;
17
EXPECT_EQ
(pool.
size
(), 0);
18
}
19
20
TEST
(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
35
TEST
(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
BLI_exception_safety_test_utils.hh
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
BLI_pool.hh
BLI_strict_flags.h
blender::Pool
Definition
BLI_pool.hh:24
blender::Pool::destruct
void destruct(T &value)
Definition
BLI_pool.hh:63
blender::Pool::size
int64_t size() const
Definition
BLI_pool.hh:72
blender::Pool::construct
T & construct(ForwardT &&...value)
Definition
BLI_pool.hh:45
blender::Vector
Definition
BLI_vector.hh:76
blender::Vector::append
void append(const T &value)
Definition
BLI_vector.hh:489
blender::tests
Definition
BLF_tests.cc:9
blender::tests::TEST
TEST(blf_load, load)
Definition
BLF_tests.cc:34
i
i
Definition
text_draw.cc:230
ptr
PointerRNA * ptr
Definition
wm_files.cc:4238
Generated on
for Blender by
doxygen
1.16.1