kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef TEST_MOCK_AUDIO_DECODER_FACTORY_H_ |
| 12 | #define TEST_MOCK_AUDIO_DECODER_FACTORY_H_ |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 13 | |
kwiberg | 37e99fd | 2017-04-10 12:15:48 | [diff] [blame] | 14 | #include <memory> |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 17 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 18 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 20 | #include "rtc_base/ref_counted_object.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "test/gmock.h" |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | class MockAudioDecoderFactory : public AudioDecoderFactory { |
| 26 | public: |
ossu | d4e9f62 | 2016-08-18 09:01:17 | [diff] [blame] | 27 | MOCK_METHOD0(GetSupportedDecoders, std::vector<AudioCodecSpec>()); |
kwiberg | d32bf75 | 2017-01-19 15:03:59 | [diff] [blame] | 28 | MOCK_METHOD1(IsSupportedDecoder, bool(const SdpAudioFormat&)); |
Karl Wiberg | d6fbf2a | 2018-02-27 12:37:31 | [diff] [blame] | 29 | std::unique_ptr<AudioDecoder> MakeAudioDecoder( |
| 30 | const SdpAudioFormat& format, |
Danil Chapovalov | 431abd9 | 2018-06-18 10:54:17 | [diff] [blame] | 31 | absl::optional<AudioCodecPairId> codec_pair_id) { |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 32 | std::unique_ptr<AudioDecoder> return_value; |
Karl Wiberg | d6fbf2a | 2018-02-27 12:37:31 | [diff] [blame] | 33 | MakeAudioDecoderMock(format, codec_pair_id, &return_value); |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 34 | return return_value; |
| 35 | } |
Karl Wiberg | d6fbf2a | 2018-02-27 12:37:31 | [diff] [blame] | 36 | MOCK_METHOD3(MakeAudioDecoderMock, |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 37 | void(const SdpAudioFormat& format, |
Danil Chapovalov | 431abd9 | 2018-06-18 10:54:17 | [diff] [blame] | 38 | absl::optional<AudioCodecPairId> codec_pair_id, |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 39 | std::unique_ptr<AudioDecoder>* return_value)); |
ossu | c54071d | 2016-08-17 09:45:41 | [diff] [blame] | 40 | |
| 41 | // Creates a MockAudioDecoderFactory with no formats and that may not be |
| 42 | // invoked to create a codec - useful for initializing a voice engine, for |
| 43 | // example. |
| 44 | static rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> |
| 45 | CreateUnusedFactory() { |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 46 | using ::testing::_; |
| 47 | using ::testing::AnyNumber; |
| 48 | using ::testing::Return; |
ossu | c54071d | 2016-08-17 09:45:41 | [diff] [blame] | 49 | |
| 50 | rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory = |
| 51 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; |
ossu | d4e9f62 | 2016-08-18 09:01:17 | [diff] [blame] | 52 | ON_CALL(*factory.get(), GetSupportedDecoders()) |
| 53 | .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>())); |
| 54 | EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber()); |
kwiberg | d32bf75 | 2017-01-19 15:03:59 | [diff] [blame] | 55 | ON_CALL(*factory, IsSupportedDecoder(_)).WillByDefault(Return(false)); |
| 56 | EXPECT_CALL(*factory, IsSupportedDecoder(_)).Times(AnyNumber()); |
Karl Wiberg | d6fbf2a | 2018-02-27 12:37:31 | [diff] [blame] | 57 | EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _, _)).Times(0); |
ossu | c54071d | 2016-08-17 09:45:41 | [diff] [blame] | 58 | return factory; |
| 59 | } |
| 60 | |
| 61 | // Creates a MockAudioDecoderFactory with no formats that may be invoked to |
| 62 | // create a codec any number of times. It will, though, return nullptr on each |
| 63 | // call, since it supports no codecs. |
| 64 | static rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> |
| 65 | CreateEmptyFactory() { |
Mirko Bonadei | 6a489f2 | 2019-04-09 13:11:12 | [diff] [blame] | 66 | using ::testing::_; |
| 67 | using ::testing::AnyNumber; |
| 68 | using ::testing::Return; |
| 69 | using ::testing::SetArgPointee; |
ossu | c54071d | 2016-08-17 09:45:41 | [diff] [blame] | 70 | |
| 71 | rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> factory = |
| 72 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>; |
ossu | d4e9f62 | 2016-08-18 09:01:17 | [diff] [blame] | 73 | ON_CALL(*factory.get(), GetSupportedDecoders()) |
| 74 | .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>())); |
| 75 | EXPECT_CALL(*factory.get(), GetSupportedDecoders()).Times(AnyNumber()); |
kwiberg | d32bf75 | 2017-01-19 15:03:59 | [diff] [blame] | 76 | ON_CALL(*factory, IsSupportedDecoder(_)).WillByDefault(Return(false)); |
| 77 | EXPECT_CALL(*factory, IsSupportedDecoder(_)).Times(AnyNumber()); |
Karl Wiberg | d6fbf2a | 2018-02-27 12:37:31 | [diff] [blame] | 78 | ON_CALL(*factory.get(), MakeAudioDecoderMock(_, _, _)) |
| 79 | .WillByDefault(SetArgPointee<2>(nullptr)); |
| 80 | EXPECT_CALL(*factory.get(), MakeAudioDecoderMock(_, _, _)) |
| 81 | .Times(AnyNumber()); |
ossu | c54071d | 2016-08-17 09:45:41 | [diff] [blame] | 82 | return factory; |
| 83 | } |
kwiberg | 5178ee8 | 2016-05-03 08:39:01 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace webrtc |
| 87 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 88 | #endif // TEST_MOCK_AUDIO_DECODER_FACTORY_H_ |