1 /*
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"
12
13 #include <memory>
14 #include <utility>
15
16 #include "api/ice_transport_factory.h"
17 #include "api/make_ref_counted.h"
18 #include "api/scoped_refptr.h"
19 #include "p2p/base/fake_ice_transport.h"
20 #include "p2p/base/fake_port_allocator.h"
21 #include "rtc_base/internal/default_socket_server.h"
22 #include "test/gtest.h"
23
24 namespace webrtc {
25
26 class IceTransportTest : public ::testing::Test {
27 protected:
IceTransportTest()28 IceTransportTest()
29 : socket_server_(rtc::CreateDefaultSocketServer()),
30 main_thread_(socket_server_.get()) {}
31
socket_server() const32 rtc::SocketServer* socket_server() const { return socket_server_.get(); }
33
34 private:
35 std::unique_ptr<rtc::SocketServer> socket_server_;
36 rtc::AutoSocketServerThread main_thread_;
37 };
38
TEST_F(IceTransportTest,CreateNonSelfDeletingTransport)39 TEST_F(IceTransportTest, CreateNonSelfDeletingTransport) {
40 auto cricket_transport =
41 std::make_unique<cricket::FakeIceTransport>("name", 0, nullptr);
42 auto ice_transport =
43 rtc::make_ref_counted<IceTransportWithPointer>(cricket_transport.get());
44 EXPECT_EQ(ice_transport->internal(), cricket_transport.get());
45 ice_transport->Clear();
46 EXPECT_NE(ice_transport->internal(), cricket_transport.get());
47 }
48
TEST_F(IceTransportTest,CreateSelfDeletingTransport)49 TEST_F(IceTransportTest, CreateSelfDeletingTransport) {
50 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
51 std::make_unique<cricket::FakePortAllocator>(
52 nullptr,
53 std::make_unique<rtc::BasicPacketSocketFactory>(socket_server())));
54 IceTransportInit init;
55 init.set_port_allocator(port_allocator.get());
56 auto ice_transport = CreateIceTransport(std::move(init));
57 EXPECT_NE(nullptr, ice_transport->internal());
58 }
59
60 } // namespace webrtc
61