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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); | 102 check(r, "mandrill_128.png", SkISize::Make(128, 128), true); |
103 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); | 103 check(r, "mandrill_16.png", SkISize::Make(16, 16), true); |
104 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); | 104 check(r, "mandrill_256.png", SkISize::Make(256, 256), true); |
105 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); | 105 check(r, "mandrill_32.png", SkISize::Make(32, 32), true); |
106 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); | 106 check(r, "mandrill_512.png", SkISize::Make(512, 512), true); |
107 check(r, "mandrill_64.png", SkISize::Make(64, 64), true); | 107 check(r, "mandrill_64.png", SkISize::Make(64, 64), true); |
108 check(r, "plane.png", SkISize::Make(250, 126), true); | 108 check(r, "plane.png", SkISize::Make(250, 126), true); |
109 check(r, "randPixels.png", SkISize::Make(8, 8), true); | 109 check(r, "randPixels.png", SkISize::Make(8, 8), true); |
110 check(r, "yellow_rose.png", SkISize::Make(400, 301), true); | 110 check(r, "yellow_rose.png", SkISize::Make(400, 301), true); |
111 } | 111 } |
| 112 |
| 113 static void test_invalid_stream(skiatest::Reporter* r, const void* stream, size_
t len) { |
| 114 SkCodec* codec = SkCodec::NewFromStream(new SkMemoryStream(stream, len, fals
e)); |
| 115 // We should not have gotten a codec. Bots should catch us if we leaked anyt
hing. |
| 116 REPORTER_ASSERT(r, !codec); |
| 117 } |
| 118 |
| 119 // Ensure that SkCodec::NewFromStream handles freeing the passed in SkStream, |
| 120 // even on failure. Test some bad streams. |
| 121 DEF_TEST(Codec_leaks, r) { |
| 122 // No codec should claim this as their format, so this tests SkCodec::NewFro
mStream. |
| 123 const char nonSupportedStream[] = "hello world"; |
| 124 // The other strings should look like the beginning of a file type, so we'll
call some |
| 125 // internal version of NewFromStream, which must also delete the stream on f
ailure. |
| 126 const unsigned char emptyPng[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a,
0x0a }; |
| 127 const unsigned char emptyJpeg[] = { 0xFF, 0xD8, 0xFF }; |
| 128 const char emptyWebp[] = "RIFF1234WEBPVP"; |
| 129 const char emptyBmp[] = { 'B', 'M' }; |
| 130 const char emptyIco[] = { '\x00', '\x00', '\x01', '\x00' }; |
| 131 const char emptyGif[] = "GIFVER"; |
| 132 |
| 133 test_invalid_stream(r, nonSupportedStream, sizeof(nonSupportedStream)); |
| 134 test_invalid_stream(r, emptyPng, sizeof(emptyPng)); |
| 135 test_invalid_stream(r, emptyJpeg, sizeof(emptyJpeg)); |
| 136 test_invalid_stream(r, emptyWebp, sizeof(emptyWebp)); |
| 137 test_invalid_stream(r, emptyBmp, sizeof(emptyBmp)); |
| 138 test_invalid_stream(r, emptyIco, sizeof(emptyIco)); |
| 139 test_invalid_stream(r, emptyGif, sizeof(emptyGif)); |
| 140 } |
OLD | NEW |