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
diff --git a/fastboot/socket_test.cpp b/fastboot/socket_test.cpp
index 9365792..cc71075 100644
--- a/fastboot/socket_test.cpp
+++ b/fastboot/socket_test.cpp
@@ -250,6 +250,9 @@
 TEST(SocketMockTest, TestSendFailure) {
     SocketMock* mock = new SocketMock;
 
+    mock->ExpectSendFailure("foo");
+    EXPECT_FALSE(SendString(mock, "foo"));
+
     EXPECT_NONFATAL_FAILURE(SendString(mock, "foo"), "no message was expected");
 
     mock->ExpectSend("foo");
@@ -274,11 +277,24 @@
     mock.AddReceive("123");
     EXPECT_TRUE(ReceiveString(&mock, "abc"));
     EXPECT_TRUE(ReceiveString(&mock, "123"));
+
+    // Make sure ReceiveAll() can piece together multiple receives.
+    mock.AddReceive("foo");
+    mock.AddReceive("bar");
+    mock.AddReceive("123");
+    EXPECT_TRUE(ReceiveString(&mock, "foobar123"));
 }
 
 TEST(SocketMockTest, TestReceiveFailure) {
     SocketMock* mock = new SocketMock;
 
+    mock->AddReceiveFailure();
+    EXPECT_FALSE(ReceiveString(mock, "foo"));
+
+    mock->AddReceive("foo");
+    mock->AddReceiveFailure();
+    EXPECT_FALSE(ReceiveString(mock, "foobar"));
+
     EXPECT_NONFATAL_FAILURE(ReceiveString(mock, "foo"), "no message was ready");
 
     mock->ExpectSend("foo");