| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
| 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 "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 mojo::InterfacePtr<serial::SerialService> service; | 67 mojo::InterfacePtr<serial::SerialService> service; |
| 68 mojo::BindToProxy( | 68 mojo::BindToProxy( |
| 69 new SerialServiceImpl( | 69 new SerialServiceImpl( |
| 70 new SerialConnectionFactory( | 70 new SerialConnectionFactory( |
| 71 base::Bind(&SerialConnectionTest::CreateIoHandler, | 71 base::Bind(&SerialConnectionTest::CreateIoHandler, |
| 72 base::Unretained(this)), | 72 base::Unretained(this)), |
| 73 base::MessageLoopProxy::current()), | 73 base::MessageLoopProxy::current()), |
| 74 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator)), | 74 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator)), |
| 75 &service); | 75 &service); |
| 76 service.set_error_handler(this); | 76 service.set_error_handler(this); |
| 77 mojo::InterfacePtr<serial::DataSink> sink; | 77 mojo::InterfacePtr<serial::DataSink> consumer; |
| 78 mojo::InterfacePtr<serial::DataSinkClient> sink_client; | 78 mojo::InterfacePtr<serial::DataSource> producer; |
| 79 mojo::InterfaceRequest<serial::DataSinkClient> sink_client_request = | 79 service->Connect("device", |
| 80 mojo::GetProxy(&sink_client); | 80 serial::ConnectionOptions::New(), |
| 81 mojo::InterfacePtr<serial::DataSource> source; | 81 mojo::GetProxy(&connection_), |
| 82 mojo::InterfacePtr<serial::DataSourceClient> source_client; | 82 mojo::GetProxy(&consumer), |
| 83 mojo::InterfaceRequest<serial::DataSourceClient> source_client_request = | 83 mojo::GetProxy(&producer)); |
| 84 mojo::GetProxy(&source_client); | 84 sender_.reset(new DataSender( |
| 85 service->Connect("device", serial::ConnectionOptions::New(), | 85 consumer.Pass(), kBufferSize, serial::SEND_ERROR_DISCONNECTED)); |
| 86 mojo::GetProxy(&connection_), mojo::GetProxy(&sink), | 86 receiver_ = new DataReceiver( |
| 87 sink_client.Pass(), mojo::GetProxy(&source), | 87 producer.Pass(), kBufferSize, serial::RECEIVE_ERROR_DISCONNECTED); |
| 88 source_client.Pass()); | |
| 89 sender_.reset(new DataSender(sink.Pass(), sink_client_request.Pass(), | |
| 90 kBufferSize, serial::SEND_ERROR_DISCONNECTED)); | |
| 91 receiver_ = | |
| 92 new DataReceiver(source.Pass(), source_client_request.Pass(), | |
| 93 kBufferSize, serial::RECEIVE_ERROR_DISCONNECTED); | |
| 94 connection_.set_error_handler(this); | 88 connection_.set_error_handler(this); |
| 95 connection_->GetInfo( | 89 connection_->GetInfo( |
| 96 base::Bind(&SerialConnectionTest::StoreInfo, base::Unretained(this))); | 90 base::Bind(&SerialConnectionTest::StoreInfo, base::Unretained(this))); |
| 97 WaitForEvent(EVENT_GOT_INFO); | 91 WaitForEvent(EVENT_GOT_INFO); |
| 98 ASSERT_TRUE(io_handler_.get()); | 92 ASSERT_TRUE(io_handler_.get()); |
| 99 } | 93 } |
| 100 | 94 |
| 101 void StoreInfo(serial::ConnectionInfoPtr options) { | 95 void StoreInfo(serial::ConnectionInfoPtr options) { |
| 102 info_ = options.Pass(); | 96 info_ = options.Pass(); |
| 103 EventReceived(EVENT_GOT_INFO); | 97 EventReceived(EVENT_GOT_INFO); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 WaitForEvent(EVENT_DATA_SENT); | 323 WaitForEvent(EVENT_DATA_SENT); |
| 330 EXPECT_EQ(serial::SEND_ERROR_NONE, send_error_); | 324 EXPECT_EQ(serial::SEND_ERROR_NONE, send_error_); |
| 331 EXPECT_EQ(4, bytes_sent_); | 325 EXPECT_EQ(4, bytes_sent_); |
| 332 ASSERT_NO_FATAL_FAILURE(Receive()); | 326 ASSERT_NO_FATAL_FAILURE(Receive()); |
| 333 WaitForEvent(EVENT_DATA_RECEIVED); | 327 WaitForEvent(EVENT_DATA_RECEIVED); |
| 334 EXPECT_EQ("data", data_received_); | 328 EXPECT_EQ("data", data_received_); |
| 335 EXPECT_EQ(serial::RECEIVE_ERROR_NONE, receive_error_); | 329 EXPECT_EQ(serial::RECEIVE_ERROR_NONE, receive_error_); |
| 336 } | 330 } |
| 337 | 331 |
| 338 } // namespace device | 332 } // namespace device |
| OLD | NEW |