Blender V4.3
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
10#include "BLI_set.hh"
11
12#include "BLI_strict_flags.h" /* Keep last. */
13
15
16TEST(LinearAllocator_ChunkedList, Append)
17{
18 LinearAllocator<> allocator;
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
35TEST(LinearAllocator_ChunkedList, AppendMany)
36{
37 LinearAllocator<> allocator;
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
52TEST(LinearAllocator_ChunkedList, Move)
53{
54 LinearAllocator<> allocator;
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(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int64_t size() const
Definition BLI_set.hh:564
bool contains(const Key &key) const
Definition BLI_set.hh:291
bool add(const Key &key)
Definition BLI_set.hh:248
bool is_empty() const
Definition BLI_set.hh:572
void append(LinearAllocator<> &allocator, const T &value)
local_group_size(16, 16) .push_constant(Type b
__int64 int64_t
Definition stdint.h:89