OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |