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

Side by Side 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, 1 month 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/ports/SkImageDecoder_CG.cpp ('k') | no next file » | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkBitmap.h"
8 #include "SkFrontBufferedStream.h" 9 #include "SkFrontBufferedStream.h"
10 #include "SkImageDecoder.h"
9 #include "SkRefCnt.h" 11 #include "SkRefCnt.h"
10 #include "SkStream.h" 12 #include "SkStream.h"
11 #include "SkTypes.h" 13 #include "SkTypes.h"
12 #include "Test.h" 14 #include "Test.h"
13 15
14 static void test_read(skiatest::Reporter* reporter, SkStream* bufferedStream, 16 static void test_read(skiatest::Reporter* reporter, SkStream* bufferedStream,
15 const void* expectations, size_t bytesToRead) { 17 const void* expectations, size_t bytesToRead) {
16 // output for reading bufferedStream. 18 // output for reading bufferedStream.
17 SkAutoMalloc storage(bytesToRead); 19 SkAutoMalloc storage(bytesToRead);
18 20
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 test_length_combos(reporter, bufferSize); 244 test_length_combos(reporter, bufferSize);
243 test_initial_offset(reporter, bufferSize); 245 test_initial_offset(reporter, bufferSize);
244 } 246 }
245 247
246 DEF_TEST(FrontBufferedStream, reporter) { 248 DEF_TEST(FrontBufferedStream, reporter) {
247 // Test 6 and 64, which are used by Android, as well as another arbitrary le ngth. 249 // Test 6 and 64, which are used by Android, as well as another arbitrary le ngth.
248 test_buffers(reporter, 6); 250 test_buffers(reporter, 6);
249 test_buffers(reporter, 15); 251 test_buffers(reporter, 15);
250 test_buffers(reporter, 64); 252 test_buffers(reporter, 64);
251 } 253 }
254
255 // Test that a FrontBufferedStream does not allow reading after the end of a str eam.
256 // This class is a dummy SkStream which reports that it is at the end on the fir st
257 // read (simulating a failure). Then it tracks whether someone calls read() agai n.
258 class FailingStream : public SkStream {
259 public:
260 FailingStream()
261 : fAtEnd(false)
262 , fReadAfterEnd(false)
263 {}
264 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE {
265 if (fAtEnd) {
266 fReadAfterEnd = true;
267 } else {
268 fAtEnd = true;
269 }
270 return 0;
271 }
272
273 virtual bool isAtEnd() const SK_OVERRIDE {
274 return fAtEnd;
275 }
276
277 bool readAfterEnd() const {
278 return fReadAfterEnd;
279 }
280 private:
281 bool fAtEnd;
282 bool fReadAfterEnd;
283 };
284
285 DEF_TEST(ShortFrontBufferedStream, reporter) {
286 FailingStream failingStream;
287 SkAutoTUnref<SkStreamRewindable> stream(SkFrontBufferedStream::Create(&faili ngStream, 64));
288 SkBitmap bm;
289 // The return value of DecodeStream is not important. We are just using Deco deStream because
290 // it simulates a bug. DecodeStream will read the stream, then rewind, then attempt to read
291 // again. FrontBufferedStream::read should not continue to read its underlyi ng stream beyond
292 // its end.
293 SkImageDecoder::DecodeStream(stream, &bm);
294 REPORTER_ASSERT(reporter, !failingStream.readAfterEnd());
295 }
OLDNEW
« 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