diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 04:24:17 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 04:24:17 +0000 |
commit | 3222e481e8bd6e542419d6d97ae26382f571e71d (patch) | |
tree | 7867b287f983d8374f7ffa0cd569d150c76b29dc | |
parent | 91ecb071fa284d802254834fb0e0400eb762078f (diff) | |
download | chromium_src-3222e481e8bd6e542419d6d97ae26382f571e71d.zip chromium_src-3222e481e8bd6e542419d6d97ae26382f571e71d.tar.gz chromium_src-3222e481e8bd6e542419d6d97ae26382f571e71d.tar.bz2 |
Updated FFmpegDemuxerTest and FFmpegVideoDecoderTest to use the gmock-based MockFilterHost.
Also deleted the old MockPipeline and MockFilterHost code as it has been completely deprecated.
BUG=16008
TEST=FFmpegDemuxerTest and FFmpegVideoDecoderTest
Review URL: http://codereview.chromium.org/149366
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20242 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | media/base/mock_filter_host.h | 107 | ||||
-rw-r--r-- | media/base/mock_filters.h | 3 | ||||
-rw-r--r-- | media/base/mock_pipeline.h | 181 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer_unittest.cc | 44 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder_unittest.cc | 34 | ||||
-rw-r--r-- | media/media.gyp | 1 |
6 files changed, 30 insertions, 340 deletions
diff --git a/media/base/mock_filter_host.h b/media/base/mock_filter_host.h index 3cc5860..c926437 100644 --- a/media/base/mock_filter_host.h +++ b/media/base/mock_filter_host.h @@ -5,9 +5,6 @@ // A FilterHost implementation based on gmock. Combined with setting a message // loop on a filter, permits single-threaded testing of filters without // requiring a pipeline. -// -// TODO(scherkus): Remove old_mocks::MockFilterHost as soon as other tests have -// transitioned over to the new gmock-based MockFilterHost. #ifndef MEDIA_BASE_MOCK_FILTER_HOST_H_ #define MEDIA_BASE_MOCK_FILTER_HOST_H_ @@ -20,7 +17,6 @@ #include "media/base/filter_host.h" #include "media/base/filters.h" #include "media/base/media_format.h" -#include "media/base/mock_pipeline.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -45,109 +41,6 @@ class MockFilterHost : public FilterHost { DISALLOW_COPY_AND_ASSIGN(MockFilterHost); }; -namespace old_mocks { - -// This version is deprecated. -template <class Filter> -class MockFilterHost : public FilterHost { - public: - MockFilterHost(MockPipeline* mock_pipeline, Filter* filter) - : mock_pipeline_(mock_pipeline), - filter_(filter), - initialized_(false), - error_(PIPELINE_OK), - wait_for_initialized_(false, false), - wait_for_error_(false, false) { - EXPECT_TRUE(mock_pipeline_); - EXPECT_TRUE(filter_); - filter_->SetFilterHost(this); - } - - virtual ~MockFilterHost() {} - - virtual void InitializationComplete() { - EXPECT_FALSE(initialized_); - initialized_ = true; - wait_for_initialized_.Signal(); - } - - virtual void Error(PipelineError error) { - error_ = error; - mock_pipeline_->Error(error); - wait_for_error_.Signal(); - } - - virtual base::TimeDelta GetTime() const { - return mock_pipeline_->GetTime(); - } - - virtual void SetTime(base::TimeDelta time) { - mock_pipeline_->SetTime(time); - } - - virtual void SetDuration(base::TimeDelta duration) { - mock_pipeline_->SetDuration(duration); - } - - virtual void SetBufferedTime(base::TimeDelta buffered_time) { - mock_pipeline_->SetBufferedTime(buffered_time); - } - - virtual void SetTotalBytes(int64 total_bytes) { - mock_pipeline_->SetTotalBytes(total_bytes); - } - - virtual void SetBufferedBytes(int64 buffered_bytes) { - mock_pipeline_->SetBufferedBytes(buffered_bytes); - } - - virtual void SetVideoSize(size_t width, size_t height) { - mock_pipeline_->SetVideoSize(width, height); - } - - bool IsInitialized() const { - return initialized_; - } - - bool WaitForInitialized() { - const base::TimeDelta kTimedWait = base::TimeDelta::FromMilliseconds(500); - while (!initialized_) { - if (!wait_for_initialized_.TimedWait(kTimedWait)) { - return false; - } - } - return true; - } - - bool WaitForError(PipelineError error) { - const base::TimeDelta kTimedWait = base::TimeDelta::FromMilliseconds(500); - while (error_ != error) { - if (!wait_for_error_.TimedWait(kTimedWait)) { - return false; - } - } - return true; - } - - private: - MockPipeline* mock_pipeline_; - scoped_refptr<Filter> filter_; - - // Tracks if the filter has executed InitializationComplete(). - bool initialized_; - - // Tracks the last pipeline error set by the filter. - PipelineError error_; - - // Allows unit tests to wait for particular conditions before asserting. - base::WaitableEvent wait_for_initialized_; - base::WaitableEvent wait_for_error_; - - DISALLOW_COPY_AND_ASSIGN(MockFilterHost); -}; - -} // namespace old_mocks - } // namespace media #endif // MEDIA_BASE_MOCK_FILTER_HOST_H_ diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index c45f8e6..07bb34e 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -13,6 +13,7 @@ #ifndef MEDIA_BASE_MOCK_FILTERS_H_ #define MEDIA_BASE_MOCK_FILTERS_H_ +#include "media/base/factory.h" #include "media/base/filters.h" #include "testing/gmock/include/gmock/gmock.h" @@ -163,8 +164,6 @@ class MockAudioRenderer : public AudioRenderer { // FilterFactory that returns canned instances of mock filters. You can set // expectations on the filters and then pass the factory into a pipeline. -// -// TODO(scherkus): add the other filter types. class MockFilterFactory : public FilterFactory { public: MockFilterFactory() diff --git a/media/base/mock_pipeline.h b/media/base/mock_pipeline.h deleted file mode 100644 index 01061c3..0000000 --- a/media/base/mock_pipeline.h +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this -// source code is governed by a BSD-style license that can be found in the -// LICENSE file. - -// Mock implementation of Pipeline. Simply provides getters/setters for every -// pipeline state variable and queues all tasks posted to the "pipeline thread." -// Since there actually isn't a separate thread unit tests can control when -// they want to execute queued tasks by calling RunAllTasks(), which helps to -// assert pre- and post-conditions. - -#ifndef MEDIA_BASE_MOCK_PIPELINE_H_ -#define MEDIA_BASE_MOCK_PIPELINE_H_ - -#include <deque> -#include <string> - -#include "base/message_loop.h" -#include "media/base/media_format.h" -#include "media/base/pipeline.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace media { - -class MockPipeline : public media::Pipeline { - public: - MockPipeline() { - Reset(false); - } - - virtual ~MockPipeline() {} - - // Implementation of PipelineStatus interface. - virtual bool IsInitialized() const { - return initialized_; - } - - virtual base::TimeDelta GetDuration() const { - return duration_; - } - - virtual base::TimeDelta GetBufferedTime() const { - return buffered_time_; - } - - virtual int64 GetTotalBytes() const { - return total_bytes_; - } - - virtual int64 GetBufferedBytes() const { - return buffered_bytes_; - } - - virtual void GetVideoSize(size_t* width_out, size_t* height_out) const { - *width_out = width_; - *height_out = height_; - } - - virtual float GetVolume() const { - return volume_; - } - - virtual float GetPlaybackRate() const { - return playback_rate_; - } - - virtual base::TimeDelta GetTime() const { - return time_; - } - - virtual base::TimeDelta GetInterpolatedTime() const { - return time_; - } - - virtual PipelineError GetError() const { - return error_; - } - - virtual bool IsRendered(const std::string&) const { - return true; - } - - // Implementation of Pipeline interface. - virtual bool Start(FilterFactory* filter_factory, - const std::string& url, - PipelineCallback* init_complete_callback) { - EXPECT_FALSE(initialized_); - initialized_ = true; - if (init_complete_callback) { - init_complete_callback->Run(true); - delete init_complete_callback; - } - return true; - } - - virtual void Stop() { - EXPECT_TRUE(initialized_ || error_ != media::PIPELINE_OK); - Reset(false); - } - - virtual void SetPlaybackRate(float playback_rate) { - playback_rate_ = playback_rate; - } - - virtual void Seek(base::TimeDelta time, - PipelineCallback* seek_complete_callback) { - time_ = time; - } - - virtual void SetVolume(float volume) { - volume_ = volume; - } - - // Public methods used by tests and by MockFilterHost to manipulate the - // state of the mock pipeline. - - // Set the state to the same as a newly created MockPipeline. If - // |reset_to_initialized| is true then the pipeline's |initialized_| state - // will be true when this method returns. - void Reset(bool reset_to_initialized) { - error_ = media::PIPELINE_OK; - volume_ = 1.0f; - playback_rate_ = 0.0f; - initialized_ = reset_to_initialized; - time_ = base::TimeDelta(); - duration_ = base::TimeDelta(); - buffered_time_ = base::TimeDelta(); - width_ = 0; - height_ = 0; - buffered_bytes_ = 0; - total_bytes_ = 0; - } - - void Error(media::PipelineError error) { - initialized_ = false; - error_ = error; - } - - void SetTime(base::TimeDelta time) { - time_ = time; - } - - virtual void SetDuration(base::TimeDelta duration) { - duration_ = duration; - } - - virtual void SetBufferedTime(base::TimeDelta buffered_time) { - buffered_time = buffered_time; - } - - virtual void SetTotalBytes(int64 total_bytes) { - total_bytes_ = total_bytes; - } - - virtual void SetBufferedBytes(int64 buffered_bytes) { - buffered_bytes_ = buffered_bytes; - } - - virtual void SetVideoSize(size_t width, size_t height) { - width_ = width; - height_ = height; - } - - private: - PipelineError error_; - float volume_; - float playback_rate_; - bool initialized_; - base::TimeDelta time_; - base::TimeDelta duration_; - base::TimeDelta buffered_time_; - size_t width_; - size_t height_; - int64 buffered_bytes_; - int64 total_bytes_; - - DISALLOW_COPY_AND_ASSIGN(MockPipeline); -}; - -} // namespace media - -#endif // MEDIA_BASE_MOCK_PIPELINE_H_ diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index 606b6b4..dc21c49 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -66,13 +66,9 @@ class FFmpegDemuxerTest : public testing::Test { demuxer_ = factory_->Create<FFmpegDemuxer>(media_format); DCHECK(demuxer_); - // Provide a message loop. + // Inject a filter host and message loop and prepare a data source. + demuxer_->SetFilterHost(&host_); demuxer_->SetMessageLoop(&message_loop_); - - // Prepare a filter host and data source for the demuxer. - pipeline_.reset(new MockPipeline()); - filter_host_.reset(new old_mocks::MockFilterHost<Demuxer>(pipeline_.get(), - demuxer_)); data_source_ = new StrictMock<MockDataSource>(); // Initialize FFmpeg fixtures. @@ -119,9 +115,6 @@ class FFmpegDemuxerTest : public testing::Test { // Release the reference to the demuxer. demuxer_ = NULL; - // Filter host also holds a reference to demuxer, destroy it. - filter_host_.reset(); - // Reset MockFFmpeg. MockFFmpeg::set(NULL); } @@ -138,19 +131,25 @@ class FFmpegDemuxerTest : public testing::Test { // Initializes both MockFFmpeg and FFmpegDemuxer. void InitializeDemuxer() { InitializeDemuxerMocks(); + + // We expect a successful initialization. + EXPECT_CALL(host_, InitializationComplete()); + + // Since we ignore data streams, the duration should be equal to the longest + // supported stream's duration (audio, in this case). + base::TimeDelta expected_duration = + base::TimeDelta::FromMicroseconds(kDurations[AV_STREAM_AUDIO]); + EXPECT_CALL(host_, SetDuration(expected_duration)); + EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForInitialized()); - EXPECT_TRUE(filter_host_->IsInitialized()); - EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); } // Fixture members. scoped_refptr<FilterFactory> factory_; scoped_refptr<FFmpegDemuxer> demuxer_; - scoped_ptr<MockPipeline> pipeline_; - scoped_ptr<old_mocks::MockFilterHost<Demuxer> > filter_host_; scoped_refptr<StrictMock<MockDataSource> > data_source_; + StrictMock<MockFilterHost> host_; MessageLoop message_loop_; // FFmpeg fixtures. @@ -196,11 +195,10 @@ TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { // Simulate av_open_input_file() failing. EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL)) .WillOnce(Return(-1)); + EXPECT_CALL(host_, Error(DEMUXER_ERROR_COULD_NOT_OPEN)); EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_COULD_NOT_OPEN)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { @@ -210,11 +208,10 @@ TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_)) .WillOnce(Return(AVERROR_IO)); EXPECT_CALL(*MockFFmpeg::get(), AVCloseInputFile(&format_context_)); + EXPECT_CALL(host_, Error(DEMUXER_ERROR_COULD_NOT_PARSE)); EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_COULD_NOT_PARSE)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { @@ -223,12 +220,11 @@ TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) { SCOPED_TRACE(""); InitializeDemuxerMocks(); } + EXPECT_CALL(host_, Error(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); format_context_.nb_streams = 0; EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { @@ -237,13 +233,12 @@ TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) { SCOPED_TRACE(""); InitializeDemuxerMocks(); } + EXPECT_CALL(host_, Error(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]); format_context_.nb_streams = 1; EXPECT_TRUE(demuxer_->Initialize(data_source_.get())); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegDemuxerTest, Initialize_Successful) { @@ -255,11 +250,6 @@ TEST_F(FFmpegDemuxerTest, Initialize_Successful) { // Verify that our demuxer streams were created from our AVStream structures. EXPECT_EQ(DS_STREAM_MAX, static_cast<int>(demuxer_->GetNumberOfStreams())); - // Since we ignore data streams, the duration should be equal to the longest - // supported stream's duration (audio, in this case). - EXPECT_EQ(kDurations[AV_STREAM_AUDIO], - pipeline_->GetDuration().InMicroseconds()); - // First stream should be video and support the FFmpegDemuxerStream interface. scoped_refptr<DemuxerStream> stream = demuxer_->GetStream(DS_STREAM_VIDEO); AVStreamProvider* av_stream_provider = NULL; diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index 8e82ebc..fca238e 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -32,9 +32,10 @@ class MockFFmpegDemuxerStream : public MockDemuxerStream, // AVStreamProvider implementation. MOCK_METHOD0(GetAVStream, AVStream*()); - private: + protected: virtual ~MockFFmpegDemuxerStream() {} + private: DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxerStream); }; @@ -77,18 +78,14 @@ class FFmpegVideoDecoderTest : public testing::Test { decoder_ = factory_->Create<FFmpegVideoDecoder>(media_format); DCHECK(decoder_); - // Provide a message loop. + // Inject a filter host and message loop and prepare a demuxer stream. + decoder_->SetFilterHost(&host_); decoder_->SetMessageLoop(&message_loop_); + demuxer_ = new StrictMock<MockFFmpegDemuxerStream>(); // Manually set the thread id for tests that don't initialize the decoder. decoder_->set_thread_id(PlatformThread::CurrentId()); - // Prepare a filter host, pipeline and demuxer for the video decoder. - pipeline_.reset(new MockPipeline()); - filter_host_.reset( - new old_mocks::MockFilterHost<VideoDecoder>(pipeline_.get(), decoder_)); - demuxer_ = new MockFFmpegDemuxerStream(); - // Initialize FFmpeg fixtures. memset(&stream_, 0, sizeof(stream_)); memset(&codec_context_, 0, sizeof(codec_context_)); @@ -120,11 +117,10 @@ class FFmpegVideoDecoderTest : public testing::Test { // Fixture members. scoped_refptr<FilterFactory> factory_; scoped_refptr<FFmpegVideoDecoder> decoder_; - scoped_ptr<MockPipeline> pipeline_; - scoped_ptr<old_mocks::MockFilterHost<VideoDecoder> > filter_host_; - scoped_refptr<MockFFmpegDemuxerStream> demuxer_; + scoped_refptr<StrictMock<MockFFmpegDemuxerStream> > demuxer_; scoped_refptr<DataBuffer> buffer_; scoped_refptr<DataBuffer> end_of_stream_buffer_; + StrictMock<MockFilterHost> host_; MessageLoop message_loop_; // FFmpeg fixtures. @@ -168,11 +164,10 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_QueryInterfaceFails) { // Test QueryInterface returning NULL. EXPECT_CALL(*demuxer_, QueryInterface(AVStreamProvider::interface_id())) .WillOnce(ReturnNull()); + EXPECT_CALL(host_, Error(PIPELINE_ERROR_DECODE)); EXPECT_TRUE(decoder_->Initialize(demuxer_)); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(PIPELINE_ERROR_DECODE)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegVideoDecoderTest, Initialize_FindDecoderFails) { @@ -184,11 +179,10 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_FindDecoderFails) { .WillOnce(Return(&stream_)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(ReturnNull()); + EXPECT_CALL(host_, Error(PIPELINE_ERROR_DECODE)); EXPECT_TRUE(decoder_->Initialize(demuxer_)); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(PIPELINE_ERROR_DECODE)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegVideoDecoderTest, Initialize_InitThreadFails) { @@ -202,11 +196,10 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_InitThreadFails) { .WillOnce(Return(&codec_)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) .WillOnce(Return(-1)); + EXPECT_CALL(host_, Error(PIPELINE_ERROR_DECODE)); EXPECT_TRUE(decoder_->Initialize(demuxer_)); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(PIPELINE_ERROR_DECODE)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) { @@ -222,11 +215,10 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_OpenDecoderFails) { .WillOnce(Return(0)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) .WillOnce(Return(-1)); + EXPECT_CALL(host_, Error(PIPELINE_ERROR_DECODE)); EXPECT_TRUE(decoder_->Initialize(demuxer_)); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForError(PIPELINE_ERROR_DECODE)); - EXPECT_FALSE(filter_host_->IsInitialized()); } TEST_F(FFmpegVideoDecoderTest, Initialize_Successful) { @@ -242,12 +234,10 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_Successful) { .WillOnce(Return(0)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) .WillOnce(Return(0)); + EXPECT_CALL(host_, InitializationComplete()); EXPECT_TRUE(decoder_->Initialize(demuxer_)); message_loop_.RunAllPending(); - EXPECT_TRUE(filter_host_->WaitForInitialized()); - EXPECT_TRUE(filter_host_->IsInitialized()); - EXPECT_EQ(PIPELINE_OK, pipeline_->GetError()); // Test that the output media format is an uncompressed video surface that // matches the dimensions specified by FFmpeg. diff --git a/media/media.gyp b/media/media.gyp index 2e149cb..aaa009f 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -159,7 +159,6 @@ 'base/mock_filter_host.h', 'base/mock_filters.h', 'base/mock_media_filters.h', - 'base/mock_pipeline.h', 'base/mock_reader.h', 'base/pipeline_impl_unittest.cc', 'base/run_all_unittests.cc', |