Flutter Engine
The Flutter Engine
Functions | Variables
TemplatesTest.cpp File Reference
#include "include/private/base/SkTemplates.h"
#include "tests/Test.h"
#include <cstddef>
#include <utility>

Go to the source code of this file.

Functions

static void test_automalloc_realloc (skiatest::Reporter *reporter)
 
 DEF_TEST (Templates, reporter)
 
template<typename TContainer , typename TCount >
static void test_container_apis (skiatest::Reporter *reporter)
 
 DEF_TEST (TemplateContainerAPIs, reporter)
 
template<typename TAutoMalloc >
static void test_realloc_to_zero (skiatest::Reporter *reporter)
 
 DEF_TEST (AutoReallocToZero, reporter)
 
 DEF_TEST (AutoTMallocSelfMove, r)
 

Variables

constexpr static int kStackPreallocCount = 10
 

Function Documentation

◆ DEF_TEST() [1/4]

DEF_TEST ( AutoReallocToZero  ,
reporter   
)

Definition at line 138 of file TemplatesTest.cpp.

138 {
139 test_realloc_to_zero<AutoTMalloc<int> >(reporter);
140 test_realloc_to_zero<AutoSTMalloc<kStackPreallocCount, int> >(reporter);
141}
reporter
Definition: FontMgrTest.cpp:39

◆ DEF_TEST() [2/4]

DEF_TEST ( AutoTMallocSelfMove  ,
 
)

Definition at line 143 of file TemplatesTest.cpp.

143 {
144#if defined(__clang__)
145 #pragma clang diagnostic push
146 #pragma clang diagnostic ignored "-Wself-move"
147#elif defined(__GNUC__) && __GNUC__ >= 13
148 #pragma GCC diagnostic push
149 #pragma GCC diagnostic ignored "-Wself-move"
150#endif
151
152 AutoTMalloc<int> foo(20);
153 REPORTER_ASSERT(r, foo.get());
154
155 foo = std::move(foo);
156 REPORTER_ASSERT(r, foo.get()); // NOLINT(bugprone-use-after-move)
157
158#if defined(__clang__)
159 #pragma clang diagnostic pop
160#elif defined(__GNUC__) && __GNUC__ >= 13
161 #pragma GCC diagnostic pop
162#endif
163}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286

◆ DEF_TEST() [3/4]

DEF_TEST ( TemplateContainerAPIs  ,
reporter   
)

Definition at line 113 of file TemplatesTest.cpp.

113 {
114 test_container_apis<AutoTArray<int>, int>(reporter);
115 test_container_apis<AutoSTArray<kStackPreallocCount, int>, int>(reporter);
116 test_container_apis<AutoTMalloc<int>, size_t>(reporter);
117 test_container_apis<AutoSTMalloc<kStackPreallocCount, int>, size_t>(reporter);
118}

◆ DEF_TEST() [4/4]

DEF_TEST ( Templates  ,
reporter   
)

Definition at line 75 of file TemplatesTest.cpp.

75 {
77}
static void test_automalloc_realloc(skiatest::Reporter *reporter)

◆ test_automalloc_realloc()

static void test_automalloc_realloc ( skiatest::Reporter reporter)
static

Definition at line 17 of file TemplatesTest.cpp.

17 {
19
20 // test we have a valid pointer, should not crash
21 array[0] = 1;
22 REPORTER_ASSERT(reporter, array[0] == 1);
23
24 // using realloc for init
25 array.realloc(1);
26
27 array[0] = 1;
28 REPORTER_ASSERT(reporter, array[0] == 1);
29
30 // verify realloc can grow
31 array.realloc(2);
32 REPORTER_ASSERT(reporter, array[0] == 1);
33
34 // realloc can shrink
35 array.realloc(1);
36 REPORTER_ASSERT(reporter, array[0] == 1);
37
38 // should not crash
39 array.realloc(0);
40
41 // grow and shrink again
42 array.realloc(10);
43 for (int i = 0; i < 10; i++) {
44 array[i] = 10 - i;
45 }
46 array.realloc(20);
47 for (int i = 0; i < 10; i++) {
48 REPORTER_ASSERT(reporter, array[i] == 10 - i);
49 }
50 array.realloc(10);
51 for (int i = 0; i < 10; i++) {
52 REPORTER_ASSERT(reporter, array[i] == 10 - i);
53 }
54
55 array.realloc(1);
56 REPORTER_ASSERT(reporter, array[0] = 10);
57
58 // resets mixed with realloc, below stack alloc size
59 array.reset(0);
60 array.realloc(1);
61 array.reset(1);
62
63 array[0] = 1;
64 REPORTER_ASSERT(reporter, array[0] == 1);
65
66 // reset and realloc > stack size
67 array.reset(2);
68 array.realloc(3);
69 array[0] = 1;
70 REPORTER_ASSERT(reporter, array[0] == 1);
71 array.realloc(1);
72 REPORTER_ASSERT(reporter, array[0] == 1);
73}
T * reset(size_t count)
Definition: SkTemplates.h:356
void realloc(size_t count)
Definition: SkTemplates.h:393

◆ test_container_apis()

template<typename TContainer , typename TCount >
static void test_container_apis ( skiatest::Reporter reporter)
static

Definition at line 83 of file TemplatesTest.cpp.

83 {
84 REPORTER_ASSERT(reporter, !TContainer((TCount)0).get());
85 REPORTER_ASSERT(reporter, !TContainer((TCount)0).data());
86 REPORTER_ASSERT(reporter, TContainer((TCount)1).get());
87 REPORTER_ASSERT(reporter, TContainer((TCount)1).data());
88 REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount).get());
89 REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount).data());
90 REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount + 1).get());
91 REPORTER_ASSERT(reporter, TContainer((TCount)kStackPreallocCount + 1).data());
92
93 TContainer container;
94 // The default constructor may or may not init to empty, depending on the type of container.
95
96 container.reset((TCount)1);
97 REPORTER_ASSERT(reporter, container.get());
98 REPORTER_ASSERT(reporter, container.get() == container.data());
99
100 container.reset((TCount)kStackPreallocCount);
101 REPORTER_ASSERT(reporter, container.get());
102 REPORTER_ASSERT(reporter, container.get() == container.data());
103
104 container.reset((TCount)kStackPreallocCount + 1);
105 REPORTER_ASSERT(reporter, container.get());
106 REPORTER_ASSERT(reporter, container.get() == container.data());
107
108 container.reset((TCount)0);
109 REPORTER_ASSERT(reporter, !container.get());
110 REPORTER_ASSERT(reporter, !container.data());
111}
constexpr static int kStackPreallocCount
const myers::Point & get(const myers::Segment &)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ test_realloc_to_zero()

template<typename TAutoMalloc >
static void test_realloc_to_zero ( skiatest::Reporter reporter)
static

Definition at line 121 of file TemplatesTest.cpp.

121 {
122 TAutoMalloc autoMalloc(kStackPreallocCount);
123 REPORTER_ASSERT(reporter, autoMalloc.get());
124
125 autoMalloc.realloc(0);
126 REPORTER_ASSERT(reporter, !autoMalloc.get());
127
128 autoMalloc.realloc(kStackPreallocCount + 1);
129 REPORTER_ASSERT(reporter, autoMalloc.get());
130
131 autoMalloc.realloc(0);
132 REPORTER_ASSERT(reporter, !autoMalloc.get());
133
134 autoMalloc.realloc(kStackPreallocCount);
135 REPORTER_ASSERT(reporter, autoMalloc.get());
136}

Variable Documentation

◆ kStackPreallocCount

constexpr static int kStackPreallocCount = 10
staticconstexpr

Definition at line 79 of file TemplatesTest.cpp.