MPS Reader Tests: Test feed() of NULL buffer
Signed-off-by: Hanno Becker <hanno.becker@arm.com>
This commit is contained in:
parent
223b72e40e
commit
2b8bad3e80
@ -117,3 +117,6 @@ mbedtls_reader_inconsistent_usage:7
|
||||
|
||||
MPS Reader: Pausing, inconsistent continuation, #8
|
||||
mbedtls_reader_inconsistent_usage:8
|
||||
|
||||
MPS Reader: Feed with invalid buffer (NULL)
|
||||
mbedtls_mps_reader_feed_empty:0
|
||||
|
@ -1059,3 +1059,41 @@ void mbedtls_reader_inconsistent_usage( int option )
|
||||
mbedtls_reader_free( &rd );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:TEST_SUITE_MPS_READER */
|
||||
void mbedtls_mps_reader_feed_empty( int option )
|
||||
{
|
||||
/* This test exercises the behaviour of the reader when it is
|
||||
* fed a NULL buffer. */
|
||||
unsigned char buf[100];
|
||||
unsigned char *tmp;
|
||||
mbedtls_reader rd;
|
||||
for( int i=0; (unsigned) i < sizeof( buf ); i++ )
|
||||
buf[i] = (unsigned char) i;
|
||||
|
||||
/* Preparation (lower layer) */
|
||||
mbedtls_reader_init( &rd, NULL, 0 );
|
||||
switch( option )
|
||||
{
|
||||
case 0: /* NULL buffer */
|
||||
TEST_ASSERT( mbedtls_reader_feed( &rd, NULL, sizeof( buf ) ) ==
|
||||
MBEDTLS_ERR_MPS_READER_INVALID_ARG );
|
||||
break;
|
||||
|
||||
default:
|
||||
TEST_ASSERT( 0 );
|
||||
break;
|
||||
}
|
||||
/* Subsequent feed-calls should still succeed. */
|
||||
TEST_ASSERT( mbedtls_reader_feed( &rd, buf, sizeof( buf ) ) == 0 );
|
||||
|
||||
/* Consumption (upper layer) */
|
||||
TEST_ASSERT( mbedtls_reader_get( &rd, 100, &tmp, NULL ) == 0 );
|
||||
ASSERT_COMPARE( tmp, 100, buf, 100 );
|
||||
TEST_ASSERT( mbedtls_reader_commit( &rd ) == 0 );
|
||||
|
||||
/* Wrapup */
|
||||
TEST_ASSERT( mbedtls_reader_reclaim( &rd, NULL ) == 0 );
|
||||
mbedtls_reader_free( &rd );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
Loading…
Reference in New Issue
Block a user