* contrib/hblzf/3rd/liblzf/Changes
* contrib/hblzf/3rd/liblzf/crc32.h
* contrib/hblzf/3rd/liblzf/LICENSE
* contrib/hblzf/3rd/liblzf/lzf.h
* contrib/hblzf/3rd/liblzf/lzf_c.c
* contrib/hblzf/3rd/liblzf/lzf_d.c
* contrib/hblzf/3rd/liblzf/lzfP.h
* contrib/hblzf/3rd/liblzf/README
+ Set svn:eol-style=native
* contrib/hblzf/3rd/liblzf/lzf.hbc
* contrib/hblzf/3rd/liblzf/lzf.hbp
* contrib/hblzf/hblzf.c
* contrib/hblzf/hblzf.hbc
* contrib/hblzf/hblzf.hbp
* contrib/hblzf/tests/hbmk.hbm
* contrib/hblzf/tests/test.prg
* contrib/hblzf/tests/test2.prg
! Fixed SVN ID (I hope) and set svn:eol-style=native
139 lines
4.4 KiB
Plaintext
139 lines
4.4 KiB
Plaintext
/*
|
|
* $Id$
|
|
*/
|
|
|
|
#include "simpleio.ch"
|
|
|
|
#include "hblzf.ch"
|
|
|
|
#define TEST_STRING "This is test of LZF extension"
|
|
#define _NREPL_ 128
|
|
|
|
PROCEDURE Main()
|
|
LOCAL cStr, str_compressed, str_decompressed
|
|
LOCAL b64_expected_result := "BFRoaXMgIAIUdGVzdCBvZiBMWkYgZXh0ZW5zaW9u"
|
|
LOCAL nLen, nResult := 0
|
|
|
|
? "LZF Api version is", ;
|
|
hb_ntos( hb_lzf_version() ) + "(0x" + hb_numtohex( hb_lzf_version() ) +")"
|
|
? "LibLZF optimized for", iif( hb_lzf_optimized_for_speed(), "speed.", "compression." )
|
|
|
|
? "--- test 1 ---"
|
|
/*
|
|
If the output buffer is not large enough or any error occurs
|
|
hb_lzf_compress return NIL
|
|
*/
|
|
cStr := TEST_STRING
|
|
str_compressed := hb_lzf_compress( cStr, 15, @nResult )
|
|
|
|
IF nResult == HB_LZF_OK
|
|
? "Lenght of a string is", hb_ntos( Len( cStr ) )
|
|
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
|
|
ELSE
|
|
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
|
|
ENDIF
|
|
|
|
? "--- test 2 ---"
|
|
cStr := TEST_STRING
|
|
str_compressed := Space( 15 )
|
|
str_compressed := hb_lzf_compress( cStr, @str_compressed, @nResult )
|
|
|
|
IF nResult == HB_LZF_OK
|
|
? "Lenght of a string is", hb_ntos( Len( cStr ) )
|
|
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
|
|
ELSE
|
|
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
|
|
ENDIF
|
|
|
|
? "--- test 3 ---"
|
|
nLen := hb_lzf_compressBound( cStr )
|
|
|
|
cStr := TEST_STRING
|
|
str_compressed := hb_lzf_compress( cStr, nLen, @nResult )
|
|
|
|
IF nResult == HB_LZF_OK
|
|
? "Lenght of a string is", hb_ntos( Len( cStr ) )
|
|
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
|
|
|
|
? iif( hb_base64encode( str_compressed ) == b64_expected_result, "OK!", "not OK!" )
|
|
ELSE
|
|
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
|
|
ENDIF
|
|
|
|
? "--- test 4 ---"
|
|
nLen := hb_lzf_compressBound( cStr )
|
|
str_compressed := Space( nLen )
|
|
|
|
cStr := TEST_STRING
|
|
str_compressed := hb_lzf_compress( cStr, @str_compressed, @nResult )
|
|
|
|
IF nResult == HB_LZF_OK
|
|
? "Lenght of a string is", hb_ntos( Len( cStr ) )
|
|
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
|
|
|
|
? iif( hb_base64encode( str_compressed ) == b64_expected_result, "OK!", "not OK!" )
|
|
ELSE
|
|
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
|
|
ENDIF
|
|
|
|
? "--- test 5 ---"
|
|
cStr := Replicate( TEST_STRING, _NREPL_ )
|
|
str_compressed := hb_lzf_compress( cStr, NIL, @nResult )
|
|
|
|
IF nResult == HB_LZF_OK
|
|
? "Lenght of a string is", hb_ntos( Len( cStr ) )
|
|
? "Lenght of a compressed string is", hb_ntos( Len( str_compressed ) )
|
|
ELSE
|
|
? "hb_lzf_compress() return ", iif( nResult == HB_LZF_BUF_ERROR, "LZF_BUF_ERROR", "LZF_MEM_ERROR" )
|
|
ENDIF
|
|
|
|
? "--- test 6 ---"
|
|
str_decompressed := hb_lzf_decompress( str_compressed, NIL, @nResult )
|
|
|
|
IF nResult == HB_LZF_DATA_CORRUPTED
|
|
? "LZF decompression failed, compressed data corrupted"
|
|
ELSE
|
|
? iif( cStr == str_decompressed, "OK!", "not OK!" )
|
|
ENDIF
|
|
|
|
? "--- test 7 ---"
|
|
cStr := Replicate( TEST_STRING, _NREPL_ )
|
|
str_compressed := hb_zcompress( cStr, NIL, @nResult )
|
|
|
|
str_decompressed := hb_lzf_decompress( str_compressed, NIL, @nResult )
|
|
|
|
IF nResult == HB_LZF_DATA_CORRUPTED
|
|
? "LZF decompression failed, compressed data corrupted!"
|
|
ELSE
|
|
? iif( cStr == str_decompressed, "OK!", "not OK!" )
|
|
ENDIF
|
|
|
|
? "--- test 8 ---"
|
|
cStr := Replicate( TEST_STRING, _NREPL_ )
|
|
str_compressed := hb_lzf_compress( cStr, NIL, @nResult )
|
|
|
|
str_decompressed := Space( 4096 )
|
|
str_decompressed := hb_lzf_decompress( str_compressed, @str_decompressed, @nResult )
|
|
|
|
IF nResult == HB_LZF_DATA_CORRUPTED
|
|
? "LZF decompression failed, compressed data corrupted!"
|
|
ELSE
|
|
? iif( cStr == str_decompressed, "OK!", "not OK!" )
|
|
ENDIF
|
|
|
|
? "--- test 9 ---"
|
|
cStr := Replicate( TEST_STRING, _NREPL_ )
|
|
str_compressed := hb_lzf_compress( cStr, NIL, @nResult )
|
|
|
|
str_decompressed := ""
|
|
str_decompressed := hb_lzf_decompress( str_compressed, @str_decompressed, @nResult )
|
|
|
|
IF nResult != HB_LZF_OK
|
|
? "hb_lzf_decompress() return", ;
|
|
iif( nResult == HB_LZF_MEM_ERROR, "HB_LZF_MEM_ERROR", hb_ntos( nResult ) )
|
|
ELSE
|
|
? iif( cStr == str_decompressed, "OK!", "not OK!" )
|
|
ENDIF
|
|
|
|
RETURN
|