OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // 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. |
11 // http://code.google.com/p/googlemock/wiki/CookBook#Nice_Mocks_and_Strict_Mocks | 11 // http://code.google.com/p/googlemock/wiki/CookBook#Nice_Mocks_and_Strict_Mocks |
12 | 12 |
13 #ifndef MEDIA_BASE_MOCK_FILTERS_H_ | 13 #ifndef MEDIA_BASE_MOCK_FILTERS_H_ |
14 #define MEDIA_BASE_MOCK_FILTERS_H_ | 14 #define MEDIA_BASE_MOCK_FILTERS_H_ |
15 | 15 |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/callback.h" | 18 #include "base/callback.h" |
19 #include "media/base/factory.h" | 19 #include "media/base/factory.h" |
20 #include "media/base/filters.h" | 20 #include "media/base/filters.h" |
| 21 #include "media/base/video_frame.h" |
21 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
22 | 23 |
23 namespace media { | 24 namespace media { |
24 | 25 |
25 // Use this template to test for object destruction by setting expectations on | 26 // Use this template to test for object destruction by setting expectations on |
26 // the method OnDestroy(). | 27 // the method OnDestroy(). |
27 // | 28 // |
28 // TODO(scherkus): not sure about the naming... perhaps contribute this back | 29 // TODO(scherkus): not sure about the naming... perhaps contribute this back |
29 // to gmock itself! | 30 // to gmock itself! |
30 template<class MockClass> | 31 template<class MockClass> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // MediaFilter implementation. | 164 // MediaFilter implementation. |
164 MOCK_METHOD0(Stop, void()); | 165 MOCK_METHOD0(Stop, void()); |
165 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 166 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
166 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); | 167 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); |
167 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 168 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
168 | 169 |
169 // VideoDecoder implementation. | 170 // VideoDecoder implementation. |
170 MOCK_METHOD2(Initialize, void(DemuxerStream* stream, | 171 MOCK_METHOD2(Initialize, void(DemuxerStream* stream, |
171 FilterCallback* callback)); | 172 FilterCallback* callback)); |
172 MOCK_METHOD0(media_format, const MediaFormat&()); | 173 MOCK_METHOD0(media_format, const MediaFormat&()); |
173 MOCK_METHOD1(Read, void(Callback1<VideoFrame*>::Type* read_callback)); | 174 MOCK_METHOD1(FillThisBuffer, void(scoped_refptr<VideoFrame>)); |
174 | 175 |
175 protected: | 176 protected: |
176 virtual ~MockVideoDecoder() {} | 177 virtual ~MockVideoDecoder() {} |
177 | 178 |
178 private: | 179 private: |
179 DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder); | 180 DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder); |
180 }; | 181 }; |
181 | 182 |
182 class MockAudioDecoder : public AudioDecoder { | 183 class MockAudioDecoder : public AudioDecoder { |
183 public: | 184 public: |
184 MockAudioDecoder() {} | 185 MockAudioDecoder() {} |
185 | 186 |
186 // MediaFilter implementation. | 187 // MediaFilter implementation. |
187 MOCK_METHOD0(Stop, void()); | 188 MOCK_METHOD0(Stop, void()); |
188 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 189 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
189 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); | 190 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); |
190 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 191 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
191 | 192 |
192 // AudioDecoder implementation. | 193 // AudioDecoder implementation. |
193 MOCK_METHOD2(Initialize, void(DemuxerStream* stream, | 194 MOCK_METHOD2(Initialize, void(DemuxerStream* stream, |
194 FilterCallback* callback)); | 195 FilterCallback* callback)); |
195 MOCK_METHOD0(media_format, const MediaFormat&()); | 196 MOCK_METHOD0(media_format, const MediaFormat&()); |
196 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); | 197 MOCK_METHOD1(FillThisBuffer, void(scoped_refptr<Buffer>)); |
| 198 |
| 199 // change to public to allow unittest for access; |
| 200 FillBufferDoneCallback* fill_buffer_done_callback() { |
| 201 return AudioDecoder::fill_buffer_done_callback(); |
| 202 } |
197 | 203 |
198 protected: | 204 protected: |
199 virtual ~MockAudioDecoder() {} | 205 virtual ~MockAudioDecoder() {} |
200 | 206 |
201 private: | 207 private: |
202 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); | 208 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); |
203 }; | 209 }; |
204 | 210 |
205 class MockVideoRenderer : public VideoRenderer { | 211 class MockVideoRenderer : public VideoRenderer { |
206 public: | 212 public: |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 354 |
349 // Helper gmock action that calls DisableAudioRenderer() on behalf of the | 355 // Helper gmock action that calls DisableAudioRenderer() on behalf of the |
350 // provided filter. | 356 // provided filter. |
351 ACTION_P(DisableAudioRenderer, filter) { | 357 ACTION_P(DisableAudioRenderer, filter) { |
352 filter->host()->DisableAudioRenderer(); | 358 filter->host()->DisableAudioRenderer(); |
353 } | 359 } |
354 | 360 |
355 } // namespace media | 361 } // namespace media |
356 | 362 |
357 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 363 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |