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

Side by Side Diff: tests/SerializationTest.cpp

Issue 110503003: PixelRef now returns (nearly) everything that is currently in SkBitmap. The goal is to refactor bit… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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 | « tests/PixelRefTest.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 * Copyright 2013 Google Inc. 2 * Copyright 2013 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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 template<typename T> 141 template<typename T>
142 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, 142 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
143 skiatest::Reporter* reporter) { 143 skiatest::Reporter* reporter) {
144 SkOrderedWriteBuffer writer(1024); 144 SkOrderedWriteBuffer writer(1024);
145 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag); 145 writer.setFlags(SkOrderedWriteBuffer::kValidation_Flag);
146 SerializationUtils<T>::Write(writer, testObj); 146 SerializationUtils<T>::Write(writer, testObj);
147 size_t bytesWritten = writer.bytesWritten(); 147 size_t bytesWritten = writer.bytesWritten();
148 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); 148 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);
149 149
150 unsigned char dataWritten[1024]; 150 unsigned char dataWritten[1024];
151 SkASSERT(bytesWritten <= sizeof(dataWritten));
151 writer.writeToMemory(dataWritten); 152 writer.writeToMemory(dataWritten);
152 153
153 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 154 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
154 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); 155 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
155 T* obj = NULL; 156 T* obj = NULL;
156 SerializationUtils<T>::Read(buffer, &obj); 157 SerializationUtils<T>::Read(buffer, &obj);
157 REPORTER_ASSERT(reporter, !buffer.isValid()); 158 REPORTER_ASSERT(reporter, !buffer.isValid());
158 REPORTER_ASSERT(reporter, NULL == obj); 159 REPORTER_ASSERT(reporter, NULL == obj);
159 160
160 // Make sure this succeeds when it should 161 // Make sure this succeeds when it should
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 301
301 // Create a bitmap with a really large height 302 // Create a bitmap with a really large height
302 SkBitmap invalidBitmap; 303 SkBitmap invalidBitmap;
303 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); 304 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000);
304 305
305 // The deserialization should succeed, and the rendering shouldn't crash , 306 // The deserialization should succeed, and the rendering shouldn't crash ,
306 // even when the device fails to initialize, due to its size 307 // even when the device fails to initialize, due to its size
307 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); 308 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter);
308 309
309 // Create a bitmap with a pixel ref too small 310 // Create a bitmap with a pixel ref too small
311 SkImageInfo info;
312 info.fWidth = 256;
313 info.fHeight = 256;
314 info.fColorType = kPMColor_SkColorType;
315 info.fAlphaType = kPremul_SkAlphaType;
316
310 SkBitmap invalidBitmap2; 317 SkBitmap invalidBitmap2;
311 invalidBitmap2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256); 318 invalidBitmap2.setConfig(info);
312 invalidBitmap2.setPixelRef(SkNEW_ARGS(SkMallocPixelRef, 319
313 (NULL, 256, NULL)))->unref(); 320 // Hack to force invalid, by making the pixelref smaller than its
321 // owning bitmap.
322 info.fWidth = 32;
323 info.fHeight = 1;
324
325 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate(
326 info, invalidBitmap2.rowBytes(), NULL))->unref();
314 327
315 // The deserialization should detect the pixel ref being too small and f ail 328 // The deserialization should detect the pixel ref being too small and f ail
316 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); 329 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter);
317 } 330 }
318 } 331 }
319 332
320 #include "TestClassDef.h" 333 #include "TestClassDef.h"
321 DEFINE_TESTCLASS("Serialization", SerializationClass, Tests) 334 DEFINE_TESTCLASS("Serialization", SerializationClass, Tests)
OLDNEW
« no previous file with comments | « tests/PixelRefTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698