| 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. |
| 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> |
| 17 |
| 16 #include "media/base/factory.h" | 18 #include "media/base/factory.h" |
| 17 #include "media/base/filters.h" | 19 #include "media/base/filters.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 | 21 |
| 20 namespace media { | 22 namespace media { |
| 21 | 23 |
| 22 // Use this template to test for object destruction by setting expectations on | 24 // Use this template to test for object destruction by setting expectations on |
| 23 // the method OnDestroy(). | 25 // the method OnDestroy(). |
| 24 // | 26 // |
| 25 // TODO(scherkus): not sure about the naming... perhaps contribute this back | 27 // TODO(scherkus): not sure about the naming... perhaps contribute this back |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // test. | 60 // test. |
| 59 FilterCallback* NewCallback() { | 61 FilterCallback* NewCallback() { |
| 60 return new CallbackImpl(this); | 62 return new CallbackImpl(this); |
| 61 } | 63 } |
| 62 | 64 |
| 63 private: | 65 private: |
| 64 // Private implementation of CallbackRunner used to trigger expectations on | 66 // Private implementation of CallbackRunner used to trigger expectations on |
| 65 // MockFilterCallback. | 67 // MockFilterCallback. |
| 66 class CallbackImpl : public CallbackRunner<Tuple0> { | 68 class CallbackImpl : public CallbackRunner<Tuple0> { |
| 67 public: | 69 public: |
| 68 CallbackImpl(MockFilterCallback* mock_callback) | 70 explicit CallbackImpl(MockFilterCallback* mock_callback) |
| 69 : mock_callback_(mock_callback) { | 71 : mock_callback_(mock_callback) { |
| 70 } | 72 } |
| 71 | 73 |
| 72 virtual ~CallbackImpl() { | 74 virtual ~CallbackImpl() { |
| 73 mock_callback_->OnCallbackDestroyed(); | 75 mock_callback_->OnCallbackDestroyed(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 virtual void RunWithParams(const Tuple0& params) { | 78 virtual void RunWithParams(const Tuple0& params) { |
| 77 mock_callback_->OnFilterCallback(); | 79 mock_callback_->OnFilterCallback(); |
| 78 } | 80 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 private: | 189 private: |
| 188 MediaFormat media_format_; | 190 MediaFormat media_format_; |
| 189 | 191 |
| 190 DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder); | 192 DISALLOW_COPY_AND_ASSIGN(MockVideoDecoder); |
| 191 }; | 193 }; |
| 192 | 194 |
| 193 class MockAudioDecoder : public AudioDecoder { | 195 class MockAudioDecoder : public AudioDecoder { |
| 194 public: | 196 public: |
| 195 MockAudioDecoder() {} | 197 MockAudioDecoder() {} |
| 196 | 198 |
| 199 // Sets the essential media format keys for this decoder. |
| 200 MockAudioDecoder(int channels, int sample_rate, int sample_bits) { |
| 201 media_format_.SetAsString(MediaFormat::kMimeType, |
| 202 mime_type::kUncompressedAudio); |
| 203 media_format_.SetAsInteger(MediaFormat::kChannels, channels); |
| 204 media_format_.SetAsInteger(MediaFormat::kSampleRate, sample_rate); |
| 205 media_format_.SetAsInteger(MediaFormat::kSampleBits, sample_bits); |
| 206 } |
| 207 |
| 197 // MediaFilter implementation. | 208 // MediaFilter implementation. |
| 198 MOCK_METHOD0(Stop, void()); | 209 MOCK_METHOD0(Stop, void()); |
| 199 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); | 210 MOCK_METHOD1(SetPlaybackRate, void(float playback_rate)); |
| 200 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); | 211 MOCK_METHOD2(Seek, void(base::TimeDelta time, FilterCallback* callback)); |
| 201 | 212 |
| 202 // AudioDecoder implementation. | 213 // AudioDecoder implementation. |
| 203 MOCK_METHOD2(Initialize, void(DemuxerStream* stream, | 214 MOCK_METHOD2(Initialize, void(DemuxerStream* stream, |
| 204 FilterCallback* callback)); | 215 FilterCallback* callback)); |
| 205 const MediaFormat& media_format() { return media_format_; } | 216 const MediaFormat& media_format() { return media_format_; } |
| 206 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); | 217 MOCK_METHOD1(Read, void(Callback1<Buffer*>::Type* read_callback)); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 361 |
| 351 // Helper gmock action that calls SetBufferedBytes() on behalf of the provided | 362 // Helper gmock action that calls SetBufferedBytes() on behalf of the provided |
| 352 // filter. | 363 // filter. |
| 353 ACTION_P2(SetBufferedBytes, filter, bytes) { | 364 ACTION_P2(SetBufferedBytes, filter, bytes) { |
| 354 filter->host()->SetBufferedBytes(bytes); | 365 filter->host()->SetBufferedBytes(bytes); |
| 355 } | 366 } |
| 356 | 367 |
| 357 } // namespace media | 368 } // namespace media |
| 358 | 369 |
| 359 #endif // MEDIA_BASE_MOCK_FILTERS_H_ | 370 #endif // MEDIA_BASE_MOCK_FILTERS_H_ |
| OLD | NEW |