OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 355 |
356 result = codec->getScanlines(bm.getAddr(0, height - remainingLines), | 356 result = codec->getScanlines(bm.getAddr(0, height - remainingLines), |
357 remainingLines, bm.rowBytes()); | 357 remainingLines, bm.rowBytes()); |
358 REPORTER_ASSERT(r, result == SkCodec::kSuccess); | 358 REPORTER_ASSERT(r, result == SkCodec::kSuccess); |
359 } | 359 } |
360 | 360 |
361 compare_to_good_digest(r, digest, bm); | 361 compare_to_good_digest(r, digest, bm); |
362 } | 362 } |
363 | 363 |
364 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_
t len) { | 364 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_
t len) { |
| 365 // Neither of these calls should return a codec. Bots should catch us if we
leaked anything. |
365 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals
e)); | 366 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals
e)); |
366 // We should not have gotten a codec. Bots should catch us if we leaked anyt
hing. | 367 REPORTER_ASSERT(r, !codec); |
| 368 |
| 369 codec = SkScaledCodec::NewFromStream(new SkMemoryStream(stream, len, false))
; |
367 REPORTER_ASSERT(r, !codec); | 370 REPORTER_ASSERT(r, !codec); |
368 } | 371 } |
369 | 372 |
370 // Ensure that SkCodec::NewFromStream handles freeing the passed in SkStream, | 373 // Ensure that SkCodec::NewFromStream handles freeing the passed in SkStream, |
371 // even on failure. Test some bad streams. | 374 // even on failure. Test some bad streams. |
372 DEF_TEST(Codec_leaks, r) { | 375 DEF_TEST(Codec_leaks, r) { |
373 // No codec should claim this as their format, so this tests SkCodec::NewFro
mStream. | 376 // No codec should claim this as their format, so this tests SkCodec::NewFro
mStream. |
374 const char nonSupportedStream[] = "hello world"; | 377 const char nonSupportedStream[] = "hello world"; |
375 // The other strings should look like the beginning of a file type, so we'll
call some | 378 // The other strings should look like the beginning of a file type, so we'll
call some |
376 // internal version of NewFromStream, which must also delete the stream on f
ailure. | 379 // internal version of NewFromStream, which must also delete the stream on f
ailure. |
377 const unsigned char emptyPng[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a,
0x0a }; | 380 const unsigned char emptyPng[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a,
0x0a }; |
378 const unsigned char emptyJpeg[] = { 0xFF, 0xD8, 0xFF }; | 381 const unsigned char emptyJpeg[] = { 0xFF, 0xD8, 0xFF }; |
379 const char emptyWebp[] = "RIFF1234WEBPVP"; | 382 const char emptyWebp[] = "RIFF1234WEBPVP"; |
380 const char emptyBmp[] = { 'B', 'M' }; | 383 const char emptyBmp[] = { 'B', 'M' }; |
381 const char emptyIco[] = { '\x00', '\x00', '\x01', '\x00' }; | 384 const char emptyIco[] = { '\x00', '\x00', '\x01', '\x00' }; |
382 const char emptyGif[] = "GIFVER"; | 385 const char emptyGif[] = "GIFVER"; |
383 | 386 |
384 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); | 387 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); |
385 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); | 388 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); |
386 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); | 389 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); |
387 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); | 390 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); |
388 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); | 391 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); |
389 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); | 392 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); |
390 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); | 393 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); |
391 } | 394 } |
392 | 395 |
| 396 DEF_TEST(Codec_null, r) { |
| 397 // Attempting to create an SkCodec or an SkScaledCodec with null should not |
| 398 // crash. |
| 399 SkCodec* codec = SkCodec::NewFromStream(nullptr); |
| 400 REPORTER_ASSERT(r, !codec); |
| 401 |
| 402 codec = SkScaledCodec::NewFromStream(nullptr); |
| 403 REPORTER_ASSERT(r, !codec); |
| 404 } |
| 405 |
393 static void test_dimensions(skiatest::Reporter* r, const char path[]) { | 406 static void test_dimensions(skiatest::Reporter* r, const char path[]) { |
394 // Create the codec from the resource file | 407 // Create the codec from the resource file |
395 SkAutoTDelete<SkStream> stream(resource(path)); | 408 SkAutoTDelete<SkStream> stream(resource(path)); |
396 if (!stream) { | 409 if (!stream) { |
397 SkDebugf("Missing resource '%s'\n", path); | 410 SkDebugf("Missing resource '%s'\n", path); |
398 return; | 411 return; |
399 } | 412 } |
400 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromStream(stream.detach())); | 413 SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromStream(stream.detach())); |
401 if (!codec) { | 414 if (!codec) { |
402 ERRORF(r, "Unable to create codec '%s'", path); | 415 ERRORF(r, "Unable to create codec '%s'", path); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 512 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
500 result = decoder->startScanlineDecode( | 513 result = decoder->startScanlineDecode( |
501 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); | 514 decoder->getInfo().makeColorType(kIndex_8_SkColorType)); |
502 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); | 515 REPORTER_ASSERT(r, SkCodec::kInvalidParameters == result); |
503 } | 516 } |
504 | 517 |
505 DEF_TEST(Codec_Params, r) { | 518 DEF_TEST(Codec_Params, r) { |
506 test_invalid_parameters(r, "index8.png"); | 519 test_invalid_parameters(r, "index8.png"); |
507 test_invalid_parameters(r, "mandrill.wbmp"); | 520 test_invalid_parameters(r, "mandrill.wbmp"); |
508 } | 521 } |
OLD | NEW |