Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: media/base/mock_ffmpeg.cc

Issue 149423: Converted remaining tests to use gmock and deleted all old mocking code. (Closed)
Patch Set: Fix again Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/base/mock_ffmpeg.h ('k') | media/base/mock_filters.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/mock_ffmpeg.h" 5 #include "media/base/mock_ffmpeg.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/filters/ffmpeg_common.h" 8 #include "media/filters/ffmpeg_common.h"
9 9
10 using ::testing::_;
11 using ::testing::AtMost;
12 using ::testing::DoAll;
13 using ::testing::Return;
14 using ::testing::SaveArg;
15
10 namespace media { 16 namespace media {
11 17
12 MockFFmpeg* MockFFmpeg::instance_ = NULL; 18 MockFFmpeg* MockFFmpeg::instance_ = NULL;
19 URLProtocol* MockFFmpeg::protocol_ = NULL;
13 20
14 MockFFmpeg::MockFFmpeg() 21 MockFFmpeg::MockFFmpeg()
15 : outstanding_packets_(0) { 22 : outstanding_packets_(0) {
23 // If we haven't assigned our static copy of URLProtocol, set up expectations
24 // to catch the URLProtocol registered when the singleton instance of
25 // FFmpegGlue is created.
26 //
27 // TODO(scherkus): this feels gross and I need to think of a way to better
28 // inject/mock singletons.
29 if (!protocol_) {
30 EXPECT_CALL(*this, AVCodecInit())
31 .Times(AtMost(1))
32 .WillOnce(Return());
33 EXPECT_CALL(*this, AVRegisterProtocol(_))
34 .Times(AtMost(1))
35 .WillOnce(DoAll(SaveArg<0>(&protocol_), Return(0)));
36 EXPECT_CALL(*this, AVRegisterAll())
37 .Times(AtMost(1))
38 .WillOnce(Return());
39 }
16 } 40 }
17 41
18 MockFFmpeg::~MockFFmpeg() { 42 MockFFmpeg::~MockFFmpeg() {
19 CHECK(!outstanding_packets_) 43 CHECK(!outstanding_packets_)
20 << "MockFFmpeg destroyed with outstanding packets"; 44 << "MockFFmpeg destroyed with outstanding packets";
21 } 45 }
22 46
23 void MockFFmpeg::inc_outstanding_packets() { 47 void MockFFmpeg::inc_outstanding_packets() {
24 ++outstanding_packets_; 48 ++outstanding_packets_;
25 } 49 }
26 50
27 void MockFFmpeg::dec_outstanding_packets() { 51 void MockFFmpeg::dec_outstanding_packets() {
28 CHECK(outstanding_packets_ > 0); 52 CHECK(outstanding_packets_ > 0);
29 --outstanding_packets_; 53 --outstanding_packets_;
30 } 54 }
31 55
32 // static 56 // static
33 void MockFFmpeg::set(MockFFmpeg* instance) { 57 void MockFFmpeg::set(MockFFmpeg* instance) {
34 instance_ = instance; 58 instance_ = instance;
35 } 59 }
36 60
37 // static 61 // static
38 MockFFmpeg* MockFFmpeg::get() { 62 MockFFmpeg* MockFFmpeg::get() {
39 return instance_; 63 return instance_;
40 } 64 }
41 65
42 // static 66 // static
67 URLProtocol* MockFFmpeg::protocol() {
68 return protocol_;
69 }
70
71 // static
43 void MockFFmpeg::DestructPacket(AVPacket* packet) { 72 void MockFFmpeg::DestructPacket(AVPacket* packet) {
44 delete [] packet->data; 73 delete [] packet->data;
45 packet->data = NULL; 74 packet->data = NULL;
46 packet->size = 0; 75 packet->size = 0;
47 } 76 }
48 77
49 // FFmpeg stubs that delegate to the FFmpegMock instance. 78 // FFmpeg stubs that delegate to the FFmpegMock instance.
50 extern "C" { 79 extern "C" {
51 80
81 void avcodec_init() {
82 media::MockFFmpeg::get()->AVCodecInit();
83 }
84
85 int av_register_protocol(URLProtocol* protocol) {
86 return media::MockFFmpeg::get()->AVRegisterProtocol(protocol);
87 }
88
89 void av_register_all() {
90 media::MockFFmpeg::get()->AVRegisterAll();
91 }
92
52 AVCodec* avcodec_find_decoder(enum CodecID id) { 93 AVCodec* avcodec_find_decoder(enum CodecID id) {
53 return media::MockFFmpeg::get()->AVCodecFindDecoder(id); 94 return media::MockFFmpeg::get()->AVCodecFindDecoder(id);
54 } 95 }
55 96
56 int avcodec_open(AVCodecContext* avctx, AVCodec* codec) { 97 int avcodec_open(AVCodecContext* avctx, AVCodec* codec) {
57 return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec); 98 return media::MockFFmpeg::get()->AVCodecOpen(avctx, codec);
58 } 99 }
59 100
60 int avcodec_close(AVCodecContext* avctx) { 101 int avcodec_close(AVCodecContext* avctx) {
61 return media::MockFFmpeg::get()->AVCodecClose(avctx); 102 return media::MockFFmpeg::get()->AVCodecClose(avctx);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // Freeing NULL pointers are valid, but they aren't interesting from a mock 170 // Freeing NULL pointers are valid, but they aren't interesting from a mock
130 // perspective. 171 // perspective.
131 if (ptr) { 172 if (ptr) {
132 media::MockFFmpeg::get()->AVFree(ptr); 173 media::MockFFmpeg::get()->AVFree(ptr);
133 } 174 }
134 } 175 }
135 176
136 } // extern "C" 177 } // extern "C"
137 178
138 } // namespace media 179 } // namespace media
OLDNEW
« no previous file with comments | « media/base/mock_ffmpeg.h ('k') | media/base/mock_filters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698