Merge "fastboot: fix SocketMock send failures."
This commit is contained in:
commit
e54ea1c12d
3 changed files with 25 additions and 6 deletions
|
|
@ -55,8 +55,9 @@ bool SocketMock::Send(const void* data, size_t length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool return_value = events_.front().return_value;
|
||||||
events_.pop();
|
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
|
// 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) {
|
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) {
|
||||||
//void SocketMock::ExpectSendFailure(std::string message) {
|
events_.push(Event(EventType::kSend, std::move(message), false, nullptr));
|
||||||
// events_.push(Event(EventType::kSend, std::move(message), 0, nullptr));
|
}
|
||||||
//}
|
|
||||||
|
|
||||||
void SocketMock::AddReceive(std::string message) {
|
void SocketMock::AddReceive(std::string message) {
|
||||||
ssize_t return_value = message.length();
|
ssize_t return_value = message.length();
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,9 @@ class SocketMock : public Socket {
|
||||||
// Adds an expectation for Send().
|
// Adds an expectation for Send().
|
||||||
void ExpectSend(std::string message);
|
void ExpectSend(std::string message);
|
||||||
|
|
||||||
|
// Adds an expectation for Send() that returns false.
|
||||||
|
void ExpectSendFailure(std::string message);
|
||||||
|
|
||||||
// Adds data to provide for Receive().
|
// Adds data to provide for Receive().
|
||||||
void AddReceive(std::string message);
|
void AddReceive(std::string message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,9 @@ TEST(SocketMockTest, TestSendSuccess) {
|
||||||
TEST(SocketMockTest, TestSendFailure) {
|
TEST(SocketMockTest, TestSendFailure) {
|
||||||
SocketMock* mock = new SocketMock;
|
SocketMock* mock = new SocketMock;
|
||||||
|
|
||||||
|
mock->ExpectSendFailure("foo");
|
||||||
|
EXPECT_FALSE(SendString(mock, "foo"));
|
||||||
|
|
||||||
EXPECT_NONFATAL_FAILURE(SendString(mock, "foo"), "no message was expected");
|
EXPECT_NONFATAL_FAILURE(SendString(mock, "foo"), "no message was expected");
|
||||||
|
|
||||||
mock->ExpectSend("foo");
|
mock->ExpectSend("foo");
|
||||||
|
|
@ -274,11 +277,24 @@ TEST(SocketMockTest, TestReceiveSuccess) {
|
||||||
mock.AddReceive("123");
|
mock.AddReceive("123");
|
||||||
EXPECT_TRUE(ReceiveString(&mock, "abc"));
|
EXPECT_TRUE(ReceiveString(&mock, "abc"));
|
||||||
EXPECT_TRUE(ReceiveString(&mock, "123"));
|
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) {
|
TEST(SocketMockTest, TestReceiveFailure) {
|
||||||
SocketMock* mock = new SocketMock;
|
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");
|
EXPECT_NONFATAL_FAILURE(ReceiveString(mock, "foo"), "no message was ready");
|
||||||
|
|
||||||
mock->ExpectSend("foo");
|
mock->ExpectSend("foo");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue