Flutter Engine
The Flutter Engine
Functions | Variables
DataRefTest.cpp File Reference
#include "include/core/SkData.h"
#include "include/core/SkDataTable.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkStream.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkMalloc.h"
#include "src/core/SkOSFile.h"
#include "src/utils/SkOSPath.h"
#include "tests/Test.h"
#include <array>
#include <cstdio>
#include <cstring>

Go to the source code of this file.

Functions

static void test_is_equal (skiatest::Reporter *reporter, const SkDataTable *a, const SkDataTable *b)
 
static void test_datatable_is_empty (skiatest::Reporter *reporter, SkDataTable *table)
 
static void test_emptytable (skiatest::Reporter *reporter)
 
static void test_simpletable (skiatest::Reporter *reporter)
 
static void test_vartable (skiatest::Reporter *reporter)
 
static void test_globaltable (skiatest::Reporter *reporter)
 
 DEF_TEST (DataTable, reporter)
 
static void delete_int_proc (const void *ptr, void *context)
 
static void assert_len (skiatest::Reporter *reporter, const sk_sp< SkData > &ref, size_t len)
 
static void assert_data (skiatest::Reporter *reporter, const sk_sp< SkData > &ref, const void *data, size_t len)
 
static void test_cstring (skiatest::Reporter *reporter)
 
static void test_files (skiatest::Reporter *reporter)
 
 DEF_TEST (Data, reporter)
 
 DEF_TEST (Data_empty, reporter)
 

Variables

static void * gGlobal
 

Function Documentation

◆ assert_data()

static void assert_data ( skiatest::Reporter reporter,
const sk_sp< SkData > &  ref,
const void *  data,
size_t  len 
)
static

Definition at line 131 of file DataRefTest.cpp.

132 {
133 REPORTER_ASSERT(reporter, ref->size() == len);
134 REPORTER_ASSERT(reporter, !memcmp(ref->data(), data, len));
135}
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ assert_len()

static void assert_len ( skiatest::Reporter reporter,
const sk_sp< SkData > &  ref,
size_t  len 
)
static

Definition at line 127 of file DataRefTest.cpp.

127 {
128 REPORTER_ASSERT(reporter, ref->size() == len);
129}

◆ DEF_TEST() [1/3]

DEF_TEST ( Data  ,
reporter   
)

Definition at line 182 of file DataRefTest.cpp.

182 {
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}
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 delete_int_proc(const void *ptr, void *context)
static void test_files(skiatest::Reporter *reporter)
static void * gGlobal
static void test_cstring(skiatest::Reporter *reporter)
#define N
Definition: beziers.cpp:19
static sk_sp< SkData > MakeWithProc(const void *ptr, size_t length, ReleaseProc proc, void *ctx)
Definition: SkData.cpp:128
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

◆ DEF_TEST() [2/3]

DEF_TEST ( Data_empty  ,
reporter   
)

Definition at line 208 of file DataRefTest.cpp.

208 {
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 * sk_malloc_throw(size_t size)
Definition: SkMalloc.h:67
bool equals(SkDrawable *a, SkDrawable *b)
static sk_sp< SkData > MakeWithoutCopy(const void *data, size_t length)
Definition: SkData.h:116
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
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 &)

◆ DEF_TEST() [3/3]

DEF_TEST ( DataTable  ,
reporter   
)

Definition at line 112 of file DataRefTest.cpp.

112 {
117}
static void test_simpletable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:56
static void test_vartable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:69
static void test_emptytable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:40
static void test_globaltable(skiatest::Reporter *reporter)
Definition: DataRefTest.cpp:94

◆ delete_int_proc()

static void delete_int_proc ( const void *  ptr,
void *  context 
)
static

Definition at line 121 of file DataRefTest.cpp.

121 {
122 const int* data = (const int*)ptr;
123 SkASSERT(context == gGlobal);
124 delete[] data;
125}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ test_cstring()

static void test_cstring ( skiatest::Reporter reporter)
static

Definition at line 137 of file DataRefTest.cpp.

137 {
138 const char str[] = "Hello world";
139 size_t len = strlen(str);
140
143
144 REPORTER_ASSERT(reporter, r0->equals(r1.get()));
145
147 REPORTER_ASSERT(reporter, 1 == r2->size());
148 REPORTER_ASSERT(reporter, 0 == *r2->bytes());
149}
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition: SkData.cpp:195

◆ test_datatable_is_empty()

static void test_datatable_is_empty ( skiatest::Reporter reporter,
SkDataTable table 
)
static

Definition at line 35 of file DataRefTest.cpp.

35 {
36 REPORTER_ASSERT(reporter, table->isEmpty());
37 REPORTER_ASSERT(reporter, 0 == table->count());
38}
SI F table(const skcms_Curve *curve, F v)

◆ test_emptytable()

static void test_emptytable ( skiatest::Reporter reporter)
static

Definition at line 40 of file DataRefTest.cpp.

40 {
42 sk_sp<SkDataTable> table1(SkDataTable::MakeCopyArrays(nullptr, nullptr, 0));
44 sk_sp<SkDataTable> table3(SkDataTable::MakeArrayProc(nullptr, 0, 0, nullptr, nullptr));
45
46 test_datatable_is_empty(reporter, table0.get());
47 test_datatable_is_empty(reporter, table1.get());
48 test_datatable_is_empty(reporter, table2.get());
49 test_datatable_is_empty(reporter, table3.get());
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}
static void test_is_equal(skiatest::Reporter *reporter, const SkDataTable *a, const SkDataTable *b)
Definition: DataRefTest.cpp:23
static void test_datatable_is_empty(skiatest::Reporter *reporter, SkDataTable *table)
Definition: DataRefTest.cpp:35
static sk_sp< SkDataTable > MakeCopyArray(const void *array, size_t elemSize, int count)
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

◆ test_files()

static void test_files ( skiatest::Reporter reporter)
static

Definition at line 151 of file DataRefTest.cpp.

151 {
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}
FILE * sk_fopen(const char path[], SkFILE_Flags)
int sk_fileno(FILE *f)
@ kRead_SkFILE_Flag
Definition: SkOSFile.h:20
#define ERRORF(r,...)
Definition: Test.h:293
static sk_sp< SkData > MakeFromFD(int fd)
Definition: SkData.cpp:158
static sk_sp< SkData > MakeFromFILE(FILE *f)
Definition: SkData.cpp:138
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
struct MyStruct s
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
SkString GetTmpDir()
Definition: Test.cpp:53

◆ test_globaltable()

static void test_globaltable ( skiatest::Reporter reporter)
static

Definition at line 94 of file DataRefTest.cpp.

94 {
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}
int count
Definition: FontMgrTest.cpp:50
static uint16_t gData[]
Definition: xfermodes.cpp:125

◆ test_is_equal()

static void test_is_equal ( skiatest::Reporter reporter,
const SkDataTable a,
const SkDataTable b 
)
static

Definition at line 23 of file DataRefTest.cpp.

24 {
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}
static bool b
struct MyStruct a[10]

◆ test_simpletable()

static void test_simpletable ( skiatest::Reporter reporter)
static

Definition at line 56 of file DataRefTest.cpp.

56 {
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}

◆ test_vartable()

static void test_vartable ( skiatest::Reporter reporter)
static

Definition at line 69 of file DataRefTest.cpp.

69 {
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}

Variable Documentation

◆ gGlobal

void* gGlobal
static

Definition at line 119 of file DataRefTest.cpp.