summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 18:14:07 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-28 18:14:07 +0000
commit0abf46737e8f32352e537104ea8a9653f3627e4f (patch)
tree49561cb0bde3cec25d40de452c8afb98926950cc /media
parent13aeae876437b7834b14c4144135e5d4a705114f (diff)
downloadchromium_src-0abf46737e8f32352e537104ea8a9653f3627e4f.zip
chromium_src-0abf46737e8f32352e537104ea8a9653f3627e4f.tar.gz
chromium_src-0abf46737e8f32352e537104ea8a9653f3627e4f.tar.bz2
Cleanup media::SeekableBuffer and unit tests
TEST=SeekableBufferTest.* Updating media::SeekableBuffer and unit tests to meet code style standards. Review URL: http://codereview.chromium.org/114042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/seekable_buffer.cc34
-rw-r--r--media/base/seekable_buffer.h68
-rw-r--r--media/base/seekable_buffer_unittest.cc227
3 files changed, 153 insertions, 176 deletions
diff --git a/media/base/seekable_buffer.cc b/media/base/seekable_buffer.cc
index a3f31bc..ec8c578 100644
--- a/media/base/seekable_buffer.cc
+++ b/media/base/seekable_buffer.cc
@@ -32,13 +32,13 @@ size_t SeekableBuffer::Read(size_t size, uint8* data) {
bool SeekableBuffer::Append(size_t size, const uint8* data) {
// Since the forward capacity is only used to check the criteria for buffer
- // full, we will always append data to the buffer.
+ // full, we always append data to the buffer.
Buffer* buffer = new Buffer(size);
memcpy(buffer->data.get(), data, size);
buffers_.push_back(buffer);
- // After we have written the first buffer, update the |current_buffer_| to
- // point to it.
+ // After we have written the first buffer, update |current_buffer_| to point
+ // to it.
if (current_buffer_ == buffers_.end()) {
DCHECK_EQ(0u, forward_bytes_);
current_buffer_ = buffers_.begin();
@@ -82,31 +82,31 @@ bool SeekableBuffer::SeekBackward(size_t size) {
// Loop until we taken enough bytes and rewind by the desired |size|.
while (taken < size) {
// |current_buffer_| can never be invalid when we are in this loop. It can
- // only be invalid before any data is appended, this case should be handled
- // by checks before we enter this loop.
+ // only be invalid before any data is appended. The invalid case should be
+ // handled by checks before we enter this loop.
DCHECK(current_buffer_ != buffers_.end());
- // We try to at most |size| bytes in the backward direction, we also have
- // to account for the offset we are in the current buffer, take the minimum
- // between the two to determine the amount of bytes to take from the
+ // We try to consume at most |size| bytes in the backward direction. We also
+ // have to account for the offset we are in the current buffer, so take the
+ // minimum between the two to determine the amount of bytes to take from the
// current buffer.
size_t consumed = std::min(size - taken, current_buffer_offset_);
// Decreases the offset in the current buffer since we are rewinding.
current_buffer_offset_ -= consumed;
- // Increase the amount of bytes taken in the backward direction, this
+ // Increase the amount of bytes taken in the backward direction. This
// determines when to stop the loop.
taken += consumed;
- // Forward bytes increases, and backward bytes decreases by the amount
+ // Forward bytes increases and backward bytes decreases by the amount
// consumed in the current buffer.
forward_bytes_ += consumed;
backward_bytes_ -= consumed;
DCHECK_GE(backward_bytes_, 0u);
- // The current buffer pointed by current iterator has been consumed,
- // move the iterator backward so it points to the previous buffer.
+ // The current buffer pointed by current iterator has been consumed. Move
+ // the iterator backward so it points to the previous buffer.
if (current_buffer_offset_ == 0) {
if (current_buffer_ == buffers_.begin())
break;
@@ -131,7 +131,7 @@ void SeekableBuffer::EvictBackwardBuffers() {
backward_bytes_ -= buffer->size;
DCHECK_GE(backward_bytes_, 0u);
- delete *i;
+ delete buffer;
buffers_.erase(i);
}
}
@@ -155,7 +155,7 @@ size_t SeekableBuffer::InternalRead(size_t size, uint8* data) {
size_t copied = std::min(size - taken,
buffer->size - current_buffer_offset_);
- // |data| is NULL if we are seeking forward, thus there's no need to copy.
+ // |data| is NULL if we are seeking forward, so there's no need to copy.
if (data)
memcpy(data + taken, buffer->data.get() + current_buffer_offset_, copied);
@@ -163,11 +163,11 @@ size_t SeekableBuffer::InternalRead(size_t size, uint8* data) {
// loop.
taken += copied;
- // We have read |copied| bytes from the current buffer, advances the offset.
+ // We have read |copied| bytes from the current buffer. Advances the offset.
current_buffer_offset_ += copied;
- // We have less forward bytes and more backward bytes, update these counters
- // by |copied|.
+ // We have less forward bytes and more backward bytes. Updates these
+ // counters by |copied|.
forward_bytes_ -= copied;
backward_bytes_ += copied;
DCHECK_GE(forward_bytes_, 0u);
diff --git a/media/base/seekable_buffer.h b/media/base/seekable_buffer.h
index 7360bfd..58b0be9 100644
--- a/media/base/seekable_buffer.h
+++ b/media/base/seekable_buffer.h
@@ -43,36 +43,36 @@ namespace media {
class SeekableBuffer {
public:
- // Construct an instance with forward capacity of |forward_capacity|
- // and backward capacity of |backward_capacity|. The values are in bytes.
+ // Constructs an instance with |forward_capacity| and |backward_capacity|.
+ // The values are in bytes.
SeekableBuffer(size_t backward_capacity, size_t forward_capacity);
~SeekableBuffer();
- // Read a maximum of |size| bytes into |buffer| from the current read
- // position. Return the number of bytes read.
- // The current read position will advances by the amount of bytes read. If
- // reading caused backward bytes to exceed backward_capacity(), an eviction
- // of backward buffer will be done internally.
+ // Reads a maximum of |size| bytes into |buffer| from the current read
+ // position. Returns the number of bytes read.
+ // The current read position will advance by the amount of bytes read. If
+ // reading caused backward_bytes() to exceed backward_capacity(), an eviction
+ // of the backward buffer will be done internally.
size_t Read(size_t size, uint8* buffer);
- // Append |data| with |size| bytes to this buffer. If this buffer becomes full
- // or is already full then return false, otherwise true.
- // Append operations are always successful, a return value of false only means
- // that there's more forward bytes than the capacity, data is still in this
- // buffer, but user is advised not to write any more.
+ // Appends |data| with |size| bytes to this buffer. If this buffer becomes
+ // full or is already full then returns false, otherwise returns true.
+ // Append operations are always successful. A return value of false only means
+ // that forward_bytes() is greater than or equals to forward_capacity(). Data
+ // appended is still in this buffer but user is advised not to write any more.
bool Append(size_t size, const uint8* data);
- // Move the read position by an offset of |offset| bytes. If |offset| is
- // positive, the current read position is moved forward. If negative, the
- // current read position is moved backward. A zero |offset| value will keep
- // the current read position stationary.
+ // Moves the read position by |offset| bytes. If |offset| is positive, the
+ // current read position is moved forward. If negative, the current read
+ // position is moved backward. A zero |offset| value will keep the current
+ // read position stationary.
// If |offset| exceeds bytes buffered in either direction, reported by
// forward_bytes() when seeking forward and backward_bytes() when seeking
// backward, the seek operation will fail and return value will be false.
// If the seek operation fails, the current read position will not be updated.
- // If a forward seeking caused backward bytes to exceed backward_capacity(),
- // this method call will cause an eviction of backward buffer.
+ // If a forward seeking caused backward_bytes() to exceed backward_capacity(),
+ // this method call will cause an eviction of the backward buffer.
bool Seek(int32 offset);
// Returns the number of bytes buffered beyond the current read position.
@@ -91,6 +91,18 @@ class SeekableBuffer {
size_t backward_capacity() const { return backward_capacity_; }
private:
+ // A structure that contains a block of data.
+ struct Buffer {
+ explicit Buffer(size_t len) : data(new uint8[len]), size(len) {}
+ // Pointer to data.
+ scoped_array<uint8> data;
+ // Size of this block.
+ size_t size;
+ };
+
+ // Definition of the buffer queue.
+ typedef std::list<Buffer*> BufferQueue;
+
// A helper method to evict buffers in the backward direction until backward
// bytes is within the backward capacity.
void EvictBackwardBuffers();
@@ -102,20 +114,20 @@ class SeekableBuffer {
// will advance but no data will be copied.
size_t InternalRead(size_t size, uint8* data);
+ // A helper method that moves the current read position forward by |size|
+ // bytes.
+ // If the return value is true, the operation completed successfully.
+ // If the return value is false, |size| is greater than forward_bytes() and
+ // the seek operation failed. The current read position is not updated.
bool SeekForward(size_t size);
+ // A helper method that moves the current read position backward by |size|
+ // bytes.
+ // If the return value is true, the operation completed successfully.
+ // If the return value is false, |size| is greater than backward_bytes() and
+ // the seek operation failed. The current read position is not updated.
bool SeekBackward(size_t size);
- // A structure that contains a block of data.
- struct Buffer {
- explicit Buffer(size_t len) : data(new uint8[len]), size(len) {}
- // Pointer to data.
- scoped_array<uint8> data;
- // Size of this block.
- size_t size;
- };
-
- typedef std::list<Buffer*> BufferQueue;
BufferQueue::iterator current_buffer_;
BufferQueue buffers_;
size_t current_buffer_offset_;
diff --git a/media/base/seekable_buffer_unittest.cc b/media/base/seekable_buffer_unittest.cc
index 65df7e1..943c179 100644
--- a/media/base/seekable_buffer_unittest.cc
+++ b/media/base/seekable_buffer_unittest.cc
@@ -11,7 +11,15 @@
namespace {
class SeekableBufferTest : public testing::Test {
+ public:
+ SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) {
+ }
+
protected:
+ static const size_t kDataSize = 409600;
+ static const size_t kBufferSize = 4096;
+ static const size_t kWriteSize = 512;
+
virtual void SetUp() {
// Setup seed.
size_t seed = static_cast<int32>(base::Time::Now().ToInternalValue());
@@ -19,26 +27,17 @@ class SeekableBufferTest : public testing::Test {
LOG(INFO) << "Random seed: " << seed;
// Creates a test data.
- data_.reset(new uint8[kDataSize]);
for (size_t i = 0; i < kDataSize; i++)
- data_.get()[i] = static_cast<char>(rand());
-
- // Creates a temp buffer.
- write_buffer_.reset(new uint8[kDataSize]);
-
- // Setup |buffer_|.
- buffer_.reset(new media::SeekableBuffer(kBufferSize, kBufferSize));
+ data_[i] = static_cast<char>(rand());
}
size_t GetRandomInt(size_t maximum) {
return rand() % maximum + 1;
}
- static const size_t kDataSize = 409600;
- static const size_t kBufferSize = 4096;
- scoped_ptr<media::SeekableBuffer> buffer_;
- scoped_array<uint8> data_;
- scoped_array<uint8> write_buffer_;
+ media::SeekableBuffer buffer_;
+ uint8 data_[kDataSize];
+ uint8 write_buffer_[kDataSize];
};
TEST_F(SeekableBufferTest, RandomReadWrite) {
@@ -48,186 +47,156 @@ TEST_F(SeekableBufferTest, RandomReadWrite) {
// Write a random amount of data.
size_t write_size = GetRandomInt(kBufferSize);
write_size = std::min(write_size, kDataSize - write_position);
- bool should_append =
- buffer_->Append(write_size, data_.get() + write_position);
+ bool should_append = buffer_.Append(write_size, data_ + write_position);
write_position += write_size;
EXPECT_GE(write_position, read_position);
- EXPECT_EQ(write_position - read_position, buffer_->forward_bytes());
- EXPECT_EQ(should_append, buffer_->forward_bytes() < kBufferSize)
- << "Incorrect buffer full reported";
+ EXPECT_EQ(write_position - read_position, buffer_.forward_bytes());
+ EXPECT_EQ(should_append, buffer_.forward_bytes() < kBufferSize)
+ << "Incorrect buffer full reported";
// Read a random amount of data.
size_t read_size = GetRandomInt(kBufferSize);
- size_t bytes_read = buffer_->Read(read_size, write_buffer_.get());
+ size_t bytes_read = buffer_.Read(read_size, write_buffer_);
EXPECT_GE(read_size, bytes_read);
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- bytes_read));
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read));
read_position += bytes_read;
EXPECT_GE(write_position, read_position);
- EXPECT_EQ(write_position - read_position, buffer_->forward_bytes());
+ EXPECT_EQ(write_position - read_position, buffer_.forward_bytes());
}
}
TEST_F(SeekableBufferTest, ReadWriteSeek) {
- const size_t kWriteSize = 512;
const size_t kReadSize = kWriteSize / 4;
- size_t write_position = 0;
- size_t read_position = 0;
- size_t forward_bytes = 0;
for (int i = 0; i < 10; ++i) {
// Write until buffer is full.
- for (int j = kBufferSize / kWriteSize; j > 0; --j) {
- bool should_append =
- buffer_->Append(kWriteSize, data_.get() + write_position);
- EXPECT_EQ(j > 1, should_append) << "Incorrect buffer full reported";
- write_position += kWriteSize;
- forward_bytes += kWriteSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
+ for (size_t j = 0; j < kBufferSize; j += kWriteSize) {
+ bool should_append = buffer_.Append(kWriteSize, data_ + j);
+ EXPECT_EQ(j < kBufferSize - kWriteSize, should_append)
+ << "Incorrect buffer full reported";
+ EXPECT_EQ(j + kWriteSize, buffer_.forward_bytes());
}
// Simulate a read and seek pattern. Each loop reads 4 times, each time
// reading a quarter of |kWriteSize|.
- for (size_t j = 0; j < kBufferSize / kWriteSize; ++j) {
+ size_t read_position = 0;
+ size_t forward_bytes = kBufferSize;
+ for (size_t j = 0; j < kBufferSize; j += kWriteSize) {
// Read.
- EXPECT_EQ(kReadSize, buffer_->Read(kReadSize, write_buffer_.get()));
+ EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_));
forward_bytes -= kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- kReadSize));
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize));
read_position += kReadSize;
// Seek forward.
- EXPECT_TRUE(buffer_->Seek(2 * kReadSize));
+ EXPECT_TRUE(buffer_.Seek(2 * kReadSize));
forward_bytes -= 2 * kReadSize;
read_position += 2 * kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
// Read.
- EXPECT_EQ(kReadSize, buffer_->Read(kReadSize, write_buffer_.get()));
+ EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_));
forward_bytes -= kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- kReadSize));
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize));
read_position += kReadSize;
// Seek backward.
- EXPECT_TRUE(buffer_->Seek(-3 * static_cast<int32>(kReadSize)));
+ EXPECT_TRUE(buffer_.Seek(-3 * static_cast<int32>(kReadSize)));
forward_bytes += 3 * kReadSize;
read_position -= 3 * kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
// Read.
- EXPECT_EQ(kReadSize, buffer_->Read(kReadSize, write_buffer_.get()));
+ EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_));
forward_bytes -= kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- kReadSize));
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize));
read_position += kReadSize;
// Read.
- EXPECT_EQ(kReadSize, buffer_->Read(kReadSize, write_buffer_.get()));
+ EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_));
forward_bytes -= kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- kReadSize));
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, kReadSize));
read_position += kReadSize;
// Seek forward.
- EXPECT_TRUE(buffer_->Seek(kReadSize));
+ EXPECT_TRUE(buffer_.Seek(kReadSize));
forward_bytes -= kReadSize;
read_position += kReadSize;
- EXPECT_EQ(forward_bytes, buffer_->forward_bytes());
+ EXPECT_EQ(forward_bytes, buffer_.forward_bytes());
}
}
}
TEST_F(SeekableBufferTest, BufferFull) {
- const size_t kWriteSize = 512;
+ const size_t kMaxWriteSize = 2 * kBufferSize;
// Write and expect the buffer to be not full.
- size_t write_position = 0;
- for (size_t i = 0; i < kBufferSize / kWriteSize - 1; ++i) {
- EXPECT_TRUE(buffer_->Append(kWriteSize, data_.get() + write_position));
- write_position += kWriteSize;
- EXPECT_EQ(write_position, buffer_->forward_bytes());
+ for (size_t i = 0; i < kBufferSize - kWriteSize; i += kWriteSize) {
+ EXPECT_TRUE(buffer_.Append(kWriteSize, data_ + i));
+ EXPECT_EQ(i + kWriteSize, buffer_.forward_bytes());
}
- // Write 10 more times, the buffer is full.
- for (int i = 0; i < 10; ++i) {
- EXPECT_FALSE(buffer_->Append(kWriteSize, data_.get() + write_position));
- write_position += kWriteSize;
- EXPECT_EQ(write_position, buffer_->forward_bytes());
+ // Write until we have kMaxWriteSize bytes in the buffer. Buffer is full in
+ // these writes.
+ for (size_t i = buffer_.forward_bytes(); i < kMaxWriteSize; i += kWriteSize) {
+ EXPECT_FALSE(buffer_.Append(kWriteSize, data_ + i));
+ EXPECT_EQ(i + kWriteSize, buffer_.forward_bytes());
}
// Read until the buffer is empty.
size_t read_position = 0;
- while (buffer_->forward_bytes()) {
+ while (buffer_.forward_bytes()) {
// Read a random amount of data.
size_t read_size = GetRandomInt(kBufferSize);
- size_t forward_bytes = buffer_->forward_bytes();
- size_t bytes_read = buffer_->Read(read_size, write_buffer_.get());
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- bytes_read));
+ size_t forward_bytes = buffer_.forward_bytes();
+ size_t bytes_read = buffer_.Read(read_size, write_buffer_);
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read));
if (read_size > forward_bytes)
EXPECT_EQ(forward_bytes, bytes_read);
else
EXPECT_EQ(read_size, bytes_read);
read_position += bytes_read;
- EXPECT_GE(write_position, read_position);
- EXPECT_EQ(write_position - read_position, buffer_->forward_bytes());
+ EXPECT_GE(kMaxWriteSize, read_position);
+ EXPECT_EQ(kMaxWriteSize - read_position, buffer_.forward_bytes());
}
- // Expect we have no bytes left.
- EXPECT_EQ(0u, buffer_->forward_bytes());
- EXPECT_EQ(0u, buffer_->Read(1, write_buffer_.get()));
+ // Expects we have no bytes left.
+ EXPECT_EQ(0u, buffer_.forward_bytes());
+ EXPECT_EQ(0u, buffer_.Read(1, write_buffer_));
}
TEST_F(SeekableBufferTest, SeekBackward) {
- EXPECT_EQ(0u, buffer_->forward_bytes());
- EXPECT_EQ(0u, buffer_->backward_bytes());
- EXPECT_FALSE(buffer_->Seek(1));
- EXPECT_FALSE(buffer_->Seek(-1));
+ EXPECT_EQ(0u, buffer_.forward_bytes());
+ EXPECT_EQ(0u, buffer_.backward_bytes());
+ EXPECT_FALSE(buffer_.Seek(1));
+ EXPECT_FALSE(buffer_.Seek(-1));
- const size_t kWriteSize = 512;
const size_t kReadSize = 256;
// Write into buffer until it's full.
- size_t write_position = 0;
- for (size_t i = 0; i < kBufferSize / kWriteSize; ++i) {
+ for (size_t i = 0; i < kBufferSize; i += kWriteSize) {
// Write a random amount of data.
- buffer_->Append(kWriteSize, data_.get() + write_position);
- write_position += kWriteSize;
+ buffer_.Append(kWriteSize, data_ + i);
}
// Read until buffer is empty.
- size_t read_position = 0;
- for (size_t i = 0; i < kBufferSize / kReadSize; ++i) {
- EXPECT_EQ(kReadSize, buffer_->Read(kReadSize, write_buffer_.get()));
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- kReadSize));
- read_position += kReadSize;
+ for (size_t i = 0; i < kBufferSize; i += kReadSize) {
+ EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_));
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize));
}
// Seek backward.
- EXPECT_TRUE(buffer_->Seek(-static_cast<int32>(kBufferSize)));
- EXPECT_FALSE(buffer_->Seek(-1));
+ EXPECT_TRUE(buffer_.Seek(-static_cast<int32>(kBufferSize)));
+ EXPECT_FALSE(buffer_.Seek(-1));
// Read again.
- read_position = 0;
- for (size_t i = 0; i < kBufferSize / kReadSize; ++i) {
- EXPECT_EQ(kReadSize, buffer_->Read(kReadSize, write_buffer_.get()));
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- kReadSize));
- read_position += kReadSize;
+ for (size_t i = 0; i < kBufferSize; i += kReadSize) {
+ EXPECT_EQ(kReadSize, buffer_.Read(kReadSize, write_buffer_));
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize));
}
}
@@ -235,49 +204,45 @@ TEST_F(SeekableBufferTest, SeekForward) {
size_t write_position = 0;
size_t read_position = 0;
while (read_position < kDataSize) {
- for (int i = 0; i < 10; ++i) {
+ for (int i = 0; i < 10 && write_position < kDataSize; ++i) {
// Write a random amount of data.
size_t write_size = GetRandomInt(kBufferSize);
write_size = std::min(write_size, kDataSize - write_position);
- if (!write_size)
- break;
- bool should_append =
- buffer_->Append(write_size, data_.get() + write_position);
+
+ bool should_append = buffer_.Append(write_size, data_ + write_position);
write_position += write_size;
EXPECT_GE(write_position, read_position);
- EXPECT_EQ(write_position - read_position, buffer_->forward_bytes());
- EXPECT_EQ(should_append, buffer_->forward_bytes() < kBufferSize)
- << "Incorrect buffer full status reported";
+ EXPECT_EQ(write_position - read_position, buffer_.forward_bytes());
+ EXPECT_EQ(should_append, buffer_.forward_bytes() < kBufferSize)
+ << "Incorrect buffer full status reported";
}
// Read a random amount of data.
size_t seek_size = GetRandomInt(kBufferSize);
- if (buffer_->Seek(seek_size))
+ if (buffer_.Seek(seek_size))
read_position += seek_size;
EXPECT_GE(write_position, read_position);
- EXPECT_EQ(write_position - read_position, buffer_->forward_bytes());
+ EXPECT_EQ(write_position - read_position, buffer_.forward_bytes());
// Read a random amount of data.
size_t read_size = GetRandomInt(kBufferSize);
- size_t bytes_read = buffer_->Read(read_size, write_buffer_.get());
+ size_t bytes_read = buffer_.Read(read_size, write_buffer_);
EXPECT_GE(read_size, bytes_read);
- EXPECT_EQ(0, memcmp(write_buffer_.get(),
- data_.get() + read_position,
- bytes_read));
+ EXPECT_EQ(0, memcmp(write_buffer_, data_ + read_position, bytes_read));
read_position += bytes_read;
EXPECT_GE(write_position, read_position);
- EXPECT_EQ(write_position - read_position, buffer_->forward_bytes());
+ EXPECT_EQ(write_position - read_position, buffer_.forward_bytes());
}
}
TEST_F(SeekableBufferTest, AllMethods) {
- EXPECT_EQ(0u, buffer_->Read(0, write_buffer_.get()));
- EXPECT_EQ(0u, buffer_->Read(1, write_buffer_.get()));
- EXPECT_TRUE(buffer_->Seek(0));
- EXPECT_FALSE(buffer_->Seek(-1));
- EXPECT_FALSE(buffer_->Seek(1));
- EXPECT_EQ(0u, buffer_->forward_bytes());
- EXPECT_EQ(0u, buffer_->backward_bytes());
+ EXPECT_EQ(0u, buffer_.Read(0, write_buffer_));
+ EXPECT_EQ(0u, buffer_.Read(1, write_buffer_));
+ EXPECT_TRUE(buffer_.Seek(0));
+ EXPECT_FALSE(buffer_.Seek(-1));
+ EXPECT_FALSE(buffer_.Seek(1));
+ EXPECT_EQ(0u, buffer_.forward_bytes());
+ EXPECT_EQ(0u, buffer_.backward_bytes());
}
-}
+} // namespace