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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace test { | 21 namespace test { |
22 | 22 |
23 // NOTE: This class inherits from VoiceEngineImpl so that its clients will be | 23 // NOTE: This class inherits from VoiceEngineImpl so that its clients will be |
24 // able to get the various interfaces as usual, via T::GetInterface(). | 24 // able to get the various interfaces as usual, via T::GetInterface(). |
25 class MockVoiceEngine : public VoiceEngineImpl { | 25 class MockVoiceEngine : public VoiceEngineImpl { |
26 public: | 26 public: |
27 // TODO(nisse): Valid overrides commented out, because the gmock | 27 // TODO(nisse): Valid overrides commented out, because the gmock |
28 // methods don't use any override declarations, and we want to avoid | 28 // methods don't use any override declarations, and we want to avoid |
29 // warnings from -Winconsistent-missing-override. See | 29 // warnings from -Winconsistent-missing-override. See |
30 // http://crbug.com/428099. | 30 // http://crbug.com/428099. |
31 MockVoiceEngine() : VoiceEngineImpl(new Config(), true) { | 31 MockVoiceEngine( |
| 32 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory = nullptr) |
| 33 : VoiceEngineImpl(new Config(), true), |
| 34 decoder_factory_(decoder_factory) { |
32 // Increase ref count so this object isn't automatically deleted whenever | 35 // Increase ref count so this object isn't automatically deleted whenever |
33 // interfaces are Release():d. | 36 // interfaces are Release():d. |
34 ++_ref_count; | 37 ++_ref_count; |
35 // We add this default behavior to make the mock easier to use in tests. It | 38 // We add this default behavior to make the mock easier to use in tests. It |
36 // will create a NiceMock of a voe::ChannelProxy. | 39 // will create a NiceMock of a voe::ChannelProxy. |
| 40 // TODO(ossu): As long as AudioReceiveStream is implmented as a wrapper |
| 41 // around Channel, we need to make sure ChannelProxy returns the same |
| 42 // decoder factory as the one passed in when creating an AudioReceiveStream. |
37 ON_CALL(*this, ChannelProxyFactory(testing::_)) | 43 ON_CALL(*this, ChannelProxyFactory(testing::_)) |
38 .WillByDefault( | 44 .WillByDefault(testing::Invoke([this](int channel_id) { |
39 testing::Invoke([](int channel_id) { | 45 auto* proxy = |
40 return new testing::NiceMock<MockVoEChannelProxy>(); | 46 new testing::NiceMock<webrtc::test::MockVoEChannelProxy>(); |
41 })); | 47 EXPECT_CALL(*proxy, GetAudioDecoderFactory()) |
| 48 .WillRepeatedly(testing::ReturnRef(decoder_factory_)); |
| 49 return proxy; |
| 50 })); |
42 } | 51 } |
43 ~MockVoiceEngine() /* override */ { | 52 ~MockVoiceEngine() /* override */ { |
44 // Decrease ref count before base class d-tor is called; otherwise it will | 53 // Decrease ref count before base class d-tor is called; otherwise it will |
45 // trigger an assertion. | 54 // trigger an assertion. |
46 --_ref_count; | 55 --_ref_count; |
47 } | 56 } |
48 // Allows injecting a ChannelProxy factory. | 57 // Allows injecting a ChannelProxy factory. |
49 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); | 58 MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); |
50 | 59 |
51 // VoiceEngineImpl | 60 // VoiceEngineImpl |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled)); | 325 MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled)); |
317 MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level)); | 326 MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level)); |
318 MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level)); | 327 MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level)); |
319 MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level)); | 328 MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level)); |
320 MOCK_METHOD2(GetSpeechOutputLevelFullRange, | 329 MOCK_METHOD2(GetSpeechOutputLevelFullRange, |
321 int(int channel, unsigned& level)); | 330 int(int channel, unsigned& level)); |
322 MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling)); | 331 MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling)); |
323 MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling)); | 332 MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling)); |
324 MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right)); | 333 MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right)); |
325 MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right)); | 334 MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right)); |
| 335 |
| 336 private: |
| 337 // TODO(ossu): I'm not particularly happy about keeping the decoder factory |
| 338 // here, but due to how gmock is implemented, I cannot just keep it in the |
| 339 // functor implementing the default version of ChannelProxyFactory, above. |
| 340 // GMock creates an unfortunate copy of the functor, which would cause us to |
| 341 // return a dangling reference. Fortunately, this should go away once |
| 342 // voe::Channel does. |
| 343 rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_; |
326 }; | 344 }; |
327 } // namespace test | 345 } // namespace test |
328 } // namespace webrtc | 346 } // namespace webrtc |
329 | 347 |
330 #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ | 348 #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |
OLD | NEW |