Kaynağa Gözat

--- Merging r20968 into '.':
U packages/bzip2/src/bzip2stream.pp
U packages/bzip2/src/bzip2.pas
U packages/bzip2/src/bzip2i386.inc
U packages/bzip2/src/bzip2si386.inc
--- Merging r20977 into '.':
A tests/test/packages/bzip2
A tests/test/packages/bzip2/tbzip2streamtest.pp
A tests/test/packages/bzip2/testbzip2.res
U tests/Makefile.fpc
C tests/Makefile
--- Merging r21263 into '.':
G packages/bzip2/src/bzip2stream.pp
--- Merging r21382 into '.':
G packages/bzip2/src/bzip2i386.inc
G packages/bzip2/src/bzip2si386.inc
--- Merging r21387 into '.':
A packages/bzip2/examples/pasbunzip2.pas
Summary of conflicts:
Text conflicts: 1

# revisions: 20968,20977,21263,21382,21387
r20968 | marco | 2012-04-21 23:32:27 +0200 (Sat, 21 Apr 2012) | 4 lines
Changed paths:
M /trunk/packages/bzip2/src/bzip2.pas
M /trunk/packages/bzip2/src/bzip2i386.inc
M /trunk/packages/bzip2/src/bzip2si386.inc
M /trunk/packages/bzip2/src/bzip2stream.pp

* assembler wouldn't include always anymore ->changed i386 to cpui386.
Changed assembler SELF reference from ESI to EAX. (probably now hidden param instead of fixed register ESI)
Alternative solution for Mantis #21242
r20977 | marco | 2012-04-22 12:12:45 +0200 (Sun, 22 Apr 2012) | 2 lines
Changed paths:
M /trunk/tests/Makefile
M /trunk/tests/Makefile.fpc
A /trunk/tests/test/packages/bzip2
A /trunk/tests/test/packages/bzip2/tbzip2streamtest.pp
A /trunk/tests/test/packages/bzip2/testbzip2.res

* test for bzip2 from Mantis #21261
r21263 | jonas | 2012-05-08 22:02:48 +0200 (Tue, 08 May 2012) | 1 line
Changed paths:
M /trunk/packages/bzip2/src/bzip2stream.pp

* fixed (harmless) range check errors
r21382 | jonas | 2012-05-24 17:34:33 +0200 (Thu, 24 May 2012) | 2 lines
Changed paths:
M /trunk/packages/bzip2/src/bzip2i386.inc
M /trunk/packages/bzip2/src/bzip2si386.inc

* fixed assembler code that was enabled in r20968 (push/pop changed ebx
and edi)
r21387 | marco | 2012-05-24 21:26:22 +0200 (Thu, 24 May 2012) | 2 lines
Changed paths:
A /trunk/packages/bzip2/examples/pasbunzip2.pas

* extraction example by Reinier Olislagers. Mantis #21304

git-svn-id: branches/fixes_2_6@21718 -

marco 13 yıl önce
ebeveyn
işleme
4e217d2cbe

+ 3 - 0
.gitattributes

@@ -953,6 +953,7 @@ packages/bfd/src/bfd.pas svneol=native#text/plain
 packages/bzip2/LICENSE svneol=native#text/plain
 packages/bzip2/Makefile svneol=native#text/plain
 packages/bzip2/Makefile.fpc svneol=native#text/plain
+packages/bzip2/examples/pasbunzip2.pas svneol=native#text/plain
 packages/bzip2/examples/pasbzip.pas svneol=native#text/plain
 packages/bzip2/fpmake.pp svneol=native#text/plain
 packages/bzip2/src/bzip2.pas svneol=native#text/plain
@@ -9821,6 +9822,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

+ 86 - 0
packages/bzip2/examples/pasbunzip2.pas

@@ -0,0 +1,86 @@
+program pasbunzip2;
+{
+    This file is part of the Free Pascal packages.
+    Copyright (c) 2012 Reinier Olislagers
+
+    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+}
+
+{ 
+Example .bz2 file extractor.
+Decompresses a .bz2 file into another file using the classes-based bzip2stream unit
+Usage: bunzip2 compressedfile.bz2
+}
+
+uses classes, bzip2stream;
+
+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
+    try
+      Decompressed:=TDecompressBzip2Stream.Create(InFile);
+    except      
+      // So[5mething went wrong, e.g. invalid format
+      // Now get out of function with result false
+      exit;
+    end;
+    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;
+    end;
+  finally
+    InFile.Free;
+  end;
+end;
+
+var
+  CompressedFile:string;
+  DecompressedFile:string;
+begin
+  CompressedFile:=ParamStr(1);
+  if CompressedFile='' then
+  begin
+    writeln('Usage: '+ParamStr(0)+' <file>');
+    halt(13); // show error in exit code
+  end;
+  DecompressedFile:=CompressedFile+'.out';
+  if Decompress(CompressedFile, DecompressedFile) then
+  begin
+    writeln('Decompressed '+CompressedFile+' to '+DecompressedFile);
+  end
+  else
+  begin  
+    writeln('An error occurred while decompressing '+CompressedFile);
+    halt(1); // show error in exit code
+  end;
+end.

+ 1 - 1
packages/bzip2/src/bzip2.pas

@@ -87,7 +87,7 @@ Type
 
 implementation
 
-{$ifdef i386}
+{$ifdef cpui386}
   {$i bzip2i386.inc}
 {$endif}
 

+ 8 - 4
packages/bzip2/src/bzip2i386.inc

@@ -32,12 +32,14 @@ procedure Tbzip2_decode_stream.detransform;assembler;
 asm
 {  mov edx,offset c
   call mcount}
+  push ebx
+  push edi
   xor edx,edx
-  lea ebx,[esi+Tbzip2_decode_stream.cftab]
-  mov ecx,[esi+Tbzip2_decode_stream.tt_count]
+  lea ebx,[eax+Tbzip2_decode_stream.cftab]
+  mov ecx,[eax+Tbzip2_decode_stream.tt_count]
   push esi
   push ebp
-  mov esi,[esi+Tbzip2_decode_stream.tt]
+  mov esi,[eax+Tbzip2_decode_stream.tt]
   mov edi,esi
   lea ebp,[4*ecx+esi]
   jmp @a2
@@ -53,4 +55,6 @@ asm
   jne @a1
   pop ebp
   pop esi
-end ['eax','ebx','ecx','edx','edi'];
+  pop edi
+  pop ebx
+end ['eax','ecx','edx'];

+ 8 - 4
packages/bzip2/src/bzip2si386.inc

@@ -7,12 +7,14 @@ procedure TDecompressBzip2Stream.detransform;assembler;
 asm
 {  mov edx,offset c
   call mcount}
+  push ebx
+  push edi
   xor edx,edx
-  lea ebx,[esi+TDecompressBzip2Stream.cftab]
-  mov ecx,[esi+TDecompressBzip2Stream.tt_count]
+  lea ebx,[eax+TDecompressBzip2Stream.cftab]
+  mov ecx,[eax+TDecompressBzip2Stream.tt_count]
   push esi
   push ebp
-  mov esi,[esi+TDecompressBzip2Stream.tt]
+  mov esi,[eax+TDecompressBzip2Stream.tt]
   mov edi,esi
   lea ebp,[4*ecx+esi]
   jmp @a2
@@ -28,4 +30,6 @@ asm
   jne @a1
   pop ebp
   pop esi
-end ['eax','ebx','ecx','edx','edi'];
+  pop edi
+  pop ebx
+end ['eax','ecx','edx'];

+ 3 - 3
packages/bzip2/src/bzip2stream.pp

@@ -96,7 +96,7 @@ Type
 
 implementation
 
-{$ifdef i386}
+{$ifdef cpui386}
   {$i bzip2si386.inc}
 {$endif}
 
@@ -147,13 +147,13 @@ begin
     begin
       Source.ReadBuffer(data,1);
       get_bits:=(read_data shr (8-n)) or data shr (8-(n-bits_available));
-      read_data:=data shl (n-bits_available);
+      read_data:=byte(data shl (n-bits_available));
       inc(bits_available,8);
     end
   else
     begin
       get_bits:=read_data shr (8-n);
-      read_data:=read_data shl n;
+      read_data:=byte(read_data shl n);
     end;
   dec(bits_available,n);
 end;

+ 3 - 3
tests/Makefile

@@ -1,8 +1,8 @@
 #
-# Don't edit, this file is generated by FPCMake Version 2.0.0 [2011/12/30]
+# Don't edit, this file is generated by FPCMake Version 2.0.0 [2012/06/26]
 #
 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 sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-solaris 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 avr-embedded armeb-linux armeb-embedded mipsel-linux
+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 sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd 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 avr-embedded armeb-linux armeb-embedded mipsel-linux
 BSDs = freebsd netbsd openbsd darwin
 UNIXs = linux $(BSDs) solaris qnx haiku
 LIMIT83fs = go32v2 os2 emx watcom
@@ -1337,7 +1337,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
-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

+ 1 - 1
tests/Makefile.fpc

@@ -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
-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

+ 122 - 0
tests/test/packages/bzip2/tbzip2streamtest.pp

@@ -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.

BIN
tests/test/packages/bzip2/testbzip2.res