#include "include/core/SkTypes.h"
#include "include/private/base/SkAlign.h"
#include "src/base/SkBlockAllocator.h"
#include "src/base/SkTBlockList.h"
#include "tests/Test.h"
#include <cstddef>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <utility>
#include <vector>
Go to the source code of this file.
|
template<int N> |
static void | check_allocator_helper (SkTBlockList< C, N > *allocator, int cnt, int popCnt, skiatest::Reporter *reporter) |
|
template<int N> |
static void | check_iterator_helper (SkTBlockList< C, N > *allocator, const std::vector< C * > &expected, skiatest::Reporter *reporter) |
|
template<int N> |
static void | check_allocator (SkTBlockList< C, N > *allocator, int cnt, int popCnt, skiatest::Reporter *reporter) |
|
template<int N> |
static void | run_allocator_test (SkTBlockList< C, N > *allocator, skiatest::Reporter *reporter) |
|
template<int N1, int N2> |
static void | run_concat_test (skiatest::Reporter *reporter, int aCount, int bCount) |
|
template<int N1, int N2> |
static void | run_concat_trivial_test (skiatest::Reporter *reporter, int aCount, int bCount) |
|
template<int N> |
static void | run_reserve_test (skiatest::Reporter *reporter) |
|
void | run_large_increment_test (skiatest::Reporter *reporter) |
|
| DEF_TEST (SkTBlockList, reporter) |
|
◆ check_allocator()
Definition at line 142 of file SkTBlockListTest.cpp.
143 {
144 enum ItemInitializer : int {
145 kCopyCtor,
146 kMoveCtor,
147 kCopyAssign,
148 kMoveAssign,
149 kEmplace,
150 };
151 static constexpr int kInitCount = (
int) kEmplace + 1;
152
155 std::vector<C*> items;
156 for (int i = 0; i < cnt; ++i) {
157 switch((ItemInitializer) (i % kInitCount)) {
158 case kCopyCtor:
160 break;
161 case kMoveCtor:
163 break;
164 case kCopyAssign:
166 break;
167 case kMoveAssign:
169 break;
170 case kEmplace:
172 break;
173 }
174 items.push_back(&allocator->
back());
175 }
181}
static void check_allocator_helper(SkTBlockList< C, N > *allocator, int cnt, int popCnt, skiatest::Reporter *reporter)
static void check_iterator_helper(SkTBlockList< C, N > *allocator, const std::vector< C * > &expected, skiatest::Reporter *reporter)
Type::kYUV Type::kRGBA() int(0.7 *637)
T & emplace_back(Args &&... args)
◆ check_allocator_helper()
Definition at line 68 of file SkTBlockListTest.cpp.
69 {
73
74 int i = 0;
75 for (
const C& c : allocator->items()) {
78 ++i;
79 }
81
82 if (cnt > 0) {
84 }
85
86 if (popCnt > 0) {
87 for (i = 0; i < popCnt; ++i) {
89 }
91 }
92}
#define REPORTER_ASSERT(r, cond,...)
◆ check_iterator_helper()
Definition at line 95 of file SkTBlockListTest.cpp.
97 {
100
101 int i = 0;
102 for (
const C& c : cAlloc->items()) {
104 ++i;
105 }
107
108
109 i = 0;
110 for (
C& c : allocator->items()) {
112 ++i;
113 }
115
116
117 i = (
int) expected.size() - 1;
118 for (
const C& c : cAlloc->ritems()) {
120 --i;
121 }
123
124
125 i = (
int) expected.size() - 1;
126 for (
C& c : allocator->ritems()) {
128 --i;
129 }
131
132
133 for (i = 0; i < allocator->
count(); ++i) {
136 }
137}
◆ DEF_TEST()
Definition at line 329 of file SkTBlockListTest.cpp.
329 {
330
333
336
339
342
345
348
354
355 run_concat_test<1, 1>(
reporter, 10, 10);
356 run_concat_test<5, 1>(
reporter, 50, 10);
357 run_concat_test<1, 5>(
reporter, 10, 50);
358 run_concat_test<5, 5>(
reporter, 100, 100);
359
360 run_concat_trivial_test<1, 1>(
reporter, 10, 10);
361 run_concat_trivial_test<5, 1>(
reporter, 50, 10);
362 run_concat_trivial_test<1, 5>(
reporter, 10, 50);
363 run_concat_trivial_test<5, 5>(
reporter, 100, 100);
364
366}
void run_large_increment_test(skiatest::Reporter *reporter)
static void run_allocator_test(SkTBlockList< C, N > *allocator, skiatest::Reporter *reporter)
◆ run_allocator_test()
Definition at line 184 of file SkTBlockListTest.cpp.
184 {
192}
static void check_allocator(SkTBlockList< C, N > *allocator, int cnt, int popCnt, skiatest::Reporter *reporter)
◆ run_concat_test()
Definition at line 195 of file SkTBlockListTest.cpp.
195 {
196
199
200 for (int i = 0; i < aCount; ++i) {
202 }
203 for (int i = 0; i < bCount; ++i) {
205 }
206
209
210
211 listA.
concat(std::move(listB));
213
214
215
218
219 int i = 0;
220 for (
const C& item : listA.items()) {
221
223 i++;
224 }
226}
void concat(SkTBlockList< T, SI > &&other)
◆ run_concat_trivial_test()
Definition at line 229 of file SkTBlockListTest.cpp.
229 {
230 static_assert(std::is_trivially_copyable<D>::value);
231
232
233
236
237 for (int i = 0; i < aCount; ++i) {
239 }
240 for (int i = 0; i < bCount; ++i) {
242 }
243
245
246 listA.
concat(std::move(listB));
249
250 int i = 0;
251 for (
const D& item : listA.items()) {
252
254 i++;
255 }
257}
◆ run_large_increment_test()
Definition at line 315 of file SkTBlockListTest.cpp.
315 {
316 static constexpr size_t kIncrementMax = std::numeric_limits<uint16_t>::max();
317
320
321
322 largeIncrement.reserve(10);
324
327}
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
static constexpr size_t kAddressAlign
static size_t ScratchBlockSize(SkTBlockList< C, N > &list)
◆ run_reserve_test()
Definition at line 260 of file SkTBlockListTest.cpp.
260 {
261 constexpr int kItemsPerBlock =
N + 4;
262
265
266 for (
int i = 0; i <
N; ++i) {
267 list.push_back(
C(i));
268 }
270
271
272 list.reserve(2 * kItemsPerBlock);
274
277 for (int i = 0; i < 2 * kItemsPerBlock; ++i) {
278 list.push_back(
C(i));
279 }
281
282
283 for (
int i = 0; i <
N; ++i) {
284 list.push_back(
C(i));
285 }
286
287
288
289 list.reserve(2 * kItemsPerBlock);
290 int extraReservedCount = kItemsPerBlock +
N;
291
292
294 extraReservedCount *
sizeof(
C));
295
297 for (int i = 0; i < 2 * kItemsPerBlock; ++i) {
298 list.push_back(
C(i));
299 }
301
302
303 list.reserve(2);
305 kItemsPerBlock *
sizeof(
C));
306
307
308 int expectedInstanceCount = 2 * (
N + 2 * kItemsPerBlock);
310
311 list.reset();
313}
static size_t TotalSize(SkTBlockList< C, N > &list)