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

Side by Side Diff: device/serial/data_source_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/data_source_sender.cc ('k') | device/serial/serial_connection.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 <stdint.h> 5 #include <stdint.h>
6
7 #include <memory>
6 #include <utility> 8 #include <utility>
7 9
8 #include "base/bind.h" 10 #include "base/bind.h"
9 #include "base/macros.h" 11 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 13 #include "base/run_loop.h"
12 #include "base/strings/string_piece.h" 14 #include "base/strings/string_piece.h"
13 #include "device/serial/buffer.h" 15 #include "device/serial/buffer.h"
14 #include "device/serial/data_receiver.h" 16 #include "device/serial/data_receiver.h"
15 #include "device/serial/data_source_sender.h" 17 #include "device/serial/data_source_sender.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 write_buffer_->Done(static_cast<uint32_t>(data.size())); 93 write_buffer_->Done(static_cast<uint32_t>(data.size()));
92 write_buffer_.reset(); 94 write_buffer_.reset();
93 } 95 }
94 96
95 void ReceiveAndWait() { 97 void ReceiveAndWait() {
96 ASSERT_TRUE(Receive()); 98 ASSERT_TRUE(Receive());
97 // Run the message loop until OnDataReceived or OnReceiveError is called. 99 // Run the message loop until OnDataReceived or OnReceiveError is called.
98 WaitForEvent(EVENT_RECEIVE_COMPLETE); 100 WaitForEvent(EVENT_RECEIVE_COMPLETE);
99 } 101 }
100 102
101 void OnDataReceived(scoped_ptr<ReadOnlyBuffer> buffer) { 103 void OnDataReceived(std::unique_ptr<ReadOnlyBuffer> buffer) {
102 ASSERT_TRUE(buffer); 104 ASSERT_TRUE(buffer);
103 error_ = 0; 105 error_ = 0;
104 buffer_ = std::move(buffer); 106 buffer_ = std::move(buffer);
105 buffer_contents_ = std::string(buffer_->GetData(), buffer_->GetSize()); 107 buffer_contents_ = std::string(buffer_->GetData(), buffer_->GetSize());
106 EventReceived(EVENT_RECEIVE_COMPLETE); 108 EventReceived(EVENT_RECEIVE_COMPLETE);
107 } 109 }
108 110
109 void OnReceiveError(int32_t error) { 111 void OnReceiveError(int32_t error) {
110 buffer_contents_.clear(); 112 buffer_contents_.clear();
111 error_ = error; 113 error_ = error;
112 EventReceived(EVENT_RECEIVE_COMPLETE); 114 EventReceived(EVENT_RECEIVE_COMPLETE);
113 } 115 }
114 116
115 void CanWriteData(scoped_ptr<WritableBuffer> buffer) { 117 void CanWriteData(std::unique_ptr<WritableBuffer> buffer) {
116 write_buffer_ = std::move(buffer); 118 write_buffer_ = std::move(buffer);
117 EventReceived(EVENT_WRITE_BUFFER_READY); 119 EventReceived(EVENT_WRITE_BUFFER_READY);
118 } 120 }
119 121
120 protected: 122 protected:
121 static const int32_t kFatalError; 123 static const int32_t kFatalError;
122 scoped_ptr<base::MessageLoop> message_loop_; 124 std::unique_ptr<base::MessageLoop> message_loop_;
123 base::Closure stop_run_loop_; 125 base::Closure stop_run_loop_;
124 126
125 scoped_refptr<DataSourceSender> source_sender_; 127 scoped_refptr<DataSourceSender> source_sender_;
126 scoped_refptr<DataReceiver> receiver_; 128 scoped_refptr<DataReceiver> receiver_;
127 129
128 scoped_ptr<ReadOnlyBuffer> buffer_; 130 std::unique_ptr<ReadOnlyBuffer> buffer_;
129 std::string buffer_contents_; 131 std::string buffer_contents_;
130 int32_t error_; 132 int32_t error_;
131 scoped_ptr<WritableBuffer> write_buffer_; 133 std::unique_ptr<WritableBuffer> write_buffer_;
132 134
133 bool seen_connection_error_; 135 bool seen_connection_error_;
134 136
135 Event expected_event_; 137 Event expected_event_;
136 138
137 private: 139 private:
138 DISALLOW_COPY_AND_ASSIGN(DataSourceTest); 140 DISALLOW_COPY_AND_ASSIGN(DataSourceTest);
139 }; 141 };
140 142
141 const int32_t DataSourceTest::kFatalError = -10; 143 const int32_t DataSourceTest::kFatalError = -10;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // Test that the receiver shutting down is correctly reported to the source. 254 // Test that the receiver shutting down is correctly reported to the source.
253 TEST_F(DataSourceTest, ReceiverShutdown) { 255 TEST_F(DataSourceTest, ReceiverShutdown) {
254 Receive(); 256 Receive();
255 receiver_ = NULL; 257 receiver_ = NULL;
256 EXPECT_EQ(kFatalError, error_); 258 EXPECT_EQ(kFatalError, error_);
257 WaitForEvent(EVENT_ERROR); 259 WaitForEvent(EVENT_ERROR);
258 EXPECT_TRUE(seen_connection_error_); 260 EXPECT_TRUE(seen_connection_error_);
259 } 261 }
260 262
261 } // namespace device 263 } // namespace device
OLDNEW
« no previous file with comments | « device/serial/data_source_sender.cc ('k') | device/serial/serial_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698