OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "jingle/glue/pseudotcp_adapter.h" | 5 #include "jingle/glue/pseudotcp_adapter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
9 #include "jingle/glue/thread_wrapper.h" | 11 #include "jingle/glue/thread_wrapper.h" |
10 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
12 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
13 #include "net/udp/udp_socket.h" | 15 #include "net/udp/udp_socket.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
16 | 18 |
17 | 19 |
18 namespace jingle_glue { | 20 namespace jingle_glue { |
19 namespace { | 21 namespace { |
20 class FakeSocket; | 22 class FakeSocket; |
21 } // namespace | 23 } // namespace |
22 } // namespace jingle_glue | 24 } // namespace jingle_glue |
23 | 25 |
24 DISABLE_RUNNABLE_METHOD_REFCOUNT(jingle_glue::FakeSocket); | |
25 | |
26 namespace jingle_glue { | 26 namespace jingle_glue { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // The range is chosen arbitrarily. It must be big enough so that we | 30 // The range is chosen arbitrarily. It must be big enough so that we |
31 // always have at least two UDP ports available. | 31 // always have at least two UDP ports available. |
32 const int kMinPort = 32000; | 32 const int kMinPort = 32000; |
33 const int kMaxPort = 33000; | 33 const int kMaxPort = 33000; |
34 | 34 |
35 const int kMessageSize = 1024; | 35 const int kMessageSize = 1024; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 read_buffer_ = buf; | 129 read_buffer_ = buf; |
130 read_buffer_size_ = buf_len; | 130 read_buffer_size_ = buf_len; |
131 return net::ERR_IO_PENDING; | 131 return net::ERR_IO_PENDING; |
132 } | 132 } |
133 } | 133 } |
134 | 134 |
135 virtual int Write(net::IOBuffer* buf, int buf_len, | 135 virtual int Write(net::IOBuffer* buf, int buf_len, |
136 net::OldCompletionCallback* callback) OVERRIDE { | 136 net::OldCompletionCallback* callback) OVERRIDE { |
137 DCHECK(buf); | 137 DCHECK(buf); |
138 if (peer_socket_) { | 138 if (peer_socket_) { |
139 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 139 MessageLoop::current()->PostDelayedTask( |
140 peer_socket_, &FakeSocket::AppendInputPacket, | 140 FROM_HERE, |
141 std::vector<char>(buf->data(), buf->data() + buf_len)), latency_ms_); | 141 base::Bind(&FakeSocket::AppendInputPacket, |
| 142 base::Unretained(peer_socket_), |
| 143 std::vector<char>(buf->data(), buf->data() + buf_len)), |
| 144 latency_ms_); |
142 } | 145 } |
143 | 146 |
144 return buf_len; | 147 return buf_len; |
145 } | 148 } |
146 | 149 |
147 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE { | 150 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE { |
148 NOTIMPLEMENTED(); | 151 NOTIMPLEMENTED(); |
149 return false; | 152 return false; |
150 } | 153 } |
151 virtual bool SetSendBufferSize(int32 size) OVERRIDE { | 154 virtual bool SetSendBufferSize(int32 size) OVERRIDE { |
(...skipping 27 matching lines...) Expand all Loading... |
179 ALLOW_THIS_IN_INITIALIZER_LIST( | 182 ALLOW_THIS_IN_INITIALIZER_LIST( |
180 read_cb_(this, &TCPChannelTester::OnRead)), | 183 read_cb_(this, &TCPChannelTester::OnRead)), |
181 write_errors_(0), | 184 write_errors_(0), |
182 read_errors_(0) { | 185 read_errors_(0) { |
183 } | 186 } |
184 | 187 |
185 virtual ~TCPChannelTester() { } | 188 virtual ~TCPChannelTester() { } |
186 | 189 |
187 void Start() { | 190 void Start() { |
188 message_loop_->PostTask( | 191 message_loop_->PostTask( |
189 FROM_HERE, NewRunnableMethod(this, &TCPChannelTester::DoStart)); | 192 FROM_HERE, base::Bind(&TCPChannelTester::DoStart, this)); |
190 } | 193 } |
191 | 194 |
192 void CheckResults() { | 195 void CheckResults() { |
193 EXPECT_EQ(0, write_errors_); | 196 EXPECT_EQ(0, write_errors_); |
194 EXPECT_EQ(0, read_errors_); | 197 EXPECT_EQ(0, read_errors_); |
195 | 198 |
196 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity()); | 199 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity()); |
197 | 200 |
198 output_buffer_->SetOffset(0); | 201 output_buffer_->SetOffset(0); |
199 ASSERT_EQ(kTestDataSize, output_buffer_->size()); | 202 ASSERT_EQ(kTestDataSize, output_buffer_->size()); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 host_pseudotcp_->Connect(&host_connect_cb); | 407 host_pseudotcp_->Connect(&host_connect_cb); |
405 client_pseudotcp_->Connect(&client_connect_cb); | 408 client_pseudotcp_->Connect(&client_connect_cb); |
406 message_loop_.Run(); | 409 message_loop_.Run(); |
407 | 410 |
408 ASSERT_EQ(NULL, host_pseudotcp_.get()); | 411 ASSERT_EQ(NULL, host_pseudotcp_.get()); |
409 } | 412 } |
410 | 413 |
411 } // namespace | 414 } // namespace |
412 | 415 |
413 } // namespace jingle_glue | 416 } // namespace jingle_glue |
OLD | NEW |