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

Side by Side Diff: tests/SerializationTest.cpp

Issue 604873004: Fix SkTableColorFilter deserialization validation. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Increase buffer size in test Created 6 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
« no previous file with comments | « src/effects/SkTableColorFilter.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 "Resources.h" 8 #include "Resources.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkMallocPixelRef.h" 11 #include "SkMallocPixelRef.h"
12 #include "SkOSFile.h" 12 #include "SkOSFile.h"
13 #include "SkPictureRecorder.h" 13 #include "SkPictureRecorder.h"
14 #include "SkTableColorFilter.h"
14 #include "SkTemplates.h" 15 #include "SkTemplates.h"
15 #include "SkTypeface.h" 16 #include "SkTypeface.h"
16 #include "SkWriteBuffer.h" 17 #include "SkWriteBuffer.h"
17 #include "SkValidatingReadBuffer.h" 18 #include "SkValidatingReadBuffer.h"
18 #include "SkXfermodeImageFilter.h" 19 #include "SkXfermodeImageFilter.h"
19 #include "Test.h" 20 #include "Test.h"
20 21
21 static const uint32_t kArraySize = 64; 22 static const uint32_t kArraySize = 64;
22 static const int kBitmapSize = 256; 23 static const int kBitmapSize = 256;
23 24
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 171 }
171 172
172 template<typename T> 173 template<typename T>
173 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed, 174 static T* TestFlattenableSerialization(T* testObj, bool shouldSucceed,
174 skiatest::Reporter* reporter) { 175 skiatest::Reporter* reporter) {
175 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); 176 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
176 SerializationUtils<T>::Write(writer, testObj); 177 SerializationUtils<T>::Write(writer, testObj);
177 size_t bytesWritten = writer.bytesWritten(); 178 size_t bytesWritten = writer.bytesWritten();
178 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); 179 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);
179 180
180 unsigned char dataWritten[1024]; 181 unsigned char dataWritten[4096];
181 SkASSERT(bytesWritten <= sizeof(dataWritten)); 182 SkASSERT(bytesWritten <= sizeof(dataWritten));
182 writer.writeToMemory(dataWritten); 183 writer.writeToMemory(dataWritten);
183 184
184 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 185 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
185 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); 186 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
186 T* obj = NULL; 187 T* obj = NULL;
187 SerializationUtils<T>::Read(buffer, &obj); 188 SerializationUtils<T>::Read(buffer, &obj);
188 REPORTER_ASSERT(reporter, !buffer.isValid()); 189 REPORTER_ASSERT(reporter, !buffer.isValid());
189 REPORTER_ASSERT(reporter, NULL == obj); 190 REPORTER_ASSERT(reporter, NULL == obj);
190 191
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // skip SrcOver, as it is allowed to return NULL from Create() 268 // skip SrcOver, as it is allowed to return NULL from Create()
268 continue; 269 continue;
269 } 270 }
270 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode: :Mode>(i))); 271 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode: :Mode>(i)));
271 REPORTER_ASSERT(reporter, mode.get()); 272 REPORTER_ASSERT(reporter, mode.get());
272 SkAutoTUnref<SkXfermode> copy( 273 SkAutoTUnref<SkXfermode> copy(
273 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter) ); 274 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter) );
274 } 275 }
275 } 276 }
276 277
278 static void TestColorFilterSerialization(skiatest::Reporter* reporter) {
279 uint8_t table[256];
280 for (int i = 0; i < 256; ++i) {
281 table[i] = (i * 41) % 256;
282 }
283 SkAutoTUnref<SkColorFilter> colorFilter(SkTableColorFilter::Create(table));
284 SkAutoTUnref<SkColorFilter> copy(
285 TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, rep orter));
286 }
287
277 static SkBitmap draw_picture(SkPicture& picture) { 288 static SkBitmap draw_picture(SkPicture& picture) {
278 SkBitmap bitmap; 289 SkBitmap bitmap;
279 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()), 290 bitmap.allocN32Pixels(SkScalarCeilToInt(picture.cullRect().width()),
280 SkScalarCeilToInt(picture.cullRect().height())); 291 SkScalarCeilToInt(picture.cullRect().height()));
281 SkCanvas canvas(bitmap); 292 SkCanvas canvas(bitmap);
282 picture.playback(&canvas); 293 picture.playback(&canvas);
283 return bitmap; 294 return bitmap;
284 } 295 }
285 296
286 static void compare_bitmaps(skiatest::Reporter* reporter, 297 static void compare_bitmaps(skiatest::Reporter* reporter,
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 { 428 {
418 SkRegion region; 429 SkRegion region;
419 TestObjectSerialization(&region, reporter); 430 TestObjectSerialization(&region, reporter);
420 } 431 }
421 432
422 // Test xfermode serialization 433 // Test xfermode serialization
423 { 434 {
424 TestXfermodeSerialization(reporter); 435 TestXfermodeSerialization(reporter);
425 } 436 }
426 437
438 // Test color filter serialization
439 {
440 TestColorFilterSerialization(reporter);
441 }
442
427 // Test string serialization 443 // Test string serialization
428 { 444 {
429 SkString string("string"); 445 SkString string("string");
430 TestObjectSerializationNoAlign<SkString, false>(&string, reporter); 446 TestObjectSerializationNoAlign<SkString, false>(&string, reporter);
431 TestObjectSerializationNoAlign<SkString, true>(&string, reporter); 447 TestObjectSerializationNoAlign<SkString, true>(&string, reporter);
432 } 448 }
433 449
434 // Test rrect serialization 450 // Test rrect serialization
435 { 451 {
436 // SkRRect does not initialize anything. 452 // SkRRect does not initialize anything.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 522
507 // Deserialize picture 523 // Deserialize picture
508 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); 524 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
509 SkAutoTUnref<SkPicture> readPict( 525 SkAutoTUnref<SkPicture> readPict(
510 SkPicture::CreateFromBuffer(reader)); 526 SkPicture::CreateFromBuffer(reader));
511 REPORTER_ASSERT(reporter, readPict.get()); 527 REPORTER_ASSERT(reporter, readPict.get());
512 } 528 }
513 529
514 TestPictureTypefaceSerialization(reporter); 530 TestPictureTypefaceSerialization(reporter);
515 } 531 }
OLDNEW
« no previous file with comments | « src/effects/SkTableColorFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698