Skip to content

Commit

Permalink
Fix protocol handler unit test crash (#3623)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobkeeler authored Jan 27, 2021
1 parent 81428f4 commit 78e705c
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions src/components/protocol_handler/test/protocol_handler_tm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4488,8 +4488,8 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_CorrectHashId) {

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4502,6 +4502,7 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_CorrectHashId) {
full_version);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

ProtocolPacket protocol_packet;
RESULT_CODE res = protocol_packet.deserializePacket(raw_message->data(),
Expand All @@ -4525,8 +4526,8 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_NOT_SUPPORTED) {

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4539,6 +4540,7 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_NOT_SUPPORTED) {
full_version);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

ProtocolPacket protocol_packet;
RESULT_CODE res = protocol_packet.deserializePacket(raw_message->data(),
Expand All @@ -4560,8 +4562,8 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_WRONG) {

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4574,6 +4576,7 @@ TEST_F(ProtocolHandlerImplTest, SetHashId_HASH_ID_WRONG) {
full_version);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

ProtocolPacket protocol_packet;
RESULT_CODE res = protocol_packet.deserializePacket(raw_message->data(),
Expand Down Expand Up @@ -4700,8 +4703,8 @@ TEST_F(ProtocolHandlerImplTest,

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4711,10 +4714,11 @@ TEST_F(ProtocolHandlerImplTest,
kFinalMessage);
handler->Handle(message);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

EXPECT_EQ(data_value,
raw_message->data()[protocol_handler::PROTOCOL_HEADER_V2_SIZE]);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}

TEST_F(ProtocolHandlerImplTest,
Expand All @@ -4739,8 +4743,8 @@ TEST_F(ProtocolHandlerImplTest,

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4750,10 +4754,11 @@ TEST_F(ProtocolHandlerImplTest,
kFinalMessage);
handler->Handle(message);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

EXPECT_EQ(data_value,
raw_message->data()[protocol_handler::PROTOCOL_HEADER_V2_SIZE]);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}

TEST_F(ProtocolHandlerImplTest,
Expand Down Expand Up @@ -4791,8 +4796,8 @@ TEST_F(ProtocolHandlerImplTest,

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4803,10 +4808,11 @@ TEST_F(ProtocolHandlerImplTest,
message->set_protection_flag(PROTECTION_ON);
handler->Handle(message);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

EXPECT_EQ(data_value,
raw_message->data()[protocol_handler::PROTOCOL_HEADER_V2_SIZE]);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}

TEST_F(ProtocolHandlerImplTest,
Expand Down Expand Up @@ -4841,8 +4847,8 @@ TEST_F(ProtocolHandlerImplTest,

RawMessagePtr raw_message;
EXPECT_CALL(transport_manager_mock, SendMessageToDevice(_))
.WillOnce(DoAll(NotifyTestAsyncWaiter(waiter),
SaveArg<0>(&raw_message),
.WillOnce(DoAll(SaveArg<0>(&raw_message),
NotifyTestAsyncWaiter(waiter),
Return(transport_manager::E_SUCCESS)));
times++;

Expand All @@ -4853,10 +4859,11 @@ TEST_F(ProtocolHandlerImplTest,
message->set_protection_flag(PROTECTION_ON);
handler->Handle(message);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
ASSERT_NE(0, raw_message.use_count());

EXPECT_EQ(encrypted_data,
raw_message->data()[protocol_handler::PROTOCOL_HEADER_V2_SIZE]);

EXPECT_TRUE(waiter->WaitFor(times, kAsyncExpectationsTimeout));
}

TEST_F(ProtocolHandlerImplTest, DecryptFrame_NoSecurityManager_Cancelled) {
Expand Down

0 comments on commit 78e705c

Please sign in to comment.