Flutter Engine
The Flutter Engine
SkContainersTest.cpp
Go to the documentation of this file.
1// Copyright 2022 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3
5
6#include "tests/Test.h"
7
8#include <algorithm>
9#include <climits>
10#include <cstddef>
11#include <cstdint>
12
14 static size_t RoundUpCapacity(const SkContainerAllocator& a, int64_t capacity){
15 return a.roundUpCapacity(capacity);
16 }
17
18 static size_t GrowthFactorCapacity(
19 const SkContainerAllocator& a, int capacity, double growthFactor) {
20 return a.growthFactorCapacity(capacity, growthFactor);
21 }
22
23 static constexpr int64_t kCapacityMultiple = SkContainerAllocator::kCapacityMultiple;
24};
25
26static int max_capacity(size_t sizeOfT) {
27 return std::min(SIZE_MAX / sizeOfT, (size_t)INT_MAX);
28}
29
30DEF_TEST(SkContainerAllocatorBasic, reporter) {
31
32 /* Comment out until a solution can be found.
33 // The following test drive the 32-bit machines out of memory so skip them.
34 if constexpr (SIZE_MAX > UINT_MAX) {
35 {
36 SkContainerAllocator a{1, max_capacity(1)};
37
38 SkSpan<std::byte> span = a.allocate(0, 1.0);
39 REPORTER_ASSERT(reporter, span.empty());
40 sk_free(span.data());
41
42 span = a.allocate(0, 1.5);
43 REPORTER_ASSERT(reporter, span.empty());
44 sk_free(span.data());
45
46 span = a.allocate(max_capacity(1), 1.0);
47 REPORTER_ASSERT(reporter, span.size() >= SkToSizeT(max_capacity(1)));
48 sk_free(span.data());
49 }
50
51 {
52 SkContainerAllocator a{16, max_capacity(16)};
53
54 SkSpan<std::byte> span = a.allocate(0, 1.0);
55 REPORTER_ASSERT(reporter, span.empty());
56 sk_free(span.data());
57
58 span = a.allocate(0, 1.5);
59 REPORTER_ASSERT(reporter, span.empty());
60 sk_free(span.data());
61
62 span = a.allocate(max_capacity(16), 1.0);
63 REPORTER_ASSERT(reporter, span.size() >= SkToSizeT(max_capacity(16)) * 16);
64 sk_free(span.data());
65 }
66 } // end skipped on 32-bit Windows tests.
67 */
68
69 for (int i = 1; i < 33; ++i) {
73
76
79 }
80
81 for (int i = 1; i < 33; ++i) {
85
88
91 }
92}
93
reporter
Definition: FontMgrTest.cpp:39
DEF_TEST(SkContainerAllocatorBasic, reporter)
static int max_capacity(size_t sizeOfT)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
struct MyStruct a[10]
static float min(float r, float g, float b)
Definition: hsl.cpp:48
static constexpr int64_t kCapacityMultiple
static size_t GrowthFactorCapacity(const SkContainerAllocator &a, int capacity, double growthFactor)
static size_t RoundUpCapacity(const SkContainerAllocator &a, int64_t capacity)