From b24b1ceb480455d6cac1f907eb5bd1afbb402723 Mon Sep 17 00:00:00 2001 From: hbos Date: Tue, 16 Aug 2016 01:19:43 -0700 Subject: [PATCH] Moving mock classes around so that they may be reused in other unittests New files, classes moved from statscollector_unittest.cc: +webrtc/api/test/mock_peerconnection.h for MockPeerConnectionFactory and MockPeerConnection +webrtc/api/test/mock_webrtcsession.h for MockWebRtcSession +webrtc/media/base/test/mock_mediachannel.h for MockVideoMediaChannel and MockVoiceMediaChannel The webrtc/media/base/test folder is new. BUG=chromium:627816 Review-Url: https://codereview.webrtc.org/2238933002 Cr-Commit-Position: refs/heads/master@{#13769} --- webrtc/api/BUILD.gn | 2 + webrtc/api/api_tests.gyp | 2 + webrtc/api/statscollector_unittest.cc | 70 +--------------------- webrtc/api/test/mock_peerconnection.h | 38 ++++++++++++ webrtc/api/test/mock_webrtcsession.h | 62 +++++++++++++++++++ webrtc/media/BUILD.gn | 1 + webrtc/media/base/test/mock_mediachannel.h | 35 +++++++++++ webrtc/media/media.gyp | 1 + 8 files changed, 144 insertions(+), 67 deletions(-) create mode 100644 webrtc/api/test/mock_peerconnection.h create mode 100644 webrtc/api/test/mock_webrtcsession.h create mode 100644 webrtc/media/base/test/mock_mediachannel.h diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn index 1a4619198f..a8e27d6aa6 100644 --- a/webrtc/api/BUILD.gn +++ b/webrtc/api/BUILD.gn @@ -333,6 +333,8 @@ if (rtc_include_tests) { "test/fakeperiodicvideocapturer.h", "test/fakertccertificategenerator.h", "test/fakevideotrackrenderer.h", + "test/mock_peerconnection.h", + "test/mock_webrtcsession.h", "test/mockpeerconnectionobservers.h", "test/peerconnectiontestwrapper.cc", "test/peerconnectiontestwrapper.h", diff --git a/webrtc/api/api_tests.gyp b/webrtc/api/api_tests.gyp index 5ff062a1b4..73aebaaac3 100644 --- a/webrtc/api/api_tests.gyp +++ b/webrtc/api/api_tests.gyp @@ -49,6 +49,8 @@ 'test/fakeperiodicvideocapturer.h', 'test/fakertccertificategenerator.h', 'test/fakevideotrackrenderer.h', + 'test/mock_peerconnection.h', + 'test/mock_webrtcsession.h', 'test/mockpeerconnectionobservers.h', 'test/peerconnectiontestwrapper.h', 'test/peerconnectiontestwrapper.cc', diff --git a/webrtc/api/statscollector_unittest.cc b/webrtc/api/statscollector_unittest.cc index e0657a1b95..f71a168e06 100644 --- a/webrtc/api/statscollector_unittest.cc +++ b/webrtc/api/statscollector_unittest.cc @@ -24,12 +24,15 @@ #include "webrtc/api/peerconnectionfactory.h" #include "webrtc/api/test/fakedatachannelprovider.h" #include "webrtc/api/test/fakevideotracksource.h" +#include "webrtc/api/test/mock_peerconnection.h" +#include "webrtc/api/test/mock_webrtcsession.h" #include "webrtc/api/videotrack.h" #include "webrtc/base/base64.h" #include "webrtc/base/fakesslidentity.h" #include "webrtc/base/gunit.h" #include "webrtc/base/network.h" #include "webrtc/media/base/fakemediaengine.h" +#include "webrtc/media/base/test/mock_mediachannel.h" #include "webrtc/p2p/base/faketransportcontroller.h" #include "webrtc/pc/channelmanager.h" @@ -65,73 +68,6 @@ const char kLocalTrackId[] = "local_track_id"; const char kRemoteTrackId[] = "remote_track_id"; const uint32_t kSsrcOfTrack = 1234; -class MockWebRtcSession : public webrtc::WebRtcSession { - public: - // TODO(nisse): Valid overrides commented out, because the gmock - // methods don't use any override declarations, and we want to avoid - // warnings from -Winconsistent-missing-override. See - // http://crbug.com/428099. - explicit MockWebRtcSession(webrtc::MediaControllerInterface* media_controller) - : WebRtcSession( - media_controller, - rtc::Thread::Current(), - rtc::Thread::Current(), - rtc::Thread::Current(), - nullptr, - std::unique_ptr( - new cricket::TransportController(rtc::Thread::Current(), - rtc::Thread::Current(), - nullptr))) {} - MOCK_METHOD0(voice_channel, cricket::VoiceChannel*()); - MOCK_METHOD0(video_channel, cricket::VideoChannel*()); - // Libjingle uses "local" for a outgoing track, and "remote" for a incoming - // track. - MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*)); - MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*)); - MOCK_METHOD1(GetTransportStats, bool(SessionStats*)); - 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)); -}; - -// The factory isn't really used; it just satisfies the base PeerConnection. -class FakePeerConnectionFactory - : public rtc::RefCountedObject {}; - -class MockPeerConnection - : public rtc::RefCountedObject { - public: - MockPeerConnection() - : rtc::RefCountedObject( - new FakePeerConnectionFactory()) {} - MOCK_METHOD0(session, WebRtcSession*()); - MOCK_CONST_METHOD0(sctp_data_channels, - const std::vector>&()); -}; - -class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel { - public: - MockVideoMediaChannel() : - cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {} - MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*)); -}; - -class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel { - public: - MockVoiceMediaChannel() : - cricket::FakeVoiceMediaChannel(NULL, cricket::AudioOptions()) {} - MOCK_METHOD1(GetStats, bool(cricket::VoiceMediaInfo*)); -}; - class FakeAudioProcessor : public webrtc::AudioProcessorInterface { public: FakeAudioProcessor() {} diff --git a/webrtc/api/test/mock_peerconnection.h b/webrtc/api/test/mock_peerconnection.h new file mode 100644 index 0000000000..21b24a932e --- /dev/null +++ b/webrtc/api/test/mock_peerconnection.h @@ -0,0 +1,38 @@ +/* + * 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 WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_ +#define WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_ + +#include + +#include "webrtc/api/peerconnection.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace webrtc { + +// The factory isn't really used; it just satisfies the base PeerConnection. +class FakePeerConnectionFactory + : public rtc::RefCountedObject {}; + +class MockPeerConnection + : public rtc::RefCountedObject { + public: + MockPeerConnection() + : rtc::RefCountedObject( + new FakePeerConnectionFactory()) {} + MOCK_METHOD0(session, WebRtcSession*()); + MOCK_CONST_METHOD0(sctp_data_channels, + const std::vector>&()); +}; + +} // namespace webrtc + +#endif // WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_ diff --git a/webrtc/api/test/mock_webrtcsession.h b/webrtc/api/test/mock_webrtcsession.h new file mode 100644 index 0000000000..459e3490db --- /dev/null +++ b/webrtc/api/test/mock_webrtcsession.h @@ -0,0 +1,62 @@ +/* + * 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 WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_ +#define WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_ + +#include +#include + +#include "webrtc/api/webrtcsession.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace webrtc { + +class MockWebRtcSession : public webrtc::WebRtcSession { + public: + // TODO(nisse): Valid overrides commented out, because the gmock + // methods don't use any override declarations, and we want to avoid + // warnings from -Winconsistent-missing-override. See + // http://crbug.com/428099. + explicit MockWebRtcSession(MediaControllerInterface* media_controller) + : WebRtcSession( + media_controller, + rtc::Thread::Current(), + rtc::Thread::Current(), + rtc::Thread::Current(), + nullptr, + std::unique_ptr( + new cricket::TransportController(rtc::Thread::Current(), + rtc::Thread::Current(), + nullptr))) {} + MOCK_METHOD0(voice_channel, cricket::VoiceChannel*()); + MOCK_METHOD0(video_channel, cricket::VideoChannel*()); + // Libjingle uses "local" for a outgoing track, and "remote" for a incoming + // track. + MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*)); + MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*)); + MOCK_METHOD1(GetTransportStats, bool(SessionStats*)); + 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)); +}; + +} // namespace webrtc + +#endif // WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_ diff --git a/webrtc/media/BUILD.gn b/webrtc/media/BUILD.gn index 9689cd2f12..a00fe6fe35 100644 --- a/webrtc/media/BUILD.gn +++ b/webrtc/media/BUILD.gn @@ -229,6 +229,7 @@ if (rtc_include_tests) { "base/fakertp.h", "base/fakevideocapturer.h", "base/fakevideorenderer.h", + "base/test/mock_mediachannel.h", "base/testutils.cc", "base/testutils.h", "engine/fakewebrtccall.cc", diff --git a/webrtc/media/base/test/mock_mediachannel.h b/webrtc/media/base/test/mock_mediachannel.h new file mode 100644 index 0000000000..6330fe0258 --- /dev/null +++ b/webrtc/media/base/test/mock_mediachannel.h @@ -0,0 +1,35 @@ +/* + * 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 WEBRTC_MEDIA_BASE_TEST_MOCK_MEDIACHANNEL_H_ +#define WEBRTC_MEDIA_BASE_TEST_MOCK_MEDIACHANNEL_H_ + +#include "webrtc/media/base/fakemediaengine.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace webrtc { + +class MockVideoMediaChannel : public cricket::FakeVideoMediaChannel { + public: + MockVideoMediaChannel() : + cricket::FakeVideoMediaChannel(NULL, cricket::VideoOptions()) {} + MOCK_METHOD1(GetStats, bool(cricket::VideoMediaInfo*)); +}; + +class MockVoiceMediaChannel : public cricket::FakeVoiceMediaChannel { + public: + MockVoiceMediaChannel() : + cricket::FakeVoiceMediaChannel(NULL, cricket::AudioOptions()) {} + MOCK_METHOD1(GetStats, bool(cricket::VoiceMediaInfo*)); +}; + +} // namespace webrtc + +#endif // WEBRTC_MEDIA_BASE_TEST_MOCK_MEDIACHANNEL_H_ diff --git a/webrtc/media/media.gyp b/webrtc/media/media.gyp index 039fdc6d5e..691f8867ca 100644 --- a/webrtc/media/media.gyp +++ b/webrtc/media/media.gyp @@ -234,6 +234,7 @@ 'base/fakertp.h', 'base/fakevideocapturer.h', 'base/fakevideorenderer.h', + 'base/test/mock_mediachannel.h', 'base/testutils.cc', 'base/testutils.h', 'engine/fakewebrtccall.cc',