summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-18 03:05:02 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-18 03:05:02 +0000
commit9c5715f50aef131228bb1e3a4a9441c2c1574386 (patch)
treeddff63c2a5996605b0198cefd8d076217dc224a6 /media
parent55b40be28fbc8be46c4c806c0969b27e509885d1 (diff)
downloadchromium_src-9c5715f50aef131228bb1e3a4a9441c2c1574386.zip
chromium_src-9c5715f50aef131228bb1e3a4a9441c2c1574386.tar.gz
chromium_src-9c5715f50aef131228bb1e3a4a9441c2c1574386.tar.bz2
Replace hard-coded media_format() methods with Google Mock methods declared in mock_filters.h.
Updated unit tests accordingly. Patch by Dominic Jodoin <dominic.jodoin@gmail.com> BUG=21040 TEST=Run the media_unittests and AudioRendererImplTest test suite in unit_tests. Ensure there is no Google Mock failures and that all tests are passing. Review URL: http://codereview.chromium.org/404016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32267 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/mock_filters.h36
-rw-r--r--media/base/pipeline_impl_unittest.cc64
-rw-r--r--media/filters/audio_renderer_base_unittest.cc13
-rw-r--r--media/filters/video_renderer_base_unittest.cc16
4 files changed, 80 insertions, 49 deletions
diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h
index e140818..ca60179 100644
--- a/media/base/mock_filters.h
+++ b/media/base/mock_filters.h
@@ -101,7 +101,7 @@ class MockDataSource : public DataSource {
// DataSource implementation.
MOCK_METHOD2(Initialize, void(const std::string& url,
FilterCallback* callback));
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD4(Read, void(int64 position, size_t size, uint8* data,
DataSource::ReadCallback* callback));
MOCK_METHOD1(GetSize, bool(int64* size_out));
@@ -111,8 +111,6 @@ class MockDataSource : public DataSource {
virtual ~MockDataSource() {}
private:
- MediaFormat media_format_;
-
DISALLOW_COPY_AND_ASSIGN(MockDataSource);
};
@@ -143,14 +141,8 @@ class MockDemuxerStream : public DemuxerStream {
public:
MockDemuxerStream() {}
- // Sets the mime type of this object's media format, which is usually checked
- // to determine the type of decoder to create.
- explicit MockDemuxerStream(const std::string& mime_type) {
- media_format_.SetAsString(MediaFormat::kMimeType, mime_type);
- }
-
// DemuxerStream implementation.
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
MOCK_METHOD1(QueryInterface, void*(const char* interface_id));
@@ -167,13 +159,6 @@ class MockVideoDecoder : public VideoDecoder {
public:
MockVideoDecoder() {}
- // Sets the essential media format keys for this decoder.
- MockVideoDecoder(const std::string& mime_type, int width, int height) {
- media_format_.SetAsString(MediaFormat::kMimeType, mime_type);
- media_format_.SetAsInteger(MediaFormat::kWidth, width);
- media_format_.SetAsInteger(MediaFormat::kHeight, height);
- }
-
// MediaFilter implementation.
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
@@ -183,15 +168,13 @@ class MockVideoDecoder : public VideoDecoder {
// VideoDecoder implementation.
MOCK_METHOD2(Initialize, void(DemuxerStream* stream,
FilterCallback* callback));
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD1(Read, void(Callback1<VideoFrame*>::Type* read_callback));
protected:
virtual ~MockVideoDecoder() {}
private:
- MediaFormat media_format_;
-
DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder);
};
@@ -199,15 +182,6 @@ class MockAudioDecoder : public AudioDecoder {
public:
MockAudioDecoder() {}
- // Sets the essential media format keys for this decoder.
- MockAudioDecoder(int channels, int sample_rate, int sample_bits) {
- media_format_.SetAsString(MediaFormat::kMimeType,
- mime_type::kUncompressedAudio);
- media_format_.SetAsInteger(MediaFormat::kChannels, channels);
- media_format_.SetAsInteger(MediaFormat::kSampleRate, sample_rate);
- media_format_.SetAsInteger(MediaFormat::kSampleBits, sample_bits);
- }
-
// MediaFilter implementation.
MOCK_METHOD0(Stop, void());
MOCK_METHOD1(SetPlaybackRate, void(float playback_rate));
@@ -217,15 +191,13 @@ class MockAudioDecoder : public AudioDecoder {
// AudioDecoder implementation.
MOCK_METHOD2(Initialize, void(DemuxerStream* stream,
FilterCallback* callback));
- const MediaFormat& media_format() { return media_format_; }
+ MOCK_METHOD0(media_format, const MediaFormat&());
MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback));
protected:
virtual ~MockAudioDecoder() {}
private:
- MediaFormat media_format_;
-
DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder);
};
diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc
index e7681da..2a2e556 100644
--- a/media/base/pipeline_impl_unittest.cc
+++ b/media/base/pipeline_impl_unittest.cc
@@ -4,6 +4,7 @@
#include <string>
+#include "base/stl_util-inl.h"
#include "base/waitable_event.h"
#include "media/base/pipeline_impl.h"
#include "media/base/media_format.h"
@@ -19,6 +20,7 @@ using ::testing::Invoke;
using ::testing::Mock;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::StrictMock;
namespace {
@@ -76,6 +78,9 @@ class PipelineImplTest : public ::testing::Test {
pipeline_->Stop(NewCallback(reinterpret_cast<CallbackHelper*>(&callbacks_),
&CallbackHelper::OnStop));
message_loop_.RunAllPending();
+
+ // Free allocated media formats (if any).
+ STLDeleteElements(&stream_media_formats_);
}
protected:
@@ -89,6 +94,8 @@ class PipelineImplTest : public ::testing::Test {
EXPECT_CALL(*mocks_->data_source(), Seek(base::TimeDelta(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->data_source(), Stop());
+ EXPECT_CALL(*mocks_->data_source(), media_format())
+ .WillOnce(ReturnRef(data_source_media_format_));
}
// Sets up expectations to allow the demuxer to initialize.
@@ -114,6 +121,22 @@ class PipelineImplTest : public ::testing::Test {
}
}
+ // Create a stream with an associated media format.
+ StrictMock<MockDemuxerStream>* CreateStream(const std::string& mime_type) {
+ StrictMock<MockDemuxerStream>* stream =
+ new StrictMock<MockDemuxerStream>();
+
+ // Sets the mime type of this stream's media format, which is usually
+ // checked to determine the type of decoder to create.
+ MediaFormat* media_format = new MediaFormat();
+ media_format->SetAsString(MediaFormat::kMimeType, mime_type);
+ EXPECT_CALL(*stream, media_format())
+ .WillRepeatedly(ReturnRef(*media_format));
+ stream_media_formats_.push_back(media_format);
+
+ return stream;
+ }
+
// Sets up expectations to allow the video decoder to initialize.
void InitializeVideoDecoder(MockDemuxerStream* stream) {
EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull()))
@@ -122,6 +145,8 @@ class PipelineImplTest : public ::testing::Test {
EXPECT_CALL(*mocks_->video_decoder(), Seek(base::TimeDelta(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->video_decoder(), Stop());
+ EXPECT_CALL(*mocks_->video_decoder(), media_format())
+ .WillOnce(ReturnRef(video_decoder_media_format_));
}
// Sets up expectations to allow the audio decoder to initialize.
@@ -132,6 +157,8 @@ class PipelineImplTest : public ::testing::Test {
EXPECT_CALL(*mocks_->audio_decoder(), Seek(base::TimeDelta(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->audio_decoder(), Stop());
+ EXPECT_CALL(*mocks_->audio_decoder(), media_format())
+ .WillOnce(ReturnRef(audio_decoder_media_format_));
}
// Sets up expectations to allow the video renderer to initialize.
@@ -174,6 +201,13 @@ class PipelineImplTest : public ::testing::Test {
scoped_refptr<PipelineImpl> pipeline_;
scoped_refptr<media::MockFilterFactory> mocks_;
+ MediaFormat data_source_media_format_;
+ MediaFormat audio_decoder_media_format_;
+ MediaFormat video_decoder_media_format_;
+
+ typedef std::vector<MediaFormat*> MediaFormatVector;
+ MediaFormatVector stream_media_formats_;
+
private:
DISALLOW_COPY_AND_ASSIGN(PipelineImplTest);
};
@@ -280,6 +314,8 @@ TEST_F(PipelineImplTest, NoStreams) {
EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
EXPECT_CALL(*mocks_->data_source(), Stop());
+ EXPECT_CALL(*mocks_->data_source(), media_format())
+ .WillOnce(ReturnRef(data_source_media_format_));
EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull()))
.WillOnce(Invoke(&RunFilterCallback));
@@ -295,7 +331,7 @@ TEST_F(PipelineImplTest, NoStreams) {
TEST_F(PipelineImplTest, AudioStream) {
scoped_refptr<StrictMock<MockDemuxerStream> > stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(stream);
@@ -313,7 +349,7 @@ TEST_F(PipelineImplTest, AudioStream) {
TEST_F(PipelineImplTest, VideoStream) {
scoped_refptr<StrictMock<MockDemuxerStream> > stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(stream);
@@ -331,9 +367,9 @@ TEST_F(PipelineImplTest, VideoStream) {
TEST_F(PipelineImplTest, AudioVideoStream) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
@@ -354,9 +390,9 @@ TEST_F(PipelineImplTest, AudioVideoStream) {
TEST_F(PipelineImplTest, Seek) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
@@ -400,7 +436,7 @@ TEST_F(PipelineImplTest, Seek) {
TEST_F(PipelineImplTest, SetVolume) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
@@ -418,14 +454,14 @@ TEST_F(PipelineImplTest, SetVolume) {
pipeline_->SetVolume(expected);
}
-TEST_F(PipelineImplTest, Properties) {
+TEST_F(PipelineImplTest, Properties) {
scoped_refptr<StrictMock<MockDemuxerStream> > stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(stream);
InitializeDataSource();
- base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
+ const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
InitializeDemuxer(&streams, kDuration);
InitializeVideoDecoder(stream);
InitializeVideoRenderer();
@@ -443,9 +479,9 @@ TEST_F(PipelineImplTest, Properties) {
TEST_F(PipelineImplTest, BroadcastMessage) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
@@ -484,9 +520,9 @@ TEST_F(PipelineImplTest, BroadcastMessage) {
TEST_F(PipelineImplTest, EndedCallback) {
scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream =
- new StrictMock<MockDemuxerStream>("audio/x-foo");
+ CreateStream("audio/x-foo");
scoped_refptr<StrictMock<MockDemuxerStream> > video_stream =
- new StrictMock<MockDemuxerStream>("video/x-foo");
+ CreateStream("video/x-foo");
MockDemuxerStreamVector streams;
streams.push_back(audio_stream);
streams.push_back(video_stream);
diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc
index 1827424..df4c9f0 100644
--- a/media/filters/audio_renderer_base_unittest.cc
+++ b/media/filters/audio_renderer_base_unittest.cc
@@ -15,6 +15,7 @@ using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::StrictMock;
namespace media {
@@ -47,12 +48,21 @@ class AudioRendererBaseTest : public ::testing::Test {
// Give the decoder some non-garbage media properties.
AudioRendererBaseTest()
: renderer_(new MockAudioRendererBase()),
- decoder_(new MockAudioDecoder(1, 44100, 16)) {
+ decoder_(new MockAudioDecoder()) {
renderer_->set_host(&host_);
// Queue all reads from the decoder.
EXPECT_CALL(*decoder_, Read(NotNull()))
.WillRepeatedly(Invoke(this, &AudioRendererBaseTest::EnqueueCallback));
+
+ // Sets the essential media format keys for this decoder.
+ decoder_media_format_.SetAsString(MediaFormat::kMimeType,
+ mime_type::kUncompressedAudio);
+ decoder_media_format_.SetAsInteger(MediaFormat::kChannels, 1);
+ decoder_media_format_.SetAsInteger(MediaFormat::kSampleRate, 44100);
+ decoder_media_format_.SetAsInteger(MediaFormat::kSampleBits, 16);
+ EXPECT_CALL(*decoder_, media_format())
+ .WillRepeatedly(ReturnRef(decoder_media_format_));
}
virtual ~AudioRendererBaseTest() {
@@ -71,6 +81,7 @@ class AudioRendererBaseTest : public ::testing::Test {
scoped_refptr<MockAudioDecoder> decoder_;
StrictMock<MockFilterHost> host_;
StrictMock<MockFilterCallback> callback_;
+ MediaFormat decoder_media_format_;
// Receives asynchronous read requests sent to |decoder_|.
std::deque<Callback1<Buffer*>::Type*> read_queue_;
diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc
index b6a5c6b..9735b5f 100644
--- a/media/filters/video_renderer_base_unittest.cc
+++ b/media/filters/video_renderer_base_unittest.cc
@@ -16,6 +16,7 @@ using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::StrictMock;
namespace media {
@@ -42,13 +43,20 @@ class VideoRendererBaseTest : public ::testing::Test {
public:
VideoRendererBaseTest()
: renderer_(new MockVideoRendererBase()),
- decoder_(new MockVideoDecoder(mime_type::kUncompressedVideo, kWidth,
- kHeight)) {
+ decoder_(new MockVideoDecoder()) {
renderer_->set_host(&host_);
// Queue all reads from the decoder.
EXPECT_CALL(*decoder_, Read(NotNull()))
.WillRepeatedly(Invoke(this, &VideoRendererBaseTest::EnqueueCallback));
+
+ // Sets the essential media format keys for this decoder.
+ decoder_media_format_.SetAsString(MediaFormat::kMimeType,
+ mime_type::kUncompressedVideo);
+ decoder_media_format_.SetAsInteger(MediaFormat::kWidth, kWidth);
+ decoder_media_format_.SetAsInteger(MediaFormat::kHeight, kHeight);
+ EXPECT_CALL(*decoder_, media_format())
+ .WillRepeatedly(ReturnRef(decoder_media_format_));
}
virtual ~VideoRendererBaseTest() {
@@ -68,6 +76,7 @@ class VideoRendererBaseTest : public ::testing::Test {
scoped_refptr<MockVideoDecoder> decoder_;
StrictMock<MockFilterHost> host_;
StrictMock<MockFilterCallback> callback_;
+ MediaFormat decoder_media_format_;
// Receives asynchronous read requests sent to |decoder_|.
std::deque<Callback1<VideoFrame*>::Type*> read_queue_;
@@ -88,7 +97,10 @@ TEST_F(VideoRendererBaseTest, Initialize_BadMediaFormat) {
InSequence s;
// Don't set a media format.
+ MediaFormat media_format;
scoped_refptr<MockVideoDecoder> bad_decoder = new MockVideoDecoder();
+ EXPECT_CALL(*bad_decoder, media_format())
+ .WillRepeatedly(ReturnRef(media_format));
// We expect to receive an error.
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_INITIALIZATION_FAILED));