Skip to content

Commit 15c6cbb

Browse files
committed
Fix Unit Tests
1 parent f67688e commit 15c6cbb

File tree

3 files changed

+124
-21
lines changed

3 files changed

+124
-21
lines changed

source/core_mqtt.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,22 +2833,22 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
28332833
pContext->index = 0;
28342834
( void ) memset( pContext->networkBuffer.pBuffer, 0, pContext->networkBuffer.size );
28352835

2836-
if( *pSessionPresent != true )
2836+
if( *pSessionPresent != true && pContext->outgoingPublishRecordMaxCount > 0U )
28372837
{
28382838
/* Clear any existing records if a new session is established. */
2839-
if( pContext->outgoingPublishRecordMaxCount > 0U )
2840-
{
2841-
( void ) memset( pContext->outgoingPublishRecords,
2842-
0x00,
2843-
pContext->outgoingPublishRecordMaxCount * sizeof( *pContext->outgoingPublishRecords ) );
2844-
}
2845-
2846-
if( pContext->incomingPublishRecordMaxCount > 0U )
2847-
{
2848-
( void ) memset( pContext->incomingPublishRecords,
2849-
0x00,
2850-
pContext->incomingPublishRecordMaxCount * sizeof( *pContext->incomingPublishRecords ) );
2851-
}
2839+
( void ) memset( pContext->outgoingPublishRecords,
2840+
0x00,
2841+
pContext->outgoingPublishRecordMaxCount * sizeof( *pContext->outgoingPublishRecords ) );
2842+
}
2843+
else if( *pSessionPresent != true && pContext->incomingPublishRecordMaxCount > 0U )
2844+
{
2845+
( void ) memset( pContext->incomingPublishRecords,
2846+
0x00,
2847+
pContext->incomingPublishRecordMaxCount * sizeof( *pContext->incomingPublishRecords ) );
2848+
}
2849+
else
2850+
{
2851+
/* MISRA Empty body */
28522852
}
28532853

28542854
pContext->connectStatus = MQTTConnected;
@@ -2879,7 +2879,7 @@ MQTTStatus_t MQTT_Connect( MQTTContext_t * pContext,
28792879
LogInfo( ( "MQTT Connection is either already established or a disconnect is pending, return status = %s.",
28802880
MQTT_Status_strerror( status ) ) );
28812881
}
2882-
else if( status == MQTTBadParameter )
2882+
else if( pContext == NULL )
28832883
{
28842884
LogError( ( "MQTT connection failed with status = %s.",
28852885
MQTT_Status_strerror( status ) ) );

test/unit-test/core_mqtt_serializer_utest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,7 +1904,7 @@ void test_MQTT_GetIncomingPacketTypeAndLength( void )
19041904
memset( buffer, 0x00, 10 );
19051905
bufPtr = buffer;
19061906
status = MQTT_GetIncomingPacketTypeAndLength( mockReceiveFailure, &networkContext, &mqttPacket );
1907-
TEST_ASSERT_EQUAL( MQTTRecvFailed, status );
1907+
TEST_ASSERT_EQUAL( MQTTStatusDisconnectPending, status );
19081908

19091909
/* Test if no data is available. */
19101910
bufPtr = buffer;
@@ -1921,7 +1921,7 @@ void test_MQTT_GetIncomingPacketTypeAndLength( void )
19211921
bufPtr = buffer;
19221922
buffer[ 0 ] = MQTT_PACKET_TYPE_PUBREL;
19231923
status = MQTT_GetIncomingPacketTypeAndLength( mockReceiveSucceedThenFail, &networkContext, &mqttPacket );
1924-
TEST_ASSERT_EQUAL( MQTTBadResponse, status );
1924+
TEST_ASSERT_EQUAL( MQTTStatusDisconnectPending, status );
19251925
}
19261926

19271927
/* ========================================================================== */

0 commit comments

Comments
 (0)