summaryrefslogtreecommitdiff
path: root/fastboot/socket_test.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
commitf3f17edcf13c81a41ae64404397ededf39ae43aa (patch)
tree56d81ff3d3bce7623a885f21059b8f32adf84161 /fastboot/socket_test.cpp
parentfc196f9e929421fba566770e42031f6dfe7c54ce (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_test.cpp')
-rw-r--r--fastboot/socket_test.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/fastboot/socket_test.cpp b/fastboot/socket_test.cpp
index 9365792a1f..cc7107529f 100644
--- a/fastboot/socket_test.cpp
+++ b/fastboot/socket_test.cpp
@@ -250,6 +250,9 @@ TEST(SocketMockTest, TestSendSuccess) {
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 @@ TEST(SocketMockTest, TestReceiveSuccess) {
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");