diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:27 +0000 |
commit | 40a355a42d4a9444dc753c04c6608dade2f06a23 (patch) | |
tree | 871fc667d2de662f171103ce5ec067014ef85e61 /third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc | |
parent | Adding upstream version 124.0.1. (diff) | |
download | firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip |
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc')
-rw-r--r-- | third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc b/third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc index 72d6a7fde0..853fbb471f 100644 --- a/third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc +++ b/third_party/libwebrtc/p2p/base/async_stun_tcp_socket_unittest.cc @@ -13,12 +13,17 @@ #include <stdint.h> #include <string.h> +#include <cstdint> #include <list> #include <memory> #include <string> #include <utility> #include "absl/memory/memory.h" +#include "api/array_view.h" +#include "rtc_base/buffer.h" +#include "rtc_base/byte_buffer.h" +#include "rtc_base/network/received_packet.h" #include "rtc_base/network/sent_packet.h" #include "rtc_base/socket.h" #include "rtc_base/third_party/sigslot/sigslot.h" @@ -96,11 +101,10 @@ class AsyncStunTCPSocketTest : public ::testing::Test, } void OnReadPacket(rtc::AsyncPacketSocket* socket, - const char* data, - size_t len, - const rtc::SocketAddress& remote_addr, - const int64_t& /* packet_time_us */) { - recv_packets_.push_back(std::string(data, len)); + const rtc::ReceivedPacket& packet) { + recv_packets_.push_back( + std::string(reinterpret_cast<const char*>(packet.payload().data()), + packet.payload().size())); } void OnSentPacket(rtc::AsyncPacketSocket* socket, @@ -111,8 +115,10 @@ class AsyncStunTCPSocketTest : public ::testing::Test, void OnNewConnection(rtc::AsyncListenSocket* /*server*/, rtc::AsyncPacketSocket* new_socket) { recv_socket_ = absl::WrapUnique(new_socket); - new_socket->SignalReadPacket.connect(this, - &AsyncStunTCPSocketTest::OnReadPacket); + new_socket->RegisterReceivedPacketCallback( + [&](rtc::AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) { + OnReadPacket(socket, packet); + }); } bool Send(const void* data, size_t len) { @@ -164,6 +170,30 @@ TEST_F(AsyncStunTCPSocketTest, TestMultipleStunPackets) { EXPECT_EQ(4u, recv_packets_.size()); } +TEST_F(AsyncStunTCPSocketTest, ProcessInputHandlesMultiplePackets) { + send_socket_->RegisterReceivedPacketCallback( + [&](rtc::AsyncPacketSocket* socket, const rtc::ReceivedPacket& packet) { + recv_packets_.push_back( + std::string(reinterpret_cast<const char*>(packet.payload().data()), + packet.payload().size())); + }); + rtc::Buffer buffer; + buffer.AppendData(kStunMessageWithZeroLength, + sizeof(kStunMessageWithZeroLength)); + // ChannelData message MUST be padded to + // a multiple of four bytes. + const unsigned char kTurnChannelData[] = { + 0x40, 0x00, 0x00, 0x04, 0x21, 0x12, 0xA4, 0x42, + }; + buffer.AppendData(kTurnChannelData, sizeof(kTurnChannelData)); + + send_socket_->ProcessInput(buffer); + EXPECT_EQ(2u, recv_packets_.size()); + EXPECT_TRUE(CheckData(kStunMessageWithZeroLength, + sizeof(kStunMessageWithZeroLength))); + EXPECT_TRUE(CheckData(kTurnChannelData, sizeof(kTurnChannelData))); +} + // Verifying TURN channel data message with zero length. TEST_F(AsyncStunTCPSocketTest, TestTurnChannelDataWithZeroLength) { EXPECT_TRUE(Send(kTurnChannelDataMessageWithZeroLength, |