| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
| 15 #include "webrtc/base/logging.h" | 15 #include "webrtc/base/logging.h" |
| 16 #include "webrtc/base/physicalsocketserver.h" | |
| 17 #include "webrtc/base/ptr_util.h" | 16 #include "webrtc/base/ptr_util.h" |
| 18 #include "webrtc/base/testclient.h" | 17 #include "webrtc/base/testclient.h" |
| 19 #include "webrtc/base/thread.h" | 18 #include "webrtc/base/thread.h" |
| 20 #include "webrtc/base/virtualsocketserver.h" | 19 #include "webrtc/base/virtualsocketserver.h" |
| 21 #include "webrtc/p2p/base/stunserver.h" | 20 #include "webrtc/p2p/base/stunserver.h" |
| 22 | 21 |
| 23 using namespace cricket; | 22 using namespace cricket; |
| 24 | 23 |
| 25 static const rtc::SocketAddress server_addr("99.99.99.1", 3478); | 24 static const rtc::SocketAddress server_addr("99.99.99.1", 3478); |
| 26 static const rtc::SocketAddress client_addr("1.2.3.4", 1234); | 25 static const rtc::SocketAddress client_addr("1.2.3.4", 1234); |
| 27 | 26 |
| 28 class StunServerTest : public testing::Test { | 27 class StunServerTest : public testing::Test { |
| 29 public: | 28 public: |
| 30 StunServerTest() | 29 StunServerTest() : ss_(new rtc::VirtualSocketServer()), network_(ss_.get()) {} |
| 31 : pss_(new rtc::PhysicalSocketServer), | |
| 32 ss_(new rtc::VirtualSocketServer(pss_.get())), | |
| 33 network_(ss_.get()) { | |
| 34 } | |
| 35 virtual void SetUp() { | 30 virtual void SetUp() { |
| 36 server_.reset(new StunServer( | 31 server_.reset(new StunServer( |
| 37 rtc::AsyncUDPSocket::Create(ss_.get(), server_addr))); | 32 rtc::AsyncUDPSocket::Create(ss_.get(), server_addr))); |
| 38 client_.reset(new rtc::TestClient( | 33 client_.reset(new rtc::TestClient( |
| 39 WrapUnique(rtc::AsyncUDPSocket::Create(ss_.get(), client_addr)))); | 34 WrapUnique(rtc::AsyncUDPSocket::Create(ss_.get(), client_addr)))); |
| 40 | 35 |
| 41 network_.Start(); | 36 network_.Start(); |
| 42 } | 37 } |
| 43 void Send(const StunMessage& msg) { | 38 void Send(const StunMessage& msg) { |
| 44 rtc::ByteBufferWriter buf; | 39 rtc::ByteBufferWriter buf; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 56 std::unique_ptr<rtc::TestClient::Packet> packet = | 51 std::unique_ptr<rtc::TestClient::Packet> packet = |
| 57 client_->NextPacket(rtc::TestClient::kTimeoutMs); | 52 client_->NextPacket(rtc::TestClient::kTimeoutMs); |
| 58 if (packet) { | 53 if (packet) { |
| 59 rtc::ByteBufferReader buf(packet->buf, packet->size); | 54 rtc::ByteBufferReader buf(packet->buf, packet->size); |
| 60 msg = new StunMessage(); | 55 msg = new StunMessage(); |
| 61 msg->Read(&buf); | 56 msg->Read(&buf); |
| 62 } | 57 } |
| 63 return msg; | 58 return msg; |
| 64 } | 59 } |
| 65 private: | 60 private: |
| 66 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | |
| 67 std::unique_ptr<rtc::VirtualSocketServer> ss_; | 61 std::unique_ptr<rtc::VirtualSocketServer> ss_; |
| 68 rtc::Thread network_; | 62 rtc::Thread network_; |
| 69 std::unique_ptr<StunServer> server_; | 63 std::unique_ptr<StunServer> server_; |
| 70 std::unique_ptr<rtc::TestClient> client_; | 64 std::unique_ptr<rtc::TestClient> client_; |
| 71 }; | 65 }; |
| 72 | 66 |
| 73 // Disable for TSan v2, see | 67 // Disable for TSan v2, see |
| 74 // https://code.google.com/p/webrtc/issues/detail?id=2517 for details. | 68 // https://code.google.com/p/webrtc/issues/detail?id=2517 for details. |
| 75 #if !defined(THREAD_SANITIZER) | 69 #if !defined(THREAD_SANITIZER) |
| 76 | 70 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 104 #endif // if !defined(THREAD_SANITIZER) | 98 #endif // if !defined(THREAD_SANITIZER) |
| 105 | 99 |
| 106 TEST_F(StunServerTest, TestBad) { | 100 TEST_F(StunServerTest, TestBad) { |
| 107 const char* bad = "this is a completely nonsensical message whose only " | 101 const char* bad = "this is a completely nonsensical message whose only " |
| 108 "purpose is to make the parser go 'ack'. it doesn't " | 102 "purpose is to make the parser go 'ack'. it doesn't " |
| 109 "look anything like a normal stun message"; | 103 "look anything like a normal stun message"; |
| 110 Send(bad, static_cast<int>(strlen(bad))); | 104 Send(bad, static_cast<int>(strlen(bad))); |
| 111 | 105 |
| 112 ASSERT_TRUE(ReceiveFails()); | 106 ASSERT_TRUE(ReceiveFails()); |
| 113 } | 107 } |
| OLD | NEW |