-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestcase1.pas
More file actions
179 lines (153 loc) · 4.1 KB
/
testcase1.pas
File metadata and controls
179 lines (153 loc) · 4.1 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
Unit TestCase1;
{$MODE objfpc}{$H+}
Interface
Uses
Classes, SysUtils, fpcunit, testutils, testregistry, ugraphics, Graphics, IntfGraphics;
Type
{ TTestCase1 }
TTestCase1 = Class(TTestCase)
private
Lena1, Lena2: TBitmap;
Lena1_intf, Lena2_intf: TLazIntfImage;
Procedure CheckLenaEqual;
protected
Procedure SetUp; override;
Procedure TearDown; override;
published
Procedure TearUpDown_Valid;
Procedure Rotate_90_Grad;
Procedure Rotate_Counter_90_Grad;
Procedure Rotate_90_for_and_back;
Procedure Rotate_90_for_and_back_2;
Procedure Rotate_90_for_and_back_3;
Procedure Rotate_180;
Procedure Rotate_180_2;
Procedure Rotate_180_3;
Procedure UpDown;
Procedure LeftRight;
Procedure Flip_Rotate;
End;
Implementation
Procedure TTestCase1.Rotate_90_Grad;
Begin
// Rotate 4 times -> get same as started with
RotateClockWise90Degrees(Lena1);
RotateClockWise90Degrees(Lena1);
RotateClockWise90Degrees(Lena1);
RotateClockWise90Degrees(Lena1);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_Counter_90_Grad;
Begin
// Rotate 4 times -> get same as started with
RotateCounterClockWise90Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena1);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_90_for_and_back;
Begin
// Rotate 90 is revertable by Rotate -90
RotateClockWise90Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena1);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_90_for_and_back_2;
Begin
// Rotate 270 is same as rotate -90
RotateClockWise90Degrees(Lena1);
RotateClockWise90Degrees(Lena1);
RotateClockWise90Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena2);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_90_for_and_back_3;
Begin
// Rotate 90 is same as rotate -270
RotateClockWise90Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena2);
RotateCounterClockWise90Degrees(Lena2);
RotateCounterClockWise90Degrees(Lena2);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_180;
Begin
Rotate180Degrees(Lena1);
Rotate180Degrees(Lena1);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_180_2;
Begin
Rotate180Degrees(Lena1);
RotateCounterClockWise90Degrees(Lena2);
RotateCounterClockWise90Degrees(Lena2);
CheckLenaEqual();
End;
Procedure TTestCase1.Rotate_180_3;
Begin
Rotate180Degrees(Lena1);
RotateClockWise90Degrees(Lena2);
RotateClockWise90Degrees(Lena2);
CheckLenaEqual();
End;
Procedure TTestCase1.UpDown;
Begin
UpSideDown(Lena1);
UpSideDown(Lena1);
CheckLenaEqual();
End;
Procedure TTestCase1.LeftRight;
Begin
LeftToRight(Lena1);
LeftToRight(Lena1);
CheckLenaEqual();
End;
Procedure TTestCase1.Flip_Rotate;
Begin
UpSideDown(Lena1);
LeftToRight(Lena1);
Rotate180Degrees(Lena2);
CheckLenaEqual();
End;
Procedure TTestCase1.CheckLenaEqual;
Var
i, j: Integer;
Begin
AssertEquals('Error, dimension [Width] wrong.', Lena1.Width, Lena2.Width);
AssertEquals('Error, dimension [Height] wrong.', Lena1.Height, Lena2.Height);
Lena1_intf := TLazIntfImage.Create(0, 0);
Lena1_intf.LoadFromBitmap(Lena1.Handle, Lena1.MaskHandle);
Lena2_intf := TLazIntfImage.Create(0, 0);
Lena2_intf.LoadFromBitmap(Lena2.Handle, Lena2.MaskHandle);
// Der Eigentliche Test Pixel für Pixel
For i := 0 To Lena1.Width - 1 Do
For j := 0 To Lena1.Height - 1 Do Begin
AssertTrue('Eror, pixel data invalid', FPColorToColor(Lena1_intf.Colors[i, j]) = FPColorToColor(Lena2_intf.Colors[i, j]))
End;
Lena1_intf.Free;
Lena2_intf.Free;
End;
Procedure TTestCase1.SetUp;
Begin
Lena1 := TBitmap.Create;
If Not FileExists('..' + PathDelim + 'Lena.bmp') Then Begin
AssertTrue('..' + PathDelim + 'Lena.bmp does not exist.', false);
End;
Lena1.LoadFromFile('..' + PathDelim + 'Lena.bmp');
lena2 := TBitmap.Create;
lena2.Assign(lena1);
End;
Procedure TTestCase1.TearDown;
Begin
Lena1.Free;
Lena2.Free;
End;
Procedure TTestCase1.TearUpDown_Valid;
Begin
// Nichts, testet nur ob Setup und Teardown alles richtig machen.
CheckLenaEqual();
End;
Initialization
RegisterTest(TTestCase1);
End.