Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/rand_util.h" | |
| 7 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 8 #include "media/base/data_buffer.h" | 9 #include "media/base/data_buffer.h" |
| 9 #include "media/base/seekable_buffer.h" | 10 #include "media/base/seekable_buffer.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace media { | 13 namespace media { |
| 13 | 14 |
| 14 class SeekableBufferTest : public testing::Test { | 15 class SeekableBufferTest : public testing::Test { |
| 15 public: | 16 public: |
| 16 SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) { | 17 SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) { |
| 17 } | 18 } |
| 18 | 19 |
| 19 protected: | 20 protected: |
| 20 static const int kDataSize = 409600; | 21 static const int kDataSize = 409600; |
| 21 static const int kBufferSize = 4096; | 22 static const int kBufferSize = 4096; |
| 22 static const int kWriteSize = 512; | 23 static const int kWriteSize = 512; |
| 23 | 24 |
| 24 virtual void SetUp() { | 25 virtual void SetUp() { |
| 25 // Setup seed. | 26 // Create random test data samples. |
| 26 int seed = static_cast<int32>(base::Time::Now().ToInternalValue()); | |
| 27 srand(seed); | |
| 28 VLOG(1) << "Random seed: " << seed; | |
| 29 | |
| 30 // Creates a test data. | |
| 31 for (int i = 0; i < kDataSize; i++) | 27 for (int i = 0; i < kDataSize; i++) |
| 32 data_[i] = static_cast<char>(rand()); | 28 data_[i] = static_cast<char>(base::RandInt(0, 255)); |
| 33 } | 29 } |
| 34 | 30 |
| 35 int GetRandomInt(int maximum) { | 31 int GetRandomInt(int maximum) { |
| 36 return rand() % maximum + 1; | 32 return base::RandInt(0, maximum); |
|
miu
2014/01/10 22:53:54
BTW--I know the exact replacement here should be:
| |
| 37 } | 33 } |
| 38 | 34 |
| 39 SeekableBuffer buffer_; | 35 SeekableBuffer buffer_; |
| 40 uint8 data_[kDataSize]; | 36 uint8 data_[kDataSize]; |
| 41 uint8 write_buffer_[kDataSize]; | 37 uint8 write_buffer_[kDataSize]; |
| 42 }; | 38 }; |
| 43 | 39 |
| 44 TEST_F(SeekableBufferTest, RandomReadWrite) { | 40 TEST_F(SeekableBufferTest, RandomReadWrite) { |
| 45 int write_position = 0; | 41 int write_position = 0; |
| 46 int read_position = 0; | 42 int read_position = 0; |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" | 339 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" |
| 344 << tests[i].first_time_useconds << ", duration:" | 340 << tests[i].first_time_useconds << ", duration:" |
| 345 << tests[i].duration_useconds << ", consumed:" | 341 << tests[i].duration_useconds << ", consumed:" |
| 346 << tests[i].consume_bytes << " }\n"; | 342 << tests[i].consume_bytes << " }\n"; |
| 347 | 343 |
| 348 buffer_.Clear(); | 344 buffer_.Clear(); |
| 349 } | 345 } |
| 350 } | 346 } |
| 351 | 347 |
| 352 } // namespace media | 348 } // namespace media |
| OLD | NEW |