本文整理汇总了C++中SkMemoryStream::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ SkMemoryStream::getPosition方法的具体用法?C++ SkMemoryStream::getPosition怎么用?C++ SkMemoryStream::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkMemoryStream
的用法示例。
在下文中一共展示了SkMemoryStream::getPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_initial_offset
// Test using a stream with an initial offset.
static void test_initial_offset(skiatest::Reporter* reporter, size_t bufferSize) {
SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
// Skip a few characters into the memStream, so that bufferedStream represents an offset into
// the stream it wraps.
const size_t arbitraryOffset = 17;
memStream->skip(arbitraryOffset);
std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
// Since SkMemoryStream has a length, bufferedStream must also.
REPORTER_ASSERT(reporter, bufferedStream->hasLength());
const size_t amountToRead = 10;
const size_t bufferedLength = bufferedStream->getLength();
size_t currentPosition = 0;
// Read the stream in chunks. After each read, the position must match currentPosition,
// which sums the amount attempted to read, unless the end of the stream has been reached.
// Importantly, the end should not have been reached until currentPosition == bufferedLength.
while (currentPosition < bufferedLength) {
REPORTER_ASSERT(reporter, !bufferedStream->isAtEnd());
test_read(reporter, bufferedStream.get(), gAbcs + arbitraryOffset + currentPosition,
amountToRead);
currentPosition = SkTMin(currentPosition + amountToRead, bufferedLength);
REPORTER_ASSERT(reporter, memStream->getPosition() - arbitraryOffset == currentPosition);
}
REPORTER_ASSERT(reporter, bufferedStream->isAtEnd());
REPORTER_ASSERT(reporter, bufferedLength == currentPosition);
}
示例2: test_perfectly_sized_buffer
static void test_perfectly_sized_buffer(skiatest::Reporter* reporter, size_t bufferSize) {
SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
test_hasLength(reporter, *bufferedStream, *memStream);
// Read exactly the amount that fits in the buffer.
test_read(reporter, bufferedStream.get(), gAbcs, bufferSize);
// Rewinding should succeed.
test_rewind(reporter, bufferedStream.get(), true);
// Once again reading buffered info should succeed
test_read(reporter, bufferedStream.get(), gAbcs, bufferSize);
// Read past the size of the buffer. At this point, we cannot return.
test_read(reporter, bufferedStream.get(), gAbcs + memStream->getPosition(), 1);
test_rewind(reporter, bufferedStream.get(), false);
}
示例3: test_skipping
static void test_skipping(skiatest::Reporter* reporter, size_t bufferSize) {
SkMemoryStream* memStream = new SkMemoryStream(gAbcs, strlen(gAbcs), false);
std::unique_ptr<SkStream> bufferedStream(SkFrontBufferedStream::Create(memStream, bufferSize));
test_hasLength(reporter, *bufferedStream, *memStream);
// Skip half the buffer.
bufferedStream->skip(bufferSize / 2);
// Rewind, then read part of the buffer, which should have been read.
test_rewind(reporter, bufferedStream.get(), true);
test_read(reporter, bufferedStream.get(), gAbcs, bufferSize / 4);
// Now skip beyond the buffered piece, but still within the total buffer.
bufferedStream->skip(bufferSize / 2);
// Test that reading will still work.
test_read(reporter, bufferedStream.get(), gAbcs + memStream->getPosition(), bufferSize / 4);
test_rewind(reporter, bufferedStream.get(), true);
test_read(reporter, bufferedStream.get(), gAbcs, bufferSize);
}