OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 net::Socket* client_socket, | 174 net::Socket* client_socket, |
175 net::Socket* host_socket) | 175 net::Socket* host_socket) |
176 : message_loop_(message_loop), | 176 : message_loop_(message_loop), |
177 host_socket_(host_socket), | 177 host_socket_(host_socket), |
178 client_socket_(client_socket), | 178 client_socket_(client_socket), |
179 done_(false), | 179 done_(false), |
180 write_errors_(0), | 180 write_errors_(0), |
181 read_errors_(0) { | 181 read_errors_(0) { |
182 } | 182 } |
183 | 183 |
184 virtual ~TCPChannelTester() { } | |
185 | |
186 void Start() { | 184 void Start() { |
187 message_loop_->PostTask( | 185 message_loop_->PostTask( |
188 FROM_HERE, base::Bind(&TCPChannelTester::DoStart, this)); | 186 FROM_HERE, base::Bind(&TCPChannelTester::DoStart, this)); |
189 } | 187 } |
190 | 188 |
191 void CheckResults() { | 189 void CheckResults() { |
192 EXPECT_EQ(0, write_errors_); | 190 EXPECT_EQ(0, write_errors_); |
193 EXPECT_EQ(0, read_errors_); | 191 EXPECT_EQ(0, read_errors_); |
194 | 192 |
195 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity()); | 193 ASSERT_EQ(kTestDataSize + kMessageSize, input_buffer_->capacity()); |
196 | 194 |
197 output_buffer_->SetOffset(0); | 195 output_buffer_->SetOffset(0); |
198 ASSERT_EQ(kTestDataSize, output_buffer_->size()); | 196 ASSERT_EQ(kTestDataSize, output_buffer_->size()); |
199 | 197 |
200 EXPECT_EQ(0, memcmp(output_buffer_->data(), | 198 EXPECT_EQ(0, memcmp(output_buffer_->data(), |
201 input_buffer_->StartOfBuffer(), kTestDataSize)); | 199 input_buffer_->StartOfBuffer(), kTestDataSize)); |
202 } | 200 } |
203 | 201 |
204 protected: | 202 protected: |
| 203 virtual ~TCPChannelTester() {} |
| 204 |
205 void Done() { | 205 void Done() { |
206 done_ = true; | 206 done_ = true; |
207 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 207 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
208 } | 208 } |
209 | 209 |
210 void DoStart() { | 210 void DoStart() { |
211 InitBuffers(); | 211 InitBuffers(); |
212 DoRead(); | 212 DoRead(); |
213 DoWrite(); | 213 DoWrite(); |
214 } | 214 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 279 } |
280 } else if (result > 0) { | 280 } else if (result > 0) { |
281 // Allocate memory for the next read. | 281 // Allocate memory for the next read. |
282 input_buffer_->SetCapacity(input_buffer_->capacity() + result); | 282 input_buffer_->SetCapacity(input_buffer_->capacity() + result); |
283 if (input_buffer_->capacity() == kTestDataSize + kMessageSize) | 283 if (input_buffer_->capacity() == kTestDataSize + kMessageSize) |
284 Done(); | 284 Done(); |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 private: | 288 private: |
| 289 friend class base::RefCountedThreadSafe<TCPChannelTester>; |
| 290 |
289 MessageLoop* message_loop_; | 291 MessageLoop* message_loop_; |
290 net::Socket* host_socket_; | 292 net::Socket* host_socket_; |
291 net::Socket* client_socket_; | 293 net::Socket* client_socket_; |
292 bool done_; | 294 bool done_; |
293 | 295 |
294 scoped_refptr<net::DrainableIOBuffer> output_buffer_; | 296 scoped_refptr<net::DrainableIOBuffer> output_buffer_; |
295 scoped_refptr<net::GrowableIOBuffer> input_buffer_; | 297 scoped_refptr<net::GrowableIOBuffer> input_buffer_; |
296 | 298 |
297 int write_errors_; | 299 int write_errors_; |
298 int read_errors_; | 300 int read_errors_; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 client_pseudotcp_.get()); | 437 client_pseudotcp_.get()); |
436 | 438 |
437 tester->Start(); | 439 tester->Start(); |
438 message_loop_.Run(); | 440 message_loop_.Run(); |
439 tester->CheckResults(); | 441 tester->CheckResults(); |
440 } | 442 } |
441 | 443 |
442 } // namespace | 444 } // namespace |
443 | 445 |
444 } // namespace jingle_glue | 446 } // namespace jingle_glue |
OLD | NEW |