- Added further coverage tests for Base64
This commit is contained in:
parent
37940d9ff6
commit
5946fd9124
2 changed files with 42 additions and 21 deletions
|
@ -1,44 +1,59 @@
|
|||
Test case base64_encode #1
|
||||
base64_encode:"":""
|
||||
base64_encode:"":"":1000:0
|
||||
|
||||
Test case base64_encode #2
|
||||
base64_encode:"f":"Zg=="
|
||||
base64_encode:"f":"Zg==":1000:0
|
||||
|
||||
Test case base64_encode #3
|
||||
base64_encode:"fo":"Zm8="
|
||||
base64_encode:"fo":"Zm8=":1000:0
|
||||
|
||||
Test case base64_encode #4
|
||||
base64_encode:"foo":"Zm9v"
|
||||
base64_encode:"foo":"Zm9v":1000:0
|
||||
|
||||
Test case base64_encode #5
|
||||
base64_encode:"foob":"Zm9vYg=="
|
||||
base64_encode:"foob":"Zm9vYg==":1000:0
|
||||
|
||||
Test case base64_encode #6
|
||||
base64_encode:"fooba":"Zm9vYmE="
|
||||
base64_encode:"fooba":"Zm9vYmE=":1000:0
|
||||
|
||||
Test case base64_encode #7
|
||||
base64_encode:"foobar":"Zm9vYmFy"
|
||||
base64_encode:"foobar":"Zm9vYmFy":1000:0
|
||||
|
||||
Test case base64_decode #1
|
||||
base64_decode:"":""
|
||||
base64_decode:"":"":0
|
||||
|
||||
Test case base64_decode #2
|
||||
base64_decode:"Zg==":"f"
|
||||
base64_decode:"Zg==":"f":0
|
||||
|
||||
Test case base64_decode #3
|
||||
base64_decode:"Zm8=":"fo"
|
||||
base64_decode:"Zm8=":"fo":0
|
||||
|
||||
Test case base64_decode #4
|
||||
base64_decode:"Zm9v":"foo"
|
||||
base64_decode:"Zm9v":"foo":0
|
||||
|
||||
Test case base64_decode #5
|
||||
base64_decode:"Zm9vYg==":"foob"
|
||||
base64_decode:"Zm9vYg==":"foob":0
|
||||
|
||||
Test case base64_decode #6
|
||||
base64_decode:"Zm9vYmE=":"fooba"
|
||||
base64_decode:"Zm9vYmE=":"fooba":0
|
||||
|
||||
Test case base64_decode #7
|
||||
base64_decode:"Zm9vYmFy":"foobar"
|
||||
base64_decode:"Zm9vYmFy":"foobar":0
|
||||
|
||||
Base64 encode (buffer size just right)
|
||||
base64_encode:"foobar":"Zm9vYmFy":9:0
|
||||
|
||||
Base64 encode (buffer size too small)
|
||||
base64_encode:"foobar":"":8:POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL
|
||||
|
||||
Base64 decode (Illegal character)
|
||||
base64_decode:"zm#=":"":POLARSSL_ERR_BASE64_INVALID_CHARACTER
|
||||
|
||||
Base64 decode (Too much equal signs)
|
||||
base64_decode:"zm===":"":POLARSSL_ERR_BASE64_INVALID_CHARACTER
|
||||
|
||||
Base64 decode (Invalid char after equal signs)
|
||||
base64_decode:"zm=masd":"":POLARSSL_ERR_BASE64_INVALID_CHARACTER
|
||||
|
||||
Base64 Selftest
|
||||
base64_selftest:
|
||||
|
|
|
@ -3,23 +3,26 @@ BEGIN_HEADER
|
|||
END_HEADER
|
||||
|
||||
BEGIN_CASE
|
||||
base64_encode:src_string:dst_string
|
||||
base64_encode:src_string:dst_string:dst_buf_size:result
|
||||
{
|
||||
unsigned char src_str[1000];
|
||||
unsigned char dst_str[1000];
|
||||
int len = 1000;
|
||||
int len = {dst_buf_size};
|
||||
|
||||
memset(src_str, 0x00, 1000);
|
||||
memset(dst_str, 0x00, 1000);
|
||||
|
||||
strcpy( (char *) src_str, {src_string} );
|
||||
TEST_ASSERT( base64_encode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == 0 );
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, {dst_string} ) == 0 );
|
||||
TEST_ASSERT( base64_encode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == {result} );
|
||||
if( {result} == 0 )
|
||||
{
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, {dst_string} ) == 0 );
|
||||
}
|
||||
}
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
base64_decode:src_string:dst_string
|
||||
base64_decode:src_string:dst_string:result
|
||||
{
|
||||
unsigned char src_str[1000];
|
||||
unsigned char dst_str[1000];
|
||||
|
@ -30,8 +33,11 @@ base64_decode:src_string:dst_string
|
|||
memset(dst_str, 0x00, 1000);
|
||||
|
||||
strcpy( (char *) src_str, {src_string} );
|
||||
TEST_ASSERT( res = base64_decode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == 0 );
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, {dst_string} ) == 0 );
|
||||
TEST_ASSERT( res = base64_decode( dst_str, &len, src_str, strlen( (char *) src_str ) ) == {result} );
|
||||
if( {result} == 0 )
|
||||
{
|
||||
TEST_ASSERT( strcmp( (char *) dst_str, {dst_string} ) == 0 );
|
||||
}
|
||||
}
|
||||
END_CASE
|
||||
|
||||
|
|
Loading…
Reference in a new issue