Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: tests/DataRefTest.cpp

Issue 26223009: Remove SkDataTable from SkFlattenable hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/core/SkDataTable.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "Test.h" 8 #include "Test.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkDataTable.h" 10 #include "SkDataTable.h"
11 #include "SkOrderedReadBuffer.h" 11 #include "SkOrderedReadBuffer.h"
12 #include "SkOrderedWriteBuffer.h" 12 #include "SkOrderedWriteBuffer.h"
13 #include "SkOSFile.h" 13 #include "SkOSFile.h"
14 #include "SkStream.h" 14 #include "SkStream.h"
15 15
16 static void test_is_equal(skiatest::Reporter* reporter, 16 static void test_is_equal(skiatest::Reporter* reporter,
17 const SkDataTable* a, const SkDataTable* b) { 17 const SkDataTable* a, const SkDataTable* b) {
18 REPORTER_ASSERT(reporter, a->count() == b->count()); 18 REPORTER_ASSERT(reporter, a->count() == b->count());
19 for (int i = 0; i < a->count(); ++i) { 19 for (int i = 0; i < a->count(); ++i) {
20 size_t sizea, sizeb; 20 size_t sizea, sizeb;
21 const void* mema = a->at(i, &sizea); 21 const void* mema = a->at(i, &sizea);
22 const void* memb = b->at(i, &sizeb); 22 const void* memb = b->at(i, &sizeb);
23 REPORTER_ASSERT(reporter, sizea == sizeb); 23 REPORTER_ASSERT(reporter, sizea == sizeb);
24 REPORTER_ASSERT(reporter, !memcmp(mema, memb, sizea)); 24 REPORTER_ASSERT(reporter, !memcmp(mema, memb, sizea));
25 } 25 }
26 } 26 }
27 27
28 static void test_datatable_flatten(skiatest::Reporter* reporter,
29 SkDataTable* table) {
30 SkOrderedWriteBuffer wb(1024);
31 wb.writeFlattenable(table);
32
33 size_t wsize = wb.size();
34 SkAutoMalloc storage(wsize);
35 wb.writeToMemory(storage.get());
36
37 SkOrderedReadBuffer rb(storage.get(), wsize);
38 SkAutoTUnref<SkDataTable> newTable((SkDataTable*)rb.readFlattenable());
39
40 test_is_equal(reporter, table, newTable);
41 }
42
43 static void test_datatable_is_empty(skiatest::Reporter* reporter, 28 static void test_datatable_is_empty(skiatest::Reporter* reporter,
44 SkDataTable* table) { 29 SkDataTable* table) {
45 REPORTER_ASSERT(reporter, table->isEmpty()); 30 REPORTER_ASSERT(reporter, table->isEmpty());
46 REPORTER_ASSERT(reporter, 0 == table->count()); 31 REPORTER_ASSERT(reporter, 0 == table->count());
47 test_datatable_flatten(reporter, table);
48 } 32 }
49 33
50 static void test_emptytable(skiatest::Reporter* reporter) { 34 static void test_emptytable(skiatest::Reporter* reporter) {
51 SkAutoTUnref<SkDataTable> table0(SkDataTable::NewEmpty()); 35 SkAutoTUnref<SkDataTable> table0(SkDataTable::NewEmpty());
52 SkAutoTUnref<SkDataTable> table1(SkDataTable::NewCopyArrays(NULL, NULL, 0)); 36 SkAutoTUnref<SkDataTable> table1(SkDataTable::NewCopyArrays(NULL, NULL, 0));
53 SkAutoTUnref<SkDataTable> table2(SkDataTable::NewCopyArray(NULL, 0, 0)); 37 SkAutoTUnref<SkDataTable> table2(SkDataTable::NewCopyArray(NULL, 0, 0));
54 SkAutoTUnref<SkDataTable> table3(SkDataTable::NewArrayProc(NULL, 0, 0, 38 SkAutoTUnref<SkDataTable> table3(SkDataTable::NewArrayProc(NULL, 0, 0,
55 NULL, NULL)); 39 NULL, NULL));
56 40
57 test_datatable_is_empty(reporter, table0); 41 test_datatable_is_empty(reporter, table0);
(...skipping 12 matching lines...) Expand all
70 SkAutoTUnref<SkDataTable> itable(SkDataTable::NewCopyArray(idata, 54 SkAutoTUnref<SkDataTable> itable(SkDataTable::NewCopyArray(idata,
71 sizeof(idata[0]), 55 sizeof(idata[0]),
72 icount)); 56 icount));
73 REPORTER_ASSERT(reporter, itable->count() == icount); 57 REPORTER_ASSERT(reporter, itable->count() == icount);
74 for (int i = 0; i < icount; ++i) { 58 for (int i = 0; i < icount; ++i) {
75 size_t size; 59 size_t size;
76 REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i)); 60 REPORTER_ASSERT(reporter, sizeof(int) == itable->atSize(i));
77 REPORTER_ASSERT(reporter, *itable->atT<int>(i, &size) == idata[i]); 61 REPORTER_ASSERT(reporter, *itable->atT<int>(i, &size) == idata[i]);
78 REPORTER_ASSERT(reporter, sizeof(int) == size); 62 REPORTER_ASSERT(reporter, sizeof(int) == size);
79 } 63 }
80 test_datatable_flatten(reporter, itable);
81 } 64 }
82 65
83 static void test_vartable(skiatest::Reporter* reporter) { 66 static void test_vartable(skiatest::Reporter* reporter) {
84 const char* str[] = { 67 const char* str[] = {
85 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" 68 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
86 }; 69 };
87 int count = SK_ARRAY_COUNT(str); 70 int count = SK_ARRAY_COUNT(str);
88 size_t sizes[SK_ARRAY_COUNT(str)]; 71 size_t sizes[SK_ARRAY_COUNT(str)];
89 for (int i = 0; i < count; ++i) { 72 for (int i = 0; i < count; ++i) {
90 sizes[i] = strlen(str[i]) + 1; 73 sizes[i] = strlen(str[i]) + 1;
91 } 74 }
92 75
93 SkAutoTUnref<SkDataTable> table(SkDataTable::NewCopyArrays( 76 SkAutoTUnref<SkDataTable> table(SkDataTable::NewCopyArrays(
94 (const void*const*)str, sizes, count)); 77 (const void*const*)str, sizes, count));
95 78
96 REPORTER_ASSERT(reporter, table->count() == count); 79 REPORTER_ASSERT(reporter, table->count() == count);
97 for (int i = 0; i < count; ++i) { 80 for (int i = 0; i < count; ++i) {
98 size_t size; 81 size_t size;
99 REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]); 82 REPORTER_ASSERT(reporter, table->atSize(i) == sizes[i]);
100 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size), 83 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size),
101 str[i])); 84 str[i]));
102 REPORTER_ASSERT(reporter, size == sizes[i]); 85 REPORTER_ASSERT(reporter, size == sizes[i]);
103 86
104 const char* s = table->atStr(i); 87 const char* s = table->atStr(i);
105 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); 88 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
106 } 89 }
107 test_datatable_flatten(reporter, table);
108 } 90 }
109 91
110 static void test_tablebuilder(skiatest::Reporter* reporter) { 92 static void test_tablebuilder(skiatest::Reporter* reporter) {
111 const char* str[] = { 93 const char* str[] = {
112 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg" 94 "", "a", "be", "see", "deigh", "ef", "ggggggggggggggggggggggggggg"
113 }; 95 };
114 int count = SK_ARRAY_COUNT(str); 96 int count = SK_ARRAY_COUNT(str);
115 97
116 SkDataTableBuilder builder(16); 98 SkDataTableBuilder builder(16);
117 99
118 for (int i = 0; i < count; ++i) { 100 for (int i = 0; i < count; ++i) {
119 builder.append(str[i], strlen(str[i]) + 1); 101 builder.append(str[i], strlen(str[i]) + 1);
120 } 102 }
121 SkAutoTUnref<SkDataTable> table(builder.detachDataTable()); 103 SkAutoTUnref<SkDataTable> table(builder.detachDataTable());
122 104
123 REPORTER_ASSERT(reporter, table->count() == count); 105 REPORTER_ASSERT(reporter, table->count() == count);
124 for (int i = 0; i < count; ++i) { 106 for (int i = 0; i < count; ++i) {
125 size_t size; 107 size_t size;
126 REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1); 108 REPORTER_ASSERT(reporter, table->atSize(i) == strlen(str[i]) + 1);
127 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size), 109 REPORTER_ASSERT(reporter, !strcmp(table->atT<const char>(i, &size),
128 str[i])); 110 str[i]));
129 REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1); 111 REPORTER_ASSERT(reporter, size == strlen(str[i]) + 1);
130 112
131 const char* s = table->atStr(i); 113 const char* s = table->atStr(i);
132 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i])); 114 REPORTER_ASSERT(reporter, strlen(s) == strlen(str[i]));
133 } 115 }
134 test_datatable_flatten(reporter, table);
135 } 116 }
136 117
137 static void test_globaltable(skiatest::Reporter* reporter) { 118 static void test_globaltable(skiatest::Reporter* reporter) {
138 static const int gData[] = { 119 static const int gData[] = {
139 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 120 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
140 }; 121 };
141 int count = SK_ARRAY_COUNT(gData); 122 int count = SK_ARRAY_COUNT(gData);
142 123
143 SkAutoTUnref<SkDataTable> table(SkDataTable::NewArrayProc(gData, 124 SkAutoTUnref<SkDataTable> table(SkDataTable::NewArrayProc(gData,
144 sizeof(gData[0]), count, NULL, NULL)); 125 sizeof(gData[0]), count, NULL, NULL));
145 126
146 REPORTER_ASSERT(reporter, table->count() == count); 127 REPORTER_ASSERT(reporter, table->count() == count);
147 for (int i = 0; i < count; ++i) { 128 for (int i = 0; i < count; ++i) {
148 size_t size; 129 size_t size;
149 REPORTER_ASSERT(reporter, table->atSize(i) == sizeof(int)); 130 REPORTER_ASSERT(reporter, table->atSize(i) == sizeof(int));
150 REPORTER_ASSERT(reporter, *table->atT<const char>(i, &size) == i); 131 REPORTER_ASSERT(reporter, *table->atT<const char>(i, &size) == i);
151 REPORTER_ASSERT(reporter, sizeof(int) == size); 132 REPORTER_ASSERT(reporter, sizeof(int) == size);
152 } 133 }
153 test_datatable_flatten(reporter, table);
154 } 134 }
155 135
156 static void TestDataTable(skiatest::Reporter* reporter) { 136 static void TestDataTable(skiatest::Reporter* reporter) {
157 test_emptytable(reporter); 137 test_emptytable(reporter);
158 test_simpletable(reporter); 138 test_simpletable(reporter);
159 test_vartable(reporter); 139 test_vartable(reporter);
160 test_tablebuilder(reporter); 140 test_tablebuilder(reporter);
161 test_globaltable(reporter); 141 test_globaltable(reporter);
162 } 142 }
163 143
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 assert_len(reporter, tmp, 0); 231 assert_len(reporter, tmp, 0);
252 tmp->unref(); 232 tmp->unref();
253 233
254 test_cstring(reporter); 234 test_cstring(reporter);
255 test_files(reporter); 235 test_files(reporter);
256 } 236 }
257 237
258 #include "TestClassDef.h" 238 #include "TestClassDef.h"
259 DEFINE_TESTCLASS("Data", DataTestClass, TestData) 239 DEFINE_TESTCLASS("Data", DataTestClass, TestData)
260 DEFINE_TESTCLASS("DataTable", DataTableTestClass, TestDataTable) 240 DEFINE_TESTCLASS("DataTable", DataTableTestClass, TestDataTable)
OLDNEW
« no previous file with comments | « src/core/SkDataTable.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698