summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 23:04:57 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 23:04:57 +0000
commit67798caf395912068941e0f3479232d9adce1d0f (patch)
tree7fe0e552ca003267e737c216406d744db9eee815 /media
parent8358105e6826be9bbb7ef2a43671d596aa492ba6 (diff)
downloadchromium_src-67798caf395912068941e0f3479232d9adce1d0f.zip
chromium_src-67798caf395912068941e0f3479232d9adce1d0f.tar.gz
chromium_src-67798caf395912068941e0f3479232d9adce1d0f.tar.bz2
Wrote gmock-based mock filters and a mock filter factory.
Next up is actually refactoring tests to use these and not the old_mocks version. The biggest user is the PipelineImpl tests, which I'm currently refactoring anyway hence sending this out for review. BUG=16008 TEST=FFmpegVideoDecoderTest should still pass Review URL: http://codereview.chromium.org/149356 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/filters.h2
-rw-r--r--media/base/mock_filters.h175
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc20
3 files changed, 188 insertions, 9 deletions
diff --git a/media/base/filters.h b/media/base/filters.h
index 43f24fd..bc94d39 100644
--- a/media/base/filters.h
+++ b/media/base/filters.h
@@ -245,7 +245,7 @@ class AudioDecoder : public MediaFilter {
// Schedules a read. Decoder takes ownership of the callback.
//
// TODO(scherkus): switch Read() callback to scoped_refptr<>.
- virtual void Read(Callback1<Buffer*>::Type* read_callbasck) = 0;
+ virtual void Read(Callback1<Buffer*>::Type* read_callback) = 0;
};
diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h
index 2a2b13c..c45f8e6 100644
--- a/media/base/mock_filters.h
+++ b/media/base/mock_filters.h
@@ -43,6 +43,181 @@ class MockDataSource : public DataSource {
DISALLOW_COPY_AND_ASSIGN(MockDataSource);
};
+class MockDemuxer : public Demuxer {
+ public:
+ MockDemuxer() {}
+
+ // MediaFilter implementation.
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
+ MOCK_METHOD1(Seek, void(base::TimeDelta time));
+
+ // Demuxer implementation.
+ MOCK_METHOD1(Initialize, bool(DataSource* data_source));
+ MOCK_METHOD0(GetNumberOfStreams, size_t());
+ MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(int stream_id));
+
+ protected:
+ virtual ~MockDemuxer() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockDemuxer);
+};
+
+class MockDemuxerStream : public DemuxerStream {
+ public:
+ MockDemuxerStream() {}
+
+ // DemuxerStream implementation.
+ MOCK_METHOD0(media_format, const MediaFormat&());
+ MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
+ MOCK_METHOD1(QueryInterface, void*(const char* interface_id));
+
+ protected:
+ virtual ~MockDemuxerStream() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockDemuxerStream);
+};
+
+class MockVideoDecoder : public VideoDecoder {
+ public:
+ MockVideoDecoder() {}
+
+ // MediaFilter implementation.
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
+ MOCK_METHOD1(Seek, void(base::TimeDelta time));
+
+ // VideoDecoder implementation.
+ MOCK_METHOD1(Initialize, bool(DemuxerStream* demuxer_stream));
+ MOCK_METHOD0(media_format, const MediaFormat&());
+ MOCK_METHOD1(Read, void(Callback1<VideoFrame*>::Type* read_callback));
+
+ protected:
+ virtual ~MockVideoDecoder() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder);
+};
+
+class MockAudioDecoder : public AudioDecoder {
+ public:
+ MockAudioDecoder() {}
+
+ // MediaFilter implementation.
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
+ MOCK_METHOD1(Seek, void(base::TimeDelta time));
+
+ // AudioDecoder implementation.
+ MOCK_METHOD1(Initialize, bool(DemuxerStream* demuxer_stream));
+ MOCK_METHOD0(media_format, const MediaFormat&());
+ MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
+
+ protected:
+ virtual ~MockAudioDecoder() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder);
+};
+
+class MockVideoRenderer : public VideoRenderer {
+ public:
+ MockVideoRenderer() {}
+
+ // MediaFilter implementation.
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
+ MOCK_METHOD1(Seek, void(base::TimeDelta time));
+
+ // VideoRenderer implementation.
+ MOCK_METHOD1(Initialize, bool(VideoDecoder* decoder));
+
+ protected:
+ virtual ~MockVideoRenderer() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer);
+};
+
+class MockAudioRenderer : public AudioRenderer {
+ public:
+ MockAudioRenderer() {}
+
+ // MediaFilter implementation.
+ MOCK_METHOD0(Stop, void());
+ MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
+ MOCK_METHOD1(Seek, void(base::TimeDelta time));
+
+ // AudioRenderer implementation.
+ MOCK_METHOD1(Initialize, bool(AudioDecoder* decoder));
+ MOCK_METHOD1(SetVolume, void(float volume));
+
+ protected:
+ virtual ~MockAudioRenderer() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAudioRenderer);
+};
+
+// 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()
+ : data_source_(new MockDataSource()),
+ demuxer_(new MockDemuxer()),
+ video_decoder_(new MockVideoDecoder()),
+ audio_decoder_(new MockAudioDecoder()),
+ video_renderer_(new MockVideoRenderer()),
+ audio_renderer_(new MockAudioRenderer()) {
+ }
+
+ virtual ~MockFilterFactory() {}
+
+ // Mock accessors.
+ MockDataSource* data_source() const { return data_source_; }
+ MockDemuxer* demuxer() const { return demuxer_; }
+ MockVideoDecoder* video_decoder() const { return video_decoder_; }
+ MockAudioDecoder* audio_decoder() const { return audio_decoder_; }
+ MockVideoRenderer* video_renderer() const { return video_renderer_; }
+ MockAudioRenderer* audio_renderer() const { return audio_renderer_; }
+
+ protected:
+ MediaFilter* Create(FilterType filter_type, const MediaFormat& media_format) {
+ switch (filter_type) {
+ case FILTER_DATA_SOURCE:
+ return data_source_;
+ case FILTER_DEMUXER:
+ return demuxer_;
+ case FILTER_VIDEO_DECODER:
+ return video_decoder_;
+ case FILTER_AUDIO_DECODER:
+ return audio_decoder_;
+ case FILTER_VIDEO_RENDERER:
+ return video_renderer_;
+ case FILTER_AUDIO_RENDERER:
+ return audio_renderer_;
+ default:
+ NOTREACHED() << "Unknown filter type: " << filter_type;
+ }
+ return NULL;
+ }
+
+ private:
+ scoped_refptr<MockDataSource> data_source_;
+ scoped_refptr<MockDemuxer> demuxer_;
+ scoped_refptr<MockVideoDecoder> video_decoder_;
+ scoped_refptr<MockAudioDecoder> audio_decoder_;
+ scoped_refptr<MockVideoRenderer> video_renderer_;
+ scoped_refptr<MockAudioRenderer> audio_renderer_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockFilterFactory);
+};
+
} // namespace media
#endif // MEDIA_BASE_MOCK_FILTERS_H_
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index 40b122d..1c2b39a 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -9,6 +9,7 @@
#include "media/base/filters.h"
#include "media/base/mock_ffmpeg.h"
#include "media/base/mock_filter_host.h"
+#include "media/base/mock_filters.h"
#include "media/filters/ffmpeg_common.h"
#include "media/filters/ffmpeg_interfaces.h"
#include "media/filters/ffmpeg_video_decoder.h"
@@ -23,15 +24,18 @@ using ::testing::StrictMock;
namespace media {
-class MockDemuxerStream : public DemuxerStream, public AVStreamProvider {
+class MockFFmpegDemuxerStream : public MockDemuxerStream,
+ public AVStreamProvider {
public:
- // DemuxerStream interface.
- MOCK_METHOD0(media_format, const MediaFormat&());
- MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
- MOCK_METHOD1(QueryInterface, void*(const char* interface_id));
+ MockFFmpegDemuxerStream() {}
- // AVStreamProvider interface.
+ // AVStreamProvider implementation.
MOCK_METHOD0(GetAVStream, AVStream*());
+
+ private:
+ virtual ~MockFFmpegDemuxerStream() {}
+
+ DISALLOW_COPY_AND_ASSIGN(MockFFmpegDemuxerStream);
};
// Class that just mocks the private functions.
@@ -83,7 +87,7 @@ class FFmpegVideoDecoderTest : public testing::Test {
pipeline_.reset(new MockPipeline());
filter_host_.reset(new MockFilterHost<VideoDecoder>(pipeline_.get(),
decoder_));
- demuxer_ = new MockDemuxerStream();
+ demuxer_ = new MockFFmpegDemuxerStream();
// Initialize FFmpeg fixtures.
memset(&stream_, 0, sizeof(stream_));
@@ -118,7 +122,7 @@ class FFmpegVideoDecoderTest : public testing::Test {
scoped_refptr<FFmpegVideoDecoder> decoder_;
scoped_ptr<MockPipeline> pipeline_;
scoped_ptr<MockFilterHost<VideoDecoder> > filter_host_;
- scoped_refptr<MockDemuxerStream> demuxer_;
+ scoped_refptr<MockFFmpegDemuxerStream> demuxer_;
scoped_refptr<DataBuffer> buffer_;
scoped_refptr<DataBuffer> end_of_stream_buffer_;
MessageLoop message_loop_;