[MemSheriff] Exclude crashing test under Dr. Memory
[chromium-blink-merge.git] / device / serial / test_serial_io_handler.cc
blobbf8fbb1334ac6840795a31bad358df60917b8a1f
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
3 // found in the LICENSE file.
5 #include "device/serial/test_serial_io_handler.h"
7 #include "base/bind.h"
8 #include "device/serial/serial.mojom.h"
10 namespace device {
12 TestSerialIoHandler::TestSerialIoHandler()
13 : SerialIoHandler(NULL),
14 opened_(false),
15 dtr_(false),
16 rts_(false),
17 flushes_(0) {
20 scoped_refptr<SerialIoHandler> TestSerialIoHandler::Create() {
21 return scoped_refptr<SerialIoHandler>(new TestSerialIoHandler);
24 void TestSerialIoHandler::Open(const std::string& port,
25 const OpenCompleteCallback& callback) {
26 DCHECK(!opened_);
27 opened_ = true;
28 callback.Run(true);
31 bool TestSerialIoHandler::ConfigurePort(
32 const serial::ConnectionOptions& options) {
33 if (options.bitrate)
34 info_.bitrate = options.bitrate;
35 if (options.data_bits != serial::DATA_BITS_NONE)
36 info_.data_bits = options.data_bits;
37 if (options.parity_bit != serial::PARITY_BIT_NONE)
38 info_.parity_bit = options.parity_bit;
39 if (options.stop_bits != serial::STOP_BITS_NONE)
40 info_.stop_bits = options.stop_bits;
41 if (options.has_cts_flow_control)
42 info_.cts_flow_control = options.cts_flow_control;
43 return true;
46 void TestSerialIoHandler::ReadImpl() {
49 void TestSerialIoHandler::CancelReadImpl() {
50 QueueReadCompleted(0, read_cancel_reason());
53 void TestSerialIoHandler::WriteImpl() {
54 DCHECK(pending_read_buffer());
55 DCHECK_LE(pending_write_buffer_len(), pending_read_buffer_len());
56 memcpy(pending_read_buffer()->data(),
57 pending_write_buffer()->data(),
58 pending_write_buffer_len());
59 QueueReadCompleted(pending_write_buffer_len(), serial::RECEIVE_ERROR_NONE);
60 QueueWriteCompleted(pending_write_buffer_len(), serial::SEND_ERROR_NONE);
63 void TestSerialIoHandler::CancelWriteImpl() {
64 QueueWriteCompleted(0, write_cancel_reason());
67 serial::DeviceControlSignalsPtr TestSerialIoHandler::GetControlSignals() const {
68 serial::DeviceControlSignalsPtr signals(serial::DeviceControlSignals::New());
69 *signals = device_control_signals_;
70 return signals.Pass();
73 serial::ConnectionInfoPtr TestSerialIoHandler::GetPortInfo() const {
74 serial::ConnectionInfoPtr info(serial::ConnectionInfo::New());
75 *info = info_;
76 return info.Pass();
79 bool TestSerialIoHandler::Flush() const {
80 flushes_++;
81 return true;
84 bool TestSerialIoHandler::SetControlSignals(
85 const serial::HostControlSignals& signals) {
86 if (signals.has_dtr)
87 dtr_ = signals.dtr;
88 if (signals.has_rts)
89 rts_ = signals.rts;
90 return true;
93 TestSerialIoHandler::~TestSerialIoHandler() {
96 } // namespace device