@@ -463,11 +463,59 @@ void test_MQTT_GetConnectPacketSize( void )
463463 status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
464464 TEST_ASSERT_EQUAL_INT ( MQTTBadParameter , status );
465465
466+ /* Verify NULL client identifier with provided non-zero length fails. */
466467 connectInfo .pClientIdentifier = NULL ;
467468 connectInfo .clientIdentifierLength = CLIENT_IDENTIFIER_LENGTH ;
469+ connectInfo .cleanSession = true;
468470 status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
469471 TEST_ASSERT_EQUAL_INT ( MQTTBadParameter , status );
470472
473+ /* Verify empty string client ID with provided non-zero length fails. */
474+ connectInfo .pClientIdentifier = "" ;
475+ connectInfo .clientIdentifierLength = 99U ;
476+ connectInfo .cleanSession = true;
477+ status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
478+ TEST_ASSERT_EQUAL_INT ( MQTTBadParameter , status );
479+
480+ /* Verify zero-length client identifier must have clean session. */
481+ connectInfo .pClientIdentifier = NULL ;
482+ connectInfo .clientIdentifierLength = 0U ;
483+ connectInfo .cleanSession = false;
484+ status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
485+ TEST_ASSERT_EQUAL_INT ( MQTTBadParameter , status );
486+
487+ /* Verify zero-length client identifier must have clean session. */
488+ connectInfo .pClientIdentifier = "" ;
489+ connectInfo .clientIdentifierLength = 0U ;
490+ connectInfo .cleanSession = false;
491+ status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
492+ TEST_ASSERT_EQUAL_INT ( MQTTBadParameter , status );
493+
494+ /* NULL client ID and client ID length of 0 is treated as zero-length identifier */
495+ connectInfo .pClientIdentifier = NULL ;
496+ connectInfo .clientIdentifierLength = 0U ;
497+ connectInfo .cleanSession = true;
498+ connectInfo .pUserName = NULL ;
499+ connectInfo .pPassword = NULL ;
500+ status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
501+ TEST_ASSERT_EQUAL_INT ( MQTTSuccess , status );
502+ /* Make sure remaining size returned is 12. */
503+ TEST_ASSERT_EQUAL_INT ( 12 , remainingLength );
504+ /* Make sure packet size is 14. */
505+ TEST_ASSERT_EQUAL_INT ( 14 , packetSize );
506+
507+ /* Empty string client ID and client ID length of 0 is treated as zero-length identifier */
508+ connectInfo .pClientIdentifier = "" ;
509+ connectInfo .clientIdentifierLength = 0U ;
510+ connectInfo .pUserName = NULL ;
511+ connectInfo .pPassword = NULL ;
512+ status = MQTT_GetConnectPacketSize ( & connectInfo , NULL , & remainingLength , & packetSize );
513+ TEST_ASSERT_EQUAL_INT ( MQTTSuccess , status );
514+ /* Make sure remaining size returned is 12. */
515+ TEST_ASSERT_EQUAL_INT ( 12 , remainingLength );
516+ /* Make sure packet size is 14. */
517+ TEST_ASSERT_EQUAL_INT ( 14 , packetSize );
518+
471519 /* Test a will message payload length that is too large. */
472520 memset ( & connectInfo , 0x0 , sizeof ( connectInfo ) );
473521 connectInfo .pClientIdentifier = CLIENT_IDENTIFIER ;
0 commit comments