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 <cstdlib> | |
6 | |
5 #include "base/logging.h" | 7 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
7 #include "base/rand_util.h" | |
8 #include "base/time/time.h" | 9 #include "base/time/time.h" |
9 #include "media/base/data_buffer.h" | 10 #include "media/base/data_buffer.h" |
10 #include "media/base/seekable_buffer.h" | 11 #include "media/base/seekable_buffer.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace media { | 14 namespace media { |
14 | 15 |
15 class SeekableBufferTest : public testing::Test { | 16 class SeekableBufferTest : public testing::Test { |
16 public: | 17 public: |
17 SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) { | 18 SeekableBufferTest() : buffer_(kBufferSize, kBufferSize) { |
18 } | 19 } |
19 | 20 |
20 protected: | 21 protected: |
21 static const int kDataSize = 409600; | 22 static const int kDataSize = 409600; |
DaleCurtis
2014/01/17 23:28:21
Geez are we really allocating 400k of data for thi
| |
22 static const int kBufferSize = 4096; | 23 static const int kBufferSize = 4096; |
23 static const int kWriteSize = 512; | 24 static const int kWriteSize = 512; |
24 | 25 |
25 virtual void SetUp() { | 26 virtual void SetUp() { |
27 // Note: We use srand() and rand() rather than base::RandXXX() to improve | |
28 // unit test performance. We don't need good random numbers, just | |
29 // something that generates "mixed data." | |
30 const unsigned int kKnownSeed = 0x98765432; | |
31 srand(kKnownSeed); | |
32 | |
26 // Create random test data samples. | 33 // Create random test data samples. |
27 for (int i = 0; i < kDataSize; i++) | 34 for (int i = 0; i < kDataSize; i++) |
28 data_[i] = static_cast<char>(base::RandInt(0, 255)); | 35 data_[i] = static_cast<char>(rand()); |
DaleCurtis
2014/01/17 23:28:21
You might try base::RandBytes()... after this CL t
| |
29 } | 36 } |
30 | 37 |
31 int GetRandomInt(int maximum) { | 38 int GetRandomInt(int maximum) { |
32 return base::RandInt(0, maximum); | 39 return rand() % (maximum + 1); |
33 } | 40 } |
34 | 41 |
35 SeekableBuffer buffer_; | 42 SeekableBuffer buffer_; |
36 uint8 data_[kDataSize]; | 43 uint8 data_[kDataSize]; |
37 uint8 write_buffer_[kDataSize]; | 44 uint8 write_buffer_[kDataSize]; |
38 }; | 45 }; |
39 | 46 |
40 TEST_F(SeekableBufferTest, RandomReadWrite) { | 47 TEST_F(SeekableBufferTest, RandomReadWrite) { |
41 int write_position = 0; | 48 int write_position = 0; |
42 int read_position = 0; | 49 int read_position = 0; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
339 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" | 346 EXPECT_EQ(tests[i].expected_time, actual) << "With test = { start:" |
340 << tests[i].first_time_useconds << ", duration:" | 347 << tests[i].first_time_useconds << ", duration:" |
341 << tests[i].duration_useconds << ", consumed:" | 348 << tests[i].duration_useconds << ", consumed:" |
342 << tests[i].consume_bytes << " }\n"; | 349 << tests[i].consume_bytes << " }\n"; |
343 | 350 |
344 buffer_.Clear(); | 351 buffer_.Clear(); |
345 } | 352 } |
346 } | 353 } |
347 | 354 |
348 } // namespace media | 355 } // namespace media |
OLD | NEW |