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 21 matching lines...) Expand all Loading... |
32 } | 32 } |
33 virtual void SetUp() { | 33 virtual void SetUp() { |
34 server_.reset(new StunServer( | 34 server_.reset(new StunServer( |
35 rtc::AsyncUDPSocket::Create(ss_.get(), server_addr))); | 35 rtc::AsyncUDPSocket::Create(ss_.get(), server_addr))); |
36 client_.reset(new rtc::TestClient( | 36 client_.reset(new rtc::TestClient( |
37 rtc::AsyncUDPSocket::Create(ss_.get(), client_addr))); | 37 rtc::AsyncUDPSocket::Create(ss_.get(), client_addr))); |
38 | 38 |
39 worker_.Start(); | 39 worker_.Start(); |
40 } | 40 } |
41 void Send(const StunMessage& msg) { | 41 void Send(const StunMessage& msg) { |
42 rtc::ByteBuffer buf; | 42 rtc::ByteBufferWriter buf; |
43 msg.Write(&buf); | 43 msg.Write(&buf); |
44 Send(buf.Data(), static_cast<int>(buf.Length())); | 44 Send(buf.Data(), static_cast<int>(buf.Length())); |
45 } | 45 } |
46 void Send(const char* buf, int len) { | 46 void Send(const char* buf, int len) { |
47 client_->SendTo(buf, len, server_addr); | 47 client_->SendTo(buf, len, server_addr); |
48 } | 48 } |
49 bool ReceiveFails() { | 49 bool ReceiveFails() { |
50 return(client_->CheckNoPacket()); | 50 return(client_->CheckNoPacket()); |
51 } | 51 } |
52 StunMessage* Receive() { | 52 StunMessage* Receive() { |
53 StunMessage* msg = NULL; | 53 StunMessage* msg = NULL; |
54 rtc::TestClient::Packet* packet = | 54 rtc::TestClient::Packet* packet = |
55 client_->NextPacket(rtc::TestClient::kTimeoutMs); | 55 client_->NextPacket(rtc::TestClient::kTimeoutMs); |
56 if (packet) { | 56 if (packet) { |
57 rtc::ByteBuffer buf(packet->buf, packet->size); | 57 rtc::ByteBufferReader buf(packet->buf, packet->size); |
58 msg = new StunMessage(); | 58 msg = new StunMessage(); |
59 msg->Read(&buf); | 59 msg->Read(&buf); |
60 delete packet; | 60 delete packet; |
61 } | 61 } |
62 return msg; | 62 return msg; |
63 } | 63 } |
64 private: | 64 private: |
65 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 65 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
66 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | 66 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
67 rtc::Thread worker_; | 67 rtc::Thread worker_; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 #endif // if !defined(THREAD_SANITIZER) | 103 #endif // if !defined(THREAD_SANITIZER) |
104 | 104 |
105 TEST_F(StunServerTest, TestBad) { | 105 TEST_F(StunServerTest, TestBad) { |
106 const char* bad = "this is a completely nonsensical message whose only " | 106 const char* bad = "this is a completely nonsensical message whose only " |
107 "purpose is to make the parser go 'ack'. it doesn't " | 107 "purpose is to make the parser go 'ack'. it doesn't " |
108 "look anything like a normal stun message"; | 108 "look anything like a normal stun message"; |
109 Send(bad, static_cast<int>(strlen(bad))); | 109 Send(bad, static_cast<int>(strlen(bad))); |
110 | 110 |
111 ASSERT_TRUE(ReceiveFails()); | 111 ASSERT_TRUE(ReceiveFails()); |
112 } | 112 } |
OLD | NEW |