* test for bzip2 from Mantis

git-svn-id: trunk@20977 -
This commit is contained in:
marco 2012-04-22 10:12:45 +00:00
parent d8101679fa
commit 743e58ed0f
5 changed files with 127 additions and 3 deletions

2
.gitattributes vendored
View File

@ -10052,6 +10052,8 @@ tests/test/opt/twpo5.pp svneol=native#text/plain
tests/test/opt/twpo6.pp svneol=native#text/plain
tests/test/opt/twpo7.pp svneol=native#text/plain
tests/test/opt/uwpo2.pp svneol=native#text/plain
tests/test/packages/bzip2/tbzip2streamtest.pp svneol=native#text/plain
tests/test/packages/bzip2/testbzip2.res -text
tests/test/packages/cocoaint/tobjc33.pp svneol=native#text/plain
tests/test/packages/cocoaint/tobjc33a.pp svneol=native#text/plain
tests/test/packages/cocoaint/tobjcnh1.pp svneol=native#text/plain

View File

@ -1,5 +1,5 @@
#
# Don't edit, this file is generated by FPCMake Version 2.0.0 [2012/04/11]
# Don't edit, this file is generated by FPCMake Version 2.0.0 [2012/04/21]
#
default: allexectests
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux
@ -1352,7 +1352,7 @@ ifndef LOG
export LOG:=$(TEST_OUTPUTDIR)/log
endif
TESTSUBDIRS=cg cg/variants cg/cdecl library opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem units/strutils units/matrix units/lineinfo
TESTPACKAGESUBDIRS=packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db packages/fcl-base packages/fcl-xml packages/cocoaint
TESTPACKAGESUBDIRS=packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db packages/fcl-base packages/fcl-xml packages/cocoaint packages/bzip2
ifdef QUICKTEST
export QUICKTEST
else

View File

@ -136,7 +136,7 @@ endif
# Subdirs available in the test subdir
TESTSUBDIRS=cg cg/variants cg/cdecl library opt units/system units/dos units/crt units/objects units/strings units/sysutils units/math units/sharemem units/strutils units/matrix units/lineinfo
TESTPACKAGESUBDIRS=packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db packages/fcl-base packages/fcl-xml packages/cocoaint
TESTPACKAGESUBDIRS=packages/win-base packages/webtbs packages/hash packages/fcl-registry packages/fcl-process packages/zlib packages/fcl-db packages/fcl-base packages/fcl-xml packages/cocoaint packages/bzip2
ifdef QUICKTEST
export QUICKTEST

View File

@ -0,0 +1,122 @@
program bunzip2test;
{
This file is part of the Free Pascal packages.
Copyright (c) 1999-2012 by the Free Pascal development team
Tests bzip2 decompression.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
{$mode objfpc}{$h+}
uses SysUtils, classes, bzip2stream, md5;
// Uses new bunzip2 code (using classes, not objects) to test decompression of a bzip2 compressed file.
{$R testbzip2.res} //contains readme.txt.bz2
//Change this whenever you change the test resource:
const ExpectedHash='4ab247ef61f1f9a6fec26493aab823cd';
function Decompress(SourceFile, TargetFile: string): boolean;
var
InFile:TFileStream;
Decompressed:TDecompressBzip2Stream;
OutFile:TFileStream;
Buffer: Pointer;
i: integer;
const buffersize=$2000;
begin
result:=false; //fail by default
InFile:=TFileStream.Create(SourceFile, fmOpenRead);
try
Decompressed:=TDecompressBzip2Stream.Create(InFile);
OutFile:=TFileStream.Create(TargetFile, fmCreate);
try
//We don't have seek on the TDecompressBzip2stream, so can't use
//CopyFrom...
//Decompressed.CopyFrom(InFile, InFile.Size);
GetMem(Buffer,BufferSize);
repeat
i:=Decompressed.Read(buffer^,BufferSize);
if i>0 then
OutFile.WriteBuffer(buffer^,i);
until i<BufferSize;
result:=true;
finally
Decompressed.Free;
OutFile.Free;
FreeMem(Buffer, BufferSize);
end;
finally
InFile.Free;
end;
end;
var
code: cardinal;
CompressedFile: string;
ExampleFileResourceStream: TResourceStream;
ExampleFileStream: TFileStream;
UncompressedFile: string;
UncompressedHash: string;
begin
code := 0;
UncompressedFile:=SysUtils.GetTempFileName(EmptyStr, 'UNC');
CompressedFile:=SysUtils.GetTempFileName(EmptyStr, 'BZ2');
// Set up test bz2 file
// create a resource stream which points to our resource
ExampleFileResourceStream := TResourceStream.Create(HInstance, 'ALL', 'RT_RCDATA');
try
ExampleFileStream := TFileStream.Create(CompressedFile, fmCreate);
try
ExampleFileStream.CopyFrom(ExampleFileResourceStream, ExampleFileResourceStream.Size);
finally
ExampleFileStream.Free;
end;
finally
ExampleFileResourceStream.Free;
end;
// Actual decompression
if decompress(CompressedFile, UncompressedFile) then
begin
// Now check if contents match.
UncompressedHash:=MD5Print(MD5File(UncompressedFile, MDDefBufSize));
if UncompressedHash=ExpectedHash then
begin
code:=0; //success
end
else
begin
writeln('MD5 hash comparison between original file and uncompressed file failed');
writeln('Got hash:'+UncompressedHash);
writeln('Expected:'+ExpectedHash);
code:=2;
end;
end
else
begin
writeln('bunzip2 decompression failure');
code:=1;
end;
try
if CompressedFile<>EmptyStr then DeleteFile(CompressedFile);
if UncompressedFile<>EmptyStr then DeleteFile(UncompressedFile);
finally
// Ignore errors; operating system should clean out temp files
end;
if code = 0 then
writeln('Basic bzip2 tests passed')
else
writeln('Basic bzip2 test failed: ', code);
Halt(code);
end.

Binary file not shown.