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

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

Issue 126306: Refactor FFmpegDemuxerTest to use gmock and eliminate flakiness. (Closed)
Patch Set: Added SCOPED_TRACE Created 11 years, 6 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 | « no previous file | media/base/mock_ffmpeg.cc » ('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 #ifndef MEDIA_BASE_MOCK_FFMPEG_H_ 5 #ifndef MEDIA_BASE_MOCK_FFMPEG_H_
6 #define MEDIA_BASE_MOCK_FFMPEG_H_ 6 #define MEDIA_BASE_MOCK_FFMPEG_H_
7 7
8 // TODO(scherkus): See if we can remove ffmpeg_common from this file. 8 // TODO(scherkus): See if we can remove ffmpeg_common from this file.
9 #include "media/filters/ffmpeg_common.h" 9 #include "media/filters/ffmpeg_common.h"
10
11 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
12 11
13 namespace media { 12 namespace media {
14 13
15 class MockFFmpeg { 14 class MockFFmpeg {
16 public: 15 public:
16 MockFFmpeg();
17 ~MockFFmpeg();
18
17 MOCK_METHOD1(AVCodecFindDecoder, AVCodec*(enum CodecID id)); 19 MOCK_METHOD1(AVCodecFindDecoder, AVCodec*(enum CodecID id));
18 MOCK_METHOD2(AVCodecOpen, int(AVCodecContext* avctx, AVCodec* codec)); 20 MOCK_METHOD2(AVCodecOpen, int(AVCodecContext* avctx, AVCodec* codec));
19 MOCK_METHOD2(AVCodecThreadInit, int(AVCodecContext* avctx, int threads)); 21 MOCK_METHOD2(AVCodecThreadInit, int(AVCodecContext* avctx, int threads));
20 22
23 MOCK_METHOD5(AVOpenInputFile, int(AVFormatContext** format,
24 const char* filename,
25 AVInputFormat* input_format,
26 int buffer_size,
27 AVFormatParameters* parameters));
28 MOCK_METHOD1(AVFindStreamInfo, int(AVFormatContext* format));
29 MOCK_METHOD2(AVReadFrame, int(AVFormatContext* format, AVPacket* packet));
30 MOCK_METHOD4(AVSeekFrame, int(AVFormatContext *format,
31 int stream_index,
32 int64_t timestamp,
33 int flags));
34
35 MOCK_METHOD2(AVNewPacket, int(AVPacket* packet, int size));
36 MOCK_METHOD1(AVFree, void(void* ptr));
37 MOCK_METHOD1(AVFreePacket, void(AVPacket* packet));
38
39 // Used for verifying check points during tests.
40 MOCK_METHOD1(CheckPoint, void(int id));
41
21 // Setter/getter for the global instance of MockFFmpeg. 42 // Setter/getter for the global instance of MockFFmpeg.
22 static void set(MockFFmpeg* instance); 43 static void set(MockFFmpeg* instance);
23 static MockFFmpeg* get(); 44 static MockFFmpeg* get();
24 45
46 // AVPacket destructor for packets allocated by av_new_packet().
47 static void DestructPacket(AVPacket* packet);
48
49 // Modifies the number of outstanding packets.
50 void inc_outstanding_packets();
51 void dec_outstanding_packets();
52
25 private: 53 private:
26 static MockFFmpeg* instance_; 54 static MockFFmpeg* instance_;
55
56 // Tracks the number of packets allocated by calls to av_read_frame() and
57 // av_free_packet(). We crash the unit test if this is not zero at time of
58 // destruction.
59 int outstanding_packets_;
27 }; 60 };
28 61
62 // Used for simulating av_read_frame().
63 ACTION_P3(CreatePacket, stream_index, data, size) {
64 // Confirm we're dealing with AVPacket so we can safely const_cast<>.
65 ::testing::StaticAssertTypeEq<AVPacket*, arg1_type>();
66 memset(arg1, 0, sizeof(*arg1));
67 arg1->stream_index = stream_index;
68 arg1->data = const_cast<uint8*>(data);
69 arg1->size = size;
70
71 // Increment number of packets allocated.
72 MockFFmpeg::get()->inc_outstanding_packets();
73
74 return 0;
75 }
76
77 // Used for simulating av_new_packet().
78 ACTION(NewPacket) {
79 ::testing::StaticAssertTypeEq<AVPacket*, arg0_type>();
80 int size = arg1;
81 memset(arg0, 0, sizeof(*arg0));
82 arg0->data = new uint8[size];
83 arg0->size = size;
84 arg0->destruct = &MockFFmpeg::DestructPacket;
85
86 // Increment number of packets allocated.
87 MockFFmpeg::get()->inc_outstanding_packets();
88
89 return 0;
90 }
91
92 // Used for simulating av_free_packet().
93 ACTION(FreePacket) {
94 ::testing::StaticAssertTypeEq<AVPacket*, arg0_type>();
95
96 // Call the destructor if present, such as the one assigned in NewPacket().
97 if (arg0->destruct) {
98 arg0->destruct(arg0);
99 }
100
101 // Decrement number of packets allocated.
102 MockFFmpeg::get()->dec_outstanding_packets();
103 }
104
29 } // namespace media 105 } // namespace media
30 106
31 #endif // MEDIA_BASE_MOCK_FFMPEG_H_ 107 #endif // MEDIA_BASE_MOCK_FFMPEG_H_
OLDNEW
« no previous file with comments | « no previous file | media/base/mock_ffmpeg.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698