Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 AUDIO_MOCK_VOICE_ENGINE_H_ |
| 12 | #define AUDIO_MOCK_VOICE_ENGINE_H_ |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 13 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "modules/audio_device/include/mock_audio_device.h" |
| 17 | #include "modules/audio_device/include/mock_audio_transport.h" |
| 18 | #include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
| 19 | #include "test/gmock.h" |
| 20 | #include "test/mock_voe_channel_proxy.h" |
| 21 | #include "voice_engine/voice_engine_impl.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 24 | namespace voe { |
| 25 | class TransmitMixer; |
| 26 | } // namespace voe |
| 27 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 28 | namespace test { |
| 29 | |
| 30 | // NOTE: This class inherits from VoiceEngineImpl so that its clients will be |
| 31 | // able to get the various interfaces as usual, via T::GetInterface(). |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 32 | class MockVoiceEngine : public VoiceEngineImpl { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 33 | public: |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 34 | // TODO(nisse): Valid overrides commented out, because the gmock |
| 35 | // methods don't use any override declarations, and we want to avoid |
| 36 | // warnings from -Winconsistent-missing-override. See |
| 37 | // http://crbug.com/428099. |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 38 | MockVoiceEngine( |
| 39 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr) |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 40 | : decoder_factory_(decoder_factory) { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 41 | // Increase ref count so this object isn't automatically deleted whenever |
| 42 | // interfaces are Release():d. |
| 43 | ++_ref_count; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 44 | // We add this default behavior to make the mock easier to use in tests. It |
| 45 | // will create a NiceMock of a voe::ChannelProxy. |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 46 | // TODO(ossu): As long as AudioReceiveStream is implemented as a wrapper |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 47 | // around Channel, we need to make sure ChannelProxy returns the same |
| 48 | // decoder factory as the one passed in when creating an AudioReceiveStream. |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 49 | ON_CALL(*this, ChannelProxyFactory(testing::_)) |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 50 | .WillByDefault(testing::Invoke([this](int channel_id) { |
| 51 | auto* proxy = |
| 52 | new testing::NiceMock<webrtc::test::MockVoEChannelProxy>(); |
| 53 | EXPECT_CALL(*proxy, GetAudioDecoderFactory()) |
| 54 | .WillRepeatedly(testing::ReturnRef(decoder_factory_)); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 55 | EXPECT_CALL(*proxy, SetReceiveCodecs(testing::_)) |
| 56 | .WillRepeatedly(testing::Invoke( |
| 57 | [](const std::map<int, SdpAudioFormat>& codecs) { |
| 58 | EXPECT_THAT(codecs, testing::IsEmpty()); |
| 59 | })); |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 60 | EXPECT_CALL(*proxy, GetRtpRtcp(testing::_, testing::_)) |
| 61 | .WillRepeatedly( |
| 62 | testing::SetArgPointee<0>(GetMockRtpRtcp(channel_id))); |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 63 | return proxy; |
| 64 | })); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 65 | |
| 66 | ON_CALL(*this, audio_device_module()) |
| 67 | .WillByDefault(testing::Return(&mock_audio_device_)); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 68 | ON_CALL(*this, audio_transport()) |
| 69 | .WillByDefault(testing::Return(&mock_audio_transport_)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 70 | } |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 71 | virtual ~MockVoiceEngine() /* override */ { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 72 | // Decrease ref count before base class d-tor is called; otherwise it will |
| 73 | // trigger an assertion. |
| 74 | --_ref_count; |
| 75 | } |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 76 | |
| 77 | // These need to be the same each call to channel_id and must not leak. |
| 78 | MockRtpRtcp* GetMockRtpRtcp(int channel_id) { |
| 79 | if (mock_rtp_rtcps_.find(channel_id) == mock_rtp_rtcps_.end()) { |
| 80 | mock_rtp_rtcps_[channel_id].reset(new ::testing::NiceMock<MockRtpRtcp>); |
| 81 | } |
| 82 | return mock_rtp_rtcps_[channel_id].get(); |
| 83 | } |
| 84 | |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 85 | // Allows injecting a ChannelProxy factory. |
| 86 | MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); |
| 87 | |
| 88 | // VoiceEngineImpl |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 89 | virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy( |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 90 | int channel_id) /* override */ { |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 91 | return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id)); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 92 | } |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 93 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 94 | // VoEBase |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 95 | MOCK_METHOD3( |
| 96 | Init, |
| 97 | int(AudioDeviceModule* external_adm, |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 98 | AudioProcessing* external_apm, |
ossu | 5f7cfa5 | 2016-05-30 08:11:28 -0700 | [diff] [blame] | 99 | const rtc::scoped_refptr<AudioDecoderFactory>& decoder_factory)); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 100 | MOCK_METHOD0(audio_device_module, AudioDeviceModule*()); |
solenberg | 796b8f9 | 2017-03-01 17:02:23 -0800 | [diff] [blame] | 101 | MOCK_METHOD0(transmit_mixer, voe::TransmitMixer*()); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 102 | MOCK_METHOD0(Terminate, int()); |
| 103 | MOCK_METHOD0(CreateChannel, int()); |
solenberg | 88499ec | 2016-09-07 07:34:41 -0700 | [diff] [blame] | 104 | MOCK_METHOD1(CreateChannel, int(const ChannelConfig& config)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 105 | MOCK_METHOD1(DeleteChannel, int(int channel)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 106 | MOCK_METHOD1(StartPlayout, int(int channel)); |
| 107 | MOCK_METHOD1(StopPlayout, int(int channel)); |
| 108 | MOCK_METHOD1(StartSend, int(int channel)); |
| 109 | MOCK_METHOD1(StopSend, int(int channel)); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 110 | MOCK_METHOD0(audio_transport, AudioTransport*()); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 111 | |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 112 | private: |
| 113 | // TODO(ossu): I'm not particularly happy about keeping the decoder factory |
| 114 | // here, but due to how gmock is implemented, I cannot just keep it in the |
| 115 | // functor implementing the default version of ChannelProxyFactory, above. |
| 116 | // GMock creates an unfortunate copy of the functor, which would cause us to |
| 117 | // return a dangling reference. Fortunately, this should go away once |
| 118 | // voe::Channel does. |
| 119 | rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 120 | |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 121 | std::map<int, std::unique_ptr<MockRtpRtcp>> mock_rtp_rtcps_; |
| 122 | |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 123 | MockAudioDeviceModule mock_audio_device_; |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 124 | MockAudioTransport mock_audio_transport_; |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 125 | }; |
| 126 | } // namespace test |
| 127 | } // namespace webrtc |
| 128 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 129 | #endif // AUDIO_MOCK_VOICE_ENGINE_H_ |