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 "remoting/protocol/connection_tester.h" | 5 #include "remoting/protocol/connection_tester.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "remoting/proto/video.pb.h" |
| 12 #include "remoting/protocol/message_pipe.h" |
| 13 #include "remoting/protocol/message_serialization.h" |
11 #include "remoting/protocol/p2p_datagram_socket.h" | 14 #include "remoting/protocol/p2p_datagram_socket.h" |
12 #include "remoting/protocol/p2p_stream_socket.h" | 15 #include "remoting/protocol/p2p_stream_socket.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
15 namespace remoting { | 18 namespace remoting { |
16 namespace protocol { | 19 namespace protocol { |
17 | 20 |
18 StreamConnectionTester::StreamConnectionTester(P2PStreamSocket* client_socket, | 21 StreamConnectionTester::StreamConnectionTester(P2PStreamSocket* client_socket, |
19 P2PStreamSocket* host_socket, | 22 P2PStreamSocket* host_socket, |
20 int message_size, | 23 int message_size, |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 bad_packets_received_++; | 253 bad_packets_received_++; |
251 } else { | 254 } else { |
252 if (memcmp(read_buffer_->data(), sent_packets_[packet_id]->data(), | 255 if (memcmp(read_buffer_->data(), sent_packets_[packet_id]->data(), |
253 message_size_) != 0) | 256 message_size_) != 0) |
254 bad_packets_received_++; | 257 bad_packets_received_++; |
255 } | 258 } |
256 } | 259 } |
257 } | 260 } |
258 } | 261 } |
259 | 262 |
| 263 MessagePipeConnectionTester::MessagePipeConnectionTester( |
| 264 MessagePipe* client_pipe, |
| 265 MessagePipe* host_pipe, |
| 266 int message_size, |
| 267 int message_count) |
| 268 : host_pipe_(host_pipe), |
| 269 client_pipe_(client_pipe), |
| 270 message_size_(message_size), |
| 271 message_count_(message_count) {} |
| 272 MessagePipeConnectionTester::~MessagePipeConnectionTester() {} |
| 273 |
| 274 void MessagePipeConnectionTester::RunAndCheckResults() { |
| 275 host_pipe_->StartReceiving(base::Bind( |
| 276 &MessagePipeConnectionTester::OnMessageReceived, base::Unretained(this))); |
| 277 |
| 278 for (int i = 0; i < message_count_; ++i) { |
| 279 scoped_ptr<VideoPacket> message(new VideoPacket()); |
| 280 message->mutable_data()->resize(message_size_); |
| 281 for (int p = 0; p < message_size_; ++p) { |
| 282 message->mutable_data()[0] = static_cast<char>(i + p); |
| 283 } |
| 284 client_pipe_->Send(message.get(), base::Closure()); |
| 285 sent_messages_.push_back(std::move(message)); |
| 286 } |
| 287 |
| 288 run_loop_.Run(); |
| 289 |
| 290 ASSERT_EQ(sent_messages_.size(), received_messages_.size()); |
| 291 for (size_t i = 0; i < sent_messages_.size(); ++i) { |
| 292 EXPECT_TRUE(sent_messages_[i]->data() == received_messages_[i]->data()); |
| 293 } |
| 294 } |
| 295 |
| 296 void MessagePipeConnectionTester::OnMessageReceived( |
| 297 scoped_ptr<CompoundBuffer> message) { |
| 298 received_messages_.push_back(ParseMessage<VideoPacket>(message.get())); |
| 299 if (received_messages_.size() >= sent_messages_.size()) { |
| 300 run_loop_.Quit(); |
| 301 } |
| 302 } |
| 303 |
260 } // namespace protocol | 304 } // namespace protocol |
261 } // namespace remoting | 305 } // namespace remoting |
OLD | NEW |