-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtstpifoperations.pas
53 lines (42 loc) · 1.35 KB
/
tstpifoperations.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
unit tstpifoperations;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, fpcunit, testutils, testregistry, portableimage;
const
TEST_IMAGE_FILE: string = '../data/Lenna_RGB888_rle.pif';
TEST_IMAGE_WIDTH: Integer = 512;
TEST_IMAGE_HEIGHT: Integer = 512;
type
TPIFTest= class(TTestCase)
published
procedure LoadImageFromFile;
procedure LoadImageFromBuffer;
end;
implementation
procedure TPIFTest.LoadImageFromFile;
var
pifObj: TPortableImageFile;
begin
pifObj := TPortableImageFile.Create(TEST_IMAGE_FILE);
CheckNotNull(pifObj.Image, 'Output image is not generated');
CheckEquals(pifObj.Width, TEST_IMAGE_WIDTH, 'Invalid image width');
CheckEquals(pifObj.Height, TEST_IMAGE_HEIGHT, 'Invalid image height');
FreeAndNil(pifObj);
end;
procedure TPIFTest.LoadImageFromBuffer;
var
memStream: TMemoryStream;
pifObj: TPortableImageFile;
begin
memStream := TMemoryStream.Create;
memStream.LoadFromFile(TEST_IMAGE_FILE);
pifObj := TPortableImageFile.Create(PByte(memStream.Memory)[0], memStream.Size);
CheckNotNull(pifObj.Image, 'Output image is not generated');
CheckEquals(pifObj.Width, TEST_IMAGE_WIDTH, 'Invalid image width');
CheckEquals(pifObj.Height, TEST_IMAGE_HEIGHT, 'Invalid image height');
FreeAndNil(pifObj);
end;
initialization
RegisterTest(TPIFTest);
end.