Flutter Engine
The Flutter Engine
DescriptorTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
15#include "tests/Test.h"
16
17#include <cstddef>
18#include <cstdint>
19#include <memory>
20#include <optional>
21
23public:
24 static void SetLength(SkDescriptor* desc, size_t length) { desc->fLength = length; }
25 static void SetCount(SkDescriptor* desc, uint32_t count) { desc->fCount = count; }
26};
27
28DEF_TEST(Descriptor_empty, r) {
29 const size_t size = sizeof(SkDescriptor);
30
32 REPORTER_ASSERT(r, desc->isValid());
33 REPORTER_ASSERT(r, desc->getLength() == size);
34}
35
36DEF_TEST(Descriptor_valid_simple, r) {
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}
49
50DEF_TEST(Descriptor_valid_simple_extra_space, r) {
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}
64
65DEF_TEST(Descriptor_valid_more_tags, r) {
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}
82
83DEF_TEST(Descriptor_invalid_rec_size, r) {
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}
93
94DEF_TEST(Descriptor_invalid_length, r) {
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}
107
108DEF_TEST(Descriptor_entry_too_big, r) {
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}
125
126DEF_TEST(Descriptor_entry_over_end, r) {
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}
138
139DEF_TEST(Descriptor_flatten_unflatten, r) {
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}
DEF_TEST(Descriptor_empty, r)
int count
Definition: FontMgrTest.cpp:50
#define kRec_SkDescriptorTag
#define kEffects_SkDescriptorTag
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:167
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static std::optional< SkAutoDescriptor > MakeFromBuffer(SkReadBuffer &buffer)
void writeInt(int32_t value) override
static void SetLength(SkDescriptor *desc, size_t length)
static void SetCount(SkDescriptor *desc, uint32_t count)
static std::unique_ptr< SkDescriptor > Alloc(size_t length)
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
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63