Chromium Code Reviews| Index: media/base/sinc_resampler_unittest.cc |
| diff --git a/media/base/sinc_resampler_unittest.cc b/media/base/sinc_resampler_unittest.cc |
| index fa358e13045c82a2035070557fb0c2d793b35499..760eea561d8a7ef06f93d3021daa2e95251b0ee3 100644 |
| --- a/media/base/sinc_resampler_unittest.cc |
| +++ b/media/base/sinc_resampler_unittest.cc |
| @@ -58,6 +58,36 @@ TEST(SincResamplerTest, ChunkedResample) { |
| resampler.Resample(resampled_destination.get(), max_chunk_size); |
| } |
| +// Test flush resets the internal state properly. |
| +TEST(SincResamplerTest, Flush) { |
| + MockSource mock_source; |
| + SincResampler resampler( |
| + kSampleRateRatio, |
| + base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); |
| + scoped_array<float> resampled_destination(new float[resampler.ChunkSize()]); |
| + |
| + EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(1); |
| + resampler.Resample(resampled_destination.get(), resampler.ChunkSize()); |
| + |
| + // Figure out buffer size from internal buffer layout. |
| + int buffer_size_float = reinterpret_cast<int>( |
| + resampler.r4_ + (resampler.r4_ - resampler.r3_) - resampler.r1_); |
|
scherkus (not reviewing)
2012/09/07 13:30:17
instead of friend test + poking around internals,
DaleCurtis
2012/09/07 14:17:35
I like this idea. Will change.
DaleCurtis
2012/09/10 12:06:24
Found a better way => Prime with junk data, Flush(
|
| + int buffer_size_bytes = buffer_size_float * sizeof(*( |
|
scherkus (not reviewing)
2012/09/07 13:30:17
looks bizarre -- drop sizeof to next line?
DaleCurtis
2012/09/10 12:06:24
Removed.
|
| + resampler.input_buffer_.get())); |
| + |
| + // Fill input buffer with junk data so we can if it's cleared afterwards. |
| + memset(resampler.input_buffer_.get(), 0xFF, buffer_size_bytes); |
| + |
| + EXPECT_TRUE(resampler.buffer_primed_); |
| + EXPECT_NE(resampler.virtual_source_idx_, 0); |
| + |
| + resampler.Flush(); |
| + EXPECT_FALSE(resampler.buffer_primed_); |
| + EXPECT_EQ(resampler.virtual_source_idx_, 0); |
| + for (int i = 0; i < buffer_size_float; ++i) |
| + ASSERT_FLOAT_EQ(resampler.input_buffer_.get()[i], 0); |
| +} |
| + |
| // Ensure various optimized Convolve() methods return the same value. Only run |
| // this test if other optimized methods exist, otherwise the default Convolve() |
| // will be tested by the parameterized SincResampler tests below. |