OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 | 12 |
13 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
14 #include "webrtc/base/physicalsocketserver.h" | |
15 #include "webrtc/base/thread.h" | 14 #include "webrtc/base/thread.h" |
16 #include "webrtc/base/virtualsocketserver.h" | 15 #include "webrtc/base/virtualsocketserver.h" |
17 #include "webrtc/p2p/base/fakeportallocator.h" | 16 #include "webrtc/p2p/base/fakeportallocator.h" |
18 #include "webrtc/p2p/base/portallocator.h" | 17 #include "webrtc/p2p/base/portallocator.h" |
19 | 18 |
20 static const char kContentName[] = "test content"; | 19 static const char kContentName[] = "test content"; |
21 // Based on ICE_UFRAG_LENGTH | 20 // Based on ICE_UFRAG_LENGTH |
22 static const char kIceUfrag[] = "UF00"; | 21 static const char kIceUfrag[] = "UF00"; |
23 // Based on ICE_PWD_LENGTH | 22 // Based on ICE_PWD_LENGTH |
24 static const char kIcePwd[] = "TESTICEPWD00000000000000"; | 23 static const char kIcePwd[] = "TESTICEPWD00000000000000"; |
25 static const char kTurnUsername[] = "test"; | 24 static const char kTurnUsername[] = "test"; |
26 static const char kTurnPassword[] = "test"; | 25 static const char kTurnPassword[] = "test"; |
27 | 26 |
28 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { | 27 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
29 public: | 28 public: |
30 PortAllocatorTest() | 29 PortAllocatorTest() |
31 : pss_(new rtc::PhysicalSocketServer), | 30 : vss_(new rtc::VirtualSocketServer()), main_(vss_.get()) { |
32 vss_(new rtc::VirtualSocketServer(pss_.get())), | |
33 main_(vss_.get()) { | |
34 allocator_.reset( | 31 allocator_.reset( |
35 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | 32 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
36 } | 33 } |
37 | 34 |
38 protected: | 35 protected: |
39 void SetConfigurationWithPoolSize(int candidate_pool_size) { | 36 void SetConfigurationWithPoolSize(int candidate_pool_size) { |
40 EXPECT_TRUE(allocator_->SetConfiguration( | 37 EXPECT_TRUE(allocator_->SetConfiguration( |
41 cricket::ServerAddresses(), std::vector<cricket::RelayServerConfig>(), | 38 cricket::ServerAddresses(), std::vector<cricket::RelayServerConfig>(), |
42 candidate_pool_size, false)); | 39 candidate_pool_size, false)); |
43 } | 40 } |
(...skipping 30 matching lines...) Expand all Loading... |
74 | 71 |
75 int GetAllPooledSessionsReturnCount() { | 72 int GetAllPooledSessionsReturnCount() { |
76 int count = 0; | 73 int count = 0; |
77 while (GetPooledSession()) { | 74 while (GetPooledSession()) { |
78 TakePooledSession(); | 75 TakePooledSession(); |
79 ++count; | 76 ++count; |
80 } | 77 } |
81 return count; | 78 return count; |
82 } | 79 } |
83 | 80 |
84 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | |
85 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 81 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
86 rtc::AutoSocketServerThread main_; | 82 rtc::AutoSocketServerThread main_; |
87 std::unique_ptr<cricket::FakePortAllocator> allocator_; | 83 std::unique_ptr<cricket::FakePortAllocator> allocator_; |
88 rtc::SocketAddress stun_server_1{"11.11.11.11", 3478}; | 84 rtc::SocketAddress stun_server_1{"11.11.11.11", 3478}; |
89 rtc::SocketAddress stun_server_2{"22.22.22.22", 3478}; | 85 rtc::SocketAddress stun_server_2{"22.22.22.22", 3478}; |
90 cricket::RelayServerConfig turn_server_1{"11.11.11.11", 3478, | 86 cricket::RelayServerConfig turn_server_1{"11.11.11.11", 3478, |
91 kTurnUsername, kTurnPassword, | 87 kTurnUsername, kTurnPassword, |
92 cricket::PROTO_UDP, false}; | 88 cricket::PROTO_UDP, false}; |
93 cricket::RelayServerConfig turn_server_2{"22.22.22.22", 3478, | 89 cricket::RelayServerConfig turn_server_2{"22.22.22.22", 3478, |
94 kTurnUsername, kTurnPassword, | 90 kTurnUsername, kTurnPassword, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); | 268 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
273 } | 269 } |
274 | 270 |
275 // Verify that after DiscardCandidatePool, TakePooledSession doesn't return | 271 // Verify that after DiscardCandidatePool, TakePooledSession doesn't return |
276 // anything. | 272 // anything. |
277 TEST_F(PortAllocatorTest, DiscardCandidatePool) { | 273 TEST_F(PortAllocatorTest, DiscardCandidatePool) { |
278 SetConfigurationWithPoolSize(1); | 274 SetConfigurationWithPoolSize(1); |
279 allocator_->DiscardCandidatePool(); | 275 allocator_->DiscardCandidatePool(); |
280 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); | 276 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); |
281 } | 277 } |
OLD | NEW |