summaryrefslogtreecommitdiffstats
path: root/media/base/mock_ffmpeg.cc
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-19 18:23:49 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-19 18:23:49 +0000
commitb1dc1dec10e03ca7fdf4219d7059dfc07973811a (patch)
tree87c44dfa015a6139daac9d027f906d9d6581d051 /media/base/mock_ffmpeg.cc
parent68a983963a8ef1718400bb7a7f177f5a26ae4656 (diff)
downloadchromium_src-b1dc1dec10e03ca7fdf4219d7059dfc07973811a.zip
chromium_src-b1dc1dec10e03ca7fdf4219d7059dfc07973811a.tar.gz
chromium_src-b1dc1dec10e03ca7fdf4219d7059dfc07973811a.tar.bz2
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
Diffstat (limited to 'media/base/mock_ffmpeg.cc')
-rw-r--r--media/base/mock_ffmpeg.cc71
1 files changed, 71 insertions, 0 deletions
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