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

Side by Side Diff: tests/StreamTest.cpp

Issue 1703293002: Remove position from FrontBufferedStream (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix test_peeking_front_buffered_stream Created 4 years, 10 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/FrontBufferedStreamTest.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 2011 Google Inc. 2 * Copyright 2011 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 "Resources.h" 8 #include "Resources.h"
9 #include "SkData.h" 9 #include "SkData.h"
10 #include "SkFrontBufferedStream.h" 10 #include "SkFrontBufferedStream.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 bufferedStream.reset(SkFrontBufferedStream::Create(original.duplicate(), buf ferSize)); 259 bufferedStream.reset(SkFrontBufferedStream::Create(original.duplicate(), buf ferSize));
260 REPORTER_ASSERT(r, bufferedStream != nullptr); 260 REPORTER_ASSERT(r, bufferedStream != nullptr);
261 261
262 const size_t bytesToPeek = bufferSize + 1; 262 const size_t bytesToPeek = bufferSize + 1;
263 SkAutoMalloc peekStorage(bytesToPeek); 263 SkAutoMalloc peekStorage(bytesToPeek);
264 SkAutoMalloc readStorage(bytesToPeek); 264 SkAutoMalloc readStorage(bytesToPeek);
265 265
266 for (size_t start = 0; start <= bufferSize; start++) { 266 for (size_t start = 0; start <= bufferSize; start++) {
267 // Skip to the starting point 267 // Skip to the starting point
268 REPORTER_ASSERT(r, bufferedStream->skip(start) == start); 268 REPORTER_ASSERT(r, bufferedStream->skip(start) == start);
269 REPORTER_ASSERT(r, bufferedStream->getPosition() == start);
270 269
271 const size_t bytesPeeked = bufferedStream->peek(peekStorage.get(), bytes ToPeek); 270 const size_t bytesPeeked = bufferedStream->peek(peekStorage.get(), bytes ToPeek);
272 if (0 == bytesPeeked) { 271 if (0 == bytesPeeked) {
273 // Peeking should only fail completely if we have read beyond the bu ffer. 272 // Peeking should only fail completely if we have read/skipped beyon d the buffer.
274 REPORTER_ASSERT(r, bufferedStream->getPosition() >= bufferSize); 273 REPORTER_ASSERT(r, start >= bufferSize);
275 break; 274 break;
276 } 275 }
277 276
278 // Only read the amount that was successfully peeked. 277 // Only read the amount that was successfully peeked.
279 const size_t bytesRead = bufferedStream->read(readStorage.get(), bytesPe eked); 278 const size_t bytesRead = bufferedStream->read(readStorage.get(), bytesPe eked);
280 REPORTER_ASSERT(r, bytesRead == bytesPeeked); 279 REPORTER_ASSERT(r, bytesRead == bytesPeeked);
281 REPORTER_ASSERT(r, !memcmp(peekStorage.get(), readStorage.get(), bytesPe eked)); 280 REPORTER_ASSERT(r, !memcmp(peekStorage.get(), readStorage.get(), bytesPe eked));
282 281
283 // This should be safe to rewind. 282 // This should be safe to rewind.
284 REPORTER_ASSERT(r, bufferedStream->rewind()); 283 REPORTER_ASSERT(r, bufferedStream->rewind());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 SkMemoryStream smartStream(src.get(), (size_t)N); 429 SkMemoryStream smartStream(src.get(), (size_t)N);
431 stream_copy_test(reporter, src, N, &smartStream); 430 stream_copy_test(reporter, src, N, &smartStream);
432 } 431 }
433 432
434 DEF_TEST(StreamEmptyStreamMemoryBase, r) { 433 DEF_TEST(StreamEmptyStreamMemoryBase, r) {
435 SkDynamicMemoryWStream tmp; 434 SkDynamicMemoryWStream tmp;
436 SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream()); 435 SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream());
437 REPORTER_ASSERT(r, nullptr == asset->getMemoryBase()); 436 REPORTER_ASSERT(r, nullptr == asset->getMemoryBase());
438 } 437 }
439 438
OLDNEW
« no previous file with comments | « tests/FrontBufferedStreamTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698