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

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

Issue 1544323002: Convert Pass()→std::move() in //device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 12 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_service_impl.cc ('k') | device/serial/test_serial_io_handler.cc » ('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 <utility>
6
5 #include "base/bind.h" 7 #include "base/bind.h"
6 #include "base/macros.h" 8 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 10 #include "base/run_loop.h"
9 #include "device/serial/serial.mojom.h" 11 #include "device/serial/serial.mojom.h"
10 #include "device/serial/serial_service_impl.h" 12 #include "device/serial/serial_service_impl.h"
11 #include "device/serial/test_serial_io_handler.h" 13 #include "device/serial/test_serial_io_handler.h"
12 #include "mojo/public/cpp/bindings/interface_ptr.h" 14 #include "mojo/public/cpp/bindings/interface_ptr.h"
13 #include "mojo/public/cpp/bindings/interface_request.h" 15 #include "mojo/public/cpp/bindings/interface_request.h"
14 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
15 17
16 namespace device { 18 namespace device {
17 namespace { 19 namespace {
18 20
19 class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator { 21 class FakeSerialDeviceEnumerator : public SerialDeviceEnumerator {
20 mojo::Array<serial::DeviceInfoPtr> GetDevices() override { 22 mojo::Array<serial::DeviceInfoPtr> GetDevices() override {
21 mojo::Array<serial::DeviceInfoPtr> devices(1); 23 mojo::Array<serial::DeviceInfoPtr> devices(1);
22 devices[0] = serial::DeviceInfo::New(); 24 devices[0] = serial::DeviceInfo::New();
23 devices[0]->path = "device"; 25 devices[0]->path = "device";
24 return devices.Pass(); 26 return devices;
25 } 27 }
26 }; 28 };
27 29
28 class FailToOpenIoHandler : public TestSerialIoHandler { 30 class FailToOpenIoHandler : public TestSerialIoHandler {
29 public: 31 public:
30 void Open(const std::string& port, 32 void Open(const std::string& port,
31 const serial::ConnectionOptions& options, 33 const serial::ConnectionOptions& options,
32 const OpenCompleteCallback& callback) override { 34 const OpenCompleteCallback& callback) override {
33 callback.Run(false); 35 callback.Run(false);
34 } 36 }
35 37
36 protected: 38 protected:
37 ~FailToOpenIoHandler() override {} 39 ~FailToOpenIoHandler() override {}
38 }; 40 };
39 41
40 } // namespace 42 } // namespace
41 43
42 class SerialServiceTest : public testing::Test { 44 class SerialServiceTest : public testing::Test {
43 public: 45 public:
44 SerialServiceTest() : connected_(false), expecting_error_(false) {} 46 SerialServiceTest() : connected_(false), expecting_error_(false) {}
45 47
46 void StoreDevices(mojo::Array<serial::DeviceInfoPtr> devices) { 48 void StoreDevices(mojo::Array<serial::DeviceInfoPtr> devices) {
47 devices_ = devices.Pass(); 49 devices_ = std::move(devices);
48 StopMessageLoop(); 50 StopMessageLoop();
49 } 51 }
50 52
51 void OnConnectionError() { 53 void OnConnectionError() {
52 StopMessageLoop(); 54 StopMessageLoop();
53 EXPECT_TRUE(expecting_error_); 55 EXPECT_TRUE(expecting_error_);
54 } 56 }
55 57
56 void RunMessageLoop() { 58 void RunMessageLoop() {
57 run_loop_.reset(new base::RunLoop); 59 run_loop_.reset(new base::RunLoop);
(...skipping 23 matching lines...) Expand all
81 base::ThreadTaskRunnerHandle::Get()), 83 base::ThreadTaskRunnerHandle::Get()),
82 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator), 84 scoped_ptr<SerialDeviceEnumerator>(new FakeSerialDeviceEnumerator),
83 mojo::GetProxy(&service)); 85 mojo::GetProxy(&service));
84 mojo::InterfacePtr<serial::Connection> connection; 86 mojo::InterfacePtr<serial::Connection> connection;
85 mojo::InterfacePtr<serial::DataSink> sink; 87 mojo::InterfacePtr<serial::DataSink> sink;
86 mojo::InterfacePtr<serial::DataSource> source; 88 mojo::InterfacePtr<serial::DataSource> source;
87 mojo::InterfacePtr<serial::DataSourceClient> source_client; 89 mojo::InterfacePtr<serial::DataSourceClient> source_client;
88 mojo::GetProxy(&source_client); 90 mojo::GetProxy(&source_client);
89 service->Connect(path, serial::ConnectionOptions::New(), 91 service->Connect(path, serial::ConnectionOptions::New(),
90 mojo::GetProxy(&connection), mojo::GetProxy(&sink), 92 mojo::GetProxy(&connection), mojo::GetProxy(&sink),
91 mojo::GetProxy(&source), source_client.Pass()); 93 mojo::GetProxy(&source), std::move(source_client));
92 connection.set_connection_error_handler(base::Bind( 94 connection.set_connection_error_handler(base::Bind(
93 &SerialServiceTest::OnConnectionError, base::Unretained(this))); 95 &SerialServiceTest::OnConnectionError, base::Unretained(this)));
94 expecting_error_ = !expecting_success; 96 expecting_error_ = !expecting_success;
95 connection->GetInfo( 97 connection->GetInfo(
96 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this))); 98 base::Bind(&SerialServiceTest::OnGotInfo, base::Unretained(this)));
97 RunMessageLoop(); 99 RunMessageLoop();
98 EXPECT_EQ(!expecting_success, connection.encountered_error()); 100 EXPECT_EQ(!expecting_success, connection.encountered_error());
99 EXPECT_EQ(expecting_success, connected_); 101 EXPECT_EQ(expecting_success, connected_);
100 connection.reset(); 102 connection.reset();
101 } 103 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 TEST_F(SerialServiceTest, ConnectInvalidPath) { 136 TEST_F(SerialServiceTest, ConnectInvalidPath) {
135 RunConnectTest("invalid_path", false); 137 RunConnectTest("invalid_path", false);
136 } 138 }
137 139
138 TEST_F(SerialServiceTest, ConnectOpenFailed) { 140 TEST_F(SerialServiceTest, ConnectOpenFailed) {
139 io_handler_ = new FailToOpenIoHandler; 141 io_handler_ = new FailToOpenIoHandler;
140 RunConnectTest("device", false); 142 RunConnectTest("device", false);
141 } 143 }
142 144
143 } // namespace device 145 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/serial_service_impl.cc ('k') | device/serial/test_serial_io_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698