First public contribution.
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 TestLine::TestLine(const TPoint& aStart,const TPoint& aFinish, CTTypes* aTest):
28 Method to test the functionality within the TLinearDDA class (Linear Digital Differential Analyser)
29 Called from the TTypes test script
33 iLine.Construct(iStart,iFinish);
35 iLine.Construct(iStart,iFinish);
37 iLine.Construct(iStart,iFinish);
39 iLine.Construct(iStart,iFinish);
41 iLine.Construct(iStart,iFinish);
43 iLine.Construct(iStart,iFinish);
48 TestLine::TestSingleStep
50 Iterate through a line of pixels & confirm the final call to SingleStep rests on the last pixel
52 void TestLine::TestSingleStep()
55 while(!iLine.SingleStep(point))
57 iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
58 iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
60 iTest->TEST(point==iFinish);
64 TestLine::TestSingleScanLine
66 Iterate through each scaline & confirm successive scan lines are concatenated.
67 Confirm the last scanline holds the endppoint that was specified during construction of TLinearDDA
69 void TestLine::TestSingleScanLine()
72 if(!iLine.SingleScanline(point1,point2))
73 iTest->TEST(point1==iStart);
74 TInt lastycoord=point1.iY;
75 while(!iLine.SingleScanline(point1,point2))
77 iTest->TEST((point1.iX>=iStart.iX && point1.iX<=iFinish.iX) || (point1.iX<=iStart.iX && point1.iX>=iFinish.iX));
78 iTest->TEST((point1.iY>=iStart.iY && point1.iY<=iFinish.iY) || (point1.iY<=iStart.iY && point1.iY>=iFinish.iY));
79 iTest->TEST((point2.iX>=iStart.iX && point2.iX<=iFinish.iX) || (point2.iX<=iStart.iX && point2.iX>=iFinish.iX));
80 iTest->TEST(point1.iY==point2.iY);
81 iTest->TEST(Abs(point1.iY-lastycoord)==1);
84 iTest->TEST(point2==iFinish);
88 TestLine::TestNextStep
90 Iterate trhough a the start position of each scanline & confirm they are concatenated.
91 Confirm the last scanline holds the endpoint specified during TLinearDDA construction (iFinish)
93 void TestLine::TestNextStep()
95 TPoint point,oldpoint;
96 iLine.NextStep(oldpoint);
97 iTest->TEST(oldpoint==iStart);
98 while(!iLine.NextStep(point))
100 iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX));
101 iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY));
102 iTest->TEST(Abs(point.iY-oldpoint.iY)==1);
105 iTest->TEST(point==iFinish);
109 TestLine::TestJumpToRect
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)
113 void TestLine::TestJumpToRect()
115 TPoint midpoint=iStart+iFinish;
118 TSize rsize(Abs(iStart.iX-iFinish.iX),Abs(iStart.iY-iFinish.iY));
119 TRect rect(TPoint(iFinish.iX-(rsize.iWidth>>1),iFinish.iY-(rsize.iHeight>>1)),rsize);
120 TRect largerect(TPoint(iFinish.iX-(rsize.iWidth<<1),iFinish.iY-(rsize.iHeight<<1)),TSize(rsize.iWidth<<2,rsize.iHeight<<2));
121 TRect offsetrect(rect);
122 offsetrect.Move(iStart-iFinish);
123 if(iFinish.iX>iStart.iX)
124 offsetrect.Move(TPoint(-(rsize.iWidth>>2),0));
126 offsetrect.Move(TPoint(rsize.iWidth>>2,0));
127 if(iFinish.iY>iStart.iY)
128 offsetrect.Move(TPoint(0,(rsize.iHeight>>1)+4));
130 offsetrect.Move(TPoint(0,-(rsize.iHeight>>1)-4));
131 TPoint intersect,point;
133 iLine.JumpToRect(rect);
134 iLine.SingleStep(intersect);
135 line.Construct(iStart,iFinish);
136 while(!line.SingleStep(point))
139 iTest->TEST(point==intersect);
140 while(!iLine.SingleStep(intersect))
142 line.SingleStep(point);
143 iTest->TEST(point==intersect);
145 line.SingleStep(point);
146 iTest->TEST(point==intersect);
147 iTest->TEST(intersect==iFinish);
148 iLine.Construct(iStart,iFinish);
149 iLine.JumpToRect(largerect);
150 iLine.SingleStep(point);
151 iTest->TEST(Abs(point.iX-iStart.iX)<=1);
152 iTest->TEST(Abs(point.iY-iStart.iY)<=1);
153 iLine.Construct(iStart,iFinish);
154 iLine.JumpToRect(offsetrect);
155 iLine.SingleStep(point);
156 if(rsize.iWidth>rsize.iHeight)
157 iTest->TEST(point==iStart);
159 iTest->TEST(Min(Abs(point.iY-offsetrect.iTl.iY),Abs(point.iY-offsetrect.iBr.iY))==1);
163 TestLine::TestJumpToXCoord
165 Test the JumpToXCoord functionailty, confirming the positions by SingleStep calls
167 void TestLine::TestJumpToXCoord()
169 TInt xc1=(iStart.iX+iFinish.iX)>>1;
172 TInt xc4=Min(iStart.iX,iFinish.iX)-Abs(xc1);
173 TInt xc5=Max(iStart.iX,iFinish.iX)+Abs(xc1);
175 TPoint intersect,point;
177 iLine.JumpToXCoord(xc1,y);
178 line.Construct(iStart,iFinish);
179 while(!line.SingleStep(point))
182 iTest->TEST(y==point.iY);
183 while(!iLine.SingleStep(point))
185 line.SingleStep(intersect);
186 iTest->TEST(point.iX==intersect.iX);
187 iTest->TEST(point.iY==intersect.iY);
189 TBool done=line.SingleStep(intersect);
191 iLine.Construct(iStart,iFinish);
192 iLine.JumpToXCoord(xc2,y);
193 iTest->TEST(y==iStart.iY);
194 iLine.Construct(iStart,iFinish);
195 iLine.JumpToXCoord(xc3,y);
196 iLine.SingleStep(point);
197 iTest->TEST(point.iX==xc3);
198 iLine.Construct(iStart,iFinish);
199 iLine.JumpToXCoord(xc4,y);
200 iLine.Construct(iStart,iFinish);
201 iLine.JumpToXCoord(xc5,y);
205 TestLine::TestJumpToYCoord
207 Test the JumpToYCoord functionailty, confirming the positions by SingleStep calls
209 void TestLine::TestJumpToYCoord()
211 TInt yc1=(iStart.iY+iFinish.iY)>>1;
214 TInt yc4=Min(iStart.iY,iFinish.iY)-Abs(yc1);
215 TInt yc5=Max(iStart.iY,iFinish.iY)+Abs(yc1);
217 TPoint intersect,point;
219 iLine.JumpToYCoord(x,yc1);
220 line.Construct(iStart,iFinish);
221 while(!line.SingleStep(point))
224 iTest->TEST(TPoint(x,yc1)==point);
225 while(!iLine.SingleStep(point))
227 line.SingleStep(intersect);
228 iTest->TEST(point==intersect);
230 TBool done=line.SingleStep(intersect);
232 iLine.Construct(iStart,iFinish);
233 iLine.JumpToYCoord(x,yc2);
234 iTest->TEST(x==iStart.iX);
235 iLine.Construct(iStart,iFinish);
236 iLine.JumpToYCoord(x,yc3);
237 iLine.SingleStep(point);
238 iTest->TEST(point.iY==yc3);
239 iLine.Construct(iStart,iFinish);
240 iLine.JumpToYCoord(x,yc4);
241 iLine.Construct(iStart,iFinish);
242 iLine.JumpToYCoord(x,yc5);