dcsctp: Add mocks
This is for convenience to the users of dcSCTP, which may want to have unit tests where the socket is mocked. And since it's best practice not to mock other teams' or project's classes, a mock will be provided by the upstream project - this one. Bug: webrtc:12614 Change-Id: I65d5d21097e7feda9162567560d3838759c962fc Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/224161 Reviewed-by: Florent Castelli <orphis@webrtc.org> Commit-Queue: Victor Boivie <boivie@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34385}
This commit is contained in:
parent
da9dfae850
commit
c362eb2d1c
@ -56,11 +56,21 @@ rtc_source_set("factory") {
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||
}
|
||||
|
||||
rtc_source_set("mocks") {
|
||||
testonly = true
|
||||
sources = [ "mock_dcsctp_socket.h" ]
|
||||
deps = [
|
||||
":socket",
|
||||
"../../../test:test_support",
|
||||
]
|
||||
}
|
||||
|
||||
if (rtc_include_tests) {
|
||||
rtc_library("dcsctp_public_unittests") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
":mocks",
|
||||
":strong_alias",
|
||||
":types",
|
||||
"../../../rtc_base:checks",
|
||||
@ -69,6 +79,7 @@ if (rtc_include_tests) {
|
||||
"../../../test:test_support",
|
||||
]
|
||||
sources = [
|
||||
"mock_dcsctp_socket_test.cc",
|
||||
"strong_alias_test.cc",
|
||||
"types_test.cc",
|
||||
]
|
||||
|
||||
64
net/dcsctp/public/mock_dcsctp_socket.h
Normal file
64
net/dcsctp/public/mock_dcsctp_socket.h
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 NET_DCSCTP_PUBLIC_MOCK_DCSCTP_SOCKET_H_
|
||||
#define NET_DCSCTP_PUBLIC_MOCK_DCSCTP_SOCKET_H_
|
||||
|
||||
#include "net/dcsctp/public/dcsctp_socket.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
||||
class MockDcSctpSocket : public DcSctpSocketInterface {
|
||||
public:
|
||||
MOCK_METHOD(void,
|
||||
ReceivePacket,
|
||||
(rtc::ArrayView<const uint8_t> data),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(void, HandleTimeout, (TimeoutID timeout_id), (override));
|
||||
|
||||
MOCK_METHOD(void, Connect, (), (override));
|
||||
|
||||
MOCK_METHOD(void, Shutdown, (), (override));
|
||||
|
||||
MOCK_METHOD(void, Close, (), (override));
|
||||
|
||||
MOCK_METHOD(SocketState, state, (), (const, override));
|
||||
|
||||
MOCK_METHOD(const DcSctpOptions&, options, (), (const, override));
|
||||
|
||||
MOCK_METHOD(void, SetMaxMessageSize, (size_t max_message_size), (override));
|
||||
|
||||
MOCK_METHOD(SendStatus,
|
||||
Send,
|
||||
(DcSctpMessage message, const SendOptions& send_options),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(ResetStreamsStatus,
|
||||
ResetStreams,
|
||||
(rtc::ArrayView<const StreamID> outgoing_streams),
|
||||
(override));
|
||||
|
||||
MOCK_METHOD(size_t, buffered_amount, (StreamID stream_id), (const, override));
|
||||
|
||||
MOCK_METHOD(size_t,
|
||||
buffered_amount_low_threshold,
|
||||
(StreamID stream_id),
|
||||
(const, override));
|
||||
|
||||
MOCK_METHOD(void,
|
||||
SetBufferedAmountLowThreshold,
|
||||
(StreamID stream_id, size_t bytes),
|
||||
(override));
|
||||
};
|
||||
|
||||
} // namespace dcsctp
|
||||
|
||||
#endif // NET_DCSCTP_PUBLIC_MOCK_DCSCTP_SOCKET_H_
|
||||
27
net/dcsctp/public/mock_dcsctp_socket_test.cc
Normal file
27
net/dcsctp/public/mock_dcsctp_socket_test.cc
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
#include "net/dcsctp/public/mock_dcsctp_socket.h"
|
||||
|
||||
#include "rtc_base/gunit.h"
|
||||
#include "test/gmock.h"
|
||||
|
||||
namespace dcsctp {
|
||||
|
||||
// This test exists to ensure that all methods are mocked correctly, and to
|
||||
// generate compiler errors if they are not.
|
||||
TEST(MockDcSctpSocketTest, CanInstantiateAndConnect) {
|
||||
testing::StrictMock<MockDcSctpSocket> socket;
|
||||
|
||||
EXPECT_CALL(socket, Connect);
|
||||
|
||||
socket.Connect();
|
||||
}
|
||||
|
||||
} // namespace dcsctp
|
||||
Loading…
x
Reference in New Issue
Block a user