From b1dc1dec10e03ca7fdf4219d7059dfc07973811a Mon Sep 17 00:00:00 2001 From: "scherkus@chromium.org" Date: Fri, 19 Jun 2009 18:23:49 +0000 Subject: Refactor FFmpegDemuxerTest to use gmock and eliminate flakiness. This eliminates all final traces of the old global-functions-and-variables style of mocking, which was a massive headache to maintain and verify correctness. No new tests have been added, however gmock creates much stronger assertions for the tests themselves. I also made FFmpegDemuxerTest a friend of FFmpegDemuxer to let tests verify that all tasks on the internal demuxing thread have completed. BUG=13933 TEST=FFmpegDemuxerTest should more awesome and less flaky Review URL: http://codereview.chromium.org/126306 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18833 0039d316-1c4b-4281-b951-d872f2087c98 --- media/base/mock_ffmpeg.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'media/base/mock_ffmpeg.cc') diff --git a/media/base/mock_ffmpeg.cc b/media/base/mock_ffmpeg.cc index 4e9fc03..b1de0c4 100644 --- a/media/base/mock_ffmpeg.cc +++ b/media/base/mock_ffmpeg.cc @@ -11,6 +11,24 @@ namespace media { MockFFmpeg* MockFFmpeg::instance_ = NULL; +MockFFmpeg::MockFFmpeg() + : outstanding_packets_(0) { +} + +MockFFmpeg::~MockFFmpeg() { + CHECK(!outstanding_packets_) + << "MockFFmpeg destroyed with outstanding packets"; +} + +void MockFFmpeg::inc_outstanding_packets() { + ++outstanding_packets_; +} + +void MockFFmpeg::dec_outstanding_packets() { + CHECK(outstanding_packets_ > 0); + --outstanding_packets_; +} + // static void MockFFmpeg::set(MockFFmpeg* instance) { instance_ = instance; @@ -21,6 +39,13 @@ MockFFmpeg* MockFFmpeg::get() { return instance_; } +// static +void MockFFmpeg::DestructPacket(AVPacket* packet) { + delete [] packet->data; + packet->data = NULL; + packet->size = 0; +} + // FFmpeg stubs that delegate to the FFmpegMock instance. extern "C" { @@ -55,6 +80,52 @@ void av_init_packet(AVPacket* pkt) { NOTREACHED(); } +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); +} + +int av_find_stream_info(AVFormatContext* format) { + return media::MockFFmpeg::get()->AVFindStreamInfo(format); +} + +int64 av_rescale_q(int64 a, AVRational bq, AVRational cq) { + // Because this is a math function there's little point in mocking it, so we + // implement a cheap version that's capable of overflowing. + int64 num = bq.num * cq.den; + int64 den = cq.num * bq.den; + return a * num / den; +} + +void av_free_packet(AVPacket* packet) { + media::MockFFmpeg::get()->AVFreePacket(packet); +} + +int av_new_packet(AVPacket* packet, int size) { + return media::MockFFmpeg::get()->AVNewPacket(packet, size); +} + +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); + } +} + +int av_read_frame(AVFormatContext* format, AVPacket* packet) { + return media::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); +} + } // extern "C" } // namespace media -- cgit v1.1