OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 // | 4 // |
5 // A new breed of mock media filters, this time using gmock! Feel free to add | 5 // A new breed of mock media filters, this time using gmock! Feel free to add |
6 // actions if you need interesting side-effects (i.e., copying data to the | 6 // actions if you need interesting side-effects (i.e., copying data to the |
7 // buffer passed into MockDataSource::Read()). | 7 // buffer passed into MockDataSource::Read()). |
8 // | 8 // |
9 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock | 9 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock |
10 // filters to fail the test or do nothing when an unexpected method is called. | 10 // filters to fail the test or do nothing when an unexpected method is called. |
(...skipping 25 matching lines...) Expand all Loading... | |
36 MOCK_METHOD1(GetSize, bool(int64* size_out)); | 36 MOCK_METHOD1(GetSize, bool(int64* size_out)); |
37 MOCK_METHOD0(IsSeekable, bool()); | 37 MOCK_METHOD0(IsSeekable, bool()); |
38 | 38 |
39 protected: | 39 protected: |
40 virtual ~MockDataSource() {} | 40 virtual ~MockDataSource() {} |
41 | 41 |
42 private: | 42 private: |
43 DISALLOW_COPY_AND_ASSIGN(MockDataSource); | 43 DISALLOW_COPY_AND_ASSIGN(MockDataSource); |
44 }; | 44 }; |
45 | 45 |
46 class MockDemuxer : public Demuxer { | |
47 public: | |
48 MockDemuxer() {} | |
49 | |
50 // MediaFilter implementation. | |
51 MOCK_METHOD0(Stop, void()); | |
52 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | |
53 MOCK_METHOD1(Seek, void(base::TimeDelta time)); | |
54 | |
55 // Demuxer implementation. | |
56 MOCK_METHOD1(Initialize, bool(DataSource* data_source)); | |
57 MOCK_METHOD0(GetNumberOfStreams, size_t()); | |
58 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(int stream_id)); | |
59 | |
60 protected: | |
61 virtual ~MockDemuxer() {} | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); | |
65 }; | |
66 | |
67 class MockDemuxerStream : public DemuxerStream { | |
68 public: | |
69 MockDemuxerStream() {} | |
70 | |
71 // DemuxerStream implementation. | |
72 MOCK_METHOD0(media_format, const MediaFormat&()); | |
73 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); | |
74 MOCK_METHOD1(QueryInterface, void*(const char* interface_id)); | |
75 | |
76 protected: | |
77 virtual ~MockDemuxerStream() {} | |
78 | |
79 private: | |
80 DISALLOW_COPY_AND_ASSIGN(MockDemuxerStream); | |
81 }; | |
82 | |
83 class MockVideoDecoder : public VideoDecoder { | |
84 public: | |
85 MockVideoDecoder() {} | |
86 | |
87 // MediaFilter implementation. | |
88 MOCK_METHOD0(Stop, void()); | |
89 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | |
90 MOCK_METHOD1(Seek, void(base::TimeDelta time)); | |
91 | |
92 // VideoDecoder implementation. | |
93 MOCK_METHOD1(Initialize, bool(DemuxerStream* demuxer_stream)); | |
94 MOCK_METHOD0(media_format, const MediaFormat&()); | |
95 MOCK_METHOD1(Read, void(Callback1<VideoFrame*>::Type* read_callback)); | |
96 | |
97 protected: | |
98 virtual ~MockVideoDecoder() {} | |
99 | |
100 private: | |
101 DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder); | |
102 }; | |
103 | |
104 class MockAudioDecoder : public AudioDecoder { | |
105 public: | |
106 MockAudioDecoder() {} | |
107 | |
108 // MediaFilter implementation. | |
109 MOCK_METHOD0(Stop, void()); | |
110 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | |
111 MOCK_METHOD1(Seek, void(base::TimeDelta time)); | |
112 | |
113 // AudioDecoder implementation. | |
114 MOCK_METHOD1(Initialize, bool(DemuxerStream* demuxer_stream)); | |
115 MOCK_METHOD0(media_format, const MediaFormat&()); | |
116 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); | |
117 | |
118 protected: | |
119 virtual ~MockAudioDecoder() {} | |
120 | |
121 private: | |
122 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); | |
123 }; | |
124 | |
125 class MockVideoRenderer : public VideoRenderer { | |
126 public: | |
127 MockVideoRenderer() {} | |
128 | |
129 // MediaFilter implementation. | |
130 MOCK_METHOD0(Stop, void()); | |
131 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | |
132 MOCK_METHOD1(Seek, void(base::TimeDelta time)); | |
133 | |
134 // VideoRenderer implementation. | |
135 MOCK_METHOD1(Initialize, bool(VideoDecoder* decoder)); | |
136 | |
137 protected: | |
138 virtual ~MockVideoRenderer() {} | |
139 | |
140 private: | |
141 DISALLOW_COPY_AND_ASSIGN(MockVideoRenderer); | |
142 }; | |
143 | |
144 class MockAudioRenderer : public AudioRenderer { | |
145 public: | |
146 MockAudioRenderer() {} | |
147 | |
148 // MediaFilter implementation. | |
149 MOCK_METHOD0(Stop, void()); | |
150 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | |
151 MOCK_METHOD1(Seek, void(base::TimeDelta time)); | |
152 | |
153 // AudioRenderer implementation. | |
154 MOCK_METHOD1(Initialize, bool(AudioDecoder* decoder)); | |
155 MOCK_METHOD1(SetVolume, void(float volume)); | |
156 | |
157 protected: | |
158 virtual ~MockAudioRenderer() {} | |
159 | |
160 private: | |
161 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderer); | |
162 }; | |
163 | |
164 // FilterFactory that returns canned instances of mock filters. You can set | |
165 // expectations on the filters and then pass the factory into a pipeline. | |
166 // | |
167 // TODO(scherkus): add the other filter types. | |
168 class MockFilterFactory : public FilterFactory { | |
awong
2009/07/08 22:06:03
Hmm...having a factory that holds mocks...this fee
scherkus (not reviewing)
2009/07/08 22:14:51
You got it. Normal filter pattern is to have the
| |
169 public: | |
170 MockFilterFactory() | |
171 : data_source_(new MockDataSource()), | |
172 demuxer_(new MockDemuxer()), | |
173 video_decoder_(new MockVideoDecoder()), | |
174 audio_decoder_(new MockAudioDecoder()), | |
175 video_renderer_(new MockVideoRenderer()), | |
176 audio_renderer_(new MockAudioRenderer()) { | |
177 } | |
178 | |
179 virtual ~MockFilterFactory() {} | |
180 | |
181 // Mock accessors. | |
182 MockDataSource* data_source() const { return data_source_; } | |
183 MockDemuxer* demuxer() const { return demuxer_; } | |
184 MockVideoDecoder* video_decoder() const { return video_decoder_; } | |
185 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } | |
186 MockVideoRenderer* video_renderer() const { return video_renderer_; } | |
187 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } | |
188 | |
189 protected: | |
190 MediaFilter* Create(FilterType filter_type, const MediaFormat& media_format) { | |
191 switch (filter_type) { | |
192 case FILTER_DATA_SOURCE: | |
193 return data_source_; | |
194 case FILTER_DEMUXER: | |
195 return demuxer_; | |
196 case FILTER_VIDEO_DECODER: | |
197 return video_decoder_; | |
198 case FILTER_AUDIO_DECODER: | |
199 return audio_decoder_; | |
200 case FILTER_VIDEO_RENDERER: | |
201 return video_renderer_; | |
202 case FILTER_AUDIO_RENDERER: | |
203 return audio_renderer_; | |
204 default: | |
205 NOTREACHED() << "Unknown filter type: " << filter_type; | |
206 } | |
207 return NULL; | |
208 } | |
209 | |
210 private: | |
211 scoped_refptr<MockDataSource> data_source_; | |
212 scoped_refptr<MockDemuxer> demuxer_; | |
213 scoped_refptr<MockVideoDecoder> video_decoder_; | |
214 scoped_refptr<MockAudioDecoder> audio_decoder_; | |
215 scoped_refptr<MockVideoRenderer> video_renderer_; | |
216 scoped_refptr<MockAudioRenderer> audio_renderer_; | |
217 | |
218 DISALLOW_COPY_AND_ASSIGN(MockFilterFactory); | |
219 }; | |
220 | |
46 } // namespace media | 221 } // namespace media |
47 | 222 |
48 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 223 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |