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

Side by Side Diff: media/base/seekable_buffer_unittest.cc

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Inlined getters and setters on DataBuffer Created 7 years, 6 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 | « media/base/seekable_buffer.cc ('k') | media/filters/audio_renderer_algorithm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "media/base/data_buffer.h" 8 #include "media/base/data_buffer.h"
9 #include "media/base/seekable_buffer.h" 9 #include "media/base/seekable_buffer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 const int kSeekSize = kWriteSize / 3; 226 const int kSeekSize = kWriteSize / 3;
227 227
228 scoped_refptr<DataBuffer> buffer = DataBuffer::CopyFrom(data_, kWriteSize); 228 scoped_refptr<DataBuffer> buffer = DataBuffer::CopyFrom(data_, kWriteSize);
229 229
230 const uint8* data; 230 const uint8* data;
231 int size; 231 int size;
232 EXPECT_FALSE(buffer_.GetCurrentChunk(&data, &size)); 232 EXPECT_FALSE(buffer_.GetCurrentChunk(&data, &size));
233 233
234 buffer_.Append(buffer.get()); 234 buffer_.Append(buffer.get());
235 EXPECT_TRUE(buffer_.GetCurrentChunk(&data, &size)); 235 EXPECT_TRUE(buffer_.GetCurrentChunk(&data, &size));
236 EXPECT_EQ(data, buffer->GetData()); 236 EXPECT_EQ(data, buffer->data());
237 EXPECT_EQ(size, buffer->GetDataSize()); 237 EXPECT_EQ(size, buffer->data_size());
238 238
239 buffer_.Seek(kSeekSize); 239 buffer_.Seek(kSeekSize);
240 EXPECT_TRUE(buffer_.GetCurrentChunk(&data, &size)); 240 EXPECT_TRUE(buffer_.GetCurrentChunk(&data, &size));
241 EXPECT_EQ(data, buffer->GetData() + kSeekSize); 241 EXPECT_EQ(data, buffer->data() + kSeekSize);
242 EXPECT_EQ(size, buffer->GetDataSize() - kSeekSize); 242 EXPECT_EQ(size, buffer->data_size() - kSeekSize);
243 } 243 }
244 244
245 TEST_F(SeekableBufferTest, SeekForward) { 245 TEST_F(SeekableBufferTest, SeekForward) {
246 int write_position = 0; 246 int write_position = 0;
247 int read_position = 0; 247 int read_position = 0;
248 while (read_position < kDataSize) { 248 while (read_position < kDataSize) {
249 for (int i = 0; i < 10 && write_position < kDataSize; ++i) { 249 for (int i = 0; i < 10 && write_position < kDataSize; ++i) {
250 // Write a random amount of data. 250 // Write a random amount of data.
251 int write_size = GetRandomInt(kBufferSize); 251 int write_size = GetRandomInt(kBufferSize);
252 write_size = std::min(write_size, kDataSize - write_position); 252 write_size = std::min(write_size, kDataSize - write_position);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 { 5, 8000000, kWriteSize, 8000005 }, 324 { 5, 8000000, kWriteSize, 8000005 },
325 }; 325 };
326 326
327 // current_time() must initially return kNoTimestamp(). 327 // current_time() must initially return kNoTimestamp().
328 EXPECT_EQ(kNoTimestamp().ToInternalValue(), 328 EXPECT_EQ(kNoTimestamp().ToInternalValue(),
329 buffer_.current_time().ToInternalValue()); 329 buffer_.current_time().ToInternalValue());
330 330
331 scoped_refptr<DataBuffer> buffer = DataBuffer::CopyFrom(data_, kWriteSize); 331 scoped_refptr<DataBuffer> buffer = DataBuffer::CopyFrom(data_, kWriteSize);
332 332
333 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 333 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
334 buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( 334 buffer->set_timestamp(base::TimeDelta::FromMicroseconds(
335 tests[i].first_time_useconds)); 335 tests[i].first_time_useconds));
336 buffer->SetDuration(base::TimeDelta::FromMicroseconds( 336 buffer->set_duration(base::TimeDelta::FromMicroseconds(
337 tests[i].duration_useconds)); 337 tests[i].duration_useconds));
338 buffer_.Append(buffer.get()); 338 buffer_.Append(buffer.get());
339 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); 339 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes));
340 340
341 int64 actual = buffer_.current_time().ToInternalValue(); 341 int64 actual = buffer_.current_time().ToInternalValue();
342 342
343 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" 343 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:"
344 << tests[i].first_time_useconds << ", duration:" 344 << tests[i].first_time_useconds << ", duration:"
345 << tests[i].duration_useconds << ", consumed:" 345 << tests[i].duration_useconds << ", consumed:"
346 << tests[i].consume_bytes << " }\n"; 346 << tests[i].consume_bytes << " }\n";
347 347
348 buffer_.Clear(); 348 buffer_.Clear();
349 } 349 }
350 } 350 }
351 351
352 } // namespace media 352 } // namespace media
OLDNEW
« no previous file with comments | « media/base/seekable_buffer.cc ('k') | media/filters/audio_renderer_algorithm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698