OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 protected: | 90 protected: |
91 virtual ~MockDataSource(); | 91 virtual ~MockDataSource(); |
92 | 92 |
93 private: | 93 private: |
94 int64 total_bytes_; | 94 int64 total_bytes_; |
95 int64 buffered_bytes_; | 95 int64 buffered_bytes_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(MockDataSource); | 97 DISALLOW_COPY_AND_ASSIGN(MockDataSource); |
98 }; | 98 }; |
99 | 99 |
100 class MockDataSourceFactory : public DataSourceFactory { | |
101 public: | |
102 MockDataSourceFactory(MockDataSource* data_source); | |
103 | |
104 void SetError(PipelineError error); | |
105 void RunBuildCallback(const std::string& url, BuildCallback* callback); | |
106 void DestroyBuildCallback(const std::string& url, BuildCallback* callback); | |
107 | |
108 // DataSourceFactory methods. | |
109 MOCK_METHOD2(Build, void(const std::string& url, BuildCallback* callback)); | |
110 virtual DataSourceFactory* Clone() const; | |
111 | |
112 private: | |
113 scoped_refptr<MockDataSource> data_source_; | |
114 PipelineError error_; | |
115 }; | |
116 | |
117 class MockDemuxer : public Demuxer { | 100 class MockDemuxer : public Demuxer { |
118 public: | 101 public: |
119 MockDemuxer(); | 102 MockDemuxer(); |
120 | |
121 // Filter implementation. | 103 // Filter implementation. |
| 104 virtual void set_host(FilterHost* host); |
122 MOCK_METHOD1(Stop, void(FilterCallback* callback)); | 105 MOCK_METHOD1(Stop, void(FilterCallback* callback)); |
123 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 106 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
124 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); | 107 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); |
125 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 108 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
126 | 109 |
127 // Demuxer implementation. | 110 // Demuxer implementation. |
128 MOCK_METHOD2(Initialize, void(DataSource* data_source, | 111 MOCK_METHOD2(Initialize, void(DataSource* data_source, |
129 FilterCallback* callback)); | 112 FilterCallback* callback)); |
130 MOCK_METHOD0(GetNumberOfStreams, size_t()); | 113 MOCK_METHOD0(GetNumberOfStreams, size_t()); |
131 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(int stream_id)); | 114 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(int stream_id)); |
132 | 115 |
| 116 // Sets the TotalBytes, BufferedBytes, & Duration values to be sent to host() |
| 117 // when set_host() is called. |
| 118 void SetTotalAndBufferedBytesAndDuration( |
| 119 int64 total_bytes, int64 buffered_bytes, const base::TimeDelta& duration); |
| 120 |
133 protected: | 121 protected: |
134 virtual ~MockDemuxer(); | 122 virtual ~MockDemuxer(); |
135 | 123 |
136 private: | 124 private: |
| 125 int64 total_bytes_; |
| 126 int64 buffered_bytes_; |
| 127 base::TimeDelta duration_; |
| 128 |
137 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); | 129 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); |
138 }; | 130 }; |
139 | 131 |
| 132 class MockDemuxerFactory : public DemuxerFactory { |
| 133 public: |
| 134 explicit MockDemuxerFactory(MockDemuxer* demuxer); |
| 135 virtual ~MockDemuxerFactory(); |
| 136 |
| 137 void SetError(PipelineError error); |
| 138 void RunBuildCallback(const std::string& url, BuildCallback* callback); |
| 139 void DestroyBuildCallback(const std::string& url, BuildCallback* callback); |
| 140 |
| 141 // DemuxerFactory methods. |
| 142 MOCK_METHOD2(Build, void(const std::string& url, BuildCallback* callback)); |
| 143 virtual DemuxerFactory* Clone() const; |
| 144 |
| 145 private: |
| 146 scoped_refptr<MockDemuxer> demuxer_; |
| 147 PipelineError error_; |
| 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(MockDemuxerFactory); |
| 150 }; |
| 151 |
140 class MockDemuxerStream : public DemuxerStream { | 152 class MockDemuxerStream : public DemuxerStream { |
141 public: | 153 public: |
142 MockDemuxerStream(); | 154 MockDemuxerStream(); |
143 | 155 |
144 // DemuxerStream implementation. | 156 // DemuxerStream implementation. |
145 MOCK_METHOD0(media_format, const MediaFormat&()); | 157 MOCK_METHOD0(media_format, const MediaFormat&()); |
146 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); | 158 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); |
147 MOCK_METHOD1(QueryInterface, void*(const char* interface_id)); | 159 MOCK_METHOD1(QueryInterface, void*(const char* interface_id)); |
148 MOCK_METHOD0(EnableBitstreamConverter, void()); | 160 MOCK_METHOD0(EnableBitstreamConverter, void()); |
149 | 161 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 }; | 275 }; |
264 | 276 |
265 // FilterFactory that returns canned instances of mock filters. You can set | 277 // FilterFactory that returns canned instances of mock filters. You can set |
266 // expectations on the filters and then pass the collection into a pipeline. | 278 // expectations on the filters and then pass the collection into a pipeline. |
267 class MockFilterCollection { | 279 class MockFilterCollection { |
268 public: | 280 public: |
269 MockFilterCollection(); | 281 MockFilterCollection(); |
270 virtual ~MockFilterCollection(); | 282 virtual ~MockFilterCollection(); |
271 | 283 |
272 // Mock accessors. | 284 // Mock accessors. |
273 MockDataSource* data_source() const { return data_source_; } | |
274 MockDemuxer* demuxer() const { return demuxer_; } | 285 MockDemuxer* demuxer() const { return demuxer_; } |
275 MockVideoDecoder* video_decoder() const { return video_decoder_; } | 286 MockVideoDecoder* video_decoder() const { return video_decoder_; } |
276 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } | 287 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } |
277 MockVideoRenderer* video_renderer() const { return video_renderer_; } | 288 MockVideoRenderer* video_renderer() const { return video_renderer_; } |
278 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } | 289 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } |
279 | 290 |
280 FilterCollection* filter_collection() const { | 291 FilterCollection* filter_collection() const { |
281 return filter_collection(true, true, PIPELINE_OK); | 292 return filter_collection(true, true, PIPELINE_OK); |
282 } | 293 } |
283 | 294 |
284 FilterCollection* filter_collection(bool include_data_source, | 295 FilterCollection* filter_collection(bool include_demuxer, |
285 bool run_build_callback, | 296 bool run_build_callback, |
286 PipelineError build_error) const; | 297 PipelineError build_error) const; |
287 | 298 |
288 private: | 299 private: |
289 scoped_refptr<MockDataSource> data_source_; | |
290 scoped_refptr<MockDemuxer> demuxer_; | 300 scoped_refptr<MockDemuxer> demuxer_; |
291 scoped_refptr<MockVideoDecoder> video_decoder_; | 301 scoped_refptr<MockVideoDecoder> video_decoder_; |
292 scoped_refptr<MockAudioDecoder> audio_decoder_; | 302 scoped_refptr<MockAudioDecoder> audio_decoder_; |
293 scoped_refptr<MockVideoRenderer> video_renderer_; | 303 scoped_refptr<MockVideoRenderer> video_renderer_; |
294 scoped_refptr<MockAudioRenderer> audio_renderer_; | 304 scoped_refptr<MockAudioRenderer> audio_renderer_; |
295 | 305 |
296 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); | 306 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); |
297 }; | 307 }; |
298 | 308 |
299 // Helper gmock functions that immediately executes and destroys the | 309 // Helper gmock functions that immediately executes and destroys the |
300 // FilterCallback on behalf of the provided filter. Can be used when mocking | 310 // FilterCallback on behalf of the provided filter. Can be used when mocking |
301 // the Initialize() and Seek() methods. | 311 // the Initialize() and Seek() methods. |
302 void RunFilterCallback(::testing::Unused, FilterCallback* callback); | 312 void RunFilterCallback(::testing::Unused, FilterCallback* callback); |
| 313 void RunPipelineStatusCallback(PipelineError status, |
| 314 PipelineStatusCallback* callback); |
303 void RunFilterCallback3(::testing::Unused, FilterCallback* callback, | 315 void RunFilterCallback3(::testing::Unused, FilterCallback* callback, |
304 ::testing::Unused); | 316 ::testing::Unused); |
305 | 317 |
306 // Helper gmock function that immediately destroys the FilterCallback on behalf | 318 // Helper gmock function that immediately destroys the FilterCallback on behalf |
307 // of the provided filter. Can be used when mocking the Initialize() and Seek() | 319 // of the provided filter. Can be used when mocking the Initialize() and Seek() |
308 // methods. | 320 // methods. |
309 void DestroyFilterCallback(::testing::Unused, FilterCallback* callback); | 321 void DestroyFilterCallback(::testing::Unused, FilterCallback* callback); |
310 | 322 |
311 // Helper gmock function that immediately executes and destroys the | 323 // Helper gmock function that immediately executes and destroys the |
312 // FilterCallback on behalf of the provided filter. Can be used when mocking | 324 // FilterCallback on behalf of the provided filter. Can be used when mocking |
(...skipping 22 matching lines...) Expand all Loading... |
335 public: | 347 public: |
336 MockStatisticsCallback(); | 348 MockStatisticsCallback(); |
337 ~MockStatisticsCallback(); | 349 ~MockStatisticsCallback(); |
338 | 350 |
339 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 351 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
340 }; | 352 }; |
341 | 353 |
342 } // namespace media | 354 } // namespace media |
343 | 355 |
344 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 356 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |