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

Side by Side Diff: tests/FrontBufferedStreamTest.cpp

Issue 1037793002: C++11 override should now be supported by all of {bots,Chrome,Android,Mozilla} (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: git cl web Created 5 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 | « 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 // A custom class whose isAtEnd behaves the way Android's stream does - since it is an adaptor to a 125 // A custom class whose isAtEnd behaves the way Android's stream does - since it is an adaptor to a
126 // Java InputStream, it does not know that it is at the end until it has attempt ed to read beyond 126 // Java InputStream, it does not know that it is at the end until it has attempt ed to read beyond
127 // the end and failed. Used by test_read_beyond_buffer. 127 // the end and failed. Used by test_read_beyond_buffer.
128 class AndroidLikeMemoryStream : public SkMemoryStream { 128 class AndroidLikeMemoryStream : public SkMemoryStream {
129 public: 129 public:
130 AndroidLikeMemoryStream(void* data, size_t size, bool ownMemory) 130 AndroidLikeMemoryStream(void* data, size_t size, bool ownMemory)
131 : INHERITED(data, size, ownMemory) 131 : INHERITED(data, size, ownMemory)
132 , fIsAtEnd(false) {} 132 , fIsAtEnd(false) {}
133 133
134 size_t read(void* dst, size_t requested) SK_OVERRIDE { 134 size_t read(void* dst, size_t requested) override {
135 size_t bytesRead = this->INHERITED::read(dst, requested); 135 size_t bytesRead = this->INHERITED::read(dst, requested);
136 if (bytesRead < requested) { 136 if (bytesRead < requested) {
137 fIsAtEnd = true; 137 fIsAtEnd = true;
138 } 138 }
139 return bytesRead; 139 return bytesRead;
140 } 140 }
141 141
142 bool isAtEnd() const SK_OVERRIDE { 142 bool isAtEnd() const override {
143 return fIsAtEnd; 143 return fIsAtEnd;
144 } 144 }
145 145
146 private: 146 private:
147 bool fIsAtEnd; 147 bool fIsAtEnd;
148 typedef SkMemoryStream INHERITED; 148 typedef SkMemoryStream INHERITED;
149 }; 149 };
150 150
151 // This test ensures that buffering the exact length of the stream and attemptin g to read beyond it 151 // This test ensures that buffering the exact length of the stream and attemptin g to read beyond it
152 // does not invalidate the buffer. 152 // does not invalidate the buffer.
(...skipping 15 matching lines...) Expand all
168 168
169 // Dummy stream that optionally has a length and/or position. Tests that FrontBu fferedStream's 169 // Dummy stream that optionally has a length and/or position. Tests that FrontBu fferedStream's
170 // length depends on the stream it's buffering having a length and position. 170 // length depends on the stream it's buffering having a length and position.
171 class LengthOptionalStream : public SkStream { 171 class LengthOptionalStream : public SkStream {
172 public: 172 public:
173 LengthOptionalStream(bool hasLength, bool hasPosition) 173 LengthOptionalStream(bool hasLength, bool hasPosition)
174 : fHasLength(hasLength) 174 : fHasLength(hasLength)
175 , fHasPosition(hasPosition) 175 , fHasPosition(hasPosition)
176 {} 176 {}
177 177
178 bool hasLength() const SK_OVERRIDE { 178 bool hasLength() const override {
179 return fHasLength; 179 return fHasLength;
180 } 180 }
181 181
182 bool hasPosition() const SK_OVERRIDE { 182 bool hasPosition() const override {
183 return fHasPosition; 183 return fHasPosition;
184 } 184 }
185 185
186 size_t read(void*, size_t) SK_OVERRIDE { 186 size_t read(void*, size_t) override {
187 return 0; 187 return 0;
188 } 188 }
189 189
190 bool isAtEnd() const SK_OVERRIDE { 190 bool isAtEnd() const override {
191 return true; 191 return true;
192 } 192 }
193 193
194 private: 194 private:
195 const bool fHasLength; 195 const bool fHasLength;
196 const bool fHasPosition; 196 const bool fHasPosition;
197 }; 197 };
198 198
199 // Test all possible combinations of the wrapped stream having a length and a po sition. 199 // Test all possible combinations of the wrapped stream having a length and a po sition.
200 static void test_length_combos(skiatest::Reporter* reporter, size_t bufferSize) { 200 static void test_length_combos(skiatest::Reporter* reporter, size_t bufferSize) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 257
258 // Test that a FrontBufferedStream does not allow reading after the end of a str eam. 258 // Test that a FrontBufferedStream does not allow reading after the end of a str eam.
259 // This class is a dummy SkStream which reports that it is at the end on the fir st 259 // This class is a dummy SkStream which reports that it is at the end on the fir st
260 // read (simulating a failure). Then it tracks whether someone calls read() agai n. 260 // read (simulating a failure). Then it tracks whether someone calls read() agai n.
261 class FailingStream : public SkStream { 261 class FailingStream : public SkStream {
262 public: 262 public:
263 FailingStream() 263 FailingStream()
264 : fAtEnd(false) 264 : fAtEnd(false)
265 , fReadAfterEnd(false) 265 , fReadAfterEnd(false)
266 {} 266 {}
267 size_t read(void* buffer, size_t size) SK_OVERRIDE { 267 size_t read(void* buffer, size_t size) override {
268 if (fAtEnd) { 268 if (fAtEnd) {
269 fReadAfterEnd = true; 269 fReadAfterEnd = true;
270 } else { 270 } else {
271 fAtEnd = true; 271 fAtEnd = true;
272 } 272 }
273 return 0; 273 return 0;
274 } 274 }
275 275
276 bool isAtEnd() const SK_OVERRIDE { 276 bool isAtEnd() const override {
277 return fAtEnd; 277 return fAtEnd;
278 } 278 }
279 279
280 bool readAfterEnd() const { 280 bool readAfterEnd() const {
281 return fReadAfterEnd; 281 return fReadAfterEnd;
282 } 282 }
283 private: 283 private:
284 bool fAtEnd; 284 bool fAtEnd;
285 bool fReadAfterEnd; 285 bool fReadAfterEnd;
286 }; 286 };
287 287
288 DEF_TEST(ShortFrontBufferedStream, reporter) { 288 DEF_TEST(ShortFrontBufferedStream, reporter) {
289 FailingStream* failingStream = SkNEW(FailingStream); 289 FailingStream* failingStream = SkNEW(FailingStream);
290 SkAutoTDelete<SkStreamRewindable> stream(SkFrontBufferedStream::Create(faili ngStream, 64)); 290 SkAutoTDelete<SkStreamRewindable> stream(SkFrontBufferedStream::Create(faili ngStream, 64));
291 SkBitmap bm; 291 SkBitmap bm;
292 // The return value of DecodeStream is not important. We are just using Deco deStream because 292 // The return value of DecodeStream is not important. We are just using Deco deStream because
293 // it simulates a bug. DecodeStream will read the stream, then rewind, then attempt to read 293 // it simulates a bug. DecodeStream will read the stream, then rewind, then attempt to read
294 // again. FrontBufferedStream::read should not continue to read its underlyi ng stream beyond 294 // again. FrontBufferedStream::read should not continue to read its underlyi ng stream beyond
295 // its end. 295 // its end.
296 SkImageDecoder::DecodeStream(stream, &bm); 296 SkImageDecoder::DecodeStream(stream, &bm);
297 REPORTER_ASSERT(reporter, !failingStream->readAfterEnd()); 297 REPORTER_ASSERT(reporter, !failingStream->readAfterEnd());
298 } 298 }
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