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 <algorithm> | 11 #include <algorithm> |
12 #include <list> | 12 #include <list> |
13 #include <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
18 #include "webrtc/base/thread.h" | 18 #include "webrtc/base/thread.h" |
19 #include "webrtc/base/asyncpacketsocket.h" | 19 #include "webrtc/base/asyncpacketsocket.h" |
20 #include "webrtc/base/ipaddress.h" | 20 #include "webrtc/base/ipaddress.h" |
21 #include "webrtc/base/physicalsocketserver.h" | 21 #include "webrtc/base/physicalsocketserver.h" |
22 #include "webrtc/base/socketaddress.h" | 22 #include "webrtc/base/socketaddress.h" |
23 #include "webrtc/base/socketserver.h" | 23 #include "webrtc/base/socketserver.h" |
24 #include "webrtc/base/virtualsocketserver.h" | 24 #include "webrtc/base/virtualsocketserver.h" |
25 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 25 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
26 #include "webrtc/p2p/base/packettransportinterface.h" | 26 #include "webrtc/p2p/base/packettransportinternal.h" |
27 #include "webrtc/p2p/base/udptransport.h" | 27 #include "webrtc/p2p/base/udptransport.h" |
28 | 28 |
29 namespace cricket { | 29 namespace cricket { |
30 | 30 |
31 constexpr int kTimeoutMs = 10000; | 31 constexpr int kTimeoutMs = 10000; |
32 static const rtc::IPAddress kIPv4LocalHostAddress = | 32 static const rtc::IPAddress kIPv4LocalHostAddress = |
33 rtc::IPAddress(0x7F000001); // 127.0.0.1 | 33 rtc::IPAddress(0x7F000001); // 127.0.0.1 |
34 | 34 |
35 class UdpTransportTest : public testing::Test, public sigslot::has_slots<> { | 35 class UdpTransportTest : public testing::Test, public sigslot::has_slots<> { |
36 public: | 36 public: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 bool CheckData(const char* data, int len) { | 74 bool CheckData(const char* data, int len) { |
75 bool ret = false; | 75 bool ret = false; |
76 if (!ch_packets_.empty()) { | 76 if (!ch_packets_.empty()) { |
77 std::string packet = ch_packets_.front(); | 77 std::string packet = ch_packets_.front(); |
78 ret = (packet == std::string(data, len)); | 78 ret = (packet == std::string(data, len)); |
79 ch_packets_.pop_front(); | 79 ch_packets_.pop_front(); |
80 } | 80 } |
81 return ret; | 81 return ret; |
82 } | 82 } |
83 | 83 |
84 void OnWritableState(rtc::PacketTransportInterface* transport) { | 84 void OnWritableState(rtc::PacketTransportInternal* transport) { |
85 num_sig_writable_++; | 85 num_sig_writable_++; |
86 } | 86 } |
87 | 87 |
88 void OnReadyToSend(rtc::PacketTransportInterface* transport) { | 88 void OnReadyToSend(rtc::PacketTransportInternal* transport) { |
89 num_sig_ready_to_send_++; | 89 num_sig_ready_to_send_++; |
90 } | 90 } |
91 | 91 |
92 void OnReadPacket(rtc::PacketTransportInterface* transport, | 92 void OnReadPacket(rtc::PacketTransportInternal* transport, |
93 const char* data, | 93 const char* data, |
94 size_t len, | 94 size_t len, |
95 const rtc::PacketTime& packet_time, | 95 const rtc::PacketTime& packet_time, |
96 int flags) { | 96 int flags) { |
97 num_received_packets_++; | 97 num_received_packets_++; |
98 LOG(LS_VERBOSE) << "OnReadPacket (unittest)"; | 98 LOG(LS_VERBOSE) << "OnReadPacket (unittest)"; |
99 ch_packets_.push_front(std::string(data, len)); | 99 ch_packets_.push_front(std::string(data, len)); |
100 } | 100 } |
101 | 101 |
102 void OnSentPacket(rtc::PacketTransportInterface* transport, | 102 void OnSentPacket(rtc::PacketTransportInternal* transport, |
103 const rtc::SentPacket&) { | 103 const rtc::SentPacket&) { |
104 num_sig_sent_packets_++; | 104 num_sig_sent_packets_++; |
105 } | 105 } |
106 | 106 |
107 int SendData(const char* data, size_t len) { | 107 int SendData(const char* data, size_t len) { |
108 rtc::PacketOptions options; | 108 rtc::PacketOptions options; |
109 return ch_->SendPacket(data, len, options, 0); | 109 return ch_->SendPacket(data, len, options, 0); |
110 } | 110 } |
111 | 111 |
112 void GetLocalPort(uint16_t* local_port) { | 112 void GetLocalPort(uint16_t* local_port) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 EXPECT_TRUE(ep1_.ch_->writable()); | 186 EXPECT_TRUE(ep1_.ch_->writable()); |
187 EXPECT_EQ(1u, ep1_.num_sig_writable_); | 187 EXPECT_EQ(1u, ep1_.num_sig_writable_); |
188 EXPECT_EQ(1u, ep1_.num_sig_ready_to_send_); | 188 EXPECT_EQ(1u, ep1_.num_sig_ready_to_send_); |
189 const char data[] = "abc"; | 189 const char data[] = "abc"; |
190 ep1_.SendData(data, sizeof(data)); | 190 ep1_.SendData(data, sizeof(data)); |
191 EXPECT_EQ_WAIT(1u, ep1_.ch_packets_.size(), kTimeoutMs); | 191 EXPECT_EQ_WAIT(1u, ep1_.ch_packets_.size(), kTimeoutMs); |
192 EXPECT_EQ_WAIT(1u, ep1_.num_sig_sent_packets_, kTimeoutMs); | 192 EXPECT_EQ_WAIT(1u, ep1_.num_sig_sent_packets_, kTimeoutMs); |
193 } | 193 } |
194 | 194 |
195 } // namespace cricket | 195 } // namespace cricket |
OLD | NEW |