Files
harbour-core/harbour/tests/base64.prg
Viktor Szakats ffaf84caa2 2011-02-11 13:30 UTC+0100 Viktor Szakats (harbour.01 syenar.hu)
* src/rtl/base64d.c
    ! Fixed crash when empty or non-string parameter was passed to HB_BASE64DECODE().

  + tests/base64.prg
    + Added base64 test suite. [Tamas]
2011-02-11 12:31:19 +00:00

47 lines
1.2 KiB
Plaintext

/*
* $Id$
*/
/* RFC4648 test vectors for base64 */
#pragma warninglevel=3
#pragma exitseverity=2
REQUEST HB_GT_CGI_DEFAULT
PROCEDURE Main()
LOCAL aTestVectors, aVector, cStr
aTestVectors := { ;
"" => "", ;
"f" => "Zg==", ;
"fo" => "Zm8=", ;
"foo" => "Zm9v", ;
"foob" => "Zm9vYg==", ;
"fooba" => "Zm9vYmE=", ;
"foobar" => "Zm9vYmFy" }
FOR EACH aVector IN aTestVectors
cStr := hb_base64encode( aVector:__enumKey )
IF cStr != aVector
OutStd( hb_strFormat( "hb_base64encode(): expected '%s' got '%s' while encoding '%s'" + hb_eol(), ;
aVector:__enumKey(), cStr, aVector ) )
ELSE
OutStd( hb_strFormat( "hb_base64encode(): passed '%s'" + hb_eol(), aVector:__enumKey ) )
ENDIF
cStr := hb_base64decode( aVector )
IF cStr != aVector:__enumKey()
OutStd( hb_strFormat( "hb_base64decode(): expected '%s' got '%s' while decoding '%s'" + hb_eol(), ;
aVector, cStr, aVector:__enumKey() ) )
ELSE
OutStd( hb_strFormat( "hb_base64decode(): passed '%s'" + hb_eol(), aVector ) )
ENDIF
NEXT
RETURN