diff --git a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c index 8a8763043..0c2577cf0 100644 --- a/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c +++ b/test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c @@ -795,10 +795,48 @@ void test_FreeRTOS_get_tx_head_InvalidParams( void ) pucReturn = FreeRTOS_get_tx_head( NULL, &xLength ); TEST_ASSERT_EQUAL( NULL, pucReturn ); +} + +/** + * @brief Socket with stream not yet created is passed to the function. + */ +void test_FreeRTOS_get_tx_head_NoStream( void ) +{ + uint8_t * pucReturn; + FreeRTOS_Socket_t xSocket; + BaseType_t xLength; + uint8_t ucStream[ ipconfigTCP_MSS ]; + const size_t uxRemainingSize = 5; + + memset( &xSocket, 0, sizeof( xSocket ) ); + memset( ucStream, 0, ipconfigTCP_MSS ); + /* NULL stream. */ xSocket.ucProtocol = FREERTOS_IPPROTO_TCP; + pvPortMalloc_ExpectAnyArgsAndReturn(ucStream); + uxStreamBufferGetSpace_ExpectAndReturn( ( StreamBuffer_t * ) ucStream, uxRemainingSize ); pucReturn = FreeRTOS_get_tx_head( &xSocket, &xLength ); - TEST_ASSERT_EQUAL( NULL, pucReturn ); + TEST_ASSERT_EQUAL_PTR( &( ( ( StreamBuffer_t * ) ucStream )->ucArray[ 0 ] ), pucReturn ); + TEST_ASSERT_EQUAL( uxRemainingSize, xLength ); +} + +/** + * @brief Socket with stream not created but malloc failed previously. + */ +void test_FreeRTOS_get_tx_head_NoStreamMallocError( void ) +{ + uint8_t * pucReturn; + FreeRTOS_Socket_t xSocket; + BaseType_t xLength; + + memset( &xSocket, 0, sizeof( xSocket ) ); + + /* NULL stream. */ + xSocket.ucProtocol = FREERTOS_IPPROTO_TCP; + xSocket.u.xTCP.bits.bMallocError = pdTRUE; + pucReturn = FreeRTOS_get_tx_head( &xSocket, &xLength ); + TEST_ASSERT_EQUAL_PTR( NULL, pucReturn ); + TEST_ASSERT_EQUAL( 0, xLength ); } /**