dcsctp: Add transmission_control_block_test

This component is mostly "glue" and is heavily tested in the
socket tests, but not the ToString method, which results in
getting "low test coverage" warnings.

So for the sake of it, add a test that verifies that it works.

Bug: None
Change-Id: Id2b75e2798f334452be50631ef1ff15f53fe4157
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300441
Reviewed-by: Florent Castelli <orphis@webrtc.org>
Commit-Queue: Victor Boivie <boivie@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39826}
diff --git a/net/dcsctp/socket/BUILD.gn b/net/dcsctp/socket/BUILD.gn
index 92ce413..aeb157b 100644
--- a/net/dcsctp/socket/BUILD.gn
+++ b/net/dcsctp/socket/BUILD.gn
@@ -225,6 +225,7 @@
       ":mock_context",
       ":packet_sender",
       ":stream_reset_handler",
+      ":transmission_control_block",
       "../../../api:array_view",
       "../../../api:create_network_emulation_manager",
       "../../../api:network_emulation_manager_api",
@@ -273,6 +274,7 @@
       "packet_sender_test.cc",
       "state_cookie_test.cc",
       "stream_reset_handler_test.cc",
+      "transmission_control_block_test.cc",
     ]
   }
 }
diff --git a/net/dcsctp/socket/transmission_control_block_test.cc b/net/dcsctp/socket/transmission_control_block_test.cc
new file mode 100644
index 0000000..40aea58
--- /dev/null
+++ b/net/dcsctp/socket/transmission_control_block_test.cc
@@ -0,0 +1,119 @@
+/*
+ *  Copyright (c) 2023 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/socket/transmission_control_block.h"
+
+#include <array>
+#include <cstdint>
+#include <memory>
+#include <type_traits>
+#include <vector>
+
+#include "absl/types/optional.h"
+#include "api/array_view.h"
+#include "api/task_queue/task_queue_base.h"
+#include "net/dcsctp/common/handover_testing.h"
+#include "net/dcsctp/common/internal_types.h"
+#include "net/dcsctp/packet/chunk/reconfig_chunk.h"
+#include "net/dcsctp/packet/parameter/incoming_ssn_reset_request_parameter.h"
+#include "net/dcsctp/packet/parameter/outgoing_ssn_reset_request_parameter.h"
+#include "net/dcsctp/packet/parameter/parameter.h"
+#include "net/dcsctp/packet/parameter/reconfiguration_response_parameter.h"
+#include "net/dcsctp/public/dcsctp_message.h"
+#include "net/dcsctp/rx/data_tracker.h"
+#include "net/dcsctp/rx/reassembly_queue.h"
+#include "net/dcsctp/socket/capabilities.h"
+#include "net/dcsctp/socket/mock_context.h"
+#include "net/dcsctp/socket/mock_dcsctp_socket_callbacks.h"
+#include "net/dcsctp/testing/data_generator.h"
+#include "net/dcsctp/testing/testing_macros.h"
+#include "net/dcsctp/timer/timer.h"
+#include "net/dcsctp/tx/mock_send_queue.h"
+#include "net/dcsctp/tx/retransmission_queue.h"
+#include "rtc_base/gunit.h"
+#include "test/gmock.h"
+
+namespace dcsctp {
+namespace {
+using ::testing::Return;
+using ::testing::StrictMock;
+
+constexpr VerificationTag kMyVerificationTag = VerificationTag(123);
+constexpr VerificationTag kPeerVerificationTag = VerificationTag(456);
+constexpr TSN kMyInitialTsn = TSN(10);
+constexpr TSN kPeerInitialTsn = TSN(1000);
+constexpr size_t kArwnd = 65536;
+constexpr TieTag kTieTag = TieTag(12345678);
+
+class TransmissionControlBlockTest : public testing::Test {
+ protected:
+  TransmissionControlBlockTest()
+      : sender_(callbacks_, on_send_fn_.AsStdFunction()),
+        timer_manager_([this](webrtc::TaskQueueBase::DelayPrecision precision) {
+          return callbacks_.CreateTimeout(precision);
+        }) {}
+
+  DcSctpOptions options_;
+  Capabilities capabilities_;
+  StrictMock<MockDcSctpSocketCallbacks> callbacks_;
+  StrictMock<MockSendQueue> send_queue_;
+  testing::MockFunction<void(rtc::ArrayView<const uint8_t>, SendPacketStatus)>
+      on_send_fn_;
+  testing::MockFunction<bool()> on_connection_established;
+  PacketSender sender_;
+  TimerManager timer_manager_;
+};
+
+TEST_F(TransmissionControlBlockTest, LogsBasicInfoInToString) {
+  EXPECT_CALL(send_queue_, EnableMessageInterleaving);
+
+  capabilities_.negotiated_maximum_incoming_streams = 1000;
+  capabilities_.negotiated_maximum_outgoing_streams = 2000;
+  TransmissionControlBlock tcb(
+      timer_manager_, "log: ", options_, capabilities_, callbacks_, send_queue_,
+      kMyVerificationTag, kMyInitialTsn, kPeerVerificationTag, kPeerInitialTsn,
+      kArwnd, kTieTag, sender_, on_connection_established.AsStdFunction());
+
+  EXPECT_EQ(tcb.ToString(),
+            "verification_tag=000001c8, last_cumulative_ack=999, capabilities= "
+            "max_in=1000 max_out=2000");
+}
+
+TEST_F(TransmissionControlBlockTest, LogsAllCapabilitiesInToSring) {
+  EXPECT_CALL(send_queue_, EnableMessageInterleaving);
+
+  capabilities_.negotiated_maximum_incoming_streams = 1000;
+  capabilities_.negotiated_maximum_outgoing_streams = 2000;
+  capabilities_.message_interleaving = true;
+  capabilities_.partial_reliability = true;
+  capabilities_.reconfig = true;
+
+  TransmissionControlBlock tcb(
+      timer_manager_, "log: ", options_, capabilities_, callbacks_, send_queue_,
+      kMyVerificationTag, kMyInitialTsn, kPeerVerificationTag, kPeerInitialTsn,
+      kArwnd, kTieTag, sender_, on_connection_established.AsStdFunction());
+
+  EXPECT_EQ(tcb.ToString(),
+            "verification_tag=000001c8, last_cumulative_ack=999, "
+            "capabilities=PR,IL,Reconfig, max_in=1000 max_out=2000");
+}
+
+TEST_F(TransmissionControlBlockTest, IsInitiallyHandoverReady) {
+  EXPECT_CALL(send_queue_, EnableMessageInterleaving);
+  EXPECT_CALL(send_queue_, HasStreamsReadyToBeReset).WillOnce(Return(false));
+
+  TransmissionControlBlock tcb(
+      timer_manager_, "log: ", options_, capabilities_, callbacks_, send_queue_,
+      kMyVerificationTag, kMyInitialTsn, kPeerVerificationTag, kPeerInitialTsn,
+      kArwnd, kTieTag, sender_, on_connection_established.AsStdFunction());
+
+  EXPECT_TRUE(tcb.GetHandoverReadiness().IsReady());
+}
+}  // namespace
+}  // namespace dcsctp