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

Side by Side Diff: tests/SerializationTest.cpp

Issue 103033005: Revert "remvoe duplicate impl for SkImageInfo flattening" (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));
152 writer.writeToMemory(dataWritten); 151 writer.writeToMemory(dataWritten);
153 152
154 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 153 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
155 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); 154 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
156 T* obj = NULL; 155 T* obj = NULL;
157 SerializationUtils<T>::Read(buffer, &obj); 156 SerializationUtils<T>::Read(buffer, &obj);
158 REPORTER_ASSERT(reporter, !buffer.isValid()); 157 REPORTER_ASSERT(reporter, !buffer.isValid());
159 REPORTER_ASSERT(reporter, NULL == obj); 158 REPORTER_ASSERT(reporter, NULL == obj);
160 159
161 // Make sure this succeeds when it should 160 // Make sure this succeeds when it should
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 300
302 // Create a bitmap with a really large height 301 // Create a bitmap with a really large height
303 SkBitmap invalidBitmap; 302 SkBitmap invalidBitmap;
304 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000); 303 invalidBitmap.setConfig(SkBitmap::kARGB_8888_Config, 256, 1000000000);
305 304
306 // The deserialization should succeed, and the rendering shouldn't crash , 305 // The deserialization should succeed, and the rendering shouldn't crash ,
307 // even when the device fails to initialize, due to its size 306 // even when the device fails to initialize, due to its size
308 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); 307 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter);
309 308
310 // Create a bitmap with a pixel ref too small 309 // 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
317 SkBitmap invalidBitmap2; 310 SkBitmap invalidBitmap2;
318 invalidBitmap2.setConfig(info); 311 invalidBitmap2.setConfig(SkBitmap::kARGB_8888_Config, 256, 256);
319 312 invalidBitmap2.setPixelRef(SkNEW_ARGS(SkMallocPixelRef,
320 // Hack to force invalid, by making the pixelref smaller than its 313 (NULL, 256, NULL)))->unref();
321 // owning bitmap.
322 info.fWidth = 32;
323 info.fHeight = 1;
324
325 invalidBitmap2.setPixelRef(SkMallocPixelRef::NewAllocate(
326 info, invalidBitmap2.rowBytes(), NULL))->unref();
327 314
328 // The deserialization should detect the pixel ref being too small and f ail 315 // The deserialization should detect the pixel ref being too small and f ail
329 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter); 316 TestBitmapSerialization(validBitmap, invalidBitmap2, false, reporter);
330 } 317 }
331 } 318 }
332 319
333 #include "TestClassDef.h" 320 #include "TestClassDef.h"
334 DEFINE_TESTCLASS("Serialization", SerializationClass, Tests) 321 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