diff options
author | fmalita <fmalita@chromium.org> | 2015-09-03 07:17:25 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-03 07:17:25 -0700 |
commit | 2be7125f3274a4b661f50e992fc0eb3c14c24f05 (patch) | |
tree | de15270f9114db847f7f8d317c050f5b83062b52 /tests | |
parent | 1a9cafff044e5a352c60065e44d64e9d0eb8f92a (diff) |
Add a SkPixelSerializer SkImage encode variant
R=reed@google.com
BUG=skia:4285
Review URL: https://codereview.chromium.org/1310633006
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ImageTest.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index bbf6682084..d271966979 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -10,6 +10,7 @@ #include "SkDevice.h" #include "SkImageEncoder.h" #include "SkImage_Base.h" +#include "SkPixelSerializer.h" #include "SkRRect.h" #include "SkSurface.h" #include "SkUtils.h" @@ -104,6 +105,36 @@ DEF_GPUTEST(Image_Encode_Gpu, reporter, factory) { } #endif +namespace { + +const char* kSerializedData = "serialized"; + +class MockSerializer : public SkPixelSerializer { +protected: + bool onUseEncodedData(const void*, size_t) override { + return false; + } + + SkData* onEncodePixels(const SkImageInfo&, const void*, size_t) override { + return SkData::NewWithCString(kSerializedData); + } +}; + +} // anonymous namespace + +// Test that SkImage encoding observes custom pixel serializers. +DEF_TEST(Image_Encode_Serializer, reporter) { + MockSerializer serializer; + const SkIRect ir = SkIRect::MakeXYWH(5, 5, 10, 10); + SkAutoTUnref<SkImage> image(make_image(nullptr, 20, 20, ir)); + SkAutoTUnref<SkData> encoded(image->encode(&serializer)); + SkAutoTUnref<SkData> reference(SkData::NewWithCString(kSerializedData)); + + REPORTER_ASSERT(reporter, encoded); + REPORTER_ASSERT(reporter, encoded->size() > 0); + REPORTER_ASSERT(reporter, encoded->equals(reference)); +} + DEF_TEST(Image_NewRasterCopy, reporter) { const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); |