Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tony-josi-aws committed Sep 11, 2023
1 parent f7dedf4 commit 7d17533
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion test/unit-test/FreeRTOS_Sockets/FreeRTOS_Sockets_TCP_API_utest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down

0 comments on commit 7d17533

Please sign in to comment.