aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar yujieqin <yujieqin@google.com>2016-02-05 08:21:19 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-05 08:21:19 -0800
commit9c7a8a464894436fc71a15b5419e818905226cdf (patch)
treeeeaf5afed6b1cc4745769f54274b0140067282ec /tests
parente63ffef6248bd103b5f7827f1e4bc75e47ca9e20 (diff)
Optimize the SkRawStream when the input is an asset stream
Diffstat (limited to 'tests')
-rw-r--r--tests/CodexTest.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index 747d064481..1261d2b556 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -389,6 +389,7 @@ DEF_TEST(Codec, r) {
// RAW
#if defined(SK_CODEC_DECODES_RAW)
check(r, "sample_1mp.dng", SkISize::Make(600, 338), false, false, false);
+ check(r, "dng_with_preview.dng", SkISize::Make(600, 338), true, false, false);
#endif
}
@@ -586,6 +587,7 @@ DEF_TEST(Codec_Dimensions, r) {
// RAW
#if defined(SK_CODEC_DECODES_RAW)
test_dimensions(r, "sample_1mp.dng");
+ test_dimensions(r, "dng_with_preview.dng");
#endif
}
@@ -829,6 +831,54 @@ private:
const size_t fLimit;
};
+// Stream that is not an asset stream (!hasPosition() or !hasLength())
+class NotAssetMemStream : public SkStream {
+public:
+ NotAssetMemStream(SkData* data) : fStream(data) {}
+
+ bool hasPosition() const override {
+ return false;
+ }
+
+ bool hasLength() const override {
+ return false;
+ }
+
+ size_t peek(void* buf, size_t bytes) const override {
+ return fStream.peek(buf, bytes);
+ }
+ size_t read(void* buf, size_t bytes) override {
+ return fStream.read(buf, bytes);
+ }
+ bool rewind() override {
+ return fStream.rewind();
+ }
+ bool isAtEnd() const override {
+ return fStream.isAtEnd();
+ }
+private:
+ SkMemoryStream fStream;
+};
+
+// Test that the RawCodec works also for not asset stream. This will test the code path using
+// SkRawBufferedStream instead of SkRawAssetStream.
+#if defined(SK_CODEC_DECODES_RAW)
+DEF_TEST(Codec_raw_notseekable, r) {
+ const char* path = "dng_with_preview.dng";
+ SkString fullPath(GetResourcePath(path));
+ SkAutoTUnref<SkData> data(SkData::NewFromFileName(fullPath.c_str()));
+ if (!data) {
+ SkDebugf("Missing resource '%s'\n", path);
+ return;
+ }
+
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(new NotAssetMemStream(data)));
+ REPORTER_ASSERT(r, codec);
+
+ test_info(r, codec.get(), codec->getInfo(), SkCodec::kSuccess, nullptr);
+}
+#endif
+
// Test that even if webp_parse_header fails to peek enough, it will fall back to read()
// + rewind() and succeed.
DEF_TEST(Codec_webp_peek, r) {