Blender
V4.3
source
blender
blenlib
tests
BLI_linear_allocator_chunked_list_test.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2024 Blender Authors
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include "testing/testing.h"
6
7
#include <iostream>
8
9
#include "
BLI_linear_allocator_chunked_list.hh
"
10
#include "
BLI_set.hh
"
11
12
#include "
BLI_strict_flags.h
"
/* Keep last. */
13
14
namespace
blender::linear_allocator::tests
{
15
16
TEST
(LinearAllocator_ChunkedList, Append)
17
{
18
LinearAllocator<>
allocator;
19
ChunkedList<std::string>
list;
20
21
list.
append
(allocator,
"1"
);
22
list.append(allocator,
"2"
);
23
list.append(allocator,
"this_is_an_extra_long_string"
);
24
25
Set<std::string>
retrieved_values;
26
for
(
const
std::string &value :
const_cast<
const
ChunkedList<std::string>
&
>
(list)) {
27
retrieved_values.
add
(value);
28
}
29
EXPECT_EQ
(retrieved_values.
size
(), 3);
30
EXPECT_TRUE(retrieved_values.
contains
(
"1"
));
31
EXPECT_TRUE(retrieved_values.
contains
(
"2"
));
32
EXPECT_TRUE(retrieved_values.
contains
(
"this_is_an_extra_long_string"
));
33
}
34
35
TEST
(LinearAllocator_ChunkedList, AppendMany)
36
{
37
LinearAllocator<>
allocator;
38
ChunkedList<int>
list;
39
40
for
(
const
int64_t
i :
IndexRange
(10000)) {
41
list.
append
(allocator,
int
(i));
42
}
43
44
Set<int>
values;
45
for
(
const
int
value : list) {
46
values.
add
(value);
47
}
48
49
EXPECT_EQ
(values.size(), 10000);
50
}
51
52
TEST
(LinearAllocator_ChunkedList, Move)
53
{
54
LinearAllocator<>
allocator;
55
ChunkedList<int>
a;
56
a.
append
(allocator, 1);
57
ChunkedList<int>
b
= std::move(a);
58
59
a.append(allocator, 2);
60
b
.append(allocator, 3);
61
62
{
63
Set<int>
a_values;
64
for
(
const
int
value : a) {
65
a_values.
add
(value);
66
}
67
Set<int>
b_values;
68
for
(
const
int
value :
b
) {
69
b_values.
add
(value);
70
}
71
72
EXPECT_EQ
(a_values.
size
(), 1);
73
EXPECT_TRUE(a_values.
contains
(2));
74
75
EXPECT_EQ
(b_values.
size
(), 2);
76
EXPECT_TRUE(b_values.
contains
(1));
77
EXPECT_TRUE(b_values.
contains
(3));
78
}
79
80
a = std::move(
b
);
81
/* Want to test self-move. Using std::move twice quiets a compiler warning. */
82
a = std::move(std::move(a));
83
84
{
85
Set<int>
a_values;
86
for
(
const
int
value : a) {
87
a_values.
add
(value);
88
}
89
Set<int>
b_values;
90
for
(
const
int
value :
b
) {
91
b_values.
add
(value);
92
}
93
94
EXPECT_EQ
(a_values.
size
(), 2);
95
EXPECT_TRUE(a_values.
contains
(1));
96
EXPECT_TRUE(a_values.
contains
(3));
97
98
EXPECT_TRUE(b_values.
is_empty
());
99
}
100
}
101
102
}
// namespace blender::linear_allocator::tests
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
BLI_linear_allocator_chunked_list.hh
BLI_set.hh
BLI_strict_flags.h
blender::IndexRange
Definition
BLI_index_range.hh:50
blender::LinearAllocator
Definition
BLI_linear_allocator.hh:27
blender::Set
Definition
BLI_set.hh:106
blender::Set::size
int64_t size() const
Definition
BLI_set.hh:564
blender::Set::contains
bool contains(const Key &key) const
Definition
BLI_set.hh:291
blender::Set::add
bool add(const Key &key)
Definition
BLI_set.hh:248
blender::Set::is_empty
bool is_empty() const
Definition
BLI_set.hh:572
blender::linear_allocator::ChunkedList
Definition
BLI_linear_allocator_chunked_list.hh:51
blender::linear_allocator::ChunkedList::append
void append(LinearAllocator<> &allocator, const T &value)
Definition
BLI_linear_allocator_chunked_list.hh:94
b
local_group_size(16, 16) .push_constant(Type b
Definition
compositor_morphological_distance_info.hh:16
blender::linear_allocator::tests
Definition
BLI_linear_allocator_chunked_list_test.cc:14
blender::linear_allocator::tests::TEST
TEST(LinearAllocator_ChunkedList, Append)
Definition
BLI_linear_allocator_chunked_list_test.cc:16
int64_t
__int64 int64_t
Definition
stdint.h:89
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0