Flutter Engine
The Flutter Engine
DataRefTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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 "src/core/SkOSFile.h"
16#include "src/utils/SkOSPath.h"
17#include "tests/Test.h"
18
19#include <array>
20#include <cstdio>
21#include <cstring>
22
24 const SkDataTable* a, const SkDataTable* b) {
25 REPORTER_ASSERT(reporter, a->count() == b->count());
26 for (int i = 0; i < a->count(); ++i) {
27 size_t sizea, sizeb;
28 const void* mema = a->at(i, &sizea);
29 const void* memb = b->at(i, &sizeb);
30 REPORTER_ASSERT(reporter, sizea == sizeb);
31 REPORTER_ASSERT(reporter, !memcmp(mema, memb, sizea));
32 }
33}
34
36 REPORTER_ASSERT(reporter, table->isEmpty());
37 REPORTER_ASSERT(reporter, 0 == table->count());
38}
39
42 sk_sp<SkDataTable> table1(SkDataTable::MakeCopyArrays(nullptr, nullptr, 0));
44 sk_sp<SkDataTable> table3(SkDataTable::MakeArrayProc(nullptr, 0, 0, nullptr, nullptr));
45
50
51 test_is_equal(reporter, table0.get(), table1.get());
52 test_is_equal(reporter, table0.get(), table2.get());
53 test_is_equal(reporter, table0.get(), table3.get());
54}
55
57 const int idata[] = { 1, 4, 9, 16, 25, 63 };
58 int icount = std::size(idata);
59 sk_sp<SkDataTable> itable(SkDataTable::MakeCopyArray(idata, sizeof(idata[0]), icount));
60 REPORTER_ASSERT(reporter, itable->count() == icount);
61 for (int i = 0; i < icount; ++i) {
62 size_t size;
63 REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i));
64 REPORTER_ASSERT(reporter, *itable->atT<int>(i, &size) == idata[i]);
65 REPORTER_ASSERT(reporter, sizeof(int) == size);
66 }
67}
68
70 const char* str[] = {
71 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
72 };
73 int count = std::size(str);
74 size_t sizes[std::size(str)];
75 for (int i = 0; i < count; ++i) {
76 sizes[i] = strlen(str[i]) + 1;
77 }
78
79 sk_sp<SkDataTable> table(SkDataTable::MakeCopyArrays((const void*const*)str, sizes, count));
80
81 REPORTER_ASSERT(reporter, table->count() == count);
82 for (int i = 0; i < count; ++i) {
83 size_t size;
84 REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]);
85 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size),
86 str[i]));
87 REPORTER_ASSERT(reporter, size == sizes[i]);
88
89 const char* s = table->atStr(i);
90 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
91 }
92}
93
95 static const int gData[] = {
96 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
97 };
98 int count = std::size(gData);
99
101 SkDataTable::MakeArrayProc(gData, sizeof(gData[0]), count, nullptr, nullptr));
102
103 REPORTER_ASSERT(reporter, table->count() == count);
104 for (int i = 0; i < count; ++i) {
105 size_t size;
106 REPORTER_ASSERT(reporter, table->atSize(i) == sizeof(int));
107 REPORTER_ASSERT(reporter, *table->atT<const char>(i, &size) == i);
108 REPORTER_ASSERT(reporter, sizeof(int) == size);
109 }
110}
111
112DEF_TEST(DataTable, reporter) {
117}
118
119static void* gGlobal;
120
121static void delete_int_proc(const void* ptr, void* context) {
122 const int* data = (const int*)ptr;
123 SkASSERT(context == gGlobal);
124 delete[] data;
125}
126
127static void assert_len(skiatest::Reporter* reporter, const sk_sp<SkData>& ref, size_t len) {
128 REPORTER_ASSERT(reporter, ref->size() == len);
129}
130
132 const void* data, size_t len) {
133 REPORTER_ASSERT(reporter, ref->size() == len);
134 REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len));
135}
136
138 const char str[] = "Hello world";
139 size_t len = strlen(str);
140
143
145
147 REPORTER_ASSERT(reporter, 1 == r2->size());
148 REPORTER_ASSERT(reporter, 0 == *r2->bytes());
149}
150
152 SkString tmpDir = skiatest::GetTmpDir();
153 if (tmpDir.isEmpty()) {
154 return;
155 }
156
157 SkString path = SkOSPath::Join(tmpDir.c_str(), "data_test");
158
159 const char s[] = "abcdefghijklmnopqrstuvwxyz";
160 {
161 SkFILEWStream writer(path.c_str());
162 if (!writer.isValid()) {
163 ERRORF(reporter, "Failed to create tmp file %s\n", path.c_str());
164 return;
165 }
166 writer.write(s, 26);
167 }
168
169 FILE* file = sk_fopen(path.c_str(), kRead_SkFILE_Flag);
171 REPORTER_ASSERT(reporter, r1.get() != nullptr);
172 REPORTER_ASSERT(reporter, r1->size() == 26);
173 REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r1->data()), s, 26) == 0);
174
175 int fd = sk_fileno(file);
177 REPORTER_ASSERT(reporter, r2.get() != nullptr);
178 REPORTER_ASSERT(reporter, r2->size() == 26);
179 REPORTER_ASSERT(reporter, strncmp(static_cast<const char*>(r2->data()), s, 26) == 0);
180}
181
183 const char* str = "We the people, in order to form a more perfect union.";
184 const int N = 10;
185
187 sk_sp<SkData> r1(SkData::MakeWithCopy(str, strlen(str)));
188 sk_sp<SkData> r2(SkData::MakeWithProc(new int[N], N*sizeof(int), delete_int_proc, gGlobal));
189 sk_sp<SkData> r3(SkData::MakeSubset(r1.get(), 7, 6));
190
191 assert_len(reporter, r0, 0);
192 assert_len(reporter, r1, strlen(str));
193 assert_len(reporter, r2, N * sizeof(int));
194 assert_len(reporter, r3, 6);
195
196 assert_data(reporter, r1, str, strlen(str));
197 assert_data(reporter, r3, "people", 6);
198
199 sk_sp<SkData> tmp(SkData::MakeSubset(r1.get(), strlen(str), 10));
200 assert_len(reporter, tmp, 0);
201 tmp = SkData::MakeSubset(r1.get(), 0, 0);
202 assert_len(reporter, tmp, 0);
203
206}
207
208DEF_TEST(Data_empty, reporter) {
209 sk_sp<SkData> array[] = {
214 SkData::MakeWithProc(nullptr, 0, [](const void*, void*){}, nullptr),
215 SkData::MakeWithoutCopy(nullptr, 0),
216 };
217 constexpr int N = std::size(array);
218
219 for (int i = 0; i < N; ++i) {
220 REPORTER_ASSERT(reporter, array[i]->size() == 0);
221 for (int j = 0; j < N; ++j) {
222 REPORTER_ASSERT(reporter, array[i]->equals(array[j].get()));
223 }
224 }
225}
static void test_simpletable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:56
DEF_TEST(DataTable, reporter)
static void assert_data(skiatest::Reporter *reporter, const sk_sp< SkData > &ref, const void *data, size_t len)
static void assert_len(skiatest::Reporter *reporter, const sk_sp< SkData > &ref, size_t len)
static void test_vartable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:69
static void test_is_equal(skiatest::Reporter *reporter, const SkDataTable *a, const SkDataTable *b)
Definition: DataRefTest.cpp:23
static void delete_int_proc(const void *ptr, void *context)
static void test_files(skiatest::Reporter *reporter)
static void * gGlobal
static void test_datatable_is_empty(skiatest::Reporter *reporter, SkDataTable *table)
Definition: DataRefTest.cpp:35
static void test_emptytable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:40
static void test_cstring(skiatest::Reporter *reporter)
static void test_globaltable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:94
reporter
Definition: FontMgrTest.cpp:39
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
static void * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
FILE * sk_fopen(const char path[], SkFILE_Flags)
int sk_fileno(FILE *f)
@ kRead_SkFILE_Flag
Definition: SkOSFile.h:20
bool equals(SkDrawable *a, SkDrawable *b)
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
SI F table(const skcms_Curve *curve, F v)
#define N
Definition: beziers.cpp:19
int count() const
Definition: SkDataTable.h:33
static sk_sp< SkDataTable > MakeCopyArray(const void *array, size_t elemSize, int count)
const T * atT(int index, size_t *size=nullptr) const
Definition: SkDataTable.h:51
static sk_sp< SkDataTable > MakeArrayProc(const void *array, size_t elemSize, int count, FreeProc proc, void *context)
static sk_sp< SkDataTable > MakeEmpty()
Definition: SkDataTable.cpp:85
static sk_sp< SkDataTable > MakeCopyArrays(const void *const *ptrs, const size_t sizes[], int count)
Definition: SkDataTable.cpp:92
size_t atSize(int index) const
Definition: SkDataTable.cpp:57
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition: SkData.h:116
const uint8_t * bytes() const
Definition: SkData.h:43
static sk_sp< SkData > MakeFromMalloc(const void *data, size_t length)
Definition: SkData.cpp:107
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
bool equals(const SkData *other) const
Definition: SkData.cpp:43
const void * data() const
Definition: SkData.h:37
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition: SkData.cpp:195
static sk_sp< SkData > MakeFromFD(int fd)
Definition: SkData.cpp:158
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
Definition: SkData.cpp:128
static sk_sp< SkData > MakeFromFILE(FILE *f)
Definition: SkData.cpp:138
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
static sk_sp< SkData > MakeSubset(const SkData *src, size_t offset, size_t length)
Definition: SkData.cpp:173
static sk_sp< SkData > MakeEmpty()
Definition: SkData.cpp:94
size_t size() const
Definition: SkData.h:30
bool write(const void *buffer, size_t size) override
Definition: SkStream.cpp:426
bool isValid() const
Definition: SkStream.h:442
static SkString Join(const char *rootPath, const char *relativePath)
Definition: SkOSPath.cpp:14
bool isEmpty() const
Definition: SkString.h:130
const char * c_str() const
Definition: SkString.h:133
T * get() const
Definition: SkRefCnt.h:303
static bool b
struct MyStruct s
struct MyStruct a[10]
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
struct PathData * Data(SkPath *path)
Definition: path_ops.cc:52
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
const myers::Point & get(const myers::Segment &)
SkString GetTmpDir()
Definition: Test.cpp:53
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63
static uint16_t gData[]
Definition: xfermodes.cpp:125