OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 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 <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "webrtc/base/asyncresolverinterface.h" | 15 #include "webrtc/base/asyncresolverinterface.h" |
16 #include "webrtc/base/bind.h" | 16 #include "webrtc/base/bind.h" |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
19 #include "webrtc/base/physicalsocketserver.h" | |
20 #include "webrtc/base/ssladapter.h" | 19 #include "webrtc/base/ssladapter.h" |
21 #include "webrtc/base/virtualsocketserver.h" | 20 #include "webrtc/base/virtualsocketserver.h" |
22 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 21 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
23 #include "webrtc/p2p/base/teststunserver.h" | 22 #include "webrtc/p2p/base/teststunserver.h" |
24 #include "webrtc/p2p/stunprober/stunprober.h" | 23 #include "webrtc/p2p/stunprober/stunprober.h" |
25 | 24 |
26 using stunprober::StunProber; | 25 using stunprober::StunProber; |
27 using stunprober::AsyncCallback; | 26 using stunprober::AsyncCallback; |
28 | 27 |
29 namespace stunprober { | 28 namespace stunprober { |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
33 const rtc::SocketAddress kLocalAddr("192.168.0.1", 0); | 32 const rtc::SocketAddress kLocalAddr("192.168.0.1", 0); |
34 const rtc::SocketAddress kStunAddr1("1.1.1.1", 3478); | 33 const rtc::SocketAddress kStunAddr1("1.1.1.1", 3478); |
35 const rtc::SocketAddress kStunAddr2("1.1.1.2", 3478); | 34 const rtc::SocketAddress kStunAddr2("1.1.1.2", 3478); |
36 const rtc::SocketAddress kFailedStunAddr("1.1.1.3", 3478); | 35 const rtc::SocketAddress kFailedStunAddr("1.1.1.3", 3478); |
37 const rtc::SocketAddress kStunMappedAddr("77.77.77.77", 0); | 36 const rtc::SocketAddress kStunMappedAddr("77.77.77.77", 0); |
38 | 37 |
39 } // namespace | 38 } // namespace |
40 | 39 |
41 class StunProberTest : public testing::Test { | 40 class StunProberTest : public testing::Test { |
42 public: | 41 public: |
43 StunProberTest() | 42 StunProberTest() |
44 : pss_(new rtc::PhysicalSocketServer), | 43 : ss_(new rtc::VirtualSocketServer()), |
45 ss_(new rtc::VirtualSocketServer(pss_.get())), | |
46 main_(ss_.get()), | 44 main_(ss_.get()), |
47 result_(StunProber::SUCCESS), | 45 result_(StunProber::SUCCESS), |
48 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(), | 46 stun_server_1_(cricket::TestStunServer::Create(rtc::Thread::Current(), |
49 kStunAddr1)), | 47 kStunAddr1)), |
50 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(), | 48 stun_server_2_(cricket::TestStunServer::Create(rtc::Thread::Current(), |
51 kStunAddr2)) { | 49 kStunAddr2)) { |
52 stun_server_1_->set_fake_stun_addr(kStunMappedAddr); | 50 stun_server_1_->set_fake_stun_addr(kStunMappedAddr); |
53 stun_server_2_->set_fake_stun_addr(kStunMappedAddr); | 51 stun_server_2_->set_fake_stun_addr(kStunMappedAddr); |
54 rtc::InitializeSSL(); | 52 rtc::InitializeSSL(); |
55 } | 53 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 EXPECT_EQ(static_cast<uint32_t>(stats.num_response_received), | 110 EXPECT_EQ(static_cast<uint32_t>(stats.num_response_received), |
113 total_pings_reported); | 111 total_pings_reported); |
114 } | 112 } |
115 | 113 |
116 private: | 114 private: |
117 void StopCallback(StunProber* prober, int result) { | 115 void StopCallback(StunProber* prober, int result) { |
118 EXPECT_EQ(result, result_); | 116 EXPECT_EQ(result, result_); |
119 stopped_ = true; | 117 stopped_ = true; |
120 } | 118 } |
121 | 119 |
122 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | |
123 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 120 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
124 rtc::AutoSocketServerThread main_; | 121 rtc::AutoSocketServerThread main_; |
125 std::unique_ptr<StunProber> prober; | 122 std::unique_ptr<StunProber> prober; |
126 int result_ = 0; | 123 int result_ = 0; |
127 bool stopped_ = false; | 124 bool stopped_ = false; |
128 std::unique_ptr<cricket::TestStunServer> stun_server_1_; | 125 std::unique_ptr<cricket::TestStunServer> stun_server_1_; |
129 std::unique_ptr<cricket::TestStunServer> stun_server_2_; | 126 std::unique_ptr<cricket::TestStunServer> stun_server_2_; |
130 }; | 127 }; |
131 | 128 |
132 TEST_F(StunProberTest, NonSharedMode) { | 129 TEST_F(StunProberTest, NonSharedMode) { |
133 RunProber(false); | 130 RunProber(false); |
134 } | 131 } |
135 | 132 |
136 TEST_F(StunProberTest, SharedMode) { | 133 TEST_F(StunProberTest, SharedMode) { |
137 RunProber(true); | 134 RunProber(true); |
138 } | 135 } |
139 | 136 |
140 } // namespace stunprober | 137 } // namespace stunprober |
OLD | NEW |