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

Unified Diff: tests/FrontBufferedStreamTest.cpp

Issue 641813009: Add test for new FrontBufferedStream behavior. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix mac assertion Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkImageDecoder_CG.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/FrontBufferedStreamTest.cpp
diff --git a/tests/FrontBufferedStreamTest.cpp b/tests/FrontBufferedStreamTest.cpp
index cb11b12de8268e938de64691261a3346889f352f..e8c2c6a678f7a195a2eacafaedf39f1ae18652e7 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());
+}
« no previous file with comments | « src/ports/SkImageDecoder_CG.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698