aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/FrontBufferedStreamTest.cpp
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2014-10-24 06:55:07 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-24 06:55:07 -0700
commit3ceef9a66aa1ae8db896b8e75496194978708476 (patch)
tree236e918e4ed1bba0038b3a3966bf0248f9e0e138 /tests/FrontBufferedStreamTest.cpp
parentb752f9f83891a72a39d2027eb33e3aecdea9e9e8 (diff)
Add test for new FrontBufferedStream behavior.
Test for https://skia.googlesource.com/skia/+/dd5a1e094c19fa10202c37c50a1f799e5af5dac0 Verify that FrontBufferedStream does not attempt to read beyond the end of its underlying stream. Make SkStreamToCGImageSource handle an empty stream better. Review URL: https://codereview.chromium.org/641813009
Diffstat (limited to 'tests/FrontBufferedStreamTest.cpp')
-rw-r--r--tests/FrontBufferedStreamTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/FrontBufferedStreamTest.cpp b/tests/FrontBufferedStreamTest.cpp
index cb11b12de8..e8c2c6a678 100644
--- a/tests/FrontBufferedStreamTest.cpp
+++ b/tests/FrontBufferedStreamTest.cpp
@@ -5,7 +5,9 @@
* found in the LICENSE file.
*/
+#include "SkBitmap.h"
#include "SkFrontBufferedStream.h"
+#include "SkImageDecoder.h"
#include "SkRefCnt.h"
#include "SkStream.h"
#include "SkTypes.h"
@@ -249,3 +251,45 @@ DEF_TEST(FrontBufferedStream, reporter) {
test_buffers(reporter, 15);
test_buffers(reporter, 64);
}
+
+// Test that a FrontBufferedStream does not allow reading after the end of a stream.
+// This class is a dummy SkStream which reports that it is at the end on the first
+// read (simulating a failure). Then it tracks whether someone calls read() again.
+class FailingStream : public SkStream {
+public:
+ FailingStream()
+ : fAtEnd(false)
+ , fReadAfterEnd(false)
+ {}
+ virtual size_t read(void* buffer, size_t size) SK_OVERRIDE {
+ if (fAtEnd) {
+ fReadAfterEnd = true;
+ } else {
+ fAtEnd = true;
+ }
+ return 0;
+ }
+
+ virtual bool isAtEnd() const SK_OVERRIDE {
+ return fAtEnd;
+ }
+
+ bool readAfterEnd() const {
+ return fReadAfterEnd;
+ }
+private:
+ bool fAtEnd;
+ bool fReadAfterEnd;
+};
+
+DEF_TEST(ShortFrontBufferedStream, reporter) {
+ FailingStream failingStream;
+ SkAutoTUnref<SkStreamRewindable> stream(SkFrontBufferedStream::Create(&failingStream, 64));
+ SkBitmap bm;
+ // The return value of DecodeStream is not important. We are just using DecodeStream because
+ // it simulates a bug. DecodeStream will read the stream, then rewind, then attempt to read
+ // again. FrontBufferedStream::read should not continue to read its underlying stream beyond
+ // its end.
+ SkImageDecoder::DecodeStream(stream, &bm);
+ REPORTER_ASSERT(reporter, !failingStream.readAfterEnd());
+}