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/base | |
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/base')
-rw-r--r-- | media/base/mock_ffmpeg.cc | 81 | ||||
-rw-r--r-- | media/base/mock_ffmpeg.h | 5 |
2 files changed, 39 insertions, 47 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. |