Skip to content

Commit

Permalink
add checks for receiver and sender
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Jun 21, 2023
1 parent 27032fa commit 1097932
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/protocols/bdx/tests/TestBdxTransferSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,14 @@ void Reset()
kSimulateBadAcceptMessageError = false;
kSimulateDuplicateBlockError = false;
sBlockCopy = nullptr;
sBdxReceiver->Reset();
sBdxSender->Reset();
if (sBdxReceiver)
{
sBdxReceiver->Reset();
}
if (sBdxSender)
{
sBdxSender->Reset();
}
sResponderExpectedOutputEvent = chip::bdx::TransferSession::OutputEvent(TransferSession::OutputEventType::kNone);
sInitiatorExpectedOutputEvent = chip::bdx::TransferSession::OutputEvent(TransferSession::OutputEventType::kNone);
sBdxReceiver = nullptr;
Expand All @@ -187,7 +193,7 @@ void OnResponderOutputEventReceived(void * context, TransferSession::OutputEvent
{
ChipLogProgress(BDX, "OnResponderOutputEventReceived %s", event.ToString(event.EventType));
nlTestSuite * inSuite = static_cast<nlTestSuite *>(context);
if (inSuite == nullptr)
if (inSuite == nullptr || sBdxReceiver == nullptr || sBdxSender == nullptr)
{
return;
}
Expand Down Expand Up @@ -342,7 +348,7 @@ void OnInitiatorOutputEventReceived(void * context, TransferSession::OutputEvent
{
ChipLogProgress(BDX, "OnInitiatorOutputEventReceived %s", event.ToString(event.EventType));
nlTestSuite * inSuite = static_cast<nlTestSuite *>(context);
if (inSuite == nullptr)
if (inSuite == nullptr || sBdxReceiver == nullptr || sBdxSender == nullptr)
{
return;
}
Expand Down Expand Up @@ -388,7 +394,10 @@ void OnInitiatorOutputEventReceived(void * context, TransferSession::OutputEvent
}
}

NL_TEST_ASSERT(inSuite, sBdxSender != nullptr && sBdxReceiver != nullptr);
if (sBdxReceiver == nullptr || sBdxSender == nullptr)
{
break;
}
// Verify that MaxBlockSize was set appropriately
NL_TEST_ASSERT(inSuite, sBdxReceiver->GetTransferBlockSize() <= kProposedBlockSize);

Expand Down Expand Up @@ -431,6 +440,11 @@ void OnInitiatorOutputEventReceived(void * context, TransferSession::OutputEvent

bool RespondToLastInitiatorOutputEvent(nlTestSuite * inSuite)
{
if (sBdxReceiver == nullptr || sBdxSender == nullptr)
{
return false;
}

switch (sLastInitiatorOutputEvent.EventType)
{
case TransferSession::OutputEventType::kMsgToSend: {
Expand Down Expand Up @@ -784,7 +798,7 @@ void SendAcceptTransferForInitReceived(nlTestSuite * inSuite)
{
acceptData.ControlMode = TransferControlFlags::kSenderDrive;
}
else
else if (sBdxReceiver != nullptr)
{
acceptData.ControlMode = sBdxReceiver->GetControlMode();
}
Expand Down

0 comments on commit 1097932

Please sign in to comment.