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}
This commit is contained in:
parent
88e31a3fd8
commit
b24b1ceb48
@ -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",
|
||||
|
||||
@ -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',
|
||||
|
||||
@ -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<cricket::TransportController>(
|
||||
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<rtc::RTCCertificate>* certificate));
|
||||
|
||||
// Workaround for gmock's inability to cope with move-only return values.
|
||||
std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
|
||||
const std::string& transport_name) /* override */ {
|
||||
return std::unique_ptr<rtc::SSLCertificate>(
|
||||
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<PeerConnectionFactory> {};
|
||||
|
||||
class MockPeerConnection
|
||||
: public rtc::RefCountedObject<webrtc::PeerConnection> {
|
||||
public:
|
||||
MockPeerConnection()
|
||||
: rtc::RefCountedObject<webrtc::PeerConnection>(
|
||||
new FakePeerConnectionFactory()) {}
|
||||
MOCK_METHOD0(session, WebRtcSession*());
|
||||
MOCK_CONST_METHOD0(sctp_data_channels,
|
||||
const std::vector<rtc::scoped_refptr<DataChannel>>&());
|
||||
};
|
||||
|
||||
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() {}
|
||||
|
||||
38
webrtc/api/test/mock_peerconnection.h
Normal file
38
webrtc/api/test/mock_peerconnection.h
Normal file
@ -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 <vector>
|
||||
|
||||
#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<webrtc::PeerConnectionFactory> {};
|
||||
|
||||
class MockPeerConnection
|
||||
: public rtc::RefCountedObject<webrtc::PeerConnection> {
|
||||
public:
|
||||
MockPeerConnection()
|
||||
: rtc::RefCountedObject<webrtc::PeerConnection>(
|
||||
new FakePeerConnectionFactory()) {}
|
||||
MOCK_METHOD0(session, WebRtcSession*());
|
||||
MOCK_CONST_METHOD0(sctp_data_channels,
|
||||
const std::vector<rtc::scoped_refptr<DataChannel>>&());
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_API_TEST_MOCK_PEERCONNECTION_H_
|
||||
62
webrtc/api/test/mock_webrtcsession.h
Normal file
62
webrtc/api/test/mock_webrtcsession.h
Normal file
@ -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 <memory>
|
||||
#include <string>
|
||||
|
||||
#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<cricket::TransportController>(
|
||||
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<rtc::RTCCertificate>* certificate));
|
||||
|
||||
// Workaround for gmock's inability to cope with move-only return values.
|
||||
std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(
|
||||
const std::string& transport_name) /* override */ {
|
||||
return std::unique_ptr<rtc::SSLCertificate>(
|
||||
GetRemoteSSLCertificate_ReturnsRawPointer(transport_name));
|
||||
}
|
||||
MOCK_METHOD1(GetRemoteSSLCertificate_ReturnsRawPointer,
|
||||
rtc::SSLCertificate*(const std::string& transport_name));
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_API_TEST_MOCK_WEBRTCSESSION_H_
|
||||
@ -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",
|
||||
|
||||
35
webrtc/media/base/test/mock_mediachannel.h
Normal file
35
webrtc/media/base/test/mock_mediachannel.h
Normal file
@ -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_
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user