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