diff options
author | David Pursell <dpursell@google.com> | 2016-02-01 09:42:09 -0800 |
---|---|---|
committer | David Pursell <dpursell@google.com> | 2016-02-03 10:01:38 -0800 |
commit | b34e4a06eeaaeaa42e0de6fdb44fb4202839b996 (patch) | |
tree | fb6863fedd661d98f6fbe0a344133623d660f6af /fastboot/socket_mock.cpp | |
parent | f971b6a24b2d785187cf98cb002b9aee9ab6b2a7 (diff) |
libcutils/fastboot: improve multi-buffer write.
Fixes libcutils multi-buffer write interface to be more friendly and
hooks into it from the fastboot Socket class.
Bug: http://b/26558551
Change-Id: Ibb3a8428fc379755602de52722c1260f9e345bc0
Diffstat (limited to 'fastboot/socket_mock.cpp')
-rw-r--r-- | fastboot/socket_mock.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/fastboot/socket_mock.cpp b/fastboot/socket_mock.cpp index 8fea55466..bcb91ecf3 100644 --- a/fastboot/socket_mock.cpp +++ b/fastboot/socket_mock.cpp @@ -38,26 +38,35 @@ SocketMock::~SocketMock() { } } -ssize_t SocketMock::Send(const void* data, size_t length) { +bool SocketMock::Send(const void* data, size_t length) { if (events_.empty()) { ADD_FAILURE() << "Send() was called when no message was expected"; - return -1; + return false; } if (events_.front().type != EventType::kSend) { ADD_FAILURE() << "Send() was called out-of-order"; - return -1; + return false; } std::string message(reinterpret_cast<const char*>(data), length); if (events_.front().message != message) { ADD_FAILURE() << "Send() expected " << events_.front().message << ", but got " << message; - return -1; + return false; } - ssize_t return_value = events_.front().return_value; events_.pop(); - return return_value; + return true; +} + +// Mock out multi-buffer send to be one large send, since that's what it should looks like from +// the user's perspective. +bool SocketMock::Send(std::vector<cutils_socket_buffer_t> buffers) { + std::string data; + for (const auto& buffer : buffers) { + data.append(reinterpret_cast<const char*>(buffer.data), buffer.length); + } + return Send(data.data(), data.size()); } ssize_t SocketMock::Receive(void* data, size_t length, int /*timeout_ms*/) { @@ -106,13 +115,13 @@ std::unique_ptr<Socket> SocketMock::Accept() { } void SocketMock::ExpectSend(std::string message) { - ssize_t return_value = message.length(); - events_.push(Event(EventType::kSend, std::move(message), return_value, nullptr)); + events_.push(Event(EventType::kSend, std::move(message), 0, nullptr)); } -void SocketMock::ExpectSendFailure(std::string message) { - events_.push(Event(EventType::kSend, std::move(message), -1, nullptr)); -} +// TODO: make this properly return false to the caller. +//void SocketMock::ExpectSendFailure(std::string message) { +// events_.push(Event(EventType::kSend, std::move(message), 0, nullptr)); +//} void SocketMock::AddReceive(std::string message) { ssize_t return_value = message.length(); |