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

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

Issue 2008010: Fixes in AlsaPcmOutputStream. (Closed)
Patch Set: - Created 10 years, 7 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 6 #include "base/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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 EXPECT_TRUE(buffer_.Seek(-static_cast<int32>(kBufferSize))); 215 EXPECT_TRUE(buffer_.Seek(-static_cast<int32>(kBufferSize)));
216 EXPECT_FALSE(buffer_.Seek(-1)); 216 EXPECT_FALSE(buffer_.Seek(-1));
217 217
218 // Read again. 218 // Read again.
219 for (size_t i = 0; i < kBufferSize; i += kReadSize) { 219 for (size_t i = 0; i < kBufferSize; i += kReadSize) {
220 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize)); 220 EXPECT_EQ(kReadSize, buffer_.Read(write_buffer_, kReadSize));
221 EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize)); 221 EXPECT_EQ(0, memcmp(write_buffer_, data_ + i, kReadSize));
222 } 222 }
223 } 223 }
224 224
225 TEST_F(SeekableBufferTest, GetCurrentChunk) {
226 const size_t kSeekSize = kWriteSize / 3;
227
228 scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(kWriteSize);
229 memcpy(buffer->GetWritableData(), data_, kWriteSize);
230 buffer->SetDataSize(kWriteSize);
231
232 const uint8* data;
233 size_t size;
234 EXPECT_FALSE(buffer_.GetCurrentChunk(&data, &size));
235
236 buffer_.Append(buffer.get());
237 EXPECT_TRUE(buffer_.GetCurrentChunk(&data, &size));
238 EXPECT_EQ(data, buffer->GetData());
239 EXPECT_EQ(size, buffer->GetDataSize());
240
241 buffer_.Seek(kSeekSize);
242 EXPECT_TRUE(buffer_.GetCurrentChunk(&data, &size));
243 EXPECT_EQ(data, buffer->GetData() + kSeekSize);
244 EXPECT_EQ(size, buffer->GetDataSize() - kSeekSize);
245 }
246
225 TEST_F(SeekableBufferTest, SeekForward) { 247 TEST_F(SeekableBufferTest, SeekForward) {
226 size_t write_position = 0; 248 size_t write_position = 0;
227 size_t read_position = 0; 249 size_t read_position = 0;
228 while (read_position < kDataSize) { 250 while (read_position < kDataSize) {
229 for (int i = 0; i < 10 && write_position < kDataSize; ++i) { 251 for (int i = 0; i < 10 && write_position < kDataSize; ++i) {
230 // Write a random amount of data. 252 // Write a random amount of data.
231 size_t write_size = GetRandomInt(kBufferSize); 253 size_t write_size = GetRandomInt(kBufferSize);
232 write_size = std::min(write_size, kDataSize - write_position); 254 write_size = std::min(write_size, kDataSize - write_position);
233 255
234 bool should_append = buffer_.Append(data_ + write_position, write_size); 256 bool should_append = buffer_.Append(data_ + write_position, write_size);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" 335 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:"
314 << tests[i].first_time_useconds << ", duration:" 336 << tests[i].first_time_useconds << ", duration:"
315 << tests[i].duration_useconds << ", consumed:" 337 << tests[i].duration_useconds << ", consumed:"
316 << tests[i].consume_bytes << "}\n"; 338 << tests[i].consume_bytes << "}\n";
317 339
318 buffer_.Clear(); 340 buffer_.Clear();
319 } 341 }
320 } 342 }
321 343
322 } // namespace 344 } // namespace
OLDNEW
« media/audio/linux/alsa_output_unittest.cc ('K') | « media/base/seekable_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698