Skip to content

Commit

Permalink
Fix Unit Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DakshitBabbar committed Sep 11, 2024
1 parent f67688e commit 15c6cbb
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 21 deletions.
30 changes: 15 additions & 15 deletions source/core_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2833,22 +2833,22 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
pContext->index = 0;
( void ) memset( pContext->networkBuffer.pBuffer, 0, pContext->networkBuffer.size );

if( *pSessionPresent != true )
if( *pSessionPresent != true && pContext->outgoingPublishRecordMaxCount > 0U )
{
/* Clear any existing records if a new session is established. */
if( pContext->outgoingPublishRecordMaxCount > 0U )
{
( void ) memset( pContext->outgoingPublishRecords,
0x00,
pContext->outgoingPublishRecordMaxCount * sizeof( *pContext->outgoingPublishRecords ) );
}

if( pContext->incomingPublishRecordMaxCount > 0U )
{
( void ) memset( pContext->incomingPublishRecords,
0x00,
pContext->incomingPublishRecordMaxCount * sizeof( *pContext->incomingPublishRecords ) );
}
( void ) memset( pContext->outgoingPublishRecords,
0x00,
pContext->outgoingPublishRecordMaxCount * sizeof( *pContext->outgoingPublishRecords ) );
}
else if( *pSessionPresent != true && pContext->incomingPublishRecordMaxCount > 0U )
{
( void ) memset( pContext->incomingPublishRecords,
0x00,
pContext->incomingPublishRecordMaxCount * sizeof( *pContext->incomingPublishRecords ) );
}
else
{
/* MISRA Empty body */
}

pContext->connectStatus = MQTTConnected;
Expand Down Expand Up @@ -2879,7 +2879,7 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
LogInfo( ( "MQTT Connection is either already established or a disconnect is pending, return status = %s.",
MQTT_Status_strerror( status ) ) );
}
else if( status == MQTTBadParameter )
else if( pContext == NULL )
{
LogError( ( "MQTT connection failed with status = %s.",
MQTT_Status_strerror( status ) ) );
Expand Down
4 changes: 2 additions & 2 deletions test/unit-test/core_mqtt_serializer_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ void test_MQTT_GetIncomingPacketTypeAndLength( void )
memset( buffer, 0x00, 10 );
bufPtr = buffer;
status = MQTT_GetIncomingPacketTypeAndLength( mockReceiveFailure, &networkContext, &mqttPacket );
TEST_ASSERT_EQUAL( MQTTRecvFailed, status );
TEST_ASSERT_EQUAL( MQTTStatusDisconnectPending, status );

/* Test if no data is available. */
bufPtr = buffer;
Expand All @@ -1921,7 +1921,7 @@ void test_MQTT_GetIncomingPacketTypeAndLength( void )
bufPtr = buffer;
buffer[ 0 ] = MQTT_PACKET_TYPE_PUBREL;
status = MQTT_GetIncomingPacketTypeAndLength( mockReceiveSucceedThenFail, &networkContext, &mqttPacket );
TEST_ASSERT_EQUAL( MQTTBadResponse, status );
TEST_ASSERT_EQUAL( MQTTStatusDisconnectPending, status );
}

/* ========================================================================== */
Expand Down
Loading

0 comments on commit 15c6cbb

Please sign in to comment.