Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); | 57 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); |
| 58 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 58 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
| 59 | 59 |
| 60 protected: | 60 protected: |
| 61 virtual ~MockFilter(); | 61 virtual ~MockFilter(); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(MockFilter); | 64 DISALLOW_COPY_AND_ASSIGN(MockFilter); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class MockDataSource : public DataSource { | 67 class MockDataSource : public DataSource { |
|
acolwell GONE FROM CHROMIUM
2011/03/08 21:48:09
Can we remove MockDataSource?
Ami GONE FROM CHROMIUM
2011/03/08 22:44:48
No, b/c ffmpeg_demuxer_unittest.cc uses it.
acolwell GONE FROM CHROMIUM
2011/03/08 23:19:00
ok. Just checking.
On 2011/03/08 22:44:48, fischm
| |
| 68 public: | 68 public: |
| 69 MockDataSource(); | 69 MockDataSource(); |
| 70 | 70 |
| 71 // Filter implementation. | 71 // Filter implementation. |
| 72 virtual void set_host(FilterHost* host); | 72 virtual void set_host(FilterHost* host); |
| 73 | 73 |
| 74 MOCK_METHOD1(Stop, void(FilterCallback* callback)); | 74 MOCK_METHOD1(Stop, void(FilterCallback* callback)); |
| 75 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 75 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
| 76 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); | 76 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); |
| 77 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 77 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
| (...skipping 12 matching lines...) Expand all 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 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 | |
| 140 class MockDemuxerStream : public DemuxerStream { | 150 class MockDemuxerStream : public DemuxerStream { |
| 141 public: | 151 public: |
| 142 MockDemuxerStream(); | 152 MockDemuxerStream(); |
| 143 | 153 |
| 144 // DemuxerStream implementation. | 154 // DemuxerStream implementation. |
| 145 MOCK_METHOD0(media_format, const MediaFormat&()); | 155 MOCK_METHOD0(media_format, const MediaFormat&()); |
| 146 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); | 156 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); |
| 147 MOCK_METHOD1(QueryInterface, void*(const char* interface_id)); | 157 MOCK_METHOD1(QueryInterface, void*(const char* interface_id)); |
| 148 MOCK_METHOD0(EnableBitstreamConverter, void()); | 158 MOCK_METHOD0(EnableBitstreamConverter, void()); |
| 149 | 159 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 }; | 273 }; |
| 264 | 274 |
| 265 // FilterFactory that returns canned instances of mock filters. You can set | 275 // FilterFactory that returns canned instances of mock filters. You can set |
| 266 // expectations on the filters and then pass the collection into a pipeline. | 276 // expectations on the filters and then pass the collection into a pipeline. |
| 267 class MockFilterCollection { | 277 class MockFilterCollection { |
| 268 public: | 278 public: |
| 269 MockFilterCollection(); | 279 MockFilterCollection(); |
| 270 virtual ~MockFilterCollection(); | 280 virtual ~MockFilterCollection(); |
| 271 | 281 |
| 272 // Mock accessors. | 282 // Mock accessors. |
| 273 MockDataSource* data_source() const { return data_source_; } | |
| 274 MockDemuxer* demuxer() const { return demuxer_; } | 283 MockDemuxer* demuxer() const { return demuxer_; } |
| 275 MockVideoDecoder* video_decoder() const { return video_decoder_; } | 284 MockVideoDecoder* video_decoder() const { return video_decoder_; } |
| 276 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } | 285 MockAudioDecoder* audio_decoder() const { return audio_decoder_; } |
| 277 MockVideoRenderer* video_renderer() const { return video_renderer_; } | 286 MockVideoRenderer* video_renderer() const { return video_renderer_; } |
| 278 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } | 287 MockAudioRenderer* audio_renderer() const { return audio_renderer_; } |
| 279 | 288 |
| 280 FilterCollection* filter_collection() const { | 289 FilterCollection* filter_collection() const { |
| 281 return filter_collection(true, true, PIPELINE_OK); | 290 return filter_collection(true, true, PIPELINE_OK); |
| 282 } | 291 } |
| 283 | 292 |
| 284 FilterCollection* filter_collection(bool include_data_source, | 293 FilterCollection* filter_collection(bool include_demuxer, |
| 285 bool run_build_callback, | 294 bool run_build_callback, |
| 286 PipelineError build_error) const; | 295 PipelineError build_error) const; |
| 287 | 296 |
| 288 private: | 297 private: |
| 289 scoped_refptr<MockDataSource> data_source_; | |
| 290 scoped_refptr<MockDemuxer> demuxer_; | 298 scoped_refptr<MockDemuxer> demuxer_; |
| 291 scoped_refptr<MockVideoDecoder> video_decoder_; | 299 scoped_refptr<MockVideoDecoder> video_decoder_; |
| 292 scoped_refptr<MockAudioDecoder> audio_decoder_; | 300 scoped_refptr<MockAudioDecoder> audio_decoder_; |
| 293 scoped_refptr<MockVideoRenderer> video_renderer_; | 301 scoped_refptr<MockVideoRenderer> video_renderer_; |
| 294 scoped_refptr<MockAudioRenderer> audio_renderer_; | 302 scoped_refptr<MockAudioRenderer> audio_renderer_; |
| 295 | 303 |
| 296 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); | 304 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); |
| 297 }; | 305 }; |
| 298 | 306 |
| 299 // Helper gmock functions that immediately executes and destroys the | 307 // Helper gmock functions that immediately executes and destroys the |
| 300 // FilterCallback on behalf of the provided filter. Can be used when mocking | 308 // FilterCallback on behalf of the provided filter. Can be used when mocking |
| 301 // the Initialize() and Seek() methods. | 309 // the Initialize() and Seek() methods. |
| 302 void RunFilterCallback(::testing::Unused, FilterCallback* callback); | 310 void RunFilterCallback(::testing::Unused, FilterCallback* callback); |
| 311 void RunPipelineStatusCallback(PipelineError status, | |
| 312 PipelineStatusCallback* callback); | |
| 303 void RunFilterCallback3(::testing::Unused, FilterCallback* callback, | 313 void RunFilterCallback3(::testing::Unused, FilterCallback* callback, |
| 304 ::testing::Unused); | 314 ::testing::Unused); |
| 305 | 315 |
| 306 // Helper gmock function that immediately destroys the FilterCallback on behalf | 316 // Helper gmock function that immediately destroys the FilterCallback on behalf |
| 307 // of the provided filter. Can be used when mocking the Initialize() and Seek() | 317 // of the provided filter. Can be used when mocking the Initialize() and Seek() |
| 308 // methods. | 318 // methods. |
| 309 void DestroyFilterCallback(::testing::Unused, FilterCallback* callback); | 319 void DestroyFilterCallback(::testing::Unused, FilterCallback* callback); |
| 310 | 320 |
| 311 // Helper gmock function that immediately executes and destroys the | 321 // Helper gmock function that immediately executes and destroys the |
| 312 // FilterCallback on behalf of the provided filter. Can be used when mocking | 322 // FilterCallback on behalf of the provided filter. Can be used when mocking |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 335 public: | 345 public: |
| 336 MockStatisticsCallback(); | 346 MockStatisticsCallback(); |
| 337 ~MockStatisticsCallback(); | 347 ~MockStatisticsCallback(); |
| 338 | 348 |
| 339 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 349 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
| 340 }; | 350 }; |
| 341 | 351 |
| 342 } // namespace media | 352 } // namespace media |
| 343 | 353 |
| 344 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 354 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
| OLD | NEW |