First public contribution.
1 // Copyright (c) 1995-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.
14 // Automatically test the window server
23 #include "../tlib/testbase.h"
27 LOCAL_D const TUint KPanicThreadHeapSize=0x8000;
29 GLREF_C TInt ProcPriTestOtherProcess(TAny *aScreenNumber);
30 GLREF_C TInt ProcToKill(TAny *aScreenNumber);
31 GLREF_C TInt ProcDirect(TAny *aScreenNumber);
32 GLREF_C TInt ProcMultiDisplay(TAny *aScreenNumber);
34 _LIT(Priority,"ProcPriTest");
35 _LIT(ToKill,"ProcToKill");
36 _LIT(Direct,"ProcDirect");
37 _LIT(MultiDisplay,"ProcMultiDisplay");
39 CProcess::TInitialFunction CProcess::iFunctions[]=
41 TInitialFunction(Priority,ProcPriTestOtherProcess),
42 TInitialFunction(ToKill,ProcToKill),
43 TInitialFunction(Direct,ProcDirect),
44 TInitialFunction(MultiDisplay,ProcMultiDisplay)
47 GLDEF_D TestWindow *BaseWin;
48 GLDEF_D TestWindow *TestWin;
49 GLDEF_D TestClient *TheClient=NULL;
50 GLDEF_D CWindowGc *TheGc;
51 TInt CTestBase::iMaxGrays=0;
52 TInt CTestBase::iScreenNo=0;
53 TInt CTestBase::iMaxColors=0;
54 TInt CTestBase::iNumberTestsPass=0;
55 TInt CTestBase::iNumberTests=0;
56 TRect CTestBase::iNormalPointerCursorArea;
57 TPartialRedrawType CTestBase::iRedrawType=EPartialRedraw_Unknown;
58 TInt CTestBase::iNumberOfGrpWndsOnPrimaryScreenWithZeroPriority = 0;
59 TInt CTestDriver::iTestNum=0;
61 GLDEF_D TInt TheTestResult=ETestPassed; // start with passed to anticipate empty test table
63 const TInt KBorderWinWidth = 5;
67 TInt64 TTestRects::iSeed=0;
68 TRect TTestRects::iList[]={
145 #if defined(__WINS__)
146 void FindNonMatchingPixelL(TPoint aPt1,TPoint aPt2,TSize aSize)
147 // This function is purely for use when debugging to find the first non-matching pixel
148 // when a check of two on screen rects has failed.
150 HBufC8* buf1=HBufC8::NewMaxLC(2*aSize.iWidth);
151 HBufC8* buf2=HBufC8::NewMaxLC(2*aSize.iWidth);
152 TPtr8 ptr1=buf1->Des();
153 TPtr8 ptr2=buf2->Des();
156 for (;row<aSize.iHeight;++row)
158 TheClient->iScreen->GetScanLine(ptr1,aPt1,aSize.iWidth,EColor64K);
159 TheClient->iScreen->GetScanLine(ptr2,aPt2,aSize.iWidth,EColor64K);
166 if (row<aSize.iHeight)
168 for (TInt col=0;col<aSize.iWidth;++col)
170 TheClient->iScreen->GetPixel(color1,aPt1);
171 TheClient->iScreen->GetPixel(color2,aPt2);
173 { // Break here to find first pixel that didn't match.
175 _LIT(KFindNonMatchingPixelFmt,"First non matching pixel (%d,%d)");
176 buf.Format(KFindNonMatchingPixelFmt,col,row);
177 TheClient->iWs.LogMessage(buf);
185 CleanupStack::PopAndDestroy(2);
188 void FindNonMatchingPixel(TPoint aPt1,TPoint aPt2,TSize aSize)
190 TRAPD(ignore,FindNonMatchingPixelL(aPt1,aPt2,aSize));
194 void AutoPanic(TInt aPanic)
196 User::Panic(_L("Auto"),aPanic);
199 void CleanUpWindow(TAny *aWindow)
201 ((RWindowTreeNode *)aWindow)->Close();
204 void PushWindowL(RWindowTreeNode *aWindow)
206 CleanupStack::PushL(TCleanupItem(CleanUpWindow,aWindow));
210 TBool OpacityAndAlphaSupportedL()
212 // If opacity is not implemented, EFalse will be returned
213 if(TransparencySupportedL()!=KErrNone)
216 const TRgb KTransparencyColor(0,0,0);
217 RWindow winb(TheClient->iWs);
218 CleanupClosePushL(winb);
219 RWindow wint(TheClient->iWs);
220 CleanupClosePushL(wint);
221 User::LeaveIfError(winb.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
222 User::LeaveIfError(wint.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
223 winb.SetExtent(TPoint(0,0), TSize(50,50));
224 wint.SetExtent(TPoint(0,0), TSize(50,50));
225 winb.SetRequiredDisplayMode(EColor256);
226 wint.SetRequiredDisplayMode(EColor256);
227 wint.SetTransparencyFactor(KTransparencyColor);
228 winb.SetBackgroundColor(TRgb(0,0,255));
229 wint.SetBackgroundColor(TRgb(255,0,0));
234 TheClient->iGc->Activate(wint);
235 TheClient->iGc->SetOpaque(ETrue);
236 TheClient->iGc->SetPenStyle(CGraphicsContext::ENullPen);
237 TheClient->iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
238 TheClient->iGc->SetBrushColor(TRgb(0,255,0));
239 TheClient->iGc->DrawRect(TRect(TPoint(0,0), TSize(50,50)));
240 TheClient->iGc->SetOpaque(EFalse);
241 TheClient->iGc->Deactivate();
245 // The window should be all green, if opacity is working, or all blue if it isn't.
246 // If the window has any other colour, then something has broken.
248 TheClient->iScreen->GetPixel(color,TPoint(25,25));
249 if (color.Red()>0 || ((color.Green()==0) == (color.Blue()==0)))
250 User::Leave(KErrGeneral);
251 TBool ret=(color.Green()>0);
253 CleanupStack::PopAndDestroy(2,&winb); // wint
257 TInt TransparencySupportedL()
259 // Creates a window and enables alpha transparency, if this feature
260 // is not enabled, KErrNotSupported will be returned
261 RWindow win(TheClient->iWs);
262 User::LeaveIfError(win.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
263 win.SetExtent(TPoint(0,0), TSize(50,50));
264 TInt ret=win.SetTransparencyAlphaChannel();
269 TInt CheckScalingSupportedOrNot()
271 TBool scalingSupported=EFalse;
272 TSizeMode originalModeData=TheClient->iScreen->GetCurrentScreenModeAttributes();
273 TSizeMode tempData=originalModeData;
274 tempData.iScreenScale=TSize(2,2);
275 TheClient->iScreen->SetCurrentScreenModeAttributes(tempData);
276 TSize scale=TheClient->iScreen->GetCurrentScreenModeScale();
277 if (scale.iWidth==2 && scale.iHeight==2)
279 scalingSupported=ETrue;
281 TheClient->iScreen->SetCurrentScreenModeAttributes(originalModeData);
283 return scalingSupported;
286 TBool CheckNonZeroOriginsSupportedOrNot()
288 TBool nonZeroOriginsSupported=EFalse;
289 TSizeMode sizeMode1=TheClient->iScreen->GetCurrentScreenModeAttributes();
290 TSizeMode sizeMode2=sizeMode1;
291 sizeMode2.iOrigin=TPoint(30,30);
292 TheClient->iScreen->SetCurrentScreenModeAttributes(sizeMode2);
293 TPoint origin=TheClient->iScreen->GetCurrentScreenModeScaledOrigin();
294 if (origin.iX==30 && origin.iY==30)
296 nonZeroOriginsSupported=ETrue;
298 TheClient->iScreen->SetCurrentScreenModeAttributes(sizeMode1);
300 return nonZeroOriginsSupported;
303 TPoint PhysicalToLogical(TPoint aPhysicalPtMinusOrigin,TSize aScale)
305 TPoint logicalPt(aPhysicalPtMinusOrigin);
306 if (aScale.iWidth!=1)
308 logicalPt.iX=(logicalPt.iX>= 0 ? logicalPt.iX/aScale.iWidth : (logicalPt.iX-(aScale.iWidth-1))/aScale.iWidth);
310 if (aScale.iHeight!=1)
312 logicalPt.iY=(logicalPt.iY>= 0 ? logicalPt.iY/aScale.iHeight : (logicalPt.iY-(aScale.iHeight-1))/aScale.iHeight);
318 // Log window, logs testing //
321 LogWindow::LogWindow() : CTWin(), iTestTitle(KNullDesC), iSubTitle(KNullDesC), iMessage(KNullDesC)
324 void LogWindow::ConstructL(CTWinBase &parent)
326 CTWin::ConstructL(parent);
327 iTitleHeight=iFont->HeightInPixels()+4;
330 void LogWindow::DrawSubTitle()
332 iGc->DrawText(iSubTitle, TRect(2,iTitleHeight*2,iSize.iWidth-2,iTitleHeight*3),iFont->AscentInPixels(), CGraphicsContext::ECenter);
335 void LogWindow::DrawMessage()
337 iGc->DrawText(iMessage, TRect(1,iTitleHeight*4,iSize.iWidth-2,iTitleHeight*5),iFont->AscentInPixels(), CGraphicsContext::ECenter);
340 void LogWindow::Draw()
342 iGc->SetPenColor(TRgb::Gray16(8));
343 iGc->SetPenColor(TRgb::Gray16(0));
345 iGc->DrawLine(TPoint(0,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight));
346 iGc->DrawText(iTestTitle, TPoint((iSize.iWidth-iFont->TextWidthInPixels(iTestTitle))/2,iFont->AscentInPixels()+2));
352 This function is not used at the moment but I leave it in in case I need it when I improve the logging in
355 void LogWindow::LogTest(const TDesC &aTitle,TInt aNum)
357 _LIT(Test,"Test %d,%S");
358 iTestTitle.Format(Test,aNum,&aTitle);
360 _LIT(AutoNewTest,"AUTO New Test: ");
361 buf.Append(AutoNewTest);
362 buf.Append(iTestTitle);
363 TheClient->LogMessage(buf);
369 This function is not used at the moment but I leave it in in case I need it when I improve the logging in
372 const TDesC& LogWindow::LogSubTest(const TDesC &aTitle,TInt aNum)
374 _LIT(SubTest,"Sub-Test[%d], %S");
375 iSubTitle.Format(SubTest,aNum,&aTitle);
378 buf.Append(iSubTitle);
379 TheClient->LogMessage(buf);
382 iGc->UseFont((CFont *)iFont);
383 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
387 TheClient->iWs.Flush();
391 const TDesC& LogWindow::LogMessage(TBool aLog,const TDesC& aText,TInt aNum)
393 if (aNum!=EDummyValue)
395 _LIT(StringInt,"%S %d");
396 iMessage.Format(StringInt,&aText,aNum);
401 iMessage.Format(String,&aText);
404 iGc->UseFont((CFont *)iFont);
405 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
412 buf.Append(iMessage);
413 TheClient->LogMessage(buf);
415 TheClient->iWs.Flush();
421 // Test window, simple window used to do test graphics in //
423 TestWindow::TestWindow() : CTWin()
427 TestWindow::~TestWindow()
432 void TestWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
434 iBorderWin=new(ELeave) CBorderWindow();
435 iBorderWin->SetUpL(pos,size,parent,aGc);
436 TRAPD(err, CTWin::ConstructL(*iBorderWin));
439 SetExt(TPoint(2,2),TSize(size.iWidth-4,size.iHeight-4));
451 void TestWindow::Draw()
456 void TestWindow::ClearWin()
458 TheGc->Activate(*Win());
463 void TestWindow::SetBorderExt(TPoint aPos, TSize aSize)
465 iBorderWin->SetExt(aPos, aSize);
468 CBorderWindow* TestWindow::GetBorderWin()
473 CBorderWindow::CBorderWindow() : CTWin()
477 void CBorderWindow::ConstructL(CTWinBase &parent)
479 CTWin::ConstructL(parent);
482 void CBorderWindow::Draw()
484 iGc->SetBrushColor(TRgb::Gray16(0));
485 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
486 iGc->SetPenStyle(CGraphicsContext::ENullPen);
487 iGc->DrawRect(TRect(Size()));
492 TestWindowGroup::TestWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
496 void TestWindowGroup::BecomeOwning()
498 iGroupWin.DefaultOwningWindow();
501 void TestWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime)
503 if (aKey.iModifiers&EModifierFunc)
508 TheClient->Driver()->iTest->TriggerFail();
513 iCurWin->WinKeyL(aKey,aTime);
516 void TestWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &aTime)
519 iCurWin->KeyDownL(aKey,aTime);
522 void TestWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &aTime)
525 iCurWin->KeyUpL(aKey,aTime);
530 TestClient::TestClient()
533 void TestClient::ConstructL()
535 CTClient::ConstructL();
537 iGroup=new(ELeave) TestWindowGroup(this);
538 iGroup->ConstructL();
540 iScreen->GetScreenSizeModeList(&iScreenModes);
541 iScreen->SetScreenMode(iScreenModes[0]);
542 TSize screenSize=iScreen->SizeInPixels();
544 TInt winWidth=(screenSize.iWidth/3)-10;
545 TInt winHeight=screenSize.iHeight-10;
546 iStdLogWindow=new(ELeave) LogWindow();
547 iStdLogWindow->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
548 BaseWin=new(ELeave) TestWindow();
549 BaseWin->SetUpL(TPoint(screenSize.iWidth/3+5,5),TSize(winWidth,winHeight),iGroup,*iGc);
550 TestWin=new(ELeave) TestWindow();
551 TestWin->SetUpL(TPoint(screenSize.iWidth/3*2+5,5),TSize(winWidth,winHeight),iGroup,*iGc);
553 iDriver = CTestDriver::CreateL(iScreenNumber); // virtual constructor
555 TheGc=new(ELeave) CWindowGc(iScreen);
556 User::LeaveIfError(TheGc->Construct());
558 _LIT(KTestLog,"WSERV Auto Test Log");
559 LogMessage(KTestLog());
560 LogAvailableScreenModeL();
562 //This class was designed to be created once and reused by all the tests, now it is created for each test,
563 //this needs to be changed back so tests like the following are only done once.
564 TestWsSetBufferSizeL();
565 TestWsSetMaxBufferSizeL();
568 inline CTestDriver* TestClient::Driver()
573 TBool TestClient::WaitForEvent()
575 if (iEventHandler->iStatus!=KRequestPending)
577 else if (iRedrawEventHandler->iStatus!=KRequestPending)
579 User::WaitForRequest(iEventHandler->iStatus,iRedrawEventHandler->iStatus);
580 TRequestStatus* status=&iEventHandler->iStatus;
582 if (iEventHandler->iStatus==KRequestPending)
584 status=&iRedrawEventHandler->iStatus;
587 TInt reason=status->Int();
588 *status=KRequestPending;
589 User::RequestComplete(status,reason);
593 TBool TestClient::IsEventWaiting()
595 return (iEventHandler->iStatus!=KRequestPending || iRedrawEventHandler->iStatus!=KRequestPending);
598 TestClient::~TestClient()
600 iScreenModes.Close();
603 delete iStdLogWindow;
608 void TestClient::LogAvailableScreenModeL()
610 _LIT(KColorModes,"Color Modes: ");
612 _LIT(KColor,"Color");
614 CArrayFixFlat<TInt>* modeList=new(ELeave) CArrayFixFlat<TInt>(15);
615 iWs.GetColorModeList(modeList);
616 TLogMessageText buf,buf2;
617 buf.Append(KColorModes);
622 mode=STATIC_CAST(TDisplayMode,(*modeList)[ii]);
623 buf.AppendNum((*modeList)[ii]);
624 buf2.Append(TDisplayModeUtils::IsDisplayModeColor(mode)?KColor():KGrey());
625 buf2.AppendNum(TDisplayModeUtils::NumDisplayModeColors(mode));
626 if (mode==EColor16MU)
628 if (++ii==modeList->Count())
638 void TestClient::TestWsSetBufferSizeL()
641 User::LeaveIfError(ws.Connect());
642 ws.SetBufferSizeL(256); // default buffer size 640
643 ws.SetBufferSizeL(0x8000); // 16K is max buffer size
644 ws.SetBufferSizeL(0x4000);
648 void TestClient::TestWsSetMaxBufferSizeL()
651 User::LeaveIfError(ws.Connect());
652 // allow buffer to grow bigger than the default 640 bytes
653 const TInt KBigMessageSize = 800;
654 ws.SetMaxBufferSizeL(KBigMessageSize + 8); // big message + command header length
656 // send the big message to the wserv
657 TBuf8<KBigMessageSize> bigMessage;
659 // LogMessage needs a pointer to a TInt with the message size at the start of the buffer
660 const TInt szLength = sizeof(TInt);
661 TInt length = KBigMessageSize - szLength; // length in Unicode characters
662 bigMessage.Append((TUint8*) &length, szLength);
667 bigMessage.Append((TUint8*) KLetterA().Ptr(), 2);
669 while (bigMessage.Length() < KBigMessageSize);
671 // send to Wserv, note that the message is too long to be logged
672 ws.TestWrite(ws.WsHandle(), EWsClOpLogMessage, bigMessage.Ptr(), KBigMessageSize);
678 void TestClient::SetTestClientScreenMode(TInt aMode)
680 iScreen->SetAppScreenMode(aMode);
681 iScreen->SetScreenMode(aMode);
682 UpdateTestClientScreenMode();
685 void TestClient::UpdateTestClientScreenMode()
687 TSize screenSize=iScreen->SizeInPixels();
689 // Sets new positions and dimensions for the three window and their controlling border windows
691 if (screenSize.iHeight > screenSize.iWidth) // Portrait mode
693 TInt winWidth=screenSize.iWidth - (KBorderWinWidth * 2);
694 TInt winHeight=(screenSize.iHeight/3) - (KBorderWinWidth * 2);
696 iStdLogWindow->SetExt(TPoint(KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
697 BaseWin->SetBorderExt(TPoint(KBorderWinWidth,screenSize.iHeight/3+KBorderWinWidth),TSize(winWidth,winHeight));
698 BaseWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
699 TestWin->SetBorderExt(TPoint(KBorderWinWidth,screenSize.iHeight/3*2+KBorderWinWidth),TSize(winWidth,winHeight));
700 TestWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
702 else // Landscape modes
704 TInt winWidth=(screenSize.iWidth/3) - (KBorderWinWidth * 2);
705 TInt winHeight=screenSize.iHeight - (KBorderWinWidth * 2);
707 iStdLogWindow->SetExt(TPoint(KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
708 BaseWin->SetBorderExt(TPoint(screenSize.iWidth/3 + KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
709 BaseWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
710 TestWin->SetBorderExt(TPoint(screenSize.iWidth/3*2+KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
711 TestWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
714 // Remove shading artefacts from window resizing operations
715 TestWin->Win()->Invalidate();
716 TestWin->Win()->BeginRedraw();
718 TestWin->Win()->EndRedraw();
720 BaseWin->Win()->Invalidate();
721 BaseWin->Win()->BeginRedraw();
723 BaseWin->Win()->EndRedraw();
725 TheClient->iWs.Flush();
730 // TestDriver, drives the test code //
732 CTestDriver* CTestDriver::CreateL(TInt aScreenNumber)
734 CTestDriver* self = NULL;
735 if (aScreenNumber==KDefaultScreen)
736 self = new (ELeave) CTestDriverPrimary(aScreenNumber);
738 self = new (ELeave) CTestDriverSecondary(aScreenNumber);
743 CTestDriver::CTestDriver(TInt aScreenNumber)
744 : iScreenNumber(aScreenNumber)
746 iStartTime.HomeTime();
747 HAL::Get(HALData::EDisplayNumberOfScreens, iNumberOfScreens);
750 CTestDriver::~CTestDriver()
754 void CTestDriver::DestroyTest()
760 void CTestDriver::TestComplete2()
763 if (iTestNum==iTestSize)
768 TTimeIntervalMicroSeconds elapseTime=endTime.MicroSecondsFrom(iStartTime);
769 TInt64 elapseTime2=elapseTime.Int64()/1000;
770 TUint diffi = I64LOW(elapseTime2);
771 _LIT(TestPass,"PASSED");
772 _LIT(TestFail,"FAILED");
773 TInt noOfTests=CTestBase::iNumberTests;
774 TInt noOfTestsPass=CTestBase::iNumberTestsPass;
775 _LIT(TimeBuf,"Elapse Time %d:%02d.%03d %S");
776 timeBuf.Format(TimeBuf,diffi/60000,(diffi/1000)%60,diffi%1000000,&(noOfTests==noOfTestsPass?TestPass:TestFail));
778 _LIT(Checks,"Checks");
780 _LIT(TestReport,"Tests:%d %S:%d");
781 TInt testNumber=(noOfTests==noOfTestsPass? noOfTestsPass : noOfTests-noOfTestsPass);
782 testReport.Format(TestReport,iTestNum,&(noOfTests==noOfTestsPass?Checks():Fails()),testNumber);
783 if (noOfTests!=noOfTestsPass)
785 _LIT(NumTests,"/%d");
786 testReport.AppendFormat(NumTests,noOfTests);
789 TBuf<60> logTestReport;
790 _LIT(LogReport," %S:%d/%d");
791 logTestReport.Format(LogReport,&Checks,noOfTestsPass,noOfTests);
793 _LIT(Finished,"AUTO Testing Complete, ");
794 buf.Append(Finished);
796 buf.Append(logTestReport);
797 TheClient->LogMessage(buf);
799 TheTestResult = noOfTests==noOfTestsPass? ETestPassed : ETestFailed;
800 DoDisplayDialog(timeBuf,testReport);
805 // Test driver for primary screen (has digitiser/pointer)
807 CTestDriverPrimary::CTestDriverPrimary(TInt aScreenNumber) : CTestDriver(aScreenNumber)
810 TInt numOfEntries = 1;
811 for (i=0; i<numOfEntries; ++i)
816 // omit multi display test (last entry in test table)
817 // for single screen platform
819 if (iNumberOfScreens==1)
824 void CTestDriverPrimary::DoDisplayDialog(TDesC& timeBuf,TDesC& testReport)
826 DisplayDialog(_L("Auto tests complete"),timeBuf, testReport);
830 // Test driver for secondary screens
832 CTestDriverSecondary::CTestDriverSecondary(TInt aScreenNumber) : CTestDriver(aScreenNumber)
835 TInt numOfEntries = 1;
836 for (i=0; i<numOfEntries; ++i)
842 void CTestDriverSecondary::DoDisplayDialog(TDesC& timeBuf,TDesC& testReport)
844 if (TheTestResult==ETestFailed)
845 DisplayDialog(iScreenNumber,_L("Auto tests complete"),timeBuf, testReport);
850 // This class provides a list of rectangles to test graphics to the test windows
851 // The list designed to test all cases total clipping, partial clipping, touching the edges,
852 // unclipped etc etc...
854 // NOTE:- Quick test version, does not provide a proper list yet
856 // For the rectangle list the graphics area is divided into 9 logical areas:-
857 // 0:The area above & left of the drawing area
858 // 1:The area above but within the left & right limits of the drawing area
859 // 2:The area above & right of the drawing area
860 // 3:The area left of but within the top & bottom limits of the drawing area
861 // 4:The area within the drawing area
862 // 5:The area right of but within the top & bottom limits of the drawing area
863 // 6:The area below & left of the drawing area
864 // 7:The area below but within the left & right limits of the drawing area
865 // 8:The area below & right of the drawing area
870 // -------------------------
874 // -------------------------
880 // The full list of rectangles needed to test an official release is as follows:
882 // 0-8: A rectangle wholly within each area (0 to 8) without touching the edges (if possible)
883 // 9-17: A rectangle wholly within each area and touching all bounding edges
884 // 18-26: A rectangle traversing each horizontal pair & triple of areas without touching the boundarys
885 // 27-35: A rectangle traversing each vertical pair & triple of areas without touching the boundarys
886 // 36-39: A rectangle traversing each 2x2 block of areas without touching the boundarys
887 // 40-43: A rectangle traversing each 2x2 block of areas touching each boundary
888 // 44: A rectangle that includes all areas
889 // 45-48: A rectangle fully enclosed in the central area that touches each edge
890 // 49-54: A rectangle fully enclosed in the central area that touches each pair of edges
891 // 55-58: A rectangle fully enclosed in the central area that touches each set of three edges
892 // 59-67: A Zero size rectangle in each of the 9 areas
893 // 68-77: Wide rectangles with heights from 0 to 9 in the central area
894 // 78-87: Tall rectangles with widths from 0 to 9 in the central area
897 void TTestRects::Construct(const RWindow &aWindow)
900 // Special case, does not use rectangles from here
902 // Special case, does not use rectangles from here
904 // Special case, does not use rectangles from here
907 iSize=aWindow.Size();
909 TInt wid=size.iWidth;
910 TInt hgt=size.iHeight;
922 iList[0]=TRect(-wid,-hgt,-wid2,-hgt2);
923 iList[1]=TRect(wid3,-hgt,wid-wid3,-hgt2);
924 iList[2]=TRect(wid+wid2,-2hgt,2wid,-hgt);
925 iList[3]=TRect(-3wid,hgt3,-wid3,hgt-hgt3);
926 iList[4]=TRect(wid4,hgt3,wid-wid3,hgt-hgt4);
927 iList[5]=TRect(3wid,hgt4,wid+3wid,hgt-hgt4);
928 iList[6]=TRect(-wid3,hgt+hgt4,-wid2,hgt+hgt);
929 iList[7]=TRect(wid2,hgt+hgt4,wid-wid4,hgt+hgt3);
930 iList[8]=TRect(2wid,hgt+hgt4,3wid,hgt+hgt2);
932 iList[9]=TRect(-wid,-hgt,0,0);
933 iList[10]=TRect(0,-2hgt,wid,0);
934 iList[11]=TRect(wid,-hgt2,wid+wid3,0);
935 iList[12]=TRect(-wid3,0,0,hgt);
936 iList[13]=TRect(0,0,wid,hgt);
937 iList[14]=TRect(wid,0,wid+wid4,hgt);
938 iList[15]=TRect(-wid,hgt,0,hgt+hgt4);
939 iList[16]=TRect(0,hgt,wid,hgt+hgt);
940 iList[17]=TRect(wid,hgt,wid+3wid,hgt+3hgt);
942 iList[18]=TRect(-wid,-hgt,wid2,hgt3);
943 iList[19]=TRect(wid3,-2hgt,2wid,-hgt3);
944 iList[20]=TRect(-wid,-hgt2,wid3,-hgt3);
945 iList[21]=TRect(-wid3,hgt4,wid2,hgt2);
946 iList[22]=TRect(wid3,hgt3,wid+wid3,hgt-hgt3);
947 iList[23]=TRect(-wid,hgt2,wid+wid4,hgt-hgt3);
948 iList[24]=TRect(-wid,2hgt,wid3,3hgt);
949 iList[25]=TRect(wid-wid4,hgt+hgt3,wid+wid4,2hgt);
950 iList[26]=TRect(-wid4,hgt+hgt4,wid+wid4,3);
953 iList[0]=TRect(0,0,size.iWidth,size.iHeight);
954 iList[1]=TRect(-10,-10,size.iWidth/2,size.iHeight/2);
955 iList[2]=TRect(size.iWidth/2,size.iHeight/2,size.iWidth+10,size.iHeight+10);
956 iList[3]=TRect(size.iWidth/4,size.iHeight/4,size.iWidth/2,size.iHeight/2);
957 iList[4]=TRect(-10,size.iHeight/4,size.iWidth+10,size.iHeight/2);
961 TInt TTestRects::Count1() const
963 // Count1() provides the simple base set of rectangles
969 TInt TTestRects::Count2() const
971 // Count2() provides an increased set of rectangles for each graphics func to test itself more thoroughly
977 TInt TTestRects::Count3() const
979 // Count3() provides the full set of rects for each graphics func to a quick test on
985 /** Reset the seed value to 0. */
986 void TTestRects::ResetSeed()
991 TInt TTestRects::Rnd(TInt aSize)
993 // Return a random based around aSize, maybe bigger maybe smaller, who knows?
996 TInt rnd=Math::Rand(iSeed);
998 if (rnd&0x8) // Increase from aSize
999 result=aSize*((rnd&0x7)+1);
1000 else // Decrease from aSize
1001 result=aSize/((rnd&0x7)+1);
1005 TInt TTestRects::RndMax(TInt aSize)
1007 // Return a random from 0 to aSize inclusive
1010 TInt64 tmpl=Math::Rand(iSeed);
1011 TInt tmp = I64INT(tmpl) & 0xFFFF;
1017 TInt TTestRects::RectCoord(TInt aSection,TInt aSize)
1023 result=-(1+Rnd(aSize));
1029 result=1+RndMax(aSize-2);
1035 result=aSize+1+Rnd(aSize);
1038 AutoPanic(EAutoPanicTestRectsSection);
1043 void TTestRects::RectCoordPair(TInt &aTl, TInt &aBr, TInt aSection, TInt aSize)
1047 aTl=RectCoord(aSection,aSize);
1048 aBr=RectCoord(aSection,aSize);
1049 } while(aTl==aBr && aSize>1);
1058 TRect TTestRects::operator[](TInt aIndex)
1061 if (aIndex<EMaxRectFromList)
1063 const TRect *pRect=&iList[aIndex];
1064 if (pRect->iTl.iX==pRect->iBr.iX)
1065 RectCoordPair(rect.iTl.iX,rect.iBr.iX,pRect->iTl.iX,iSize.iWidth);
1068 rect.iTl.iX=RectCoord(pRect->iTl.iX,iSize.iWidth);
1069 rect.iBr.iX=RectCoord(pRect->iBr.iX,iSize.iWidth);
1071 if (pRect->iTl.iY==pRect->iBr.iY)
1072 RectCoordPair(rect.iTl.iY,rect.iBr.iY,pRect->iTl.iY,iSize.iHeight);
1075 rect.iTl.iY=RectCoord(pRect->iTl.iX,iSize.iHeight);
1076 rect.iBr.iY=RectCoord(pRect->iBr.iX,iSize.iHeight);
1079 else if (aIndex<EMaxRectZeroSize)
1081 rect.iTl.iX=RectCoord(((aIndex-EMaxRectFromList)%3)*2,iSize.iWidth);
1082 rect.iTl.iY=RectCoord(((aIndex-EMaxRectFromList)/3)*2,iSize.iHeight);
1085 else if (aIndex<EMaxRectWide)
1088 rect.iBr.iX=iSize.iWidth-1;
1090 rect.iBr.iY=rect.iTl.iY+(aIndex-EMaxRectWide);
1092 else if (aIndex<EMaxRectHigh)
1095 rect.iBr.iX=rect.iTl.iX+(aIndex-EMaxRectHigh);
1097 rect.iBr.iY=iSize.iHeight-1;
1100 AutoPanic(EAutoPanicTestRectsIndex);
1107 CBitmap* CBitmap::NewLC(const TSize& aSizeInPixels,TDisplayMode aDispMode)
1109 return NewLC(0,aSizeInPixels,aDispMode);
1112 CBitmap* CBitmap::NewL(const TSize& aSizeInPixels,TDisplayMode aDispMode)
1114 CBitmap* self=NewLC(0,aSizeInPixels,aDispMode);
1115 CleanupStack::Pop(self);
1119 CBitmap* CBitmap::NewL(TInt aHandle)
1121 CBitmap* self=NewLC(aHandle,TSize(),ENone);
1122 CleanupStack::Pop(self);
1126 CBitmap* CBitmap::NewL(TDesC& /*aFileName*/)
1128 User::Leave(KErrNotSupported);
1132 CBitmap* CBitmap::NewLC(TInt aHandle,const TSize& aSizeInPixels,TDisplayMode aDispMode)
1134 CBitmap* self=new(ELeave) CBitmap();
1135 CleanupStack::PushL(self);
1136 self->ConstructL(aHandle, aSizeInPixels, aDispMode);
1140 void CBitmap::ConstructL(TInt aHandle,const TSize& aSizeInPixels,TDisplayMode aDispMode)
1142 iBitmap=new(ELeave) CFbsBitmap();
1145 User::LeaveIfError(iBitmap->Create(aSizeInPixels,aDispMode));
1149 User::LeaveIfError(iBitmap->Duplicate(aHandle));
1151 iDevice=CFbsBitmapDevice::NewL(iBitmap);
1152 User::LeaveIfError(iDevice->CreateContext(iGc));
1165 CTestBase::CTestBase(const TDesC& aTitle,CTWsGraphicsBase* aTestBase)
1167 iTestBase=aTestBase;
1168 iTitle.Copy(aTitle);
1170 iScreenNo = iTestBase->GetScreenFromIni();
1172 TheClient=new(ELeave) TestClient();
1174 if (CTestBase::iScreenNo == 1)
1176 TheClient->SetScreenNumber(1);
1181 TheClient->SetScreenNumber(0);
1185 if (iScreenNumber == 1)
1187 iMinWin = new(ELeave) CMinWin(iScreenNumber);
1188 iMinWin->ConstructL();
1191 iTestNum=CTestDriver::iTestNum;
1192 TheClient->ConstructL();
1193 TheClient->StdLogWindow().LogTest(iTitle,iTestNum);
1194 iDriver=TheClient->Driver();
1196 if (CTestBase::iScreenNo == 1)
1198 TheClient->iWs.SetFocusScreen(1);
1202 TheClient->iWs.SetFocusScreen(0);
1205 iTestRects.Construct(*BaseWin->Win());
1206 iStdTestWindowSize=BaseWin->Size();
1207 iRedrawType=EPartialRedraw_Unknown; // Reset between tests
1208 if (iMaxGrays+iMaxColors==0)
1210 TheClient->iWs.GetDefModeMaxNumColors(iMaxColors,iMaxGrays);
1211 iNormalPointerCursorArea=TheClient->iWs.PointerCursorArea();
1215 CTestBase::~CTestBase()
1221 void CTestBase::CloseAllPanicWindows()
1223 TInt idFocus = TheClient->iWs.GetFocusWindowGroup();
1225 event.SetType(EEventKey);
1226 TKeyEvent *keyEvent = event.Key();
1227 keyEvent->iCode = EKeyEscape;
1228 keyEvent->iScanCode = EStdKeyEscape;
1229 keyEvent->iModifiers = 0;
1231 while(idFocus != NULL && (theLimit-- > 0))
1233 TheClient->iWs.SendEventToAllWindowGroups(event);
1234 idFocus = TheClient->iWs.GetFocusWindowGroup();
1239 Returns the size of the standard test windows.
1240 @see iStdTestWindowSize
1242 const TSize& CTestBase::StdTestWindowSize()
1244 return iStdTestWindowSize;
1247 /** Returns the number of greys available in the richest grey mode */
1248 TInt CTestBase::MaxGrays() const
1253 /** Returns the number of colours available in the richest supported colour mode. */
1254 TInt CTestBase::MaxColors() const
1259 void CTestBase::TriggerFail()
1264 void CTestBase::LogLeave(TInt aErr)
1266 TLogMessageText buf;
1267 _LIT(Leave,"AUTO Left with error code %d in ");
1268 buf.AppendFormat(Leave,aErr);
1269 buf.Append(iSubTitle);
1270 TheClient->LogMessage(buf);
1273 void CTestBase::LogSubTest(const TDesC &aSubTitle)
1275 Driver()->iSubTestNum++;
1276 iSubTitle=aSubTitle;
1277 iTestBase->Logger().Write(TheClient->StdLogWindow().LogSubTest(aSubTitle,iState));
1280 void CTestBase::LogMessage(TInt aValue)
1282 _LIT(WinID,"Win Id:");
1283 TheClient->StdLogWindow().LogMessage(EFalse,WinID,aValue);
1286 void CTestBase::LogSubState(TInt aSubState)
1288 _LIT(SubTest,"SubState");
1289 iTestBase->Logger().Write(TheClient->StdLogWindow().LogMessage(ETrue,SubTest,aSubState));
1292 TBool DoCheckRectRWin(RWindowBase &aWin1,RWindowBase &aWin2,const TRect &aRect)
1296 rect1.Move(aWin1.InquireOffset(*TheClient->iGroup->WinTreeNode()));
1297 rect2.Move(aWin2.InquireOffset(*TheClient->iGroup->WinTreeNode()));
1298 TBool match=TheClient->iScreen->RectCompare(rect1,rect2);
1299 #if defined(__WINS__)
1301 FindNonMatchingPixel(rect1.iTl,rect2.iTl,aRect.Size());
1306 TBool DoCheckRectRWin(RWindowBase &aWin1,RWindowBase &aWin2,const TRect &aRect, TUint aFlags)
1310 rect1.Move(aWin1.InquireOffset(*TheClient->iGroup->WinTreeNode()));
1311 rect2.Move(aWin2.InquireOffset(*TheClient->iGroup->WinTreeNode()));
1312 TBool match=TheClient->iScreen->RectCompare(rect1,rect2, aFlags);
1313 #if defined(__WINS__)
1315 FindNonMatchingPixel(rect1.iTl,rect2.iTl,aRect.Size());
1320 TBool DoCheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect)
1322 return DoCheckRectRWin(*aWin1->BaseWin(), *aWin2->BaseWin(), aRect);
1325 TBool DoCheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2)
1327 TSize winSize=aWin1->Size();
1328 TRect rect1(aWin1->BaseWin()->InquireOffset(*TheClient->iGroup->WinTreeNode()),winSize);
1329 TRect rect2(aWin2->BaseWin()->InquireOffset(*TheClient->iGroup->WinTreeNode()),winSize);
1330 return TheClient->iScreen->RectCompare(rect1,rect2);
1333 TBool DoCheckRect(CTBaseWin *aWin1, CTBaseWin *aWin2, const TRect &aRect, TUint aFlags)
1335 return DoCheckRectRWin(*aWin1->BaseWin(), *aWin2->BaseWin(), aRect, aFlags);
1340 Compares the contents of 2 rectangular areas of the screen.
1342 @param aPos1 The top left corner of the first rectangle.
1343 @param aPos2 The top left corner of the second rectangle.
1344 @param aSize The size of the rectangles
1345 @return ETrue if the 2 areas have the same content, EFalse otherwise.
1347 TBool DoCheckRect(TPoint aPos1,TPoint aPos2,TSize aSize)
1349 return TheClient->iScreen->RectCompare(TRect(aPos1,aSize),TRect(aPos2,aSize));
1352 void CTestBase::DrawTestBackground(TBool aInvertColors, const TSize &aSize, TInt aGrays/*=16*/)
1354 // Draws a standard test background with a mix of colors (shades).
1355 // This is mainly used to test for graphic functions writing outside the intended area.
1357 // This code assumes an TheGc is already active on the window to use.
1360 TheGc->SetBrushColor(TRgb::Gray256(255));
1363 TInt colorInc=(aGrays>9 ? 17 : 85);
1364 TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
1365 TheGc->SetPenStyle(CGraphicsContext::ENullPen);
1366 for(TInt row=0;row<aSize.iHeight;row+=step)
1368 TheGc->SetBrushColor(TRgb::Gray256(aInvertColors ? 255-col:col));
1369 TheGc->DrawRect(TRect(0,row,aSize.iWidth,row+step));
1376 void CTestBase::AbortL()
1378 CTestDriver* driver=iDriver;
1379 iDriver->DestroyTest();
1380 driver->TestComplete2();
1381 User::Leave(ETestFailed);
1384 /*CTWsGraphicsBase*/
1386 CTWsGraphicsBase::CTWsGraphicsBase(CTestStep* aStep) : CTGraphicsBase(aStep)
1390 CTWsGraphicsBase::~CTWsGraphicsBase()
1395 void CTWsGraphicsBase::CreateTestBaseL(CTTMSGraphicsStep* aTmsStep)
1397 __ASSERT_ALWAYS(iTest==NULL,AutoPanic(EAutoPanicRecalledCreateTestBaseL));
1398 iTest=new(ELeave) CTestBase(iStep->TestStepName(),this);
1399 iTmsStep = aTmsStep;
1402 Gets the Screen Number from an .ini file supplied to the RUN_TEST_STEP. Screen number should
1403 be put under the section [useScreen] as screen=0 or screen=1.
1405 @return Screen number Defined in .ini file, otherwise 0.
1407 TInt CTWsGraphicsBase::GetScreenFromIni() const
1409 _LIT(KUseScreenSection, "useScreen");
1410 _LIT(KScreen, "screen");
1413 TBool configAvailable = iStep->GetIntFromConfig(KUseScreenSection, KScreen, screen);
1424 void CTWsGraphicsBase::TestComplete()
1426 _LIT(KTestComplete,"Test complete");
1427 INFO_PRINTF1(KTestComplete);
1428 CTGraphicsBase::TestComplete();
1431 void CTWsGraphicsBase::LogMessage(const TText8* aFile,TInt aLine,TRefByValue<const TDesC> aFmt,...)
1433 TLogMessageText buf;
1435 VA_START(list,aFmt);
1436 buf.AppendFormatList(aFmt,list);
1437 TheClient->LogMessage(buf);
1438 Logger().LogExtra(aFile,aLine,ESevrInfo,buf);
1442 TBool CTWsGraphicsBase::CheckRetValue(TBool aPass, const TDesC *aErrorMsg, const TDesC &aErrorFunction)
1444 if (!aPass && aErrorMsg)
1446 LOG_MESSAGE3(_L("%S %S failed"),aErrorMsg,&aErrorFunction);
1447 iTmsStep->MQCTest(EFalse,((TText8*)__FILE__),__LINE__);
1453 void CTWsGraphicsBase::CompareWindowsSoftFailWinscw(const TText8* aFile, TInt aLine)
1455 if (!DoCheckRect(BaseWin, TestWin, BaseWin->Size()))
1458 _LIT(KMessage,"ERROR: Test Failed but is ignored on WINSCW");
1459 Logger().LogExtra(aFile, aLine, ESevrErr, KMessage);
1461 iStep->TEST(EFalse);
1462 _LIT(KMessage,"ERROR: Test Failed");
1463 Logger().LogExtra(aFile, aLine, ESevrErr, KMessage);
1468 void CTWsGraphicsBase::CheckRect(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC *aErrorMsg)
1470 CheckRetValue(DoCheckRect(aPos1,aPos2,aSize),aErrorMsg,_L("CheckRect()"));
1473 void CTWsGraphicsBase::CheckRect(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC &aErrorMsg)
1475 CheckRect(aPos1,aPos2,aSize,&aErrorMsg);
1478 void CTWsGraphicsBase::CheckRectNoMatch(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC *aErrorMsg)
1480 CheckRetValue(!DoCheckRect(aPos1,aPos2,aSize),aErrorMsg,_L("CheckRectNoMatch()"));
1483 void CTWsGraphicsBase::CheckRectNoMatch(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC &aErrorMsg)
1485 CheckRectNoMatch(aPos1,aPos2,aSize,&aErrorMsg);
1488 void CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC *aErrorMsg)
1490 CheckRetValue(DoCheckRect(aWin1,aWin2),aErrorMsg,_L("CheckRect()"));
1493 void CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC &aErrorMsg)
1495 CheckRect(aWin1,aWin2,&aErrorMsg);
1498 void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC *aErrorMsg)
1500 CheckRetValue(!DoCheckRect(aWin1,aWin2),aErrorMsg,_L("CheckRectNoMatch()"));
1503 void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC &aErrorMsg)
1505 CheckRectNoMatch(aWin1,aWin2,&aErrorMsg);
1508 TBool CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC *aErrorMsg)
1510 return CheckRetValue(DoCheckRect(aWin1,aWin2,aRect),aErrorMsg,_L("CheckRect()"));
1513 TBool CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC &aErrorMsg)
1515 return CheckRect(aWin1,aWin2,aRect,&aErrorMsg);
1518 void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC *aErrorMsg)
1520 CheckRetValue(!DoCheckRect(aWin1,aWin2,aRect),aErrorMsg,_L("CheckRectNoMatch()"));
1523 void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC &aErrorMsg)
1525 CheckRectNoMatch(aWin1,aWin2,aRect,&aErrorMsg);
1528 void CTWsGraphicsBase::CompareWindows(const TRect &aRect, const TDesC *aErrorMsg)
1530 CheckRetValue(DoCheckRect(BaseWin,TestWin,aRect),aErrorMsg,_L("CompareWindows()"));
1533 TBool CTWsGraphicsBase::CompareWindows(const TDesC *aErrorMsg)
1535 return CheckRetValue(DoCheckRect(BaseWin,TestWin,TRect(BaseWin->Size())),aErrorMsg,_L("CompareWindows()"));
1538 void CTWsGraphicsBase::CompareWindows(const TRect &aRect, const TDesC &aErrorMsg)
1540 CompareWindows(aRect,&aErrorMsg);
1543 TBool CTWsGraphicsBase::CompareWindows(const TDesC &aErrorMsg)
1545 return CompareWindows(&aErrorMsg);
1549 Returns the size of the standard test windows.
1551 Several tests use 3 windows : one is a log window, one is a reference window
1552 and one is the actual output of the test. All these windows have the same width which is roughly
1553 1/3 of the screen. They also have the same height which is roughly equal to the screen height.
1555 const TSize& CTWsGraphicsBase::StdTestWindowSize()
1557 return iTest->StdTestWindowSize();
1560 /** Returns the number of greys available in the richest grey mode */
1561 TInt CTWsGraphicsBase::MaxGrays() const
1563 return iTest->MaxGrays();
1566 /** Returns the number of colours available in the richest supported colour mode. */
1567 TInt CTWsGraphicsBase::MaxColors() const
1569 return iTest->MaxColors();
1576 LOCAL_C TInt PanicThreadFunc(TAny *aPtr)
1578 CTrapCleanup* CleanUpStack=CTrapCleanup::New();
1579 SPanicParams *ptr=(SPanicParams *)aPtr;
1581 TRAP(ret,ret=(*ptr->func)(ptr->num,ptr->ptr));
1582 delete CleanUpStack;
1583 if (ret==EWsExitReasonBad)
1584 AutoPanic(EAutoPanicPanicFailed);
1588 TInt CTestBase::LaunchPanicThread(RThread &aThread, SPanicParams *aPtr)
1590 TBuf<32> threadName;
1591 threadName.Format(TRefByValue<const TDesC>(_L("AutoPanicThread%d")),iThreadNumber++);
1592 return(aThread.Create(threadName,PanicThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,aPtr,EOwnerThread));
1595 TInt CTestBase::TestPanicL(SPanicParams *aPtr, TInt aExitReason, const TDesC &aCategory, TBool* aTestFinished)
1598 TRequestStatus stat;
1599 TInt err=LaunchPanicThread(thread, aPtr);
1600 if (err==KErrAlreadyExists)
1602 // wait for kernel to clear up old threads
1603 // and have several attempts at starting the thread
1604 // if unsuccessful the first time
1605 for (TInt i=0;i<3;i++)
1607 User::After(TTimeIntervalMicroSeconds32(100000)); //0.1 secs
1608 err=LaunchPanicThread(thread, aPtr);
1609 if (err!=KErrAlreadyExists)
1613 User::LeaveIfError(err);
1615 User::SetJustInTime(EFalse);
1617 User::WaitForRequest(stat);
1618 User::SetJustInTime(ETrue);
1620 TBool testFinished=EFalse;
1621 TBool testPassed=ETrue;
1622 if (thread.ExitType()==EExitKill)
1624 User::LeaveIfError(thread.ExitReason());
1625 if(thread.ExitReason()!=EWsExitReasonFinished)
1629 testFinished=ETrue; // Finish tests
1633 if ((thread.ExitCategory().Compare(aCategory)!=0)
1634 || (aExitReason!=EWservNoPanic && thread.ExitReason()!=aExitReason)
1635 || (thread.ExitType()!=EExitPanic))
1642 *aTestFinished=testFinished;
1647 TInt CTestBase::TestWsPanicL(TPanicFunction aFunction, TClientPanic aExitReason, TInt aInt, TAny *aPtr, TBool* aTestFinished)
1649 return TestPanicL(aFunction,aExitReason,aInt,aPtr,KWSERV, aTestFinished);
1652 TInt CTestBase::TestW32PanicL(TPanicFunction aFunction, TW32Panic aExitReason, TInt aInt, TAny *aPtr, TBool* aTestFinished)
1654 return TestPanicL(aFunction,aExitReason,aInt,aPtr,KW32,aTestFinished);
1657 TInt CTestBase::TestWservPanicL(TPanicFunction aFunction, TWservPanic aExitReason, TInt aInt, TAny *aPtr)
1659 _LIT(KWSERV1,"Wserv Internal Panic");
1660 return TestPanicL(aFunction,aExitReason,aInt,aPtr,KWSERV1);
1663 TInt CTestBase::TestPanicL(TPanicFunction aFunction, TInt aExitReason, TInt aInt, TAny *aPtr, const TDesC &aCategory, TBool* aTestFinished)
1665 SPanicParams params;
1667 params.func=aFunction;
1669 return TestPanicL(¶ms, aExitReason, aCategory, aTestFinished);
1672 TBool CTestBase::IsFullRomL()
1674 TBool isFullRom = EFalse;
1675 _LIT(KWinName,"EikonServer");
1676 TInt numWinGroups=TheClient->iWs.NumWindowGroups();
1677 CArrayFixFlat<TInt>* list=new(ELeave) CArrayFixFlat<TInt>(numWinGroups);
1678 TheClient->iWs.WindowGroupList(list);
1679 numWinGroups=list->Count(); // Just in case it changed between originally getting it and getting the actual list
1682 for(ii=0;ii<numWinGroups;++ii)
1684 TheClient->iWs.GetWindowGroupNameFromIdentifier((*list)[ii],name);
1685 #ifndef DISABLE_FAIL_DIALOG
1687 ordinalPos+=ordinalPos; //To stop a warning
1690 TheClient->iWs.GetWindowGroupOrdinalPriority((*list)[ii]);
1701 void CTestBase::DelayIfFullRomL()
1704 User::After(400000);
1707 TPartialRedrawType CTestBase::RedrawStoreTypeL()
1709 /* if (iRedrawType==EPartialRedraw_Unknown)
1711 const TRgb KRed=TRgb(255,0,0);
1712 const TRgb KGreen=TRgb(0,255,0);
1713 const TRgb KBlue=TRgb(0,0,255);
1714 CWsScreenDevice* scrDev=TheClient->iScreen;
1715 TSize winSize=scrDev->SizeInPixels();
1716 CBlankWindow* win=new(ELeave) CBlankWindow(KRed); //Window will be red if WSERV just draws in background color
1717 CleanupStack::PushL(win);
1718 TDisplayMode mode=EColor256;
1719 win->SetUpL(TPoint(),winSize,TheClient->iGroup,*TheClient->iGc,&mode); //Window is activated
1720 win->RealDraw(ETrue);
1721 win->SetColor(KGreen);
1722 CBlankWindow* win2=new(ELeave) CBlankWindow(KRed);
1723 CleanupStack::PushL(win2);
1724 win2->SetUpL(TPoint(),winSize,TheClient->iGroup,*TheClient->iGc,&mode); //New Window completely obscures other window
1725 win2->RealDraw(ETrue);
1726 win->CTWin::DrawNow(); //Window will be green if drawn from stored commands
1727 win2->CTWin::DrawNow();
1728 win2->SetVisible(EFalse);
1730 scrDev->GetPixel(col,TPoint(5,5)); //Pixel will be red if storing off by default and green otherwise
1733 win->Win()->EnableRedrawStore(ETrue);
1734 win->CTWin::DrawNow(); //Create stored commands
1737 __ASSERT_ALWAYS(col==KGreen,AutoPanic(EAutoPanicRedrawStoring));
1738 win->SetColor(KBlue);
1739 TRect redrawRect(TSize(10,10));
1740 win->Invalidate(redrawRect);
1741 win->Win()->BeginRedraw(redrawRect);
1742 win->DrawNow(redrawRect); //Top left of Window will be blue if it draws itself
1743 win->Win()->EndRedraw();
1744 win2->SetVisible(ETrue);
1745 win2->SetVisible(EFalse);
1746 scrDev->GetPixel(col,TPoint(5,5)); //Pixel will be red if stored commands were lost
1747 iRedrawType=EPartialRedraw_None;
1750 __ASSERT_ALWAYS(col==KBlue,AutoPanic(EAutoPanicRedrawStoring));
1751 TheClient->WaitForRedrawsToFinish();
1752 win2->SetVisible(ETrue);
1753 win2->SetVisible(EFalse);
1754 scrDev->GetPixel(col,TPoint(15,15)); //Pixel will be blue if partial redraw triggers full redraw
1755 iRedrawType=EPartialRedraw_PreserveStoredCmds;
1758 __ASSERT_ALWAYS(col==KGreen,AutoPanic(EAutoPanicRedrawStoring));
1759 iRedrawType=EPartialRedraw_FullRedrawSupport;
1762 CleanupStack::PopAndDestroy(2,win);
1764 return iRedrawType;*/
1765 return EPartialRedraw_FullRedrawSupport;
1768 void CTestBase::SetUpMember(TSpriteMember &aMember)
1770 aMember.iMaskBitmap=NULL;
1771 aMember.iInvertMask=EFalse;
1772 aMember.iDrawMode=CGraphicsContext::EDrawModePEN;
1773 aMember.iOffset=TPoint();
1774 aMember.iInterval=TTimeIntervalMicroSeconds32(0);
1777 void CTestBase::SimulateKeyDownUpWithModifiers(TInt aScanCode,TUint aModifiers)
1779 if (aModifiers&EModifierAlt)
1780 SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftFunc);
1781 if (aModifiers&EModifierCtrl)
1782 SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftCtrl);
1783 if (aModifiers&EModifierShift)
1784 SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
1785 SimulateKeyDownUp(aScanCode);
1786 if (aModifiers&EModifierShift)
1787 SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
1788 if (aModifiers&EModifierCtrl)
1789 SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftCtrl);
1790 if (aModifiers&EModifierAlt)
1791 SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftFunc);
1794 void CTestBase::SimulateKeyDownUp(TInt aScanCode)
1796 __ASSERT_DEBUG(aScanCode<'a' || aScanCode>'z',AutoPanic(EAutoPanicScanCapital));
1797 SimulateKey(TRawEvent::EKeyDown,aScanCode);
1798 SimulateKey(TRawEvent::EKeyUp,aScanCode);
1801 void CTestBase::SimulatePointerDownUp(TInt aX, TInt aY)
1803 SimulatePointer(TRawEvent::EButton1Down,aX,aY);
1804 SimulatePointer(TRawEvent::EButton1Up,aX,aY);
1807 void CTestBase::SimulateKey(TRawEvent::TType aType, TInt aScanCode)
1810 rawEvent.Set(aType,aScanCode);
1811 TheClient->iWs.SimulateRawEvent(rawEvent);
1815 * Determine if the configuration supports pointer event testing.
1817 * There are certain circumstances where we want to skip pointer event
1818 * testing because we are simulating pointer events, and don't want to
1819 * simulate a pointer event from an impossible co-ordinate. We'd rather
1820 * just identify that there is no point in doing the test and skip over
1821 * to the next test case.
1823 * In particular, when a ROM configured with a digitiser is deployed on a
1824 * Naviengine, with hardware configuration DIP switches which say that there
1825 * is an external screen connected, then no touch pad is active.
1826 * The base port under these conditions returns a digitiser area (0,0,0,0)
1828 * @return ETrue if the configuration supports pointer event testing, otherwise
1831 TBool CTestBase::ConfigurationSupportsPointerEventTesting() const
1833 if (iNormalPointerCursorArea.IsEmpty())
1841 void CTestBase::SimulatePointer(TRawEvent::TType aType, TInt aX, TInt aY)
1843 __ASSERT_DEBUG(ConfigurationSupportsPointerEventTesting(), AutoPanic(EAutoPanicNoDigitiser));
1846 #ifdef WSERV_TAUTO_LOG_POINTER_EVENTS
1847 TLogMessageText buf;
1848 _LIT(KLog,"SimulatePointer Type=%d Pos=(%d,%d)");
1849 buf.Format(KLog,aType,aX,aY);
1850 TheClient->LogMessage(buf);
1854 rawEvent.Set(aType,aX,aY);
1855 TheClient->iWs.SimulateRawEvent(rawEvent);
1858 void CTestBase::SimulateEvent(TRawEvent::TType aType)
1861 rawEvent.Set(aType);
1862 TheClient->iWs.SimulateRawEvent(rawEvent);
1865 void CTestBase::LogColors(const CBitmapDevice& aDevice,TPoint aBasePoint, TPoint aStartPoint, TPoint aEndPoint)
1867 _LIT(KPixel,"Pixel(%d,%d) R=%d G=%d B=%d");
1868 TLogMessageText buf;
1871 if (aStartPoint.iX==aEndPoint.iX)
1873 if (aStartPoint.iY==aEndPoint.iY)
1875 TInt width=aEndPoint.iX-aStartPoint.iX;
1877 for (yy=aStartPoint.iY;yy<aEndPoint.iY;++yy)
1880 aDevice.GetScanLine(screen,aBasePoint+TPoint(xx,yy),width,ERgb);
1881 pixel=REINTERPRET_CAST(const TRgb*,screen.Ptr());
1882 for (;xx<aEndPoint.iX;++xx,++pixel)
1884 buf.Format(KPixel,xx,yy,pixel->Red(),pixel->Green(),pixel->Blue());
1885 //RDebug::Print(buf);
1886 TheClient->iWs.LogMessage(buf);
1889 TheClient->iWs.Flush();
1892 void CTestBase::LogColors4(const CBitmapDevice& aDevice,TPoint aStartPoint,TInt aLen)
1894 _LIT(KValue,"Pixel(%d,%d) Byte %d, Value %d");
1895 TLogMessageText buf;
1897 aDevice.GetScanLine(screen,aStartPoint,aLen,EGray4);
1898 TInt len=(aLen+3)/4;
1900 for (ii=0;ii<len;++ii,aStartPoint.iX+=4)
1902 buf.Format(KValue,aStartPoint.iX,aStartPoint.iY,ii,screen[ii]);
1903 TheClient->iWs.LogMessage(buf);
1907 void CTestBase::UpdateTestResults(TInt aNoOfTest, TInt aNoOfTestPass)
1909 iNumberTests+=aNoOfTest;
1910 iNumberTestsPass+=aNoOfTestPass;
1913 TInt CTestBase::SaveScreen(const TDesC& aFileName)
1915 return SaveScreen(aFileName,TheClient->iScreen->SizeInPixels(),TheClient->iScreen->DisplayMode());
1918 TInt CTestBase::SaveScreen(const TDesC& aFileName,const TSize& aScreenSize,TDisplayMode aColorDepth)
1920 TRAPD(err,SaveScreenL(aFileName,aScreenSize,aColorDepth));
1924 void CTestBase::SaveScreenL(const TDesC& aFileName,const TSize& aScreenSize,TDisplayMode aColorDepth)
1926 CBitmap* copyOfScreen=CBitmap::NewLC(aScreenSize,aColorDepth);
1927 CFbsScreenDevice* scrDevice=CFbsScreenDevice::NewL(iScreenNumber,aColorDepth);
1928 CleanupStack::PushL(scrDevice);
1930 User::LeaveIfError(scrDevice->CreateContext(gc));
1931 CleanupStack::PushL(gc);
1932 copyOfScreen->Gc().BitBlt(TPoint(),*gc);
1933 User::LeaveIfError(copyOfScreen->Bitmap().Save(aFileName));
1934 CleanupStack::PopAndDestroy(3,copyOfScreen);
1939 _LIT(KScreenTag,"Screen");
1941 void CProcess::GetProcArg(const TWinCommand& aParam,TBufArg& aProcArg)
1943 TInt pos = aParam.Find(KScreenTag);
1944 if (pos!=KErrNotFound)
1945 aProcArg = aParam.Left(pos-1);
1950 void CProcess::GetScreenArg(const TWinCommand& aParam, TInt& aScreenArg)
1952 TInt pos = aParam.Find(KScreenTag);
1953 if (pos!=KErrNotFound)
1955 TBufArg secondArg(aParam.Right(aParam.Length()-pos));
1956 if (secondArg.Length()>6)
1958 TBuf<1> digit(secondArg.Mid(6,1));
1960 lex.Val(aScreenArg);
1965 TInt CProcess::Start(const TWinCommand& aParam)
1967 // parse command line aParam to retrieve value of
1968 // screen number if it is specified
1970 // command line format: <process-id> [screen<id>]
1972 TBufArg procArg(_L(""));
1973 TInt screenArg = KDefaultScreen;
1975 GetProcArg(aParam, procArg);
1976 GetScreenArg(aParam, screenArg);
1979 for(ii=0;ii<eNumProcessCalls;ii++)
1981 if (procArg==iFunctions[ii].iParam)
1983 TRAPD(ret,iFunctions[ii].iFunction((TAny*)screenArg));
1985 // need to pass test result to owning process
1986 // for multiple display test
1987 if (ii==eProcessMultiDisplayTest)
1988 ret = TheTestResult;
1994 return KErrNone; //Shouldn't get here
1997 CProcess* CProcess::NewL(TInt aFunctionNo,TInt aScreenNumber)
1999 CProcess* self=new(ELeave) CProcess();
2000 CleanupStack::PushL(self);
2001 self->ConstructL(aFunctionNo,aScreenNumber);
2002 CleanupStack::Pop(self);
2006 CProcess* CProcess::NewTL(TInt aFunctionNo,TInt aScreenNumber,TRequestStatus* aStatus /*=NULL*/)
2008 CProcess* self=new(ELeave) CProcess();
2009 CleanupStack::PushL(self);
2010 self->ConstructTL(aFunctionNo,aScreenNumber,aStatus);
2011 CleanupStack::Pop(self);
2015 CProcess* CProcess::NewThreadL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr
2016 ,TRequestStatus* aStatus)
2018 CProcess* self=new(ELeave) CProcess();
2019 CleanupStack::PushL(self);
2020 self->ConstructL(aName,aFunction,aPtr,aStatus);
2021 CleanupStack::Pop(self);
2025 CProcess* CProcess::NewThreadRendezvousL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr ,TRequestStatus* aLogonStatus,TRequestStatus& aRendesvouzStatus)
2027 CProcess* self=new(ELeave) CProcess();
2028 CleanupStack::PushL(self);
2029 self->ConstructRendezvousL(aName,aFunction,aPtr,aLogonStatus,aRendesvouzStatus);
2030 CleanupStack::Pop(self);
2034 CProcess* CProcess::NewThreadRendezvousL(const TDesC& aName,TThreadStartUp* aPtr,TRequestStatus& aRendesvouzStatus)
2036 return NewThreadRendezvousL(aName,ThreadInit,aPtr,NULL,aRendesvouzStatus);
2039 CProcess* CProcess::NewThreadL(const TDesC& aName,TThreadStartUp* aPtr)
2041 return NewThreadL(aName,ThreadInit,aPtr,NULL);
2044 CProcess* CProcess::NewSimpleThreadL(const TDesC& aName,TThreadStartUp* aPtr,TRequestStatus* aStatus/*=NULL*/)
2046 return NewThreadL(aName,SimpleThreadInit,aPtr,aStatus);
2050 _LIT(KScreenFormat,"%d");
2052 void CProcess::ConstructL(TInt aFunctionNo,TInt aScreenNumber/*=KDefaultScreen*/)
2055 // add screen number into command line param
2056 // format: <proc-id> [screen<id>]
2058 TBuf<100> commandLine;
2060 commandLine = iFunctions[aFunctionNo].iParam;
2061 commandLine.Append(KSpace);
2062 commandLine.Append(KScreenTag);
2063 commandLine.AppendFormat(KScreenFormat,aScreenNumber);
2064 User::LeaveIfError(iOther.Create(RProcess().FileName(),commandLine));
2065 iCreated|=eOtherCreated;
2069 void CProcess::ConstructTL(TInt aFunctionNo,TInt aScreenNumber/*=KDefaultScreen*/,TRequestStatus* aStatus)
2072 TUint flag=eThreadCreated;
2073 TInt err=iThread.Create(iFunctions[aFunctionNo].iParam,iFunctions[aFunctionNo].iFunction
2074 ,KDefaultStackSize,KOtherProcHeapSize,KOtherProcHeapSize,(TAny*)aScreenNumber,EOwnerThread);
2075 User::LeaveIfError(err);
2083 void CProcess::ConstructL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr,TRequestStatus* aStatus)
2086 User::LeaveIfError(iThread.Create(aName,aFunction,KDefaultStackSize,KOtherProcHeapSize,KOtherProcHeapSize,aPtr,EOwnerThread));
2087 iCreated|=eThreadCreated;
2093 void CProcess::ConstructRendezvousL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr,TRequestStatus* aLogonStatus,TRequestStatus& aRendezvousStatus)
2096 User::LeaveIfError(iThread.Create(aName,aFunction,KDefaultStackSize,KOtherProcHeapSize,KOtherProcHeapSize,aPtr,EOwnerThread));
2097 iCreated|=eThreadCreated;
2099 Logon(*aLogonStatus);
2101 iThread.Rendezvous(aRendezvousStatus);
2105 void CProcess::Logon(TRequestStatus& aStatus) const
2107 if (iCreated&eThreadCreated)
2108 iThread.Logon(aStatus);
2111 iOther.Logon(aStatus);
2115 void CProcess::Terminate(TInt aReason)
2117 if (iCreated&eThreadCreated)
2118 iThread.Terminate(aReason);
2121 iOther.Terminate(aReason);
2126 void CProcess::Close()
2128 if (iCreated&eOtherCreated)
2130 if (iCreated&eThreadCreated)
2135 CProcess::~CProcess()
2140 TBool CProcess::StillAlive()
2142 if (iCreated&eOtherCreated)
2143 return iOther.ExitType()==EExitPending;
2144 return iThread.ExitType()==EExitPending;
2147 void CProcess::LeaveIfDied() //Can Leave
2149 User::After(200000); //0.2 secs
2152 if (iCreated&eOtherCreated)
2153 User::Leave(iOther.ExitReason());
2154 User::Leave(iThread.ExitReason());
2157 const TInt KFirstInstanceId = 1;
2158 const TInt KOtherInstanceId = 2;
2160 TBool CProcess::ProcessDied(TInt aScreenNo/*=KDefaultScreen*/)
2162 _LIT(pName,"TAutoServer*");
2163 TFindProcess find(pName);
2166 TBool found = EFalse;
2167 TInt instanceId = aScreenNo==KDefaultScreen? KFirstInstanceId : KOtherInstanceId;
2168 // find the correct instance of the process
2169 // required in multi display test
2170 while (!found && find.Next(name)==KErrNone)
2172 TPtrC scrId = name.Right(1);
2184 if (p.Id()!=RProcess().Id())
2187 return (find.Next(name)!=KErrNone);
2190 TInt CProcess::ThreadInit(TAny *aPtr)
2194 CTrapCleanup* CleanUpStack=CTrapCleanup::New();
2195 if (CleanUpStack==NULL)
2199 TRAP(err,InitialiseL(STATIC_CAST(TThreadStartUp*,aPtr)))
2200 delete CleanUpStack;
2206 void CProcess::InitialiseL(TThreadStartUp* aPtr)
2208 CActiveScheduler* activeScheduler=new(ELeave) CActiveScheduler;
2209 CActiveScheduler::Install(activeScheduler);
2210 CleanupStack::PushL(activeScheduler);
2211 aPtr->iInitFunction(aPtr->iParam);
2212 CActiveScheduler::Start();
2213 CleanupStack::PopAndDestroy(activeScheduler);
2216 TInt CProcess::SimpleThreadInit(TAny *aPtr)
2220 CTrapCleanup* CleanUpStack=CTrapCleanup::New();
2221 if (CleanUpStack==NULL)
2225 TThreadStartUp* ptr=STATIC_CAST(TThreadStartUp*,aPtr);
2226 ptr->iInitFunction(ptr->iParam);
2227 delete CleanUpStack;
2235 CMinWin::CMinWin(TInt aScreenNo): iScreenNo(aScreenNo)
2238 void CMinWin::ConstructL()
2240 User::LeaveIfError(iWs.Connect());
2241 iScr=new(ELeave) CWsScreenDevice(iWs);
2242 User::LeaveIfError(iScr->Construct(iScreenNo));
2243 iGroup=RWindowGroup(iWs);
2244 User::LeaveIfError(iGroup.Construct(8970+iScreenNo,ETrue));
2246 User::LeaveIfError(iWin.Construct((RWindowTreeNode)iGroup,(TUint32)this));
2248 iWin.SetExtent(TPoint(0,0),iRect.Size());
2249 iWin.SetRequiredDisplayMode(EColor256);
2250 iWin.SetBackgroundColor(KRgbGreen);
2252 iGc=new(ELeave) CWindowGc(iScr);
2253 User::LeaveIfError(iGc->Construct());
2268 void CMinWin::Draw(const TRect& aRect)
2271 iGc->Activate(iWin);
2272 iGc->SetPenStyle(CGraphicsContext::ENullPen);
2273 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
2274 iGc->SetBrushColor(KRgbGreen);
2275 iGc->DrawRect(aRect);
2283 void CTimeOut::ConstructL()
2285 CTimer::ConstructL();
2286 CActiveScheduler::Add(this);
2289 void CTimeOut::Start(TTimeIntervalMicroSeconds32 aInterval,TCallBack aCallBack)
2291 iCallBack=aCallBack;
2295 void CTimeOut::RunL()
2297 iCallBack.CallBack();
2301 * Simply returns the DisplayMode as a string. Used to display mode details on test results.
2303 GLDEF_C TPtrC DisplayModeAsString(TDisplayMode aMode)
2311 _LIT(KENoneMode,"ENone");
2312 modeAsString.Set(KENoneMode);
2315 _LIT(KEGray2Mode,"EGray2");
2316 modeAsString.Set(KEGray2Mode);
2319 _LIT(KEGray4Mode,"EGray4");
2320 modeAsString.Set(KEGray4Mode);
2323 _LIT(KEGray16Mode,"EGray16");
2324 modeAsString.Set(KEGray16Mode);
2327 _LIT(KEGray256Mode,"EGray256");
2328 modeAsString.Set(KEGray256Mode);
2331 _LIT(KEColor16Mode,"EColor16");
2332 modeAsString.Set(KEColor16Mode);
2335 _LIT(KEColor256Mode,"EColor256");
2336 modeAsString.Set(KEColor256Mode);
2339 _LIT(KEColor64KMode,"EColor64K");
2340 modeAsString.Set(KEColor64KMode);
2343 _LIT(KEColor16MMode,"EColor16M");
2344 modeAsString.Set(KEColor16MMode);
2347 _LIT(KEColor4KMode,"EColor4K");
2348 modeAsString.Set(KEColor4KMode);
2351 _LIT(KEColor16MUMode,"EColor16MU");
2352 modeAsString.Set(KEColor16MUMode);
2355 _LIT(KEColor16MAMode,"EColor16MA");
2356 modeAsString.Set(KEColor16MAMode);
2359 _LIT(KEColor16MAPMode,"EColor16MAP");
2360 modeAsString.Set(KEColor16MAPMode);
2363 _LIT(KUnknownMode,"Unknown");
2364 modeAsString.Set(KUnknownMode);
2368 return modeAsString;
2371 // Check if an area of a bitmap is of a certain color
2372 GLDEF_C TBool LossyCheckBlankBitmap(const CFbsBitmap& aBitmap, const TRect aArea, const TRgb aCheckColor, TBool aLossyCompare)
2374 const TReal errorLimit = (aLossyCompare ? 0.05 : 0.00); //Lossy(default) or exact compare?
2376 TBool result = ETrue;
2377 /* TInt mismatchedPixels = 0; */ // -- Useful for debugging
2378 TRgb bitmapPix = TRgb(0,0,0,0); //testWin Pixel
2379 for (TInt x = 0; x < aArea.Size().iWidth; x++)
2381 for (TInt y = 0; y < aArea.Size().iHeight; y++)
2383 aBitmap.GetPixel(bitmapPix, TPoint(x,y));
2385 //Check if there are differeces in color between the bitmap and the test color
2386 if(((TReal)abs(bitmapPix.Red() - aCheckColor.Red())/255) > errorLimit ||
2387 ((TReal)abs(bitmapPix.Blue() - aCheckColor.Blue())/255) > errorLimit ||
2388 ((TReal)abs(bitmapPix.Green() - aCheckColor.Green())/255) > errorLimit ||
2389 ((TReal)abs(bitmapPix.Alpha() - aCheckColor.Alpha())/255) > errorLimit)
2391 /* mismatchedPixels++; */ // -- Useful for debugging
2398 /* INFO_PRINTF2(_L("Number of different pixels: %i"), mismatchedPixels); */ // -- Useful for debugging
2402 // Compare a section of two bitmaps
2403 GLDEF_C TBool LossyCompareBitmap(const CFbsBitmap& aBitmap1, const CFbsBitmap& aBitmap2, const TRect aCompareRect, TBool aLossyCompare)
2405 const TReal errorLimit = (aLossyCompare ? 0.05 : 0.00); //Lossy or Exact compare?
2407 TBool result = ETrue;
2409 if (aBitmap1.DisplayMode() != aBitmap2.DisplayMode())
2411 RDebug::Printf(" DisplayMode difference %d, %d", aBitmap1.DisplayMode(), aBitmap2.DisplayMode());
2414 TRgb bitmap1Pix = TRgb(0,0,0,0);
2415 TRgb bitmap2Pix = TRgb(0,0,0,0);
2416 for (TInt x = 0; x < aCompareRect.Size().iWidth; x++)
2418 for (TInt y = 0; y < aCompareRect.Size().iHeight; y++)
2420 aBitmap1.GetPixel(bitmap1Pix, TPoint(x,y));
2421 aBitmap2.GetPixel(bitmap2Pix, TPoint(x,y));
2423 //Check if there are differences between the colors of the two bitmaps
2424 if(((TReal)abs(bitmap1Pix.Red() - bitmap2Pix.Red())/255) > errorLimit ||
2425 ((TReal)abs(bitmap1Pix.Blue() - bitmap2Pix.Blue())/255) > errorLimit ||
2426 ((TReal)abs(bitmap1Pix.Green() - bitmap2Pix.Green())/255) > errorLimit ||
2427 ((TReal)abs(bitmap1Pix.Alpha() - bitmap2Pix.Alpha())/255) > errorLimit)
2430 * There was a difference so return without checking the rest of the
2431 * bitmap. If you are seeing Lossy compare errors, and want to diagnose
2432 * further, consider switching over to using a recording version of this
2433 * function, LossyCompareBitmapRecord()
2445 * Compare two bitmaps, optionally a lossy comparison, recording any differences and saving bitmaps
2447 * @param aBitmap1 Bitmap being checked
2448 * @param aBitmap2 Reference Bitmap
2449 * @param aCompareRect Area of bitmap to compare
2450 * @param aLossyCompare ETrue means use a lossy compare strategy, else do an exact compare
2451 * @param aPixelsDifferent Returned value representing the number of pixels which are different
2452 * @param aLogger Facility for logging to be reported by this function
2453 * @return ETrue if the bitmaps are the same (or similar).
2454 * Otherwise EFalse, with logging reporting the differences, and bitmaps saved in c:\logs\
2455 * @pre c:\logs directory must exist
2457 GLDEF_C TBool LossyCompareBitmapRecord(CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2, const TRect aCompareRect, TBool aLossyCompare, TInt& aPixelsDifferent, CTestExecuteLogger& aLogger)
2459 const TReal errorLimit = (aLossyCompare ? 0.05 : 0.00); //Lossy or Exact compare?
2461 TBool result = ETrue;
2462 TInt mismatchedPixels = 0;
2463 TRgb bitmap1Pix = TRgb(0,0,0,0);
2464 TRgb bitmap2Pix = TRgb(0,0,0,0);
2465 if (aBitmap1.DisplayMode() != aBitmap2.DisplayMode())
2467 aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
2468 _L(" DisplayMode difference %d, %d"), aBitmap1.DisplayMode(), aBitmap2.DisplayMode());
2470 for (TInt x = 0; x < aCompareRect.Size().iWidth; x++)
2472 for (TInt y = 0; y < aCompareRect.Size().iHeight; y++)
2474 aBitmap1.GetPixel(bitmap1Pix, TPoint(x,y));
2475 aBitmap2.GetPixel(bitmap2Pix, TPoint(x,y));
2477 //Check if there are differences between the colors of the two bitmaps
2478 if(((TReal)abs(bitmap1Pix.Red() - bitmap2Pix.Red())/255) > errorLimit ||
2479 ((TReal)abs(bitmap1Pix.Blue() - bitmap2Pix.Blue())/255) > errorLimit ||
2480 ((TReal)abs(bitmap1Pix.Green() - bitmap2Pix.Green())/255) > errorLimit ||
2481 ((TReal)abs(bitmap1Pix.Alpha() - bitmap2Pix.Alpha())/255) > errorLimit)
2485 aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
2486 _L(" Pixel difference %d,%d: %d"),x,y, bitmap1Pix.Difference(bitmap2Pix));
2488 // we loop around again to pick up all the differences
2492 aPixelsDifferent = mismatchedPixels;
2495 * When the bitmaps are different, we store them locally in c:\\logs in
2496 * timestamped files. Save() is a non-const method; this is why aBitmap1
2497 * and aBitmap2 are non-const. Saving can fail, perhaps because we have
2498 * exceeded storage limits.
2503 now.UniversalTime();
2504 TInt timestamp = I64INT(now.Int64() & 0x7fffffffu);
2505 timestamp/=1000; // a millisecond resolution is easier to track
2506 TFileName mbmFileSrc;
2507 mbmFileSrc.Format (_L("c:\\logs\\%d_LossyCompareBitmap1.mbm"), timestamp);
2508 TFileName mbmFileDst;
2509 mbmFileDst.Format (_L("c:\\logs\\%d_LossyCompareBitmap2.mbm"), timestamp);
2512 saveResult1 = aBitmap1.Save(mbmFileSrc);
2513 saveResult2 = aBitmap2.Save(mbmFileDst);
2514 if (saveResult1 == KErrNone && saveResult2 == KErrNone)
2516 aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
2517 _L(" Bitmaps are different: see %S, %S"), &mbmFileSrc, &mbmFileDst);
2521 aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
2522 _L(" Bitmaps are different, but could not save files into c:\\logs : %d %d"), saveResult1, saveResult2);
2529 // Check if an area of a screen is of a certain color
2530 GLDEF_C TBool LossyCheckBlankWindow(const CWsScreenDevice& aScreen, CFbsBitmap& aBitmap, const TRect aArea, const TRgb aCheckColor)
2532 aScreen.CopyScreenToBitmap(&aBitmap, aArea);
2533 return LossyCheckBlankBitmap(aBitmap, aArea, aCheckColor);
2536 // Compare a section of two windows on the screen
2537 GLDEF_C TBool LossyCompareWindow(const CWsScreenDevice& aScreen, CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2, const TRect aCompareRect)
2539 aScreen.CopyScreenToBitmap(&aBitmap1, aCompareRect);
2540 aScreen.CopyScreenToBitmap(&aBitmap2, aCompareRect);
2541 return LossyCompareBitmap(aBitmap1, aBitmap2, aCompareRect);