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

Side by Side Diff: tests/CodexTest.cpp

Issue 1779263003: Make sp variants for SkData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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/sfnt/SkOTUtils.cpp ('k') | tests/Writer32Test.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 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 "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkBitmap.h" 10 #include "SkBitmap.h"
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 891
892 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 892 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
893 } 893 }
894 #endif 894 #endif
895 895
896 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read() 896 // Test that even if webp_parse_header fails to peek enough, it will fall back t o read()
897 // + rewind() and succeed. 897 // + rewind() and succeed.
898 DEF_TEST(Codec_webp_peek, r) { 898 DEF_TEST(Codec_webp_peek, r) {
899 const char* path = "baby_tux.webp"; 899 const char* path = "baby_tux.webp";
900 SkString fullPath(GetResourcePath(path)); 900 SkString fullPath(GetResourcePath(path));
901 SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str())); 901 auto data = SkData::MakeFromFileName(fullPath.c_str());
902 if (!data) { 902 if (!data) {
903 SkDebugf("Missing resource '%s'\n", path); 903 SkDebugf("Missing resource '%s'\n", path);
904 return; 904 return;
905 } 905 }
906 906
907 // The limit is less than webp needs to peek or read. 907 // The limit is less than webp needs to peek or read.
908 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new LimitedPeekingMemStr eam(data, 25))); 908 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(
909 new LimitedPeekingMemStream(data.get(), 25)));
909 REPORTER_ASSERT(r, codec); 910 REPORTER_ASSERT(r, codec);
910 911
911 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 912 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
912 913
913 // Similarly, a stream which does not peek should still succeed. 914 // Similarly, a stream which does not peek should still succeed.
914 codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data, 0))); 915 codec.reset(SkCodec::NewFromStream(new LimitedPeekingMemStream(data.get(), 0 )));
915 REPORTER_ASSERT(r, codec); 916 REPORTER_ASSERT(r, codec);
916 917
917 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 918 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
918 } 919 }
919 920
920 // SkCodec's wbmp decoder was initially unnecessarily restrictive. 921 // SkCodec's wbmp decoder was initially unnecessarily restrictive.
921 // It required the second byte to be zero. The wbmp specification allows 922 // It required the second byte to be zero. The wbmp specification allows
922 // a couple of bits to be 1 (so long as they do not overlap with 0x9F). 923 // a couple of bits to be 1 (so long as they do not overlap with 0x9F).
923 // Test that SkCodec now supports an image with these bits set. 924 // Test that SkCodec now supports an image with these bits set.
924 DEF_TEST(Codec_wbmp, r) { 925 DEF_TEST(Codec_wbmp, r) {
925 const char* path = "mandrill.wbmp"; 926 const char* path = "mandrill.wbmp";
926 SkAutoTDelete<SkStream> stream(resource(path)); 927 SkAutoTDelete<SkStream> stream(resource(path));
927 if (!stream) { 928 if (!stream) {
928 SkDebugf("Missing resource '%s'\n", path); 929 SkDebugf("Missing resource '%s'\n", path);
929 return; 930 return;
930 } 931 }
931 932
932 // Modify the stream to contain a second byte with some bits set. 933 // Modify the stream to contain a second byte with some bits set.
933 SkAutoTUnref<SkData> data(SkCopyStreamToData(stream)); 934 auto data = SkCopyStreamToData(stream);
934 uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data()); 935 uint8_t* writeableData = static_cast<uint8_t*>(data->writable_data());
935 writeableData[1] = static_cast<uint8_t>(~0x9F); 936 writeableData[1] = static_cast<uint8_t>(~0x9F);
936 937
937 // SkCodec should support this. 938 // SkCodec should support this.
938 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data)); 939 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(data.get()));
939 REPORTER_ASSERT(r, codec); 940 REPORTER_ASSERT(r, codec);
940 if (!codec) { 941 if (!codec) {
941 return; 942 return;
942 } 943 }
943 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr); 944 test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
944 } 945 }
945 946
946 // wbmp images have a header that can be arbitrarily large, depending on the 947 // wbmp images have a header that can be arbitrarily large, depending on the
947 // size of the image. We cap the size at 65535, meaning we only need to look at 948 // size of the image. We cap the size at 65535, meaning we only need to look at
948 // 8 bytes to determine whether we can read the image. This is important 949 // 8 bytes to determine whether we can read the image. This is important
(...skipping 15 matching lines...) Expand all
964 // Now test an image which is too big. Any image with a larger header (i.e. 965 // Now test an image which is too big. Any image with a larger header (i.e.
965 // has bigger width/height) is also too big. 966 // has bigger width/height) is also too big.
966 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header 967 const unsigned char tooBigWbmp[] = { 0x00, 0x00, // Header
967 0x84, 0x80, 0x00, // W: 65536 968 0x84, 0x80, 0x00, // W: 65536
968 0x84, 0x80, 0x00 }; // H: 65536 969 0x84, 0x80, 0x00 }; // H: 65536
969 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false)); 970 stream.reset(new SkMemoryStream(tooBigWbmp, sizeof(tooBigWbmp), false));
970 codec.reset(SkCodec::NewFromStream(stream.detach())); 971 codec.reset(SkCodec::NewFromStream(stream.detach()));
971 972
972 REPORTER_ASSERT(r, !codec); 973 REPORTER_ASSERT(r, !codec);
973 } 974 }
OLDNEW
« no previous file with comments | « src/sfnt/SkOTUtils.cpp ('k') | tests/Writer32Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698