1 /*
2 * Copyright (c) 2021 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 #include "net/dcsctp/socket/packet_sender.h"
11
12 #include "net/dcsctp/common/internal_types.h"
13 #include "net/dcsctp/packet/chunk/cookie_ack_chunk.h"
14 #include "net/dcsctp/socket/mock_dcsctp_socket_callbacks.h"
15 #include "rtc_base/gunit.h"
16 #include "test/gmock.h"
17
18 namespace dcsctp {
19 namespace {
20 using ::testing::_;
21
22 constexpr VerificationTag kVerificationTag(123);
23
24 class PacketSenderTest : public testing::Test {
25 protected:
PacketSenderTest()26 PacketSenderTest() : sender_(callbacks_, on_send_fn_.AsStdFunction()) {}
27
PacketBuilder() const28 SctpPacket::Builder PacketBuilder() const {
29 return SctpPacket::Builder(kVerificationTag, options_);
30 }
31
32 DcSctpOptions options_;
33 testing::NiceMock<MockDcSctpSocketCallbacks> callbacks_;
34 testing::MockFunction<void(rtc::ArrayView<const uint8_t>, SendPacketStatus)>
35 on_send_fn_;
36 PacketSender sender_;
37 };
38
TEST_F(PacketSenderTest,SendPacketCallsCallback)39 TEST_F(PacketSenderTest, SendPacketCallsCallback) {
40 EXPECT_CALL(on_send_fn_, Call(_, SendPacketStatus::kSuccess));
41 EXPECT_TRUE(sender_.Send(PacketBuilder().Add(CookieAckChunk())));
42
43 EXPECT_CALL(callbacks_, SendPacketWithStatus)
44 .WillOnce(testing::Return(SendPacketStatus::kError));
45 EXPECT_CALL(on_send_fn_, Call(_, SendPacketStatus::kError));
46 EXPECT_FALSE(sender_.Send(PacketBuilder().Add(CookieAckChunk())));
47 }
48
49 } // namespace
50 } // namespace dcsctp
51