OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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. | 6 // actions if you need interesting side-effects. |
7 // | 7 // |
8 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock | 8 // Don't forget you can use StrictMock<> and NiceMock<> if you want the mock |
9 // filters to fail the test or do nothing when an unexpected method is called. | 9 // filters to fail the test or do nothing when an unexpected method is called. |
10 // http://code.google.com/p/googlemock/wiki/CookBook#Nice_Mocks_and_Strict_Mocks | 10 // http://code.google.com/p/googlemock/wiki/CookBook#Nice_Mocks_and_Strict_Mocks |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 MockDemuxer(); | 58 MockDemuxer(); |
59 | 59 |
60 // Demuxer implementation. | 60 // Demuxer implementation. |
61 MOCK_METHOD2(Initialize, void(DemuxerHost* host, const PipelineStatusCB& cb)); | 61 MOCK_METHOD2(Initialize, void(DemuxerHost* host, const PipelineStatusCB& cb)); |
62 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 62 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
63 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); | 63 MOCK_METHOD2(Seek, void(base::TimeDelta time, const PipelineStatusCB& cb)); |
64 MOCK_METHOD1(Stop, void(const base::Closure& callback)); | 64 MOCK_METHOD1(Stop, void(const base::Closure& callback)); |
65 MOCK_METHOD0(OnAudioRendererDisabled, void()); | 65 MOCK_METHOD0(OnAudioRendererDisabled, void()); |
66 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); | 66 MOCK_METHOD1(GetStream, scoped_refptr<DemuxerStream>(DemuxerStream::Type)); |
67 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); | 67 MOCK_CONST_METHOD0(GetStartTime, base::TimeDelta()); |
68 MOCK_METHOD0(GetBitrate, int()); | |
69 | 68 |
70 protected: | 69 protected: |
71 virtual ~MockDemuxer(); | 70 virtual ~MockDemuxer(); |
72 | 71 |
73 private: | 72 private: |
74 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); | 73 DISALLOW_COPY_AND_ASSIGN(MockDemuxer); |
75 }; | 74 }; |
76 | 75 |
77 class MockDemuxerStream : public DemuxerStream { | 76 class MockDemuxerStream : public DemuxerStream { |
78 public: | 77 public: |
79 MockDemuxerStream(); | 78 MockDemuxerStream(); |
80 | 79 |
81 // DemuxerStream implementation. | 80 // DemuxerStream implementation. |
82 MOCK_METHOD0(type, Type()); | 81 MOCK_METHOD0(type, Type()); |
83 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); | 82 MOCK_METHOD1(Read, void(const ReadCB& read_cb)); |
84 MOCK_METHOD0(audio_decoder_config, const AudioDecoderConfig&()); | 83 MOCK_METHOD0(audio_decoder_config, const AudioDecoderConfig&()); |
85 MOCK_METHOD0(video_decoder_config, const VideoDecoderConfig&()); | 84 MOCK_METHOD0(video_decoder_config, const VideoDecoderConfig&()); |
86 MOCK_METHOD0(EnableBitstreamConverter, void()); | 85 MOCK_METHOD0(EnableBitstreamConverter, void()); |
87 MOCK_METHOD0(GetBufferedRanges, Ranges<base::TimeDelta>()); | |
88 | 86 |
89 protected: | 87 protected: |
90 virtual ~MockDemuxerStream(); | 88 virtual ~MockDemuxerStream(); |
91 | 89 |
92 private: | 90 private: |
93 DISALLOW_COPY_AND_ASSIGN(MockDemuxerStream); | 91 DISALLOW_COPY_AND_ASSIGN(MockDemuxerStream); |
94 }; | 92 }; |
95 | 93 |
96 class MockVideoDecoder : public VideoDecoder { | 94 class MockVideoDecoder : public VideoDecoder { |
97 public: | 95 public: |
(...skipping 18 matching lines...) Expand all Loading... |
116 | 114 |
117 class MockAudioDecoder : public AudioDecoder { | 115 class MockAudioDecoder : public AudioDecoder { |
118 public: | 116 public: |
119 MockAudioDecoder(); | 117 MockAudioDecoder(); |
120 | 118 |
121 // AudioDecoder implementation. | 119 // AudioDecoder implementation. |
122 MOCK_METHOD3(Initialize, void(const scoped_refptr<DemuxerStream>&, | 120 MOCK_METHOD3(Initialize, void(const scoped_refptr<DemuxerStream>&, |
123 const PipelineStatusCB&, | 121 const PipelineStatusCB&, |
124 const StatisticsCB&)); | 122 const StatisticsCB&)); |
125 MOCK_METHOD1(Read, void(const ReadCB&)); | 123 MOCK_METHOD1(Read, void(const ReadCB&)); |
126 MOCK_METHOD1(ProduceAudioSamples, void(scoped_refptr<Buffer>)); | |
127 MOCK_METHOD0(bits_per_channel, int(void)); | 124 MOCK_METHOD0(bits_per_channel, int(void)); |
128 MOCK_METHOD0(channel_layout, ChannelLayout(void)); | 125 MOCK_METHOD0(channel_layout, ChannelLayout(void)); |
129 MOCK_METHOD0(samples_per_second, int(void)); | 126 MOCK_METHOD0(samples_per_second, int(void)); |
130 MOCK_METHOD1(Reset, void(const base::Closure&)); | 127 MOCK_METHOD1(Reset, void(const base::Closure&)); |
131 | 128 |
132 protected: | 129 protected: |
133 virtual ~MockAudioDecoder(); | 130 virtual ~MockAudioDecoder(); |
134 | 131 |
135 private: | 132 private: |
136 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); | 133 DISALLOW_COPY_AND_ASSIGN(MockAudioDecoder); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 scoped_refptr<MockAudioRenderer> audio_renderer_; | 275 scoped_refptr<MockAudioRenderer> audio_renderer_; |
279 | 276 |
280 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); | 277 DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); |
281 }; | 278 }; |
282 | 279 |
283 // Helper gmock action that calls SetError() on behalf of the provided filter. | 280 // Helper gmock action that calls SetError() on behalf of the provided filter. |
284 ACTION_P2(SetError, filter, error) { | 281 ACTION_P2(SetError, filter, error) { |
285 filter->host()->SetError(error); | 282 filter->host()->SetError(error); |
286 } | 283 } |
287 | 284 |
288 // Helper gmock action that calls SetDuration() on behalf of the provided | |
289 // filter. | |
290 ACTION_P2(SetDuration, filter, duration) { | |
291 filter->host()->SetDuration(duration); | |
292 } | |
293 | |
294 ACTION(RunClosure) { | 285 ACTION(RunClosure) { |
295 arg0.Run(); | 286 arg0.Run(); |
296 } | 287 } |
297 | 288 |
298 // Helper mock statistics callback. | 289 // Helper mock statistics callback. |
299 class MockStatisticsCB { | 290 class MockStatisticsCB { |
300 public: | 291 public: |
301 MockStatisticsCB(); | 292 MockStatisticsCB(); |
302 ~MockStatisticsCB(); | 293 ~MockStatisticsCB(); |
303 | 294 |
304 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); | 295 MOCK_METHOD1(OnStatistics, void(const media::PipelineStatistics& statistics)); |
305 }; | 296 }; |
306 | 297 |
307 } // namespace media | 298 } // namespace media |
308 | 299 |
309 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 300 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
OLD | NEW |