sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include "TTYPES.H" sl@0: sl@0: TestLine::TestLine(const TPoint& aStart,const TPoint& aFinish, CTTypes* aTest): sl@0: iStart(aStart), sl@0: iFinish(aFinish), sl@0: iTest(aTest) sl@0: {} sl@0: sl@0: /** sl@0: TestLine::Test sl@0: sl@0: Method to test the functionality within the TLinearDDA class (Linear Digital Differential Analyser) sl@0: Called from the TTypes test script sl@0: */ sl@0: void TestLine::Test() sl@0: { sl@0: iLine.Construct(iStart,iFinish); sl@0: TestSingleStep(); sl@0: iLine.Construct(iStart,iFinish); sl@0: TestSingleScanLine(); sl@0: iLine.Construct(iStart,iFinish); sl@0: TestNextStep(); sl@0: iLine.Construct(iStart,iFinish); sl@0: TestJumpToXCoord(); sl@0: iLine.Construct(iStart,iFinish); sl@0: TestJumpToYCoord(); sl@0: iLine.Construct(iStart,iFinish); sl@0: TestJumpToRect(); sl@0: } sl@0: sl@0: /** sl@0: TestLine::TestSingleStep sl@0: sl@0: Iterate through a line of pixels & confirm the final call to SingleStep rests on the last pixel sl@0: */ sl@0: void TestLine::TestSingleStep() sl@0: { sl@0: TPoint point; sl@0: while(!iLine.SingleStep(point)) sl@0: { sl@0: iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX)); sl@0: iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY)); sl@0: } sl@0: iTest->TEST(point==iFinish); sl@0: } sl@0: sl@0: /** sl@0: TestLine::TestSingleScanLine sl@0: sl@0: Iterate through each scaline & confirm successive scan lines are concatenated. sl@0: Confirm the last scanline holds the endppoint that was specified during construction of TLinearDDA sl@0: */ sl@0: void TestLine::TestSingleScanLine() sl@0: { sl@0: TPoint point1,point2; sl@0: if(!iLine.SingleScanline(point1,point2)) sl@0: iTest->TEST(point1==iStart); sl@0: TInt lastycoord=point1.iY; sl@0: while(!iLine.SingleScanline(point1,point2)) sl@0: { sl@0: iTest->TEST((point1.iX>=iStart.iX && point1.iX<=iFinish.iX) || (point1.iX<=iStart.iX && point1.iX>=iFinish.iX)); sl@0: iTest->TEST((point1.iY>=iStart.iY && point1.iY<=iFinish.iY) || (point1.iY<=iStart.iY && point1.iY>=iFinish.iY)); sl@0: iTest->TEST((point2.iX>=iStart.iX && point2.iX<=iFinish.iX) || (point2.iX<=iStart.iX && point2.iX>=iFinish.iX)); sl@0: iTest->TEST(point1.iY==point2.iY); sl@0: iTest->TEST(Abs(point1.iY-lastycoord)==1); sl@0: lastycoord=point1.iY; sl@0: } sl@0: iTest->TEST(point2==iFinish); sl@0: } sl@0: sl@0: /** sl@0: TestLine::TestNextStep sl@0: sl@0: Iterate trhough a the start position of each scanline & confirm they are concatenated. sl@0: Confirm the last scanline holds the endpoint specified during TLinearDDA construction (iFinish) sl@0: */ sl@0: void TestLine::TestNextStep() sl@0: { sl@0: TPoint point,oldpoint; sl@0: iLine.NextStep(oldpoint); sl@0: iTest->TEST(oldpoint==iStart); sl@0: while(!iLine.NextStep(point)) sl@0: { sl@0: iTest->TEST((point.iX>=iStart.iX && point.iX<=iFinish.iX) || (point.iX<=iStart.iX && point.iX>=iFinish.iX)); sl@0: iTest->TEST((point.iY>=iStart.iY && point.iY<=iFinish.iY) || (point.iY<=iStart.iY && point.iY>=iFinish.iY)); sl@0: iTest->TEST(Abs(point.iY-oldpoint.iY)==1); sl@0: oldpoint=point; sl@0: } sl@0: iTest->TEST(point==iFinish); sl@0: } sl@0: sl@0: /** sl@0: TestLine::TestJumpToRect sl@0: sl@0: 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: */ sl@0: void TestLine::TestJumpToRect() sl@0: { sl@0: TPoint midpoint=iStart+iFinish; sl@0: midpoint.iX>>=1; sl@0: midpoint.iY>>=1; sl@0: TSize rsize(Abs(iStart.iX-iFinish.iX),Abs(iStart.iY-iFinish.iY)); sl@0: TRect rect(TPoint(iFinish.iX-(rsize.iWidth>>1),iFinish.iY-(rsize.iHeight>>1)),rsize); sl@0: TRect largerect(TPoint(iFinish.iX-(rsize.iWidth<<1),iFinish.iY-(rsize.iHeight<<1)),TSize(rsize.iWidth<<2,rsize.iHeight<<2)); sl@0: TRect offsetrect(rect); sl@0: offsetrect.Move(iStart-iFinish); sl@0: if(iFinish.iX>iStart.iX) sl@0: offsetrect.Move(TPoint(-(rsize.iWidth>>2),0)); sl@0: else sl@0: offsetrect.Move(TPoint(rsize.iWidth>>2,0)); sl@0: if(iFinish.iY>iStart.iY) sl@0: offsetrect.Move(TPoint(0,(rsize.iHeight>>1)+4)); sl@0: else sl@0: offsetrect.Move(TPoint(0,-(rsize.iHeight>>1)-4)); sl@0: TPoint intersect,point; sl@0: TLinearDDA line; sl@0: iLine.JumpToRect(rect); sl@0: iLine.SingleStep(intersect); sl@0: line.Construct(iStart,iFinish); sl@0: while(!line.SingleStep(point)) sl@0: if(point==intersect) sl@0: break; sl@0: iTest->TEST(point==intersect); sl@0: while(!iLine.SingleStep(intersect)) sl@0: { sl@0: line.SingleStep(point); sl@0: iTest->TEST(point==intersect); sl@0: } sl@0: line.SingleStep(point); sl@0: iTest->TEST(point==intersect); sl@0: iTest->TEST(intersect==iFinish); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToRect(largerect); sl@0: iLine.SingleStep(point); sl@0: iTest->TEST(Abs(point.iX-iStart.iX)<=1); sl@0: iTest->TEST(Abs(point.iY-iStart.iY)<=1); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToRect(offsetrect); sl@0: iLine.SingleStep(point); sl@0: if(rsize.iWidth>rsize.iHeight) sl@0: iTest->TEST(point==iStart); sl@0: else sl@0: iTest->TEST(Min(Abs(point.iY-offsetrect.iTl.iY),Abs(point.iY-offsetrect.iBr.iY))==1); sl@0: } sl@0: sl@0: /** sl@0: TestLine::TestJumpToXCoord sl@0: sl@0: Test the JumpToXCoord functionailty, confirming the positions by SingleStep calls sl@0: */ sl@0: void TestLine::TestJumpToXCoord() sl@0: { sl@0: TInt xc1=(iStart.iX+iFinish.iX)>>1; sl@0: TInt xc2=iStart.iX; sl@0: TInt xc3=iFinish.iX; sl@0: TInt xc4=Min(iStart.iX,iFinish.iX)-Abs(xc1); sl@0: TInt xc5=Max(iStart.iX,iFinish.iX)+Abs(xc1); sl@0: TInt y=0; sl@0: TPoint intersect,point; sl@0: TLinearDDA line; sl@0: iLine.JumpToXCoord(xc1,y); sl@0: line.Construct(iStart,iFinish); sl@0: while(!line.SingleStep(point)) sl@0: if(point.iX==xc1) sl@0: break; sl@0: iTest->TEST(y==point.iY); sl@0: while(!iLine.SingleStep(point)) sl@0: { sl@0: line.SingleStep(intersect); sl@0: iTest->TEST(point.iX==intersect.iX); sl@0: iTest->TEST(point.iY==intersect.iY); sl@0: } sl@0: TBool done=line.SingleStep(intersect); sl@0: iTest->TEST(done); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToXCoord(xc2,y); sl@0: iTest->TEST(y==iStart.iY); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToXCoord(xc3,y); sl@0: iLine.SingleStep(point); sl@0: iTest->TEST(point.iX==xc3); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToXCoord(xc4,y); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToXCoord(xc5,y); sl@0: } sl@0: sl@0: /** sl@0: TestLine::TestJumpToYCoord sl@0: sl@0: Test the JumpToYCoord functionailty, confirming the positions by SingleStep calls sl@0: */ sl@0: void TestLine::TestJumpToYCoord() sl@0: { sl@0: TInt yc1=(iStart.iY+iFinish.iY)>>1; sl@0: TInt yc2=iStart.iY; sl@0: TInt yc3=iFinish.iY; sl@0: TInt yc4=Min(iStart.iY,iFinish.iY)-Abs(yc1); sl@0: TInt yc5=Max(iStart.iY,iFinish.iY)+Abs(yc1); sl@0: TInt x=0; sl@0: TPoint intersect,point; sl@0: TLinearDDA line; sl@0: iLine.JumpToYCoord(x,yc1); sl@0: line.Construct(iStart,iFinish); sl@0: while(!line.SingleStep(point)) sl@0: if(point.iY==yc1) sl@0: break; sl@0: iTest->TEST(TPoint(x,yc1)==point); sl@0: while(!iLine.SingleStep(point)) sl@0: { sl@0: line.SingleStep(intersect); sl@0: iTest->TEST(point==intersect); sl@0: } sl@0: TBool done=line.SingleStep(intersect); sl@0: iTest->TEST(done); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToYCoord(x,yc2); sl@0: iTest->TEST(x==iStart.iX); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToYCoord(x,yc3); sl@0: iLine.SingleStep(point); sl@0: iTest->TEST(point.iY==yc3); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToYCoord(x,yc4); sl@0: iLine.Construct(iStart,iFinish); sl@0: iLine.JumpToYCoord(x,yc5); sl@0: } sl@0: