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

Side by Side Diff: tests/FrontBufferedStreamTest.cpp

Issue 1747423002: Fix FrontBufferedStreamTest (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 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 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" 8 #include "SkBitmap.h"
9 #include "SkCodec.h" 9 #include "SkCodec.h"
10 #include "SkFrontBufferedStream.h" 10 #include "SkFrontBufferedStream.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 test_buffers(reporter, 64); 256 test_buffers(reporter, 64);
257 } 257 }
258 258
259 // Test that a FrontBufferedStream does not allow reading after the end of a str eam. 259 // Test that a FrontBufferedStream does not allow reading after the end of a str eam.
260 // This class is a dummy SkStream which reports that it is at the end on the fir st 260 // This class is a dummy SkStream which reports that it is at the end on the fir st
261 // read (simulating a failure). Then it tracks whether someone calls read() agai n. 261 // read (simulating a failure). Then it tracks whether someone calls read() agai n.
262 class FailingStream : public SkStream { 262 class FailingStream : public SkStream {
263 public: 263 public:
264 FailingStream() 264 FailingStream()
265 : fAtEnd(false) 265 : fAtEnd(false)
266 , fReadAfterEnd(false)
267 {} 266 {}
267
268 size_t read(void* buffer, size_t size) override { 268 size_t read(void* buffer, size_t size) override {
269 if (fAtEnd) { 269 SkASSERT(!fAtEnd);
270 fReadAfterEnd = true; 270 fAtEnd = true;
271 } else {
272 fAtEnd = true;
273 }
274 return 0; 271 return 0;
275 } 272 }
276 273
277 bool isAtEnd() const override { 274 bool isAtEnd() const override {
278 return fAtEnd; 275 return fAtEnd;
279 } 276 }
280 277
281 bool readAfterEnd() const {
282 return fReadAfterEnd;
283 }
284 private: 278 private:
285 bool fAtEnd; 279 bool fAtEnd;
286 bool fReadAfterEnd;
287 }; 280 };
288 281
289 DEF_TEST(ShortFrontBufferedStream, reporter) { 282 DEF_TEST(ShortFrontBufferedStream, reporter) {
290 FailingStream* failingStream = new FailingStream; 283 FailingStream* failingStream = new FailingStream;
291 SkAutoTDelete<SkStreamRewindable> stream(SkFrontBufferedStream::Create(faili ngStream, 64)); 284 SkAutoTDelete<SkStreamRewindable> stream(SkFrontBufferedStream::Create(faili ngStream, 64));
292 285
293 // This will fail to create a codec. However, what we really want to test i s that we 286 // This will fail to create a codec. However, what we really want to test i s that we
294 // won't read past the end of the stream. 287 // won't read past the end of the stream.
295 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); 288 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
296 REPORTER_ASSERT(reporter, !failingStream->readAfterEnd());
msarett 2016/03/01 21:14:25 We can't check readAfterEnd() here. The codec has
297 } 289 }
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