os/graphics/windowing/windowserver/test/tauto/AUTO.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/AUTO.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2543 @@
     1.4 +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// Automatically test the window server
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +
    1.22 +#include <e32std.h>
    1.23 +#include <w32std.h>
    1.24 +#include <e32svr.h>
    1.25 +#include <hal.h>
    1.26 +#include "../tlib/testbase.h"
    1.27 +#include <stdlib.h>
    1.28 +#include "AUTO.H"
    1.29 +
    1.30 +LOCAL_D const TUint KPanicThreadHeapSize=0x8000;
    1.31 +
    1.32 +GLREF_C TInt ProcPriTestOtherProcess(TAny *aScreenNumber);
    1.33 +GLREF_C TInt ProcToKill(TAny *aScreenNumber);
    1.34 +GLREF_C TInt ProcDirect(TAny *aScreenNumber);
    1.35 +GLREF_C TInt ProcMultiDisplay(TAny *aScreenNumber);
    1.36 +
    1.37 +_LIT(Priority,"ProcPriTest");
    1.38 +_LIT(ToKill,"ProcToKill");
    1.39 +_LIT(Direct,"ProcDirect");
    1.40 +_LIT(MultiDisplay,"ProcMultiDisplay");
    1.41 +
    1.42 +CProcess::TInitialFunction CProcess::iFunctions[]=
    1.43 +	{
    1.44 +	TInitialFunction(Priority,ProcPriTestOtherProcess),
    1.45 +	TInitialFunction(ToKill,ProcToKill),
    1.46 +	TInitialFunction(Direct,ProcDirect),
    1.47 +	TInitialFunction(MultiDisplay,ProcMultiDisplay)
    1.48 +	};
    1.49 +
    1.50 +GLDEF_D TestWindow *BaseWin;
    1.51 +GLDEF_D TestWindow *TestWin;
    1.52 +GLDEF_D TestClient *TheClient=NULL;
    1.53 +GLDEF_D CWindowGc *TheGc;
    1.54 +TInt CTestBase::iMaxGrays=0;
    1.55 +TInt CTestBase::iScreenNo=0;
    1.56 +TInt CTestBase::iMaxColors=0;
    1.57 +TInt CTestBase::iNumberTestsPass=0;
    1.58 +TInt CTestBase::iNumberTests=0;
    1.59 +TRect CTestBase::iNormalPointerCursorArea;
    1.60 +TPartialRedrawType CTestBase::iRedrawType=EPartialRedraw_Unknown;
    1.61 +TInt CTestBase::iNumberOfGrpWndsOnPrimaryScreenWithZeroPriority = 0;
    1.62 +TInt CTestDriver::iTestNum=0;
    1.63 +
    1.64 +GLDEF_D TInt TheTestResult=ETestPassed; // start with passed to anticipate empty test table
    1.65 +
    1.66 +const TInt KBorderWinWidth = 5;
    1.67 +
    1.68 +_LIT(Auto,"AUTO ");
    1.69 +
    1.70 +TInt64 TTestRects::iSeed=0;
    1.71 +TRect TTestRects::iList[]={
    1.72 +// 0-5
    1.73 +	TRect(2,2,2,2),
    1.74 +	TRect(2,2,2,2),
    1.75 +	TRect(2,2,2,2),
    1.76 +	TRect(2,2,2,2),
    1.77 +	TRect(2,2,2,2),
    1.78 +// 5-13
    1.79 +	TRect(0,0,0,0),
    1.80 +	TRect(2,0,2,0),
    1.81 +	TRect(4,0,4,0),
    1.82 +	TRect(0,2,0,2),
    1.83 +	TRect(2,2,2,2),
    1.84 +	TRect(4,2,4,2),
    1.85 +	TRect(0,4,0,4),
    1.86 +	TRect(2,4,2,4),
    1.87 +	TRect(4,4,4,4),
    1.88 +// 13-22
    1.89 +	TRect(0,0,1,1),
    1.90 +	TRect(1,0,3,1),
    1.91 +	TRect(3,0,4,1),
    1.92 +	TRect(0,1,1,3),
    1.93 +	TRect(1,1,3,3),
    1.94 +	TRect(3,1,4,3),
    1.95 +	TRect(0,3,1,4),
    1.96 +	TRect(1,3,3,4),
    1.97 +	TRect(3,3,4,4),
    1.98 +// 23-31
    1.99 +	TRect(0,0,2,0),
   1.100 +	TRect(2,0,4,0),
   1.101 +	TRect(0,0,4,0),
   1.102 +	TRect(0,2,2,2),
   1.103 +	TRect(2,2,4,2),
   1.104 +	TRect(0,2,4,2),
   1.105 +	TRect(0,4,2,4),
   1.106 +	TRect(2,4,4,4),
   1.107 +	TRect(0,4,4,4),
   1.108 +// 32-40
   1.109 +	TRect(0,0,0,2),
   1.110 +	TRect(0,2,0,4),
   1.111 +	TRect(0,0,0,4),
   1.112 +	TRect(2,0,2,2),
   1.113 +	TRect(2,2,2,4),
   1.114 +	TRect(2,0,2,4),
   1.115 +	TRect(4,0,4,2),
   1.116 +	TRect(4,2,4,4),
   1.117 +	TRect(4,0,4,4),
   1.118 +// 41-44
   1.119 +	TRect(0,0,2,2),
   1.120 +	TRect(2,0,4,2),
   1.121 +	TRect(0,2,2,4),
   1.122 +	TRect(2,2,4,4),
   1.123 +// 45-48
   1.124 +	TRect(0,0,3,3),
   1.125 +	TRect(1,0,4,3),
   1.126 +	TRect(0,1,3,4),
   1.127 +	TRect(1,1,4,4),
   1.128 +// 49
   1.129 +	TRect(0,0,4,4),
   1.130 +// 40-53
   1.131 +	TRect(1,2,2,2),
   1.132 +	TRect(2,2,3,2),
   1.133 +	TRect(2,1,2,2),
   1.134 +	TRect(2,2,3,2),
   1.135 +// 54-59
   1.136 +	TRect(1,2,3,2),
   1.137 +	TRect(2,1,2,3),
   1.138 +	TRect(1,1,2,2),
   1.139 +	TRect(1,2,2,3),
   1.140 +	TRect(2,2,3,3),
   1.141 +	TRect(2,1,3,2),
   1.142 +// 60-63
   1.143 +	TRect(1,1,3,2),
   1.144 +	TRect(1,1,2,3),
   1.145 +	TRect(1,2,3,3),
   1.146 +	TRect(2,1,3,3)};
   1.147 +
   1.148 +#if defined(__WINS__)
   1.149 +void FindNonMatchingPixelL(TPoint aPt1,TPoint aPt2,TSize aSize)
   1.150 +// This function is purely for use when debugging to find the first non-matching pixel
   1.151 +// when a check of two on screen rects has failed.
   1.152 +	{
   1.153 +	HBufC8* buf1=HBufC8::NewMaxLC(2*aSize.iWidth);
   1.154 +	HBufC8* buf2=HBufC8::NewMaxLC(2*aSize.iWidth);
   1.155 +	TPtr8 ptr1=buf1->Des();
   1.156 +	TPtr8 ptr2=buf2->Des();
   1.157 +	TInt row=0;
   1.158 +	TBool ret = true;
   1.159 +	for (;row<aSize.iHeight;++row)
   1.160 +		{
   1.161 +		TheClient->iScreen->GetScanLine(ptr1,aPt1,aSize.iWidth,EColor64K);
   1.162 +		TheClient->iScreen->GetScanLine(ptr2,aPt2,aSize.iWidth,EColor64K);
   1.163 +		if (ptr1!=ptr2)
   1.164 +			break;
   1.165 +		++aPt1.iY;
   1.166 +		++aPt2.iY;
   1.167 +		}
   1.168 +	TRgb color1,color2;
   1.169 +	if (row<aSize.iHeight)
   1.170 +		{
   1.171 +		for (TInt col=0;col<aSize.iWidth;++col)
   1.172 +			{
   1.173 +			TheClient->iScreen->GetPixel(color1,aPt1);
   1.174 +			TheClient->iScreen->GetPixel(color2,aPt2);
   1.175 +			if (color1!=color2)
   1.176 +				{	// Break here to find first pixel that didn't match.
   1.177 +				TBuf<256> buf;
   1.178 +				_LIT(KFindNonMatchingPixelFmt,"First non matching pixel (%d,%d)");
   1.179 +				buf.Format(KFindNonMatchingPixelFmt,col,row);
   1.180 +				TheClient->iWs.LogMessage(buf);
   1.181 +				break;
   1.182 +				
   1.183 +				}
   1.184 +			++aPt1.iX;
   1.185 +			++aPt2.iX;
   1.186 +			}
   1.187 +		}
   1.188 +	CleanupStack::PopAndDestroy(2);
   1.189 +	}
   1.190 +
   1.191 +void FindNonMatchingPixel(TPoint aPt1,TPoint aPt2,TSize aSize)
   1.192 +	{
   1.193 +	TRAPD(ignore,FindNonMatchingPixelL(aPt1,aPt2,aSize));
   1.194 +	}
   1.195 +#endif
   1.196 +
   1.197 +void AutoPanic(TInt aPanic)
   1.198 +	{
   1.199 +	User::Panic(_L("Auto"),aPanic);
   1.200 +	}
   1.201 +
   1.202 +void CleanUpWindow(TAny *aWindow)
   1.203 +	{
   1.204 +	((RWindowTreeNode  *)aWindow)->Close();
   1.205 +	}
   1.206 +
   1.207 +void PushWindowL(RWindowTreeNode *aWindow)
   1.208 +	{
   1.209 +	CleanupStack::PushL(TCleanupItem(CleanUpWindow,aWindow));
   1.210 +	}
   1.211 +
   1.212 +
   1.213 +TBool OpacityAndAlphaSupportedL()
   1.214 +	{
   1.215 +	// If opacity is not implemented, EFalse will be returned
   1.216 +	if(TransparencySupportedL()!=KErrNone)
   1.217 +		return EFalse;
   1.218 +
   1.219 +	const TRgb KTransparencyColor(0,0,0);
   1.220 +	RWindow winb(TheClient->iWs);
   1.221 +	CleanupClosePushL(winb);
   1.222 +	RWindow wint(TheClient->iWs);
   1.223 +	CleanupClosePushL(wint);
   1.224 +	User::LeaveIfError(winb.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
   1.225 +	User::LeaveIfError(wint.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
   1.226 +	winb.SetExtent(TPoint(0,0), TSize(50,50));
   1.227 +	wint.SetExtent(TPoint(0,0), TSize(50,50));
   1.228 +	winb.SetRequiredDisplayMode(EColor256);
   1.229 +	wint.SetRequiredDisplayMode(EColor256);
   1.230 +	wint.SetTransparencyFactor(KTransparencyColor);
   1.231 +	winb.SetBackgroundColor(TRgb(0,0,255));
   1.232 +	wint.SetBackgroundColor(TRgb(255,0,0));
   1.233 +	winb.Activate();
   1.234 +	wint.Activate();
   1.235 +
   1.236 +	wint.BeginRedraw();
   1.237 +	TheClient->iGc->Activate(wint);
   1.238 +	TheClient->iGc->SetOpaque(ETrue);
   1.239 +	TheClient->iGc->SetPenStyle(CGraphicsContext::ENullPen);
   1.240 +	TheClient->iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.241 +	TheClient->iGc->SetBrushColor(TRgb(0,255,0));
   1.242 +	TheClient->iGc->DrawRect(TRect(TPoint(0,0), TSize(50,50)));
   1.243 +	TheClient->iGc->SetOpaque(EFalse);
   1.244 +	TheClient->iGc->Deactivate();
   1.245 +	wint.EndRedraw();
   1.246 +	TheClient->Flush();
   1.247 +
   1.248 +	// The window should be all green, if opacity is working, or all blue if it isn't.
   1.249 +	// If the window has any other colour, then something has broken.
   1.250 +	TRgb color;
   1.251 +	TheClient->iScreen->GetPixel(color,TPoint(25,25));
   1.252 +	if (color.Red()>0 || ((color.Green()==0) == (color.Blue()==0)))
   1.253 +		User::Leave(KErrGeneral);
   1.254 +	TBool ret=(color.Green()>0);
   1.255 +
   1.256 +	CleanupStack::PopAndDestroy(2,&winb); // wint
   1.257 +	return ret;
   1.258 +	}
   1.259 +
   1.260 +TInt TransparencySupportedL()
   1.261 +	{
   1.262 +	// Creates a window and enables alpha transparency, if this feature
   1.263 +	// is not enabled, KErrNotSupported will be returned
   1.264 +	RWindow win(TheClient->iWs);
   1.265 +	User::LeaveIfError(win.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
   1.266 +	win.SetExtent(TPoint(0,0), TSize(50,50));
   1.267 +	TInt ret=win.SetTransparencyAlphaChannel();
   1.268 +	win.Close();
   1.269 +	return ret;
   1.270 +	}
   1.271 +
   1.272 +TInt CheckScalingSupportedOrNot()
   1.273 +	{
   1.274 +	TBool scalingSupported=EFalse;
   1.275 +	TSizeMode originalModeData=TheClient->iScreen->GetCurrentScreenModeAttributes();
   1.276 +	TSizeMode tempData=originalModeData;
   1.277 +	tempData.iScreenScale=TSize(2,2);
   1.278 +	TheClient->iScreen->SetCurrentScreenModeAttributes(tempData);
   1.279 +	TSize scale=TheClient->iScreen->GetCurrentScreenModeScale();
   1.280 +	if (scale.iWidth==2 && scale.iHeight==2)
   1.281 +		{
   1.282 +		scalingSupported=ETrue;
   1.283 +		}
   1.284 +	TheClient->iScreen->SetCurrentScreenModeAttributes(originalModeData);
   1.285 +	TheClient->Flush();
   1.286 +	return scalingSupported;
   1.287 +	}
   1.288 +
   1.289 +TBool CheckNonZeroOriginsSupportedOrNot()
   1.290 +	{
   1.291 +	TBool nonZeroOriginsSupported=EFalse;
   1.292 +	TSizeMode sizeMode1=TheClient->iScreen->GetCurrentScreenModeAttributes();
   1.293 +	TSizeMode sizeMode2=sizeMode1;
   1.294 +	sizeMode2.iOrigin=TPoint(30,30);
   1.295 +	TheClient->iScreen->SetCurrentScreenModeAttributes(sizeMode2);
   1.296 +	TPoint origin=TheClient->iScreen->GetCurrentScreenModeScaledOrigin();
   1.297 +	if (origin.iX==30 && origin.iY==30)
   1.298 +		{
   1.299 +		nonZeroOriginsSupported=ETrue;
   1.300 +		}
   1.301 +	TheClient->iScreen->SetCurrentScreenModeAttributes(sizeMode1);
   1.302 +	TheClient->Flush();
   1.303 +	return nonZeroOriginsSupported;
   1.304 +	}
   1.305 +
   1.306 +TPoint PhysicalToLogical(TPoint aPhysicalPtMinusOrigin,TSize aScale)
   1.307 +	{
   1.308 +	TPoint logicalPt(aPhysicalPtMinusOrigin);
   1.309 +	if (aScale.iWidth!=1)
   1.310 +		{
   1.311 +		logicalPt.iX=(logicalPt.iX>= 0 ? logicalPt.iX/aScale.iWidth : (logicalPt.iX-(aScale.iWidth-1))/aScale.iWidth);
   1.312 +		}
   1.313 +	if (aScale.iHeight!=1)
   1.314 +		{
   1.315 +		logicalPt.iY=(logicalPt.iY>= 0 ? logicalPt.iY/aScale.iHeight : (logicalPt.iY-(aScale.iHeight-1))/aScale.iHeight);
   1.316 +		}
   1.317 +	return logicalPt;
   1.318 +	}
   1.319 +
   1.320 +//
   1.321 +// Log window, logs testing //
   1.322 +//
   1.323 +
   1.324 +LogWindow::LogWindow() : CTWin(), iTestTitle(KNullDesC), iSubTitle(KNullDesC), iMessage(KNullDesC)
   1.325 +	{}
   1.326 +
   1.327 +void LogWindow::ConstructL(CTWinBase &parent)
   1.328 +	{
   1.329 +	CTWin::ConstructL(parent);
   1.330 +	iTitleHeight=iFont->HeightInPixels()+4;
   1.331 +	}
   1.332 +
   1.333 +void LogWindow::DrawSubTitle()
   1.334 +	{
   1.335 +	iGc->DrawText(iSubTitle, TRect(2,iTitleHeight*2,iSize.iWidth-2,iTitleHeight*3),iFont->AscentInPixels(), CGraphicsContext::ECenter);
   1.336 +	}
   1.337 +
   1.338 +void LogWindow::DrawMessage()
   1.339 +	{
   1.340 +	iGc->DrawText(iMessage, TRect(1,iTitleHeight*4,iSize.iWidth-2,iTitleHeight*5),iFont->AscentInPixels(), CGraphicsContext::ECenter);
   1.341 +	}
   1.342 +
   1.343 +void LogWindow::Draw()
   1.344 +	{
   1.345 +	iGc->SetPenColor(TRgb::Gray16(8));
   1.346 +	iGc->SetPenColor(TRgb::Gray16(0));
   1.347 +	DrawBorder();
   1.348 +	iGc->DrawLine(TPoint(0,iTitleHeight),TPoint(iSize.iWidth,iTitleHeight));
   1.349 +	iGc->DrawText(iTestTitle, TPoint((iSize.iWidth-iFont->TextWidthInPixels(iTestTitle))/2,iFont->AscentInPixels()+2));
   1.350 +	DrawSubTitle();
   1.351 +	DrawMessage();
   1.352 +	}
   1.353 +
   1.354 +/**
   1.355 +This function is not used at the moment but I leave it in in case I need it when I improve the logging in 
   1.356 +the log window.
   1.357 +*/
   1.358 +void LogWindow::LogTest(const TDesC &aTitle,TInt aNum)
   1.359 +	{
   1.360 +	_LIT(Test,"Test %d,%S");
   1.361 +	iTestTitle.Format(Test,aNum,&aTitle);
   1.362 +	TLogMessageText buf;
   1.363 +	_LIT(AutoNewTest,"AUTO New Test: ");
   1.364 +	buf.Append(AutoNewTest);
   1.365 +	buf.Append(iTestTitle);
   1.366 +	TheClient->LogMessage(buf);
   1.367 +	iMessage.Zero();
   1.368 +	iWin.Invalidate();
   1.369 +	}
   1.370 +
   1.371 +/**
   1.372 +This function is not used at the moment but I leave it in in case I need it when I improve the logging in 
   1.373 +the log window.
   1.374 +*/
   1.375 +const TDesC& LogWindow::LogSubTest(const TDesC &aTitle,TInt aNum)
   1.376 +	{
   1.377 +	_LIT(SubTest,"Sub-Test[%d], %S");
   1.378 +	iSubTitle.Format(SubTest,aNum,&aTitle);
   1.379 +	TLogMessageText buf;
   1.380 +	buf.Append(Auto);
   1.381 +	buf.Append(iSubTitle);
   1.382 +	TheClient->LogMessage(buf);
   1.383 +	iMessage.Zero();
   1.384 +	iGc->Activate(iWin);
   1.385 +	iGc->UseFont((CFont *)iFont);
   1.386 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.387 +	DrawSubTitle();
   1.388 +	DrawMessage();
   1.389 +	iGc->Deactivate();
   1.390 +	TheClient->iWs.Flush();
   1.391 +	return iSubTitle;
   1.392 +	}
   1.393 +
   1.394 +const TDesC& LogWindow::LogMessage(TBool aLog,const TDesC& aText,TInt aNum)
   1.395 +	{
   1.396 +	if (aNum!=EDummyValue)
   1.397 +		{
   1.398 +		_LIT(StringInt,"%S %d");
   1.399 +		iMessage.Format(StringInt,&aText,aNum);
   1.400 +		}
   1.401 +	else
   1.402 +		{
   1.403 +		_LIT(String,"%S");
   1.404 +		iMessage.Format(String,&aText);
   1.405 +		}
   1.406 +	iGc->Activate(iWin);
   1.407 +	iGc->UseFont((CFont *)iFont);
   1.408 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.409 +	DrawMessage();
   1.410 +	iGc->Deactivate();
   1.411 +	if (aLog)
   1.412 +		{
   1.413 +		TLogMessageText buf;
   1.414 +		buf.Append(Auto);
   1.415 +		buf.Append(iMessage);
   1.416 +		TheClient->LogMessage(buf);
   1.417 +		}
   1.418 +	TheClient->iWs.Flush();
   1.419 +	return iMessage;
   1.420 +	}
   1.421 +
   1.422 +
   1.423 +//
   1.424 +// Test window, simple window used to do test graphics in //
   1.425 +//
   1.426 +TestWindow::TestWindow() : CTWin()
   1.427 +	{
   1.428 +	}
   1.429 +
   1.430 +TestWindow::~TestWindow()
   1.431 +	{
   1.432 +	delete iBorderWin;
   1.433 +	}
   1.434 +
   1.435 +void TestWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   1.436 +	{
   1.437 +	iBorderWin=new(ELeave) CBorderWindow();
   1.438 +	iBorderWin->SetUpL(pos,size,parent,aGc);
   1.439 +	TRAPD(err, CTWin::ConstructL(*iBorderWin));
   1.440 +	if (err==KErrNone)
   1.441 +		{
   1.442 +		SetExt(TPoint(2,2),TSize(size.iWidth-4,size.iHeight-4));
   1.443 +		if (err==KErrNone)
   1.444 +			{
   1.445 +			Activate();
   1.446 +			AssignGC(aGc);
   1.447 +			return;
   1.448 +			}
   1.449 +		}
   1.450 +	delete this;
   1.451 +	User::Leave(err);
   1.452 +	}
   1.453 +
   1.454 +void TestWindow::Draw()
   1.455 +	{
   1.456 +	iGc->Clear();
   1.457 +	}
   1.458 +
   1.459 +void TestWindow::ClearWin()
   1.460 +	{
   1.461 +	TheGc->Activate(*Win());
   1.462 +	TheGc->Clear();
   1.463 +	TheGc->Deactivate();
   1.464 +	}
   1.465 +	
   1.466 +void TestWindow::SetBorderExt(TPoint aPos, TSize aSize)
   1.467 +	{
   1.468 +	iBorderWin->SetExt(aPos, aSize);
   1.469 +	}
   1.470 +
   1.471 +CBorderWindow* TestWindow::GetBorderWin()
   1.472 +	{
   1.473 +	return iBorderWin;
   1.474 +	}
   1.475 +//
   1.476 +CBorderWindow::CBorderWindow() : CTWin()
   1.477 +	{
   1.478 +	}
   1.479 +
   1.480 +void CBorderWindow::ConstructL(CTWinBase &parent)
   1.481 +	{
   1.482 +	CTWin::ConstructL(parent);
   1.483 +	}
   1.484 +
   1.485 +void CBorderWindow::Draw()
   1.486 +	{
   1.487 +	iGc->SetBrushColor(TRgb::Gray16(0));
   1.488 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.489 +	iGc->SetPenStyle(CGraphicsContext::ENullPen);
   1.490 +	iGc->DrawRect(TRect(Size()));
   1.491 +	}
   1.492 +
   1.493 +//
   1.494 +
   1.495 +TestWindowGroup::TestWindowGroup(CTClient *aClient) : CTWindowGroup(aClient)
   1.496 +	{
   1.497 +	}
   1.498 +
   1.499 +void TestWindowGroup::BecomeOwning()
   1.500 +	{
   1.501 +	iGroupWin.DefaultOwningWindow();
   1.502 +	}
   1.503 +
   1.504 +void TestWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &aTime)
   1.505 +	{
   1.506 +	if (aKey.iModifiers&EModifierFunc)
   1.507 +		{
   1.508 +		switch(aKey.iCode)
   1.509 +			{
   1.510 +			case 'f':
   1.511 +				TheClient->Driver()->iTest->TriggerFail();
   1.512 +				break;
   1.513 +			}
   1.514 +		}
   1.515 +	else if (iCurWin)
   1.516 +		iCurWin->WinKeyL(aKey,aTime);
   1.517 +	}
   1.518 +
   1.519 +void TestWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &aTime)
   1.520 +	{
   1.521 +	if (iCurWin)
   1.522 +		iCurWin->KeyDownL(aKey,aTime);
   1.523 +	}
   1.524 +
   1.525 +void TestWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &aTime)
   1.526 +	{
   1.527 +	if (iCurWin)
   1.528 +		iCurWin->KeyUpL(aKey,aTime);
   1.529 +	}
   1.530 +
   1.531 +//
   1.532 +
   1.533 +TestClient::TestClient()
   1.534 +	{}
   1.535 +
   1.536 +void TestClient::ConstructL()
   1.537 +	{
   1.538 +	CTClient::ConstructL();
   1.539 +
   1.540 +	iGroup=new(ELeave) TestWindowGroup(this);
   1.541 +	iGroup->ConstructL();
   1.542 +
   1.543 +	iScreen->GetScreenSizeModeList(&iScreenModes);
   1.544 +	iScreen->SetScreenMode(iScreenModes[0]);
   1.545 +	TSize screenSize=iScreen->SizeInPixels();
   1.546 +
   1.547 +	TInt winWidth=(screenSize.iWidth/3)-10;
   1.548 +	TInt winHeight=screenSize.iHeight-10;
   1.549 +	iStdLogWindow=new(ELeave) LogWindow();
   1.550 +	iStdLogWindow->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.551 +	BaseWin=new(ELeave) TestWindow();
   1.552 +	BaseWin->SetUpL(TPoint(screenSize.iWidth/3+5,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.553 +	TestWin=new(ELeave) TestWindow();
   1.554 +	TestWin->SetUpL(TPoint(screenSize.iWidth/3*2+5,5),TSize(winWidth,winHeight),iGroup,*iGc);
   1.555 +
   1.556 +	iDriver = CTestDriver::CreateL(iScreenNumber); // virtual constructor
   1.557 +
   1.558 +	TheGc=new(ELeave) CWindowGc(iScreen);
   1.559 +	User::LeaveIfError(TheGc->Construct());
   1.560 +
   1.561 +	_LIT(KTestLog,"WSERV Auto Test Log");
   1.562 +	LogMessage(KTestLog());
   1.563 +	LogAvailableScreenModeL();
   1.564 +	
   1.565 +	//This class was designed to be created once and reused by all the tests, now it is created for each test,
   1.566 +	//this needs to be changed back so tests like the following are only done once.
   1.567 +	TestWsSetBufferSizeL();
   1.568 +	TestWsSetMaxBufferSizeL();
   1.569 +	}
   1.570 +	
   1.571 +inline CTestDriver* TestClient::Driver()
   1.572 +	{
   1.573 +	return iDriver;
   1.574 +	}
   1.575 +
   1.576 +TBool TestClient::WaitForEvent()
   1.577 +	{
   1.578 +	if (iEventHandler->iStatus!=KRequestPending)
   1.579 +		return ETrue;
   1.580 +	else if (iRedrawEventHandler->iStatus!=KRequestPending)
   1.581 +		return EFalse;
   1.582 +	User::WaitForRequest(iEventHandler->iStatus,iRedrawEventHandler->iStatus);
   1.583 +	TRequestStatus* status=&iEventHandler->iStatus;
   1.584 +	TBool ret=ETrue;
   1.585 +	if (iEventHandler->iStatus==KRequestPending)
   1.586 +		{
   1.587 +		status=&iRedrawEventHandler->iStatus;
   1.588 +		ret=EFalse;
   1.589 +		}
   1.590 +	TInt reason=status->Int();
   1.591 +	*status=KRequestPending;
   1.592 +	User::RequestComplete(status,reason);
   1.593 +	return ret;
   1.594 +	}
   1.595 +
   1.596 +TBool TestClient::IsEventWaiting()
   1.597 +	{
   1.598 +	return (iEventHandler->iStatus!=KRequestPending || iRedrawEventHandler->iStatus!=KRequestPending);
   1.599 +	}
   1.600 +
   1.601 +TestClient::~TestClient()
   1.602 +	{
   1.603 +	iScreenModes.Close();
   1.604 +	delete iDriver;
   1.605 +	delete TheGc;
   1.606 +	delete iStdLogWindow;
   1.607 +	delete BaseWin;
   1.608 +	delete TestWin;
   1.609 +	}
   1.610 +
   1.611 +void TestClient::LogAvailableScreenModeL()
   1.612 +	{
   1.613 +	_LIT(KColorModes,"Color Modes: ");
   1.614 +	_LIT(KComma,", ");
   1.615 +	_LIT(KColor,"Color");
   1.616 +	_LIT(KGrey,"Grey");
   1.617 +	CArrayFixFlat<TInt>* modeList=new(ELeave) CArrayFixFlat<TInt>(15);
   1.618 +	iWs.GetColorModeList(modeList);
   1.619 +	TLogMessageText buf,buf2;
   1.620 +	buf.Append(KColorModes);
   1.621 +	TDisplayMode mode;
   1.622 +	TInt ii=0;
   1.623 +	FOREVER
   1.624 +		{
   1.625 +		mode=STATIC_CAST(TDisplayMode,(*modeList)[ii]);
   1.626 +		buf.AppendNum((*modeList)[ii]);
   1.627 +		buf2.Append(TDisplayModeUtils::IsDisplayModeColor(mode)?KColor():KGrey());
   1.628 +		buf2.AppendNum(TDisplayModeUtils::NumDisplayModeColors(mode));
   1.629 +		if (mode==EColor16MU)
   1.630 +			buf2.Append('U');
   1.631 +		if (++ii==modeList->Count())
   1.632 +			break;
   1.633 +		buf.Append(KComma);
   1.634 +		buf2.Append(KComma);
   1.635 +		}
   1.636 +	LogMessage(buf);
   1.637 +	LogMessage(buf2);
   1.638 +	delete modeList;
   1.639 +	}
   1.640 +
   1.641 +void TestClient::TestWsSetBufferSizeL()
   1.642 +	{
   1.643 +	RWsSession ws;
   1.644 +	User::LeaveIfError(ws.Connect());
   1.645 +	ws.SetBufferSizeL(256);		// default buffer size 640
   1.646 +	ws.SetBufferSizeL(0x8000);	// 16K is max buffer size
   1.647 +	ws.SetBufferSizeL(0x4000);
   1.648 +	ws.Close();
   1.649 +	}
   1.650 +
   1.651 +void TestClient::TestWsSetMaxBufferSizeL() 
   1.652 +	{
   1.653 +	RWsSession ws;
   1.654 +	User::LeaveIfError(ws.Connect());
   1.655 +	// allow buffer to grow bigger than the default 640 bytes
   1.656 +	const TInt KBigMessageSize = 800;
   1.657 +	ws.SetMaxBufferSizeL(KBigMessageSize + 8);	// big message + command header length
   1.658 +	
   1.659 +	// send the big message to the wserv
   1.660 +	TBuf8<KBigMessageSize>	bigMessage;
   1.661 +
   1.662 +	// LogMessage needs a pointer to a TInt with the message size at the start of the buffer
   1.663 +	const TInt szLength = sizeof(TInt);
   1.664 +	TInt length = KBigMessageSize - szLength;			// length in Unicode characters
   1.665 +	bigMessage.Append((TUint8*) &length, szLength);
   1.666 +
   1.667 +	_LIT(KLetterA, "a");
   1.668 +	do 
   1.669 +		{
   1.670 +		bigMessage.Append((TUint8*) KLetterA().Ptr(), 2);
   1.671 +		}
   1.672 +		while (bigMessage.Length() < KBigMessageSize);
   1.673 +
   1.674 +	// send to Wserv, note that the message is too long to be logged
   1.675 +	ws.TestWrite(ws.WsHandle(), EWsClOpLogMessage, bigMessage.Ptr(), KBigMessageSize);
   1.676 +	ws.Flush();
   1.677 +
   1.678 +	ws.Close();
   1.679 +	}
   1.680 +
   1.681 +void TestClient::SetTestClientScreenMode(TInt aMode)
   1.682 +	{
   1.683 +	iScreen->SetAppScreenMode(aMode);
   1.684 +	iScreen->SetScreenMode(aMode);
   1.685 +	UpdateTestClientScreenMode();
   1.686 +	}
   1.687 +	
   1.688 +void TestClient::UpdateTestClientScreenMode()
   1.689 +	{
   1.690 +	TSize screenSize=iScreen->SizeInPixels();
   1.691 +
   1.692 +	// Sets new positions and dimensions for the three window and their controlling border windows
   1.693 +	
   1.694 +	if (screenSize.iHeight > screenSize.iWidth)		// Portrait mode
   1.695 +		{
   1.696 +		TInt winWidth=screenSize.iWidth - (KBorderWinWidth * 2);
   1.697 +		TInt winHeight=(screenSize.iHeight/3) - (KBorderWinWidth * 2);
   1.698 +		
   1.699 +		iStdLogWindow->SetExt(TPoint(KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
   1.700 +		BaseWin->SetBorderExt(TPoint(KBorderWinWidth,screenSize.iHeight/3+KBorderWinWidth),TSize(winWidth,winHeight));
   1.701 +		BaseWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
   1.702 +		TestWin->SetBorderExt(TPoint(KBorderWinWidth,screenSize.iHeight/3*2+KBorderWinWidth),TSize(winWidth,winHeight));
   1.703 +		TestWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
   1.704 +		}
   1.705 +	else											// Landscape modes
   1.706 +		{
   1.707 +		TInt winWidth=(screenSize.iWidth/3) - (KBorderWinWidth * 2);
   1.708 +		TInt winHeight=screenSize.iHeight - (KBorderWinWidth * 2);
   1.709 +		
   1.710 +		iStdLogWindow->SetExt(TPoint(KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
   1.711 +		BaseWin->SetBorderExt(TPoint(screenSize.iWidth/3 + KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));
   1.712 +		BaseWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));
   1.713 +		TestWin->SetBorderExt(TPoint(screenSize.iWidth/3*2+KBorderWinWidth,KBorderWinWidth),TSize(winWidth,winHeight));	
   1.714 +		TestWin->SetExt(TPoint(2,2),TSize(winWidth - (KBorderWinWidth - 1),winHeight - (KBorderWinWidth - 1)));		
   1.715 +		}	
   1.716 +		
   1.717 +	// Remove shading artefacts from window resizing operations		
   1.718 +	TestWin->Win()->Invalidate();
   1.719 +	TestWin->Win()->BeginRedraw();
   1.720 +	TestWin->ClearWin();
   1.721 +	TestWin->Win()->EndRedraw();
   1.722 +	
   1.723 +	BaseWin->Win()->Invalidate();
   1.724 +	BaseWin->Win()->BeginRedraw();
   1.725 +	BaseWin->ClearWin();
   1.726 +	BaseWin->Win()->EndRedraw();
   1.727 +	
   1.728 +	TheClient->iWs.Flush();
   1.729 +	}
   1.730 +
   1.731 +
   1.732 +//
   1.733 +// TestDriver, drives the test code //
   1.734 +//
   1.735 +CTestDriver* CTestDriver::CreateL(TInt aScreenNumber)
   1.736 +	{
   1.737 +	CTestDriver* self = NULL;
   1.738 +	if (aScreenNumber==KDefaultScreen)
   1.739 +		self = new (ELeave) CTestDriverPrimary(aScreenNumber);
   1.740 +	else
   1.741 +		self = new (ELeave) CTestDriverSecondary(aScreenNumber);
   1.742 +
   1.743 +	return self;
   1.744 +	}
   1.745 +
   1.746 +CTestDriver::CTestDriver(TInt aScreenNumber)
   1.747 +	: iScreenNumber(aScreenNumber)
   1.748 +	{
   1.749 +	iStartTime.HomeTime();
   1.750 +	HAL::Get(HALData::EDisplayNumberOfScreens, iNumberOfScreens);
   1.751 +	}
   1.752 +
   1.753 +CTestDriver::~CTestDriver()
   1.754 +	{
   1.755 +	}
   1.756 +
   1.757 +void CTestDriver::DestroyTest()
   1.758 +	{
   1.759 +	delete iTest;
   1.760 +	iTest=NULL;
   1.761 +	}
   1.762 +
   1.763 +void CTestDriver::TestComplete2()
   1.764 +	{
   1.765 +	++iTestNum;
   1.766 +	if (iTestNum==iTestSize)
   1.767 +		{
   1.768 +		TBuf<64> timeBuf;
   1.769 +		TTime endTime;
   1.770 +		endTime.HomeTime();
   1.771 +		TTimeIntervalMicroSeconds elapseTime=endTime.MicroSecondsFrom(iStartTime);
   1.772 +		TInt64 elapseTime2=elapseTime.Int64()/1000;
   1.773 +		TUint diffi = I64LOW(elapseTime2);
   1.774 +		_LIT(TestPass,"PASSED");
   1.775 +		_LIT(TestFail,"FAILED");
   1.776 +		TInt noOfTests=CTestBase::iNumberTests;
   1.777 +		TInt noOfTestsPass=CTestBase::iNumberTestsPass;
   1.778 +		_LIT(TimeBuf,"Elapse Time  %d:%02d.%03d   %S");
   1.779 +		timeBuf.Format(TimeBuf,diffi/60000,(diffi/1000)%60,diffi%1000000,&(noOfTests==noOfTestsPass?TestPass:TestFail));
   1.780 +		TBuf<60> testReport;
   1.781 +		_LIT(Checks,"Checks");
   1.782 +		_LIT(Fails,"Fails");
   1.783 +		_LIT(TestReport,"Tests:%d %S:%d");
   1.784 +		TInt testNumber=(noOfTests==noOfTestsPass? noOfTestsPass : noOfTests-noOfTestsPass);
   1.785 +		testReport.Format(TestReport,iTestNum,&(noOfTests==noOfTestsPass?Checks():Fails()),testNumber);
   1.786 +		if (noOfTests!=noOfTestsPass)
   1.787 +			{
   1.788 +			_LIT(NumTests,"/%d");
   1.789 +			testReport.AppendFormat(NumTests,noOfTests);
   1.790 +			}
   1.791 +
   1.792 +		TBuf<60> logTestReport;
   1.793 +		_LIT(LogReport," %S:%d/%d");
   1.794 +		logTestReport.Format(LogReport,&Checks,noOfTestsPass,noOfTests);
   1.795 +		TLogMessageText buf;
   1.796 +		_LIT(Finished,"AUTO Testing Complete, ");
   1.797 +		buf.Append(Finished);
   1.798 +		buf.Append(timeBuf);
   1.799 +		buf.Append(logTestReport);
   1.800 +		TheClient->LogMessage(buf);
   1.801 +
   1.802 +		TheTestResult = noOfTests==noOfTestsPass? ETestPassed : ETestFailed;
   1.803 +		DoDisplayDialog(timeBuf,testReport);
   1.804 +		}
   1.805 +	}
   1.806 +
   1.807 +//
   1.808 +// Test driver for primary screen (has digitiser/pointer)
   1.809 +//
   1.810 +CTestDriverPrimary::CTestDriverPrimary(TInt aScreenNumber) : CTestDriver(aScreenNumber)
   1.811 +	{
   1.812 +	TInt i;
   1.813 +	TInt numOfEntries = 1;
   1.814 +	for (i=0; i<numOfEntries; ++i)
   1.815 +		{
   1.816 +		++iTestSize;
   1.817 +		}
   1.818 +
   1.819 +	// omit multi display test (last entry in test table)
   1.820 +	// for single screen platform
   1.821 +	//
   1.822 +	if (iNumberOfScreens==1)
   1.823 +		--iTestSize;
   1.824 +
   1.825 +	}
   1.826 +
   1.827 +void CTestDriverPrimary::DoDisplayDialog(TDesC& timeBuf,TDesC& testReport)
   1.828 +	{
   1.829 +	DisplayDialog(_L("Auto tests complete"),timeBuf, testReport);
   1.830 +	}
   1.831 +
   1.832 +//
   1.833 +// Test driver for secondary screens
   1.834 +//
   1.835 +CTestDriverSecondary::CTestDriverSecondary(TInt aScreenNumber) : CTestDriver(aScreenNumber)
   1.836 +	{
   1.837 +	TInt i;
   1.838 +	TInt numOfEntries = 1;
   1.839 +	for (i=0; i<numOfEntries; ++i)
   1.840 +		{
   1.841 +		++iTestSize;
   1.842 +		}
   1.843 +	}
   1.844 +
   1.845 +void CTestDriverSecondary::DoDisplayDialog(TDesC& timeBuf,TDesC& testReport)
   1.846 +	{
   1.847 +	if (TheTestResult==ETestFailed)
   1.848 +		DisplayDialog(iScreenNumber,_L("Auto tests complete"),timeBuf, testReport);
   1.849 +	}
   1.850 +
   1.851 +// TTestRects //
   1.852 +//
   1.853 +// This class provides a list of rectangles to test graphics to the test windows
   1.854 +// The list designed to test all cases total clipping, partial clipping, touching the edges,
   1.855 +// unclipped etc etc...
   1.856 +//
   1.857 +// NOTE:- Quick test version, does not provide a proper list yet
   1.858 +//
   1.859 +// For the rectangle list the graphics area is divided into 9 logical areas:-
   1.860 +// 0:The area above & left of the drawing area
   1.861 +// 1:The area above but within the left & right limits of the drawing area
   1.862 +// 2:The area above & right of the drawing area
   1.863 +// 3:The area left of but within the top & bottom limits of the drawing area
   1.864 +// 4:The area within the drawing area
   1.865 +// 5:The area right of but within the top & bottom limits of the drawing area
   1.866 +// 6:The area below & left of the drawing area
   1.867 +// 7:The area below but within the left & right limits of the drawing area
   1.868 +// 8:The area below & right of the drawing area
   1.869 +//
   1.870 +//			|		|
   1.871 +//		0	|	1	|	2
   1.872 +//			|		|
   1.873 +//	-------------------------
   1.874 +//			|		|
   1.875 +//		3	|	4	|	5
   1.876 +//			|		|
   1.877 +//	-------------------------
   1.878 +//			|		|
   1.879 +//		6	|	7	|	8
   1.880 +//			|		|
   1.881 +//
   1.882 +//
   1.883 +// The full list of rectangles needed to test an official release is as follows:
   1.884 +//
   1.885 +//	0-8:	A rectangle wholly within each area (0 to 8) without touching the edges (if possible)
   1.886 +//	9-17:	A rectangle wholly within each area and touching all bounding edges
   1.887 +//	18-26:	A rectangle traversing each horizontal pair & triple of areas without touching the boundarys
   1.888 +//	27-35:	A rectangle traversing each vertical pair & triple of areas without touching the boundarys
   1.889 +//	36-39:	A rectangle traversing each 2x2 block of areas without touching the boundarys
   1.890 +//	40-43:	A rectangle traversing each 2x2 block of areas touching each boundary
   1.891 +//  44:		A rectangle that includes all areas
   1.892 +//  45-48:	A rectangle fully enclosed in the central area that touches each edge
   1.893 +//	49-54:	A rectangle fully enclosed in the central area that touches each pair of edges
   1.894 +//	55-58:	A rectangle fully enclosed in the central area that touches each set of three edges
   1.895 +//  59-67:	A Zero size rectangle in each of the 9 areas
   1.896 +//	68-77:	Wide rectangles with heights from 0 to 9 in the central area
   1.897 +//	78-87:	Tall rectangles with widths from 0 to 9 in the central area
   1.898 +//
   1.899 +
   1.900 +void TTestRects::Construct(const RWindow &aWindow)
   1.901 +	{
   1.902 +// 59-67
   1.903 +//		Special case, does not use rectangles from here
   1.904 +// 68-77
   1.905 +//		Special case, does not use rectangles from here
   1.906 +// 78-87
   1.907 +//		Special case, does not use rectangles from here
   1.908 +//
   1.909 +
   1.910 +	iSize=aWindow.Size();
   1.911 +/*
   1.912 +	TInt wid=size.iWidth;
   1.913 +	TInt hgt=size.iHeight;
   1.914 +	TInt wid2=wid/2;
   1.915 +	TInt hgt2=hgt/2;
   1.916 +	TInt wid3=wid/3;
   1.917 +	TInt hgt3=hgt/3;
   1.918 +	TInt wid4=wid/4;
   1.919 +	TInt hgt4=hgt/4;
   1.920 +	TInt 2wid=wid*2;
   1.921 +	TInt 2hgt=hgt*2;
   1.922 +	TInt 3wid=wid*3;
   1.923 +	TInt 3hgt=hgt*3;
   1.924 +// 0-8
   1.925 +	iList[0]=TRect(-wid,-hgt,-wid2,-hgt2);
   1.926 +	iList[1]=TRect(wid3,-hgt,wid-wid3,-hgt2);
   1.927 +	iList[2]=TRect(wid+wid2,-2hgt,2wid,-hgt);
   1.928 +	iList[3]=TRect(-3wid,hgt3,-wid3,hgt-hgt3);
   1.929 +	iList[4]=TRect(wid4,hgt3,wid-wid3,hgt-hgt4);
   1.930 +	iList[5]=TRect(3wid,hgt4,wid+3wid,hgt-hgt4);
   1.931 +	iList[6]=TRect(-wid3,hgt+hgt4,-wid2,hgt+hgt);
   1.932 +	iList[7]=TRect(wid2,hgt+hgt4,wid-wid4,hgt+hgt3);
   1.933 +	iList[8]=TRect(2wid,hgt+hgt4,3wid,hgt+hgt2);
   1.934 +// 9-17
   1.935 +	iList[9]=TRect(-wid,-hgt,0,0);
   1.936 +	iList[10]=TRect(0,-2hgt,wid,0);
   1.937 +	iList[11]=TRect(wid,-hgt2,wid+wid3,0);
   1.938 +	iList[12]=TRect(-wid3,0,0,hgt);
   1.939 +	iList[13]=TRect(0,0,wid,hgt);
   1.940 +	iList[14]=TRect(wid,0,wid+wid4,hgt);
   1.941 +	iList[15]=TRect(-wid,hgt,0,hgt+hgt4);
   1.942 +	iList[16]=TRect(0,hgt,wid,hgt+hgt);
   1.943 +	iList[17]=TRect(wid,hgt,wid+3wid,hgt+3hgt);
   1.944 +// 18-26
   1.945 +	iList[18]=TRect(-wid,-hgt,wid2,hgt3);
   1.946 +	iList[19]=TRect(wid3,-2hgt,2wid,-hgt3);
   1.947 +	iList[20]=TRect(-wid,-hgt2,wid3,-hgt3);
   1.948 +	iList[21]=TRect(-wid3,hgt4,wid2,hgt2);
   1.949 +	iList[22]=TRect(wid3,hgt3,wid+wid3,hgt-hgt3);
   1.950 +	iList[23]=TRect(-wid,hgt2,wid+wid4,hgt-hgt3);
   1.951 +	iList[24]=TRect(-wid,2hgt,wid3,3hgt);
   1.952 +	iList[25]=TRect(wid-wid4,hgt+hgt3,wid+wid4,2hgt);
   1.953 +	iList[26]=TRect(-wid4,hgt+hgt4,wid+wid4,3);
   1.954 +*/
   1.955 +/*
   1.956 +	iList[0]=TRect(0,0,size.iWidth,size.iHeight);
   1.957 +	iList[1]=TRect(-10,-10,size.iWidth/2,size.iHeight/2);
   1.958 +	iList[2]=TRect(size.iWidth/2,size.iHeight/2,size.iWidth+10,size.iHeight+10);
   1.959 +	iList[3]=TRect(size.iWidth/4,size.iHeight/4,size.iWidth/2,size.iHeight/2);
   1.960 +	iList[4]=TRect(-10,size.iHeight/4,size.iWidth+10,size.iHeight/2);
   1.961 +*/
   1.962 +	}
   1.963 +
   1.964 +TInt TTestRects::Count1() const
   1.965 +//
   1.966 +// Count1() provides the simple base set of rectangles
   1.967 +//
   1.968 +	{
   1.969 +	return(2);
   1.970 +	}
   1.971 +
   1.972 +TInt TTestRects::Count2() const
   1.973 +//
   1.974 +// Count2() provides an increased set of rectangles for each graphics func to test itself more thoroughly
   1.975 +//
   1.976 +	{
   1.977 +	return(5);
   1.978 +	}
   1.979 +
   1.980 +TInt TTestRects::Count3() const
   1.981 +//
   1.982 +// Count3() provides the full set of rects for each graphics func to a quick test on
   1.983 +//
   1.984 +	{
   1.985 +	return(88);
   1.986 +	}
   1.987 +
   1.988 +/** Reset the seed value to 0. */
   1.989 +void TTestRects::ResetSeed()
   1.990 +	{
   1.991 +	iSeed = 0;
   1.992 +	}
   1.993 +
   1.994 +TInt TTestRects::Rnd(TInt aSize)
   1.995 +//
   1.996 +// Return a random based around aSize, maybe bigger maybe smaller, who knows?
   1.997 +//
   1.998 +	{
   1.999 +	TInt rnd=Math::Rand(iSeed);
  1.1000 +	TInt result;
  1.1001 +	if (rnd&0x8)	// Increase from aSize
  1.1002 +		result=aSize*((rnd&0x7)+1);
  1.1003 +	else 			// Decrease from aSize
  1.1004 +		result=aSize/((rnd&0x7)+1);
  1.1005 +	return(result);
  1.1006 +	}
  1.1007 +
  1.1008 +TInt TTestRects::RndMax(TInt aSize)
  1.1009 +//
  1.1010 +// Return a random from 0 to aSize inclusive
  1.1011 +//
  1.1012 +	{
  1.1013 +	TInt64 tmpl=Math::Rand(iSeed);
  1.1014 +	TInt tmp = I64INT(tmpl) & 0xFFFF;
  1.1015 +	tmp*=aSize;
  1.1016 +	tmp/=0xFFFF;
  1.1017 +	return(tmp);
  1.1018 +	}
  1.1019 +
  1.1020 +TInt TTestRects::RectCoord(TInt aSection,TInt aSize)
  1.1021 +	{
  1.1022 +	TInt result=0;
  1.1023 +	switch(aSection)
  1.1024 +		{
  1.1025 +		case 0:
  1.1026 +			result=-(1+Rnd(aSize));
  1.1027 +			break;
  1.1028 +		case 1:
  1.1029 +			result=0;
  1.1030 +			break;
  1.1031 +		case 2:
  1.1032 +			result=1+RndMax(aSize-2);
  1.1033 +			break;
  1.1034 +		case 3:
  1.1035 +			result=aSize;
  1.1036 +			break;
  1.1037 +		case 4:
  1.1038 +			result=aSize+1+Rnd(aSize);
  1.1039 +			break;
  1.1040 +		default:
  1.1041 +			AutoPanic(EAutoPanicTestRectsSection);
  1.1042 +		}
  1.1043 +	return(result);
  1.1044 +	}
  1.1045 +
  1.1046 +void TTestRects::RectCoordPair(TInt &aTl, TInt &aBr, TInt aSection, TInt aSize)
  1.1047 +	{
  1.1048 +	do
  1.1049 +		{
  1.1050 +		aTl=RectCoord(aSection,aSize);
  1.1051 +		aBr=RectCoord(aSection,aSize);
  1.1052 +		} while(aTl==aBr && aSize>1);
  1.1053 +	if (aTl>aBr)
  1.1054 +		{
  1.1055 +		TInt tmp=aBr;
  1.1056 +		aBr=aTl;
  1.1057 +		aTl=tmp;
  1.1058 +		}
  1.1059 +	}
  1.1060 +
  1.1061 +TRect TTestRects::operator[](TInt aIndex)
  1.1062 +	{
  1.1063 +	TRect rect;
  1.1064 +	if (aIndex<EMaxRectFromList)
  1.1065 +		{
  1.1066 +		const TRect *pRect=&iList[aIndex];
  1.1067 +		if (pRect->iTl.iX==pRect->iBr.iX)
  1.1068 +			RectCoordPair(rect.iTl.iX,rect.iBr.iX,pRect->iTl.iX,iSize.iWidth);
  1.1069 +		else
  1.1070 +			{
  1.1071 +			rect.iTl.iX=RectCoord(pRect->iTl.iX,iSize.iWidth);
  1.1072 +			rect.iBr.iX=RectCoord(pRect->iBr.iX,iSize.iWidth);
  1.1073 +			}
  1.1074 +		if (pRect->iTl.iY==pRect->iBr.iY)
  1.1075 +			RectCoordPair(rect.iTl.iY,rect.iBr.iY,pRect->iTl.iY,iSize.iHeight);
  1.1076 +		else
  1.1077 +			{
  1.1078 +			rect.iTl.iY=RectCoord(pRect->iTl.iX,iSize.iHeight);
  1.1079 +			rect.iBr.iY=RectCoord(pRect->iBr.iX,iSize.iHeight);
  1.1080 +			}
  1.1081 +		}
  1.1082 +	else if (aIndex<EMaxRectZeroSize)
  1.1083 +		{
  1.1084 +		rect.iTl.iX=RectCoord(((aIndex-EMaxRectFromList)%3)*2,iSize.iWidth);
  1.1085 +		rect.iTl.iY=RectCoord(((aIndex-EMaxRectFromList)/3)*2,iSize.iHeight);
  1.1086 +		rect.iBr=rect.iTl;
  1.1087 +		}
  1.1088 +	else if (aIndex<EMaxRectWide)
  1.1089 +		{
  1.1090 +		rect.iTl.iX=1;
  1.1091 +		rect.iBr.iX=iSize.iWidth-1;
  1.1092 +		rect.iTl.iY=1;
  1.1093 +		rect.iBr.iY=rect.iTl.iY+(aIndex-EMaxRectWide);
  1.1094 +		}
  1.1095 +	else if (aIndex<EMaxRectHigh)
  1.1096 +		{
  1.1097 +		rect.iTl.iX=1;
  1.1098 +		rect.iBr.iX=rect.iTl.iX+(aIndex-EMaxRectHigh);
  1.1099 +		rect.iTl.iY=1;
  1.1100 +		rect.iBr.iY=iSize.iHeight-1;
  1.1101 +		}
  1.1102 +	else
  1.1103 +		AutoPanic(EAutoPanicTestRectsIndex);
  1.1104 +	return(rect);
  1.1105 +	}
  1.1106 +
  1.1107 +
  1.1108 +/*CBitmap*/
  1.1109 +
  1.1110 +CBitmap* CBitmap::NewLC(const TSize& aSizeInPixels,TDisplayMode aDispMode)
  1.1111 +	{
  1.1112 +	return NewLC(0,aSizeInPixels,aDispMode);
  1.1113 +	}
  1.1114 +
  1.1115 +CBitmap* CBitmap::NewL(const TSize& aSizeInPixels,TDisplayMode aDispMode)
  1.1116 +	{
  1.1117 +	CBitmap* self=NewLC(0,aSizeInPixels,aDispMode);
  1.1118 +	CleanupStack::Pop(self);
  1.1119 +	return self;
  1.1120 +	}
  1.1121 +
  1.1122 +CBitmap* CBitmap::NewL(TInt aHandle)
  1.1123 +	{
  1.1124 +	CBitmap* self=NewLC(aHandle,TSize(),ENone);
  1.1125 +	CleanupStack::Pop(self);
  1.1126 +	return self;
  1.1127 +	}
  1.1128 +
  1.1129 +CBitmap* CBitmap::NewL(TDesC& /*aFileName*/)
  1.1130 +	{
  1.1131 +	User::Leave(KErrNotSupported);
  1.1132 +	return NULL;
  1.1133 +	}
  1.1134 +
  1.1135 +CBitmap* CBitmap::NewLC(TInt aHandle,const TSize& aSizeInPixels,TDisplayMode aDispMode)
  1.1136 +	{
  1.1137 +	CBitmap* self=new(ELeave) CBitmap();
  1.1138 +	CleanupStack::PushL(self);
  1.1139 +	self->ConstructL(aHandle, aSizeInPixels, aDispMode);
  1.1140 +	return self;
  1.1141 +	}
  1.1142 +
  1.1143 +void CBitmap::ConstructL(TInt aHandle,const TSize& aSizeInPixels,TDisplayMode aDispMode)
  1.1144 +	{
  1.1145 +	iBitmap=new(ELeave) CFbsBitmap();
  1.1146 +	if (aHandle==0)
  1.1147 +		{
  1.1148 +		User::LeaveIfError(iBitmap->Create(aSizeInPixels,aDispMode));
  1.1149 +		}
  1.1150 +	else
  1.1151 +		{
  1.1152 +		User::LeaveIfError(iBitmap->Duplicate(aHandle));
  1.1153 +		}
  1.1154 +	iDevice=CFbsBitmapDevice::NewL(iBitmap);
  1.1155 +	User::LeaveIfError(iDevice->CreateContext(iGc));
  1.1156 +	}
  1.1157 +
  1.1158 +CBitmap::~CBitmap()
  1.1159 +	{
  1.1160 +	delete iGc;
  1.1161 +	delete iDevice;
  1.1162 +	delete iBitmap;
  1.1163 +	}
  1.1164 +
  1.1165 +
  1.1166 +// CTestBase //
  1.1167 +
  1.1168 +CTestBase::CTestBase(const TDesC& aTitle,CTWsGraphicsBase* aTestBase)
  1.1169 +	{
  1.1170 +	iTestBase=aTestBase;
  1.1171 +	iTitle.Copy(aTitle);
  1.1172 +	
  1.1173 +	iScreenNo = iTestBase->GetScreenFromIni();
  1.1174 +	
  1.1175 +	TheClient=new(ELeave) TestClient();
  1.1176 +	
  1.1177 +	if (CTestBase::iScreenNo == 1)
  1.1178 +		{
  1.1179 +		TheClient->SetScreenNumber(1);
  1.1180 +		iScreenNumber = 1;		
  1.1181 +		}
  1.1182 +	else
  1.1183 +		{
  1.1184 +		TheClient->SetScreenNumber(0);
  1.1185 +		iScreenNumber = 0;
  1.1186 +		}
  1.1187 +
  1.1188 +	if (iScreenNumber == 1)
  1.1189 +		{
  1.1190 +		iMinWin = new(ELeave) CMinWin(iScreenNumber);
  1.1191 +		iMinWin->ConstructL();
  1.1192 +		}
  1.1193 +
  1.1194 +	iTestNum=CTestDriver::iTestNum;
  1.1195 +	TheClient->ConstructL();
  1.1196 +	TheClient->StdLogWindow().LogTest(iTitle,iTestNum);
  1.1197 +	iDriver=TheClient->Driver();
  1.1198 +	
  1.1199 +	if (CTestBase::iScreenNo == 1)
  1.1200 +		{
  1.1201 +		TheClient->iWs.SetFocusScreen(1);
  1.1202 +		}
  1.1203 +	else
  1.1204 +		{
  1.1205 +		TheClient->iWs.SetFocusScreen(0);
  1.1206 +		}
  1.1207 +	
  1.1208 +	iTestRects.Construct(*BaseWin->Win());
  1.1209 +	iStdTestWindowSize=BaseWin->Size();
  1.1210 +	iRedrawType=EPartialRedraw_Unknown;	// Reset between tests
  1.1211 +	if (iMaxGrays+iMaxColors==0)
  1.1212 +		{
  1.1213 +		TheClient->iWs.GetDefModeMaxNumColors(iMaxColors,iMaxGrays);
  1.1214 +		iNormalPointerCursorArea=TheClient->iWs.PointerCursorArea();
  1.1215 +		}
  1.1216 +	}
  1.1217 +
  1.1218 +CTestBase::~CTestBase()
  1.1219 +	{
  1.1220 +	delete iMinWin;
  1.1221 +	delete TheClient;
  1.1222 +	}
  1.1223 +
  1.1224 +void CTestBase::CloseAllPanicWindows()
  1.1225 +	{
  1.1226 +	TInt idFocus = TheClient->iWs.GetFocusWindowGroup();
  1.1227 +	TWsEvent event;
  1.1228 +	event.SetType(EEventKey);
  1.1229 +	TKeyEvent *keyEvent = event.Key();
  1.1230 +	keyEvent->iCode = EKeyEscape;
  1.1231 +	keyEvent->iScanCode = EStdKeyEscape;
  1.1232 +	keyEvent->iModifiers = 0;
  1.1233 +	TInt theLimit = 50;
  1.1234 +	while(idFocus != NULL && (theLimit-- > 0))
  1.1235 +		{
  1.1236 +		TheClient->iWs.SendEventToAllWindowGroups(event);
  1.1237 +		idFocus = TheClient->iWs.GetFocusWindowGroup();
  1.1238 +		}
  1.1239 +	}
  1.1240 +	
  1.1241 +/**
  1.1242 +Returns the size of the standard test windows.
  1.1243 +@see iStdTestWindowSize
  1.1244 +*/	
  1.1245 +const TSize& CTestBase::StdTestWindowSize()
  1.1246 +	{
  1.1247 +	return iStdTestWindowSize;
  1.1248 +	}
  1.1249 +
  1.1250 +/** Returns the number of greys available in the richest grey mode */
  1.1251 +TInt CTestBase::MaxGrays() const
  1.1252 +	{
  1.1253 +	return iMaxGrays;
  1.1254 +	}
  1.1255 +
  1.1256 +/** Returns the number of colours available in the richest supported colour mode. */
  1.1257 +TInt CTestBase::MaxColors() const
  1.1258 +	{
  1.1259 +	return iMaxColors;
  1.1260 +	}
  1.1261 +
  1.1262 +void CTestBase::TriggerFail()
  1.1263 +	{
  1.1264 +	iFail=ETrue;
  1.1265 +	}
  1.1266 +
  1.1267 +void CTestBase::LogLeave(TInt aErr)
  1.1268 +	{
  1.1269 +	TLogMessageText buf;
  1.1270 +	_LIT(Leave,"AUTO Left with error code %d in ");
  1.1271 +	buf.AppendFormat(Leave,aErr);
  1.1272 +	buf.Append(iSubTitle);
  1.1273 +	TheClient->LogMessage(buf);
  1.1274 +	}
  1.1275 +
  1.1276 +void CTestBase::LogSubTest(const TDesC &aSubTitle)
  1.1277 +	{
  1.1278 +	Driver()->iSubTestNum++;
  1.1279 +	iSubTitle=aSubTitle;
  1.1280 +	iTestBase->Logger().Write(TheClient->StdLogWindow().LogSubTest(aSubTitle,iState));
  1.1281 +	}
  1.1282 +
  1.1283 +void CTestBase::LogMessage(TInt aValue)
  1.1284 +	{
  1.1285 +	_LIT(WinID,"Win Id:");
  1.1286 +	TheClient->StdLogWindow().LogMessage(EFalse,WinID,aValue);
  1.1287 +	}
  1.1288 +
  1.1289 +void CTestBase::LogSubState(TInt aSubState)
  1.1290 +	{
  1.1291 +	_LIT(SubTest,"SubState");
  1.1292 +	iTestBase->Logger().Write(TheClient->StdLogWindow().LogMessage(ETrue,SubTest,aSubState));
  1.1293 +	}
  1.1294 +
  1.1295 +TBool DoCheckRectRWin(RWindowBase &aWin1,RWindowBase &aWin2,const TRect &aRect)
  1.1296 +	{
  1.1297 +	TRect rect1(aRect);
  1.1298 +	TRect rect2(aRect);
  1.1299 +	rect1.Move(aWin1.InquireOffset(*TheClient->iGroup->WinTreeNode()));
  1.1300 +	rect2.Move(aWin2.InquireOffset(*TheClient->iGroup->WinTreeNode()));
  1.1301 +	TBool match=TheClient->iScreen->RectCompare(rect1,rect2);
  1.1302 +#if defined(__WINS__)
  1.1303 +	if (!match)
  1.1304 +		FindNonMatchingPixel(rect1.iTl,rect2.iTl,aRect.Size());
  1.1305 +#endif
  1.1306 +	return match;
  1.1307 +	}
  1.1308 +
  1.1309 +TBool DoCheckRectRWin(RWindowBase &aWin1,RWindowBase &aWin2,const TRect &aRect, TUint aFlags)
  1.1310 +	{
  1.1311 +	TRect rect1(aRect);
  1.1312 +	TRect rect2(aRect);
  1.1313 +	rect1.Move(aWin1.InquireOffset(*TheClient->iGroup->WinTreeNode()));
  1.1314 +	rect2.Move(aWin2.InquireOffset(*TheClient->iGroup->WinTreeNode()));
  1.1315 +	TBool match=TheClient->iScreen->RectCompare(rect1,rect2, aFlags);
  1.1316 +#if defined(__WINS__)
  1.1317 +	if (!match)
  1.1318 +		FindNonMatchingPixel(rect1.iTl,rect2.iTl,aRect.Size());
  1.1319 +#endif
  1.1320 +	return match;
  1.1321 +	}
  1.1322 +
  1.1323 +TBool DoCheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect)
  1.1324 +	{
  1.1325 +	return DoCheckRectRWin(*aWin1->BaseWin(), *aWin2->BaseWin(), aRect);
  1.1326 +	}
  1.1327 +
  1.1328 +TBool DoCheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2)
  1.1329 +	{
  1.1330 +	TSize winSize=aWin1->Size();
  1.1331 +	TRect rect1(aWin1->BaseWin()->InquireOffset(*TheClient->iGroup->WinTreeNode()),winSize);
  1.1332 +	TRect rect2(aWin2->BaseWin()->InquireOffset(*TheClient->iGroup->WinTreeNode()),winSize);
  1.1333 +	return TheClient->iScreen->RectCompare(rect1,rect2);
  1.1334 +	}
  1.1335 +
  1.1336 +TBool DoCheckRect(CTBaseWin *aWin1, CTBaseWin *aWin2, const TRect &aRect, TUint aFlags)
  1.1337 +	{
  1.1338 +	return DoCheckRectRWin(*aWin1->BaseWin(), *aWin2->BaseWin(), aRect, aFlags);
  1.1339 +	}
  1.1340 +
  1.1341 +
  1.1342 +/**
  1.1343 +Compares the contents of 2 rectangular areas of the screen.
  1.1344 +
  1.1345 +@param aPos1 The top left corner of the first rectangle.
  1.1346 +@param aPos2 The top left corner of the second rectangle.
  1.1347 +@param aSize The size of the rectangles
  1.1348 +@return ETrue if the 2 areas have the same content, EFalse otherwise.
  1.1349 +*/
  1.1350 +TBool DoCheckRect(TPoint aPos1,TPoint aPos2,TSize aSize)
  1.1351 +	{
  1.1352 +	return TheClient->iScreen->RectCompare(TRect(aPos1,aSize),TRect(aPos2,aSize));
  1.1353 +	}
  1.1354 +
  1.1355 +void CTestBase::DrawTestBackground(TBool aInvertColors, const TSize &aSize, TInt aGrays/*=16*/)
  1.1356 +//
  1.1357 +// Draws a standard test background with a mix of colors (shades).
  1.1358 +// This is mainly used to test for graphic functions writing outside the intended area.
  1.1359 +//
  1.1360 +// This code assumes an TheGc is already active on the window to use.
  1.1361 +//
  1.1362 +	{
  1.1363 +	TheGc->SetBrushColor(TRgb::Gray256(255));
  1.1364 +	TInt step=5;
  1.1365 +	TInt col=0;
  1.1366 +	TInt colorInc=(aGrays>9 ? 17 : 85);
  1.1367 +	TheGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.1368 +	TheGc->SetPenStyle(CGraphicsContext::ENullPen);
  1.1369 +	for(TInt row=0;row<aSize.iHeight;row+=step)
  1.1370 +		{
  1.1371 +		TheGc->SetBrushColor(TRgb::Gray256(aInvertColors ? 255-col:col));
  1.1372 +		TheGc->DrawRect(TRect(0,row,aSize.iWidth,row+step));
  1.1373 +		col=col+colorInc;
  1.1374 +		if (col>255)
  1.1375 +			col=0;
  1.1376 +		}
  1.1377 +	}
  1.1378 +
  1.1379 +void CTestBase::AbortL()
  1.1380 +	{
  1.1381 +	CTestDriver* driver=iDriver;
  1.1382 +	iDriver->DestroyTest();
  1.1383 +	driver->TestComplete2();
  1.1384 +	User::Leave(ETestFailed);
  1.1385 +	}
  1.1386 +
  1.1387 +/*CTWsGraphicsBase*/
  1.1388 +
  1.1389 +CTWsGraphicsBase::CTWsGraphicsBase(CTestStep* aStep) : CTGraphicsBase(aStep)
  1.1390 +	{
  1.1391 +	}
  1.1392 +
  1.1393 +CTWsGraphicsBase::~CTWsGraphicsBase()
  1.1394 +	{
  1.1395 +	delete iTest;
  1.1396 +	}
  1.1397 +
  1.1398 +void CTWsGraphicsBase::CreateTestBaseL(CTTMSGraphicsStep* aTmsStep)
  1.1399 +	{
  1.1400 +	__ASSERT_ALWAYS(iTest==NULL,AutoPanic(EAutoPanicRecalledCreateTestBaseL));
  1.1401 +	iTest=new(ELeave) CTestBase(iStep->TestStepName(),this);
  1.1402 +	iTmsStep = aTmsStep;
  1.1403 +	}
  1.1404 +/**
  1.1405 +Gets the Screen Number from an .ini file supplied to the RUN_TEST_STEP. Screen number should
  1.1406 +be put under the section [useScreen] as screen=0 or screen=1.
  1.1407 +
  1.1408 +@return Screen number Defined in .ini file, otherwise 0.
  1.1409 +*/
  1.1410 +TInt CTWsGraphicsBase::GetScreenFromIni() const
  1.1411 +	{
  1.1412 +	_LIT(KUseScreenSection, "useScreen");
  1.1413 +	_LIT(KScreen, "screen");
  1.1414 +
  1.1415 +	TInt screen = 0;
  1.1416 +	TBool configAvailable = iStep->GetIntFromConfig(KUseScreenSection, KScreen, screen);
  1.1417 +	if(configAvailable)
  1.1418 +		{
  1.1419 +		return screen;
  1.1420 +		}
  1.1421 +	else
  1.1422 +		{
  1.1423 +		return 0;
  1.1424 +		}
  1.1425 +	}
  1.1426 +
  1.1427 +void CTWsGraphicsBase::TestComplete()
  1.1428 +	{
  1.1429 +	_LIT(KTestComplete,"Test complete");
  1.1430 +	INFO_PRINTF1(KTestComplete);
  1.1431 +	CTGraphicsBase::TestComplete();
  1.1432 +	}
  1.1433 +
  1.1434 +void CTWsGraphicsBase::LogMessage(const TText8* aFile,TInt aLine,TRefByValue<const TDesC> aFmt,...)
  1.1435 +	{
  1.1436 +	TLogMessageText buf;
  1.1437 +	VA_LIST list;
  1.1438 +	VA_START(list,aFmt);
  1.1439 +	buf.AppendFormatList(aFmt,list);
  1.1440 +	TheClient->LogMessage(buf);
  1.1441 +	Logger().LogExtra(aFile,aLine,ESevrInfo,buf);
  1.1442 +	VA_END(list);
  1.1443 +	}
  1.1444 +
  1.1445 +TBool CTWsGraphicsBase::CheckRetValue(TBool aPass, const TDesC *aErrorMsg, const TDesC &aErrorFunction)
  1.1446 +	{
  1.1447 +	if (!aPass && aErrorMsg)
  1.1448 +		{
  1.1449 +		LOG_MESSAGE3(_L("%S %S failed"),aErrorMsg,&aErrorFunction);
  1.1450 +		iTmsStep->MQCTest(EFalse,((TText8*)__FILE__),__LINE__);
  1.1451 +		}
  1.1452 +	iStep->TEST(aPass);
  1.1453 +	return aPass;
  1.1454 +	}
  1.1455 +
  1.1456 +void CTWsGraphicsBase::CompareWindowsSoftFailWinscw(const TText8* aFile, TInt aLine)
  1.1457 +	{
  1.1458 +	if (!DoCheckRect(BaseWin, TestWin, BaseWin->Size()))
  1.1459 +		{
  1.1460 +#ifdef __WINS__
  1.1461 +		_LIT(KMessage,"ERROR: Test Failed but is ignored on WINSCW");
  1.1462 +		Logger().LogExtra(aFile, aLine, ESevrErr, KMessage);
  1.1463 +#else // __WINS__
  1.1464 +		iStep->TEST(EFalse);
  1.1465 +		_LIT(KMessage,"ERROR: Test Failed");
  1.1466 +		Logger().LogExtra(aFile, aLine, ESevrErr, KMessage);
  1.1467 +#endif // __WINS__
  1.1468 +		}
  1.1469 +	}
  1.1470 +
  1.1471 +void CTWsGraphicsBase::CheckRect(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC *aErrorMsg)
  1.1472 +	{
  1.1473 +	CheckRetValue(DoCheckRect(aPos1,aPos2,aSize),aErrorMsg,_L("CheckRect()"));
  1.1474 +	}
  1.1475 +
  1.1476 +void CTWsGraphicsBase::CheckRect(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC &aErrorMsg)
  1.1477 +	{
  1.1478 +	CheckRect(aPos1,aPos2,aSize,&aErrorMsg);
  1.1479 +	}
  1.1480 +
  1.1481 +void CTWsGraphicsBase::CheckRectNoMatch(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC *aErrorMsg)
  1.1482 +	{
  1.1483 +	CheckRetValue(!DoCheckRect(aPos1,aPos2,aSize),aErrorMsg,_L("CheckRectNoMatch()"));
  1.1484 +	}
  1.1485 +
  1.1486 +void CTWsGraphicsBase::CheckRectNoMatch(TPoint aPos1,TPoint aPos2,TSize aSize, const TDesC &aErrorMsg)
  1.1487 +	{
  1.1488 +	CheckRectNoMatch(aPos1,aPos2,aSize,&aErrorMsg);
  1.1489 +	}
  1.1490 +
  1.1491 +void CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC *aErrorMsg)
  1.1492 +	{
  1.1493 +	CheckRetValue(DoCheckRect(aWin1,aWin2),aErrorMsg,_L("CheckRect()"));
  1.1494 +	}
  1.1495 +
  1.1496 +void CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC &aErrorMsg)
  1.1497 +	{
  1.1498 +	CheckRect(aWin1,aWin2,&aErrorMsg);
  1.1499 +	}
  1.1500 +
  1.1501 +void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC *aErrorMsg)
  1.1502 +	{
  1.1503 +	CheckRetValue(!DoCheckRect(aWin1,aWin2),aErrorMsg,_L("CheckRectNoMatch()"));
  1.1504 +	}
  1.1505 +
  1.1506 +void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2, const TDesC &aErrorMsg)
  1.1507 +	{
  1.1508 +	CheckRectNoMatch(aWin1,aWin2,&aErrorMsg);
  1.1509 +	}
  1.1510 +
  1.1511 +TBool CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC *aErrorMsg)
  1.1512 +	{
  1.1513 +	return CheckRetValue(DoCheckRect(aWin1,aWin2,aRect),aErrorMsg,_L("CheckRect()"));
  1.1514 +	}
  1.1515 +
  1.1516 +TBool CTWsGraphicsBase::CheckRect(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC &aErrorMsg)
  1.1517 +	{
  1.1518 +	return CheckRect(aWin1,aWin2,aRect,&aErrorMsg);
  1.1519 +	}
  1.1520 +
  1.1521 +void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC *aErrorMsg)
  1.1522 +	{
  1.1523 +	CheckRetValue(!DoCheckRect(aWin1,aWin2,aRect),aErrorMsg,_L("CheckRectNoMatch()"));
  1.1524 +	}
  1.1525 +
  1.1526 +void CTWsGraphicsBase::CheckRectNoMatch(CTBaseWin *aWin1,CTBaseWin *aWin2,const TRect &aRect, const TDesC &aErrorMsg)
  1.1527 +	{
  1.1528 +	CheckRectNoMatch(aWin1,aWin2,aRect,&aErrorMsg);
  1.1529 +	}
  1.1530 +
  1.1531 +void CTWsGraphicsBase::CompareWindows(const TRect &aRect, const TDesC *aErrorMsg)
  1.1532 +	{
  1.1533 +	CheckRetValue(DoCheckRect(BaseWin,TestWin,aRect),aErrorMsg,_L("CompareWindows()"));
  1.1534 +	}
  1.1535 +
  1.1536 +TBool CTWsGraphicsBase::CompareWindows(const TDesC *aErrorMsg)
  1.1537 +	{
  1.1538 +	return CheckRetValue(DoCheckRect(BaseWin,TestWin,TRect(BaseWin->Size())),aErrorMsg,_L("CompareWindows()"));
  1.1539 +	}
  1.1540 +
  1.1541 +void CTWsGraphicsBase::CompareWindows(const TRect &aRect, const TDesC &aErrorMsg)
  1.1542 +	{
  1.1543 +	CompareWindows(aRect,&aErrorMsg);
  1.1544 +	}
  1.1545 +
  1.1546 +TBool CTWsGraphicsBase::CompareWindows(const TDesC &aErrorMsg)
  1.1547 +	{
  1.1548 +	return CompareWindows(&aErrorMsg);
  1.1549 +	}
  1.1550 +
  1.1551 +/**
  1.1552 +Returns the size of the standard test windows.
  1.1553 +
  1.1554 +Several tests use 3 windows : one is a log window, one is a reference window 
  1.1555 +and one is the actual output of the test. All these windows have the same width which is roughly
  1.1556 +1/3 of the screen. They also have the same height which is roughly equal to the screen height.
  1.1557 +*/
  1.1558 +const TSize& CTWsGraphicsBase::StdTestWindowSize()
  1.1559 +	{
  1.1560 +	return iTest->StdTestWindowSize();
  1.1561 +	}
  1.1562 +
  1.1563 +/** Returns the number of greys available in the richest grey mode */
  1.1564 +TInt CTWsGraphicsBase::MaxGrays() const
  1.1565 +	{
  1.1566 +	return iTest->MaxGrays();
  1.1567 +	}
  1.1568 +
  1.1569 +/** Returns the number of colours available in the richest supported colour mode. */
  1.1570 +TInt CTWsGraphicsBase::MaxColors() const
  1.1571 +	{
  1.1572 +	return iTest->MaxColors();
  1.1573 +	}
  1.1574 +
  1.1575 +//
  1.1576 +// Panic testing //
  1.1577 +//
  1.1578 +
  1.1579 +LOCAL_C TInt PanicThreadFunc(TAny *aPtr)
  1.1580 +	{
  1.1581 +	CTrapCleanup* CleanUpStack=CTrapCleanup::New();
  1.1582 +	SPanicParams *ptr=(SPanicParams *)aPtr;
  1.1583 +	TInt ret;
  1.1584 +	TRAP(ret,ret=(*ptr->func)(ptr->num,ptr->ptr));
  1.1585 +	delete CleanUpStack;
  1.1586 +	if (ret==EWsExitReasonBad)
  1.1587 +		AutoPanic(EAutoPanicPanicFailed);
  1.1588 +	return(ret);
  1.1589 +	}
  1.1590 +
  1.1591 +TInt CTestBase::LaunchPanicThread(RThread &aThread, SPanicParams *aPtr)
  1.1592 +	{
  1.1593 +	TBuf<32> threadName;
  1.1594 +	threadName.Format(TRefByValue<const TDesC>(_L("AutoPanicThread%d")),iThreadNumber++);
  1.1595 +	return(aThread.Create(threadName,PanicThreadFunc,KDefaultStackSize,KPanicThreadHeapSize,KPanicThreadHeapSize,aPtr,EOwnerThread));
  1.1596 +	}
  1.1597 +
  1.1598 +TInt CTestBase::TestPanicL(SPanicParams *aPtr, TInt aExitReason, const TDesC &aCategory, TBool* aTestFinished)
  1.1599 +	{
  1.1600 +	RThread thread;
  1.1601 +	TRequestStatus stat;
  1.1602 +	TInt err=LaunchPanicThread(thread, aPtr);
  1.1603 +	if (err==KErrAlreadyExists)
  1.1604 +		{
  1.1605 +		// wait for kernel to clear up old threads
  1.1606 +		// and have several attempts at starting the thread
  1.1607 +		// if unsuccessful the first time
  1.1608 +		for (TInt i=0;i<3;i++)
  1.1609 +			{
  1.1610 +			User::After(TTimeIntervalMicroSeconds32(100000));		//0.1 secs
  1.1611 +			err=LaunchPanicThread(thread, aPtr);
  1.1612 +			if (err!=KErrAlreadyExists)
  1.1613 +				break;
  1.1614 +			}
  1.1615 +		}
  1.1616 +	User::LeaveIfError(err);
  1.1617 +	thread.Logon(stat);
  1.1618 +	User::SetJustInTime(EFalse);
  1.1619 +	thread.Resume();
  1.1620 +	User::WaitForRequest(stat);
  1.1621 +	User::SetJustInTime(ETrue);
  1.1622 +
  1.1623 +	TBool testFinished=EFalse;
  1.1624 +	TBool testPassed=ETrue;
  1.1625 +	if (thread.ExitType()==EExitKill)
  1.1626 +		{
  1.1627 +		User::LeaveIfError(thread.ExitReason());
  1.1628 +		if(thread.ExitReason()!=EWsExitReasonFinished)
  1.1629 +			{
  1.1630 +			testPassed=EFalse;
  1.1631 +			}
  1.1632 +		testFinished=ETrue;	// Finish tests
  1.1633 +		}
  1.1634 +	else
  1.1635 +		{
  1.1636 +		if ((thread.ExitCategory().Compare(aCategory)!=0)
  1.1637 +		|| (aExitReason!=EWservNoPanic && thread.ExitReason()!=aExitReason)
  1.1638 +		|| (thread.ExitType()!=EExitPanic))
  1.1639 +			{
  1.1640 +			testPassed=EFalse;
  1.1641 +			}			
  1.1642 +		}
  1.1643 +
  1.1644 +	if(aTestFinished)
  1.1645 +		*aTestFinished=testFinished;
  1.1646 +	thread.Close();
  1.1647 +	return(testPassed);
  1.1648 +	}
  1.1649 +
  1.1650 +TInt CTestBase::TestWsPanicL(TPanicFunction aFunction, TClientPanic aExitReason, TInt aInt, TAny *aPtr, TBool* aTestFinished)
  1.1651 +	{
  1.1652 +	return TestPanicL(aFunction,aExitReason,aInt,aPtr,KWSERV, aTestFinished);
  1.1653 +	}
  1.1654 +
  1.1655 +TInt CTestBase::TestW32PanicL(TPanicFunction aFunction, TW32Panic aExitReason, TInt aInt, TAny *aPtr, TBool* aTestFinished)
  1.1656 +	{
  1.1657 +	return TestPanicL(aFunction,aExitReason,aInt,aPtr,KW32,aTestFinished);
  1.1658 +	}
  1.1659 +	
  1.1660 + TInt CTestBase::TestWservPanicL(TPanicFunction aFunction, TWservPanic aExitReason, TInt aInt, TAny *aPtr)
  1.1661 + 	{
  1.1662 +	_LIT(KWSERV1,"Wserv Internal Panic");
  1.1663 +	return TestPanicL(aFunction,aExitReason,aInt,aPtr,KWSERV1);
  1.1664 +	}
  1.1665 +	
  1.1666 +TInt CTestBase::TestPanicL(TPanicFunction aFunction, TInt aExitReason, TInt aInt, TAny *aPtr, const TDesC &aCategory, TBool* aTestFinished)
  1.1667 +	{
  1.1668 +	SPanicParams params;
  1.1669 +	params.num=aInt;
  1.1670 +	params.func=aFunction;
  1.1671 +	params.ptr=aPtr;
  1.1672 +	return TestPanicL(&params, aExitReason, aCategory, aTestFinished);
  1.1673 +	}
  1.1674 +
  1.1675 +TBool CTestBase::IsFullRomL()
  1.1676 +	{
  1.1677 +	TBool isFullRom = EFalse;
  1.1678 +	_LIT(KWinName,"EikonServer");
  1.1679 +	TInt numWinGroups=TheClient->iWs.NumWindowGroups();
  1.1680 +	CArrayFixFlat<TInt>* list=new(ELeave) CArrayFixFlat<TInt>(numWinGroups);
  1.1681 +	TheClient->iWs.WindowGroupList(list);
  1.1682 +	numWinGroups=list->Count();	// Just in case it changed between originally getting it and getting the actual list
  1.1683 +	TBuf<64> name;
  1.1684 +	TInt ii;
  1.1685 +	for(ii=0;ii<numWinGroups;++ii)
  1.1686 +		{
  1.1687 +		TheClient->iWs.GetWindowGroupNameFromIdentifier((*list)[ii],name);
  1.1688 +	#ifndef DISABLE_FAIL_DIALOG
  1.1689 +		TInt ordinalPos=0;
  1.1690 +		ordinalPos+=ordinalPos;		//To stop a warning
  1.1691 +		ordinalPos=
  1.1692 +	#endif
  1.1693 +			TheClient->iWs.GetWindowGroupOrdinalPriority((*list)[ii]);
  1.1694 +		if (name==KWinName)
  1.1695 +			{
  1.1696 +			isFullRom = ETrue;
  1.1697 +			break;
  1.1698 +			}
  1.1699 +		}
  1.1700 +	delete list;
  1.1701 +	return isFullRom;
  1.1702 +	}
  1.1703 +
  1.1704 +void CTestBase::DelayIfFullRomL()
  1.1705 +	{
  1.1706 +	if (IsFullRomL())
  1.1707 +		User::After(400000);
  1.1708 +	}
  1.1709 +
  1.1710 +TPartialRedrawType CTestBase::RedrawStoreTypeL()
  1.1711 +	{
  1.1712 +/*	if (iRedrawType==EPartialRedraw_Unknown)
  1.1713 +		{
  1.1714 +		const TRgb KRed=TRgb(255,0,0);
  1.1715 +		const TRgb KGreen=TRgb(0,255,0);
  1.1716 +		const TRgb KBlue=TRgb(0,0,255);
  1.1717 +		CWsScreenDevice* scrDev=TheClient->iScreen;
  1.1718 +		TSize winSize=scrDev->SizeInPixels();
  1.1719 +		CBlankWindow* win=new(ELeave) CBlankWindow(KRed);	//Window will be red if WSERV just draws in background color
  1.1720 +		CleanupStack::PushL(win);
  1.1721 +		TDisplayMode mode=EColor256;
  1.1722 +		win->SetUpL(TPoint(),winSize,TheClient->iGroup,*TheClient->iGc,&mode);	//Window is activated
  1.1723 +		win->RealDraw(ETrue);
  1.1724 +		win->SetColor(KGreen);
  1.1725 +		CBlankWindow* win2=new(ELeave) CBlankWindow(KRed);
  1.1726 +		CleanupStack::PushL(win2);
  1.1727 +		win2->SetUpL(TPoint(),winSize,TheClient->iGroup,*TheClient->iGc,&mode);	//New Window completely obscures other window
  1.1728 +		win2->RealDraw(ETrue);
  1.1729 +		win->CTWin::DrawNow();	//Window will be green if drawn from stored commands
  1.1730 +		win2->CTWin::DrawNow();
  1.1731 +		win2->SetVisible(EFalse);
  1.1732 +		TRgb col;
  1.1733 +		scrDev->GetPixel(col,TPoint(5,5));	//Pixel will be red if storing off by default and green otherwise
  1.1734 +		if (col==KRed)
  1.1735 +			{
  1.1736 +			win->Win()->EnableRedrawStore(ETrue);
  1.1737 +			win->CTWin::DrawNow();	//Create stored commands
  1.1738 +			}
  1.1739 +		else
  1.1740 +			__ASSERT_ALWAYS(col==KGreen,AutoPanic(EAutoPanicRedrawStoring));
  1.1741 +		win->SetColor(KBlue);
  1.1742 +		TRect redrawRect(TSize(10,10));
  1.1743 +		win->Invalidate(redrawRect);
  1.1744 +		win->Win()->BeginRedraw(redrawRect);
  1.1745 +		win->DrawNow(redrawRect);	//Top left of Window will be blue if it draws itself
  1.1746 +		win->Win()->EndRedraw();
  1.1747 +		win2->SetVisible(ETrue);
  1.1748 +		win2->SetVisible(EFalse);
  1.1749 +		scrDev->GetPixel(col,TPoint(5,5));	//Pixel will be red if stored commands were lost
  1.1750 +		iRedrawType=EPartialRedraw_None;
  1.1751 +		if (col!=KRed)
  1.1752 +			{
  1.1753 +			__ASSERT_ALWAYS(col==KBlue,AutoPanic(EAutoPanicRedrawStoring));
  1.1754 +			TheClient->WaitForRedrawsToFinish();
  1.1755 +			win2->SetVisible(ETrue);
  1.1756 +			win2->SetVisible(EFalse);
  1.1757 +			scrDev->GetPixel(col,TPoint(15,15));	//Pixel will be blue if partial redraw triggers full redraw
  1.1758 +			iRedrawType=EPartialRedraw_PreserveStoredCmds;
  1.1759 +			if (col!=KBlue)
  1.1760 +				{
  1.1761 +				__ASSERT_ALWAYS(col==KGreen,AutoPanic(EAutoPanicRedrawStoring));
  1.1762 +				iRedrawType=EPartialRedraw_FullRedrawSupport;
  1.1763 +				}
  1.1764 +			}
  1.1765 +		CleanupStack::PopAndDestroy(2,win);
  1.1766 +		}
  1.1767 +	return iRedrawType;*/
  1.1768 +	return EPartialRedraw_FullRedrawSupport;
  1.1769 +	}
  1.1770 +
  1.1771 +void CTestBase::SetUpMember(TSpriteMember &aMember)
  1.1772 +	{
  1.1773 +	aMember.iMaskBitmap=NULL;
  1.1774 +	aMember.iInvertMask=EFalse;
  1.1775 +	aMember.iDrawMode=CGraphicsContext::EDrawModePEN;
  1.1776 +	aMember.iOffset=TPoint();
  1.1777 +	aMember.iInterval=TTimeIntervalMicroSeconds32(0);
  1.1778 +	}
  1.1779 +
  1.1780 +void CTestBase::SimulateKeyDownUpWithModifiers(TInt aScanCode,TUint aModifiers)
  1.1781 +	{
  1.1782 +	if (aModifiers&EModifierAlt)
  1.1783 +		SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftFunc);
  1.1784 +	if (aModifiers&EModifierCtrl)
  1.1785 +		SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftCtrl);
  1.1786 +	if (aModifiers&EModifierShift)
  1.1787 +		SimulateKey(TRawEvent::EKeyDown,EStdKeyLeftShift);
  1.1788 +	SimulateKeyDownUp(aScanCode);
  1.1789 +	if (aModifiers&EModifierShift)
  1.1790 +		SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftShift);
  1.1791 +	if (aModifiers&EModifierCtrl)
  1.1792 +		SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftCtrl);
  1.1793 +	if (aModifiers&EModifierAlt)
  1.1794 +		SimulateKey(TRawEvent::EKeyUp,EStdKeyLeftFunc);
  1.1795 +	}
  1.1796 +
  1.1797 +void CTestBase::SimulateKeyDownUp(TInt aScanCode)
  1.1798 +	{
  1.1799 +	__ASSERT_DEBUG(aScanCode<'a' || aScanCode>'z',AutoPanic(EAutoPanicScanCapital));
  1.1800 +	SimulateKey(TRawEvent::EKeyDown,aScanCode);
  1.1801 +	SimulateKey(TRawEvent::EKeyUp,aScanCode);
  1.1802 +	}
  1.1803 +
  1.1804 +void CTestBase::SimulatePointerDownUp(TInt aX, TInt aY)
  1.1805 +	{
  1.1806 +	SimulatePointer(TRawEvent::EButton1Down,aX,aY);
  1.1807 +	SimulatePointer(TRawEvent::EButton1Up,aX,aY);
  1.1808 +	}
  1.1809 +
  1.1810 +void CTestBase::SimulateKey(TRawEvent::TType aType, TInt aScanCode)
  1.1811 +	{
  1.1812 +	TRawEvent rawEvent;
  1.1813 +	rawEvent.Set(aType,aScanCode);
  1.1814 +	TheClient->iWs.SimulateRawEvent(rawEvent);
  1.1815 +	}
  1.1816 +
  1.1817 +/**
  1.1818 + * Determine if the configuration supports pointer event testing.
  1.1819 + * 
  1.1820 + * There are certain circumstances where we want to skip pointer event
  1.1821 + * testing because we are simulating pointer events, and don't want to
  1.1822 + * simulate a pointer event from an impossible co-ordinate.  We'd rather
  1.1823 + * just identify that there is no point in doing the test and skip over
  1.1824 + * to the next test case.
  1.1825 + * 
  1.1826 + * In particular, when a ROM configured with a digitiser is deployed on a
  1.1827 + * Naviengine, with hardware configuration DIP switches which say that there
  1.1828 + * is an external screen connected, then no touch pad is active.
  1.1829 + * The base port under these conditions returns a digitiser area (0,0,0,0)
  1.1830 + * 
  1.1831 + * @return ETrue if the configuration supports pointer event testing, otherwise
  1.1832 + *         return EFalse.
  1.1833 + */
  1.1834 +TBool CTestBase::ConfigurationSupportsPointerEventTesting() const
  1.1835 +    {
  1.1836 +    if (iNormalPointerCursorArea.IsEmpty())
  1.1837 +        {
  1.1838 +        return EFalse;
  1.1839 +        }
  1.1840 +    return ETrue;
  1.1841 +    }
  1.1842 +
  1.1843 +
  1.1844 +void CTestBase::SimulatePointer(TRawEvent::TType aType, TInt aX, TInt aY)
  1.1845 +	{
  1.1846 +	__ASSERT_DEBUG(ConfigurationSupportsPointerEventTesting(), AutoPanic(EAutoPanicNoDigitiser));
  1.1847 +
  1.1848 +
  1.1849 +#ifdef WSERV_TAUTO_LOG_POINTER_EVENTS
  1.1850 +	TLogMessageText buf;
  1.1851 +	_LIT(KLog,"SimulatePointer  Type=%d  Pos=(%d,%d)");
  1.1852 +	buf.Format(KLog,aType,aX,aY);
  1.1853 +	TheClient->LogMessage(buf);
  1.1854 +#endif
  1.1855 +	
  1.1856 +	TRawEvent rawEvent;
  1.1857 +	rawEvent.Set(aType,aX,aY);
  1.1858 +	TheClient->iWs.SimulateRawEvent(rawEvent);
  1.1859 +	}
  1.1860 +
  1.1861 +void CTestBase::SimulateEvent(TRawEvent::TType aType)
  1.1862 +	{
  1.1863 +	TRawEvent rawEvent;
  1.1864 +	rawEvent.Set(aType);
  1.1865 +	TheClient->iWs.SimulateRawEvent(rawEvent);
  1.1866 +	}
  1.1867 +
  1.1868 +void CTestBase::LogColors(const CBitmapDevice& aDevice,TPoint aBasePoint, TPoint aStartPoint, TPoint aEndPoint)
  1.1869 +	{
  1.1870 +	_LIT(KPixel,"Pixel(%d,%d) R=%d G=%d B=%d");
  1.1871 +	TLogMessageText buf;
  1.1872 +	TBuf8<2560> screen;
  1.1873 +	const TRgb* pixel;
  1.1874 +	if (aStartPoint.iX==aEndPoint.iX)
  1.1875 +		++aEndPoint.iX;
  1.1876 +	if (aStartPoint.iY==aEndPoint.iY)
  1.1877 +		++aEndPoint.iY;
  1.1878 +	TInt width=aEndPoint.iX-aStartPoint.iX;
  1.1879 +	TInt xx,yy;
  1.1880 +	for (yy=aStartPoint.iY;yy<aEndPoint.iY;++yy)
  1.1881 +		{
  1.1882 +		xx=aStartPoint.iX;
  1.1883 +		aDevice.GetScanLine(screen,aBasePoint+TPoint(xx,yy),width,ERgb);
  1.1884 +		pixel=REINTERPRET_CAST(const TRgb*,screen.Ptr());
  1.1885 +		for (;xx<aEndPoint.iX;++xx,++pixel)
  1.1886 +			{
  1.1887 +			buf.Format(KPixel,xx,yy,pixel->Red(),pixel->Green(),pixel->Blue());
  1.1888 +			//RDebug::Print(buf);
  1.1889 +			TheClient->iWs.LogMessage(buf);
  1.1890 +			}
  1.1891 +		}
  1.1892 +	TheClient->iWs.Flush();
  1.1893 +	}
  1.1894 +
  1.1895 +void CTestBase::LogColors4(const CBitmapDevice& aDevice,TPoint aStartPoint,TInt aLen)
  1.1896 +	{
  1.1897 +	_LIT(KValue,"Pixel(%d,%d)  Byte %d,  Value %d");
  1.1898 +	TLogMessageText buf;
  1.1899 +	TBuf8<2560> screen;
  1.1900 +	aDevice.GetScanLine(screen,aStartPoint,aLen,EGray4);
  1.1901 +	TInt len=(aLen+3)/4;
  1.1902 +	TInt ii;
  1.1903 +	for (ii=0;ii<len;++ii,aStartPoint.iX+=4)
  1.1904 +		{
  1.1905 +		buf.Format(KValue,aStartPoint.iX,aStartPoint.iY,ii,screen[ii]);
  1.1906 +		TheClient->iWs.LogMessage(buf);
  1.1907 +		}
  1.1908 +	}
  1.1909 +
  1.1910 +void CTestBase::UpdateTestResults(TInt aNoOfTest, TInt aNoOfTestPass)
  1.1911 +	{
  1.1912 +	iNumberTests+=aNoOfTest;
  1.1913 +	iNumberTestsPass+=aNoOfTestPass;
  1.1914 +	}
  1.1915 +
  1.1916 +TInt CTestBase::SaveScreen(const TDesC& aFileName)
  1.1917 +	{
  1.1918 +	return SaveScreen(aFileName,TheClient->iScreen->SizeInPixels(),TheClient->iScreen->DisplayMode());
  1.1919 +	}
  1.1920 +
  1.1921 +TInt CTestBase::SaveScreen(const TDesC& aFileName,const TSize& aScreenSize,TDisplayMode aColorDepth)
  1.1922 +	{
  1.1923 +	TRAPD(err,SaveScreenL(aFileName,aScreenSize,aColorDepth));
  1.1924 +	return err;
  1.1925 +	}
  1.1926 +
  1.1927 +void CTestBase::SaveScreenL(const TDesC& aFileName,const TSize& aScreenSize,TDisplayMode aColorDepth)
  1.1928 +	{
  1.1929 +	CBitmap* copyOfScreen=CBitmap::NewLC(aScreenSize,aColorDepth);
  1.1930 +	CFbsScreenDevice* scrDevice=CFbsScreenDevice::NewL(iScreenNumber,aColorDepth);
  1.1931 +	CleanupStack::PushL(scrDevice);
  1.1932 +	CFbsBitGc* gc;
  1.1933 +	User::LeaveIfError(scrDevice->CreateContext(gc));
  1.1934 +	CleanupStack::PushL(gc);
  1.1935 +	copyOfScreen->Gc().BitBlt(TPoint(),*gc);
  1.1936 +	User::LeaveIfError(copyOfScreen->Bitmap().Save(aFileName));
  1.1937 +	CleanupStack::PopAndDestroy(3,copyOfScreen);
  1.1938 +	}
  1.1939 +
  1.1940 +
  1.1941 +/*CProcess*/
  1.1942 +_LIT(KScreenTag,"Screen");
  1.1943 +
  1.1944 +void CProcess::GetProcArg(const TWinCommand& aParam,TBufArg& aProcArg)
  1.1945 +	{
  1.1946 +	TInt pos = aParam.Find(KScreenTag);
  1.1947 +	if (pos!=KErrNotFound)
  1.1948 +		aProcArg = aParam.Left(pos-1);
  1.1949 +	else
  1.1950 +		aProcArg = aParam;
  1.1951 +	}
  1.1952 +
  1.1953 +void CProcess::GetScreenArg(const TWinCommand& aParam, TInt& aScreenArg)
  1.1954 +	{
  1.1955 +	TInt pos = aParam.Find(KScreenTag);
  1.1956 +	if (pos!=KErrNotFound)
  1.1957 +		{
  1.1958 +		TBufArg secondArg(aParam.Right(aParam.Length()-pos));
  1.1959 +		if (secondArg.Length()>6)
  1.1960 +			{
  1.1961 +			TBuf<1> digit(secondArg.Mid(6,1));
  1.1962 +			TLex lex(digit);
  1.1963 +			lex.Val(aScreenArg);
  1.1964 +			}
  1.1965 +		}
  1.1966 +	}
  1.1967 +
  1.1968 +TInt CProcess::Start(const TWinCommand& aParam)
  1.1969 +	{
  1.1970 +	// parse command line aParam to retrieve value of
  1.1971 +	// screen number if it is specified
  1.1972 +	//
  1.1973 +	// command line format: <process-id> [screen<id>]
  1.1974 +	//
  1.1975 +	TBufArg procArg(_L(""));
  1.1976 +	TInt screenArg = KDefaultScreen;
  1.1977 +
  1.1978 +	GetProcArg(aParam, procArg);
  1.1979 +	GetScreenArg(aParam, screenArg);
  1.1980 +
  1.1981 +	TInt ii;
  1.1982 +	for(ii=0;ii<eNumProcessCalls;ii++)
  1.1983 +		{
  1.1984 +		if (procArg==iFunctions[ii].iParam)
  1.1985 +			{
  1.1986 +			TRAPD(ret,iFunctions[ii].iFunction((TAny*)screenArg));
  1.1987 +
  1.1988 +			// need to pass test result to owning process
  1.1989 +			// for multiple display test
  1.1990 +			if (ii==eProcessMultiDisplayTest)
  1.1991 +				ret = TheTestResult;
  1.1992 +
  1.1993 +			return ret;
  1.1994 +			}
  1.1995 +		}
  1.1996 +
  1.1997 +	return KErrNone;		//Shouldn't get here
  1.1998 +	}
  1.1999 +
  1.2000 +CProcess* CProcess::NewL(TInt aFunctionNo,TInt aScreenNumber)
  1.2001 +	{
  1.2002 +	CProcess* self=new(ELeave) CProcess();
  1.2003 +	CleanupStack::PushL(self);
  1.2004 +	self->ConstructL(aFunctionNo,aScreenNumber);
  1.2005 +	CleanupStack::Pop(self);
  1.2006 +	return self;
  1.2007 +	}
  1.2008 +
  1.2009 +CProcess* CProcess::NewTL(TInt aFunctionNo,TInt aScreenNumber,TRequestStatus* aStatus /*=NULL*/)
  1.2010 +	{
  1.2011 +	CProcess* self=new(ELeave) CProcess();
  1.2012 +	CleanupStack::PushL(self);
  1.2013 +	self->ConstructTL(aFunctionNo,aScreenNumber,aStatus);
  1.2014 +	CleanupStack::Pop(self);
  1.2015 +	return self;
  1.2016 +	}
  1.2017 +
  1.2018 +CProcess* CProcess::NewThreadL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr
  1.2019 +																						,TRequestStatus* aStatus)
  1.2020 +	{
  1.2021 +	CProcess* self=new(ELeave) CProcess();
  1.2022 +	CleanupStack::PushL(self);
  1.2023 +	self->ConstructL(aName,aFunction,aPtr,aStatus);
  1.2024 +	CleanupStack::Pop(self);
  1.2025 +	return self;
  1.2026 +	}
  1.2027 +
  1.2028 +CProcess* CProcess::NewThreadRendezvousL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr ,TRequestStatus* aLogonStatus,TRequestStatus& aRendesvouzStatus)
  1.2029 +    {
  1.2030 +    CProcess* self=new(ELeave) CProcess();
  1.2031 +    CleanupStack::PushL(self);
  1.2032 +    self->ConstructRendezvousL(aName,aFunction,aPtr,aLogonStatus,aRendesvouzStatus);
  1.2033 +    CleanupStack::Pop(self);
  1.2034 +    return self;
  1.2035 +    }
  1.2036 +
  1.2037 +CProcess* CProcess::NewThreadRendezvousL(const TDesC& aName,TThreadStartUp* aPtr,TRequestStatus& aRendesvouzStatus)
  1.2038 +    {
  1.2039 +    return NewThreadRendezvousL(aName,ThreadInit,aPtr,NULL,aRendesvouzStatus);
  1.2040 +    }
  1.2041 +
  1.2042 +CProcess* CProcess::NewThreadL(const TDesC& aName,TThreadStartUp* aPtr)
  1.2043 +	{
  1.2044 +	return NewThreadL(aName,ThreadInit,aPtr,NULL);
  1.2045 +	}
  1.2046 +
  1.2047 +CProcess* CProcess::NewSimpleThreadL(const TDesC& aName,TThreadStartUp* aPtr,TRequestStatus* aStatus/*=NULL*/)
  1.2048 +	{
  1.2049 +	return NewThreadL(aName,SimpleThreadInit,aPtr,aStatus);
  1.2050 +	}
  1.2051 +
  1.2052 +_LIT(KSpace," ");
  1.2053 +_LIT(KScreenFormat,"%d");
  1.2054 +
  1.2055 +void CProcess::ConstructL(TInt aFunctionNo,TInt aScreenNumber/*=KDefaultScreen*/)
  1.2056 +	{
  1.2057 +	Close();
  1.2058 +	// add screen number into command line param
  1.2059 +	// format: <proc-id> [screen<id>]
  1.2060 +	//
  1.2061 +	TBuf<100> commandLine;
  1.2062 +
  1.2063 +	commandLine = iFunctions[aFunctionNo].iParam;
  1.2064 +	commandLine.Append(KSpace);
  1.2065 +	commandLine.Append(KScreenTag);
  1.2066 +	commandLine.AppendFormat(KScreenFormat,aScreenNumber);
  1.2067 +	User::LeaveIfError(iOther.Create(RProcess().FileName(),commandLine));
  1.2068 +	iCreated|=eOtherCreated;
  1.2069 +	iOther.Resume();
  1.2070 +	}
  1.2071 +
  1.2072 +void CProcess::ConstructTL(TInt aFunctionNo,TInt aScreenNumber/*=KDefaultScreen*/,TRequestStatus* aStatus)
  1.2073 +	{
  1.2074 +	Close();
  1.2075 +	TUint flag=eThreadCreated;
  1.2076 +	TInt err=iThread.Create(iFunctions[aFunctionNo].iParam,iFunctions[aFunctionNo].iFunction
  1.2077 +													,KDefaultStackSize,KOtherProcHeapSize,KOtherProcHeapSize,(TAny*)aScreenNumber,EOwnerThread);
  1.2078 +	User::LeaveIfError(err);
  1.2079 +	iCreated|=flag;
  1.2080 +	if (aStatus)
  1.2081 +		Logon(*aStatus);
  1.2082 +	iThread.Resume();
  1.2083 +	}
  1.2084 +
  1.2085 +
  1.2086 +void CProcess::ConstructL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr,TRequestStatus* aStatus)
  1.2087 +	{
  1.2088 +	Close();
  1.2089 +	User::LeaveIfError(iThread.Create(aName,aFunction,KDefaultStackSize,KOtherProcHeapSize,KOtherProcHeapSize,aPtr,EOwnerThread));
  1.2090 +	iCreated|=eThreadCreated;
  1.2091 +	if (aStatus)
  1.2092 +		Logon(*aStatus);
  1.2093 +	iThread.Resume();
  1.2094 +	}
  1.2095 +
  1.2096 +void CProcess::ConstructRendezvousL(const TDesC& aName,TThreadFunction aFunction,TThreadStartUp* aPtr,TRequestStatus* aLogonStatus,TRequestStatus& aRendezvousStatus)
  1.2097 +    {
  1.2098 +    Close();
  1.2099 +    User::LeaveIfError(iThread.Create(aName,aFunction,KDefaultStackSize,KOtherProcHeapSize,KOtherProcHeapSize,aPtr,EOwnerThread));
  1.2100 +    iCreated|=eThreadCreated;
  1.2101 +    if (aLogonStatus)
  1.2102 +        Logon(*aLogonStatus);
  1.2103 +
  1.2104 +    iThread.Rendezvous(aRendezvousStatus);     
  1.2105 +    iThread.Resume();
  1.2106 +    }
  1.2107 +
  1.2108 +void CProcess::Logon(TRequestStatus& aStatus) const
  1.2109 +	{
  1.2110 +	if (iCreated&eThreadCreated)
  1.2111 +		iThread.Logon(aStatus);
  1.2112 +	else
  1.2113 +		{
  1.2114 +		iOther.Logon(aStatus);
  1.2115 +		}
  1.2116 +	}
  1.2117 +
  1.2118 +void CProcess::Terminate(TInt aReason)
  1.2119 +	{
  1.2120 +	if (iCreated&eThreadCreated)
  1.2121 +		iThread.Terminate(aReason);
  1.2122 +	else
  1.2123 +		{
  1.2124 +		iOther.Terminate(aReason);
  1.2125 +		}
  1.2126 +	Close();
  1.2127 +	}
  1.2128 +
  1.2129 +void CProcess::Close()
  1.2130 +	{
  1.2131 +	if (iCreated&eOtherCreated)
  1.2132 +		iOther.Close();
  1.2133 +	if (iCreated&eThreadCreated)
  1.2134 +		iThread.Close();
  1.2135 +	iCreated=0;
  1.2136 +	}
  1.2137 +
  1.2138 +CProcess::~CProcess()
  1.2139 +	{
  1.2140 +	Close();
  1.2141 +	}
  1.2142 +
  1.2143 +TBool CProcess::StillAlive()
  1.2144 +	{
  1.2145 +	if (iCreated&eOtherCreated)
  1.2146 +		return iOther.ExitType()==EExitPending;
  1.2147 +	return iThread.ExitType()==EExitPending;
  1.2148 +	}
  1.2149 +
  1.2150 +void CProcess::LeaveIfDied()		//Can Leave
  1.2151 +	{
  1.2152 +	User::After(200000);		//0.2 secs
  1.2153 +	if (StillAlive())
  1.2154 +		return;
  1.2155 +	if (iCreated&eOtherCreated)
  1.2156 +		User::Leave(iOther.ExitReason());
  1.2157 +	User::Leave(iThread.ExitReason());
  1.2158 +	}
  1.2159 +
  1.2160 +const TInt KFirstInstanceId = 1;
  1.2161 +const TInt KOtherInstanceId = 2;
  1.2162 +
  1.2163 +TBool CProcess::ProcessDied(TInt aScreenNo/*=KDefaultScreen*/)
  1.2164 +	{
  1.2165 +	_LIT(pName,"TAutoServer*");
  1.2166 +	TFindProcess find(pName);
  1.2167 +	TFullName name;
  1.2168 +
  1.2169 +	TBool found = EFalse;
  1.2170 +	TInt instanceId = aScreenNo==KDefaultScreen? KFirstInstanceId : KOtherInstanceId;
  1.2171 +	// find the correct instance of the process
  1.2172 +	// required in multi display test
  1.2173 +	while (!found && find.Next(name)==KErrNone)
  1.2174 +		{
  1.2175 +		TPtrC scrId = name.Right(1);
  1.2176 +		TInt id;
  1.2177 +		TLex lex(scrId);
  1.2178 +		lex.Val(id);
  1.2179 +		if (id==instanceId)
  1.2180 +			found = ETrue;
  1.2181 +		}
  1.2182 +	if (!found)
  1.2183 +		return EFalse;
  1.2184 +
  1.2185 +	RProcess p;
  1.2186 +	p.Open(name);
  1.2187 +	if (p.Id()!=RProcess().Id())
  1.2188 +		return EFalse;
  1.2189 +	p.Close();
  1.2190 +	return (find.Next(name)!=KErrNone);
  1.2191 +	}
  1.2192 +
  1.2193 +TInt CProcess::ThreadInit(TAny *aPtr)
  1.2194 +	{
  1.2195 +	__UHEAP_MARK;
  1.2196 +	TInt err=KErrNone;
  1.2197 +	CTrapCleanup* CleanUpStack=CTrapCleanup::New();
  1.2198 +	if (CleanUpStack==NULL)
  1.2199 +		err=KErrNoMemory;
  1.2200 +	else
  1.2201 +		{
  1.2202 +		TRAP(err,InitialiseL(STATIC_CAST(TThreadStartUp*,aPtr)))
  1.2203 +		delete CleanUpStack;
  1.2204 +		}
  1.2205 +	__UHEAP_MARKEND;
  1.2206 +	return(err);
  1.2207 +	}
  1.2208 +
  1.2209 +void CProcess::InitialiseL(TThreadStartUp* aPtr)
  1.2210 +	{
  1.2211 +	CActiveScheduler* activeScheduler=new(ELeave) CActiveScheduler;
  1.2212 +	CActiveScheduler::Install(activeScheduler);
  1.2213 +	CleanupStack::PushL(activeScheduler);
  1.2214 +	aPtr->iInitFunction(aPtr->iParam);
  1.2215 +	CActiveScheduler::Start();
  1.2216 +	CleanupStack::PopAndDestroy(activeScheduler);
  1.2217 +	}
  1.2218 +
  1.2219 +TInt CProcess::SimpleThreadInit(TAny *aPtr)
  1.2220 +	{
  1.2221 +	__UHEAP_MARK;
  1.2222 +	TInt err=KErrNone;
  1.2223 +	CTrapCleanup* CleanUpStack=CTrapCleanup::New();
  1.2224 +	if (CleanUpStack==NULL)
  1.2225 +		err=KErrNoMemory;
  1.2226 +	else
  1.2227 +		{
  1.2228 +		TThreadStartUp* ptr=STATIC_CAST(TThreadStartUp*,aPtr);
  1.2229 +		ptr->iInitFunction(ptr->iParam);
  1.2230 +		delete CleanUpStack;
  1.2231 +		}
  1.2232 +	__UHEAP_MARKEND;
  1.2233 +	return(err);
  1.2234 +	}
  1.2235 +
  1.2236 +/*CMinWin*/
  1.2237 +
  1.2238 +CMinWin::CMinWin(TInt aScreenNo): iScreenNo(aScreenNo)
  1.2239 +	{}
  1.2240 +
  1.2241 +void CMinWin::ConstructL()
  1.2242 +	{
  1.2243 +	User::LeaveIfError(iWs.Connect());
  1.2244 +	iScr=new(ELeave) CWsScreenDevice(iWs);
  1.2245 +	User::LeaveIfError(iScr->Construct(iScreenNo));
  1.2246 +	iGroup=RWindowGroup(iWs);
  1.2247 +	User::LeaveIfError(iGroup.Construct(8970+iScreenNo,ETrue));
  1.2248 +	iWin=RWindow(iWs);
  1.2249 +	User::LeaveIfError(iWin.Construct((RWindowTreeNode)iGroup,(TUint32)this));
  1.2250 +	iRect=TSize(10,10);
  1.2251 +	iWin.SetExtent(TPoint(0,0),iRect.Size());
  1.2252 +	iWin.SetRequiredDisplayMode(EColor256);
  1.2253 +	iWin.SetBackgroundColor(KRgbGreen);
  1.2254 +	iWin.Activate();
  1.2255 +	iGc=new(ELeave) CWindowGc(iScr);
  1.2256 +	User::LeaveIfError(iGc->Construct());
  1.2257 +
  1.2258 +	Draw(iRect);
  1.2259 +	iWs.Flush();
  1.2260 +	}
  1.2261 +
  1.2262 +CMinWin::~CMinWin()
  1.2263 +	{
  1.2264 +	delete iGc;
  1.2265 +	iWin.Close();
  1.2266 +	iGroup.Close();
  1.2267 +	delete iScr;
  1.2268 +	iWs.Close();
  1.2269 +	}
  1.2270 +
  1.2271 +void CMinWin::Draw(const TRect& aRect)
  1.2272 +	{
  1.2273 +	iWin.BeginRedraw();
  1.2274 +	iGc->Activate(iWin);
  1.2275 +	iGc->SetPenStyle(CGraphicsContext::ENullPen);
  1.2276 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2277 +	iGc->SetBrushColor(KRgbGreen);
  1.2278 +	iGc->DrawRect(aRect);
  1.2279 +	iGc->Deactivate();
  1.2280 +	iWin.EndRedraw();
  1.2281 +	}
  1.2282 +
  1.2283 +
  1.2284 +/*CTimeOut*/
  1.2285 +
  1.2286 +void CTimeOut::ConstructL()
  1.2287 +	{
  1.2288 +	CTimer::ConstructL();
  1.2289 +	CActiveScheduler::Add(this);
  1.2290 +	}
  1.2291 +
  1.2292 +void CTimeOut::Start(TTimeIntervalMicroSeconds32 aInterval,TCallBack aCallBack)
  1.2293 +	{
  1.2294 +	iCallBack=aCallBack;
  1.2295 +	After(aInterval);
  1.2296 +	}
  1.2297 +
  1.2298 +void CTimeOut::RunL()
  1.2299 +	{
  1.2300 +	iCallBack.CallBack();
  1.2301 +	}
  1.2302 +
  1.2303 +/* 
  1.2304 + * Simply returns the DisplayMode as a string. Used to display mode details on test results. 
  1.2305 + */
  1.2306 +GLDEF_C TPtrC DisplayModeAsString(TDisplayMode aMode)
  1.2307 +	{
  1.2308 +	
  1.2309 +	TPtrC modeAsString;
  1.2310 +	
  1.2311 +	switch(aMode)
  1.2312 +		{
  1.2313 +		case ENone:
  1.2314 +			_LIT(KENoneMode,"ENone");
  1.2315 +			modeAsString.Set(KENoneMode);
  1.2316 +			break;
  1.2317 +		case EGray2: 
  1.2318 +			_LIT(KEGray2Mode,"EGray2");
  1.2319 +			modeAsString.Set(KEGray2Mode);
  1.2320 +			break;
  1.2321 +		case EGray4:
  1.2322 +			_LIT(KEGray4Mode,"EGray4");
  1.2323 +			modeAsString.Set(KEGray4Mode);
  1.2324 +			break;
  1.2325 +		case EGray16:
  1.2326 +			_LIT(KEGray16Mode,"EGray16");
  1.2327 +			modeAsString.Set(KEGray16Mode);
  1.2328 +			break;
  1.2329 +		case EGray256:
  1.2330 +			_LIT(KEGray256Mode,"EGray256");
  1.2331 +			modeAsString.Set(KEGray256Mode);
  1.2332 +			break;
  1.2333 +		case EColor16:
  1.2334 +			_LIT(KEColor16Mode,"EColor16");
  1.2335 +			modeAsString.Set(KEColor16Mode);
  1.2336 +			break;
  1.2337 +		case EColor256:
  1.2338 +			_LIT(KEColor256Mode,"EColor256");
  1.2339 +			modeAsString.Set(KEColor256Mode);
  1.2340 +			break;
  1.2341 +		case EColor64K:
  1.2342 +			_LIT(KEColor64KMode,"EColor64K");
  1.2343 +			modeAsString.Set(KEColor64KMode);
  1.2344 +			break;
  1.2345 +		case EColor16M:
  1.2346 +			_LIT(KEColor16MMode,"EColor16M");
  1.2347 +			modeAsString.Set(KEColor16MMode);
  1.2348 +			break;
  1.2349 +		case EColor4K:
  1.2350 +			_LIT(KEColor4KMode,"EColor4K");
  1.2351 +			modeAsString.Set(KEColor4KMode);
  1.2352 +			break;
  1.2353 +		case EColor16MU:
  1.2354 +			_LIT(KEColor16MUMode,"EColor16MU");
  1.2355 +			modeAsString.Set(KEColor16MUMode);
  1.2356 +			break;
  1.2357 +		case EColor16MA:
  1.2358 +			_LIT(KEColor16MAMode,"EColor16MA");
  1.2359 +			modeAsString.Set(KEColor16MAMode);
  1.2360 +			break;
  1.2361 +		case EColor16MAP:
  1.2362 +			_LIT(KEColor16MAPMode,"EColor16MAP");
  1.2363 +			modeAsString.Set(KEColor16MAPMode);
  1.2364 +			break;
  1.2365 +		default:
  1.2366 +			_LIT(KUnknownMode,"Unknown");
  1.2367 +			modeAsString.Set(KUnknownMode);
  1.2368 +			break;
  1.2369 +		}
  1.2370 +	
  1.2371 +	return modeAsString;
  1.2372 +	}
  1.2373 +
  1.2374 +// Check if an area of a bitmap is of a certain color
  1.2375 +GLDEF_C TBool LossyCheckBlankBitmap(const CFbsBitmap& aBitmap, const TRect aArea, const TRgb aCheckColor, TBool aLossyCompare)
  1.2376 +	{
  1.2377 +	const TReal errorLimit = (aLossyCompare ? 0.05 : 0.00); //Lossy(default) or exact compare?
  1.2378 +	
  1.2379 +	TBool result = ETrue;
  1.2380 +	/* TInt mismatchedPixels = 0; */ // -- Useful for debugging
  1.2381 +	TRgb bitmapPix = TRgb(0,0,0,0); //testWin Pixel
  1.2382 +	for (TInt x = 0; x < aArea.Size().iWidth; x++)
  1.2383 +		{
  1.2384 +		for (TInt y = 0; y < aArea.Size().iHeight; y++)
  1.2385 +			{
  1.2386 +			aBitmap.GetPixel(bitmapPix, TPoint(x,y));
  1.2387 +			
  1.2388 +			//Check if there are differeces in color between the bitmap and the test color
  1.2389 +			if(((TReal)abs(bitmapPix.Red() - aCheckColor.Red())/255) > errorLimit || 
  1.2390 +					((TReal)abs(bitmapPix.Blue() - aCheckColor.Blue())/255) > errorLimit || 
  1.2391 +					((TReal)abs(bitmapPix.Green() - aCheckColor.Green())/255) > errorLimit || 
  1.2392 +					((TReal)abs(bitmapPix.Alpha() - aCheckColor.Alpha())/255) > errorLimit)
  1.2393 +				{
  1.2394 +				/* mismatchedPixels++; */ // -- Useful for debugging
  1.2395 +				result = EFalse;
  1.2396 +				break;
  1.2397 +				}
  1.2398 +			}
  1.2399 +		}
  1.2400 +	
  1.2401 +	/* INFO_PRINTF2(_L("Number of different pixels: %i"), mismatchedPixels); */ // -- Useful for debugging
  1.2402 +	return result;
  1.2403 +	}
  1.2404 +
  1.2405 +// Compare a section of two bitmaps
  1.2406 +GLDEF_C TBool LossyCompareBitmap(const CFbsBitmap& aBitmap1, const CFbsBitmap& aBitmap2, const TRect aCompareRect, TBool aLossyCompare)
  1.2407 +	{
  1.2408 +	const TReal errorLimit = (aLossyCompare ? 0.05 : 0.00); //Lossy or Exact compare?
  1.2409 +	
  1.2410 +	TBool result = ETrue;
  1.2411 +
  1.2412 +	if (aBitmap1.DisplayMode() != aBitmap2.DisplayMode())
  1.2413 +		{
  1.2414 +		RDebug::Printf(" DisplayMode difference %d, %d", aBitmap1.DisplayMode(), aBitmap2.DisplayMode());
  1.2415 +		}
  1.2416 +	
  1.2417 +	TRgb bitmap1Pix = TRgb(0,0,0,0);
  1.2418 +	TRgb bitmap2Pix = TRgb(0,0,0,0);
  1.2419 +	for (TInt x = 0; x < aCompareRect.Size().iWidth; x++)
  1.2420 +		{
  1.2421 +		for (TInt y = 0; y < aCompareRect.Size().iHeight; y++)
  1.2422 +			{
  1.2423 +			aBitmap1.GetPixel(bitmap1Pix, TPoint(x,y));
  1.2424 +			aBitmap2.GetPixel(bitmap2Pix, TPoint(x,y));
  1.2425 +						
  1.2426 +			//Check if there are differences between the colors of the two bitmaps
  1.2427 +			if(((TReal)abs(bitmap1Pix.Red() - bitmap2Pix.Red())/255) > errorLimit || 
  1.2428 +					((TReal)abs(bitmap1Pix.Blue() - bitmap2Pix.Blue())/255) > errorLimit || 
  1.2429 +					((TReal)abs(bitmap1Pix.Green() - bitmap2Pix.Green())/255) > errorLimit || 
  1.2430 +					((TReal)abs(bitmap1Pix.Alpha() - bitmap2Pix.Alpha())/255) > errorLimit)
  1.2431 +				{
  1.2432 +				/*
  1.2433 +				 * There was a difference so return without checking the rest of the
  1.2434 +				 * bitmap.  If you are seeing Lossy compare errors, and want to diagnose
  1.2435 +				 * further, consider switching over to using a recording version of this
  1.2436 +				 * function, LossyCompareBitmapRecord()
  1.2437 +				 */
  1.2438 +				result = EFalse;
  1.2439 +				break;
  1.2440 +				}
  1.2441 +			}
  1.2442 +		}
  1.2443 +	
  1.2444 +	return result;
  1.2445 +	}
  1.2446 +
  1.2447 +/**
  1.2448 + * Compare two bitmaps, optionally a lossy comparison, recording any differences and saving bitmaps
  1.2449 + * 
  1.2450 + * @param	aBitmap1			Bitmap being checked
  1.2451 + * @param	aBitmap2			Reference Bitmap
  1.2452 + * @param	aCompareRect		Area of bitmap to compare
  1.2453 + * @param	aLossyCompare		ETrue means use a lossy compare strategy, else do an exact compare
  1.2454 + * @param	aPixelsDifferent	Returned value representing the number of pixels which are different
  1.2455 + * @param	aLogger				Facility for logging to be reported by this function
  1.2456 + * @return						ETrue if the bitmaps are the same (or similar).
  1.2457 + * 								Otherwise EFalse, with logging reporting the differences, and bitmaps saved in c:\logs\
  1.2458 + * @pre 						c:\logs directory must exist
  1.2459 + */
  1.2460 +GLDEF_C TBool LossyCompareBitmapRecord(CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2, const TRect aCompareRect, TBool aLossyCompare, TInt& aPixelsDifferent, CTestExecuteLogger& aLogger)
  1.2461 +	{
  1.2462 +	const TReal errorLimit = (aLossyCompare ? 0.05 : 0.00); //Lossy or Exact compare?
  1.2463 +	
  1.2464 +	TBool result = ETrue;
  1.2465 +	TInt mismatchedPixels = 0;
  1.2466 +	TRgb bitmap1Pix = TRgb(0,0,0,0);
  1.2467 +	TRgb bitmap2Pix = TRgb(0,0,0,0);
  1.2468 +	if (aBitmap1.DisplayMode() != aBitmap2.DisplayMode())
  1.2469 +		{
  1.2470 +		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
  1.2471 +				_L(" DisplayMode difference %d, %d"), aBitmap1.DisplayMode(), aBitmap2.DisplayMode());
  1.2472 +		}
  1.2473 +	for (TInt x = 0; x < aCompareRect.Size().iWidth; x++)
  1.2474 +		{
  1.2475 +		for (TInt y = 0; y < aCompareRect.Size().iHeight; y++)
  1.2476 +			{
  1.2477 +			aBitmap1.GetPixel(bitmap1Pix, TPoint(x,y));
  1.2478 +			aBitmap2.GetPixel(bitmap2Pix, TPoint(x,y));
  1.2479 +						
  1.2480 +			//Check if there are differences between the colors of the two bitmaps
  1.2481 +			if(((TReal)abs(bitmap1Pix.Red() - bitmap2Pix.Red())/255) > errorLimit || 
  1.2482 +					((TReal)abs(bitmap1Pix.Blue() - bitmap2Pix.Blue())/255) > errorLimit || 
  1.2483 +					((TReal)abs(bitmap1Pix.Green() - bitmap2Pix.Green())/255) > errorLimit || 
  1.2484 +					((TReal)abs(bitmap1Pix.Alpha() - bitmap2Pix.Alpha())/255) > errorLimit)
  1.2485 +				{
  1.2486 +				mismatchedPixels++;
  1.2487 +				
  1.2488 +				aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
  1.2489 +						_L(" Pixel difference %d,%d: %d"),x,y, bitmap1Pix.Difference(bitmap2Pix));
  1.2490 +				result = EFalse;
  1.2491 +				// we loop around again to pick up all the differences
  1.2492 +				}
  1.2493 +			}
  1.2494 +		}
  1.2495 +	aPixelsDifferent = mismatchedPixels;
  1.2496 +	
  1.2497 +	/*
  1.2498 +	 * When the bitmaps are different, we store them locally in c:\\logs in
  1.2499 +	 * timestamped files.  Save() is a non-const method; this is why aBitmap1
  1.2500 +	 * and aBitmap2 are non-const.  Saving can fail, perhaps because we have
  1.2501 +	 * exceeded storage limits.
  1.2502 +	 */
  1.2503 +	if (!result) 
  1.2504 +		{
  1.2505 +		TTime now;
  1.2506 +		now.UniversalTime();
  1.2507 +		TInt timestamp = I64INT(now.Int64() & 0x7fffffffu);
  1.2508 +		timestamp/=1000; // a millisecond resolution is easier to track
  1.2509 +		TFileName mbmFileSrc;
  1.2510 +		mbmFileSrc.Format (_L("c:\\logs\\%d_LossyCompareBitmap1.mbm"), timestamp);
  1.2511 +		TFileName mbmFileDst;
  1.2512 +		mbmFileDst.Format (_L("c:\\logs\\%d_LossyCompareBitmap2.mbm"), timestamp); 
  1.2513 +		TInt saveResult1;
  1.2514 +		TInt saveResult2;
  1.2515 +		saveResult1 = aBitmap1.Save(mbmFileSrc);
  1.2516 +		saveResult2 = aBitmap2.Save(mbmFileDst);		
  1.2517 +		if (saveResult1 == KErrNone && saveResult2 == KErrNone)
  1.2518 +			{
  1.2519 +			aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
  1.2520 +						_L(" Bitmaps are different: see %S, %S"), &mbmFileSrc, &mbmFileDst);				
  1.2521 +			}
  1.2522 +		else
  1.2523 +			{
  1.2524 +			aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo,
  1.2525 +						_L(" Bitmaps are different, but could not save files into c:\\logs : %d %d"), saveResult1, saveResult2);
  1.2526 +			}
  1.2527 +		}
  1.2528 +
  1.2529 +	return result;
  1.2530 +	}
  1.2531 +
  1.2532 +// Check if an area of a screen is of a certain color
  1.2533 +GLDEF_C TBool LossyCheckBlankWindow(const CWsScreenDevice& aScreen, CFbsBitmap& aBitmap, const TRect aArea, const TRgb aCheckColor)
  1.2534 +	{
  1.2535 +	aScreen.CopyScreenToBitmap(&aBitmap, aArea);
  1.2536 +	return LossyCheckBlankBitmap(aBitmap, aArea, aCheckColor);
  1.2537 +	}
  1.2538 +
  1.2539 +// Compare a section of two windows on the screen
  1.2540 +GLDEF_C TBool LossyCompareWindow(const CWsScreenDevice& aScreen, CFbsBitmap& aBitmap1, CFbsBitmap& aBitmap2, const TRect aCompareRect)
  1.2541 +	{
  1.2542 +	aScreen.CopyScreenToBitmap(&aBitmap1, aCompareRect);
  1.2543 +	aScreen.CopyScreenToBitmap(&aBitmap2, aCompareRect);
  1.2544 +	return LossyCompareBitmap(aBitmap1, aBitmap2, aCompareRect);
  1.2545 +	}
  1.2546 +