ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef TEST_MOCK_AUDIO_ENCODER_FACTORY_H_ |
| 12 | #define TEST_MOCK_AUDIO_ENCODER_FACTORY_H_ |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/audio_codecs/audio_encoder_factory.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 18 | #include "api/scoped_refptr.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 19 | #include "rtc_base/ref_counted_object.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "test/gmock.h" |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 24 | class MockAudioEncoderFactory |
| 25 | : public ::testing::NiceMock<AudioEncoderFactory> { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 26 | public: |
| 27 | MOCK_METHOD0(GetSupportedEncoders, std::vector<AudioCodecSpec>()); |
| 28 | MOCK_METHOD1(QueryAudioEncoder, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 29 | absl::optional<AudioCodecInfo>(const SdpAudioFormat& format)); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 30 | |
Karl Wiberg | d6fbf2a | 2018-02-27 13:37:31 +0100 | [diff] [blame] | 31 | std::unique_ptr<AudioEncoder> MakeAudioEncoder( |
| 32 | int payload_type, |
| 33 | const SdpAudioFormat& format, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 34 | absl::optional<AudioCodecPairId> codec_pair_id) { |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 35 | std::unique_ptr<AudioEncoder> return_value; |
Karl Wiberg | d6fbf2a | 2018-02-27 13:37:31 +0100 | [diff] [blame] | 36 | MakeAudioEncoderMock(payload_type, format, codec_pair_id, &return_value); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 37 | return return_value; |
| 38 | } |
Karl Wiberg | d6fbf2a | 2018-02-27 13:37:31 +0100 | [diff] [blame] | 39 | MOCK_METHOD4(MakeAudioEncoderMock, |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 40 | void(int payload_type, |
| 41 | const SdpAudioFormat& format, |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 42 | absl::optional<AudioCodecPairId> codec_pair_id, |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 43 | std::unique_ptr<AudioEncoder>* return_value)); |
| 44 | |
| 45 | // Creates a MockAudioEncoderFactory with no formats and that may not be |
| 46 | // invoked to create a codec - useful for initializing a voice engine, for |
| 47 | // example. |
| 48 | static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> |
| 49 | CreateUnusedFactory() { |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 50 | using ::testing::_; |
| 51 | using ::testing::AnyNumber; |
| 52 | using ::testing::Return; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 53 | |
| 54 | rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory = |
| 55 | new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>; |
| 56 | ON_CALL(*factory.get(), GetSupportedEncoders()) |
| 57 | .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>())); |
| 58 | ON_CALL(*factory.get(), QueryAudioEncoder(_)) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 59 | .WillByDefault(Return(absl::nullopt)); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 60 | |
| 61 | EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber()); |
| 62 | EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber()); |
Karl Wiberg | d6fbf2a | 2018-02-27 13:37:31 +0100 | [diff] [blame] | 63 | EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)).Times(0); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 64 | return factory; |
| 65 | } |
| 66 | |
| 67 | // Creates a MockAudioEncoderFactory with no formats that may be invoked to |
| 68 | // create a codec any number of times. It will, though, return nullptr on each |
| 69 | // call, since it supports no codecs. |
| 70 | static rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> |
| 71 | CreateEmptyFactory() { |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 72 | using ::testing::_; |
| 73 | using ::testing::AnyNumber; |
| 74 | using ::testing::Return; |
| 75 | using ::testing::SetArgPointee; |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 76 | |
| 77 | rtc::scoped_refptr<webrtc::MockAudioEncoderFactory> factory = |
| 78 | new rtc::RefCountedObject<webrtc::MockAudioEncoderFactory>; |
| 79 | ON_CALL(*factory.get(), GetSupportedEncoders()) |
| 80 | .WillByDefault(Return(std::vector<webrtc::AudioCodecSpec>())); |
| 81 | ON_CALL(*factory.get(), QueryAudioEncoder(_)) |
Danil Chapovalov | 431abd9 | 2018-06-18 12:54:17 +0200 | [diff] [blame] | 82 | .WillByDefault(Return(absl::nullopt)); |
Karl Wiberg | d6fbf2a | 2018-02-27 13:37:31 +0100 | [diff] [blame] | 83 | ON_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)) |
| 84 | .WillByDefault(SetArgPointee<3>(nullptr)); |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 85 | |
| 86 | EXPECT_CALL(*factory.get(), GetSupportedEncoders()).Times(AnyNumber()); |
| 87 | EXPECT_CALL(*factory.get(), QueryAudioEncoder(_)).Times(AnyNumber()); |
Karl Wiberg | d6fbf2a | 2018-02-27 13:37:31 +0100 | [diff] [blame] | 88 | EXPECT_CALL(*factory.get(), MakeAudioEncoderMock(_, _, _, _)) |
ossu | 20a4b3f | 2017-04-27 02:08:52 -0700 | [diff] [blame] | 89 | .Times(AnyNumber()); |
| 90 | return factory; |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | } // namespace webrtc |
| 95 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 96 | #endif // TEST_MOCK_AUDIO_ENCODER_FACTORY_H_ |