summaryrefslogtreecommitdiff
path: root/fastboot/socket_mock.cpp
diff options
context:
space:
mode:
authorDavid Pursell <dpursell@google.com>2016-02-03 10:23:05 -0800
committerDavid Pursell <dpursell@google.com>2016-02-03 10:43:01 -0800
commit2c094f79836d7defb6114e59b6412157658c0f90 (patch)
tree56d81ff3d3bce7623a885f21059b8f32adf84161 /fastboot/socket_mock.cpp
parentf6f800ef3c4f7caef65f75bd6365a2045be488ea (diff)
fastboot: fix SocketMock send failures.
Fixes SocketMock::ExpectSendFailure() to allow unit testing of errors during send, and adds tests for ExpectSendFailure() and AddReceiveFailure(). Also adds missing tests to make sure ReceiveAll() continues to read until failure or all bytes have been read. Bug: http://b/26157893 Change-Id: I67e7d6de8e8ec4a3b62a6b7d7217f7530862edf7
Diffstat (limited to 'fastboot/socket_mock.cpp')
-rw-r--r--fastboot/socket_mock.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/fastboot/socket_mock.cpp b/fastboot/socket_mock.cpp
index bcb91ecf3..c962f303d 100644
--- a/fastboot/socket_mock.cpp
+++ b/fastboot/socket_mock.cpp
@@ -55,8 +55,9 @@ bool SocketMock::Send(const void* data, size_t length) {
return false;
}
+ bool return_value = events_.front().return_value;
events_.pop();
- return true;
+ return return_value;
}
// Mock out multi-buffer send to be one large send, since that's what it should looks like from
@@ -115,13 +116,12 @@ std::unique_ptr<Socket> SocketMock::Accept() {
}
void SocketMock::ExpectSend(std::string message) {
- events_.push(Event(EventType::kSend, std::move(message), 0, nullptr));
+ events_.push(Event(EventType::kSend, std::move(message), true, 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::ExpectSendFailure(std::string message) {
+ events_.push(Event(EventType::kSend, std::move(message), false, nullptr));
+}
void SocketMock::AddReceive(std::string message) {
ssize_t return_value = message.length();