Harald Alvestrand | 4241cf5 | 2019-01-21 08:29:42 | [diff] [blame] | 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" |
Harald Alvestrand | 4241cf5 | 2019-01-21 08:29:42 | [diff] [blame] | 12 | |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 13 | #include <memory> |
| 14 | #include <utility> |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 15 | |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 16 | #include "api/ice_transport_factory.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 17 | #include "api/scoped_refptr.h" |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 18 | #include "p2p/base/fake_ice_transport.h" |
| 19 | #include "p2p/base/fake_port_allocator.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 20 | #include "rtc_base/ref_counted_object.h" |
Harald Alvestrand | 4241cf5 | 2019-01-21 08:29:42 | [diff] [blame] | 21 | #include "test/gtest.h" |
| 22 | |
| 23 | namespace webrtc { |
| 24 | |
Niels Möller | 83830f3 | 2022-05-20 07:12:57 | [diff] [blame] | 25 | class IceTransportTest : public ::testing::Test { |
| 26 | private: |
| 27 | rtc::AutoThread main_thread_; |
| 28 | }; |
Harald Alvestrand | 4241cf5 | 2019-01-21 08:29:42 | [diff] [blame] | 29 | |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 30 | TEST_F(IceTransportTest, CreateNonSelfDeletingTransport) { |
| 31 | auto cricket_transport = |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 32 | std::make_unique<cricket::FakeIceTransport>("name", 0, nullptr); |
Tommi | 87f7090 | 2021-04-27 12:43:08 | [diff] [blame] | 33 | auto ice_transport = |
| 34 | rtc::make_ref_counted<IceTransportWithPointer>(cricket_transport.get()); |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 35 | EXPECT_EQ(ice_transport->internal(), cricket_transport.get()); |
| 36 | ice_transport->Clear(); |
| 37 | EXPECT_NE(ice_transport->internal(), cricket_transport.get()); |
| 38 | } |
| 39 | |
| 40 | TEST_F(IceTransportTest, CreateSelfDeletingTransport) { |
| 41 | std::unique_ptr<cricket::FakePortAllocator> port_allocator( |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 42 | std::make_unique<cricket::FakePortAllocator>(nullptr, nullptr)); |
Steve Anton | 6fdfec1 | 2019-07-01 21:07:33 | [diff] [blame] | 43 | IceTransportInit init; |
| 44 | init.set_port_allocator(port_allocator.get()); |
| 45 | auto ice_transport = CreateIceTransport(std::move(init)); |
Harald Alvestrand | 9846262 | 2019-01-30 13:57:03 | [diff] [blame] | 46 | EXPECT_NE(nullptr, ice_transport->internal()); |
Harald Alvestrand | 4241cf5 | 2019-01-21 08:29:42 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | } // namespace webrtc |