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/thread.h" | 14 #include "webrtc/base/thread.h" |
15 #include "webrtc/p2p/base/fakeportallocator.h" | 15 #include "webrtc/p2p/base/fakeportallocator.h" |
16 #include "webrtc/p2p/base/portallocator.h" | 16 #include "webrtc/p2p/base/portallocator.h" |
17 | 17 |
18 static const char kSessionId[] = "session id"; | |
19 static const char kContentName[] = "test content"; | 18 static const char kContentName[] = "test content"; |
20 // Based on ICE_UFRAG_LENGTH | 19 // Based on ICE_UFRAG_LENGTH |
21 static const char kIceUfrag[] = "UF00"; | 20 static const char kIceUfrag[] = "UF00"; |
22 // Based on ICE_PWD_LENGTH | 21 // Based on ICE_PWD_LENGTH |
23 static const char kIcePwd[] = "TESTICEPWD00000000000000"; | 22 static const char kIcePwd[] = "TESTICEPWD00000000000000"; |
24 static const char kTurnUsername[] = "test"; | 23 static const char kTurnUsername[] = "test"; |
25 static const char kTurnPassword[] = "test"; | 24 static const char kTurnPassword[] = "test"; |
26 | 25 |
27 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { | 26 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
28 public: | 27 public: |
29 PortAllocatorTest() { | 28 PortAllocatorTest() { |
30 allocator_.reset( | 29 allocator_.reset( |
31 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | 30 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
32 } | 31 } |
33 | 32 |
34 protected: | 33 protected: |
35 void SetConfigurationWithPoolSize(int candidate_pool_size) { | 34 void SetConfigurationWithPoolSize(int candidate_pool_size) { |
36 allocator_->SetConfiguration(cricket::ServerAddresses(), | 35 allocator_->SetConfiguration(cricket::ServerAddresses(), |
37 std::vector<cricket::RelayServerConfig>(), | 36 std::vector<cricket::RelayServerConfig>(), |
38 candidate_pool_size, false); | 37 candidate_pool_size, false); |
39 } | 38 } |
40 | 39 |
41 std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession( | 40 std::unique_ptr<cricket::FakePortAllocatorSession> CreateSession( |
42 const std::string& sid, | |
43 const std::string& content_name, | 41 const std::string& content_name, |
44 int component, | 42 int component, |
45 const std::string& ice_ufrag, | 43 const std::string& ice_ufrag, |
46 const std::string& ice_pwd) { | 44 const std::string& ice_pwd) { |
47 return std::unique_ptr<cricket::FakePortAllocatorSession>( | 45 return std::unique_ptr<cricket::FakePortAllocatorSession>( |
48 static_cast<cricket::FakePortAllocatorSession*>( | 46 static_cast<cricket::FakePortAllocatorSession*>( |
49 allocator_ | 47 allocator_ |
50 ->CreateSession(sid, content_name, component, ice_ufrag, | 48 ->CreateSession(content_name, component, ice_ufrag, ice_pwd) |
51 ice_pwd) | |
52 .release())); | 49 .release())); |
53 } | 50 } |
54 | 51 |
55 const cricket::FakePortAllocatorSession* GetPooledSession() const { | 52 const cricket::FakePortAllocatorSession* GetPooledSession() const { |
56 return static_cast<const cricket::FakePortAllocatorSession*>( | 53 return static_cast<const cricket::FakePortAllocatorSession*>( |
57 allocator_->GetPooledSession()); | 54 allocator_->GetPooledSession()); |
58 } | 55 } |
59 | 56 |
60 std::unique_ptr<cricket::FakePortAllocatorSession> TakePooledSession() { | 57 std::unique_ptr<cricket::FakePortAllocatorSession> TakePooledSession() { |
61 return std::unique_ptr<cricket::FakePortAllocatorSession>( | 58 return std::unique_ptr<cricket::FakePortAllocatorSession>( |
(...skipping 26 matching lines...) Expand all Loading... |
88 EXPECT_EQ(0UL, allocator_->stun_servers().size()); | 85 EXPECT_EQ(0UL, allocator_->stun_servers().size()); |
89 EXPECT_EQ(0UL, allocator_->turn_servers().size()); | 86 EXPECT_EQ(0UL, allocator_->turn_servers().size()); |
90 EXPECT_EQ(0, allocator_->candidate_pool_size()); | 87 EXPECT_EQ(0, allocator_->candidate_pool_size()); |
91 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); | 88 EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); |
92 } | 89 } |
93 | 90 |
94 // Call CreateSession and verify that the parameters passed in and the | 91 // Call CreateSession and verify that the parameters passed in and the |
95 // candidate filter are applied as expected. | 92 // candidate filter are applied as expected. |
96 TEST_F(PortAllocatorTest, CreateSession) { | 93 TEST_F(PortAllocatorTest, CreateSession) { |
97 allocator_->set_candidate_filter(cricket::CF_RELAY); | 94 allocator_->set_candidate_filter(cricket::CF_RELAY); |
98 auto session = CreateSession(kSessionId, kContentName, 1, kIceUfrag, kIcePwd); | 95 auto session = CreateSession(kContentName, 1, kIceUfrag, kIcePwd); |
99 ASSERT_NE(nullptr, session); | 96 ASSERT_NE(nullptr, session); |
100 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); | 97 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
101 EXPECT_EQ(kContentName, session->content_name()); | 98 EXPECT_EQ(kContentName, session->content_name()); |
102 EXPECT_EQ(1, session->component()); | 99 EXPECT_EQ(1, session->component()); |
103 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); | 100 EXPECT_EQ(kIceUfrag, session->ice_ufrag()); |
104 EXPECT_EQ(kIcePwd, session->ice_pwd()); | 101 EXPECT_EQ(kIcePwd, session->ice_pwd()); |
105 } | 102 } |
106 | 103 |
107 TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { | 104 TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { |
108 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; | 105 cricket::ServerAddresses stun_servers_1 = {stun_server_1}; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // unfiltered until it's returned by TakePooledSession. | 235 // unfiltered until it's returned by TakePooledSession. |
239 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { | 236 TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { |
240 allocator_->set_candidate_filter(cricket::CF_RELAY); | 237 allocator_->set_candidate_filter(cricket::CF_RELAY); |
241 SetConfigurationWithPoolSize(1); | 238 SetConfigurationWithPoolSize(1); |
242 auto peeked_session = GetPooledSession(); | 239 auto peeked_session = GetPooledSession(); |
243 ASSERT_NE(nullptr, peeked_session); | 240 ASSERT_NE(nullptr, peeked_session); |
244 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); | 241 EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); |
245 auto session = TakePooledSession(); | 242 auto session = TakePooledSession(); |
246 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); | 243 EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); |
247 } | 244 } |
OLD | NEW |