-
Notifications
You must be signed in to change notification settings - Fork 27
/
System.Zip.TestCase.pas
95 lines (75 loc) · 1.94 KB
/
System.Zip.TestCase.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
unit System.Zip.TestCase;
interface
uses TestFramework, System.Zip;
type
TTestCase_Zip = class(TTestCase)
protected
function GetCompression: TZipCompression; virtual; abstract;
published
procedure TestCase_Zip_File;
end;
TTestCase_Zip_zcStored = class(TTestCase_Zip)
protected
function GetCompression: TZipCompression; override;
end;
TTestCase_Zip_zcDeflate = class(TTestCase_Zip)
protected
function GetCompression: TZipCompression; override;
end;
TTestCase_Zip_zcLZMA = class(TTestCase_Zip)
protected
function GetCompression: TZipCompression; override;
end;
implementation
uses System.Classes, System.SysUtils, System.IOUtils, System.Zip.LZMA;
procedure TTestCase_Zip.TestCase_Zip_File;
var fZip, fData: string;
i: integer;
Z: TZipFile;
B, C: TBytes;
begin
fZip := TPath.ChangeExtension(TPath.GetTempFileName, '.zip');
fData := TPath.ChangeExtension(TPath.GetTempFileName, '.bin');
Randomize;
SetLength(B, 10 * 1024 * 1024);
for i := Low(B) to High(B) do
B[i] := Random(128);
TFile.WriteAllBytes(fData, B);
// Compress File
Z := TZipFile.Create;
Z.Open(fZip, zmWrite);
try
Z.Add(fData, '', GetCompression);
finally
Z.Close;
Z.Free;
TFile.Delete(fData);
end;
// Decompress File
TZipFile.ExtractZipFile(fZip, TPath.GetTempPath);
TFile.Delete(fZip);
CheckTrue(TFile.Exists(fData));
C := TFile.ReadAllBytes(fData);
CheckEquals(Length(B), Length(C));
CheckTrue(CompareMem(B, C, Length(B)));
TFile.Delete(fData);
end;
function TTestCase_Zip_zcStored.GetCompression: TZipCompression;
begin
Result := zcStored;
end;
function TTestCase_Zip_zcDeflate.GetCompression: TZipCompression;
begin
Result := zcDeflate;
end;
function TTestCase_Zip_zcLZMA.GetCompression: TZipCompression;
begin
Result := zcLZMA;
end;
initialization
RegisterTests([
TTestCase_Zip_zcStored.Suite
, TTestCase_Zip_zcDeflate.Suite
, TTestCase_Zip_zcLZMA.Suite
]);
end.