OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
(...skipping 11 matching lines...) Expand all Loading... |
22 using namespace cricket; | 22 using namespace cricket; |
23 | 23 |
24 static const rtc::SocketAddress server_addr("99.99.99.1", 3478); | 24 static const rtc::SocketAddress server_addr("99.99.99.1", 3478); |
25 static const rtc::SocketAddress client_addr("1.2.3.4", 1234); | 25 static const rtc::SocketAddress client_addr("1.2.3.4", 1234); |
26 | 26 |
27 class StunServerTest : public testing::Test { | 27 class StunServerTest : public testing::Test { |
28 public: | 28 public: |
29 StunServerTest() | 29 StunServerTest() |
30 : pss_(new rtc::PhysicalSocketServer), | 30 : pss_(new rtc::PhysicalSocketServer), |
31 ss_(new rtc::VirtualSocketServer(pss_.get())), | 31 ss_(new rtc::VirtualSocketServer(pss_.get())), |
32 worker_(ss_.get()) { | 32 network_(ss_.get()) { |
33 } | 33 } |
34 virtual void SetUp() { | 34 virtual void SetUp() { |
35 server_.reset(new StunServer( | 35 server_.reset(new StunServer( |
36 rtc::AsyncUDPSocket::Create(ss_.get(), server_addr))); | 36 rtc::AsyncUDPSocket::Create(ss_.get(), server_addr))); |
37 client_.reset(new rtc::TestClient( | 37 client_.reset(new rtc::TestClient( |
38 rtc::AsyncUDPSocket::Create(ss_.get(), client_addr))); | 38 rtc::AsyncUDPSocket::Create(ss_.get(), client_addr))); |
39 | 39 |
40 worker_.Start(); | 40 network_.Start(); |
41 } | 41 } |
42 void Send(const StunMessage& msg) { | 42 void Send(const StunMessage& msg) { |
43 rtc::ByteBufferWriter buf; | 43 rtc::ByteBufferWriter buf; |
44 msg.Write(&buf); | 44 msg.Write(&buf); |
45 Send(buf.Data(), static_cast<int>(buf.Length())); | 45 Send(buf.Data(), static_cast<int>(buf.Length())); |
46 } | 46 } |
47 void Send(const char* buf, int len) { | 47 void Send(const char* buf, int len) { |
48 client_->SendTo(buf, len, server_addr); | 48 client_->SendTo(buf, len, server_addr); |
49 } | 49 } |
50 bool ReceiveFails() { | 50 bool ReceiveFails() { |
51 return(client_->CheckNoPacket()); | 51 return(client_->CheckNoPacket()); |
52 } | 52 } |
53 StunMessage* Receive() { | 53 StunMessage* Receive() { |
54 StunMessage* msg = NULL; | 54 StunMessage* msg = NULL; |
55 rtc::TestClient::Packet* packet = | 55 rtc::TestClient::Packet* packet = |
56 client_->NextPacket(rtc::TestClient::kTimeoutMs); | 56 client_->NextPacket(rtc::TestClient::kTimeoutMs); |
57 if (packet) { | 57 if (packet) { |
58 rtc::ByteBufferReader buf(packet->buf, packet->size); | 58 rtc::ByteBufferReader buf(packet->buf, packet->size); |
59 msg = new StunMessage(); | 59 msg = new StunMessage(); |
60 msg->Read(&buf); | 60 msg->Read(&buf); |
61 delete packet; | 61 delete packet; |
62 } | 62 } |
63 return msg; | 63 return msg; |
64 } | 64 } |
65 private: | 65 private: |
66 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 66 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
67 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 67 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
68 rtc::Thread worker_; | 68 rtc::Thread network_; |
69 std::unique_ptr<StunServer> server_; | 69 std::unique_ptr<StunServer> server_; |
70 std::unique_ptr<rtc::TestClient> client_; | 70 std::unique_ptr<rtc::TestClient> client_; |
71 }; | 71 }; |
72 | 72 |
73 // Disable for TSan v2, see | 73 // Disable for TSan v2, see |
74 // https://code.google.com/p/webrtc/issues/detail?id=2517 for details. | 74 // https://code.google.com/p/webrtc/issues/detail?id=2517 for details. |
75 #if !defined(THREAD_SANITIZER) | 75 #if !defined(THREAD_SANITIZER) |
76 | 76 |
77 TEST_F(StunServerTest, TestGood) { | 77 TEST_F(StunServerTest, TestGood) { |
78 StunMessage req; | 78 StunMessage req; |
(...skipping 25 matching lines...) Expand all Loading... |
104 #endif // if !defined(THREAD_SANITIZER) | 104 #endif // if !defined(THREAD_SANITIZER) |
105 | 105 |
106 TEST_F(StunServerTest, TestBad) { | 106 TEST_F(StunServerTest, TestBad) { |
107 const char* bad = "this is a completely nonsensical message whose only " | 107 const char* bad = "this is a completely nonsensical message whose only " |
108 "purpose is to make the parser go 'ack'. it doesn't " | 108 "purpose is to make the parser go 'ack'. it doesn't " |
109 "look anything like a normal stun message"; | 109 "look anything like a normal stun message"; |
110 Send(bad, static_cast<int>(strlen(bad))); | 110 Send(bad, static_cast<int>(strlen(bad))); |
111 | 111 |
112 ASSERT_TRUE(ReceiveFails()); | 112 ASSERT_TRUE(ReceiveFails()); |
113 } | 113 } |
OLD | NEW |