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

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

Issue 2140001: Removed PushSource::Packet. SeekableBuffer.current_time() fixed to return (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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 EXPECT_EQ(0u, buffer_.Read(write_buffer_, 1)); 284 EXPECT_EQ(0u, buffer_.Read(write_buffer_, 1));
285 EXPECT_TRUE(buffer_.Seek(0)); 285 EXPECT_TRUE(buffer_.Seek(0));
286 EXPECT_FALSE(buffer_.Seek(-1)); 286 EXPECT_FALSE(buffer_.Seek(-1));
287 EXPECT_FALSE(buffer_.Seek(1)); 287 EXPECT_FALSE(buffer_.Seek(1));
288 EXPECT_EQ(0u, buffer_.forward_bytes()); 288 EXPECT_EQ(0u, buffer_.forward_bytes());
289 EXPECT_EQ(0u, buffer_.backward_bytes()); 289 EXPECT_EQ(0u, buffer_.backward_bytes());
290 } 290 }
291 291
292 292
293 TEST_F(SeekableBufferTest, GetTime) { 293 TEST_F(SeekableBufferTest, GetTime) {
294 const base::TimeDelta kInvalidTimestamp =
295 media::StreamSample::kInvalidTimestamp;
296
294 const struct { 297 const struct {
295 int64 first_time_useconds; 298 int64 first_time_useconds;
296 int64 duration_useconds; 299 int64 duration_useconds;
297 size_t consume_bytes; 300 size_t consume_bytes;
298 int64 expected_time; 301 int64 expected_time;
299 } tests[] = { 302 } tests[] = {
300 // Timestamps of 0 are treated as garbage. 303 // Timestamps of 0 are treated as garbage.
301 { 0, 1000000, 0, 0 }, 304 { 0, 1000000, 0, kInvalidTimestamp.ToInternalValue() },
302 { 0, 4000000, 0, 0 }, 305 { 0, 4000000, 0, kInvalidTimestamp.ToInternalValue() },
303 { 0, 8000000, 0, 0 }, 306 { 0, 8000000, 0, kInvalidTimestamp.ToInternalValue() },
304 { 0, 1000000, 4, 0 }, 307 { 0, 1000000, 4, kInvalidTimestamp.ToInternalValue() },
305 { 0, 4000000, 4, 0 }, 308 { 0, 4000000, 4, kInvalidTimestamp.ToInternalValue() },
306 { 0, 8000000, 4, 0 }, 309 { 0, 8000000, 4, kInvalidTimestamp.ToInternalValue() },
307 { 0, 1000000, kWriteSize, 0 }, 310 { 0, 1000000, kWriteSize, kInvalidTimestamp.ToInternalValue() },
308 { 0, 4000000, kWriteSize, 0 }, 311 { 0, 4000000, kWriteSize, kInvalidTimestamp.ToInternalValue() },
309 { 0, 8000000, kWriteSize, 0 }, 312 { 0, 8000000, kWriteSize, kInvalidTimestamp.ToInternalValue() },
310 { 5, 1000000, 0, 5 }, 313 { 5, 1000000, 0, 5 },
311 { 5, 4000000, 0, 5 }, 314 { 5, 4000000, 0, 5 },
312 { 5, 8000000, 0, 5 }, 315 { 5, 8000000, 0, 5 },
313 { 5, 1000000, kWriteSize / 2, 500005 }, 316 { 5, 1000000, kWriteSize / 2, 500005 },
314 { 5, 4000000, kWriteSize / 2, 2000005 }, 317 { 5, 4000000, kWriteSize / 2, 2000005 },
315 { 5, 8000000, kWriteSize / 2, 4000005 }, 318 { 5, 8000000, kWriteSize / 2, 4000005 },
316 { 5, 1000000, kWriteSize, 1000005 }, 319 { 5, 1000000, kWriteSize, 1000005 },
317 { 5, 4000000, kWriteSize, 4000005 }, 320 { 5, 4000000, kWriteSize, 4000005 },
318 { 5, 8000000, kWriteSize, 8000005 }, 321 { 5, 8000000, kWriteSize, 8000005 },
319 }; 322 };
320 323
324 // current_time() must initially return kInvalidTimestamp.
325 EXPECT_EQ(kInvalidTimestamp.ToInternalValue(),
326 buffer_.current_time().ToInternalValue());
327
321 scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(kWriteSize); 328 scoped_refptr<media::DataBuffer> buffer = new media::DataBuffer(kWriteSize);
322 memcpy(buffer->GetWritableData(), data_, kWriteSize); 329 memcpy(buffer->GetWritableData(), data_, kWriteSize);
323 buffer->SetDataSize(kWriteSize); 330 buffer->SetDataSize(kWriteSize);
324 331
325 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 332 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
326 buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( 333 buffer->SetTimestamp(base::TimeDelta::FromMicroseconds(
327 tests[i].first_time_useconds)); 334 tests[i].first_time_useconds));
328 buffer->SetDuration(base::TimeDelta::FromMicroseconds( 335 buffer->SetDuration(base::TimeDelta::FromMicroseconds(
329 tests[i].duration_useconds)); 336 tests[i].duration_useconds));
330 buffer_.Append(buffer.get()); 337 buffer_.Append(buffer.get());
331 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes)); 338 EXPECT_TRUE(buffer_.Seek(tests[i].consume_bytes));
332 339
333 int64 actual = buffer_.current_time().ToInternalValue(); 340 int64 actual = buffer_.current_time().ToInternalValue();
334 341
335 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" 342 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:"
336 << tests[i].first_time_useconds << ", duration:" 343 << tests[i].first_time_useconds << ", duration:"
337 << tests[i].duration_useconds << ", consumed:" 344 << tests[i].duration_useconds << ", consumed:"
338 << tests[i].consume_bytes << "}\n"; 345 << tests[i].consume_bytes << "}\n";
339 346
340 buffer_.Clear(); 347 buffer_.Clear();
341 } 348 }
342 } 349 }
343 350
344 } // namespace 351 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698