Flutter Engine
The Flutter Engine
Classes | Functions
DescriptorTest.cpp File Reference
#include "include/core/SkData.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkTypes.h"
#include "src/core/SkDescriptor.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkScalerContext.h"
#include "src/core/SkWriteBuffer.h"
#include "tests/Test.h"
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>

Go to the source code of this file.

Classes

class  SkDescriptorTestHelper
 

Functions

 DEF_TEST (Descriptor_empty, r)
 
 DEF_TEST (Descriptor_valid_simple, r)
 
 DEF_TEST (Descriptor_valid_simple_extra_space, r)
 
 DEF_TEST (Descriptor_valid_more_tags, r)
 
 DEF_TEST (Descriptor_invalid_rec_size, r)
 
 DEF_TEST (Descriptor_invalid_length, r)
 
 DEF_TEST (Descriptor_entry_too_big, r)
 
 DEF_TEST (Descriptor_entry_over_end, r)
 
 DEF_TEST (Descriptor_flatten_unflatten, r)
 

Function Documentation

◆ DEF_TEST() [1/9]

DEF_TEST ( Descriptor_empty  ,
 
)

Definition at line 28 of file DescriptorTest.cpp.

28 {
29 const size_t size = sizeof(SkDescriptor);
30
32 REPORTER_ASSERT(r, desc->isValid());
33 REPORTER_ASSERT(r, desc->getLength() == size);
34}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static std::unique_ptr< SkDescriptor > Alloc(size_t length)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ DEF_TEST() [2/9]

DEF_TEST ( Descriptor_entry_over_end  ,
 
)

Definition at line 126 of file DescriptorTest.cpp.

126 {
127 auto desc = SkDescriptor::Alloc(36);
128
129 // Make the start of the Entry be in the SkDescriptor, but the second half falls out side the
130 // SkDescriptor. So: 12 (for descriptor) + 8 (for entry) + 12 (for entry length) = 32. An
131 // An Entry is 8 bytes, so 4 bytes are < 36 and 4 bytes > 36.
132 desc->addEntry(kEffects_SkDescriptorTag, 12, nullptr);
133
136 REPORTER_ASSERT(r, !desc->isValid());
137}
#define kEffects_SkDescriptorTag
static void SetLength(SkDescriptor *desc, size_t length)
static void SetCount(SkDescriptor *desc, uint32_t count)

◆ DEF_TEST() [3/9]

DEF_TEST ( Descriptor_entry_too_big  ,
 
)

Definition at line 108 of file DescriptorTest.cpp.

108 {
109 const size_t size = sizeof(SkDescriptor) + sizeof(SkDescriptor::Entry) + 4;
110 // Must be less than fLength, but big enough to be bigger then fLength when added.
111 const size_t effect_size = sizeof(SkDescriptor) + sizeof(SkDescriptor::Entry);
112
114
115 desc->addEntry(kEffects_SkDescriptorTag, effect_size, nullptr);
116
119 REPORTER_ASSERT(r, !desc->isValid());
120
123 REPORTER_ASSERT(r, !desc->isValid());
124}

◆ DEF_TEST() [4/9]

DEF_TEST ( Descriptor_flatten_unflatten  ,
 
)

Definition at line 139 of file DescriptorTest.cpp.

139 {
140 {
141 SkBinaryWriteBuffer writer({});
142 auto desc = SkDescriptor::Alloc(sizeof(SkDescriptor));
143 desc->computeChecksum();
144 desc->flatten(writer);
145 auto data = writer.snapshotAsData();
146 SkReadBuffer reader{data->data(), data->size()};
147 auto ad = SkAutoDescriptor::MakeFromBuffer(reader);
148 REPORTER_ASSERT(r, ad.has_value());
149 REPORTER_ASSERT(r, ad->getDesc()->isValid());
150 }
151
152 { // broken header
153 SkBinaryWriteBuffer writer({});
154 writer.writeInt(0); // fChecksum
155 auto data = writer.snapshotAsData();
156 SkReadBuffer reader{data->data(), data->size()};
157 auto ad = SkAutoDescriptor::MakeFromBuffer(reader);
158 REPORTER_ASSERT(r, !ad.has_value());
159 }
160
161 { // length too big
162 SkBinaryWriteBuffer writer({});
163 // Simulate a broken header
164 writer.writeInt(0); // fChecksum
165 writer.writeInt(4000); // fLength
166 writer.writeInt(0); // fCount
167 auto data = writer.snapshotAsData();
168 SkReadBuffer reader{data->data(), data->size()};
169 auto ad = SkAutoDescriptor::MakeFromBuffer(reader);
170 REPORTER_ASSERT(r, !ad.has_value());
171 }
172
173 { // length too small
174 SkBinaryWriteBuffer writer({});
175 // Simulate a broken header
176 writer.writeInt(0); // fChecksum
177 writer.writeInt(3); // fLength
178 writer.writeInt(0); // fCount
179 auto data = writer.snapshotAsData();
180 SkReadBuffer reader{data->data(), data->size()};
181 auto ad = SkAutoDescriptor::MakeFromBuffer(reader);
182 REPORTER_ASSERT(r, !ad.has_value());
183 }
184
185 { // garbage in count
186 SkBinaryWriteBuffer writer({});
187 // Simulate a broken header
188 writer.writeInt(0); // fChecksum
189 writer.writeInt(20); // fLength
190 writer.writeInt(10); // fCount
191 writer.writeInt(0);
192 writer.writeInt(0);
193 auto data = writer.snapshotAsData();
194 SkReadBuffer reader{data->data(), data->size()};
195 auto ad = SkAutoDescriptor::MakeFromBuffer(reader);
196 REPORTER_ASSERT(r, !ad.has_value());
197 }
198}
static std::optional< SkAutoDescriptor > MakeFromBuffer(SkReadBuffer &buffer)
void writeInt(int32_t value) override
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ DEF_TEST() [5/9]

DEF_TEST ( Descriptor_invalid_length  ,
 
)

Definition at line 94 of file DescriptorTest.cpp.

94 {
95 const size_t size = sizeof(SkDescriptor) + sizeof(SkDescriptor::Entry);
96 const size_t effect_size = 1000;
97
99 desc->addEntry(kEffects_SkDescriptorTag, effect_size, nullptr);
100
102 REPORTER_ASSERT(r, !desc->isValid());
103
104 SkDescriptorTestHelper::SetLength(desc.get(), size + effect_size);
105 REPORTER_ASSERT(r, desc->isValid());
106}

◆ DEF_TEST() [6/9]

DEF_TEST ( Descriptor_invalid_rec_size  ,
 
)

Definition at line 83 of file DescriptorTest.cpp.

83 {
84 const size_t size =
85 sizeof(SkDescriptor) + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContextRec) - 4;
86
89 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec) - 4, &rec);
90 REPORTER_ASSERT(r, desc->getLength() == size);
91 REPORTER_ASSERT(r, !desc->isValid());
92}
#define kRec_SkDescriptorTag

◆ DEF_TEST() [7/9]

DEF_TEST ( Descriptor_valid_more_tags  ,
 
)

Definition at line 65 of file DescriptorTest.cpp.

65 {
66 const size_t effectSize = 16;
67 const size_t testSize = 32;
68 const size_t size = sizeof(SkDescriptor) + 3 * sizeof(SkDescriptor::Entry) +
69 sizeof(SkScalerContextRec) + effectSize + testSize;
70
73 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
74 desc->addEntry(kEffects_SkDescriptorTag, effectSize, nullptr);
75 desc->addEntry(SkSetFourByteTag('t', 'e', 's', 't'), testSize, nullptr);
76 REPORTER_ASSERT(r, desc->isValid());
77 REPORTER_ASSERT(r, desc->getLength() == size);
78
80 REPORTER_ASSERT(r, !desc->isValid());
81}
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167

◆ DEF_TEST() [8/9]

DEF_TEST ( Descriptor_valid_simple  ,
 
)

Definition at line 36 of file DescriptorTest.cpp.

36 {
37 const size_t size =
38 sizeof(SkDescriptor) + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContextRec);
39
42 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
43 REPORTER_ASSERT(r, desc->isValid());
44 REPORTER_ASSERT(r, desc->getLength() == size);
45
47 REPORTER_ASSERT(r, !desc->isValid());
48}

◆ DEF_TEST() [9/9]

DEF_TEST ( Descriptor_valid_simple_extra_space  ,
 
)

Definition at line 50 of file DescriptorTest.cpp.

50 {
51 const size_t extra_space = 100;
52 const size_t size =
53 sizeof(SkDescriptor) + sizeof(SkDescriptor::Entry) + sizeof(SkScalerContextRec);
54
55 auto desc = SkDescriptor::Alloc(size + extra_space);
57 desc->addEntry(kRec_SkDescriptorTag, sizeof(rec), &rec);
58 REPORTER_ASSERT(r, desc->isValid());
59 REPORTER_ASSERT(r, desc->getLength() == size);
60
62 REPORTER_ASSERT(r, !desc->isValid());
63}