Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: device/serial/serial_connection_unittest.cc

Issue 1874313002: Convert device to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/serial/serial_connection.cc ('k') | device/serial/serial_device_enumerator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "device/serial/serial_connection.h" 5 #include "device/serial/serial_connection.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8
9 #include <memory>
8 #include <string> 10 #include <string>
9 #include <utility> 11 #include <utility>
10 12
11 #include "base/bind.h" 13 #include "base/bind.h"
12 #include "base/macros.h" 14 #include "base/macros.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 16 #include "base/run_loop.h"
15 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
16 #include "device/serial/data_receiver.h" 18 #include "device/serial/data_receiver.h"
17 #include "device/serial/data_sender.h" 19 #include "device/serial/data_sender.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 expected_event_(EVENT_NONE) {} 68 expected_event_(EVENT_NONE) {}
67 69
68 void SetUp() override { 70 void SetUp() override {
69 message_loop_.reset(new base::MessageLoop); 71 message_loop_.reset(new base::MessageLoop);
70 mojo::InterfacePtr<serial::SerialService> service; 72 mojo::InterfacePtr<serial::SerialService> service;
71 new SerialServiceImpl( 73 new SerialServiceImpl(
72 new SerialConnectionFactory( 74 new SerialConnectionFactory(
73 base::Bind(&SerialConnectionTest::CreateIoHandler, 75 base::Bind(&SerialConnectionTest::CreateIoHandler,
74 base::Unretained(this)), 76 base::Unretained(this)),
75 base::ThreadTaskRunnerHandle::Get()), 77 base::ThreadTaskRunnerHandle::Get()),
76 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), 78 std::unique_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator),
77 mojo::GetProxy(&service)); 79 mojo::GetProxy(&service));
78 service.set_connection_error_handler(base::Bind( 80 service.set_connection_error_handler(base::Bind(
79 &SerialConnectionTest::OnConnectionError, base::Unretained(this))); 81 &SerialConnectionTest::OnConnectionError, base::Unretained(this)));
80 mojo::InterfacePtr<serial::DataSink> sink; 82 mojo::InterfacePtr<serial::DataSink> sink;
81 mojo::InterfacePtr<serial::DataSource> source; 83 mojo::InterfacePtr<serial::DataSource> source;
82 mojo::InterfacePtr<serial::DataSourceClient> source_client; 84 mojo::InterfacePtr<serial::DataSourceClient> source_client;
83 mojo::InterfaceRequest<serial::DataSourceClient> source_client_request = 85 mojo::InterfaceRequest<serial::DataSourceClient> source_client_request =
84 mojo::GetProxy(&source_client); 86 mojo::GetProxy(&source_client);
85 service->Connect("device", serial::ConnectionOptions::New(), 87 service->Connect("device", serial::ConnectionOptions::New(),
86 mojo::GetProxy(&connection_), mojo::GetProxy(&sink), 88 mojo::GetProxy(&connection_), mojo::GetProxy(&sink),
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 send_error_ = serial::SendError::NONE; 158 send_error_ = serial::SendError::NONE;
157 EventReceived(EVENT_DATA_SENT); 159 EventReceived(EVENT_DATA_SENT);
158 } 160 }
159 161
160 void OnSendError(uint32_t bytes_sent, int32_t error) { 162 void OnSendError(uint32_t bytes_sent, int32_t error) {
161 bytes_sent_ += bytes_sent; 163 bytes_sent_ += bytes_sent;
162 send_error_ = static_cast<serial::SendError>(error); 164 send_error_ = static_cast<serial::SendError>(error);
163 EventReceived(EVENT_SEND_ERROR); 165 EventReceived(EVENT_SEND_ERROR);
164 } 166 }
165 167
166 void OnDataReceived(scoped_ptr<ReadOnlyBuffer> buffer) { 168 void OnDataReceived(std::unique_ptr<ReadOnlyBuffer> buffer) {
167 data_received_ += std::string(buffer->GetData(), buffer->GetSize()); 169 data_received_ += std::string(buffer->GetData(), buffer->GetSize());
168 buffer->Done(buffer->GetSize()); 170 buffer->Done(buffer->GetSize());
169 receive_error_ = serial::ReceiveError::NONE; 171 receive_error_ = serial::ReceiveError::NONE;
170 EventReceived(EVENT_DATA_RECEIVED); 172 EventReceived(EVENT_DATA_RECEIVED);
171 } 173 }
172 174
173 void OnReceiveError(int32_t error) { 175 void OnReceiveError(int32_t error) {
174 receive_error_ = static_cast<serial::ReceiveError>(error); 176 receive_error_ = static_cast<serial::ReceiveError>(error);
175 EventReceived(EVENT_RECEIVE_ERROR); 177 EventReceived(EVENT_RECEIVE_ERROR);
176 } 178 }
177 179
178 void OnConnectionError() { 180 void OnConnectionError() {
179 EventReceived(EVENT_ERROR); 181 EventReceived(EVENT_ERROR);
180 FAIL() << "Connection error"; 182 FAIL() << "Connection error";
181 } 183 }
182 184
183 mojo::Array<serial::DeviceInfoPtr> devices_; 185 mojo::Array<serial::DeviceInfoPtr> devices_;
184 serial::ConnectionInfoPtr info_; 186 serial::ConnectionInfoPtr info_;
185 serial::DeviceControlSignalsPtr signals_; 187 serial::DeviceControlSignalsPtr signals_;
186 bool connected_; 188 bool connected_;
187 bool success_; 189 bool success_;
188 int bytes_sent_; 190 int bytes_sent_;
189 serial::SendError send_error_; 191 serial::SendError send_error_;
190 serial::ReceiveError receive_error_; 192 serial::ReceiveError receive_error_;
191 std::string data_received_; 193 std::string data_received_;
192 Event expected_event_; 194 Event expected_event_;
193 195
194 scoped_ptr<base::MessageLoop> message_loop_; 196 std::unique_ptr<base::MessageLoop> message_loop_;
195 base::Closure stop_run_loop_; 197 base::Closure stop_run_loop_;
196 mojo::InterfacePtr<serial::Connection> connection_; 198 mojo::InterfacePtr<serial::Connection> connection_;
197 scoped_ptr<DataSender> sender_; 199 std::unique_ptr<DataSender> sender_;
198 scoped_refptr<DataReceiver> receiver_; 200 scoped_refptr<DataReceiver> receiver_;
199 scoped_refptr<TestSerialIoHandler> io_handler_; 201 scoped_refptr<TestSerialIoHandler> io_handler_;
200 202
201 private: 203 private:
202 DISALLOW_COPY_AND_ASSIGN(SerialConnectionTest); 204 DISALLOW_COPY_AND_ASSIGN(SerialConnectionTest);
203 }; 205 };
204 206
205 const uint32_t SerialConnectionTest::kBufferSize = 10; 207 const uint32_t SerialConnectionTest::kBufferSize = 10;
206 208
207 TEST_F(SerialConnectionTest, GetInfo) { 209 TEST_F(SerialConnectionTest, GetInfo) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 WaitForEvent(EVENT_DATA_SENT); 332 WaitForEvent(EVENT_DATA_SENT);
331 EXPECT_EQ(serial::SendError::NONE, send_error_); 333 EXPECT_EQ(serial::SendError::NONE, send_error_);
332 EXPECT_EQ(4, bytes_sent_); 334 EXPECT_EQ(4, bytes_sent_);
333 ASSERT_NO_FATAL_FAILURE(Receive()); 335 ASSERT_NO_FATAL_FAILURE(Receive());
334 WaitForEvent(EVENT_DATA_RECEIVED); 336 WaitForEvent(EVENT_DATA_RECEIVED);
335 EXPECT_EQ("data", data_received_); 337 EXPECT_EQ("data", data_received_);
336 EXPECT_EQ(serial::ReceiveError::NONE, receive_error_); 338 EXPECT_EQ(serial::ReceiveError::NONE, receive_error_);
337 } 339 }
338 340
339 } // namespace device 341 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_connection.cc ('k') | device/serial/serial_device_enumerator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698