blob: aaf9f2e57a5092b64ef1c9b2d3f5e142f4ea0b70 [file] [log] [blame]
Harald Alvestrand4241cf52019-01-21 09:29:42 +01001/*
2 * Copyright 2019 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
11#include "pc/ice_transport.h"
Harald Alvestrand4241cf52019-01-21 09:29:42 +010012
Harald Alvestrand98462622019-01-30 14:57:03 +010013#include <memory>
14#include <utility>
Harald Alvestrand98462622019-01-30 14:57:03 +010015
Harald Alvestrand98462622019-01-30 14:57:03 +010016#include "api/ice_transport_factory.h"
Niels Möller105711e2022-06-14 15:48:26 +020017#include "api/make_ref_counted.h"
Harald Alvestrandc24a2182022-02-23 13:44:59 +000018#include "api/scoped_refptr.h"
Harald Alvestrand98462622019-01-30 14:57:03 +010019#include "p2p/base/fake_ice_transport.h"
20#include "p2p/base/fake_port_allocator.h"
Byoungchan Leed58f5262022-06-27 18:05:22 +090021#include "rtc_base/internal/default_socket_server.h"
Harald Alvestrand4241cf52019-01-21 09:29:42 +010022#include "test/gtest.h"
Sameer Vijaykar0793ee72023-01-23 16:31:29 +010023#include "test/scoped_key_value_config.h"
Harald Alvestrand4241cf52019-01-21 09:29:42 +010024
25namespace webrtc {
26
Niels Möller83830f32022-05-20 09:12:57 +020027class IceTransportTest : public ::testing::Test {
Byoungchan Leed58f5262022-06-27 18:05:22 +090028 protected:
29 IceTransportTest()
30 : socket_server_(rtc::CreateDefaultSocketServer()),
31 main_thread_(socket_server_.get()) {}
32
33 rtc::SocketServer* socket_server() const { return socket_server_.get(); }
34
Sameer Vijaykar0793ee72023-01-23 16:31:29 +010035 webrtc::test::ScopedKeyValueConfig field_trials_;
36
Niels Möller83830f32022-05-20 09:12:57 +020037 private:
Byoungchan Leed58f5262022-06-27 18:05:22 +090038 std::unique_ptr<rtc::SocketServer> socket_server_;
39 rtc::AutoSocketServerThread main_thread_;
Niels Möller83830f32022-05-20 09:12:57 +020040};
Harald Alvestrand4241cf52019-01-21 09:29:42 +010041
Harald Alvestrand98462622019-01-30 14:57:03 +010042TEST_F(IceTransportTest, CreateNonSelfDeletingTransport) {
43 auto cricket_transport =
Mirko Bonadei317a1f02019-09-17 17:06:18 +020044 std::make_unique<cricket::FakeIceTransport>("name", 0, nullptr);
Tommi87f70902021-04-27 14:43:08 +020045 auto ice_transport =
46 rtc::make_ref_counted<IceTransportWithPointer>(cricket_transport.get());
Harald Alvestrand98462622019-01-30 14:57:03 +010047 EXPECT_EQ(ice_transport->internal(), cricket_transport.get());
48 ice_transport->Clear();
49 EXPECT_NE(ice_transport->internal(), cricket_transport.get());
50}
51
52TEST_F(IceTransportTest, CreateSelfDeletingTransport) {
53 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Byoungchan Leed58f5262022-06-27 18:05:22 +090054 std::make_unique<cricket::FakePortAllocator>(
55 nullptr,
Sameer Vijaykar0793ee72023-01-23 16:31:29 +010056 std::make_unique<rtc::BasicPacketSocketFactory>(socket_server()),
57 &field_trials_));
Steve Anton6fdfec12019-07-01 14:07:33 -070058 IceTransportInit init;
59 init.set_port_allocator(port_allocator.get());
60 auto ice_transport = CreateIceTransport(std::move(init));
Harald Alvestrand98462622019-01-30 14:57:03 +010061 EXPECT_NE(nullptr, ice_transport->internal());
Harald Alvestrand4241cf52019-01-21 09:29:42 +010062}
63
64} // namespace webrtc