Add new constructor for TestUDPPort

The new constructor exposes an already existing constructor,
and is used to create a (test) UDPPort
with a socket...so that one does not (really) need a
socket factory.

Bug: b/339018639
Change-Id: Ib591fe6ae61519fe29cdea819192694448b071e0
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/356141
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42571}
This commit is contained in:
Jonas Oreland 2024-07-02 13:46:59 +02:00 committed by WebRTC LUCI CQ
parent f101f3f803
commit a58047d4e9
2 changed files with 22 additions and 0 deletions

View File

@ -1014,6 +1014,7 @@ if (rtc_include_tests) {
"../rtc_base:task_queue_for_test", "../rtc_base:task_queue_for_test",
"../rtc_base:threading", "../rtc_base:threading",
"../rtc_base/memory:always_valid_pointer", "../rtc_base/memory:always_valid_pointer",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings:string_view", "//third_party/abseil-cpp/absl/strings:string_view",
] ]
} }

View File

@ -16,6 +16,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "p2p/base/basic_packet_socket_factory.h" #include "p2p/base/basic_packet_socket_factory.h"
#include "p2p/base/port_allocator.h" #include "p2p/base/port_allocator.h"
@ -47,6 +48,18 @@ class TestUDPPort : public UDPPort {
return port; return port;
} }
static std::unique_ptr<TestUDPPort> Create(
const PortParametersRef& args,
rtc::AsyncPacketSocket* socket,
bool emit_localhost_for_anyaddress) {
auto port = absl::WrapUnique(
new TestUDPPort(args, socket, emit_localhost_for_anyaddress));
if (!port->Init()) {
return nullptr;
}
return port;
}
protected: protected:
TestUDPPort(const PortParametersRef& args, TestUDPPort(const PortParametersRef& args,
uint16_t min_port, uint16_t min_port,
@ -57,6 +70,14 @@ class TestUDPPort : public UDPPort {
min_port, min_port,
max_port, max_port,
emit_localhost_for_anyaddress) {} emit_localhost_for_anyaddress) {}
TestUDPPort(const PortParametersRef& args,
rtc::AsyncPacketSocket* socket,
bool emit_localhost_for_anyaddress)
: UDPPort(args,
webrtc::IceCandidateType::kHost,
socket,
emit_localhost_for_anyaddress) {}
}; };
// A FakePortAllocatorSession can be used with either a real or fake socket // A FakePortAllocatorSession can be used with either a real or fake socket