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

Side by Side Diff: tests/FrontBufferedStreamTest.cpp

Issue 806653007: Fix up all the easy virtual ... SK_OVERRIDE cases. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 11 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 | « tests/DrawBitmapRectTest.cpp ('k') | tests/GLProgramsTest.cpp » ('j') | 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 "SkFrontBufferedStream.h" 9 #include "SkFrontBufferedStream.h"
10 #include "SkImageDecoder.h" 10 #include "SkImageDecoder.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 // Dummy stream that optionally has a length and/or position. Tests that FrontBu fferedStream's 166 // Dummy stream that optionally has a length and/or position. Tests that FrontBu fferedStream's
167 // length depends on the stream it's buffering having a length and position. 167 // length depends on the stream it's buffering having a length and position.
168 class LengthOptionalStream : public SkStream { 168 class LengthOptionalStream : public SkStream {
169 public: 169 public:
170 LengthOptionalStream(bool hasLength, bool hasPosition) 170 LengthOptionalStream(bool hasLength, bool hasPosition)
171 : fHasLength(hasLength) 171 : fHasLength(hasLength)
172 , fHasPosition(hasPosition) 172 , fHasPosition(hasPosition)
173 {} 173 {}
174 174
175 virtual bool hasLength() const SK_OVERRIDE { 175 bool hasLength() const SK_OVERRIDE {
176 return fHasLength; 176 return fHasLength;
177 } 177 }
178 178
179 virtual bool hasPosition() const SK_OVERRIDE { 179 bool hasPosition() const SK_OVERRIDE {
180 return fHasPosition; 180 return fHasPosition;
181 } 181 }
182 182
183 virtual size_t read(void*, size_t) SK_OVERRIDE { 183 size_t read(void*, size_t) SK_OVERRIDE {
184 return 0; 184 return 0;
185 } 185 }
186 186
187 virtual bool isAtEnd() const SK_OVERRIDE { 187 bool isAtEnd() const SK_OVERRIDE {
188 return true; 188 return true;
189 } 189 }
190 190
191 private: 191 private:
192 const bool fHasLength; 192 const bool fHasLength;
193 const bool fHasPosition; 193 const bool fHasPosition;
194 }; 194 };
195 195
196 // Test all possible combinations of the wrapped stream having a length and a po sition. 196 // Test all possible combinations of the wrapped stream having a length and a po sition.
197 static void test_length_combos(skiatest::Reporter* reporter, size_t bufferSize) { 197 static void test_length_combos(skiatest::Reporter* reporter, size_t bufferSize) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 254
255 // Test that a FrontBufferedStream does not allow reading after the end of a str eam. 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 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. 257 // read (simulating a failure). Then it tracks whether someone calls read() agai n.
258 class FailingStream : public SkStream { 258 class FailingStream : public SkStream {
259 public: 259 public:
260 FailingStream() 260 FailingStream()
261 : fAtEnd(false) 261 : fAtEnd(false)
262 , fReadAfterEnd(false) 262 , fReadAfterEnd(false)
263 {} 263 {}
264 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE { 264 size_t read(void* buffer, size_t size) SK_OVERRIDE {
265 if (fAtEnd) { 265 if (fAtEnd) {
266 fReadAfterEnd = true; 266 fReadAfterEnd = true;
267 } else { 267 } else {
268 fAtEnd = true; 268 fAtEnd = true;
269 } 269 }
270 return 0; 270 return 0;
271 } 271 }
272 272
273 virtual bool isAtEnd() const SK_OVERRIDE { 273 bool isAtEnd() const SK_OVERRIDE {
274 return fAtEnd; 274 return fAtEnd;
275 } 275 }
276 276
277 bool readAfterEnd() const { 277 bool readAfterEnd() const {
278 return fReadAfterEnd; 278 return fReadAfterEnd;
279 } 279 }
280 private: 280 private:
281 bool fAtEnd; 281 bool fAtEnd;
282 bool fReadAfterEnd; 282 bool fReadAfterEnd;
283 }; 283 };
284 284
285 DEF_TEST(ShortFrontBufferedStream, reporter) { 285 DEF_TEST(ShortFrontBufferedStream, reporter) {
286 FailingStream failingStream; 286 FailingStream failingStream;
287 SkAutoTUnref<SkStreamRewindable> stream(SkFrontBufferedStream::Create(&faili ngStream, 64)); 287 SkAutoTUnref<SkStreamRewindable> stream(SkFrontBufferedStream::Create(&faili ngStream, 64));
288 SkBitmap bm; 288 SkBitmap bm;
289 // The return value of DecodeStream is not important. We are just using Deco deStream because 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 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 291 // again. FrontBufferedStream::read should not continue to read its underlyi ng stream beyond
292 // its end. 292 // its end.
293 SkImageDecoder::DecodeStream(stream, &bm); 293 SkImageDecoder::DecodeStream(stream, &bm);
294 REPORTER_ASSERT(reporter, !failingStream.readAfterEnd()); 294 REPORTER_ASSERT(reporter, !failingStream.readAfterEnd());
295 } 295 }
OLDNEW
« no previous file with comments | « tests/DrawBitmapRectTest.cpp ('k') | tests/GLProgramsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698