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

Side by Side Diff: tests/SerializationTest.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « tests/SVGDeviceTest.cpp ('k') | tests/SkBase64Test.cpp » ('j') | 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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 SerializationUtils<T>::Write(writer, testObj); 179 SerializationUtils<T>::Write(writer, testObj);
180 size_t bytesWritten = writer.bytesWritten(); 180 size_t bytesWritten = writer.bytesWritten();
181 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten); 181 REPORTER_ASSERT(reporter, SkAlign4(bytesWritten) == bytesWritten);
182 182
183 unsigned char dataWritten[4096]; 183 unsigned char dataWritten[4096];
184 SkASSERT(bytesWritten <= sizeof(dataWritten)); 184 SkASSERT(bytesWritten <= sizeof(dataWritten));
185 writer.writeToMemory(dataWritten); 185 writer.writeToMemory(dataWritten);
186 186
187 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4) 187 // Make sure this fails when it should (test with smaller size, but still mu ltiple of 4)
188 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4); 188 SkValidatingReadBuffer buffer(dataWritten, bytesWritten - 4);
189 T* obj = NULL; 189 T* obj = nullptr;
190 SerializationUtils<T>::Read(buffer, &obj); 190 SerializationUtils<T>::Read(buffer, &obj);
191 REPORTER_ASSERT(reporter, !buffer.isValid()); 191 REPORTER_ASSERT(reporter, !buffer.isValid());
192 REPORTER_ASSERT(reporter, NULL == obj); 192 REPORTER_ASSERT(reporter, nullptr == obj);
193 193
194 // Make sure this succeeds when it should 194 // Make sure this succeeds when it should
195 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten); 195 SkValidatingReadBuffer buffer2(dataWritten, bytesWritten);
196 const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2. skip(0)); 196 const unsigned char* peekBefore = static_cast<const unsigned char*>(buffer2. skip(0));
197 T* obj2 = NULL; 197 T* obj2 = nullptr;
198 SerializationUtils<T>::Read(buffer2, &obj2); 198 SerializationUtils<T>::Read(buffer2, &obj2);
199 const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.s kip(0)); 199 const unsigned char* peekAfter = static_cast<const unsigned char*>(buffer2.s kip(0));
200 if (shouldSucceed) { 200 if (shouldSucceed) {
201 // This should have succeeded, since there are enough bytes to read this 201 // This should have succeeded, since there are enough bytes to read this
202 REPORTER_ASSERT(reporter, buffer2.isValid()); 202 REPORTER_ASSERT(reporter, buffer2.isValid());
203 REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten); 203 REPORTER_ASSERT(reporter, static_cast<size_t>(peekAfter - peekBefore) == bytesWritten);
204 REPORTER_ASSERT(reporter, obj2); 204 REPORTER_ASSERT(reporter, obj2);
205 } else { 205 } else {
206 // If the deserialization was supposed to fail, make sure it did 206 // If the deserialization was supposed to fail, make sure it did
207 REPORTER_ASSERT(reporter, !buffer.isValid()); 207 REPORTER_ASSERT(reporter, !buffer.isValid());
208 REPORTER_ASSERT(reporter, NULL == obj2); 208 REPORTER_ASSERT(reporter, nullptr == obj2);
209 } 209 }
210 210
211 return obj2; // Return object to perform further validity tests on it 211 return obj2; // Return object to perform further validity tests on it
212 } 212 }
213 213
214 template<typename T> 214 template<typename T>
215 static void TestArraySerialization(T* data, skiatest::Reporter* reporter) { 215 static void TestArraySerialization(T* data, skiatest::Reporter* reporter) {
216 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); 216 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
217 SerializationUtils<T>::Write(writer, data, kArraySize); 217 SerializationUtils<T>::Write(writer, data, kArraySize);
218 size_t bytesWritten = writer.bytesWritten(); 218 size_t bytesWritten = writer.bytesWritten();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 SkPaint paint; 260 SkPaint paint;
261 paint.setImageFilter(deserializedFilter); 261 paint.setImageFilter(deserializedFilter);
262 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24))); 262 canvas.clipRect(SkRect::MakeXYWH(0, 0, SkIntToScalar(24), SkIntToScalar( 24)));
263 canvas.drawBitmap(bitmap, 0, 0, &paint); 263 canvas.drawBitmap(bitmap, 0, 0, &paint);
264 } 264 }
265 } 265 }
266 266
267 static void TestXfermodeSerialization(skiatest::Reporter* reporter) { 267 static void TestXfermodeSerialization(skiatest::Reporter* reporter) {
268 for (size_t i = 0; i <= SkXfermode::kLastMode; ++i) { 268 for (size_t i = 0; i <= SkXfermode::kLastMode; ++i) {
269 if (i == SkXfermode::kSrcOver_Mode) { 269 if (i == SkXfermode::kSrcOver_Mode) {
270 // skip SrcOver, as it is allowed to return NULL from Create() 270 // skip SrcOver, as it is allowed to return nullptr from Create()
271 continue; 271 continue;
272 } 272 }
273 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode: :Mode>(i))); 273 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(static_cast<SkXfermode: :Mode>(i)));
274 REPORTER_ASSERT(reporter, mode.get()); 274 REPORTER_ASSERT(reporter, mode.get());
275 SkAutoTUnref<SkXfermode> copy( 275 SkAutoTUnref<SkXfermode> copy(
276 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter) ); 276 TestFlattenableSerialization<SkXfermode>(mode.get(), true, reporter) );
277 } 277 }
278 } 278 }
279 279
280 static void TestColorFilterSerialization(skiatest::Reporter* reporter) { 280 static void TestColorFilterSerialization(skiatest::Reporter* reporter) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 SkPaint paint; 324 SkPaint paint;
325 paint.setColor(SK_ColorGRAY); 325 paint.setColor(SK_ColorGRAY);
326 paint.setTextSize(SkIntToScalar(30)); 326 paint.setTextSize(SkIntToScalar(30));
327 paint.setTypeface(typeface); 327 paint.setTypeface(typeface);
328 328
329 // Paint some text. 329 // Paint some text.
330 SkPictureRecorder recorder; 330 SkPictureRecorder recorder;
331 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize); 331 SkIRect canvasRect = SkIRect::MakeWH(kBitmapSize, kBitmapSize);
332 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()) , 332 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(canvasRect.width()) ,
333 SkIntToScalar(canvasRect.height() ), 333 SkIntToScalar(canvasRect.height() ),
334 NULL, 0); 334 nullptr, 0);
335 canvas->drawColor(SK_ColorWHITE); 335 canvas->drawColor(SK_ColorWHITE);
336 canvas->drawText(text, 2, 24, 32, paint); 336 canvas->drawText(text, 2, 24, 32, paint);
337 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 337 SkAutoTUnref<SkPicture> picture(recorder.endRecording());
338 338
339 // Serlialize picture and create its clone from stream. 339 // Serlialize picture and create its clone from stream.
340 SkDynamicMemoryWStream stream; 340 SkDynamicMemoryWStream stream;
341 picture->serialize(&stream); 341 picture->serialize(&stream);
342 SkAutoTDelete<SkStream> inputStream(stream.detachAsStream()); 342 SkAutoTDelete<SkStream> inputStream(stream.detachAsStream());
343 SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStrea m.get())); 343 SkAutoTUnref<SkPicture> loadedPicture(SkPicture::CreateFromStream(inputStrea m.get()));
344 344
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 406 }
407 } 407 }
408 408
409 static void draw_something(SkCanvas* canvas) { 409 static void draw_something(SkCanvas* canvas) {
410 SkPaint paint; 410 SkPaint paint;
411 SkBitmap bitmap; 411 SkBitmap bitmap;
412 make_checkerboard_bitmap(bitmap); 412 make_checkerboard_bitmap(bitmap);
413 413
414 canvas->save(); 414 canvas->save();
415 canvas->scale(0.5f, 0.5f); 415 canvas->scale(0.5f, 0.5f);
416 canvas->drawBitmap(bitmap, 0, 0, NULL); 416 canvas->drawBitmap(bitmap, 0, 0, nullptr);
417 canvas->restore(); 417 canvas->restore();
418 418
419 paint.setAntiAlias(true); 419 paint.setAntiAlias(true);
420 420
421 paint.setColor(SK_ColorRED); 421 paint.setColor(SK_ColorRED);
422 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2 ), SkIntToScalar(kBitmapSize/3), paint); 422 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2 ), SkIntToScalar(kBitmapSize/3), paint);
423 paint.setColor(SK_ColorBLACK); 423 paint.setColor(SK_ColorBLACK);
424 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); 424 paint.setTextSize(SkIntToScalar(kBitmapSize/3));
425 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint); 425 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint);
426 } 426 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 // The deserialization should succeed, and the rendering shouldn't crash , 517 // The deserialization should succeed, and the rendering shouldn't crash ,
518 // even when the device fails to initialize, due to its size 518 // even when the device fails to initialize, due to its size
519 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter); 519 TestBitmapSerialization(validBitmap, invalidBitmap, true, reporter);
520 } 520 }
521 521
522 // Test simple SkPicture serialization 522 // Test simple SkPicture serialization
523 { 523 {
524 SkPictureRecorder recorder; 524 SkPictureRecorder recorder;
525 draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize), 525 draw_something(recorder.beginRecording(SkIntToScalar(kBitmapSize),
526 SkIntToScalar(kBitmapSize), 526 SkIntToScalar(kBitmapSize),
527 NULL, 0)); 527 nullptr, 0));
528 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 528 SkAutoTUnref<SkPicture> pict(recorder.endRecording());
529 529
530 // Serialize picture 530 // Serialize picture
531 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag); 531 SkWriteBuffer writer(SkWriteBuffer::kValidation_Flag);
532 pict->flatten(writer); 532 pict->flatten(writer);
533 size_t size = writer.bytesWritten(); 533 size_t size = writer.bytesWritten();
534 SkAutoTMalloc<unsigned char> data(size); 534 SkAutoTMalloc<unsigned char> data(size);
535 writer.writeToMemory(static_cast<void*>(data.get())); 535 writer.writeToMemory(static_cast<void*>(data.get()));
536 536
537 // Deserialize picture 537 // Deserialize picture
538 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size); 538 SkValidatingReadBuffer reader(static_cast<void*>(data.get()), size);
539 SkAutoTUnref<SkPicture> readPict( 539 SkAutoTUnref<SkPicture> readPict(
540 SkPicture::CreateFromBuffer(reader)); 540 SkPicture::CreateFromBuffer(reader));
541 REPORTER_ASSERT(reporter, readPict.get()); 541 REPORTER_ASSERT(reporter, readPict.get());
542 } 542 }
543 543
544 TestPictureTypefaceSerialization(reporter); 544 TestPictureTypefaceSerialization(reporter);
545 } 545 }
OLDNEW
« no previous file with comments | « tests/SVGDeviceTest.cpp ('k') | tests/SkBase64Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698