First public contribution.
1 // Copyright (c) 1996-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.
22 @internalComponent - Internal Symbian test code
27 #define TAUTO_BITMAP_NAME _L("Z:\\WSTEST\\TAUTO.MBM")
29 //#define LOGGING on //Uncomment this line to get extra test logging - useful if debugging a failure of one of the tests
31 typedef CGdiTestLowLevel *(*GdiTestFunc)();
33 _LIT(KMonospaceTestFontTypefaceName,"Arial");
34 const TInt KMaxFontSize = 200;
36 static inline TBool IsLengthEqual(TInt aLLen, TInt aRLen, TInt aBbLen)
38 // The bounding box of a 'w' is one pixel wider than it should be. W overlaps in to the bounding box of 'x' as the two
39 // are stuck together. So add a tolerance of -1.
40 return (((aLLen+aRLen)==aBbLen) || ((aLLen+aRLen-1)==aBbLen));
49 GdiTest GdiTestFuncs[]={
50 {BoxTextTest,_S("BoxText")},
51 {VertTextTest,_S("VertText")},
52 /*{JustifiedTextTest,_S("JustifiedText")},*/ // DEF107985 The test for JustifiedText has been removed as it was a bad/useless test
53 {VertBoxTextTest,_S("VertBoxText")},
54 {SetOriginTest,_S("SetOrigin")},
55 {PolyLineTest,_S("PolyLine")},
56 {PolygonTest,_S("Polygon")},
57 {DrawArcTest,_S("DrawArc")},
58 {DrawPieTest,_S("DrawPie")},
59 {DrawRoundRectTest,_S("DrawRoundRect")},
60 {WideLineTest,_S("WideLine")},
61 {DrawTextTest,_S("DrawText")},
62 {DrawRectTest,_S("DrawRect")},
65 CTestWindow::CTestWindow(TRgb aCol) : CBlankWindow(aCol)
69 CTestWindow::~CTestWindow()
73 void CTestWindow::ConstructL(TPoint aPos,TSize aSize,CTWinBase* aParent, CWindowGc& aGc)
75 iWin=RWindow(TheClient->iWs);
76 User::LeaveIfError(iWin.Construct(*(aParent->WinTreeNode()),ENullWsHandle));
82 void CGdiTestLowLevel::SetGdiTest(CTGdi *aGdiTest)
87 void CGdiTestLowLevel::AssignGdi(CWindowGc *aGc)
92 void CGdiTestLowLevel::ConstructL(TInt)
96 void CGdiTestLowLevel::PreTestSetupL(const TRect &,TInt)
100 //=======================================//
101 // Individual GDI low level test classes //
102 //=======================================//
105 void CGdiRect::ConstructL(TInt)
109 void CGdiRect::PreTestSetupL(const TRect &, TInt aCount)
111 iBrushCol=TRgb::Gray256(aCount&0x1 ? 0xFF : 0x60);
112 iPenCol=TRgb::Gray256(aCount&0x1 ? 0xA0 : 0x0);
115 TInt CGdiRect::Count(TBool )
120 void CGdiDrawRect::BaseTest(const TRect &aRect, TInt aCount)
122 TheTest(aRect,aCount);
125 void CGdiDrawRect::TheTest(const TRect &aRect, TInt)
127 iGdi->SetBrushColor(iBrushCol);
128 iGdi->SetPenColor(iPenCol);
129 iGdi->DrawRect(aRect);
132 TInt CGdiDrawRect::Count(TBool aMode)
137 TInt CGdiDrawRoundRect::Count(TBool aMode)
142 void CGdiDrawRoundRect::BaseTest(const TRect &aRect, TInt aCount)
144 TheTest(aRect,aCount);
147 void CGdiDrawRoundRect::TheTest(const TRect &aRect, TInt aCount)
149 iGdi->SetBrushColor(iBrushCol);
150 iGdi->SetPenColor(iPenCol);
151 TSize size((aRect.iBr.iX-aRect.iTl.iX)/4,(aRect.iBr.iY-aRect.iTl.iY)/4);
155 size.SetSize((aRect.iBr.iX-aRect.iTl.iX)/4,(aRect.iBr.iY-aRect.iTl.iY)/4);
161 size.SetSize((aRect.iBr.iX-aRect.iTl.iX)/2,(aRect.iBr.iY-aRect.iTl.iY)/2);
164 size.SetSize((aRect.iBr.iX-aRect.iTl.iX),(aRect.iBr.iY-aRect.iTl.iY));
167 iGdi->DrawRoundRect(aRect,size);
170 TInt CGdiDrawACP::Count(TBool )
175 void CGdiDrawACP::ConstructL(TInt)
179 void CGdiDrawACP::PreTestSetupL(const TRect &, TInt )
181 iBrushCol=TRgb::Gray256(0xff);
185 void CGdiDrawArc::BaseTest(const TRect &aRect, TInt aCount)
187 TheTest(aRect,aCount);
190 void CGdiDrawArc::TheTest(const TRect &aRect, TInt)
192 iGdi->SetBrushColor(iBrushCol);
193 iGdi->SetPenColor(iPenCol);
194 TPoint start(aRect.iTl.iX/2+aRect.iBr.iX,aRect.iTl.iY/2+aRect.iBr.iY);
195 iGdi->DrawArc(aRect,start,TPoint(0,0));
198 void CGdiDrawPie::BaseTest(const TRect &aRect, TInt aCount)
200 TheTest(aRect,aCount);
203 void CGdiDrawPie::TheTest(const TRect &aRect, TInt)
205 iGdi->SetBrushColor(iBrushCol);
206 iGdi->SetPenColor(iPenCol);
207 TPoint start(aRect.iTl.iX/2+aRect.iBr.iX,aRect.iTl.iY/2+aRect.iBr.iY);
208 iGdi->DrawPie(aRect,start,TPoint(0,0));
215 CGdiPolyLine::CGdiPolyLine() : iPnts(5)
218 void CGdiPolyLine::PreTestSetupL(const TRect &aRect, TInt aCount)
221 TInt wid=aRect.Width();
222 TInt hgt=aRect.Height();
226 for(pos=0;pos<wid;pos+=10)
228 iPnts.AppendL(TPoint(aRect.iTl.iX+pos,aRect.iTl.iY));
229 iPnts.AppendL(TPoint(aRect.iTl.iX+pos+5,aRect.iBr.iY));
231 for(pos=0;pos<hgt;pos+=10)
233 iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY+pos));
234 iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY+pos+5));
239 TInt hgt=aRect.Height();
240 iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY));
241 iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY+hgt/2));
242 iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iBr.iY));
243 iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iBr.iY));
244 iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY+hgt/2));
245 iPnts.AppendL(TPoint(aRect.iBr.iX,aRect.iTl.iY));
246 iPnts.AppendL(TPoint(aRect.iTl.iX,aRect.iTl.iY));
250 void CGdiPolyLine::ConstructL(TInt )
254 TInt CGdiPolyLine::Count(TBool aMainTests)
256 return(aMainTests ? 2 : 1);
259 void CGdiPolyLine::BaseTest(const TRect &, TInt )
263 for(index=0;index<iPnts.Count();index++)
266 iGdi->DrawLine(prev,iPnts[index]);
270 iGdi->Plot(iPnts[index-1]);
273 void CGdiPolyLine::TheTest(const TRect &, TInt )
275 iGdi->DrawPolyLine(&iPnts);
282 CGdiPolygon::CGdiPolygon() : iPnts(5)
285 void CGdiPolygon::PreTestSetupL(const TRect &aRect, TInt )
289 TInt maxPoints=Min((TInt)KMaxPolygonPoints,Min(aRect.Width(),aRect.Height())/KPolygonStep);
293 iPnts.AppendL(aRect.iTl);
294 while(numPoints<maxPoints)
297 pnt.SetXY(aRect.iTl.iX+(numPoints+1)*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
299 pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+(numPoints+1)*KPolygonStep);
303 pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
309 pnt.SetXY(aRect.iTl.iX+numPoints*KPolygonStep,aRect.iTl.iY+(numPoints+1)*KPolygonStep);
311 pnt.SetXY(aRect.iTl.iX+(numPoints+1)*KPolygonStep,aRect.iTl.iY+numPoints*KPolygonStep);
317 void CGdiPolygon::ConstructL(TInt )
321 TInt CGdiPolygon::Count(TBool aMainTests)
323 return(aMainTests ? 2 : 1);
326 void CGdiPolygon::BaseTest(const TRect &aRect, TInt )
328 iGdi->SetPenColor(TRgb::Gray4(2));
329 iGdi->SetBrushColor(TRgb::Gray4(1));
330 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
331 TInt maxPoints=Min((TInt)KMaxPolygonPoints,Min(aRect.Width(),aRect.Height())/KPolygonStep);
332 for(TInt numPoints=0;numPoints<maxPoints;numPoints++)
333 iGdi->DrawRect(TRect(aRect.iTl.iX+numPoints*KPolygonStep + 1,aRect.iTl.iY+numPoints*KPolygonStep + 1,
334 aRect.iTl.iX+(numPoints+1)*KPolygonStep ,aRect.iTl.iY+(numPoints+1)*KPolygonStep));
337 void CGdiPolygon::TheTest(const TRect &, TInt )
338 //This is the only one that can leave so it's not worth adding an 'L'
340 iGdi->SetPenColor(TRgb::Gray4(2));
341 iGdi->SetBrushColor(TRgb::Gray4(1));
342 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
343 User::LeaveIfError(iGdi->DrawPolygon(&iPnts,CGraphicsContext::EAlternate));
348 TInt CGdiWideLine::Count(TBool aMainTests)
350 return(aMainTests ? EMainNumWidths : EMinorNumWidths);
353 void CGdiWideLine::ConstructL(TInt)
357 void CGdiWideLine::PreTestSetupL(const TRect &, TInt aCount)
359 TInt widths[]={1,4,50,-2,
364 iWidth=widths[aCount];
367 void CGdiWideLine::BaseTest(const TRect &aRect, TInt)
369 iGdi->SetPenSize(TSize(iWidth,iWidth));
370 iGdi->DrawLine(aRect.iTl,aRect.iBr);
371 iGdi->MoveTo(aRect.iTl+TPoint(0,10));
372 iGdi->DrawLineBy(aRect.iBr-aRect.iTl);
373 iGdi->MoveBy(aRect.iTl-aRect.iBr+TPoint(0,10));
374 iGdi->DrawLineTo(aRect.iBr+TPoint(0,20));
377 void CGdiWideLine::TheTest(const TRect &aRect, TInt)
379 iGdi->SetPenSize(TSize(iWidth,iWidth));
380 iGdi->MoveTo(aRect.iTl);
381 iGdi->DrawLineBy(aRect.iBr-aRect.iTl);
382 iGdi->MoveBy(aRect.iTl-aRect.iBr+TPoint(0,10));
383 iGdi->DrawLineTo(aRect.iBr+TPoint(0,10));
384 iGdi->DrawLine(aRect.iTl+TPoint(0,20),aRect.iBr+TPoint(0,20));
391 CGdiSetOrigin::~CGdiSetOrigin()
393 delete iPolylineArray;
394 delete iPolygonArray;
395 TheClient->iScreen->ReleaseFont(iFont);
398 TInt CGdiSetOrigin::Count(TBool )
403 void CGdiSetOrigin::ConstructL(TInt)
405 iPolylineArray=new(ELeave) CArrayFixFlat<TPoint>(3);
406 iPolylineArray->AppendL(TPoint(40,1));
407 iPolylineArray->AppendL(TPoint(50,11));
408 iPolylineArray->AppendL(TPoint(40,21));
409 iPolygonArray=new(ELeave) CArrayFixFlat<TPoint>(3);
410 iPolygonArray->AppendL(TPoint(40,30));
411 iPolygonArray->AppendL(TPoint(50,40));
412 iPolygonArray->AppendL(TPoint(40,45));
413 TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
414 User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
417 void CGdiSetOrigin::PreTestSetupL(const TRect &, TInt )
421 void CGdiSetOrigin::DrawIt(const TPoint &aOffset)
423 iGdi->DrawLine(TPoint(10,10)+aOffset,TPoint(20,30)+aOffset);
424 iGdi->DrawLineBy(TPoint(-10,5));
425 iGdi->DrawLineTo(TPoint(20,5)+aOffset);
426 iGdi->MoveTo(TPoint(20,10)+aOffset);
427 iGdi->DrawLineTo(TPoint(30,15)+aOffset);
428 iGdi->MoveBy(TPoint(-10,2));
429 iGdi->DrawLineBy(TPoint(10,0));
430 iGdi->UseFont(iFont);
431 iGdi->DrawText(_L("Set Origin Test"),TPoint(40,20)+aOffset);
433 iGdi->DrawRect(TRect(TPoint(10,45)+aOffset,TPoint(20,55)+aOffset));
434 iGdi->DrawRoundRect(TRect(TPoint(21,45)+aOffset,TPoint(30,55)+aOffset),TSize(3,2));
435 iGdi->DrawEllipse(TRect(TPoint(31,45)+aOffset,TPoint(40,55)+aOffset));
437 for(index=0;index<iPolylineArray->Count();index++)
438 (*iPolylineArray)[index]+=aOffset;
439 iGdi->DrawPolyLine(iPolylineArray);
440 for(index=0;index<iPolylineArray->Count();index++)
441 (*iPolylineArray)[index]-=aOffset;
442 for(index=0;index<iPolygonArray->Count();index++)
443 (*iPolygonArray)[index]+=aOffset;
444 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
445 User::LeaveIfError(iGdi->DrawPolygon(iPolygonArray,CGraphicsContext::EAlternate)); //Doesn't cause any harm if it leaves
446 for(index=0;index<iPolygonArray->Count();index++)
447 (*iPolygonArray)[index]-=aOffset;
450 void CGdiSetOrigin::BaseTest(const TRect &aRect, TInt)
455 void CGdiSetOrigin::TheTest(const TRect &aRect, TInt)
457 iGdi->SetOrigin(aRect.iTl);
465 CGdiDrawText::~CGdiDrawText()
467 TheClient->iScreen->ReleaseFont(iFont);
470 TInt CGdiDrawText::Count(TBool )
475 void CGdiDrawText::ConstructL(TInt)
477 TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
478 User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
480 for(index=0;index<iBigBuffer.MaxLength();index++)
481 iBigBuffer.Append(TChar((index%26)+'a'));
482 const TInt characters=iBigBuffer.Length();
483 TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
484 for(index=0;index<iBigBuffer.MaxLength();index+=33)
486 TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(index));
487 TInt rLen=iFont->TextWidthInPixels(iBigBuffer.Right(characters-index));
488 TBool result = IsLengthEqual(lLen,rLen,bbLen);
489 iGdiTest->TEST(result);
492 _LIT(KLog,"Font width metrics error, Width(%dchars)=%d, Width(%dchars)=%d, Width(%dchars)=%d");
493 iGdiTest->LOG_MESSAGE7(KLog,index,lLen,characters-index,rLen,characters,bbLen);
498 void CGdiDrawText::PreTestSetupL(const TRect&,TInt)
501 void CGdiDrawText::BaseTest(const TRect& aRect,TInt)
503 TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
504 TInt fAscent=iFont->AscentInPixels();
505 TInt fHeight=iFont->HeightInPixels();
506 iGdi->UseFont(iFont);
508 iGdi->DrawText(_L("Hello"), TPoint(aRect.iTl.iX, aRect.iTl.iY+fAscent));
509 TInt missingChars=iFont->TextCount(iBigBuffer,bbLen-aRect.iBr.iX)-1; // -1 so one off screen char is drawn to handle overhang
512 TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
513 TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
514 TInt rLen=iFont->TextWidthInPixels(bbb);
515 TBool result = IsLengthEqual(lLen,rLen,bbLen);
516 iGdiTest->TEST(result);
519 _LIT(KLog,"Font width metrics error, missingChars=%d %d+%d=%d");
520 iGdiTest->LOG_MESSAGE5(KLog,missingChars,lLen,rLen,bbLen);
522 iGdi->DrawText(bbb,TPoint(aRect.iBr.iX-rLen,aRect.iTl.iY+fAscent+fHeight));
527 void CGdiDrawText::TheTest(const TRect& aRect,TInt)
529 TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
530 TInt fAscent=iFont->AscentInPixels();
531 TInt fHeight=iFont->HeightInPixels();
532 iGdi->UseFont(iFont);
534 iGdi->DrawText(_L("Hello"), TPoint(aRect.iTl.iX, aRect.iTl.iY+fAscent));
535 iGdi->DrawText(iBigBuffer,TPoint(aRect.iBr.iX-bbLen,aRect.iTl.iY+fAscent+fHeight));
540 // Draw vertical text //
543 CGdiDrawVertText::~CGdiDrawVertText()
545 TheClient->iScreen->ReleaseFont(iFont);
548 TInt CGdiDrawVertText::Count(TBool )
553 void CGdiDrawVertText::ConstructL(TInt)
555 TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
556 User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
558 for(index=0;index<iBigBuffer.MaxLength();index++)
559 iBigBuffer.Append(TChar((index%26)+'a'));
561 TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
562 for(index=0;index<iBigBuffer.MaxLength();index+=33)
564 TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(index));
565 TInt rLen=iFont->TextWidthInPixels(iBigBuffer.Right(iBigBuffer.Length()-index));
566 TBool result = IsLengthEqual(lLen,rLen,bbLen);
567 iGdiTest->TEST(result);
569 iGdiTest->INFO_PRINTF3(_L("iFont->TextWidthInPixels(iBigBuffer) return value - Expected: %d, Actual: %d"), lLen+rLen, bbLen);
573 void CGdiDrawVertText::PreTestSetupL(const TRect &, TInt )
577 void CGdiDrawVertText::BaseTest(const TRect &aRect, TInt)
579 TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
580 TInt fAscent=iFont->AscentInPixels();
581 TInt fHeight=iFont->HeightInPixels();
582 iGdi->UseFont(iFont);
584 TInt tlen=iFont->TextWidthInPixels(_L("Hello"));
585 iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iTl.iX+fAscent, aRect.iTl.iY+tlen), ETrue);
586 iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iBr.iX-fAscent, aRect.iTl.iY), EFalse);
587 TInt missingChars=iFont->TextCount(iBigBuffer,bbLen-aRect.iBr.iY)-1; // -1 so one off screen char is drawn to handle overhang
590 TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
591 TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
592 TInt rLen=iFont->TextWidthInPixels(bbb);
593 TBool result = IsLengthEqual(lLen,rLen,bbLen);
594 iGdiTest->TEST(result);
596 iGdiTest->INFO_PRINTF3(_L("iFont->TextWidthInPixels(iBigBuffer) return value - Expected: %d, Actual: %d"), lLen+rLen, bbLen);
598 iGdi->DrawTextVertical(bbb,TPoint(aRect.iTl.iX+fHeight-fAscent+fHeight,aRect.iBr.iY-rLen),EFalse);
603 void CGdiDrawVertText::TheTest(const TRect &aRect, TInt)
605 TInt bbLen=iFont->TextWidthInPixels(iBigBuffer);
606 TInt fAscent=iFont->AscentInPixels();
607 TInt fHeight=iFont->HeightInPixels();
608 iGdi->UseFont(iFont);
610 TInt tlen=iFont->TextWidthInPixels(_L("Hello"));
611 iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iTl.iX+fAscent, aRect.iTl.iY+tlen), ETrue);
612 iGdi->DrawTextVertical(_L("Hello"), TPoint(aRect.iBr.iX-fAscent, aRect.iTl.iY), EFalse);
613 iGdi->DrawTextVertical(iBigBuffer,TPoint(aRect.iTl.iX+fHeight-fAscent+fHeight,aRect.iBr.iY-bbLen),EFalse);
618 // Draw Justified text //
621 // DEF107985 The test for JustifiedText has been removed as it was a bad/useless test. The original test was
622 // broken after it was migrated to TEF TGdi test. It was not worth fixing as the purpose of test was not clear,
623 // and fixing it basically required rewriting the whole test.
631 CGdiBoxText::~CGdiBoxText()
633 TheClient->iScreen->ReleaseFont(iFont);
636 TInt CGdiBoxText::Count(TBool )
641 void CGdiBoxText::ConstructL(TInt)
643 TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
644 User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
645 for(TInt index=0;index<iBigBuffer.MaxLength();index++)
646 iBigBuffer.Append(TChar((index%26)+'a'));
647 iBbLen=iFont->TextWidthInPixels(iBigBuffer);
650 void CGdiBoxText::PreTestSetupL(const TRect &, TInt )
654 void CGdiBoxText::BaseTest(const TRect &aRect, TInt)
656 TInt rWid=aRect.iBr.iX-aRect.iTl.iX;
657 TInt fAscent=iFont->AscentInPixels();
658 TInt fHeight=iFont->HeightInPixels();
659 iGdi->UseFont(iFont);
660 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
663 rect.iBr.iY=rect.iTl.iY+fHeight;
665 TInt missingChars=iFont->TextCount(iBigBuffer,iBbLen-rWid);
666 TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars);
667 TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars));
668 TInt rLen=iFont->TextWidthInPixels(bbb);
669 TBool result = IsLengthEqual(lLen,rLen,iBbLen);
670 iGdiTest->TEST(result);
672 iGdiTest->INFO_PRINTF3(_L("(lLen+rLen)==iBbLen return value - Expected: %d, Actual: %d"), lLen+rLen, iBbLen);
674 iGdi->DrawText(bbb, rect, fAscent,CGraphicsContext::ELeft, rWid-rLen);
676 rect.Move(TPoint(0,fHeight));
677 iGdi->DrawText(iBigBuffer, rect, fAscent,CGraphicsContext::ELeft, 0);
679 TBuf<10> buf2(_L("1234567890"));
680 rect.Move(TPoint(0,fHeight));
681 iGdi->DrawText(buf2,rect,fAscent,CGraphicsContext::ERight,rect.Width()-iFont->TextWidthInPixels(buf2));
684 void CGdiBoxText::TheTest(const TRect &aRect, TInt)
686 TInt rWid=aRect.iBr.iX-aRect.iTl.iX;
687 TInt fAscent=iFont->AscentInPixels();
688 TInt fHeight=iFont->HeightInPixels();
689 iGdi->UseFont(iFont);
690 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
692 rect.iBr.iY=rect.iTl.iY+fHeight;
694 iGdi->DrawText(iBigBuffer, rect, fAscent, CGraphicsContext::ELeft, rWid-iBbLen);
696 rect.Move(TPoint(0,fHeight));
698 iGdi->SetClippingRegion(TRegionFix<1>(rect));
699 iGdi->DrawText(iBigBuffer, rect.iTl+TPoint(0,fAscent));
700 TBuf<10> buf2(_L("1234567890"));
701 rect.Move(TPoint(0,fHeight));
702 iGdi->CancelClippingRegion();
703 iGdi->DrawText(buf2,rect,fAscent);
710 CGdiVertBoxText::~CGdiVertBoxText()
712 TheClient->iScreen->ReleaseFont(iFont);
715 TInt CGdiVertBoxText::Count(TBool )
720 void CGdiVertBoxText::ConstructL(TInt)
722 TFontSpec fspec(KMonospaceTestFontTypefaceName,KMaxFontSize);
723 User::LeaveIfError(TheClient->iScreen->GetNearestFontToDesignHeightInTwips((CFont *&)iFont,fspec));
724 for(TInt index=0;index<iBigBuffer.MaxLength();index++)
725 iBigBuffer.Append(TChar((index%26)+'a'));
726 iBbLen=iFont->TextWidthInPixels(iBigBuffer);
729 void CGdiVertBoxText::PreTestSetupL(const TRect &, TInt )
733 void CGdiVertBoxText::BaseTest(const TRect &aRect, TInt)
735 TInt rWid=aRect.iBr.iY-aRect.iTl.iY;
736 TInt fAscent=iFont->AscentInPixels();
737 TInt fHeight=iFont->HeightInPixels();
738 iGdi->UseFont(iFont);
739 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
742 rect.iBr.iX=rect.iTl.iX+fHeight;
744 TInt missingChars=iFont->TextCount(iBigBuffer,iBbLen-rWid);
745 TPtrC bbb=iBigBuffer.Right(iBigBuffer.Length()-missingChars+1);
746 TInt lLen=iFont->TextWidthInPixels(iBigBuffer.Left(missingChars-1));
747 TInt rLen=iFont->TextWidthInPixels(bbb);
748 TBool result = IsLengthEqual(lLen,rLen,iBbLen);
749 iGdiTest->TEST(result);
751 iGdiTest->INFO_PRINTF3(_L("(lLen+rLen)==iBbLen return value - Expected: %d, Actual: %d"), lLen+rLen, iBbLen);
753 iGdi->DrawTextVertical(bbb, rect, fAscent, ETrue,CGraphicsContext::ELeft, rWid-rLen);
755 rect.iTl.iX=rect.iBr.iX;
756 rect.iBr.iX=rect.iTl.iX+fHeight;
757 iGdi->DrawTextVertical(iBigBuffer, rect, fAscent, ETrue,CGraphicsContext::ELeft, 0);
760 void CGdiVertBoxText::TheTest(const TRect &aRect, TInt)
762 TInt rWid=aRect.iBr.iY-aRect.iTl.iY;
763 TInt fAscent=iFont->AscentInPixels();
764 TInt fHeight=iFont->HeightInPixels();
765 iGdi->UseFont(iFont);
766 iGdi->SetBrushStyle(CGraphicsContext::ESolidBrush);
768 rect.iBr.iX=rect.iTl.iX+fHeight;
770 iGdi->DrawTextVertical(iBigBuffer, rect, fAscent, ETrue, CGraphicsContext::ELeft, rWid-iBbLen);
772 rect.iTl.iX=rect.iBr.iX;
773 rect.iBr.iX=rect.iTl.iX+fHeight;
775 iGdi->SetClippingRegion(TRegionFix<1>(rect));
776 iGdi->DrawTextVertical(iBigBuffer, TPoint(rect.iTl.iX+fAscent,rect.iBr.iY), ETrue);
782 CGdiBlitMasked::~CGdiBlitMasked()
784 for(TInt index=0;index<ENumMasks;index++)
788 delete iScratchDevice;
791 delete iScratchMaskDevice;
792 delete iScratchMaskGc;
795 TInt CGdiBlitMasked::Count(TBool aMainTests)
797 return(aMainTests ? ENumMasks*2 : ENumMasks*2);
800 void CGdiBlitMasked::doCreateTestBitmapL(CFbsBitmap *aBitmap, CFbsBitGc *&aGc, CFbsBitmapDevice *&aDevice, const TSize &aSize)
802 User::LeaveIfNull(aDevice=CFbsBitmapDevice::NewL(aBitmap));
803 User::LeaveIfError(aDevice->CreateContext(aGc));
805 aGc->SetBrushColor(TRgb(128,128,128));
806 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
807 aGc->SetPenStyle(CGraphicsContext::ENullPen);
808 aGc->DrawRect(TRect(aBitmap->SizeInPixels()));
809 aGc->SetPenStyle(CGraphicsContext::ESolidPen);
810 for(TInt index=(-aSize.iHeight);index<aSize.iWidth;index+=5)
812 aGc->DrawLine(TPoint(index,0),TPoint(index+aSize.iHeight,aSize.iHeight));
813 aGc->DrawLine(TPoint(index,aSize.iHeight),TPoint(index+aSize.iHeight,0));
817 void CGdiBlitMasked::createTestBitmapL(CFbsBitmap *&aBitmap, const TSize &aSize)
820 CFbsBitmapDevice *device=NULL;
821 aBitmap=new(ELeave) CFbsBitmap();
822 User::LeaveIfError(aBitmap->Create(aSize,EGray16));
823 TRAPD(err,doCreateTestBitmapL(aBitmap, gc, device, aSize));
826 User::LeaveIfError(err);
829 void CGdiBlitMasked::ConstructL(TInt)
832 for(TInt index=0;index<ENumMasks;index++)
834 iMask[index]=new(ELeave) CFbsBitmap();
835 User::LeaveIfError(iMask[index]->Load(TAUTO_BITMAP_NAME,2+index));
836 TSize size=iMask[index]->SizeInPixels();
837 if (max.iWidth<size.iWidth)
838 max.iWidth=size.iWidth;
839 if (max.iHeight<size.iHeight)
840 max.iHeight=size.iHeight;
842 iScratch=new(ELeave) CFbsBitmap();
843 User::LeaveIfError(iScratch->Create(max,EGray16));
844 iScratchDevice=CFbsBitmapDevice::NewL(iScratch);
845 User::LeaveIfError(iScratchDevice->CreateContext(iScratchGc));
847 iScratchMask=new(ELeave) CFbsBitmap();
848 User::LeaveIfError(iScratchMask->Create(max,EGray16));
849 iScratchMaskDevice=CFbsBitmapDevice::NewL(iScratchMask);
850 User::LeaveIfError(iScratchMaskDevice->CreateContext(iScratchMaskGc));
852 createTestBitmapL(iBitmap, max);
855 void CGdiBlitMasked::PreTestSetupL(const TRect &, TInt aCount)
857 iInvertMask=aCount&0x1;
859 iCurrMask= iMask[aCount%ENumMasks];
860 iDrawMode=CGraphicsContext::EDrawModePEN;
863 void CGdiBlitMasked::BaseTest(const TRect &aRect, TInt)
865 // needs re-writing to emulate tiling of the source rect
866 if (!aRect.Intersects(TRect(BaseWin->Size())))
868 TSize size(aRect.Size());
869 TSize bitSize=iBitmap->SizeInPixels();
870 if (size.iWidth>bitSize.iWidth)
871 size.iWidth=bitSize.iWidth;
872 if (size.iHeight>bitSize.iHeight)
873 size.iHeight=bitSize.iHeight;
875 // Set up the scratch mask as a black and white bitmap containing the mask to blit
876 // The mask pattern is replicated all over the scratchmask bitmap
878 iScratchMaskGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
879 iScratchMaskGc->SetPenStyle(CGraphicsContext::ENullPen);
880 iScratchMaskGc->SetBrushColor(TRgb(0,0,0));
881 iScratchMaskGc->DrawRect(TRect(iScratchMask->SizeInPixels()));
882 iScratchMaskGc->SetPenColor(TRgb(255,255,255));
883 iScratchMaskGc->SetPenStyle(CGraphicsContext::ESolidPen);
884 TSize maskSize(iCurrMask->SizeInPixels());
886 TRgb *rgbBuf=(TRgb *)User::AllocL(maskSize.iWidth*sizeof(TRgb)); //Doesn't do any harm if it leaves
887 for(pos.iY=0;pos.iY<maskSize.iHeight;pos.iY++)
889 TPtr8 ptr((TUint8 *)rgbBuf,maskSize.iWidth*sizeof(TRgb));
890 iCurrMask->GetScanLine(ptr, pos, maskSize.iWidth, ERgb);
891 for(TInt index=0;index<maskSize.iWidth;index++)
893 iScratchMaskGc->SetPenColor(rgbBuf[index]);
894 // if ((isLow && !iLowCutOff) || (!isLow && iLowCutOff))
895 iScratchMaskGc->Plot(TPoint(index,pos.iY));
900 for(pos.iY=0;pos.iY<size.iHeight;pos.iY+=maskSize.iHeight)
901 for(pos.iX=0;pos.iX<size.iWidth;pos.iX+=maskSize.iWidth)
902 iScratchMaskGc->CopyRect(pos, TRect(maskSize));
904 // Blit this to the screen in ANDNOT mode to clear all the pixels we want the mask blit to draw to
906 iGdi->SetDrawMode(CGraphicsContext::EDrawModeANDNOT);
907 iGdi->BitBlt(aRect.iTl, iScratchMask, TRect(size));
909 // Copy the test bitmap to the scratch bitmap then use the scratch mask to clear all the bits
910 // that should masked out of the draw to the screen
912 iScratchGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
913 iScratchGc->BitBlt(TPoint(0,0), iBitmap);
914 iScratchGc->SetDrawMode(CGraphicsContext::EDrawModeAND);
915 iScratchGc->BitBlt(TPoint(0,0), iScratchMask);
917 // Now copy the scratch bitmap to the screen in OR mode to get the final result
919 iGdi->SetDrawMode(CGraphicsContext::EDrawModeOR);
920 iGdi->BitBlt(aRect.iTl, iScratch, TRect(size));
923 void CGdiBlitMasked::TheTest(const TRect &aRect, TInt)
925 iGdi->BitBltMasked(aRect.iTl,iBitmap,TRect((aRect.iBr-aRect.iTl).AsSize()),
926 iCurrMask,iInvertMask);
931 CTGdi::CTGdi(CTestStep* aStep) : CTWsGraphicsBase(aStep), iGdiTest (NULL), iTextOffsetX(10),iTextOffsetY(10)
935 void CTGdi::ConstructL()
937 iWinSize=TestWin->Size();
940 TSize CTGdi::WinSize()
945 void CTGdi::DoGdiTestL(const TRect &aRect, TInt aNum)
948 iGdiTest->PreTestSetupL(aRect,aNum);
950 BaseWin->Win()->Invalidate();
951 BaseWin->Win()->BeginRedraw();
952 TheGc->Activate(*BaseWin->Win());
953 iTest->DrawTestBackground(EFalse,BaseWin->Size());
954 iGdiTest->BaseTest(aRect,aNum);
956 BaseWin->Win()->EndRedraw();
958 TestWin->Win()->Invalidate();
959 TestWin->Win()->BeginRedraw();
960 TheGc->Activate(*TestWin->Win());
961 iTest->DrawTestBackground(EFalse,TestWin->Size());
962 iGdiTest->TheTest(aRect,aNum);
964 TestWin->Win()->EndRedraw();
966 TheClient->iWs.Flush();
967 TheClient->WaitForRedrawsToFinish();
968 TheClient->iWs.Finish();
970 _LIT(KLog,"GDI Substate=%d test=%d rect=(%d,%d,%d,%d) ");
972 buf.Format(KLog,iSubState,aNum,aRect.iTl.iX,aRect.iTl.iY,aRect.iBr.iX,aRect.iBr.iY);
973 iTestPassing=CompareWindows(buf);
976 void CTGdi::GdiTestL(CGdiTestLowLevel *aTest)
978 TTestRects::ResetSeed();
981 iGdiTest->SetGdiTest(this);
982 iGdiTest->AssignGdi(TheGc);
983 iGdiTest->ConstructL(iTest->iTestRects.Count1());
986 for(index=0; iTestPassing && index<iTest->iTestRects.Count2(); ++index)
988 TInt max=iGdiTest->Count(index<iTest->iTestRects.Count1());
989 TRect rect=iTest->iTestRects[index];
991 _LIT(KLog1,"Testing rectangle %d (%d,%d,%d,%d) 1st pass");
992 LOG_MESSAGE6(KLog1,index,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
994 for(index2=0; iTestPassing && index2<max; ++index2)
995 DoGdiTestL(rect,index2);
998 _LIT(KLog,"Test fail on rectangle %d at iteration %d");
999 LOG_MESSAGE3(KLog,index,index2);
1002 for(; iTestPassing && index<iTest->iTestRects.Count3(); index++)
1004 TRect rect=iTest->iTestRects[index];
1005 #if defined(LOGGING)
1006 _LIT(KLog2,"Testing rectangle %d (%d,%d,%d,%d) 2nd pass");
1007 LOG_MESSAGE6(KLog2,index,rect.iTl.iX,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY);
1015 void CTGdi::NonDrawing()
1017 // Test all non-drawing GDI functions
1020 TDisplayMode mode=TheClient->iScreen->DisplayMode();
1021 TEST((mode!=ERgb) && (mode!=ENone));
1024 TInt res = session.Connect();
1025 TEST(res == KErrNone);
1027 CArrayFixFlat<TInt>* modeList= new CArrayFixFlat<TInt> (15);
1031 #if defined(SYMBIAN_GRAPHICS_GCE)
1032 res = session.GetColorModeList(iTest->iScreenNumber, modeList);
1034 res = session.GetColorModeList(modeList);
1035 #endif //SYMBIAN_GRAPHICS_GCE
1037 TEST(res == KErrNone);
1045 TBool found = EFalse;
1046 for(TInt ii = 0; ii < modeList->Count() && !found; ii++)
1048 TDisplayMode mode1 = (TDisplayMode) ((*modeList)[ii]);
1061 // Auxiliary Fn for Test Case ID CTGdi_TestDefetct_DEF045746
1062 // This method draws the text represented by aText parameter on the window
1065 void CTGdi::DrawTextOnWindow(const TDesC& aText,CTWin* aWin)
1067 aWin->Win()->BeginRedraw();
1068 TheGc->Activate(*aWin->Win());
1069 TheGc->Device()->GetNearestFontToDesignHeightInTwips(iFont,TFontSpec(_L("Arial"),250));
1070 TheGc->UseFont(iFont);
1072 TheGc->DrawRect(TRect(aWin->Win()->Size()));
1073 TheGc->DrawText(aText,TPoint(iTextOffsetX,iTextOffsetY));
1074 TheGc->Device()->ReleaseFont(iFont);
1075 TheGc->Deactivate();
1076 aWin->Win()->EndRedraw();
1080 void CTGdi::TestDefetct_DEF045746L()
1082 _LIT(KString,"This is a test window for the defect fix DEF045746 \
1083 propagated from Opera browser. Most window graphics context drawing\
1084 functions map to equivalent CFbsBitGc functions they are implemented\
1085 on the screen with any co-ordinates being relative to the top left\
1086 corner of the window. However extra clipping is applied. The drawing\
1087 will always be clipped to the visible part of the window, in addition\
1088 it will be clipped to the non-invalid part if you are not doing a\
1089 redraw and to the region being validated if you are doing a redraw.");
1091 TPtrC TestText(KString().Ptr(),100);
1092 TPtrC LargeText(KString().Ptr());
1093 TPtrC ShortText(KString().Ptr(),200);
1095 TSize scrSize=TheClient->iScreen->SizeInPixels();
1097 const TInt windowGap=5;
1098 winSize.SetSize(scrSize.iWidth -2* windowGap,scrSize.iHeight/2 - windowGap);
1100 iWin=new(ELeave) CTestWindow(TRgb(0,0,0));
1101 iWin->ConstructL(TPoint(5,5),TSize(winSize),TheClient->iGroup,*TheClient->iGc);
1102 CTestWindow* expectWin= new(ELeave) CTestWindow(TRgb(0,0,0));
1103 expectWin->ConstructL(TPoint(5,scrSize.iHeight/2 + windowGap),TSize(winSize),TheClient->iGroup,*TheClient->iGc);
1104 DrawTextOnWindow(ShortText,iWin);
1105 DrawTextOnWindow(TestText,expectWin);
1106 TInt fHeight=iFont->HeightInPixels();//Used to compare only pixels where text is drawn
1107 TRect iRect=winSize;
1108 iRect.iTl.iX=iTextOffsetX;
1109 iRect.iTl.iY=iTextOffsetY;
1110 iRect.iBr.iY=iTextOffsetY+fHeight;
1111 CheckRect(iWin,expectWin,iRect,_L("TestDefetct_DEF045746L A"));
1113 DrawTextOnWindow(LargeText,iWin);
1114 CheckRect(iWin,expectWin,iRect,_L("TestDefetct_DEF045746L B"));
1121 void CTGdi::RunTestCaseL(TInt /*aCurTestCase*/)
1123 //_LIT(KTest1,"NonDrawing"); this test is not running
1124 _LIT(KTest2,"DEF045746");
1125 _LIT(KTest3,"Drawing Tests");
1126 ((CTGdiStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
1127 static TTime startTime;
1128 switch(++iTest->iState)
1131 @SYMTestCaseID GRAPHICS-WSERV-0262
1135 @SYMTestCaseDesc Test all non-drawing GDI functions
1137 @SYMTestPriority High
1139 @SYMTestStatus Implemented
1141 @SYMTestActions Check all non-drawing GDI functions operate correctly
1143 @SYMTestExpectedResults Non-drawing GDI functions operate correctly
1147 startTime.HomeTime();
1148 ((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0262"));
1149 //iTest->LogSubTest(KTest1);
1150 //PeterI this tests whether the display mode is EGray4 or EGray16.
1151 //The actual display mode is EColor16MU so this test will always fail
1155 * @SYMTestCaseID GRAPHICS-WSERV-0263
1157 * @SYMPREQ DEF045746
1159 * @SYMTestCaseDesc Test defect fix for DEF045746
1161 * @SYMTestPriority High
1163 * @SYMTestStatus Implemented
1165 * @SYMTestActions The method tests CWindowGc::DrawText().The test is carried
1166 * out by writing small & very large strings to the window graphic context.
1168 * @SYMTestExpectedResults The window with large / small strings written is
1169 * compared with an expected result window. In both the cases strings should
1174 ((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0263"));
1175 iTest->LogSubTest(KTest2);
1176 TestDefetct_DEF045746L();
1179 @SYMTestCaseID GRAPHICS-WSERV-0264
1183 @SYMTestCaseDesc Test all drawing GDI functions
1185 @SYMTestPriority High
1187 @SYMTestStatus Implemented
1189 @SYMTestActions Check all drawing GDI functions operate correctly
1191 @SYMTestExpectedResults Drawing GDI functions operate correctly
1195 ((CTGdiStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0264"));
1196 iTest->LogSubTest(KTest3);
1198 TheClient->WaitForRedrawsToFinish(); //Just in case the two test windows have any invalid areas
1199 TInt numTests = sizeof(GdiTestFuncs) / sizeof(GdiTestFuncs[0]);
1200 while (iSubState < numTests)
1202 LOG_MESSAGE(TPtrC(GdiTestFuncs[iSubState].txt));
1203 GdiTestL((*GdiTestFuncs[iSubState].func)());
1209 ((CTGdiStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
1210 ((CTGdiStep*)iStep)->CloseTMSGraphicsStep();
1212 // log time and print duration
1215 TInt64 duration = endTime.MicroSecondsFrom(startTime).Int64();
1216 float time = (float) I64LOW(duration) / 1000.0f;
1217 _LIT(KDuration,"Total test duration is %f millisec");
1218 RDebug::Print(KDuration, time);
1221 ((CTGdiStep*)iStep)->RecordTestResultL();
1224 CGdiTestLowLevel *SetOriginTest()
1226 return(new(ELeave) CGdiSetOrigin());
1229 CGdiTestLowLevel *PolyLineTest()
1231 return(new(ELeave) CGdiPolyLine());
1234 CGdiTestLowLevel *PolygonTest()
1236 return(new(ELeave) CGdiPolygon());
1239 CGdiTestLowLevel *BlitMaskedTest()
1241 return(new(ELeave) CGdiBlitMasked());
1244 CGdiTestLowLevel *DrawArcTest()
1246 return(new(ELeave) CGdiDrawArc());
1249 CGdiTestLowLevel *DrawPieTest()
1251 return(new(ELeave) CGdiDrawPie());
1254 CGdiTestLowLevel *DrawRoundRectTest()
1256 return(new(ELeave) CGdiDrawRoundRect());
1259 CGdiTestLowLevel *BoxTextTest()
1261 return(new(ELeave) CGdiBoxText());
1264 CGdiTestLowLevel *VertTextTest()
1266 return(new(ELeave) CGdiDrawVertText());
1269 CGdiTestLowLevel *VertBoxTextTest()
1271 return(new(ELeave) CGdiVertBoxText());
1274 CGdiTestLowLevel *WideLineTest()
1276 return(new(ELeave) CGdiWideLine());
1279 CGdiTestLowLevel *DrawTextTest()
1281 return(new(ELeave) CGdiDrawText());
1284 CGdiTestLowLevel *DrawRectTest()
1286 return(new(ELeave) CGdiDrawRect());
1289 __WS_CONSTRUCT_STEP__(Gdi)