in platform/posix/transport/utest/sockets_utest.c [306:367]
void test_Sockets_Connect_Fail_setsockopt( void )
{
SocketStatus_t socketStatus, expectedSocketStatus;
int tcpSocket = 1;
uint16_t i, j;
int32_t allErrorCases[] =
{
EBADF, EDOM, EINVAL, EISCONN,
ENOPROTOOPT, ENOTSOCK, ENOMEM, ENOBUFS
};
for( i = 0; i < ( sizeof( allErrorCases ) / sizeof( int32_t ) ); i++ )
{
errno = allErrorCases[ i ];
for( j = 0; j < 2; j++ )
{
expectSocketsConnectCalls( NUM_ADDR_INFO );
if( j == 0 )
{
setsockopt_ExpectAnyArgsAndReturn( -1 );
/* for ENOPROTOOPT case, Sockets_Connect continues
* despite setsockopt returning error. */
if( errno == ENOPROTOOPT )
{
setsockopt_ExpectAnyArgsAndReturn( -1 );
}
}
else
{
setsockopt_ExpectAnyArgsAndReturn( 0 );
setsockopt_ExpectAnyArgsAndReturn( -1 );
}
socketStatus = Sockets_Connect( &tcpSocket,
&serverInfo,
SEND_RECV_TIMEOUT,
SEND_RECV_TIMEOUT );
if( ( errno == ENOMEM ) || ( errno == ENOBUFS ) )
{
expectedSocketStatus = SOCKETS_INSUFFICIENT_MEMORY;
}
else if( ( errno == ENOTSOCK ) || ( errno == EDOM ) || ( errno == EBADF ) )
{
expectedSocketStatus = SOCKETS_INVALID_PARAMETER;
}
else if( errno == ENOPROTOOPT )
{
expectedSocketStatus = SOCKETS_SUCCESS;
}
else
{
expectedSocketStatus = SOCKETS_API_ERROR;
}
TEST_ASSERT_EQUAL( expectedSocketStatus, socketStatus );
}
}
}