diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-19 00:05:30 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-19 00:05:30 +0000 |
commit | 8b70f1e6b4909378f23fe1ebd6a75db6919a7155 (patch) | |
tree | e6c352189c573ac1f9d3a7f41a55463525112979 /media | |
parent | 9444d4e59f5703da920d792141a78224861319bd (diff) | |
download | chromium_src-8b70f1e6b4909378f23fe1ebd6a75db6919a7155.zip chromium_src-8b70f1e6b4909378f23fe1ebd6a75db6919a7155.tar.gz chromium_src-8b70f1e6b4909378f23fe1ebd6a75db6919a7155.tar.bz2 |
Retry: Move MockFFmpeg instance setting into the constructor/destructor.
Previously tests had to manually call MockFFmpeg::set() during test setup and teardown. Now that operation is handled automatically via scoping.
BUG=72933
TEST=media_unittests
Review URL: http://codereview.chromium.org/6539021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75472 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/mock_ffmpeg.cc | 81 | ||||
-rw-r--r-- | media/base/mock_ffmpeg.h | 5 | ||||
-rw-r--r-- | media/filters/bitstream_converter_unittest.cc | 10 | ||||
-rw-r--r-- | media/filters/ffmpeg_demuxer_unittest.cc | 96 | ||||
-rw-r--r-- | media/filters/ffmpeg_glue_unittest.cc | 11 | ||||
-rw-r--r-- | media/filters/ffmpeg_h264_bitstream_converter_unittest.cc | 1 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder_unittest.cc | 6 | ||||
-rw-r--r-- | media/media.gyp | 47 | ||||
-rw-r--r-- | media/video/ffmpeg_video_decode_engine_unittest.cc | 40 |
9 files changed, 106 insertions, 191 deletions
diff --git a/media/base/mock_ffmpeg.cc b/media/base/mock_ffmpeg.cc index f3aa552..ec19b1b 100644 --- a/media/base/mock_ffmpeg.cc +++ b/media/base/mock_ffmpeg.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -20,6 +20,9 @@ URLProtocol* MockFFmpeg::protocol_ = NULL; MockFFmpeg::MockFFmpeg() : outstanding_packets_(0) { + CHECK(instance_ == NULL) << "Only a single MockFFmpeg instance can exist"; + instance_ = this; + // If we haven't assigned our static copy of URLProtocol, set up expectations // to catch the URLProtocol registered when the singleton instance of // FFmpegGlue is created. @@ -40,16 +43,13 @@ MockFFmpeg::MockFFmpeg() .Times(AtMost(1)) .WillOnce(Return()); } - // av_lockmgr_register() is also called from ~FFmpegLock(), so we expect - // it to be called at the end. - EXPECT_CALL(*this, AVRegisterLockManager(_)) - .Times(AtMost(2)) - .WillRepeatedly(Return(0)); } MockFFmpeg::~MockFFmpeg() { CHECK(!outstanding_packets_) << "MockFFmpeg destroyed with outstanding packets"; + CHECK(instance_); + instance_ = NULL; } void MockFFmpeg::inc_outstanding_packets() { @@ -62,11 +62,6 @@ void MockFFmpeg::dec_outstanding_packets() { } // static -void MockFFmpeg::set(MockFFmpeg* instance) { - instance_ = instance; -} - -// static MockFFmpeg* MockFFmpeg::get() { return instance_; } @@ -86,59 +81,57 @@ void MockFFmpeg::DestructPacket(AVPacket* packet) { // FFmpeg stubs that delegate to the FFmpegMock instance. extern "C" { void avcodec_init() { - media::MockFFmpeg::get()->AVCodecInit(); + MockFFmpeg::get()->AVCodecInit(); } int av_register_protocol2(URLProtocol* protocol, int size) { - return media::MockFFmpeg::get()->AVRegisterProtocol2(protocol, size); + return MockFFmpeg::get()->AVRegisterProtocol2(protocol, size); } void av_register_all() { - media::MockFFmpeg::get()->AVRegisterAll(); + MockFFmpeg::get()->AVRegisterAll(); } int av_lockmgr_register(int (*cb)(void**, enum AVLockOp)) { - media::MockFFmpeg* mock = media::MockFFmpeg::get(); // Here |mock| may be NULL when this function is called from ~FFmpegGlue(). - if (mock != NULL) { - return mock->AVRegisterLockManager(cb); - } else { - return 0; + if (MockFFmpeg::get()) { + return MockFFmpeg::get()->AVRegisterLockManager(cb); } + return 0; } AVCodec* avcodec_find_decoder(enum CodecID id) { - return media::MockFFmpeg::get()->AVCodecFindDecoder(id); + return MockFFmpeg::get()->AVCodecFindDecoder(id); } int avcodec_open(AVCodecContext* avctx, AVCodec* codec) { - return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec); + return MockFFmpeg::get()->AVCodecOpen(avctx, codec); } int avcodec_close(AVCodecContext* avctx) { - return media::MockFFmpeg::get()->AVCodecClose(avctx); + return MockFFmpeg::get()->AVCodecClose(avctx); } int avcodec_thread_init(AVCodecContext* avctx, int threads) { - return media::MockFFmpeg::get()->AVCodecThreadInit(avctx, threads); + return MockFFmpeg::get()->AVCodecThreadInit(avctx, threads); } void avcodec_flush_buffers(AVCodecContext* avctx) { - return media::MockFFmpeg::get()->AVCodecFlushBuffers(avctx); + return MockFFmpeg::get()->AVCodecFlushBuffers(avctx); } AVFrame* avcodec_alloc_frame() { - return media::MockFFmpeg::get()->AVCodecAllocFrame(); + return MockFFmpeg::get()->AVCodecAllocFrame(); } int avcodec_decode_video2(AVCodecContext* avctx, AVFrame* picture, int* got_picture_ptr, AVPacket* avpkt) { - return media::MockFFmpeg::get()-> + return MockFFmpeg::get()-> AVCodecDecodeVideo2(avctx, picture, got_picture_ptr, avpkt); } AVBitStreamFilterContext* av_bitstream_filter_init(const char* name) { - return media::MockFFmpeg::get()->AVBitstreamFilterInit(name); + return MockFFmpeg::get()->AVBitstreamFilterInit(name); } int av_bitstream_filter_filter(AVBitStreamFilterContext* bsfc, @@ -149,29 +142,29 @@ int av_bitstream_filter_filter(AVBitStreamFilterContext* bsfc, const uint8_t* buf, int buf_size, int keyframe) { - return media::MockFFmpeg::get()-> + return MockFFmpeg::get()-> AVBitstreamFilterFilter(bsfc, avctx, args, poutbuf, poutbuf_size, buf, buf_size, keyframe); } void av_bitstream_filter_close(AVBitStreamFilterContext* bsf) { - return media::MockFFmpeg::get()->AVBitstreamFilterClose(bsf); + return MockFFmpeg::get()->AVBitstreamFilterClose(bsf); } int av_open_input_file(AVFormatContext** format, const char* filename, AVInputFormat* input_format, int buffer_size, AVFormatParameters* parameters) { - return media::MockFFmpeg::get()->AVOpenInputFile(format, filename, - input_format, buffer_size, - parameters); + return MockFFmpeg::get()->AVOpenInputFile(format, filename, + input_format, buffer_size, + parameters); } void av_close_input_file(AVFormatContext* format) { - media::MockFFmpeg::get()->AVCloseInputFile(format); + MockFFmpeg::get()->AVCloseInputFile(format); } int av_find_stream_info(AVFormatContext* format) { - return media::MockFFmpeg::get()->AVFindStreamInfo(format); + return MockFFmpeg::get()->AVFindStreamInfo(format); } int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) { @@ -183,45 +176,45 @@ int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) { } int av_read_frame(AVFormatContext* format, AVPacket* packet) { - return media::MockFFmpeg::get()->AVReadFrame(format, packet); + return MockFFmpeg::get()->AVReadFrame(format, packet); } int av_seek_frame(AVFormatContext *format, int stream_index, int64_t timestamp, int flags) { - return media::MockFFmpeg::get()->AVSeekFrame(format, stream_index, timestamp, - flags); + return MockFFmpeg::get()->AVSeekFrame(format, stream_index, timestamp, + flags); } void av_init_packet(AVPacket* pkt) { - return media::MockFFmpeg::get()->AVInitPacket(pkt); + return MockFFmpeg::get()->AVInitPacket(pkt); } int av_new_packet(AVPacket* packet, int size) { - return media::MockFFmpeg::get()->AVNewPacket(packet, size); + return MockFFmpeg::get()->AVNewPacket(packet, size); } void av_free_packet(AVPacket* packet) { - media::MockFFmpeg::get()->AVFreePacket(packet); + MockFFmpeg::get()->AVFreePacket(packet); } void av_free(void* ptr) { // Freeing NULL pointers are valid, but they aren't interesting from a mock // perspective. if (ptr) { - media::MockFFmpeg::get()->AVFree(ptr); + MockFFmpeg::get()->AVFree(ptr); } } int av_dup_packet(AVPacket* packet) { - return media::MockFFmpeg::get()->AVDupPacket(packet); + return MockFFmpeg::get()->AVDupPacket(packet); } void av_log_set_level(int level) { - media::MockFFmpeg::get()->AVLogSetLevel(level); + MockFFmpeg::get()->AVLogSetLevel(level); } void av_destruct_packet(AVPacket *pkt) { - media::MockFFmpeg::get()->AVDestructPacket(pkt); + MockFFmpeg::get()->AVDestructPacket(pkt); } } // extern "C" diff --git a/media/base/mock_ffmpeg.h b/media/base/mock_ffmpeg.h index 09daf03..89402fe 100644 --- a/media/base/mock_ffmpeg.h +++ b/media/base/mock_ffmpeg.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -65,8 +65,7 @@ class MockFFmpeg { // Used for verifying check points during tests. MOCK_METHOD1(CheckPoint, void(int id)); - // Setter/getter for the global instance of MockFFmpeg. - static void set(MockFFmpeg* instance); + // Returns the current MockFFmpeg instance. static MockFFmpeg* get(); // Returns the URLProtocol registered by the FFmpegGlue singleton. diff --git a/media/filters/bitstream_converter_unittest.cc b/media/filters/bitstream_converter_unittest.cc index 85ca34e..6efb225 100644 --- a/media/filters/bitstream_converter_unittest.cc +++ b/media/filters/bitstream_converter_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -23,9 +23,6 @@ namespace media { class BitstreamConverterTest : public testing::Test { protected: BitstreamConverterTest() { - // Initialize MockFFmpeg. - MockFFmpeg::set(&mock_ffmpeg_); - memset(&test_stream_context_, 0, sizeof(test_stream_context_)); memset(&test_filter_, 0, sizeof(test_filter_)); memset(&test_packet_, 0, sizeof(test_packet_)); @@ -33,10 +30,7 @@ class BitstreamConverterTest : public testing::Test { test_packet_.size = kTestSize1; } - virtual ~BitstreamConverterTest() { - // Reset MockFFmpeg. - MockFFmpeg::set(NULL); - } + virtual ~BitstreamConverterTest() {} AVCodecContext test_stream_context_; AVBitStreamFilterContext test_filter_; diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc index aec72ea..c492493 100644 --- a/media/filters/ffmpeg_demuxer_unittest.cc +++ b/media/filters/ffmpeg_demuxer_unittest.cc @@ -105,9 +105,6 @@ class FFmpegDemuxerTest : public testing::Test { streams_[i].time_base.den = 1 * base::Time::kMicrosecondsPerSecond; streams_[i].time_base.num = 1; } - - // Initialize MockFFmpeg. - MockFFmpeg::set(&mock_ffmpeg_); } virtual ~FFmpegDemuxerTest() { @@ -119,18 +116,15 @@ class FFmpegDemuxerTest : public testing::Test { // Release the reference to the demuxer. demuxer_ = NULL; - - // Reset MockFFmpeg. - MockFFmpeg::set(NULL); } // Sets up MockFFmpeg to allow FFmpegDemuxer to successfully initialize. void InitializeDemuxerMocks() { - EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL)) + EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); - EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_)) + EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVCloseInputFile(&format_context_)); + EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); } // Initializes both MockFFmpeg and FFmpegDemuxer. @@ -179,7 +173,7 @@ const uint8* FFmpegDemuxerTest::kNullData = NULL; TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { // Simulate av_open_input_file() failing. - EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL)) + EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) .WillOnce(Return(-1)); EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_OPEN)); @@ -189,11 +183,11 @@ TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) { TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) { // Simulate av_find_stream_info() failing. - EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL)) + EXPECT_CALL(mock_ffmpeg_, AVOpenInputFile(_, _, NULL, 0, NULL)) .WillOnce(DoAll(SetArgumentPointee<0>(&format_context_), Return(0))); - EXPECT_CALL(*MockFFmpeg::get(), AVFindStreamInfo(&format_context_)) + EXPECT_CALL(mock_ffmpeg_, AVFindStreamInfo(&format_context_)) .WillOnce(Return(AVERROR_IO)); - EXPECT_CALL(*MockFFmpeg::get(), AVCloseInputFile(&format_context_)); + EXPECT_CALL(mock_ffmpeg_, AVCloseInputFile(&format_context_)); EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_PARSE)); demuxer_->Initialize(data_source_.get(), NewExpectedCallback()); @@ -270,14 +264,14 @@ TEST_F(FFmpegDemuxerTest, Read_DiscardUninteresting) { } // Ignore all AVFreePacket() calls. We check this elsewhere. - EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).Times(AnyNumber()); + EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); // The demuxer will read a data packet which will get immediately freed, // followed by a read error to end the reading. InSequence s; - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_DATA, kNullData, 0)); - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(Return(AVERROR_IO)); // Attempt a read from the audio stream and run the message loop until done. @@ -301,13 +295,13 @@ TEST_F(FFmpegDemuxerTest, Read_Audio) { } // Ignore all AVFreePacket() calls. We check this via valgrind. - EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).Times(AnyNumber()); + EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); // The demuxer will read a data packet which will get immediately freed, // followed by reading an audio packet... - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kAudioData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); // Attempt a read from the audio stream and run the message loop until done. @@ -333,12 +327,12 @@ TEST_F(FFmpegDemuxerTest, Read_Video) { } // Ignore all AVFreePacket() calls. We check this via valgrind. - EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).Times(AnyNumber()); + EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); // Simulate a successful frame read. - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_VIDEO, kVideoData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); // Attempt a read from the video stream and run the message loop until done. @@ -364,9 +358,9 @@ TEST_F(FFmpegDemuxerTest, Read_EndOfStream) { } // Ignore all AVFreePacket() calls. We check this via valgrind. - EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).Times(AnyNumber()); + EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(Return(AVERROR_IO)); // We should now expect an end of stream buffer. @@ -403,59 +397,59 @@ TEST_F(FFmpegDemuxerTest, Seek) { const int64 kExpectedFlags = AVSEEK_FLAG_BACKWARD; // Ignore all AVFreePacket() calls. We check this via valgrind. - EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).Times(AnyNumber()); + EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); // Expect all calls in sequence. InSequence s; // First we'll read a video packet that causes two audio packets to be queued // inside FFmpegDemuxer... - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kAudioData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kAudioData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_VIDEO, kVideoData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1)); + EXPECT_CALL(mock_ffmpeg_, CheckPoint(1)); // ...then we'll expect a seek call... - EXPECT_CALL(*MockFFmpeg::get(), + EXPECT_CALL(mock_ffmpeg_, AVSeekFrame(&format_context_, -1, kExpectedTimestamp, kExpectedFlags)) .WillOnce(Return(0)); // ...then our callback will be executed... FilterCallback* seek_callback = NewExpectedCallback(); - EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2)); + EXPECT_CALL(mock_ffmpeg_, CheckPoint(2)); // ...followed by two audio packet reads we'll trigger... - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kAudioData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kAudioData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); // ...followed by two video packet reads... - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_VIDEO, kVideoData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_VIDEO, kVideoData, kDataSize)); - EXPECT_CALL(*MockFFmpeg::get(), AVDupPacket(_)) + EXPECT_CALL(mock_ffmpeg_, AVDupPacket(_)) .WillOnce(Return(0)); // ...and finally a sanity checkpoint to make sure everything was released. - EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(3)); + EXPECT_CALL(mock_ffmpeg_, CheckPoint(3)); // Read a video packet and release it. scoped_refptr<DemuxerStreamReader> reader(new DemuxerStreamReader()); @@ -470,13 +464,13 @@ TEST_F(FFmpegDemuxerTest, Seek) { // Release the video packet and verify the other packets are still queued. reader->Reset(); message_loop_.RunAllPending(); - MockFFmpeg::get()->CheckPoint(1); + mock_ffmpeg_.CheckPoint(1); // Issue a simple forward seek, which should discard queued packets. demuxer_->Seek(base::TimeDelta::FromMicroseconds(kExpectedTimestamp), seek_callback); message_loop_.RunAllPending(); - MockFFmpeg::get()->CheckPoint(2); + mock_ffmpeg_.CheckPoint(2); // Audio read #1. reader->Read(audio); @@ -520,7 +514,7 @@ TEST_F(FFmpegDemuxerTest, Seek) { // Manually release the last reference to the buffer and verify it was freed. reader->Reset(); message_loop_.RunAllPending(); - MockFFmpeg::get()->CheckPoint(3); + mock_ffmpeg_.CheckPoint(3); } // A mocked callback specialization for calling Read(). Since RunWithParams() @@ -568,14 +562,14 @@ TEST_F(FFmpegDemuxerTest, Stop) { // The callback should be immediately deleted. We'll use a checkpoint to // verify that it has indeed been deleted. EXPECT_CALL(*callback, OnDelete()); - EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(1)); + EXPECT_CALL(mock_ffmpeg_, CheckPoint(1)); // Attempt the read... audio->Read(callback.release()); message_loop_.RunAllPending(); // ...and verify that |callback| was deleted. - MockFFmpeg::get()->CheckPoint(1); + mock_ffmpeg_.CheckPoint(1); } TEST_F(FFmpegDemuxerTest, DisableAudioStream) { @@ -593,17 +587,17 @@ TEST_F(FFmpegDemuxerTest, DisableAudioStream) { message_loop_.RunAllPending(); // Ignore all AVFreePacket() calls. We check this via valgrind. - EXPECT_CALL(*MockFFmpeg::get(), AVFreePacket(_)).Times(AnyNumber()); + EXPECT_CALL(mock_ffmpeg_, AVFreePacket(_)).Times(AnyNumber()); // Expect all calls in sequence. InSequence s; // The demuxer will read an audio packet which will get immediately freed. - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(CreatePacketNoCount(AV_STREAM_AUDIO, kNullData, 0)); // Then an end-of-stream packet is read. - EXPECT_CALL(*MockFFmpeg::get(), AVReadFrame(&format_context_, _)) + EXPECT_CALL(mock_ffmpeg_, AVReadFrame(&format_context_, _)) .WillOnce(Return(AVERROR_IO)); // Get our streams. diff --git a/media/filters/ffmpeg_glue_unittest.cc b/media/filters/ffmpeg_glue_unittest.cc index f823669..3c09fcf 100644 --- a/media/filters/ffmpeg_glue_unittest.cc +++ b/media/filters/ffmpeg_glue_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -36,12 +36,9 @@ class MockProtocol : public FFmpegURLProtocol { class FFmpegGlueTest : public ::testing::Test { public: - FFmpegGlueTest() { - } + FFmpegGlueTest() {} virtual void SetUp() { - MockFFmpeg::set(&mock_ffmpeg_); - // Singleton should initialize FFmpeg. CHECK(FFmpegGlue::GetInstance()); @@ -50,10 +47,6 @@ class FFmpegGlueTest : public ::testing::Test { CHECK(protocol_); } - virtual void TearDown() { - MockFFmpeg::set(NULL); - } - // Helper to open a URLContext pointing to the given mocked protocol. // Callers are expected to close the context at the end of their test. virtual void OpenContext(MockProtocol* protocol, URLContext* context) { diff --git a/media/filters/ffmpeg_h264_bitstream_converter_unittest.cc b/media/filters/ffmpeg_h264_bitstream_converter_unittest.cc index bf582f6..5799123 100644 --- a/media/filters/ffmpeg_h264_bitstream_converter_unittest.cc +++ b/media/filters/ffmpeg_h264_bitstream_converter_unittest.cc @@ -270,7 +270,6 @@ class FFmpegH264BitstreamConverterTest : public testing::Test { FFmpegH264BitstreamConverterTest() { // Set up the ffmpeg mock and use our local fake functions to do the // actual implementation for packet allocation / freeing. - MockFFmpeg::set(&ffmpeg_mock_); ON_CALL(ffmpeg_mock_, AVInitPacket(_)) .WillByDefault(Invoke(fake_av_init_packet)); ON_CALL(ffmpeg_mock_, AVNewPacket(_, _)) diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index da87170..95acdc4 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -156,9 +156,6 @@ class FFmpegVideoDecoderTest : public testing::Test { stream_.r_frame_rate.den = 1; buffer_ = new DataBuffer(1); end_of_stream_buffer_ = new DataBuffer(0); - - // Initialize MockFFmpeg. - MockFFmpeg::set(&mock_ffmpeg_); } virtual ~FFmpegVideoDecoderTest() { @@ -172,9 +169,6 @@ class FFmpegVideoDecoderTest : public testing::Test { // Finish up any remaining tasks. message_loop_.RunAllPending(); - - // Reset MockFFmpeg. - MockFFmpeg::set(NULL); } void InitializeDecoderSuccessfully() { diff --git a/media/media.gyp b/media/media.gyp index 1b76aff..2e6e613 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -399,53 +399,6 @@ }], ], }], - # media_unittests is failing like crazy on Windows. So disable all test - # cases. See bug: http://crbug.com/72790 - ['OS=="win"', { - 'sources!': [ - 'audio/audio_input_controller_unittest.cc', - 'audio/audio_input_unittest.cc', - 'audio/audio_output_controller_unittest.cc', - 'audio/audio_output_proxy_unittest.cc', - 'audio/audio_parameters_unittest.cc', - 'audio/audio_util_unittest.cc', - 'audio/fake_audio_input_stream_unittest.cc', - 'audio/linux/alsa_output_unittest.cc', - 'audio/mac/audio_output_mac_unittest.cc', - 'audio/simple_sources_unittest.cc', - 'audio/win/audio_output_win_unittest.cc', - 'base/composite_filter_unittest.cc', - 'base/clock_impl_unittest.cc', - 'base/data_buffer_unittest.cc', - 'base/djb2_unittest.cc', - 'base/filter_collection_unittest.cc', - 'base/h264_bitstream_converter_unittest.cc', - 'base/mock_ffmpeg.cc', - 'base/mock_ffmpeg.h', - 'base/mock_reader.h', - 'base/mock_task.cc', - 'base/mock_task.h', - 'base/pipeline_impl_unittest.cc', - 'base/pts_heap_unittest.cc', - 'base/seekable_buffer_unittest.cc', - 'base/state_matrix_unittest.cc', - 'base/video_frame_unittest.cc', - 'base/yuv_convert_unittest.cc', - 'filters/audio_renderer_algorithm_ola_unittest.cc', - 'filters/audio_renderer_base_unittest.cc', - 'filters/bitstream_converter_unittest.cc', - 'filters/decoder_base_unittest.cc', - 'filters/ffmpeg_demuxer_unittest.cc', - 'filters/ffmpeg_glue_unittest.cc', - 'filters/ffmpeg_h264_bitstream_converter_unittest.cc', - 'filters/ffmpeg_video_decoder_unittest.cc', - 'filters/file_data_source_unittest.cc', - 'filters/video_renderer_base_unittest.cc', - 'omx/mock_omx.cc', - 'omx/mock_omx.h', - 'video/ffmpeg_video_decode_engine_unittest.cc', - ], - }], ], }, { diff --git a/media/video/ffmpeg_video_decode_engine_unittest.cc b/media/video/ffmpeg_video_decode_engine_unittest.cc index 666e522..e3bea41 100644 --- a/media/video/ffmpeg_video_decode_engine_unittest.cc +++ b/media/video/ffmpeg_video_decode_engine_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -68,9 +68,6 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, buffer_ = new DataBuffer(1); - // Initialize MockFFmpeg. - MockFFmpeg::set(&mock_ffmpeg_); - test_engine_.reset(new FFmpegVideoDecodeEngine()); test_engine_->SetCodecContextForTest(&codec_context_); @@ -84,19 +81,18 @@ class FFmpegVideoDecodeEngineTest : public testing::Test, ~FFmpegVideoDecodeEngineTest() { test_engine_.reset(); - MockFFmpeg::set(NULL); } void Initialize() { - EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(Return(&codec_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) + EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) + EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) + EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) + EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); config_.codec = kCodecH264; @@ -166,11 +162,11 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_Normal) { TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { // Test avcodec_find_decoder() returning NULL. - EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(ReturnNull()); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) + EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) + EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); config_.codec = kCodecH264; @@ -186,13 +182,13 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_FindDecoderFails) { // Note There are 2 threads for FFmpeg-mt. TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { // Test avcodec_thread_init() failing. - EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(Return(&codec_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) + EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) + EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) .WillOnce(Return(-1)); - EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) + EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); config_.codec = kCodecH264; @@ -207,15 +203,15 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { // Test avcodec_open() failing. - EXPECT_CALL(*MockFFmpeg::get(), AVCodecFindDecoder(CODEC_ID_NONE)) + EXPECT_CALL(mock_ffmpeg_, AVCodecFindDecoder(CODEC_ID_NONE)) .WillOnce(Return(&codec_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) + EXPECT_CALL(mock_ffmpeg_, AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) + EXPECT_CALL(mock_ffmpeg_, AVCodecThreadInit(&codec_context_, 2)) .WillOnce(Return(0)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) + EXPECT_CALL(mock_ffmpeg_, AVCodecOpen(&codec_context_, &codec_)) .WillOnce(Return(-1)); - EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) + EXPECT_CALL(mock_ffmpeg_, AVFree(&yuv_frame_)) .Times(1); config_.codec = kCodecH264; |