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

Side by Side Diff: tests/DataRefTest.cpp

Issue 27208002: remove SkDataSet, and just store a key/value in SkAnnotation (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/ports/SkGlobalInitialization_default.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 "SkDataSet.h"
11 #include "SkDataTable.h" 10 #include "SkDataTable.h"
12 #include "SkOrderedReadBuffer.h" 11 #include "SkOrderedReadBuffer.h"
13 #include "SkOrderedWriteBuffer.h" 12 #include "SkOrderedWriteBuffer.h"
14 #include "SkOSFile.h" 13 #include "SkOSFile.h"
15 #include "SkStream.h" 14 #include "SkStream.h"
16 15
17 static void test_is_equal(skiatest::Reporter* reporter, 16 static void test_is_equal(skiatest::Reporter* reporter,
18 const SkDataTable* a, const SkDataTable* b) { 17 const SkDataTable* a, const SkDataTable* b) {
19 REPORTER_ASSERT(reporter, a->count() == b->count()); 18 REPORTER_ASSERT(reporter, a->count() == b->count());
20 for (int i = 0; i < a->count(); ++i) { 19 for (int i = 0; i < a->count(); ++i) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 } 154 }
156 155
157 static void TestDataTable(skiatest::Reporter* reporter) { 156 static void TestDataTable(skiatest::Reporter* reporter) {
158 test_emptytable(reporter); 157 test_emptytable(reporter);
159 test_simpletable(reporter); 158 test_simpletable(reporter);
160 test_vartable(reporter); 159 test_vartable(reporter);
161 test_tablebuilder(reporter); 160 test_tablebuilder(reporter);
162 test_globaltable(reporter); 161 test_globaltable(reporter);
163 } 162 }
164 163
165 static void unrefAll(const SkDataSet::Pair pairs[], int count) {
166 for (int i = 0; i < count; ++i) {
167 pairs[i].fValue->unref();
168 }
169 }
170
171 // asserts that inner is a subset of outer
172 static void test_dataset_subset(skiatest::Reporter* reporter,
173 const SkDataSet& outer, const SkDataSet& inner) {
174 SkDataSet::Iter iter(inner);
175 for (; !iter.done(); iter.next()) {
176 SkData* outerData = outer.find(iter.key());
177 REPORTER_ASSERT(reporter, outerData);
178 REPORTER_ASSERT(reporter, outerData->equals(iter.value()));
179 }
180 }
181
182 static void test_datasets_equal(skiatest::Reporter* reporter,
183 const SkDataSet& ds0, const SkDataSet& ds1) {
184 REPORTER_ASSERT(reporter, ds0.count() == ds1.count());
185
186 test_dataset_subset(reporter, ds0, ds1);
187 test_dataset_subset(reporter, ds1, ds0);
188 }
189
190 static void test_dataset(skiatest::Reporter* reporter, const SkDataSet& ds,
191 int count) {
192 REPORTER_ASSERT(reporter, ds.count() == count);
193
194 SkDataSet::Iter iter(ds);
195 int index = 0;
196 for (; !iter.done(); iter.next()) {
197 // const char* name = iter.key();
198 // SkData* data = iter.value();
199 // SkDebugf("[%d] %s:%s\n", index, name, (const char*)data->bytes());
200 index += 1;
201 }
202 REPORTER_ASSERT(reporter, index == count);
203
204 SkDynamicMemoryWStream ostream;
205 ds.writeToStream(&ostream);
206 SkMemoryStream istream;
207 istream.setData(ostream.copyToData())->unref();
208 SkDataSet copy(&istream);
209
210 test_datasets_equal(reporter, ds, copy);
211 }
212
213 static void test_dataset(skiatest::Reporter* reporter) {
214 SkDataSet set0(NULL, 0);
215 SkDataSet set1("hello", SkAutoTUnref<SkData>(SkData::NewWithCString("world") ));
216
217 const SkDataSet::Pair pairs[] = {
218 { "one", SkData::NewWithCString("1") },
219 { "two", SkData::NewWithCString("2") },
220 { "three", SkData::NewWithCString("3") },
221 };
222 SkDataSet set3(pairs, 3);
223 unrefAll(pairs, 3);
224
225 test_dataset(reporter, set0, 0);
226 test_dataset(reporter, set1, 1);
227 test_dataset(reporter, set3, 3);
228 }
229
230 static void* gGlobal; 164 static void* gGlobal;
231 165
232 static void delete_int_proc(const void* ptr, size_t len, void* context) { 166 static void delete_int_proc(const void* ptr, size_t len, void* context) {
233 int* data = (int*)ptr; 167 int* data = (int*)ptr;
234 SkASSERT(context == gGlobal); 168 SkASSERT(context == gGlobal);
235 delete[] data; 169 delete[] data;
236 } 170 }
237 171
238 static void assert_len(skiatest::Reporter* reporter, SkData* ref, size_t len) { 172 static void assert_len(skiatest::Reporter* reporter, SkData* ref, size_t len) {
239 REPORTER_ASSERT(reporter, ref->size() == len); 173 REPORTER_ASSERT(reporter, ref->size() == len);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 assert_data(reporter, r3, "people", 6); 245 assert_data(reporter, r3, "people", 6);
312 246
313 SkData* tmp = SkData::NewSubset(r1, strlen(str), 10); 247 SkData* tmp = SkData::NewSubset(r1, strlen(str), 10);
314 assert_len(reporter, tmp, 0); 248 assert_len(reporter, tmp, 0);
315 tmp->unref(); 249 tmp->unref();
316 tmp = SkData::NewSubset(r1, 0, 0); 250 tmp = SkData::NewSubset(r1, 0, 0);
317 assert_len(reporter, tmp, 0); 251 assert_len(reporter, tmp, 0);
318 tmp->unref(); 252 tmp->unref();
319 253
320 test_cstring(reporter); 254 test_cstring(reporter);
321 test_dataset(reporter);
322 test_files(reporter); 255 test_files(reporter);
323 } 256 }
324 257
325 #include "TestClassDef.h" 258 #include "TestClassDef.h"
326 DEFINE_TESTCLASS("Data", DataTestClass, TestData) 259 DEFINE_TESTCLASS("Data", DataTestClass, TestData)
327 DEFINE_TESTCLASS("DataTable", DataTableTestClass, TestDataTable) 260 DEFINE_TESTCLASS("DataTable", DataTableTestClass, TestDataTable)
OLDNEW
« no previous file with comments | « src/ports/SkGlobalInitialization_default.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698