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

Side by Side Diff: tests/StreamTest.cpp

Issue 2206633004: Move off SK_SUPPORT_LEGACY_DATA_FACTORIES. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Gotta catch 'em all. Created 4 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkFrontBufferedStream.h" 10 #include "SkFrontBufferedStream.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 ERRORF(reporter, "sizes:%x != n:%x\n", i, sizes[i], n); 167 ERRORF(reporter, "sizes:%x != n:%x\n", i, sizes[i], n);
168 } 168 }
169 } 169 }
170 } 170 }
171 171
172 // Test that setting an SkMemoryStream to a nullptr data does not result in a cr ash when calling 172 // Test that setting an SkMemoryStream to a nullptr data does not result in a cr ash when calling
173 // methods that access fData. 173 // methods that access fData.
174 static void TestDereferencingData(SkMemoryStream* memStream) { 174 static void TestDereferencingData(SkMemoryStream* memStream) {
175 memStream->read(nullptr, 0); 175 memStream->read(nullptr, 0);
176 memStream->getMemoryBase(); 176 memStream->getMemoryBase();
177 SkAutoDataUnref data(memStream->copyToData()); 177 sk_sp<SkData> data(memStream->copyToData());
178 } 178 }
179 179
180 static void TestNullData() { 180 static void TestNullData() {
181 SkData* nullData = nullptr; 181 SkData* nullData = nullptr;
182 SkMemoryStream memStream(nullData); 182 SkMemoryStream memStream(nullData);
183 TestDereferencingData(&memStream); 183 TestDereferencingData(&memStream);
184 184
185 memStream.setData(nullData); 185 memStream.setData(nullData);
186 TestDereferencingData(&memStream); 186 TestDereferencingData(&memStream);
187 187
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 SkDynamicMemoryWStream dynamicMemoryWStream; 354 SkDynamicMemoryWStream dynamicMemoryWStream;
355 for (int i = 0; i < 32; ++i) { 355 for (int i = 0; i < 32; ++i) {
356 // Randomize the length of the blocks. 356 // Randomize the length of the blocks.
357 size_t size = rand.nextRangeU(1, sizeof(buffer)); 357 size_t size = rand.nextRangeU(1, sizeof(buffer));
358 for (size_t j = 0; j < size; ++j) { 358 for (size_t j = 0; j < size; ++j) {
359 buffer[j] = valueSource.nextU() & 0xFF; 359 buffer[j] = valueSource.nextU() & 0xFF;
360 } 360 }
361 dynamicMemoryWStream.write(buffer, size); 361 dynamicMemoryWStream.write(buffer, size);
362 } 362 }
363 SkAutoTDelete<SkStreamAsset> asset(dynamicMemoryWStream.detachAsStream()); 363 SkAutoTDelete<SkStreamAsset> asset(dynamicMemoryWStream.detachAsStream());
364 SkAutoTUnref<SkData> expected(SkData::NewUninitialized(asset->getLength())); 364 sk_sp<SkData> expected(SkData::MakeUninitialized(asset->getLength()));
365 uint8_t* expectedPtr = static_cast<uint8_t*>(expected->writable_data()); 365 uint8_t* expectedPtr = static_cast<uint8_t*>(expected->writable_data());
366 valueSource.setSeed(kSeed); // reseed. 366 valueSource.setSeed(kSeed); // reseed.
367 // We want the exact same same "random" string of numbers to put 367 // We want the exact same same "random" string of numbers to put
368 // in expected. i.e.: don't rely on SkDynamicMemoryStream to work 368 // in expected. i.e.: don't rely on SkDynamicMemoryStream to work
369 // correctly while we are testing SkDynamicMemoryStream. 369 // correctly while we are testing SkDynamicMemoryStream.
370 for (size_t i = 0; i < asset->getLength(); ++i) { 370 for (size_t i = 0; i < asset->getLength(); ++i) {
371 expectedPtr[i] = valueSource.nextU() & 0xFF; 371 expectedPtr[i] = valueSource.nextU() & 0xFF;
372 } 372 }
373 stream_peek_test(rep, asset, expected); 373 stream_peek_test(rep, asset, expected.get());
374 } 374 }
375 375
376 namespace { 376 namespace {
377 class DumbStream : public SkStream { 377 class DumbStream : public SkStream {
378 public: 378 public:
379 DumbStream(const uint8_t* data, size_t n) 379 DumbStream(const uint8_t* data, size_t n)
380 : fData(data), fCount(n), fIdx(0) {} 380 : fData(data), fCount(n), fIdx(0) {}
381 size_t read(void* buffer, size_t size) override { 381 size_t read(void* buffer, size_t size) override {
382 size_t copyCount = SkTMin(fCount - fIdx, size); 382 size_t copyCount = SkTMin(fCount - fIdx, size);
383 if (copyCount) { 383 if (copyCount) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 stream_copy_test(reporter, src, N, &dumbStream); 427 stream_copy_test(reporter, src, N, &dumbStream);
428 SkMemoryStream smartStream(src.get(), (size_t)N); 428 SkMemoryStream smartStream(src.get(), (size_t)N);
429 stream_copy_test(reporter, src, N, &smartStream); 429 stream_copy_test(reporter, src, N, &smartStream);
430 } 430 }
431 431
432 DEF_TEST(StreamEmptyStreamMemoryBase, r) { 432 DEF_TEST(StreamEmptyStreamMemoryBase, r) {
433 SkDynamicMemoryWStream tmp; 433 SkDynamicMemoryWStream tmp;
434 SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream()); 434 SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream());
435 REPORTER_ASSERT(r, nullptr == asset->getMemoryBase()); 435 REPORTER_ASSERT(r, nullptr == asset->getMemoryBase());
436 } 436 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698