Chromium Code Reviews| Index: media/base/audio_block_fifo_unittest.cc |
| diff --git a/media/base/audio_block_fifo_unittest.cc b/media/base/audio_block_fifo_unittest.cc |
| index 8e8b5e071521896dfc2e0ef953ef1f1e02125165..933ac5dc74d68371d1e285bd9f12630f818b5cd0 100644 |
| --- a/media/base/audio_block_fifo_unittest.cc |
| +++ b/media/base/audio_block_fifo_unittest.cc |
| @@ -8,29 +8,48 @@ |
| namespace media { |
| class AudioBlockFifoTest : public testing::Test { |
| - public: |
| + protected: |
| AudioBlockFifoTest() {} |
| virtual ~AudioBlockFifoTest() {} |
| - void PushAndVerify(AudioBlockFifo* fifo, int frames_to_push, |
| - int channels, int block_frames, int max_frames) { |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(AudioBlockFifoTest); |
| +}; |
| + |
| +class AudioBlockFifoTestP : public AudioBlockFifoTest, |
|
DaleCurtis
2014/08/25 17:42:23
AudioBlockFifoFormatTest ? The P is not really he
no longer working on chromium
2014/08/26 09:39:52
Done.
|
| + public testing::WithParamInterface<bool> { |
| + protected: |
| + void PushAndVerify(AudioBlockFifo* fifo, |
| + int frames_to_push, |
| + int channels, |
| + int block_frames, |
| + int max_frames) { |
| const int bytes_per_sample = 2; |
| const int data_byte_size = bytes_per_sample * channels * frames_to_push; |
| - scoped_ptr<uint8[]> data(new uint8[data_byte_size]); |
| - memset(data.get(), 0, data_byte_size); |
| - |
| - for (int filled_frames = max_frames - fifo->GetUnfilledFrames(); |
| - filled_frames + frames_to_push <= max_frames;) { |
| - fifo->Push(data.get(), frames_to_push, bytes_per_sample); |
| - filled_frames += frames_to_push; |
| - EXPECT_EQ(max_frames - filled_frames, fifo->GetUnfilledFrames()); |
| - EXPECT_EQ(static_cast<int>(filled_frames / block_frames), |
| - fifo->available_blocks()); |
| + if (GetParam()) { |
| + scoped_ptr<media::AudioBus> data = |
| + AudioBus::Create(channels, frames_to_push); |
| + for (int filled_frames = max_frames - fifo->GetUnfilledFrames(); |
| + filled_frames + frames_to_push <= max_frames;) { |
| + fifo->Push(data.get()); |
| + filled_frames += frames_to_push; |
| + EXPECT_EQ(max_frames - filled_frames, fifo->GetUnfilledFrames()); |
| + EXPECT_EQ(static_cast<int>(filled_frames / block_frames), |
| + fifo->available_blocks()); |
| + } |
| + } else { |
| + scoped_ptr<uint8[]> data(new uint8[data_byte_size]); |
| + memset(data.get(), 0, data_byte_size); |
| + for (int filled_frames = max_frames - fifo->GetUnfilledFrames(); |
| + filled_frames + frames_to_push <= max_frames;) { |
| + fifo->Push(data.get(), frames_to_push, bytes_per_sample); |
| + filled_frames += frames_to_push; |
| + EXPECT_EQ(max_frames - filled_frames, fifo->GetUnfilledFrames()); |
| + EXPECT_EQ(static_cast<int>(filled_frames / block_frames), |
| + fifo->available_blocks()); |
| + } |
| } |
| } |
| - |
| - private: |
| - DISALLOW_COPY_AND_ASSIGN(AudioBlockFifoTest); |
| }; |
| // Verify that construction works as intended. |
| @@ -44,7 +63,7 @@ TEST_F(AudioBlockFifoTest, Construct) { |
| } |
| // Pushes audio bus objects to/from a FIFO up to different degrees. |
| -TEST_F(AudioBlockFifoTest, Push) { |
| +TEST_P(AudioBlockFifoTestP, Push) { |
| const int channels = 2; |
| const int frames = 128; |
| const int blocks = 2; |
| @@ -65,7 +84,7 @@ TEST_F(AudioBlockFifoTest, Push) { |
| // Perform a sequence of Push/Consume calls to different degrees, and verify |
| // things are correct. |
| -TEST_F(AudioBlockFifoTest, PushAndConsume) { |
| +TEST_P(AudioBlockFifoTestP, PushAndConsume) { |
| const int channels = 2; |
| const int frames = 441; |
| const int blocks = 4; |
| @@ -100,10 +119,9 @@ TEST_F(AudioBlockFifoTest, PushAndConsume) { |
| fifo.Clear(); |
| int new_push_frames = 128; |
| // Change the input frame and try to fill up the FIFO. |
| - PushAndVerify(&fifo, new_push_frames, channels, frames, |
| - frames * blocks); |
| + PushAndVerify(&fifo, new_push_frames, channels, frames, frames * blocks); |
| EXPECT_TRUE(fifo.GetUnfilledFrames() != 0); |
| - EXPECT_TRUE(fifo.available_blocks() == blocks -1); |
| + EXPECT_TRUE(fifo.available_blocks() == blocks - 1); |
| // Consume all the existing filled blocks of data. |
| while (fifo.available_blocks()) { |
| @@ -122,14 +140,13 @@ TEST_F(AudioBlockFifoTest, PushAndConsume) { |
| // Completely fill up the buffer again. |
| new_push_frames = frames * blocks - remain_frames; |
| - PushAndVerify(&fifo, new_push_frames, channels, frames, |
| - frames * blocks); |
| + PushAndVerify(&fifo, new_push_frames, channels, frames, frames * blocks); |
| EXPECT_TRUE(fifo.GetUnfilledFrames() == 0); |
| EXPECT_TRUE(fifo.available_blocks() == blocks); |
| } |
| // Perform a sequence of Push/Consume calls to a 1 block FIFO. |
| -TEST_F(AudioBlockFifoTest, PushAndConsumeOneBlockFifo) { |
| +TEST_P(AudioBlockFifoTestP, PushAndConsumeOneBlockFifo) { |
| static const int channels = 2; |
| static const int frames = 441; |
| static const int blocks = 1; |
| @@ -146,4 +163,8 @@ TEST_F(AudioBlockFifoTest, PushAndConsumeOneBlockFifo) { |
| EXPECT_TRUE(fifo.GetUnfilledFrames() == frames); |
| } |
| +INSTANTIATE_TEST_CASE_P(AudioBlockFifoTests, |
| + AudioBlockFifoTestP, |
| + ::testing::Values(false, true)); |
| + |
| } // namespace media |