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

Side by Side Diff: tests/FrontBufferedStreamTest.cpp

Issue 649553003: Revert of Add test for new FrontBufferedStream behavior. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | 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"
9 #include "SkFrontBufferedStream.h" 8 #include "SkFrontBufferedStream.h"
10 #include "SkImageDecoder.h"
11 #include "SkRefCnt.h" 9 #include "SkRefCnt.h"
12 #include "SkStream.h" 10 #include "SkStream.h"
13 #include "SkTypes.h" 11 #include "SkTypes.h"
14 #include "Test.h" 12 #include "Test.h"
15 13
16 static void test_read(skiatest::Reporter* reporter, SkStream* bufferedStream, 14 static void test_read(skiatest::Reporter* reporter, SkStream* bufferedStream,
17 const void* expectations, size_t bytesToRead) { 15 const void* expectations, size_t bytesToRead) {
18 // output for reading bufferedStream. 16 // output for reading bufferedStream.
19 SkAutoMalloc storage(bytesToRead); 17 SkAutoMalloc storage(bytesToRead);
20 18
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 test_length_combos(reporter, bufferSize); 242 test_length_combos(reporter, bufferSize);
245 test_initial_offset(reporter, bufferSize); 243 test_initial_offset(reporter, bufferSize);
246 } 244 }
247 245
248 DEF_TEST(FrontBufferedStream, reporter) { 246 DEF_TEST(FrontBufferedStream, reporter) {
249 // Test 6 and 64, which are used by Android, as well as another arbitrary le ngth. 247 // Test 6 and 64, which are used by Android, as well as another arbitrary le ngth.
250 test_buffers(reporter, 6); 248 test_buffers(reporter, 6);
251 test_buffers(reporter, 15); 249 test_buffers(reporter, 15);
252 test_buffers(reporter, 64); 250 test_buffers(reporter, 64);
253 } 251 }
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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698