sl@0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32test.h>
|
sl@0
|
17 |
#include "TTYPES.H"
|
sl@0
|
18 |
|
sl@0
|
19 |
TestLine::TestLine(const TPoint& aStart,const TPoint& aFinish, CTTypes* aTest):
|
sl@0
|
20 |
iStart(aStart),
|
sl@0
|
21 |
iFinish(aFinish),
|
sl@0
|
22 |
iTest(aTest)
|
sl@0
|
23 |
{}
|
sl@0
|
24 |
|
sl@0
|
25 |
/**
|
sl@0
|
26 |
TestLine::Test
|
sl@0
|
27 |
|
sl@0
|
28 |
Method to test the functionality within the TLinearDDA class (Linear Digital Differential Analyser)
|
sl@0
|
29 |
Called from the TTypes test script
|
sl@0
|
30 |
*/
|
sl@0
|
31 |
void TestLine::Test()
|
sl@0
|
32 |
{
|
sl@0
|
33 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
34 |
TestSingleStep();
|
sl@0
|
35 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
36 |
TestSingleScanLine();
|
sl@0
|
37 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
38 |
TestNextStep();
|
sl@0
|
39 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
40 |
TestJumpToXCoord();
|
sl@0
|
41 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
42 |
TestJumpToYCoord();
|
sl@0
|
43 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
44 |
TestJumpToRect();
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
TestLine::TestSingleStep
|
sl@0
|
49 |
|
sl@0
|
50 |
Iterate through a line of pixels & confirm the final call to SingleStep rests on the last pixel
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
void TestLine::TestSingleStep()
|
sl@0
|
53 |
{
|
sl@0
|
54 |
TPoint point;
|
sl@0
|
55 |
while(!iLine.SingleStep(point))
|
sl@0
|
56 |
{
|
sl@0
|
57 |
iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
|
sl@0
|
58 |
iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
|
sl@0
|
59 |
}
|
sl@0
|
60 |
iTest->TEST(point==iFinish);
|
sl@0
|
61 |
}
|
sl@0
|
62 |
|
sl@0
|
63 |
/**
|
sl@0
|
64 |
TestLine::TestSingleScanLine
|
sl@0
|
65 |
|
sl@0
|
66 |
Iterate through each scaline & confirm successive scan lines are concatenated.
|
sl@0
|
67 |
Confirm the last scanline holds the endppoint that was specified during construction of TLinearDDA
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
void TestLine::TestSingleScanLine()
|
sl@0
|
70 |
{
|
sl@0
|
71 |
TPoint point1,point2;
|
sl@0
|
72 |
if(!iLine.SingleScanline(point1,point2))
|
sl@0
|
73 |
iTest->TEST(point1==iStart);
|
sl@0
|
74 |
TInt lastycoord=point1.iY;
|
sl@0
|
75 |
while(!iLine.SingleScanline(point1,point2))
|
sl@0
|
76 |
{
|
sl@0
|
77 |
iTest->TEST((point1.iX>=iStart.iX && point1.iX<=iFinish.iX) || (point1.iX<=iStart.iX && point1.iX>=iFinish.iX));
|
sl@0
|
78 |
iTest->TEST((point1.iY>=iStart.iY && point1.iY<=iFinish.iY) || (point1.iY<=iStart.iY && point1.iY>=iFinish.iY));
|
sl@0
|
79 |
iTest->TEST((point2.iX>=iStart.iX && point2.iX<=iFinish.iX) || (point2.iX<=iStart.iX && point2.iX>=iFinish.iX));
|
sl@0
|
80 |
iTest->TEST(point1.iY==point2.iY);
|
sl@0
|
81 |
iTest->TEST(Abs(point1.iY-lastycoord)==1);
|
sl@0
|
82 |
lastycoord=point1.iY;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
iTest->TEST(point2==iFinish);
|
sl@0
|
85 |
}
|
sl@0
|
86 |
|
sl@0
|
87 |
/**
|
sl@0
|
88 |
TestLine::TestNextStep
|
sl@0
|
89 |
|
sl@0
|
90 |
Iterate trhough a the start position of each scanline & confirm they are concatenated.
|
sl@0
|
91 |
Confirm the last scanline holds the endpoint specified during TLinearDDA construction (iFinish)
|
sl@0
|
92 |
*/
|
sl@0
|
93 |
void TestLine::TestNextStep()
|
sl@0
|
94 |
{
|
sl@0
|
95 |
TPoint point,oldpoint;
|
sl@0
|
96 |
iLine.NextStep(oldpoint);
|
sl@0
|
97 |
iTest->TEST(oldpoint==iStart);
|
sl@0
|
98 |
while(!iLine.NextStep(point))
|
sl@0
|
99 |
{
|
sl@0
|
100 |
iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
|
sl@0
|
101 |
iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
|
sl@0
|
102 |
iTest->TEST(Abs(point.iY-oldpoint.iY)==1);
|
sl@0
|
103 |
oldpoint=point;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
iTest->TEST(point==iFinish);
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
/**
|
sl@0
|
109 |
TestLine::TestJumpToRect
|
sl@0
|
110 |
|
sl@0
|
111 |
Test the JumpToRect functionality, confirming that the start of the clipping rectangle is correctly detected (note we iterate through SingleStep to find the position exactly)
|
sl@0
|
112 |
*/
|
sl@0
|
113 |
void TestLine::TestJumpToRect()
|
sl@0
|
114 |
{
|
sl@0
|
115 |
TPoint midpoint=iStart+iFinish;
|
sl@0
|
116 |
midpoint.iX>>=1;
|
sl@0
|
117 |
midpoint.iY>>=1;
|
sl@0
|
118 |
TSize rsize(Abs(iStart.iX-iFinish.iX),Abs(iStart.iY-iFinish.iY));
|
sl@0
|
119 |
TRect rect(TPoint(iFinish.iX-(rsize.iWidth>>1),iFinish.iY-(rsize.iHeight>>1)),rsize);
|
sl@0
|
120 |
TRect largerect(TPoint(iFinish.iX-(rsize.iWidth<<1),iFinish.iY-(rsize.iHeight<<1)),TSize(rsize.iWidth<<2,rsize.iHeight<<2));
|
sl@0
|
121 |
TRect offsetrect(rect);
|
sl@0
|
122 |
offsetrect.Move(iStart-iFinish);
|
sl@0
|
123 |
if(iFinish.iX>iStart.iX)
|
sl@0
|
124 |
offsetrect.Move(TPoint(-(rsize.iWidth>>2),0));
|
sl@0
|
125 |
else
|
sl@0
|
126 |
offsetrect.Move(TPoint(rsize.iWidth>>2,0));
|
sl@0
|
127 |
if(iFinish.iY>iStart.iY)
|
sl@0
|
128 |
offsetrect.Move(TPoint(0,(rsize.iHeight>>1)+4));
|
sl@0
|
129 |
else
|
sl@0
|
130 |
offsetrect.Move(TPoint(0,-(rsize.iHeight>>1)-4));
|
sl@0
|
131 |
TPoint intersect,point;
|
sl@0
|
132 |
TLinearDDA line;
|
sl@0
|
133 |
iLine.JumpToRect(rect);
|
sl@0
|
134 |
iLine.SingleStep(intersect);
|
sl@0
|
135 |
line.Construct(iStart,iFinish);
|
sl@0
|
136 |
while(!line.SingleStep(point))
|
sl@0
|
137 |
if(point==intersect)
|
sl@0
|
138 |
break;
|
sl@0
|
139 |
iTest->TEST(point==intersect);
|
sl@0
|
140 |
while(!iLine.SingleStep(intersect))
|
sl@0
|
141 |
{
|
sl@0
|
142 |
line.SingleStep(point);
|
sl@0
|
143 |
iTest->TEST(point==intersect);
|
sl@0
|
144 |
}
|
sl@0
|
145 |
line.SingleStep(point);
|
sl@0
|
146 |
iTest->TEST(point==intersect);
|
sl@0
|
147 |
iTest->TEST(intersect==iFinish);
|
sl@0
|
148 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
149 |
iLine.JumpToRect(largerect);
|
sl@0
|
150 |
iLine.SingleStep(point);
|
sl@0
|
151 |
iTest->TEST(Abs(point.iX-iStart.iX)<=1);
|
sl@0
|
152 |
iTest->TEST(Abs(point.iY-iStart.iY)<=1);
|
sl@0
|
153 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
154 |
iLine.JumpToRect(offsetrect);
|
sl@0
|
155 |
iLine.SingleStep(point);
|
sl@0
|
156 |
if(rsize.iWidth>rsize.iHeight)
|
sl@0
|
157 |
iTest->TEST(point==iStart);
|
sl@0
|
158 |
else
|
sl@0
|
159 |
iTest->TEST(Min(Abs(point.iY-offsetrect.iTl.iY),Abs(point.iY-offsetrect.iBr.iY))==1);
|
sl@0
|
160 |
}
|
sl@0
|
161 |
|
sl@0
|
162 |
/**
|
sl@0
|
163 |
TestLine::TestJumpToXCoord
|
sl@0
|
164 |
|
sl@0
|
165 |
Test the JumpToXCoord functionailty, confirming the positions by SingleStep calls
|
sl@0
|
166 |
*/
|
sl@0
|
167 |
void TestLine::TestJumpToXCoord()
|
sl@0
|
168 |
{
|
sl@0
|
169 |
TInt xc1=(iStart.iX+iFinish.iX)>>1;
|
sl@0
|
170 |
TInt xc2=iStart.iX;
|
sl@0
|
171 |
TInt xc3=iFinish.iX;
|
sl@0
|
172 |
TInt xc4=Min(iStart.iX,iFinish.iX)-Abs(xc1);
|
sl@0
|
173 |
TInt xc5=Max(iStart.iX,iFinish.iX)+Abs(xc1);
|
sl@0
|
174 |
TInt y=0;
|
sl@0
|
175 |
TPoint intersect,point;
|
sl@0
|
176 |
TLinearDDA line;
|
sl@0
|
177 |
iLine.JumpToXCoord(xc1,y);
|
sl@0
|
178 |
line.Construct(iStart,iFinish);
|
sl@0
|
179 |
while(!line.SingleStep(point))
|
sl@0
|
180 |
if(point.iX==xc1)
|
sl@0
|
181 |
break;
|
sl@0
|
182 |
iTest->TEST(y==point.iY);
|
sl@0
|
183 |
while(!iLine.SingleStep(point))
|
sl@0
|
184 |
{
|
sl@0
|
185 |
line.SingleStep(intersect);
|
sl@0
|
186 |
iTest->TEST(point.iX==intersect.iX);
|
sl@0
|
187 |
iTest->TEST(point.iY==intersect.iY);
|
sl@0
|
188 |
}
|
sl@0
|
189 |
TBool done=line.SingleStep(intersect);
|
sl@0
|
190 |
iTest->TEST(done);
|
sl@0
|
191 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
192 |
iLine.JumpToXCoord(xc2,y);
|
sl@0
|
193 |
iTest->TEST(y==iStart.iY);
|
sl@0
|
194 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
195 |
iLine.JumpToXCoord(xc3,y);
|
sl@0
|
196 |
iLine.SingleStep(point);
|
sl@0
|
197 |
iTest->TEST(point.iX==xc3);
|
sl@0
|
198 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
199 |
iLine.JumpToXCoord(xc4,y);
|
sl@0
|
200 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
201 |
iLine.JumpToXCoord(xc5,y);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
|
sl@0
|
204 |
/**
|
sl@0
|
205 |
TestLine::TestJumpToYCoord
|
sl@0
|
206 |
|
sl@0
|
207 |
Test the JumpToYCoord functionailty, confirming the positions by SingleStep calls
|
sl@0
|
208 |
*/
|
sl@0
|
209 |
void TestLine::TestJumpToYCoord()
|
sl@0
|
210 |
{
|
sl@0
|
211 |
TInt yc1=(iStart.iY+iFinish.iY)>>1;
|
sl@0
|
212 |
TInt yc2=iStart.iY;
|
sl@0
|
213 |
TInt yc3=iFinish.iY;
|
sl@0
|
214 |
TInt yc4=Min(iStart.iY,iFinish.iY)-Abs(yc1);
|
sl@0
|
215 |
TInt yc5=Max(iStart.iY,iFinish.iY)+Abs(yc1);
|
sl@0
|
216 |
TInt x=0;
|
sl@0
|
217 |
TPoint intersect,point;
|
sl@0
|
218 |
TLinearDDA line;
|
sl@0
|
219 |
iLine.JumpToYCoord(x,yc1);
|
sl@0
|
220 |
line.Construct(iStart,iFinish);
|
sl@0
|
221 |
while(!line.SingleStep(point))
|
sl@0
|
222 |
if(point.iY==yc1)
|
sl@0
|
223 |
break;
|
sl@0
|
224 |
iTest->TEST(TPoint(x,yc1)==point);
|
sl@0
|
225 |
while(!iLine.SingleStep(point))
|
sl@0
|
226 |
{
|
sl@0
|
227 |
line.SingleStep(intersect);
|
sl@0
|
228 |
iTest->TEST(point==intersect);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
TBool done=line.SingleStep(intersect);
|
sl@0
|
231 |
iTest->TEST(done);
|
sl@0
|
232 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
233 |
iLine.JumpToYCoord(x,yc2);
|
sl@0
|
234 |
iTest->TEST(x==iStart.iX);
|
sl@0
|
235 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
236 |
iLine.JumpToYCoord(x,yc3);
|
sl@0
|
237 |
iLine.SingleStep(point);
|
sl@0
|
238 |
iTest->TEST(point.iY==yc3);
|
sl@0
|
239 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
240 |
iLine.JumpToYCoord(x,yc4);
|
sl@0
|
241 |
iLine.Construct(iStart,iFinish);
|
sl@0
|
242 |
iLine.JumpToYCoord(x,yc5);
|
sl@0
|
243 |
}
|
sl@0
|
244 |
|