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 | |
| 11 | #ifndef WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |
| 12 | #define WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |
| 13 | |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 16 | #include "testing/gmock/include/gmock/gmock.h" |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 17 | #include "webrtc/test/mock_voe_channel_proxy.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 18 | #include "webrtc/voice_engine/voice_engine_impl.h" |
| 19 | |
| 20 | namespace webrtc { |
| 21 | namespace test { |
| 22 | |
| 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(). |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 25 | class MockVoiceEngine : public VoiceEngineImpl { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 26 | public: |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame^] | 27 | // TODO(nisse): Valid overrides commented out, because the gmock |
| 28 | // methods don't use any override declarations, and we want to avoid |
| 29 | // warnings from -Winconsistent-missing-override. See |
| 30 | // http://crbug.com/428099. |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 31 | MockVoiceEngine() : VoiceEngineImpl(new Config(), true) { |
| 32 | // Increase ref count so this object isn't automatically deleted whenever |
| 33 | // interfaces are Release():d. |
| 34 | ++_ref_count; |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 35 | // We add this default behavior to make the mock easier to use in tests. It |
| 36 | // will create a NiceMock of a voe::ChannelProxy. |
| 37 | ON_CALL(*this, ChannelProxyFactory(testing::_)) |
| 38 | .WillByDefault( |
| 39 | testing::Invoke([](int channel_id) { |
| 40 | return new testing::NiceMock<MockVoEChannelProxy>(); |
| 41 | })); |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 42 | } |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame^] | 43 | ~MockVoiceEngine() /* override */ { |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 44 | // Decrease ref count before base class d-tor is called; otherwise it will |
| 45 | // trigger an assertion. |
| 46 | --_ref_count; |
| 47 | } |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 48 | // Allows injecting a ChannelProxy factory. |
| 49 | MOCK_METHOD1(ChannelProxyFactory, voe::ChannelProxy*(int channel_id)); |
| 50 | |
| 51 | // VoiceEngineImpl |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame^] | 52 | std::unique_ptr<voe::ChannelProxy> GetChannelProxy( |
| 53 | int channel_id) /* override */ { |
kwiberg | b7f89d6 | 2016-02-17 10:04:18 -0800 | [diff] [blame] | 54 | return std::unique_ptr<voe::ChannelProxy>(ChannelProxyFactory(channel_id)); |
solenberg | 1372508 | 2015-11-25 08:16:52 -0800 | [diff] [blame] | 55 | } |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 56 | |
| 57 | // VoEAudioProcessing |
| 58 | MOCK_METHOD2(SetNsStatus, int(bool enable, NsModes mode)); |
| 59 | MOCK_METHOD2(GetNsStatus, int(bool& enabled, NsModes& mode)); |
| 60 | MOCK_METHOD2(SetAgcStatus, int(bool enable, AgcModes mode)); |
| 61 | MOCK_METHOD2(GetAgcStatus, int(bool& enabled, AgcModes& mode)); |
| 62 | MOCK_METHOD1(SetAgcConfig, int(AgcConfig config)); |
| 63 | MOCK_METHOD1(GetAgcConfig, int(AgcConfig& config)); |
| 64 | MOCK_METHOD2(SetEcStatus, int(bool enable, EcModes mode)); |
| 65 | MOCK_METHOD2(GetEcStatus, int(bool& enabled, EcModes& mode)); |
| 66 | MOCK_METHOD1(EnableDriftCompensation, int(bool enable)); |
| 67 | MOCK_METHOD0(DriftCompensationEnabled, bool()); |
| 68 | MOCK_METHOD1(SetDelayOffsetMs, void(int offset)); |
| 69 | MOCK_METHOD0(DelayOffsetMs, int()); |
| 70 | MOCK_METHOD2(SetAecmMode, int(AecmModes mode, bool enableCNG)); |
| 71 | MOCK_METHOD2(GetAecmMode, int(AecmModes& mode, bool& enabledCNG)); |
| 72 | MOCK_METHOD1(EnableHighPassFilter, int(bool enable)); |
| 73 | MOCK_METHOD0(IsHighPassFilterEnabled, bool()); |
| 74 | MOCK_METHOD3(SetRxNsStatus, int(int channel, bool enable, NsModes mode)); |
| 75 | MOCK_METHOD3(GetRxNsStatus, int(int channel, bool& enabled, NsModes& mode)); |
| 76 | MOCK_METHOD3(SetRxAgcStatus, int(int channel, bool enable, AgcModes mode)); |
| 77 | MOCK_METHOD3(GetRxAgcStatus, int(int channel, bool& enabled, AgcModes& mode)); |
| 78 | MOCK_METHOD2(SetRxAgcConfig, int(int channel, AgcConfig config)); |
| 79 | MOCK_METHOD2(GetRxAgcConfig, int(int channel, AgcConfig& config)); |
| 80 | MOCK_METHOD2(RegisterRxVadObserver, |
| 81 | int(int channel, VoERxVadCallback& observer)); |
| 82 | MOCK_METHOD1(DeRegisterRxVadObserver, int(int channel)); |
| 83 | MOCK_METHOD1(VoiceActivityIndicator, int(int channel)); |
| 84 | MOCK_METHOD1(SetEcMetricsStatus, int(bool enable)); |
| 85 | MOCK_METHOD1(GetEcMetricsStatus, int(bool& enabled)); |
| 86 | MOCK_METHOD4(GetEchoMetrics, int(int& ERL, int& ERLE, int& RERL, int& A_NLP)); |
| 87 | MOCK_METHOD3(GetEcDelayMetrics, |
| 88 | int(int& delay_median, |
| 89 | int& delay_std, |
| 90 | float& fraction_poor_delays)); |
| 91 | MOCK_METHOD1(StartDebugRecording, int(const char* fileNameUTF8)); |
| 92 | MOCK_METHOD1(StartDebugRecording, int(FILE* file_handle)); |
| 93 | MOCK_METHOD0(StopDebugRecording, int()); |
| 94 | MOCK_METHOD1(SetTypingDetectionStatus, int(bool enable)); |
| 95 | MOCK_METHOD1(GetTypingDetectionStatus, int(bool& enabled)); |
| 96 | MOCK_METHOD1(TimeSinceLastTyping, int(int& seconds)); |
| 97 | MOCK_METHOD5(SetTypingDetectionParameters, |
| 98 | int(int timeWindow, |
| 99 | int costPerTyping, |
| 100 | int reportingThreshold, |
| 101 | int penaltyDecay, |
| 102 | int typeEventDelay)); |
| 103 | MOCK_METHOD1(EnableStereoChannelSwapping, void(bool enable)); |
| 104 | MOCK_METHOD0(IsStereoChannelSwappingEnabled, bool()); |
| 105 | |
| 106 | // VoEBase |
| 107 | MOCK_METHOD1(RegisterVoiceEngineObserver, int(VoiceEngineObserver& observer)); |
| 108 | MOCK_METHOD0(DeRegisterVoiceEngineObserver, int()); |
| 109 | MOCK_METHOD2(Init, |
| 110 | int(AudioDeviceModule* external_adm, |
| 111 | AudioProcessing* audioproc)); |
| 112 | MOCK_METHOD0(audio_processing, AudioProcessing*()); |
| 113 | MOCK_METHOD0(Terminate, int()); |
| 114 | MOCK_METHOD0(CreateChannel, int()); |
| 115 | MOCK_METHOD1(CreateChannel, int(const Config& config)); |
| 116 | MOCK_METHOD1(DeleteChannel, int(int channel)); |
| 117 | MOCK_METHOD1(StartReceive, int(int channel)); |
| 118 | MOCK_METHOD1(StopReceive, int(int channel)); |
| 119 | MOCK_METHOD1(StartPlayout, int(int channel)); |
| 120 | MOCK_METHOD1(StopPlayout, int(int channel)); |
| 121 | MOCK_METHOD1(StartSend, int(int channel)); |
| 122 | MOCK_METHOD1(StopSend, int(int channel)); |
| 123 | MOCK_METHOD1(GetVersion, int(char version[1024])); |
| 124 | MOCK_METHOD0(LastError, int()); |
| 125 | MOCK_METHOD0(audio_transport, AudioTransport*()); |
| 126 | MOCK_METHOD2(AssociateSendChannel, |
| 127 | int(int channel, int accociate_send_channel)); |
| 128 | |
| 129 | // VoECodec |
| 130 | MOCK_METHOD0(NumOfCodecs, int()); |
| 131 | MOCK_METHOD2(GetCodec, int(int index, CodecInst& codec)); |
| 132 | MOCK_METHOD2(SetSendCodec, int(int channel, const CodecInst& codec)); |
| 133 | MOCK_METHOD2(GetSendCodec, int(int channel, CodecInst& codec)); |
| 134 | MOCK_METHOD2(SetBitRate, int(int channel, int bitrate_bps)); |
| 135 | MOCK_METHOD2(GetRecCodec, int(int channel, CodecInst& codec)); |
| 136 | MOCK_METHOD2(SetRecPayloadType, int(int channel, const CodecInst& codec)); |
| 137 | MOCK_METHOD2(GetRecPayloadType, int(int channel, CodecInst& codec)); |
| 138 | MOCK_METHOD3(SetSendCNPayloadType, |
| 139 | int(int channel, int type, PayloadFrequencies frequency)); |
| 140 | MOCK_METHOD2(SetFECStatus, int(int channel, bool enable)); |
| 141 | MOCK_METHOD2(GetFECStatus, int(int channel, bool& enabled)); |
| 142 | MOCK_METHOD4(SetVADStatus, |
| 143 | int(int channel, bool enable, VadModes mode, bool disableDTX)); |
| 144 | MOCK_METHOD4( |
| 145 | GetVADStatus, |
| 146 | int(int channel, bool& enabled, VadModes& mode, bool& disabledDTX)); |
| 147 | MOCK_METHOD2(SetOpusMaxPlaybackRate, int(int channel, int frequency_hz)); |
| 148 | MOCK_METHOD2(SetOpusDtx, int(int channel, bool enable_dtx)); |
| 149 | MOCK_METHOD0(GetEventLog, RtcEventLog*()); |
| 150 | |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 151 | // VoEExternalMedia |
| 152 | MOCK_METHOD3(RegisterExternalMediaProcessing, |
| 153 | int(int channel, |
| 154 | ProcessingTypes type, |
| 155 | VoEMediaProcess& processObject)); |
| 156 | MOCK_METHOD2(DeRegisterExternalMediaProcessing, |
| 157 | int(int channel, ProcessingTypes type)); |
| 158 | MOCK_METHOD3(GetAudioFrame, |
| 159 | int(int channel, int desired_sample_rate_hz, AudioFrame* frame)); |
| 160 | MOCK_METHOD2(SetExternalMixing, int(int channel, bool enable)); |
| 161 | |
| 162 | // VoEFile |
| 163 | MOCK_METHOD7(StartPlayingFileLocally, |
| 164 | int(int channel, |
| 165 | const char fileNameUTF8[1024], |
| 166 | bool loop, |
| 167 | FileFormats format, |
| 168 | float volumeScaling, |
| 169 | int startPointMs, |
| 170 | int stopPointMs)); |
| 171 | MOCK_METHOD6(StartPlayingFileLocally, |
| 172 | int(int channel, |
| 173 | InStream* stream, |
| 174 | FileFormats format, |
| 175 | float volumeScaling, |
| 176 | int startPointMs, |
| 177 | int stopPointMs)); |
| 178 | MOCK_METHOD1(StopPlayingFileLocally, int(int channel)); |
| 179 | MOCK_METHOD1(IsPlayingFileLocally, int(int channel)); |
| 180 | MOCK_METHOD6(StartPlayingFileAsMicrophone, |
| 181 | int(int channel, |
| 182 | const char fileNameUTF8[1024], |
| 183 | bool loop, |
| 184 | bool mixWithMicrophone, |
| 185 | FileFormats format, |
| 186 | float volumeScaling)); |
| 187 | MOCK_METHOD5(StartPlayingFileAsMicrophone, |
| 188 | int(int channel, |
| 189 | InStream* stream, |
| 190 | bool mixWithMicrophone, |
| 191 | FileFormats format, |
| 192 | float volumeScaling)); |
| 193 | MOCK_METHOD1(StopPlayingFileAsMicrophone, int(int channel)); |
| 194 | MOCK_METHOD1(IsPlayingFileAsMicrophone, int(int channel)); |
| 195 | MOCK_METHOD4(StartRecordingPlayout, |
| 196 | int(int channel, |
| 197 | const char* fileNameUTF8, |
| 198 | CodecInst* compression, |
| 199 | int maxSizeBytes)); |
| 200 | MOCK_METHOD1(StopRecordingPlayout, int(int channel)); |
| 201 | MOCK_METHOD3(StartRecordingPlayout, |
| 202 | int(int channel, OutStream* stream, CodecInst* compression)); |
| 203 | MOCK_METHOD3(StartRecordingMicrophone, |
| 204 | int(const char* fileNameUTF8, |
| 205 | CodecInst* compression, |
| 206 | int maxSizeBytes)); |
| 207 | MOCK_METHOD2(StartRecordingMicrophone, |
| 208 | int(OutStream* stream, CodecInst* compression)); |
| 209 | MOCK_METHOD0(StopRecordingMicrophone, int()); |
| 210 | |
| 211 | // VoEHardware |
| 212 | MOCK_METHOD1(GetNumOfRecordingDevices, int(int& devices)); |
| 213 | MOCK_METHOD1(GetNumOfPlayoutDevices, int(int& devices)); |
| 214 | MOCK_METHOD3(GetRecordingDeviceName, |
| 215 | int(int index, char strNameUTF8[128], char strGuidUTF8[128])); |
| 216 | MOCK_METHOD3(GetPlayoutDeviceName, |
| 217 | int(int index, char strNameUTF8[128], char strGuidUTF8[128])); |
| 218 | MOCK_METHOD2(SetRecordingDevice, |
| 219 | int(int index, StereoChannel recordingChannel)); |
| 220 | MOCK_METHOD1(SetPlayoutDevice, int(int index)); |
| 221 | MOCK_METHOD1(SetAudioDeviceLayer, int(AudioLayers audioLayer)); |
| 222 | MOCK_METHOD1(GetAudioDeviceLayer, int(AudioLayers& audioLayer)); |
| 223 | MOCK_METHOD1(SetRecordingSampleRate, int(unsigned int samples_per_sec)); |
| 224 | MOCK_CONST_METHOD1(RecordingSampleRate, int(unsigned int* samples_per_sec)); |
| 225 | MOCK_METHOD1(SetPlayoutSampleRate, int(unsigned int samples_per_sec)); |
| 226 | MOCK_CONST_METHOD1(PlayoutSampleRate, int(unsigned int* samples_per_sec)); |
| 227 | MOCK_CONST_METHOD0(BuiltInAECIsAvailable, bool()); |
| 228 | MOCK_METHOD1(EnableBuiltInAEC, int(bool enable)); |
| 229 | MOCK_CONST_METHOD0(BuiltInAGCIsAvailable, bool()); |
| 230 | MOCK_METHOD1(EnableBuiltInAGC, int(bool enable)); |
| 231 | MOCK_CONST_METHOD0(BuiltInNSIsAvailable, bool()); |
| 232 | MOCK_METHOD1(EnableBuiltInNS, int(bool enable)); |
| 233 | |
| 234 | // VoENetEqStats |
| 235 | MOCK_METHOD2(GetNetworkStatistics, |
| 236 | int(int channel, NetworkStatistics& stats)); |
| 237 | MOCK_CONST_METHOD2(GetDecodingCallStatistics, |
| 238 | int(int channel, AudioDecodingCallStats* stats)); |
| 239 | |
| 240 | // VoENetwork |
| 241 | MOCK_METHOD2(RegisterExternalTransport, |
| 242 | int(int channel, Transport& transport)); |
| 243 | MOCK_METHOD1(DeRegisterExternalTransport, int(int channel)); |
| 244 | MOCK_METHOD3(ReceivedRTPPacket, |
| 245 | int(int channel, const void* data, size_t length)); |
| 246 | MOCK_METHOD4(ReceivedRTPPacket, |
| 247 | int(int channel, |
| 248 | const void* data, |
| 249 | size_t length, |
| 250 | const PacketTime& packet_time)); |
| 251 | MOCK_METHOD3(ReceivedRTCPPacket, |
| 252 | int(int channel, const void* data, size_t length)); |
| 253 | |
| 254 | // VoERTP_RTCP |
| 255 | MOCK_METHOD2(SetLocalSSRC, int(int channel, unsigned int ssrc)); |
| 256 | MOCK_METHOD2(GetLocalSSRC, int(int channel, unsigned int& ssrc)); |
| 257 | MOCK_METHOD2(GetRemoteSSRC, int(int channel, unsigned int& ssrc)); |
| 258 | MOCK_METHOD3(SetSendAudioLevelIndicationStatus, |
| 259 | int(int channel, bool enable, unsigned char id)); |
| 260 | MOCK_METHOD3(SetReceiveAudioLevelIndicationStatus, |
| 261 | int(int channel, bool enable, unsigned char id)); |
| 262 | MOCK_METHOD3(SetSendAbsoluteSenderTimeStatus, |
| 263 | int(int channel, bool enable, unsigned char id)); |
| 264 | MOCK_METHOD3(SetReceiveAbsoluteSenderTimeStatus, |
| 265 | int(int channel, bool enable, unsigned char id)); |
| 266 | MOCK_METHOD2(SetRTCPStatus, int(int channel, bool enable)); |
| 267 | MOCK_METHOD2(GetRTCPStatus, int(int channel, bool& enabled)); |
| 268 | MOCK_METHOD2(SetRTCP_CNAME, int(int channel, const char cName[256])); |
| 269 | MOCK_METHOD2(GetRTCP_CNAME, int(int channel, char cName[256])); |
| 270 | MOCK_METHOD2(GetRemoteRTCP_CNAME, int(int channel, char cName[256])); |
| 271 | MOCK_METHOD7(GetRemoteRTCPData, |
| 272 | int(int channel, |
| 273 | unsigned int& NTPHigh, |
| 274 | unsigned int& NTPLow, |
| 275 | unsigned int& timestamp, |
| 276 | unsigned int& playoutTimestamp, |
| 277 | unsigned int* jitter, |
| 278 | unsigned short* fractionLost)); |
| 279 | MOCK_METHOD4(GetRTPStatistics, |
| 280 | int(int channel, |
| 281 | unsigned int& averageJitterMs, |
| 282 | unsigned int& maxJitterMs, |
| 283 | unsigned int& discardedPackets)); |
| 284 | MOCK_METHOD2(GetRTCPStatistics, int(int channel, CallStatistics& stats)); |
| 285 | MOCK_METHOD2(GetRemoteRTCPReportBlocks, |
| 286 | int(int channel, std::vector<ReportBlock>* receive_blocks)); |
| 287 | MOCK_METHOD3(SetREDStatus, int(int channel, bool enable, int redPayloadtype)); |
| 288 | MOCK_METHOD3(GetREDStatus, |
| 289 | int(int channel, bool& enable, int& redPayloadtype)); |
| 290 | MOCK_METHOD3(SetNACKStatus, int(int channel, bool enable, int maxNoPackets)); |
| 291 | |
| 292 | // VoEVideoSync |
| 293 | MOCK_METHOD1(GetPlayoutBufferSize, int(int& buffer_ms)); |
| 294 | MOCK_METHOD2(SetMinimumPlayoutDelay, int(int channel, int delay_ms)); |
| 295 | MOCK_METHOD3(GetDelayEstimate, |
| 296 | int(int channel, |
| 297 | int* jitter_buffer_delay_ms, |
| 298 | int* playout_buffer_delay_ms)); |
| 299 | MOCK_CONST_METHOD1(GetLeastRequiredDelayMs, int(int channel)); |
| 300 | MOCK_METHOD2(SetInitTimestamp, int(int channel, unsigned int timestamp)); |
| 301 | MOCK_METHOD2(SetInitSequenceNumber, int(int channel, short sequenceNumber)); |
| 302 | MOCK_METHOD2(GetPlayoutTimestamp, int(int channel, unsigned int& timestamp)); |
| 303 | MOCK_METHOD3(GetRtpRtcp, |
| 304 | int(int channel, |
| 305 | RtpRtcp** rtpRtcpModule, |
| 306 | RtpReceiver** rtp_receiver)); |
| 307 | |
| 308 | // VoEVolumeControl |
| 309 | MOCK_METHOD1(SetSpeakerVolume, int(unsigned int volume)); |
| 310 | MOCK_METHOD1(GetSpeakerVolume, int(unsigned int& volume)); |
| 311 | MOCK_METHOD1(SetMicVolume, int(unsigned int volume)); |
| 312 | MOCK_METHOD1(GetMicVolume, int(unsigned int& volume)); |
| 313 | MOCK_METHOD2(SetInputMute, int(int channel, bool enable)); |
| 314 | MOCK_METHOD2(GetInputMute, int(int channel, bool& enabled)); |
| 315 | MOCK_METHOD1(GetSpeechInputLevel, int(unsigned int& level)); |
| 316 | MOCK_METHOD2(GetSpeechOutputLevel, int(int channel, unsigned int& level)); |
| 317 | MOCK_METHOD1(GetSpeechInputLevelFullRange, int(unsigned int& level)); |
| 318 | MOCK_METHOD2(GetSpeechOutputLevelFullRange, |
| 319 | int(int channel, unsigned& level)); |
| 320 | MOCK_METHOD2(SetChannelOutputVolumeScaling, int(int channel, float scaling)); |
| 321 | MOCK_METHOD2(GetChannelOutputVolumeScaling, int(int channel, float& scaling)); |
| 322 | MOCK_METHOD3(SetOutputVolumePan, int(int channel, float left, float right)); |
| 323 | MOCK_METHOD3(GetOutputVolumePan, int(int channel, float& left, float& right)); |
| 324 | }; |
| 325 | } // namespace test |
| 326 | } // namespace webrtc |
| 327 | |
| 328 | #endif // WEBRTC_AUDIO_MOCK_VOICE_ENGINE_H_ |