From 651b92e5d889a5f920ab6daed12e638544fce99a Mon Sep 17 00:00:00 2001 From: Jiawei Ou Date: Fri, 29 Jun 2018 15:46:44 -0700 Subject: [PATCH] Regenerate mock peer connection to add missing mock methods. Generated using gmock_gen.py with some editing. This mock doesn't seem to be used by unittest in webrtc, but we need to use it in downstream unittests. Bug: None Change-Id: Ia7904ffdd22f3d16fe5fd515fa68833817b44481 Reviewed-on: https://webrtc-review.googlesource.com/85780 Commit-Queue: Tommi Reviewed-by: Tommi Cr-Commit-Position: refs/heads/master@{#23900} --- api/BUILD.gn | 12 ++ api/test/mock_peerconnectioninterface.h | 140 +++++++++++++++++++++ pc/test/mock_peerconnection.h | 155 +++++++++++++++++++++--- 3 files changed, 290 insertions(+), 17 deletions(-) create mode 100644 api/test/mock_peerconnectioninterface.h diff --git a/api/BUILD.gn b/api/BUILD.gn index f73c80da6d..4357947997 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -414,6 +414,18 @@ if (rtc_include_tests) { ] } + rtc_source_set("mock_peerconnectioninterface") { + testonly = true + sources = [ + "test/mock_peerconnectioninterface.h", + ] + + deps = [ + ":libjingle_peerconnection_api", + "../test:test_support", + ] + } + rtc_source_set("mock_rtp") { testonly = true sources = [ diff --git a/api/test/mock_peerconnectioninterface.h b/api/test/mock_peerconnectioninterface.h new file mode 100644 index 0000000000..397860cc7c --- /dev/null +++ b/api/test/mock_peerconnectioninterface.h @@ -0,0 +1,140 @@ +/* + * Copyright 2016 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_TEST_MOCK_PEERCONNECTIONINTERFACE_H_ +#define API_TEST_MOCK_PEERCONNECTIONINTERFACE_H_ + +#include +#include +#include +#include + +#include "api/peerconnectioninterface.h" +#include "test/gmock.h" + +namespace webrtc { + +class MockPeerConnectionInterface + : public rtc::RefCountedObject { + public: + // PeerConnectionInterface + MOCK_METHOD0(local_streams, rtc::scoped_refptr()); + MOCK_METHOD0(remote_streams, rtc::scoped_refptr()); + MOCK_METHOD1(AddStream, bool(MediaStreamInterface*)); + MOCK_METHOD1(RemoveStream, void(MediaStreamInterface*)); + MOCK_METHOD2(AddTrack, + RTCErrorOr>( + rtc::scoped_refptr, + const std::vector&)); + MOCK_METHOD2(AddTrack, + rtc::scoped_refptr( + MediaStreamTrackInterface*, + std::vector)); + MOCK_METHOD1(RemoveTrack, bool(RtpSenderInterface*)); + MOCK_METHOD1(AddTransceiver, + RTCErrorOr>( + rtc::scoped_refptr)); + MOCK_METHOD2(AddTransceiver, + RTCErrorOr>( + rtc::scoped_refptr, + const RtpTransceiverInit&)); + MOCK_METHOD1(AddTransceiver, + RTCErrorOr>( + cricket::MediaType)); + MOCK_METHOD2(AddTransceiver, + RTCErrorOr>( + cricket::MediaType, + const RtpTransceiverInit&)); + MOCK_METHOD2(CreateSender, + rtc::scoped_refptr(const std::string&, + const std::string&)); + MOCK_CONST_METHOD0(GetSenders, + std::vector>()); + MOCK_CONST_METHOD0(GetReceivers, + std::vector>()); + MOCK_CONST_METHOD0( + GetTransceivers, + std::vector>()); + MOCK_METHOD3(GetStats, + bool(StatsObserver*, + MediaStreamTrackInterface*, + StatsOutputLevel)); + MOCK_METHOD1(GetStats, void(RTCStatsCollectorCallback*)); + MOCK_METHOD2(GetStats, + void(rtc::scoped_refptr, + rtc::scoped_refptr)); + MOCK_METHOD2(GetStats, + void(rtc::scoped_refptr, + rtc::scoped_refptr)); + MOCK_METHOD0(ClearStatsCache, void()); + MOCK_METHOD2( + CreateDataChannel, + rtc::scoped_refptr(const std::string&, + const DataChannelInit*)); + MOCK_CONST_METHOD0(local_description, const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(remote_description, const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(current_local_description, + const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(current_remote_description, + const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(pending_local_description, + const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(pending_remote_description, + const SessionDescriptionInterface*()); + MOCK_METHOD2(CreateOffer, + void(CreateSessionDescriptionObserver*, + const MediaConstraintsInterface*)); + MOCK_METHOD2(CreateOffer, + void(CreateSessionDescriptionObserver*, + const RTCOfferAnswerOptions&)); + MOCK_METHOD2(CreateAnswer, + void(CreateSessionDescriptionObserver*, + const RTCOfferAnswerOptions&)); + MOCK_METHOD2(CreateAnswer, + void(CreateSessionDescriptionObserver*, + const MediaConstraintsInterface*)); + MOCK_METHOD2(SetLocalDescription, + void(SetSessionDescriptionObserver*, + SessionDescriptionInterface*)); + MOCK_METHOD2(SetRemoteDescription, + void(SetSessionDescriptionObserver*, + SessionDescriptionInterface*)); + MOCK_METHOD2(SetRemoteDescription, + void(std::unique_ptr, + rtc::scoped_refptr)); + MOCK_METHOD0(GetConfiguration, PeerConnectionInterface::RTCConfiguration()); + MOCK_METHOD2(SetConfiguration, + bool(const PeerConnectionInterface::RTCConfiguration&, + RTCError*)); + MOCK_METHOD1(SetConfiguration, + bool(const PeerConnectionInterface::RTCConfiguration&)); + MOCK_METHOD1(AddIceCandidate, bool(const IceCandidateInterface*)); + MOCK_METHOD1(RemoveIceCandidates, + bool(const std::vector&)); + MOCK_METHOD1(RegisterUMAObserver, void(UMAObserver*)); + MOCK_METHOD1(SetBitrate, RTCError(const BitrateSettings&)); + MOCK_METHOD1(SetBitrate, RTCError(const BitrateParameters&)); + MOCK_METHOD1(SetBitrateAllocationStrategy, + void(std::unique_ptr)); + MOCK_METHOD1(SetAudioPlayout, void(bool)); + MOCK_METHOD1(SetAudioRecording, void(bool)); + MOCK_METHOD0(signaling_state, SignalingState()); + MOCK_METHOD0(ice_connection_state, IceConnectionState()); + MOCK_METHOD0(ice_gathering_state, IceGatheringState()); + MOCK_METHOD2(StartRtcEventLog, bool(rtc::PlatformFile, int64_t)); + MOCK_METHOD2(StartRtcEventLog, + bool(std::unique_ptr, int64_t)); + MOCK_METHOD0(StopRtcEventLog, void()); + MOCK_METHOD0(Close, void()); +}; + +} // namespace webrtc + +#endif // API_TEST_MOCK_PEERCONNECTIONINTERFACE_H_ diff --git a/pc/test/mock_peerconnection.h b/pc/test/mock_peerconnection.h index dfd5ecc8ad..5eee5c9c06 100644 --- a/pc/test/mock_peerconnection.h +++ b/pc/test/mock_peerconnection.h @@ -11,7 +11,9 @@ #ifndef PC_TEST_MOCK_PEERCONNECTION_H_ #define PC_TEST_MOCK_PEERCONNECTION_H_ +#include #include +#include #include #include #include @@ -51,33 +53,152 @@ class MockPeerConnection factory, std::unique_ptr(), std::unique_ptr()) {} + + // PeerConnectionInterface MOCK_METHOD0(local_streams, rtc::scoped_refptr()); MOCK_METHOD0(remote_streams, rtc::scoped_refptr()); + MOCK_METHOD1(AddStream, bool(MediaStreamInterface*)); + MOCK_METHOD1(RemoveStream, void(MediaStreamInterface*)); + MOCK_METHOD2(AddTrack, + RTCErrorOr>( + rtc::scoped_refptr, + const std::vector&)); + MOCK_METHOD2(AddTrack, + rtc::scoped_refptr( + MediaStreamTrackInterface*, + std::vector)); + MOCK_METHOD1(RemoveTrack, bool(RtpSenderInterface*)); + MOCK_METHOD1(AddTransceiver, + RTCErrorOr>( + rtc::scoped_refptr)); + MOCK_METHOD2(AddTransceiver, + RTCErrorOr>( + rtc::scoped_refptr, + const RtpTransceiverInit&)); + MOCK_METHOD1(AddTransceiver, + RTCErrorOr>( + cricket::MediaType)); + MOCK_METHOD2(AddTransceiver, + RTCErrorOr>( + cricket::MediaType, + const RtpTransceiverInit&)); + MOCK_METHOD2(CreateSender, + rtc::scoped_refptr(const std::string&, + const std::string&)); MOCK_CONST_METHOD0(GetSenders, std::vector>()); MOCK_CONST_METHOD0(GetReceivers, std::vector>()); - MOCK_CONST_METHOD0(sctp_data_channels, - std::vector>()); - MOCK_CONST_METHOD0(voice_channel, cricket::VoiceChannel*()); - MOCK_CONST_METHOD0(video_channel, cricket::VideoChannel*()); - // Libjingle uses "local" for a outgoing track, and "remote" for a incoming - // track. + MOCK_CONST_METHOD0( + GetTransceivers, + std::vector>()); + MOCK_METHOD3(GetStats, + bool(StatsObserver*, + MediaStreamTrackInterface*, + StatsOutputLevel)); + MOCK_METHOD1(GetStats, void(RTCStatsCollectorCallback*)); + MOCK_METHOD2(GetStats, + void(rtc::scoped_refptr, + rtc::scoped_refptr)); + MOCK_METHOD2(GetStats, + void(rtc::scoped_refptr, + rtc::scoped_refptr)); + MOCK_METHOD0(ClearStatsCache, void()); + MOCK_METHOD2( + CreateDataChannel, + rtc::scoped_refptr(const std::string&, + const DataChannelInit*)); + MOCK_CONST_METHOD0(local_description, const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(remote_description, const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(current_local_description, + const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(current_remote_description, + const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(pending_local_description, + const SessionDescriptionInterface*()); + MOCK_CONST_METHOD0(pending_remote_description, + const SessionDescriptionInterface*()); + MOCK_METHOD2(CreateOffer, + void(CreateSessionDescriptionObserver*, + const MediaConstraintsInterface*)); + MOCK_METHOD2(CreateOffer, + void(CreateSessionDescriptionObserver*, + const RTCOfferAnswerOptions&)); + MOCK_METHOD2(CreateAnswer, + void(CreateSessionDescriptionObserver*, + const RTCOfferAnswerOptions&)); + MOCK_METHOD2(CreateAnswer, + void(CreateSessionDescriptionObserver*, + const MediaConstraintsInterface*)); + MOCK_METHOD2(SetLocalDescription, + void(SetSessionDescriptionObserver*, + SessionDescriptionInterface*)); + MOCK_METHOD2(SetRemoteDescription, + void(SetSessionDescriptionObserver*, + SessionDescriptionInterface*)); + MOCK_METHOD2(SetRemoteDescription, + void(std::unique_ptr, + rtc::scoped_refptr)); + MOCK_METHOD0(GetConfiguration, PeerConnectionInterface::RTCConfiguration()); + MOCK_METHOD2(SetConfiguration, + bool(const PeerConnectionInterface::RTCConfiguration&, + RTCError*)); + MOCK_METHOD1(SetConfiguration, + bool(const PeerConnectionInterface::RTCConfiguration&)); + MOCK_METHOD1(AddIceCandidate, bool(const IceCandidateInterface*)); + MOCK_METHOD1(RemoveIceCandidates, + bool(const std::vector&)); + MOCK_METHOD1(RegisterUMAObserver, void(UMAObserver*)); + MOCK_METHOD1(SetBitrate, RTCError(const BitrateSettings&)); + MOCK_METHOD1(SetBitrate, RTCError(const BitrateParameters&)); + MOCK_METHOD1(SetBitrateAllocationStrategy, + void(std::unique_ptr)); + MOCK_METHOD1(SetAudioPlayout, void(bool)); + MOCK_METHOD1(SetAudioRecording, void(bool)); + MOCK_METHOD0(signaling_state, SignalingState()); + MOCK_METHOD0(ice_connection_state, IceConnectionState()); + MOCK_METHOD0(ice_gathering_state, IceGatheringState()); + MOCK_METHOD2(StartRtcEventLog, bool(rtc::PlatformFile, int64_t)); + MOCK_METHOD2(StartRtcEventLog, + bool(std::unique_ptr, int64_t)); + MOCK_METHOD0(StopRtcEventLog, void()); + MOCK_METHOD0(Close, void()); + + // PeerConnectionInternal + MOCK_CONST_METHOD0(network_thread, rtc::Thread*()); + MOCK_CONST_METHOD0(worker_thread, rtc::Thread*()); + MOCK_CONST_METHOD0(signaling_thread, rtc::Thread*()); + MOCK_CONST_METHOD0(session_id, std::string()); + MOCK_CONST_METHOD0(initial_offerer, bool()); + MOCK_CONST_METHOD0(GetTransceiversInternal, + std::vector>>()); MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*)); MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*)); + MOCK_METHOD0(SignalDataChannelCreated, sigslot::signal1&()); + MOCK_CONST_METHOD0(rtp_data_channel, cricket::RtpDataChannel*()); + MOCK_CONST_METHOD0(sctp_data_channels, + std::vector>()); + MOCK_CONST_METHOD0(sctp_content_name, absl::optional()); + MOCK_CONST_METHOD0(sctp_transport_name, absl::optional()); + MOCK_CONST_METHOD0(GetPooledCandidateStats, cricket::CandidateStatsList()); + + typedef std::map TransportNamesByMid; + MOCK_CONST_METHOD0(GetTransportNamesByMid, TransportNamesByMid()); + + typedef std::map TransportStatsByNames; + MOCK_METHOD1(GetTransportStatsByNames, + TransportStatsByNames(const std::set&)); MOCK_METHOD0(GetCallStats, Call::Stats()); MOCK_METHOD2(GetLocalCertificate, - bool(const std::string& transport_name, - rtc::scoped_refptr* certificate)); - - // Workaround for gmock's inability to cope with move-only return values. - std::unique_ptr GetRemoteSSLCertificate( - const std::string& transport_name) /* override */ { - return std::unique_ptr( - GetRemoteSSLCertificate_ReturnsRawPointer(transport_name)); - } - MOCK_METHOD1(GetRemoteSSLCertificate_ReturnsRawPointer, - rtc::SSLCertificate*(const std::string& transport_name)); + bool(const std::string&, + rtc::scoped_refptr*)); + MOCK_METHOD1(GetRemoteSSLCertChain, + std::unique_ptr(const std::string&)); + MOCK_CONST_METHOD1(IceRestartPending, bool(const std::string&)); + MOCK_CONST_METHOD1(NeedsIceRestart, bool(const std::string&)); + MOCK_METHOD2(GetSslRole, + bool(const std::string& content_name, rtc::SSLRole*)); }; } // namespace webrtc