OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ | 11 #ifndef WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |
12 #define WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ | 12 #define WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "webrtc/modules/audio_device/include/mock_audio_device.h" | 16 #include "webrtc/modules/audio_device/include/mock_audio_device.h" |
17 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" | 17 #include "webrtc/modules/audio_device/include/mock_audio_transport.h" |
18 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" | 18 #include "webrtc/modules/audio_processing/include/mock_audio_processing.h" |
| 19 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
19 #include "webrtc/test/gmock.h" | 20 #include "webrtc/test/gmock.h" |
20 #include "webrtc/test/mock_voe_channel_proxy.h" | 21 #include "webrtc/test/mock_voe_channel_proxy.h" |
21 #include "webrtc/voice_engine/voice_engine_impl.h" | 22 #include "webrtc/voice_engine/voice_engine_impl.h" |
22 | 23 |
23 namespace webrtc { | 24 namespace webrtc { |
24 namespace voe { | 25 namespace voe { |
25 class TransmitMixer; | 26 class TransmitMixer; |
26 } // namespace voe | 27 } // namespace voe |
27 | 28 |
28 namespace test { | 29 namespace test { |
(...skipping 21 matching lines...) Expand all Loading... |
50 .WillByDefault(testing::Invoke([this](int channel_id) { | 51 .WillByDefault(testing::Invoke([this](int channel_id) { |
51 auto* proxy = | 52 auto* proxy = |
52 new testing::NiceMock<webrtc::test::MockVoEChannelProxy>(); | 53 new testing::NiceMock<webrtc::test::MockVoEChannelProxy>(); |
53 EXPECT_CALL(*proxy, GetAudioDecoderFactory()) | 54 EXPECT_CALL(*proxy, GetAudioDecoderFactory()) |
54 .WillRepeatedly(testing::ReturnRef(decoder_factory_)); | 55 .WillRepeatedly(testing::ReturnRef(decoder_factory_)); |
55 EXPECT_CALL(*proxy, SetReceiveCodecs(testing::_)) | 56 EXPECT_CALL(*proxy, SetReceiveCodecs(testing::_)) |
56 .WillRepeatedly(testing::Invoke( | 57 .WillRepeatedly(testing::Invoke( |
57 [](const std::map<int, SdpAudioFormat>& codecs) { | 58 [](const std::map<int, SdpAudioFormat>& codecs) { |
58 EXPECT_THAT(codecs, testing::IsEmpty()); | 59 EXPECT_THAT(codecs, testing::IsEmpty()); |
59 })); | 60 })); |
| 61 EXPECT_CALL(*proxy, GetRtpRtcp(testing::_, testing::_)) |
| 62 .WillRepeatedly( |
| 63 testing::SetArgPointee<0>(GetMockRtpRtcp(channel_id))); |
60 return proxy; | 64 return proxy; |
61 })); | 65 })); |
62 | 66 |
63 ON_CALL(mock_audio_device_, TimeUntilNextProcess()) | 67 ON_CALL(mock_audio_device_, TimeUntilNextProcess()) |
64 .WillByDefault(testing::Return(1000)); | 68 .WillByDefault(testing::Return(1000)); |
65 ON_CALL(*this, audio_device_module()) | 69 ON_CALL(*this, audio_device_module()) |
66 .WillByDefault(testing::Return(&mock_audio_device_)); | 70 .WillByDefault(testing::Return(&mock_audio_device_)); |
67 ON_CALL(*this, audio_processing()) | 71 ON_CALL(*this, audio_processing()) |
68 .WillByDefault(testing::Return(&mock_audio_processing_)); | 72 .WillByDefault(testing::Return(&mock_audio_processing_)); |
69 ON_CALL(*this, audio_transport()) | 73 ON_CALL(*this, audio_transport()) |
70 .WillByDefault(testing::Return(&mock_audio_transport_)); | 74 .WillByDefault(testing::Return(&mock_audio_transport_)); |
71 } | 75 } |
72 virtual ~MockVoiceEngine() /* override */ { | 76 virtual ~MockVoiceEngine() /* override */ { |
73 // Decrease ref count before base class d-tor is called; otherwise it will | 77 // Decrease ref count before base class d-tor is called; otherwise it will |
74 // trigger an assertion. | 78 // trigger an assertion. |
75 --_ref_count; | 79 --_ref_count; |
76 } | 80 } |
| 81 |
| 82 // These need to be the same each call to channel_id and must not leak. |
| 83 MockRtpRtcp* GetMockRtpRtcp(int channel_id) { |
| 84 if (mock_rtp_rtcps_.find(channel_id) == mock_rtp_rtcps_.end()) { |
| 85 mock_rtp_rtcps_[channel_id].reset(new ::testing::NiceMock<MockRtpRtcp>); |
| 86 } |
| 87 return mock_rtp_rtcps_[channel_id].get(); |
| 88 } |
| 89 |
77 // Allows injecting a ChannelProxy factory. | 90 // Allows injecting a ChannelProxy factory. |
78 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); | 91 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); |
79 | 92 |
80 // VoiceEngineImpl | 93 // VoiceEngineImpl |
81 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy( | 94 virtual std::unique_ptr<voe::ChannelProxy> GetChannelProxy( |
82 int channel_id) /* override */ { | 95 int channel_id) /* override */ { |
83 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id)); | 96 return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id)); |
84 } | 97 } |
85 | 98 |
86 // VoEBase | 99 // VoEBase |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 | 247 |
235 private: | 248 private: |
236 // TODO(ossu): I'm not particularly happy about keeping the decoder factory | 249 // TODO(ossu): I'm not particularly happy about keeping the decoder factory |
237 // here, but due to how gmock is implemented, I cannot just keep it in the | 250 // here, but due to how gmock is implemented, I cannot just keep it in the |
238 // functor implementing the default version of ChannelProxyFactory, above. | 251 // functor implementing the default version of ChannelProxyFactory, above. |
239 // GMock creates an unfortunate copy of the functor, which would cause us to | 252 // GMock creates an unfortunate copy of the functor, which would cause us to |
240 // return a dangling reference. Fortunately, this should go away once | 253 // return a dangling reference. Fortunately, this should go away once |
241 // voe::Channel does. | 254 // voe::Channel does. |
242 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; | 255 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
243 | 256 |
| 257 std::map<int, std::unique_ptr<MockRtpRtcp>> mock_rtp_rtcps_; |
| 258 |
244 MockAudioDeviceModule mock_audio_device_; | 259 MockAudioDeviceModule mock_audio_device_; |
245 MockAudioProcessing mock_audio_processing_; | 260 MockAudioProcessing mock_audio_processing_; |
246 MockAudioTransport mock_audio_transport_; | 261 MockAudioTransport mock_audio_transport_; |
247 }; | 262 }; |
248 } // namespace test | 263 } // namespace test |
249 } // namespace webrtc | 264 } // namespace webrtc |
250 | 265 |
251 #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ | 266 #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |
OLD | NEW |