os/graphics/windowing/windowserver/test/tauto/TWSGRAPHS.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/TWSGRAPHS.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2593 @@
     1.4 +// Copyright (c) 2006-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 +// This test step contains a series of tests cases to validate the correct behaviour of PREQ1246 implementation.
    1.18 +// In order to create these test cases, basic implementations of the objects involved in this PREQ will be created,
    1.19 +// .i.e. CWsGraphic-derived objects (generically named CWsGraphicTest) and CWsGraphicDrawer-derived objects
    1.20 +// (generically named CWsGraphicDrawerTest).
    1.21 +// Actual construction is performed by a UI-specific entity such as a theme manager. The test code shall replace
    1.22 +// that theme manager functionality, in terms of being the test code who owns a collection of CWsGraphicTest
    1.23 +// objects.
    1.24 +// 
    1.25 +//
    1.26 +
    1.27 +/**
    1.28 + @file
    1.29 + @test
    1.30 + @internalComponent - Internal Symbian test code
    1.31 +*/
    1.32 +
    1.33 +#include "TWSGRAPHS.H"
    1.34 +#include "../inc/WSGRAPHICDRAWERARRAY.H"
    1.35 +#include "../../nga/graphicdrawer/panics.h"
    1.36 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
    1.37 +#include "wsbufferdrawer.h"
    1.38 +#endif
    1.39 +
    1.40 +_LIT(KTestExe, "TWSGRAPHICTEST.exe");
    1.41 +_LIT(KSpace, " ");
    1.42 +
    1.43 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
    1.44 +const TInt KCustomTextCursorId = TTextCursor::ETypeLastBasic + 57; // 57 is arbitrary
    1.45 +#endif
    1.46 +
    1.47 +CCrWin* CCrWin::NewL(TInt aScreenId, TBool aDraw)
    1.48 +	{
    1.49 +	CCrWin* win = new(ELeave) CCrWin;
    1.50 +	CleanupStack::PushL(win);
    1.51 +	win->ConstructL(aScreenId, aDraw);
    1.52 +	CleanupStack::Pop(win);
    1.53 +	return win;
    1.54 +	}
    1.55 +
    1.56 +CCrWin::~CCrWin()
    1.57 +	{
    1.58 +	iWin.Close();
    1.59 +	iGroup.Close();
    1.60 +	delete iGc;
    1.61 +	delete iScr;
    1.62 +	iWs.Close();
    1.63 +	}
    1.64 +
    1.65 +void CCrWin::ConstructL(TInt aScreenId, TBool aDraw)
    1.66 +	{
    1.67 +	User::LeaveIfError(iWs.Connect());
    1.68 +	iScr = new(ELeave) CWsScreenDevice(iWs);
    1.69 +	User::LeaveIfError(iScr->Construct(aScreenId));
    1.70 +	User::LeaveIfError(iScr->CreateContext(iGc));
    1.71 +	iGroup = RWindowGroup(iWs);
    1.72 +	User::LeaveIfError(iGroup.Construct(0xbadbabe,ETrue));
    1.73 +	iGroup.SetOrdinalPosition(0,100);
    1.74 +	iWin = RWindow(iWs);
    1.75 +	User::LeaveIfError(iWin.Construct(iGroup,0xbadcafe));
    1.76 +	iWin.SetRequiredDisplayMode(EColor64K);
    1.77 +	iWin.Activate();
    1.78 +	iWs.Flush();
    1.79 +	if (aDraw)
    1.80 +	Draw();
    1.81 +	}
    1.82 +
    1.83 +void CCrWin::Draw()
    1.84 +	{
    1.85 +	iWin.BeginRedraw();
    1.86 +	iGc->Activate(iWin);
    1.87 +	iGc->SetBrushColor(KRgbRed);
    1.88 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
    1.89 +	TRect rect(iScr->SizeInPixels());
    1.90 +	iGc->DrawRect(rect);
    1.91 +	iGc->SetBrushColor(KRgbBlue);
    1.92 +	iGc->DrawEllipse(TRect(rect.iTl.iX,rect.iTl.iY,rect.iBr.iX/2,rect.iBr.iY));
    1.93 +	iGc->DrawEllipse(TRect(rect.iBr.iX/2,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY));
    1.94 +	iGc->Deactivate();
    1.95 +	iWin.EndRedraw();
    1.96 +	iWs.Flush();
    1.97 +	}
    1.98 +
    1.99 +
   1.100 +void CCrWin::DrawFirstHalf()
   1.101 +	{
   1.102 +	iWin.BeginRedraw();
   1.103 +	iGc->Activate(iWin);
   1.104 +	iGc->SetBrushColor(KRgbRed);
   1.105 +	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.106 +	TRect rect(TPoint(0,0),TSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight));
   1.107 +	iGc->DrawRect(rect);
   1.108 +	iWs.Flush();	
   1.109 +	}
   1.110 +
   1.111 +void CCrWin::DrawSecondHalf()
   1.112 +	{
   1.113 +	TRect rect(TPoint(iScr->SizeInPixels().iWidth/2,0),TSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight));
   1.114 +	iGc->DrawRect(rect);
   1.115 +	iGc->Deactivate();
   1.116 +	iWin.EndRedraw();	
   1.117 +	iWs.Flush();		
   1.118 +	}
   1.119 +
   1.120 +/** 
   1.121 +The objective of this function is, two animations should run independently
   1.122 +with respective frame rate in the given time interval.
   1.123 +The time delay allows to draw animations freely and the plug-in
   1.124 +calculates number of times DoDraw() function called during this interval.
   1.125 +
   1.126 +@param TInt Wsgrphic test plug-in id.
   1.127 +*/
   1.128 +void CCrWin::DrawGraphic(TInt aWsId)
   1.129 +	{
   1.130 +	// draw the animation in two positions
   1.131 +	const TSize screenSize = iScr->SizeInPixels();	
   1.132 +	const TRect position(0,0,screenSize.iWidth/2,screenSize.iHeight);
   1.133 +	const TRect position2((screenSize.iWidth/2)+1,0,screenSize.iWidth,screenSize.iHeight);
   1.134 +	//PeterI if CWsGraphic animation areas overlap then when one redraws the other will as well.
   1.135 +	//2 separate positions are needed otherwise the framerates will be identical.
   1.136 +	
   1.137 +	iWin.BeginRedraw();
   1.138 +	iGc->Activate(iWin);
   1.139 +	const TUint8 animid1=0;
   1.140 +	const TUint8 fps1=20;
   1.141 +	TBuf8<2> animData1;
   1.142 +	animData1.Append(animid1);   //animId1
   1.143 +	animData1.Append(fps1); //20fps
   1.144 +	iGc->DrawWsGraphic(aWsId,position,animData1);
   1.145 +	iWs.Flush();
   1.146 +	User::After(200000);
   1.147 +	const TUint8 animid2=1;
   1.148 +	const TUint8 fps2=60;
   1.149 +	TBuf8<2> animData2;
   1.150 +	animData2.Append(animid2);   //animId2
   1.151 +	animData2.Append(fps2); //60fps
   1.152 +	iGc->DrawWsGraphic(aWsId,position2,animData2);
   1.153 +	iWs.Flush();
   1.154 +	User::After(200000);
   1.155 +	iGc->Deactivate();
   1.156 +	iWin.EndRedraw();
   1.157 +	iWs.Flush();
   1.158 +	}
   1.159 +
   1.160 +/**
   1.161 + * Set a standard text cursor on this window.
   1.162 + * @see RWindowGroup::SetTextCursor()
   1.163 + */
   1.164 +void CCrWin::SetTextCursor(const TPoint &aPos, const TTextCursor &aCursor)
   1.165 +	{
   1.166 +	iGroup.SetTextCursor(iWin, aPos, aCursor);
   1.167 +	}
   1.168 +
   1.169 +/**
   1.170 + * Cancel a text cursor from this window.
   1.171 + * @see RWindowGroup::CancelTextCursor()
   1.172 + */
   1.173 +void CCrWin::CancelTextCursor()
   1.174 +	{
   1.175 +	iGroup.CancelTextCursor();
   1.176 +	}
   1.177 +
   1.178 +CCrAlphaWin* CCrAlphaWin::NewL(TInt aScreenId)
   1.179 +	{
   1.180 +	CCrAlphaWin* win = new(ELeave) CCrAlphaWin;
   1.181 +	CleanupStack::PushL(win);
   1.182 +	win->ConstructL(aScreenId);
   1.183 +	CleanupStack::Pop(win);
   1.184 +	return win;
   1.185 +	}
   1.186 +
   1.187 +CCrAlphaWin::~CCrAlphaWin()
   1.188 +	{
   1.189 +	iWin.Close();
   1.190 +	iGroup.Close();
   1.191 +	delete iScr;
   1.192 +	iWs.Close();
   1.193 +	}
   1.194 +
   1.195 +void CCrAlphaWin::ConstructL(TInt aScreenId)
   1.196 +	{
   1.197 +	User::LeaveIfError(iWs.Connect());
   1.198 +	iScr = new(ELeave) CWsScreenDevice(iWs);
   1.199 +	User::LeaveIfError(iScr->Construct(aScreenId));
   1.200 +	iGroup = RWindowGroup(iWs);
   1.201 +	User::LeaveIfError(iGroup.Construct(0xbadc0de,ETrue));
   1.202 +	iGroup.SetOrdinalPosition(0,100);
   1.203 +	iWin = RWindow(iWs);
   1.204 +	User::LeaveIfError(iWin.Construct(iGroup,0xbadbeef));
   1.205 +	iWin.SetRequiredDisplayMode(EColor64K);
   1.206 +	iWin.SetTransparencyAlphaChannel();
   1.207 +	iWin.SetBackgroundColor(TRgb(0xff,0xff,0,0x80));
   1.208 +	iWin.Activate();
   1.209 +	iWs.Flush();
   1.210 +	}
   1.211 +
   1.212 +
   1.213 +//
   1.214 +//  CTWsGraphs
   1.215 +//
   1.216 +
   1.217 +CTWsGraphs::CTWsGraphs(CTestStep* aStep):
   1.218 +	CTWsGraphicsBase(aStep)
   1.219 +	{
   1.220 +	}
   1.221 +
   1.222 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.223 +LOCAL_D void DeleteSpriteMember(TAny* aSpriteMember)
   1.224 +	{
   1.225 +	TSpriteMember* member=reinterpret_cast<TSpriteMember*>(aSpriteMember);
   1.226 +	delete member->iBitmap;
   1.227 +	member->iBitmap=NULL;
   1.228 +	delete member->iMaskBitmap;
   1.229 +	member->iMaskBitmap=NULL;
   1.230 +	}
   1.231 +#endif
   1.232 +
   1.233 +CTWsGraphs::~CTWsGraphs()
   1.234 +	{
   1.235 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.236 +	DeleteSpriteMember(&iSpriteMemberArray[0]);
   1.237 +	iSpriteMemberArray.Close();
   1.238 +#endif
   1.239 +	delete iGdCoverage;
   1.240 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.241 +	delete iAfter;
   1.242 +	delete iBefore;
   1.243 +	delete iBackCopy;
   1.244 +	delete iFrontCopy;
   1.245 +#endif
   1.246 +	delete iListen;
   1.247 +	delete iNotify2;
   1.248 +	delete iNotify1;
   1.249 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.250 +	delete iRedir;
   1.251 +#endif
   1.252 +	}
   1.253 +
   1.254 +void CTWsGraphs::ConstructL()
   1.255 +	{
   1.256 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.257 +	iRedir = CWsRedir::NewL(iTest->iScreenNumber,ETrue);
   1.258 +	iRedir->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
   1.259 +#endif
   1.260 +	iNotify1 = CWsNotify::NewL(EFalse);
   1.261 +	iNotify2 = CWsNotify::NewL(ETrue);
   1.262 +	iListen = CWsListen::NewL(ETrue);
   1.263 +	iListen->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
   1.264 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.265 +	iFrontCopy = new(ELeave) CFbsBitmap;
   1.266 +	iBackCopy = new(ELeave) CFbsBitmap;
   1.267 +	iBefore = new(ELeave) CFbsBitmap;
   1.268 +	User::LeaveIfError(iBefore->Create(TheClient->iScreen->SizeInPixels(), EColor64K));
   1.269 +	iAfter = new(ELeave) CFbsBitmap;
   1.270 +	User::LeaveIfError(iAfter->Create(TheClient->iScreen->SizeInPixels(), EColor64K));
   1.271 +#endif
   1.272 +	iGdCoverage = CWsGdCoverage::NewL();
   1.273 +	iGdCoverage->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
   1.274 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.275 +	TSpriteMember spriteMember;
   1.276 +	spriteMember.iBitmap = NULL;
   1.277 +	spriteMember.iMaskBitmap = NULL;
   1.278 +	spriteMember.iInvertMask =EFalse;
   1.279 +	spriteMember.iDrawMode = CGraphicsContext::EDrawModePEN;
   1.280 +	spriteMember.iOffset = TPoint();
   1.281 +	spriteMember.iInterval = TTimeIntervalMicroSeconds32(0);
   1.282 +	CleanupStack::PushL(TCleanupItem(DeleteSpriteMember, &spriteMember));
   1.283 +	spriteMember.iBitmap = new (ELeave) CFbsBitmap;
   1.284 +	User::LeaveIfError(spriteMember.iBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1));
   1.285 +	spriteMember.iMaskBitmap = new (ELeave) CFbsBitmap;
   1.286 +	User::LeaveIfError(spriteMember.iMaskBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1mask));
   1.287 +	User::LeaveIfError(iSpriteMemberArray.Append(spriteMember));
   1.288 +	CleanupStack::Pop(&spriteMember);
   1.289 +#endif
   1.290 +	}
   1.291 +
   1.292 +void CTWsGraphs::LaunchNewProcess(const TDesC& aExecutable)
   1.293 +	{
   1.294 +	TBuf<128> args;
   1.295 + 	args.Append(KSpace);
   1.296 +	args.AppendNum(iTest->iScreenNumber);
   1.297 +	RProcess pr;
   1.298 +	TInt err = pr.Create(aExecutable,args);
   1.299 +	if (err == KErrNone)
   1.300 +		{
   1.301 +		TRequestStatus status;
   1.302 +		pr.Logon(status);
   1.303 +		pr.Resume();
   1.304 +		User::WaitForRequest(status);
   1.305 +		err = pr.ExitReason();
   1.306 +		pr.Close();
   1.307 +		if (err != KErrNone)
   1.308 +			{
   1.309 +			_LIT(KLog,"%S returned error: %d. Check RDebug output.");
   1.310 +			LOG_MESSAGE3(KLog, &aExecutable, err);
   1.311 +			}
   1.312 +		}
   1.313 +	else
   1.314 +		{
   1.315 +		_LIT(KLog,"Can't create the process (%S), err=%d");
   1.316 +		LOG_MESSAGE3(KLog, &aExecutable, err);
   1.317 +		}
   1.318 +	TEST(err == KErrNone);
   1.319 +	// Restore main test group to foreground.
   1.320 +	TheClient->iGroup->GroupWin()->SetOrdinalPosition(0);
   1.321 +	}
   1.322 +
   1.323 +TInt CTWsGraphs::PluginCallBack(TAny* /*aArg*/)
   1.324 +	{
   1.325 +	return (TInt)EWait;
   1.326 +	}
   1.327 +
   1.328 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.329 +
   1.330 +/**
   1.331 + @SYMTestCaseID				GRAPHICS-WSERV-0371
   1.332 + @SYMREQ					GT247-CR0714
   1.333 + @SYMTestCaseDesc			Test interface extension
   1.334 + @SYMTestPriority			High
   1.335 + @SYMTestStatus				Implemented
   1.336 + @SYMTestActions			Retrieves object interfaces from Content Rendering Plugin (plugin).
   1.337 +							Actions step:
   1.338 +							-Create plugin
   1.339 +							-Query interfaces obtained from plugin side
   1.340 + @SYMTestExpectedResults	Supported interfaces should return non null
   1.341 +*/
   1.342 +TestState CTWsGraphs::TestInterfaceExtensionL()
   1.343 +	{
   1.344 +	if (iSubState==0)
   1.345 +		{
   1.346 +		_LIT(KTestInterfaceExtension, "TestInterfaceExtension");
   1.347 +		INFO_PRINTF1(KTestInterfaceExtension);
   1.348 +
   1.349 +		++iSubState;
   1.350 +		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));
   1.351 +		iRedir->QueryPlugin(iRedirInfo);
   1.352 +		return EWait;
   1.353 +		}
   1.354 +	TEST(iRedirInfo.iScreenConfigInterface!=NULL);
   1.355 +	TEST(iRedirInfo.iFrontBufferInterface!=NULL);
   1.356 +	TEST(iRedirInfo.iScreenBitmapHandle!=0);
   1.357 +	iFrontCopy->Duplicate(iRedirInfo.iScreenBitmapHandle);
   1.358 +
   1.359 +	if (TransparencySupportedL()!=KErrNotSupported)
   1.360 +		{
   1.361 +		TEST(iRedirInfo.iBackBufferInterface!=NULL);
   1.362 +		TEST(iRedirInfo.iFlickerBitmapHandle!=0);
   1.363 +		iBackCopy->Duplicate(iRedirInfo.iFlickerBitmapHandle);
   1.364 +		}
   1.365 +
   1.366 +	++(iTest->iState);
   1.367 +	iSubState = 0;
   1.368 +	return ENext;
   1.369 +	}
   1.370 +
   1.371 +#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.372 +
   1.373 +void CTWsGraphs::CreateWindowL(TBool aDraw)
   1.374 +	{
   1.375 +	iWin = CCrWin::NewL(iTest->iScreenNumber, aDraw);
   1.376 +	}
   1.377 +
   1.378 +void CTWsGraphs::DestroyWindowL()
   1.379 +	{
   1.380 +	delete iWin;
   1.381 +	iWin = NULL;
   1.382 +	}
   1.383 +
   1.384 +void CTWsGraphs::CreateAlphaWindowL()
   1.385 +	{
   1.386 +	iAlpha = CCrAlphaWin::NewL(iTest->iScreenNumber);
   1.387 +	}
   1.388 +
   1.389 +void CTWsGraphs::DestroyAlphaWindowL()
   1.390 +	{
   1.391 +	delete iAlpha;
   1.392 +	iAlpha = NULL;
   1.393 +	}
   1.394 +
   1.395 +TBool CTWsGraphs::CompareBitmapArea16Bpp(CFbsBitmap* aBmp1, const TPoint& aPos1, CFbsBitmap* aBmp2, const TPoint& aPos2, const TSize& aSize)
   1.396 +	{
   1.397 +	const TDisplayMode dispmode = aBmp1->DisplayMode();
   1.398 +	if (dispmode!=aBmp2->DisplayMode())
   1.399 +		return EFalse;
   1.400 +	const TInt stride1 = aBmp1->DataStride();
   1.401 +	const TInt stride2 = aBmp2->DataStride();
   1.402 +	const TInt linebytes = aSize.iWidth * 2;
   1.403 +	const TInt pixelbytes = 2;
   1.404 +	aBmp1->LockHeap();
   1.405 +	const TUint8* p1 = ((const TUint8*)aBmp1->DataAddress())+aPos1.iY*stride1+aPos1.iX*pixelbytes;
   1.406 +	const TUint8* p2 = ((const TUint8*)aBmp2->DataAddress())+aPos2.iY*stride2+aPos2.iX*pixelbytes;
   1.407 +	for (TInt y=0; y<aSize.iHeight; ++y)
   1.408 +		{
   1.409 +		if (Mem::Compare(p1+y*stride1,linebytes,p2+y*stride2,linebytes)!=0)
   1.410 +			{
   1.411 +			aBmp1->UnlockHeap();
   1.412 +			return EFalse;
   1.413 +			}
   1.414 +		}
   1.415 +	aBmp1->UnlockHeap();
   1.416 +	return ETrue;
   1.417 +	}
   1.418 +
   1.419 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.420 +TestState CTWsGraphs::TestScreenRedirectionL()
   1.421 +	{
   1.422 +	if (iSubState==0)
   1.423 +		{
   1.424 +		_LIT(KTestScreenRedirection, "TestScreenRedirection");
   1.425 +		INFO_PRINTF1(KTestScreenRedirection);
   1.426 +
   1.427 +		++iSubState;
   1.428 +		/**
   1.429 +		 @SYMTestCaseID				GRAPHICS-WSERV-0372
   1.430 +		 @SYMREQ					GT247-CR0714
   1.431 +		 @SYMTestCaseDesc			Redirect wserv screen drawing to custom graphics context
   1.432 +		 @SYMTestPriority			High
   1.433 +		 @SYMTestStatus				Implemented
   1.434 +		 @SYMTestActions			Redirects wserv screen drawing to bitmap context owned by plugin.
   1.435 +									Actions step:
   1.436 +									-Draw opaque window.
   1.437 +									-Save screen content to a bitmap
   1.438 +									-Instruct plugin to redirect wserv screen drawing to a bitmap device
   1.439 +									-Draw the same window again
   1.440 +									-Retrieve plugin bitmap and compare against  the saved bitmap
   1.441 +		 @SYMTestExpectedResults	Bitmap content match
   1.442 +		*/
   1.443 +		CreateWindowL();		
   1.444 +		TheClient->iScreen->CopyScreenToBitmap(iBefore);
   1.445 +		DestroyWindowL();
   1.446 +		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
   1.447 +		return EWait;
   1.448 +		}
   1.449 +
   1.450 +	if (iSubState==1)
   1.451 +		{
   1.452 +		++iSubState;
   1.453 +		CreateWindowL();
   1.454 +		TSize sz = iBefore->SizeInPixels();
   1.455 +		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
   1.456 +		iBefore->LockHeap();
   1.457 +		TEST(Mem::Compare((const TUint8*)iFrontCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
   1.458 +		iBefore->UnlockHeap();
   1.459 +
   1.460 +		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));			
   1.461 +		iRedir->QueryPlugin(iRedirInfo);
   1.462 +		return EWait;
   1.463 +		}
   1.464 +
   1.465 +	if (iSubState==2)
   1.466 +		{
   1.467 +		++iSubState;
   1.468 +		/**
   1.469 +		 @SYMTestCaseID				GRAPHICS-WSERV-0047
   1.470 +		 @SYMTestCaseDesc			Screen update event
   1.471 +		 @SYMTestPriority			Medium
   1.472 +		 @SYMTestStatus				Implemented
   1.473 +		 @SYMTestActions			Check plugin receive screen update event during redirection
   1.474 +		 @SYMTestExpectedResults	Counter is non-zero
   1.475 +		*/
   1.476 +		TEST(iRedirInfo.iUpdateCounter>0);
   1.477 +
   1.478 +		DestroyWindowL();
   1.479 +		/**
   1.480 +		 @SYMTestCaseID				GRAPHICS-WSERV-0373
   1.481 +		 @SYMREQ					GT247-CR0714
   1.482 +		 @SYMTestCaseDesc			Stop wserv screen drawing redirection
   1.483 +		 @SYMTestPriority			High
   1.484 +		 @SYMTestStatus				Implemented
   1.485 +		 @SYMTestActions			Stop wserv screen drawing redirection.
   1.486 +									Actions step:
   1.487 +									-Instruct plugin to stop wserv screen drawing redirection
   1.488 +									-Draw the same window again
   1.489 +									-Save screen content to another bitmap
   1.490 +									-Compare the saved bitmap against newly saved bitmap
   1.491 +		 @SYMTestExpectedResults	Bitmap content match
   1.492 +		*/
   1.493 +		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
   1.494 +		return EWait;
   1.495 +		}
   1.496 +
   1.497 +	if (iSubState==3)
   1.498 +		{
   1.499 +		++iSubState;
   1.500 +		CreateWindowL();
   1.501 +		TheClient->iScreen->CopyScreenToBitmap(iAfter);
   1.502 +		TSize sz = iBefore->SizeInPixels();	
   1.503 +		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K	
   1.504 +		iAfter->LockHeap();
   1.505 +		TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
   1.506 +		iAfter->UnlockHeap();
   1.507 +		DestroyWindowL();
   1.508 +
   1.509 +		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));			
   1.510 +		iRedir->QueryPlugin(iRedirInfo);
   1.511 +		return EWait;
   1.512 +		}
   1.513 +
   1.514 +	/**
   1.515 +	 @SYMTestCaseID				GRAPHICS-WSERV-0374
   1.516 +	 @SYMTestCaseDesc			Screen update event
   1.517 +	 @SYMTestPriority			Medium
   1.518 +	 @SYMTestStatus				Implemented
   1.519 +	 @SYMTestActions			Check plugin receive no screen update event when redirection is terminated
   1.520 +	 @SYMTestExpectedResults	Counter is zero
   1.521 +	*/
   1.522 +	TEST(iRedirInfo.iUpdateCounter==0);
   1.523 +
   1.524 +	++(iTest->iState);
   1.525 +	iSubState = 0;
   1.526 +
   1.527 +	return ENext;
   1.528 +	}
   1.529 +
   1.530 +TestState CTWsGraphs::TestTextCursorUnderRedirectionL(TTestCursorType aCursorType)
   1.531 +	{
   1.532 +	/**
   1.533 +	 @SYMTestCaseID				GRAPHICS-WSERV-0363
   1.534 +	 @SYMTestCaseDesc			Text Cursor when drawing redirected
   1.535 +	 @SYMTestPriority			Medium
   1.536 +	 @SYMTestStatus				Implemented
   1.537 +	 @SYMTestActions			Action steps:
   1.538 +	 							- Draw the text cursor in the left side of the screen
   1.539 +	 							- Re-direct the Front Buffer
   1.540 +	 							- Move the text cursor to the right side of the screen
   1.541 +	 							- Pause 0.5 seconds because this amount of time is needed
   1.542 +								  to change from the flash ON phase to the flash OFF phase
   1.543 +	 							- Stop re-directing
   1.544 +	 							- See if when we exit re-direction in a different place in
   1.545 +	 							  the phase of the text cursor flashing, whether we get
   1.546 +	 							  non-text cursor drawing artefacts in the old location
   1.547 +	 							  where the text cursor used to be
   1.548 +	 @SYMTestExpectedResults	Left side of the screen does not show a Text Cursor
   1.549 +	 */
   1.550 +	
   1.551 +	ASSERT(aCursorType == ETestStandardTextCursor || aCursorType == ETestCustomTextCursor);
   1.552 +	
   1.553 +	// Cursor Flash Period is 1 second (comprising two phases; ON and OFF)
   1.554 +	const TInt KCursorFlashPeriod = 1000000;
   1.555 +	const TInt KWaitForNextFlashPhase = KCursorFlashPeriod / 2;
   1.556 +	
   1.557 +	// Size of the cursor; it may be either a standard or custom text cursor
   1.558 +	TSize cursorSize = (aCursorType == ETestStandardTextCursor) ? TSize(15, 20) : TSize(80, 80);
   1.559 +		
   1.560 +	// Original Text Cursor position in the left part of the screen
   1.561 +	const TPoint originalCursorPos(45, 40);
   1.562 +	
   1.563 +	// New Text Cursor position in the right half of the screen
   1.564 +	const TPoint newCursorPos((TheClient->iScreen->SizeInPixels().iWidth/2) + 45, 40);
   1.565 +	
   1.566 +	// Clean area of the screen which never had a text cursor
   1.567 +	const TPoint cleanReferencePos(45, 40 + 80);
   1.568 +	
   1.569 +	/* Initial setup to get a window with a standard flashing text cursor */
   1.570 +	if (iSubState == 0)
   1.571 +		{
   1.572 +		++iSubState;			
   1.573 +		CreateWindowL(ETrue);
   1.574 +		
   1.575 +		if (aCursorType == ETestStandardTextCursor)
   1.576 +			{
   1.577 +			_LIT(KTestTextCursorUnderRedirection, "TestTextCursorUnderRedirection(Standard Cursor)");
   1.578 +			INFO_PRINTF1(KTestTextCursorUnderRedirection);	
   1.579 +			iTextCursor.iType=TTextCursor::ETypeRectangle;
   1.580 +			iTextCursor.iHeight=cursorSize.iHeight;
   1.581 +			iTextCursor.iAscent=0;
   1.582 +			iTextCursor.iWidth=cursorSize.iWidth;
   1.583 +			iTextCursor.iFlags=0; 			// means flash the cursor
   1.584 +			iTextCursor.iColor=KRgbGreen;
   1.585 +			iWin->SetTextCursor(originalCursorPos, iTextCursor);
   1.586 +			}
   1.587 +		else if (aCursorType == ETestCustomTextCursor)
   1.588 +			{
   1.589 +			_LIT(KTestTextCursorUnderRedirection, "TestTextCursorUnderRedirection(Custom Cursor)");
   1.590 +			INFO_PRINTF1(KTestTextCursorUnderRedirection);	
   1.591 +
   1.592 +			TInt err = TheClient->iWs.SetCustomTextCursor(
   1.593 +					KCustomTextCursorId,
   1.594 +					iSpriteMemberArray.Array(),
   1.595 +					ESpriteFlash,
   1.596 +					RWsSession::ECustomTextCursorAlignTop
   1.597 +					);
   1.598 +			iTextCursor.iType=KCustomTextCursorId;
   1.599 +			iTextCursor.iHeight=cursorSize.iHeight;
   1.600 +			iTextCursor.iAscent=0;
   1.601 +			iTextCursor.iWidth=cursorSize.iWidth;
   1.602 +			iTextCursor.iFlags=TTextCursor::EFlagClipHorizontal; // means flash the cursor and clip the sprite
   1.603 +			iTextCursor.iColor=KRgbCyan;
   1.604 +			iWin->SetTextCursor(originalCursorPos, iTextCursor);
   1.605 +			}
   1.606 +		else
   1.607 +			{
   1.608 +			// unknown type of test being requested
   1.609 +			ASSERT(0);
   1.610 +			}
   1.611 +		iWin->DrawFirstHalf();	
   1.612 +		return EWait;
   1.613 +		}
   1.614 +	/*
   1.615 +	 * Re-direct drawing to another Front Buffer.  Whilst re-directed, change the
   1.616 +	 * position of the text cursor.  Then pause 0.5 seconds because this is how
   1.617 +	 * long it will take to enter the next phase in the flashing cycle.  Finally
   1.618 +	 * stop re-directing.  We exit the re-direction in a different point in the
   1.619 +	 * phase of the text cursor from when we entered it.
   1.620 +	 * This is key to testing for faulty behaviour.
   1.621 +	 */
   1.622 +	if (iSubState==1)
   1.623 +		{
   1.624 +		++iSubState;
   1.625 +		User::After(KCursorFlashPeriod * 2);  // so its easy to visually review progress
   1.626 +		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
   1.627 +		iWin->SetTextCursor(newCursorPos, iTextCursor);
   1.628 +		User::After(KWaitForNextFlashPhase);
   1.629 +		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
   1.630 +		return EWait;
   1.631 +		}
   1.632 +	/*
   1.633 +	 * Paint the right hand side of the screen which should now have a text cursor.
   1.634 +	 */
   1.635 +	if (iSubState==2)
   1.636 +		{
   1.637 +		++iSubState;
   1.638 +		iWin->DrawSecondHalf();
   1.639 +		return EWait;
   1.640 +		}
   1.641 +	/*
   1.642 +	 * Let the cursor flash a few times, as it assists manual viewing of the progress
   1.643 +	 * of the test.
   1.644 +	 */
   1.645 +	if (iSubState==3)
   1.646 +		{
   1.647 +		++iSubState;
   1.648 +		User::After(KCursorFlashPeriod * 3);
   1.649 +		return EWait;
   1.650 +		}
   1.651 +	/*
   1.652 +	 * Check to see if the text cursor did move to the right of the screen.
   1.653 +	 */
   1.654 +	if (iSubState==4)
   1.655 +		{
   1.656 +		++iSubState;
   1.657 +		
   1.658 +		/* When we do a screen comparison, we supply flag 0, which means
   1.659 +		 * don't include the text cursor.  We do this because we are interested
   1.660 +		 * in screen artefacts.
   1.661 +		 */
   1.662 +		TEST(TheClient->iScreen->RectCompare(
   1.663 +				TRect(originalCursorPos, cursorSize),
   1.664 +				TRect(cleanReferencePos, cursorSize),
   1.665 +				0)); // must not supply CWsScreenDevice::EIncludeTextCursor
   1.666 +		
   1.667 +		return EWait;
   1.668 +		}
   1.669 +	/* Clean up */
   1.670 +	if (iSubState==5)
   1.671 +		{
   1.672 +		++iSubState;
   1.673 +		iWin->CancelTextCursor();
   1.674 +		DestroyWindowL();
   1.675 +		}
   1.676 +	
   1.677 +	iSubState = 0;
   1.678 +
   1.679 +	return ENext;
   1.680 +	}
   1.681 +
   1.682 +/**
   1.683 + @SYMTestCaseID				GRAPHICS-WSERV-0375
   1.684 + @SYMREQ					GT247-CR0714
   1.685 + @SYMTestCaseDesc			Redirect wserv flickerfree drawing to custom graphics context
   1.686 + @SYMTestPriority			Medium
   1.687 + @SYMTestStatus				Implemented
   1.688 + @SYMTestActions			Redirect wserv flickerfree buffer drawing.
   1.689 +							Action step:
   1.690 +							-Draw opaque window (as background) and transparent window
   1.691 +							-Save screen content to a bitmap
   1.692 +							-Instruct plugin to redirect wserv flickerfree buffer drawing
   1.693 +							-Draw the same opaque window and transparent window again
   1.694 +							-Retrieve plugin bitmap and compare against the saved bitmap
   1.695 + @SYMTestExpectedResults	Bitmap content match
   1.696 +*/
   1.697 +/**
   1.698 + @SYMTestCaseID				GRAPHICS-WSERV-0376
   1.699 + @SYMREQ					GT247-CR0714
   1.700 + @SYMTestCaseDesc			Stop wserv flickerfree drawing redirection
   1.701 + @SYMTestPriority			Medium
   1.702 + @SYMTestStatus				Implemented
   1.703 + @SYMTestActions			Stop wserv flickerfree buffer drawing redirection.
   1.704 +							Action step:
   1.705 +							-Instruct plugin to stop wserv filckerfree drawing redirection
   1.706 +							-Draw the same opaque and transparent window
   1.707 +							-Save screen content to another bitmap
   1.708 +							-Compare saved bitmap against newly saved bitmap
   1.709 + @SYMTestExpectedResults	Bitmap content match
   1.710 +*/
   1.711 +
   1.712 +TestState CTWsGraphs::TestFlickerRedirectionL()
   1.713 +	{
   1.714 +	if (TransparencySupportedL()==KErrNotSupported)
   1.715 +		{
   1.716 +		++(iTest->iState);
   1.717 +		return ENext;
   1.718 +		}
   1.719 +
   1.720 +	// flush transparent window destruction created in TransparencySupportedL before
   1.721 +	// proceeding with the test
   1.722 +
   1.723 +	TheClient->iWs.Flush();
   1.724 +
   1.725 +	if (iSubState==0)
   1.726 +		{
   1.727 +		_LIT(KTestFlickerRedirection, "TestFlickerRedirection");
   1.728 +		INFO_PRINTF1(KTestFlickerRedirection);
   1.729 +
   1.730 +		++iSubState;
   1.731 +
   1.732 +		CreateWindowL();
   1.733 +		CreateAlphaWindowL();
   1.734 +		TheClient->iScreen->CopyScreenToBitmap(iBefore);
   1.735 +		DestroyAlphaWindowL();
   1.736 +		DestroyWindowL();
   1.737 +		iRedir->Redirect(CWsRedir::EBackBuffer, ETrue);
   1.738 +		return EWait;
   1.739 +		}
   1.740 +
   1.741 +	if (iSubState==1)
   1.742 +		{
   1.743 +		++iSubState;
   1.744 +		CreateWindowL();
   1.745 +		CreateAlphaWindowL();
   1.746 +		TSize sz = iBefore->SizeInPixels();
   1.747 +		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
   1.748 +		iBefore->LockHeap();
   1.749 +		TInt ret=Mem::Compare((const TUint8*)iBackCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes);
   1.750 +		TEST(ret==0);
   1.751 +		if (ret!=0)
   1.752 +			{
   1.753 +			_LIT(KLog,"The memory of two bitmaps doesn't match");
   1.754 +			LOG_MESSAGE(KLog);
   1.755 +			}
   1.756 +		iBefore->UnlockHeap();
   1.757 +		DestroyAlphaWindowL();
   1.758 +		DestroyWindowL();
   1.759 +		iRedir->Redirect(CWsRedir::EBackBuffer, EFalse);
   1.760 +		return EWait;
   1.761 +		}
   1.762 +
   1.763 +	CreateWindowL();
   1.764 +	CreateAlphaWindowL();
   1.765 +	TheClient->iScreen->CopyScreenToBitmap(iAfter);
   1.766 +	TSize sz = iBefore->SizeInPixels();
   1.767 +	TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
   1.768 +	iAfter->LockHeap();
   1.769 +	TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
   1.770 +	iAfter->UnlockHeap();
   1.771 +	DestroyAlphaWindowL();
   1.772 +	DestroyWindowL();
   1.773 +
   1.774 +	++(iTest->iState);
   1.775 +	iSubState = 0;
   1.776 +	return ENext;
   1.777 +	}
   1.778 +
   1.779 +#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.780 +
   1.781 +/**
   1.782 + @SYMTestCaseID				GRAPHICS-WSERV-0377
   1.783 + @SYMREQ					GT247-CR0714
   1.784 + @SYMTestCaseDesc			Enable event notification
   1.785 + @SYMTestPriority			Medium
   1.786 + @SYMTestStatus				Implemented
   1.787 + @SYMTestActions			Enable plugin to register to event notification.
   1.788 +							Action step:
   1.789 +							-Instruct plugin to register event handler
   1.790 +							-Draw fullscreen window (plugin will receive window visibility changed event)
   1.791 +							-Query visibility region from plugin side
   1.792 +							-Compare window visible region against value obtained by plugin
   1.793 + @SYMTestExpectedResults	Visible region match
   1.794 +*/
   1.795 +/**
   1.796 + @SYMTestCaseID				GRAPHICS-WSERV-0378
   1.797 + @SYMREQ					GT247-CR0714
   1.798 + @SYMTestCaseDesc			Disable event notification
   1.799 + @SYMTestPriority			Medium
   1.800 + @SYMTestStatus				Implemented
   1.801 + @SYMTestActions			Disable plugin to register to event notification.
   1.802 +							Action step:
   1.803 +							-Instruct plugin to unregister event handler
   1.804 +							-Destroy fullscreen window (plugin will not receive window visibility changed event)
   1.805 +							-Query visibility region from plugin side
   1.806 +
   1.807 + @SYMTestExpectedResults	Plugin does not receive events notification
   1.808 +*/
   1.809 +TestState CTWsGraphs::TestEventNotificationL()
   1.810 +	{
   1.811 +	if (iSubState==0)
   1.812 +		{
   1.813 +		_LIT(KTestEventNotification, "TestEventNotification");
   1.814 +		INFO_PRINTF1(KTestEventNotification);
   1.815 +
   1.816 +		++iSubState;
   1.817 +		iListen->Enable(ETrue);
   1.818 +		CreateWindowL();
   1.819 +		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
   1.820 +		TheClient->iWs.Finish();
   1.821 +		TheClient->WaitForRedrawsToFinish();
   1.822 +		iListen->QueryPlugin(iListenInfo);
   1.823 +		return EWait;
   1.824 +		}
   1.825 +
   1.826 +	if (iSubState==1)
   1.827 +		{
   1.828 +		++iSubState;
   1.829 +		iListen->Enable(EFalse);
   1.830 +		TEST(iListenInfo.iNumRect==1);
   1.831 +		TEST(iListenInfo.iRect==TRect(TPoint(0,0),TheClient->iScreen->SizeInPixels()));
   1.832 +		DestroyWindowL();
   1.833 +		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
   1.834 +		iListen->QueryPlugin(iListenInfo);
   1.835 +		iListen->Enable(EFalse);
   1.836 +		DestroyWindowL();
   1.837 +		return EWait;
   1.838 +		}
   1.839 +		
   1.840 +	TEST(iListenInfo.iNumRect==0);
   1.841 +	
   1.842 +	++(iTest->iState);
   1.843 +	iSubState = 0;
   1.844 +	return ENext;
   1.845 +	}
   1.846 +
   1.847 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.848 +
   1.849 +TestState CTWsGraphs::TestRedirectionUsingWsBackBufferL()
   1.850 +	{
   1.851 +	if (TransparencySupportedL()==KErrNotSupported)
   1.852 +		{
   1.853 +		++(iTest->iState);
   1.854 +		return ENext;
   1.855 +		}
   1.856 +
   1.857 +	// flush transparent window destruction created in TransparencySupportedL before
   1.858 +	// proceeding with the test
   1.859 +
   1.860 +	TheClient->iWs.Flush();
   1.861 +
   1.862 +	if (iSubState==0)
   1.863 +		{
   1.864 +		_LIT(KTestRedirectionWsBack, "TestRedirectionUsingWsBackBuffer");
   1.865 +		INFO_PRINTF1(KTestRedirectionWsBack);
   1.866 +		
   1.867 +		++iSubState;
   1.868 +
   1.869 +		/**
   1.870 +		 @SYMTestCaseID				GRAPHICS-WSERV-0379
   1.871 +		 @SYMTestCaseDesc			Redirect wserv flickerfree to MWsBackBuffer object
   1.872 +		 @SYMTestPriority			Medium
   1.873 +		 @SYMTestStatus				Implemented
   1.874 +		 @SYMTestActions			-Draw opaque window (as background) and transparent window
   1.875 +									-Save screen content to a bitmap
   1.876 +									-Instruct plugin to redirect flickerfree buffer to MWsBackBuffer object
   1.877 +									-Draw the same opaque window and transparent window again
   1.878 +									-Retrieve plugin bitmap and compare against the saved bitmap
   1.879 +		 @SYMTestExpectedResults	Bitmap content match
   1.880 +		*/
   1.881 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0379"));
   1.882 +		CreateWindowL();
   1.883 +		CreateAlphaWindowL();
   1.884 +		TheClient->iScreen->CopyScreenToBitmap(iBefore);
   1.885 +		DestroyAlphaWindowL();		
   1.886 +		DestroyWindowL();		
   1.887 +		iRedir->RedirectUsingWsBackBuffer(ETrue);
   1.888 +		return EWait;
   1.889 +		}
   1.890 +
   1.891 +	if (iSubState==1)
   1.892 +		{
   1.893 +		++iSubState;
   1.894 +		CreateWindowL();
   1.895 +		CreateAlphaWindowL();
   1.896 +		TSize sz = iBefore->SizeInPixels();
   1.897 +		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
   1.898 +		iBefore->LockHeap();
   1.899 +		TInt ret=Mem::Compare((const TUint8*)iBackCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes);
   1.900 +		TEST(ret==0);
   1.901 +		if (ret!=0)
   1.902 +			{
   1.903 +			_LIT(KLog,"The memory of two bitmaps doesn't match");
   1.904 +			LOG_MESSAGE(KLog);
   1.905 +			}
   1.906 +		iBefore->UnlockHeap();
   1.907 +		DestroyAlphaWindowL();
   1.908 +		DestroyWindowL();
   1.909 +
   1.910 +		/**
   1.911 +		 @SYMTestCaseID				GRAPHICS-WSERV-0380
   1.912 +		 @SYMTestCaseDesc			Restore wserv flickerfree redirection from MWsBackBuffer object
   1.913 +		 @SYMTestPriority			Medium
   1.914 +		 @SYMTestStatus				Implemented
   1.915 +		 @SYMTestActions			-Instruct plugin to stop wserv filckerfree drawing redirection
   1.916 +									-Draw the same opaque and transparent window
   1.917 +									-Save screen content to another bitmap
   1.918 +									-Compare saved bitmap against newly saved bitmap
   1.919 +		 @SYMTestExpectedResults	Bitmap content match
   1.920 +		*/
   1.921 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0380"));
   1.922 +		iRedir->RedirectUsingWsBackBuffer(EFalse);
   1.923 +		return EWait;
   1.924 +		}
   1.925 +
   1.926 +	CreateWindowL();
   1.927 +	CreateAlphaWindowL();
   1.928 +	TheClient->iScreen->CopyScreenToBitmap(iAfter);
   1.929 +	TSize sz = iBefore->SizeInPixels();
   1.930 +	TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
   1.931 +	iAfter->LockHeap();
   1.932 +	TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
   1.933 +	iAfter->UnlockHeap();
   1.934 +	DestroyAlphaWindowL();
   1.935 +	DestroyWindowL();
   1.936 +/**
   1.937 +	@SYMTestCaseID	GRAPHICS-WSERV-0527
   1.938 +*/
   1.939 +	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0527"));
   1.940 +	++(iTest->iState);
   1.941 +	iSubState = 0;
   1.942 +	return ENext;
   1.943 +	}
   1.944 +
   1.945 +#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
   1.946 +
   1.947 +//A call to do coverage through a plugin. 
   1.948 +//This can serve as a basis for future coverage to objects exposed by the
   1.949 +//plugin. For now a single simple test is implmeneted.
   1.950 +TestState CTWsGraphs::TestGraphicDrawerCoverage()
   1.951 +	{
   1.952 +	__ASSERT_ALWAYS(iGdCoverage->RunTest(1)==KErrNone||KErrNotReady, User::Invariant());
   1.953 +	return ENext;
   1.954 +	}
   1.955 +
   1.956 +//Simplified non-functional class to create a few dummy CWsGraphicDrawer instances.
   1.957 +//This code is intended to test the Array class, not the Drawer.
   1.958 +//Note that this object is not at all functional! The only guaranteed method is Id().
   1.959 +//WsGraphicDrawer is declared as a friend and is actually intended to be the factory class for CWsGraphicDrawer
   1.960 +class WsGraphicDrawer:public CWsGraphicDrawer
   1.961 +	{
   1.962 +public:
   1.963 +	WsGraphicDrawer()
   1.964 +		{
   1.965 +		}
   1.966 +	//stub for virtual construction. Most members are ignored
   1.967 +	virtual void ConstructL(MWsGraphicDrawerEnvironment& ,const TGraphicDrawerId& id,MWsClient& ,const TDesC8& )
   1.968 +		{
   1.969 +		ConstructL(id);
   1.970 +		}
   1.971 +	//simplified custom construction
   1.972 +	void ConstructL(const TGraphicDrawerId& id)
   1.973 +		{
   1.974 +		MWsGraphicDrawerEnvironment* nullEnv=NULL;
   1.975 +		MWsGraphicDrawerEnvironment& aEnv=*nullEnv;
   1.976 +		MWsClient* nullClient=NULL;
   1.977 +		MWsClient& aOwner=*nullClient;
   1.978 +		this->BaseConstructL(aEnv,id,aOwner);
   1.979 +		this->iDtor_ID_Key=TUid::Null();
   1.980 +		
   1.981 +		}
   1.982 +	//stubs for pure virtual methods
   1.983 +	virtual void HandleMessage(const TDesC8& )
   1.984 +		{}
   1.985 +	virtual void DoDraw(MWsGc& ,const TRect& ,const TDesC8& ) const
   1.986 +		{}
   1.987 +	
   1.988 +	};
   1.989 +//Class to allow me to pre-allocate the CWsGraphicDrawerArray so it doesn't pop up a false-positive memory allocation!
   1.990 +class DummyCleanup:public TCleanupItem
   1.991 +	{
   1.992 +public:
   1.993 +	static void CleanUp(TAny*)		{}
   1.994 +	DummyCleanup(): TCleanupItem(CleanUp,this)	{}
   1.995 +	operator DummyCleanup*()	{	return this;	}
   1.996 +	
   1.997 +	};
   1.998 +
   1.999 +//Helper function to explain test fails. Most other tests are against KErrNone
  1.1000 +void CTWsGraphs::ReportNegativeResultfail(TInt aLine,TInt aResult,TInt aExpectedResult)
  1.1001 +	{
  1.1002 +	testBooleanTrue((aResult==aExpectedResult), (TText8*)__FILE__, aLine);
  1.1003 +	if (aResult!=aExpectedResult)
  1.1004 +		{
  1.1005 +		INFO_PRINTF3(_L("Expected return code %i, got %i"),aExpectedResult,aResult);	
  1.1006 +		}
  1.1007 +	
  1.1008 +	}
  1.1009 +	
  1.1010 +//This is an attempt to use wserv test's pre-existing Panic handler to perform some negative tests.
  1.1011 +//At present this handler appears to be broken:
  1.1012 +// 1) It doesn't write to the correct html log file
  1.1013 +// 2) It no longer writes to the WSERV.LOG file it was writing to a few versions ago
  1.1014 +// 3) It doesn't close the panic window so subsequent tests that check the display output fail.
  1.1015 +//That was a waste of effort.
  1.1016 +struct CTWsGraphs::WrapTestCall
  1.1017 +	{
  1.1018 +	CTWsGraphs* thisThis;
  1.1019 +	TUint		testCount;
  1.1020 +	TBool		continueTests;
  1.1021 +	TUint 		testFailedLine;
  1.1022 +	//This field was intended to allow threaded panicing tests to report other errors
  1.1023 +	//As I can't get threaded panicing tests to operate correctly, I have not implemented support for the field.
  1.1024 +	//TBuf<1024>	errorMessages;	
  1.1025 +		
  1.1026 +	WrapTestCall (	CTWsGraphs* thisThis,	TUint		testCount):
  1.1027 +		thisThis(thisThis),	testCount(testCount)
  1.1028 +		{	continueTests=false;testFailedLine=0;	}
  1.1029 +	};
  1.1030 +	
  1.1031 +TInt	CTWsGraphs::DoNegTestCall(TInt /*aInt*/, TAny *aPtr)
  1.1032 +	{
  1.1033 +	CTWsGraphs::WrapTestCall* aWrap=static_cast<CTWsGraphs::WrapTestCall*>(aPtr);
  1.1034 +	aWrap->continueTests=aWrap->thisThis->NegTestAddSwapGDArrayL(aWrap->testCount,aWrap);	
  1.1035 +	return 0;
  1.1036 +	}
  1.1037 +	
  1.1038 +TBool	CTWsGraphs::LaunchNegTestCall(TUint		aTestCount,TUint PanicCode,const TDesC &aPanicCategory)
  1.1039 +	{
  1.1040 +	WrapTestCall wt(this,aTestCount);
  1.1041 +	(void)PanicCode;
  1.1042 +	(void)aPanicCategory;
  1.1043 +//I have disabled the panicing tests because they don't output diagnostics 
  1.1044 +//and the open panic window causes subsequent screen bitmap comparrisson tests to fail.
  1.1045 +//	iTest->TestPanicL(DoNegTestCall,aPanicCode,3,&wt,aPanicCategory);
  1.1046 +	return wt.continueTests;	
  1.1047 +	}
  1.1048 +
  1.1049 +/**
  1.1050 +	Loops through all the positive and negative tests associated with the  GraphicDrawerArray.
  1.1051 +	The aim is to perform isolated testing of these classes as some are not currently being used.
  1.1052 +	
  1.1053 +**/
  1.1054 +void CTWsGraphs::TestAddSwapGDArrayL()
  1.1055 +	{
  1.1056 +
  1.1057 +
  1.1058 +	INFO_PRINTF1(_L("Positive tests for GraphicDrawerArray"));
  1.1059 +	for (TInt i=0;PosTestAddSwapGDArrayL(i);i++)
  1.1060 +		{}
  1.1061 +
  1.1062 +
  1.1063 +
  1.1064 +	INFO_PRINTF1(_L("Verifying that negative tests for GraphicDrawerArray don't actually panic"));
  1.1065 +	for (TInt i=1;NegTestAddSwapGDArrayL(i);i++)
  1.1066 +		{}
  1.1067 +	}
  1.1068 +/**
  1.1069 +	Resets and deallocates the GDA withoud deleting the objects.
  1.1070 +	@param 	 testArray	the array to reset
  1.1071 +	@return true if the array was already empty.
  1.1072 +**/
  1.1073 +static bool	ResetArray(CWsGraphicDrawerArray& testArray)
  1.1074 +{
  1.1075 +	bool rv=(testArray.IsEmpty());
  1.1076 +	MWsClient* nullClient=NULL;
  1.1077 +	testArray.RemoveAll(*nullClient);
  1.1078 +	testArray.ResetAndDestroy();		
  1.1079 +	return rv;
  1.1080 +}
  1.1081 +/**
  1.1082 +   @SYMTestCaseID GRAPHICS-WSERV-AddSwapGDArray-0001
  1.1083 +   @SYMDEF			DEF093926  
  1.1084 +  
  1.1085 +   @SYMTestCaseDesc DEF093926: Check for stability of Add and Swap unwind methods in isolation.
  1.1086 +   		Note that this code is testing the functionality of a class internal to CWindowServer.
  1.1087 +   		At present CWindowServer presents just a simple shim on this class, 
  1.1088 +   		but if that implementation of  CWindowServer changes than this test will be redudant.
  1.1089 +   
  1.1090 +   @SYMTestPriority High
  1.1091 +   
  1.1092 +   @SYMTestStatus Implemented
  1.1093 +   
  1.1094 +   @SYMTestActions
  1.1095 +	The sequence for each of these positive test sections is pretty much the same:
  1.1096 +	Add one record with id 1234(test for errors)
  1.1097 +	Add one record with id Badf00d
  1.1098 +	Swap with another record with id Badf00d
  1.1099 +	Remove 2 records
  1.1100 +	result=no leaks
  1.1101 +	
  1.1102 +		Add/Swap: no Cleanup item - no leaks after Remove the added items
  1.1103 +   	    AddTLC/SwapTLC: Cleanup item requires Commit - check for no leaks after Remove.
  1.1104 +   	    AddTLC/SwapTLC: Cleanup item gets executed by forced Leave  - check for no leaks after.
  1.1105 +		AddTLC, SwapTLC in allocation failure scenarios. Add/Swap don't allocate anything!
  1.1106 +		obsoleted AddLC/SwapLC to ensure correct function when forced Leave - check for no leaks after
  1.1107 +		obsoleted AddLC/SwapLC to ensure correct function. These will always leak in good case.
  1.1108 +   @SYMTestExpectedResults 
  1.1109 +   		no exceptions or panics within this fn. 
  1.1110 +   		only the old AddLC and SwapLC should leak as indicated.
  1.1111 + */
  1.1112 +TBool CTWsGraphs::PosTestAddSwapGDArrayL(TInt testcase)
  1.1113 +	{
  1.1114 +	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-AddSwapGDArray-0001"));
  1.1115 +    CWsGraphicDrawerArray testArray;
  1.1116 +    //Represents the memory cached in the array once it has been used even when it is then resized to zero
  1.1117 +#if defined(_DEBUG)
  1.1118 +    const TInt KArrayMemUseBaseline=1;
  1.1119 +#endif
  1.1120 +    //Use testArray.IsEmpty() to prove the array is clear when it should be!
  1.1121 +    TGraphicDrawerId id1234=  	{  	1234,		EFalse    	};
  1.1122 +    TGraphicDrawerId idBADF00D=	{  	0xBADF00D,	EFalse    	};
  1.1123 +    WsGraphicDrawer dg1234;		
  1.1124 +    dg1234.ConstructL(id1234);
  1.1125 +    WsGraphicDrawer dgBADF00D;	
  1.1126 +    dgBADF00D.ConstructL(idBADF00D);
  1.1127 +    WsGraphicDrawer dgBADF00D_2;
  1.1128 +    dgBADF00D_2.ConstructL(idBADF00D);
  1.1129 +    CWsGraphicDrawerArray::XRollBackBase* rollBack1;
  1.1130 + 	TInt errCode=KErrAbort;
  1.1131 +	TInt leaveCode=KErrNone;
  1.1132 +	DummyCleanup markerCleanup;
  1.1133 +	CleanupStack::PushL(markerCleanup);	 //This allows me to check the stack is clear!
  1.1134 +	//expected result of this fn: no exceptions or panics. 
  1.1135 +	//Put as much as you like in here, so long as it shouldn't fail.
  1.1136 +	
  1.1137 +	__UHEAP_MARK;
  1.1138 +			__UHEAP_CHECK(0);
  1.1139 +	TUint expectedLeakCount=0;
  1.1140 +	TBool returnCode=ETrue;
  1.1141 +	switch (testcase)
  1.1142 +		{
  1.1143 +		case 0:
  1.1144 +
  1.1145 +			INFO_PRINTF1(_L("Sub test P0: AddL/Swap: no Cleanup item"));
  1.1146 +			TEST(testArray.IsEmpty());
  1.1147 +				TRAP(leaveCode,errCode=testArray.Add(&dg1234));
  1.1148 +			TEST(errCode==KErrNone);
  1.1149 +			TEST(leaveCode==KErrNone);
  1.1150 +			TEST(!testArray.IsEmpty());
  1.1151 +				TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
  1.1152 +			TEST(errCode==KErrNone);
  1.1153 +			TEST(leaveCode==KErrNone);
  1.1154 +				TRAP(leaveCode,errCode=testArray.Swap(&dgBADF00D_2));
  1.1155 +			TEST(errCode==KErrNone);
  1.1156 +			TEST(leaveCode==KErrNone);
  1.1157 +				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
  1.1158 +			TEST(errCode==KErrNone);
  1.1159 +			TEST(leaveCode==KErrNone);
  1.1160 +				//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
  1.1161 +				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
  1.1162 +			TEST(errCode==KErrNone);
  1.1163 +			TEST(leaveCode==KErrNone);
  1.1164 +			TEST(testArray.IsEmpty());
  1.1165 +		break;
  1.1166 +		//
  1.1167 +		case 1:
  1.1168 +			INFO_PRINTF1(_L("Sub test P1: AddTLC/SwapTLC: Cleanup item requires Commit."));
  1.1169 +			
  1.1170 +			rollBack1=NULL;
  1.1171 +			TEST(testArray.IsEmpty());
  1.1172 +			TRAP(leaveCode,
  1.1173 +				rollBack1=testArray.AddTLC(&dg1234);
  1.1174 +				CleanupStack::Check(rollBack1);
  1.1175 +				testArray.CommitP(rollBack1);	
  1.1176 +				)
  1.1177 +			TEST(rollBack1!=NULL);
  1.1178 +			TEST(leaveCode==KErrNone);
  1.1179 +			TEST(!testArray.IsEmpty());
  1.1180 +			rollBack1=NULL;
  1.1181 +			TRAP(leaveCode,
  1.1182 +				rollBack1=testArray.AddTLC(&dgBADF00D);
  1.1183 +				CleanupStack::Check(rollBack1);
  1.1184 +				testArray.CommitP(rollBack1);	
  1.1185 +				)
  1.1186 +			TEST(rollBack1!=NULL);
  1.1187 +			TEST(leaveCode==KErrNone);
  1.1188 +			rollBack1=NULL;
  1.1189 +			TRAP(leaveCode,
  1.1190 +				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
  1.1191 +				CleanupStack::Check(rollBack1);
  1.1192 +				testArray.CommitP(rollBack1);	
  1.1193 +				)
  1.1194 +			TEST(rollBack1!=NULL);
  1.1195 +			TEST(leaveCode==KErrNone);
  1.1196 +			rollBack1=NULL;
  1.1197 +			TRAP(leaveCode,
  1.1198 +				rollBack1=testArray.RemoveTLC(dg1234.Id());
  1.1199 +				CleanupStack::Check(rollBack1);
  1.1200 +				testArray.CommitP(rollBack1);	
  1.1201 +				)
  1.1202 +			TEST(rollBack1!=NULL);
  1.1203 +			TEST(leaveCode==KErrNone);
  1.1204 +			rollBack1=NULL;
  1.1205 +				TRAP(leaveCode,
  1.1206 +				rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());			
  1.1207 +				CleanupStack::Check(rollBack1);
  1.1208 +				testArray.CommitP(rollBack1);	
  1.1209 +				)
  1.1210 +			TEST(rollBack1!=NULL);
  1.1211 +			TEST(leaveCode==KErrNone);
  1.1212 +			rollBack1=NULL;
  1.1213 +			TEST(testArray.IsEmpty());
  1.1214 +		break;
  1.1215 +		//
  1.1216 +		case 2:
  1.1217 +			INFO_PRINTF1(_L("Sub test P2: AddTLC/SwapTLC: Cleanup item gets executed."));
  1.1218 +			
  1.1219 +			rollBack1=NULL;
  1.1220 +			TEST(testArray.IsEmpty());
  1.1221 +			TRAP(leaveCode,
  1.1222 +				rollBack1=testArray.AddTLC(&dg1234);
  1.1223 +				User::Leave(1234);
  1.1224 +				);	
  1.1225 +			TEST(rollBack1!=NULL);
  1.1226 +			TEST(leaveCode==1234);
  1.1227 +			TEST(testArray.IsEmpty());
  1.1228 +			rollBack1=NULL;
  1.1229 +			CleanupStack::Check(markerCleanup);
  1.1230 +			__UHEAP_CHECK(KArrayMemUseBaseline);
  1.1231 +
  1.1232 +			TRAP(leaveCode,	errCode=testArray.Add(&dgBADF00D));
  1.1233 +			TEST(errCode==KErrNone);
  1.1234 +			TEST(leaveCode==KErrNone);
  1.1235 +			rollBack1=NULL;
  1.1236 +			TRAP(leaveCode,
  1.1237 +				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
  1.1238 +				User::Leave(1234);
  1.1239 +				);	
  1.1240 +			TEST(rollBack1!=NULL);
  1.1241 +			TEST(leaveCode==1234);
  1.1242 +			TEST(!testArray.IsEmpty());
  1.1243 +			rollBack1=NULL;
  1.1244 +			TRAP(leaveCode,
  1.1245 +				rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());
  1.1246 +				TEST(testArray.IsEmpty());
  1.1247 +				User::Leave(1234);
  1.1248 +				);	
  1.1249 +			TEST(rollBack1!=NULL);
  1.1250 +			TEST(leaveCode==1234);
  1.1251 +			TEST(!testArray.IsEmpty());
  1.1252 +			
  1.1253 +			
  1.1254 +				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
  1.1255 +			TEST(errCode==KErrNone);
  1.1256 +			TEST(leaveCode==KErrNone);
  1.1257 +			TEST(testArray.IsEmpty());
  1.1258 +			rollBack1=NULL;
  1.1259 +		break;
  1.1260 +		//
  1.1261 +		case 3:
  1.1262 +			INFO_PRINTF1(_L("Sub test P3: AddLC/SwapLC: Cleanup item gets executed - doesn't leak"));
  1.1263 +			TEST(testArray.IsEmpty());
  1.1264 +			TRAP(leaveCode,
  1.1265 +				testArray.AddLC(&dg1234);
  1.1266 +				User::Leave(1234);
  1.1267 +				);	
  1.1268 +			TEST(leaveCode==1234);
  1.1269 +			TEST(testArray.IsEmpty());
  1.1270 +			rollBack1=NULL;
  1.1271 +		__UHEAP_CHECK(KArrayMemUseBaseline);	  //because it threw it didn't leak
  1.1272 +			
  1.1273 +			//use my new method to add the object to be swapped out so no leak
  1.1274 +			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
  1.1275 +			TEST(errCode==KErrNone);
  1.1276 +			TEST(leaveCode==KErrNone);
  1.1277 +		__UHEAP_CHECK(KArrayMemUseBaseline);	  //new method doesn't leak.
  1.1278 +			rollBack1=NULL;
  1.1279 +			TRAP(leaveCode,
  1.1280 +				errCode=testArray.SwapLC(&dgBADF00D_2);
  1.1281 +				User::Leave(1234);
  1.1282 +				);	
  1.1283 +			TEST(errCode==KErrNone);
  1.1284 +			TEST(leaveCode==1234);
  1.1285 +			TEST(!testArray.IsEmpty());
  1.1286 +			
  1.1287 +				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
  1.1288 +			TEST(errCode==KErrNone);
  1.1289 +			TEST(leaveCode==KErrNone);
  1.1290 +			TEST(testArray.IsEmpty());
  1.1291 +			rollBack1=NULL;
  1.1292 +		break;
  1.1293 +		//
  1.1294 +		case 4:
  1.1295 +	
  1.1296 +		//I don't really care whether the individual calls succeed or fail, 
  1.1297 +		//just whether it leaks overall, and that the error codes correspond to no-action
  1.1298 +		for (TInt faultRate=1;faultRate<5;faultRate++)
  1.1299 +			{
  1.1300 +			INFO_PRINTF2(_L("Sub test P4: Add/Swap: memory faulting %i"),faultRate);
  1.1301 +			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
  1.1302 +			TInt err1=KErrNone;
  1.1303 +			rollBack1=NULL;
  1.1304 +			TRAP(leaveCode,
  1.1305 +				errCode=testArray.Add(&dg1234);
  1.1306 +				)
  1.1307 +			err1=errCode;
  1.1308 +			__UHEAP_SETFAIL(RAllocator::ENone,0);
  1.1309 +			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
  1.1310 +			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
  1.1311 +			rollBack1=NULL;
  1.1312 +			TRAP(leaveCode,
  1.1313 +				errCode=testArray.Swap(&dgBADF00D_2);
  1.1314 +				)
  1.1315 +			__UHEAP_SETFAIL(RAllocator::ENone,0);
  1.1316 +			//If the first Add fails then the object should not be removed
  1.1317 +			if (!err1)
  1.1318 +				{
  1.1319 +				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
  1.1320 +				TEST(errCode==KErrNone);
  1.1321 +				TEST(leaveCode==KErrNone);
  1.1322 +				}
  1.1323 +			//If the swap fails, then the add still needs to be removed
  1.1324 +			//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
  1.1325 +			TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
  1.1326 +			TEST(errCode==KErrNone);
  1.1327 +			TEST(leaveCode==KErrNone);
  1.1328 +			TEST(testArray.IsEmpty());
  1.1329 +			ResetArray(testArray);
  1.1330 +			CleanupStack::Check(markerCleanup);
  1.1331 +			__UHEAP_CHECK(0);
  1.1332 +			}
  1.1333 +		break;
  1.1334 +		//
  1.1335 +		case 5:
  1.1336 +				
  1.1337 +		//I don't really care whether the individual calls succeed or fail, 
  1.1338 +		//just whether it leaks overall, and that the error codes correspond to no-action
  1.1339 +		for (TInt faultRate=1;faultRate<5;faultRate++)
  1.1340 +			{
  1.1341 +			INFO_PRINTF2(_L("Sub test P5: AddTLC/SwapTLC: memory faulting %i"),faultRate);
  1.1342 +			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
  1.1343 +			TInt err1=KErrNone,err2=KErrNone,err3=KErrNone;
  1.1344 +			rollBack1=NULL;
  1.1345 +			TRAP(leaveCode,
  1.1346 +				rollBack1=testArray.AddTLC(&dg1234);
  1.1347 +				CleanupStack::Check(rollBack1);
  1.1348 +				testArray.CommitP(rollBack1);	
  1.1349 +				)
  1.1350 +			err1=leaveCode;
  1.1351 +			__UHEAP_SETFAIL(RAllocator::ENone,0);
  1.1352 +			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
  1.1353 +			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
  1.1354 +			rollBack1=NULL;
  1.1355 +			TRAP(leaveCode,
  1.1356 +				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
  1.1357 +				CleanupStack::Check(rollBack1);
  1.1358 +				testArray.CommitP(rollBack1);	
  1.1359 +				)
  1.1360 +			//If the first Add fails then the object should not be removed
  1.1361 +			if (!err1)
  1.1362 +				{
  1.1363 +				TRAP(leaveCode,
  1.1364 +					rollBack1=testArray.RemoveTLC(dg1234.Id());			
  1.1365 +					CleanupStack::Check(rollBack1);
  1.1366 +					testArray.CommitP(rollBack1);	
  1.1367 +					)
  1.1368 +				err2=leaveCode;
  1.1369 +				}
  1.1370 +			//If the swap fails, then the add still needs to be removed
  1.1371 +			//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
  1.1372 +			TRAP(leaveCode,
  1.1373 +					rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());
  1.1374 +					CleanupStack::Check(rollBack1);
  1.1375 +					testArray.CommitP(rollBack1);	
  1.1376 +					)
  1.1377 +			err3=leaveCode;
  1.1378 +			
  1.1379 +			
  1.1380 +			__UHEAP_SETFAIL(RAllocator::ENone,0);
  1.1381 +			//If the Removes failed then the object should be removed again
  1.1382 +			if (err2)
  1.1383 +				{
  1.1384 +				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
  1.1385 +				TEST(errCode==KErrNone);
  1.1386 +				TEST(leaveCode==KErrNone);
  1.1387 +				}
  1.1388 +			if (err3)
  1.1389 +				{
  1.1390 +				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
  1.1391 +				TEST(errCode==KErrNone);
  1.1392 +				TEST(leaveCode==KErrNone);
  1.1393 +				}
  1.1394 +			TEST(testArray.IsEmpty());
  1.1395 +			ResetArray(testArray);
  1.1396 +			CleanupStack::Check(markerCleanup);
  1.1397 +			__UHEAP_CHECK(0);
  1.1398 +			}
  1.1399 +				
  1.1400 +		break;
  1.1401 +		//
  1.1402 +		case 6:
  1.1403 +	//this set does leak:
  1.1404 +	
  1.1405 +		INFO_PRINTF1(_L("Sub test P6: AddLC/SwapLC: Cleanup item gets popped - unfixable leaks"));
  1.1406 +			TEST(testArray.IsEmpty());
  1.1407 +			TRAP(leaveCode,
  1.1408 +				testArray.AddLC(&dg1234);
  1.1409 +				CleanupStack::Pop();
  1.1410 +				);	
  1.1411 +			TEST(leaveCode==KErrNone);
  1.1412 +			TEST(!testArray.IsEmpty());
  1.1413 +		
  1.1414 +		CleanupStack::Check(markerCleanup);
  1.1415 +		__UHEAP_CHECK(KArrayMemUseBaseline+1);	
  1.1416 +			
  1.1417 +			TRAP(leaveCode,
  1.1418 +				testArray.AddLC(&dgBADF00D);
  1.1419 +				CleanupStack::Pop();
  1.1420 +				)
  1.1421 +			TEST(leaveCode==KErrNone);
  1.1422 +		CleanupStack::Check(markerCleanup);
  1.1423 +		__UHEAP_CHECK(KArrayMemUseBaseline+2);	
  1.1424 +			rollBack1=NULL;
  1.1425 +			TRAP(leaveCode,
  1.1426 +				errCode=testArray.SwapLC(&dgBADF00D_2);
  1.1427 +				CleanupStack::Pop();
  1.1428 +				);	
  1.1429 +			TEST(errCode==KErrNone);
  1.1430 +			TEST(leaveCode==KErrNone);
  1.1431 +			TEST(!testArray.IsEmpty());
  1.1432 +				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
  1.1433 +			TEST(errCode==KErrNone);
  1.1434 +			TEST(leaveCode==KErrNone);
  1.1435 +				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
  1.1436 +			TEST(errCode==KErrNone);
  1.1437 +			TEST(leaveCode==KErrNone);
  1.1438 +			TEST(testArray.IsEmpty());
  1.1439 +			rollBack1=NULL;
  1.1440 +			expectedLeakCount=3;
  1.1441 +		break;
  1.1442 +		//
  1.1443 +		case 7:
  1.1444 +			returnCode=EFalse;
  1.1445 +		break;
  1.1446 +		}
  1.1447 +	ResetArray(testArray);
  1.1448 +	CleanupStack::Check(markerCleanup);
  1.1449 +	__UHEAP_CHECK(expectedLeakCount);
  1.1450 +	__UHEAP_MARKENDC(expectedLeakCount);
  1.1451 +	if (expectedLeakCount!=0)
  1.1452 +		{	//Ensure that the leaked items are no longer associated with this debug level.
  1.1453 +			//Note that __DbgSetAllocFail(FALSE,RAllocator::EReset,1) resets the debug level to 0, 
  1.1454 +			//so levels can't be nested when using this call.
  1.1455 +		__UHEAP_MARK;			
  1.1456 +	    __UHEAP_TOTAL_RESET;	
  1.1457 +		INFO_PRINTF2(_L("Anticipated %i leaks declassified"),expectedLeakCount);	//can't get here if wrong
  1.1458 +		}
  1.1459 +			
  1.1460 +	CleanupStack::PopAndDestroy(markerCleanup);
  1.1461 +	((CTWsGraphsStep*)iStep)->RecordTestResultL();
  1.1462 +	return returnCode;
  1.1463 +	}
  1.1464 +
  1.1465 +/**
  1.1466 +	@param 	failcase		index to test to perform
  1.1467 +	@param	aWrappedParams  represents inter-thread information when test is run on a private thread
  1.1468 +				if aWrappedParams is NULL then the test is running on the main thread.
  1.1469 +	@return true if there are higher-numbered fail cases.
  1.1470 +
  1.1471 +   @SYMTestCaseID GRAPHICS-WSERV-NegAddSwapGDArray-0001
  1.1472 +   @SYMDEF			DEF093926  
  1.1473 +  
  1.1474 +   @SYMTestCaseDesc DEF093926: Check for stability of Add and Swap unwind methods in isolation,
  1.1475 +   					specifically checking that bad inputs are rejected gracefully.
  1.1476 +   		Note that this code is testing the functionality of a class internal to CWindowServer.
  1.1477 +   		At present CWindowServer presents just a simple shim on this class, 
  1.1478 +   		but if that implementation of  CWindowServer changes than this test will be redudant.
  1.1479 +   
  1.1480 +   @SYMTestPriority High
  1.1481 +   
  1.1482 +   @SYMTestStatus Implemented
  1.1483 +   
  1.1484 +   @SYMTestActions
  1.1485 +   
  1.1486 +		Add/Swap: no Cleanup item - no leaks after Remove the added items
  1.1487 +   	    AddTLC/SwapTLC: Cleanup item requires Commit - check for no leaks after Remove.
  1.1488 +   	    AddTLC/SwapTLC: Cleanup item gets executed by forced Leave  - check for no leaks after.
  1.1489 +		AddTLC, SwapTLC in allocation failure scenarios. Add/Swap don't allocate anything!
  1.1490 +		obsoleted AddLC/SwapLC to ensure correct function when forced Leave - check for no leaks after
  1.1491 +		obsoleted AddLC/SwapLC to ensure correct function. These will always leak in good case.
  1.1492 +	Calls NegTestAddSwapGDArrayL.	
  1.1493 +	case 1/2/3: Tests AddL, AddLC, AddTLC that a NULL input is rejected
  1.1494 +	case 4/5/6: Tests SwapL, SwapLC, SwapTLC that a NULL input is rejected
  1.1495 +	case 7/8/9: Tests AddL, AddLC, AddTLC that a repeat input is rejected
  1.1496 +	case 10/11/12: Tests SwapL, SwapLC, SwapTLC that a non-repeat input is rejected
  1.1497 +   @SYMTestExpectedResults 
  1.1498 + */
  1.1499 +TBool CTWsGraphs::NegTestAddSwapGDArrayL(TInt failcase,WrapTestCall*aWrappedParams)
  1.1500 +	{
  1.1501 +	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-NegAddSwapGDArray-0001"));
  1.1502 +	_LIT(KCategory,"WsGraphicDrawer");
  1.1503 +	if (!aWrappedParams)
  1.1504 +		{
  1.1505 +		INFO_PRINTF2(_L("NegTestAddSwapGDArrayL Negative sub test %i"),failcase);
  1.1506 +		};
  1.1507 +    CWsGraphicDrawerArray testArray;
  1.1508 +    TGraphicDrawerId id1234=  	{  	1234,		EFalse    	};
  1.1509 +    TGraphicDrawerId idBADF00D=	{  	0xBADF00D,	EFalse    	};
  1.1510 +    WsGraphicDrawer dg1234;		
  1.1511 +    dg1234.ConstructL(id1234);
  1.1512 +    WsGraphicDrawer dgBADF00D;	
  1.1513 +    dgBADF00D.ConstructL(idBADF00D);
  1.1514 +    WsGraphicDrawer dgBADF00D_2;
  1.1515 +    dgBADF00D_2.ConstructL(idBADF00D);
  1.1516 +    CWsGraphicDrawerArray::XRollBackBase* rollBack1=NULL;
  1.1517 + 	TInt errCode=KErrAbort;
  1.1518 +	TInt leaveCode=KErrNone;
  1.1519 +	TBool	returnMoreTests=ETrue;
  1.1520 +	DummyCleanup markerCleanup;
  1.1521 +	TBool mayPanic=EFalse;
  1.1522 +#ifdef __WINS__
  1.1523 +	mayPanic=ETrue;
  1.1524 +#endif
  1.1525 +
  1.1526 +	CleanupStack::PushL(markerCleanup);	 //This allows me to check the stack is clear!
  1.1527 +	__UHEAP_MARK;
  1.1528 +	
  1.1529 +	switch (failcase)
  1.1530 +		{
  1.1531 +		case 1:	//NULL arg: expected result:  returns KErrArgument
  1.1532 +	    	TRAP(leaveCode,
  1.1533 +	    		errCode=testArray.Add(NULL);
  1.1534 +	    		)
  1.1535 +			TEST(leaveCode==KErrNone);
  1.1536 +	    	ReportNegativeResultfail(__LINE__,errCode,KErrArgument);
  1.1537 +	    break;
  1.1538 +		case 2:	//NULL arg: expected result: throws KErrArgument
  1.1539 +			TRAP(leaveCode,	
  1.1540 +				rollBack1=testArray.AddTLC(NULL);
  1.1541 +				TEST(EFalse);	//Should never get here!
  1.1542 +				)
  1.1543 +			TEST(rollBack1==NULL);
  1.1544 +	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrArgument);
  1.1545 +	    break;
  1.1546 +		case 3:	//NULL arg: expected result: debug: panic. In release doesn't return any information!
  1.1547 +			if (!aWrappedParams && mayPanic)
  1.1548 +				{
  1.1549 +			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
  1.1550 +				}
  1.1551 +			else
  1.1552 +				{
  1.1553 +				TRAP(leaveCode,
  1.1554 +					testArray.AddLC(NULL);
  1.1555 +					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
  1.1556 +					);	
  1.1557 +				TEST(leaveCode==1234);	//Panics before here in debug
  1.1558 +				}
  1.1559 +	    break;
  1.1560 +		//
  1.1561 +		case 4:	//NULL arg: expected result: returns KErrArgument
  1.1562 +	    	TRAP(leaveCode,
  1.1563 +	    		errCode=testArray.Swap(NULL)
  1.1564 +	    		)
  1.1565 +			TEST(leaveCode==KErrNone);
  1.1566 +	    	ReportNegativeResultfail(__LINE__,errCode,KErrArgument);
  1.1567 +	    break;
  1.1568 +		case 5:	//expected result:  throws KErrArgument
  1.1569 +			TRAP(leaveCode,
  1.1570 +				rollBack1=testArray.SwapTLC(NULL);
  1.1571 +				testArray.CommitP(rollBack1);
  1.1572 +				)
  1.1573 +			TEST(rollBack1==NULL);
  1.1574 +	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrArgument);
  1.1575 +	    break;
  1.1576 +		case 6:	//NULL arg: expected result: debug: panic. In release doesn't return any information!
  1.1577 +			if (!aWrappedParams && mayPanic)
  1.1578 +				{
  1.1579 +			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
  1.1580 +				}
  1.1581 +			else
  1.1582 +				{
  1.1583 +				TRAP(leaveCode,
  1.1584 +					errCode=testArray.SwapLC(NULL);
  1.1585 +					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
  1.1586 +					);
  1.1587 +				TEST(leaveCode==1234);	//Panics before here in debug
  1.1588 +				TEST(errCode==KErrNotFound);
  1.1589 +				}
  1.1590 +		break;
  1.1591 +		//
  1.1592 +		case 7:	//Add overwrites: expected result: returns KErrAlreadyExists
  1.1593 +	    	TRAP(leaveCode,
  1.1594 +	    		errCode=testArray.Add(&dg1234);
  1.1595 +	    		)
  1.1596 +			TEST(errCode==KErrNone);
  1.1597 +			TEST(leaveCode==KErrNone);
  1.1598 +	    	TRAP(leaveCode,
  1.1599 +	    		errCode=testArray.Add(&dg1234);		//oops! Already added!
  1.1600 +	    		)
  1.1601 +			TEST(leaveCode==KErrNone);
  1.1602 +	    	ReportNegativeResultfail(__LINE__,errCode,KErrAlreadyExists);
  1.1603 +	    break;
  1.1604 +		case 8:	//Add overwrites: expected result:  throws KErrAlreadyExists
  1.1605 +	    	TRAP(leaveCode,
  1.1606 +	    		errCode=testArray.Add(&dg1234);
  1.1607 +	    		)
  1.1608 +			TEST(errCode==KErrNone);
  1.1609 +			TEST(leaveCode==KErrNone);
  1.1610 +			TRAP(leaveCode,	
  1.1611 +				rollBack1=testArray.AddTLC(&dg1234);		//oops! Already added!
  1.1612 +				testArray.CommitP(rollBack1);
  1.1613 +				)
  1.1614 +			TEST(rollBack1==NULL);
  1.1615 +	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrAlreadyExists);
  1.1616 +	    break;
  1.1617 +		case 9:	//Add overwrites: expected result: debug: does not panic, but throws KErrAlreadyExists.
  1.1618 +	    	TRAP(leaveCode,
  1.1619 +	    		errCode=testArray.Add(&dg1234);
  1.1620 +	    		)
  1.1621 +			TEST(errCode==KErrNone);
  1.1622 +			TEST(leaveCode==KErrNone);
  1.1623 +			TRAP(leaveCode,
  1.1624 +					testArray.AddLC(&dg1234);		//oops! Already added! Should leave.
  1.1625 +					User::Leave(1234);  //Should leave before here! No leak if cleanup is taken.
  1.1626 +				);	
  1.1627 +	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrAlreadyExists);
  1.1628 +	    break;
  1.1629 +		//
  1.1630 +		case 10:	//Swap empty slot: expected result:  returns KErrNotFound
  1.1631 +	    	TRAP(leaveCode,
  1.1632 +	    		errCode=testArray.Swap(&dg1234) 		//oops! Nothing to swap with!
  1.1633 +	    		)
  1.1634 +			TEST(leaveCode==KErrNone);
  1.1635 +	    	ReportNegativeResultfail(__LINE__,errCode,KErrNotFound);
  1.1636 +	    break;
  1.1637 +		case 11:	//Swap empty slot: expected result: throws KErrNotFound
  1.1638 +			TRAP(leaveCode,
  1.1639 +				rollBack1=testArray.SwapTLC(&dg1234);		//oops! Nothing to swap with!
  1.1640 +				testArray.CommitP(rollBack1);
  1.1641 +				)
  1.1642 +			TEST(rollBack1==NULL);
  1.1643 +	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrNotFound);
  1.1644 +	    break;
  1.1645 +		case 12:	//Swap empty slot: expected result: debug: panic. In release doesn't return any information!
  1.1646 +			if (!aWrappedParams && mayPanic)
  1.1647 +				{
  1.1648 +			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
  1.1649 +				}
  1.1650 +			else
  1.1651 +				{
  1.1652 +				TRAP(leaveCode,
  1.1653 +					errCode=testArray.SwapLC(&dg1234);		//oops! Nothing to swap with!
  1.1654 +					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
  1.1655 +					);	
  1.1656 +				TEST(leaveCode==1234);			//Panics before here in debug
  1.1657 +				TEST(errCode==KErrNotFound);	//Panics before here in debug
  1.1658 +				}
  1.1659 +	    break;
  1.1660 +	    
  1.1661 +		//
  1.1662 +		default:
  1.1663 +			returnMoreTests=EFalse;
  1.1664 +		}
  1.1665 +	ResetArray(testArray);
  1.1666 +	CleanupStack::Check(markerCleanup);
  1.1667 +	__UHEAP_CHECK(0);
  1.1668 +	__UHEAP_MARKENDC(0);
  1.1669 +    testArray.Close();
  1.1670 +//    CWsGraphicDrawerArray::testArrayValidator::ResetArray(&testArray);
  1.1671 +	CleanupStack::PopAndDestroy(markerCleanup);
  1.1672 +	return returnMoreTests;
  1.1673 +	}
  1.1674 +
  1.1675 +/**
  1.1676 +   @SYMTestCaseID 	GRAPHICS-WSERV-LeakInService-0001
  1.1677 +   @SYMDEF			DEF093926  
  1.1678 +   @SYMTestCaseDesc Check for leaks over repeated re-assignments.
  1.1679 +   
  1.1680 +   @SYMTestPriority High
  1.1681 +   
  1.1682 +   @SYMTestStatus Implemented
  1.1683 +   
  1.1684 +   @SYMTestActions 
  1.1685 +   Repeatedly create the same bitmap instance
  1.1686 +   After a few initial wobbles in the server-side HeapCount it should not increase
  1.1687 +   5 calls are made without checking the level, then 5 more check the level.
  1.1688 +   Note that as we are testing the main server heap, 
  1.1689 +   other threads may interrupt and perform operations that change the memory figures.
  1.1690 +   
  1.1691 +   @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no leaks are reported.
  1.1692 + */	
  1.1693 +void CTWsGraphs::DoTestLeakInServiceL()
  1.1694 +	{
  1.1695 +		INFO_PRINTF1(_L("DoTestLeakInServiceL"));
  1.1696 +		const TInt prepCount=5;
  1.1697 +		const TInt testCount=5;
  1.1698 +		
  1.1699 +				
  1.1700 +		TUid uid1 = {0x10000001};
  1.1701 +		TUid uid2 = {0x10000002};
  1.1702 +		 
  1.1703 +		TWsGraphicId twsGraphicId1(uid1);
  1.1704 +		TEST(twsGraphicId1.Uid()==uid1);
  1.1705 +		
  1.1706 +		TWsGraphicId twsGraphicId2(uid2);
  1.1707 +		TEST(twsGraphicId2.Uid()==uid2);
  1.1708 +		
  1.1709 +		TWsGraphicId twsGraphicId3(twsGraphicId2);
  1.1710 +		TEST(twsGraphicId3.Uid()==uid2);
  1.1711 +		
  1.1712 +		TWsGraphicId twsGraphicId4(1);
  1.1713 +		twsGraphicId4.Set(uid1);
  1.1714 +		TEST(twsGraphicId4.Uid()==uid1);		
  1.1715 +
  1.1716 +		TSize screenSize = TheClient->iScreen->SizeInPixels();
  1.1717 +		
  1.1718 +		__UHEAP_RESET;
  1.1719 +		__UHEAP_MARK;
  1.1720 +		// Create local shared CWsGraphicBitmap	
  1.1721 +		// Repeat operation for any sign of memory leak...	
  1.1722 +		CFbsBitmap bitmap2;
  1.1723 +		CFbsBitmap mask2;		
  1.1724 +		
  1.1725 +		bitmap2.Create(screenSize,TheClient->iScreen->DisplayMode());
  1.1726 +		mask2.Create(bitmap2.SizeInPixels(),TheClient->iScreen->DisplayMode());
  1.1727 +			
  1.1728 +		TInt c0=TheClient->iWs.HeapCount();
  1.1729 +		CWsGraphicBitmap* bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
  1.1730 +		for (TInt i=0;i<prepCount;i++)
  1.1731 +			{
  1.1732 +			//TInt c2=TheClient->iWs.HeapCount();
  1.1733 +			delete bTestX; 								
  1.1734 +			//TInt c3=TheClient->iWs.HeapCount();
  1.1735 +			bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
  1.1736 +			//TInt c4=TheClient->iWs.HeapCount();
  1.1737 +			}
  1.1738 +		// Give WSERV a chance to settle.
  1.1739 +		TheClient->iWs.Finish();
  1.1740 +		User::After (1000000); //1s
  1.1741 +		
  1.1742 +		TInt c1=TheClient->iWs.HeapCount();
  1.1743 +		TInt failures=0;
  1.1744 +		for (TInt i=0;i<testCount;i++)
  1.1745 +			{
  1.1746 +			TInt c2=TheClient->iWs.HeapCount();
  1.1747 +			delete bTestX;
  1.1748 +			//TInt c3=TheClient->iWs.HeapCount();
  1.1749 +			//The heap count doesn't go down after delete operation
  1.1750 +			//because the delete message is buffered by the server, because it does not have a return value.
  1.1751 +			//Aparrently, although CWsGraphicBitmap and TheClient terminate at the same server,
  1.1752 +			//and use the same general heap (I have tested this under debug),
  1.1753 +			//they do not share the same session, so flushing TheClient does not effect CWsGraphicBitmap
  1.1754 +			bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
  1.1755 +			
  1.1756 +			// Give WSERV a chance to settle.
  1.1757 +			TheClient->iWs.Finish();
  1.1758 +			User::After (1000000); //1s
  1.1759 +
  1.1760 +			TInt c4=TheClient->iWs.HeapCount();   
  1.1761 +			//Can compare immediately after allocation as the server doesn't buffer the create command.
  1.1762 +			if (!(c2==c4))
  1.1763 +				{
  1.1764 +				if (c4 > c2) // only fail the test if the count has increased
  1.1765 +					{
  1.1766 +					failures++;
  1.1767 +					}
  1.1768 +				INFO_PRINTF2(_L("Server Heap count change accross delete/new = %i"),c4-c2);
  1.1769 +				}
  1.1770 +			}
  1.1771 +		// Outside of main loop to avoid client/wserv interaction during test.
  1.1772 +		TEST(failures==0);
  1.1773 +		TInt c5=TheClient->iWs.HeapCount();
  1.1774 +		TEST((c1-c5)/testCount==0);	   //If every call leaked.
  1.1775 +		if ((c1-c5)/testCount)
  1.1776 +			{
  1.1777 +			INFO_PRINTF3(_L("Server Heap count change accross %i delete/new cycles = %i"),testCount,c5-c1);
  1.1778 +			INFO_PRINTF3(_L("Before %i / After %i"),c1,c5);
  1.1779 +			}
  1.1780 +		
  1.1781 +		delete bTestX; 
  1.1782 +		
  1.1783 +		__UHEAP_CHECK(0);
  1.1784 +		__UHEAP_MARKEND;
  1.1785 +		
  1.1786 +	}
  1.1787 +/**
  1.1788 + @SYMTestCaseID				GRAPHICS-WSERV-0381 
  1.1789 + @SYMDEF					DEF095063
  1.1790 + @SYMTestCaseDesc			Test case for INC098114 CWsGraphicDrawer::SendMessage panics window server
  1.1791 + @SYMTestPriority			Medium
  1.1792 + @SYMTestStatus				Implemented
  1.1793 + @SYMTestActions			Enable the test flag and reproduce the defect
  1.1794 +							Action step:
  1.1795 +							-Instruct plugin to register event handler
  1.1796 +							-Draw fullscreen window (plugin will receive window visibility changed event)
  1.1797 +							-Set the test flag 
  1.1798 +							-Query visibility region from plugin side
  1.1799 +							-Instruct plugin to unregister event handler
  1.1800 +							-Destroy fullscreen window (plugin will not receive window visibility changed event)
  1.1801 +						
  1.1802 + @SYMTestExpectedResults	wserv should not panic with the fix
  1.1803 +*/	
  1.1804 +
  1.1805 +TestState CTWsGraphs::TestSuccessiveMessageL()
  1.1806 +	{
  1.1807 +	if (iSubState==0)
  1.1808 +		{
  1.1809 +		_LIT(KTestSuccessiveMessage, "TestSuccessiveMessage");
  1.1810 +		INFO_PRINTF1(KTestSuccessiveMessage);
  1.1811 +
  1.1812 +		++iSubState;
  1.1813 +		iListen->Enable(ETrue);
  1.1814 +		CreateWindowL();
  1.1815 +		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
  1.1816 +		//Set the test flag to enable the reproduction of defect
  1.1817 +		iListen->SetTestFlag();
  1.1818 +		iListen->QueryPlugin(iListenInfo);
  1.1819 +		iListen->Enable(EFalse);
  1.1820 +		DestroyWindowL();
  1.1821 +		return EWait;
  1.1822 +		}
  1.1823 +
  1.1824 +	++(iTest->iState);
  1.1825 +	iSubState = 0;
  1.1826 +	return ENext;
  1.1827 +	}
  1.1828 +
  1.1829 +TestState CTWsGraphs::TestWindowGroupChangeL()
  1.1830 +	{
  1.1831 +	if (iSubState==0)
  1.1832 +		{
  1.1833 +		_LIT(KTestWindowGroupChange, "TestWindowGroupChange");
  1.1834 +		INFO_PRINTF1(KTestWindowGroupChange);
  1.1835 +
  1.1836 +		++iSubState;
  1.1837 +		iListen->Enable(ETrue);
  1.1838 +		CreateWindowL();
  1.1839 +		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
  1.1840 +		iListen->QueryPlugin(iListenInfo);
  1.1841 +		return EWait;
  1.1842 +		}
  1.1843 +
  1.1844 +	if (iSubState==1)
  1.1845 +		{
  1.1846 +		++iSubState;
  1.1847 +		iOriginalWindowGroupId = iListenInfo.iWindowGroupId;
  1.1848 +		iNewWin = CCrWin::NewL(iTest->iScreenNumber, ETrue);
  1.1849 +		iListen->QueryPlugin(iListenInfo);
  1.1850 +		return EWait;
  1.1851 +		}
  1.1852 +
  1.1853 +	TEST(iListenInfo.iWindowGroupId != iOriginalWindowGroupId);
  1.1854 +	
  1.1855 +	delete iNewWin;
  1.1856 +	iNewWin = NULL;
  1.1857 +	iListen->Enable(EFalse);
  1.1858 +	DestroyWindowL();
  1.1859 +	++(iTest->iState);
  1.1860 +	iSubState = 0;
  1.1861 +	return ENext;
  1.1862 +	}
  1.1863 +
  1.1864 +/**
  1.1865 + @SYMTestCaseID				GRAPHICS-WSERV-0382
  1.1866 + @SYMDEF 					INC085451
  1.1867 + @SYMTestCaseDesc			Test Animation frame rate
  1.1868 + @SYMTestPriority			Medium
  1.1869 + @SYMTestStatus				Implemented
  1.1870 + @SYMTestActions			Simulate an Animation artwork by calling DrawWsGraphic and DoDraw.
  1.1871 +							Action step:
  1.1872 +							-Calls DrawWsGraphic for two different animations with different frame rates
  1.1873 +							-Retrieve the frame count for two differnt frames per seconds
  1.1874 +							-Test the two frame rate shouldn't be same.
  1.1875 +
  1.1876 + @SYMTestExpectedResults	Animation Frame rate should be different for different frames per second
  1.1877 +*/
  1.1878 +TestState CTWsGraphs::TestFrameRateL()
  1.1879 +	{
  1.1880 +	//Check for Transparency enabled in wsini.ini
  1.1881 +	if (TransparencySupportedL()==KErrNotSupported)
  1.1882 +		{
  1.1883 +		++(iTest->iState);
  1.1884 +		return ENext;
  1.1885 +		}
  1.1886 +
  1.1887 +	// flush transparent window destruction created in TransparencySupportedL before
  1.1888 +	// proceeding with the test
  1.1889 +	TheClient->iWs.Flush();
  1.1890 +
  1.1891 +	//Here 	iSubState is 0, when this functions executes first time 
  1.1892 +	//		iSubState is 1 means the call is from a callback function.
  1.1893 +	if(iSubState == 0)
  1.1894 +		{
  1.1895 +		_LIT(KTestFrameRate, "TestFrameRate");
  1.1896 +		INFO_PRINTF1(KTestFrameRate);
  1.1897 +
  1.1898 +		++iSubState;
  1.1899 +		iTestframerate = CGraphicTestFrameRate::NewL(iTest->iScreenNumber);
  1.1900 +
  1.1901 +		//Set the callback function
  1.1902 +		iTestframerate->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
  1.1903 +
  1.1904 +		//Create the window and call the graphic animation
  1.1905 +		CreateWindowL(EFalse);
  1.1906 +		iWin->DrawGraphic(iTestframerate->Id().Id());
  1.1907 +		return EWait;
  1.1908 +		}
  1.1909 +
  1.1910 +	//PeterI wait a while for animations to redraw then query the plugin
  1.1911 +	User::After(2000000);
  1.1912 +	TheClient->iWs.Flush();
  1.1913 +	TheClient->WaitForRedrawsToFinish();
  1.1914 +	TheClient->iWs.Finish();
  1.1915 +
  1.1916 +	//Invoke the plug-in and get the counter value
  1.1917 +	Mem::FillZ(&iAnimCount, sizeof(TAnimRate));
  1.1918 +
  1.1919 +	iTestframerate->QueryPlugin(iAnimCount);
  1.1920 +	TheClient->iWs.Flush();
  1.1921 +	TheClient->WaitForRedrawsToFinish();
  1.1922 +	TheClient->iWs.Finish();
  1.1923 +
  1.1924 +	//Compare and test the total frame rate for two different frame counts....
  1.1925 +	TEST((iAnimCount.iAnim1>0 && iAnimCount.iAnim2>0) && iAnimCount.iAnim1 !=iAnimCount.iAnim2);
  1.1926 +	if(iSubState == 1)
  1.1927 +		{
  1.1928 +		DestroyWindowL();
  1.1929 +		delete iTestframerate;
  1.1930 +		}
  1.1931 +	++(iTest->iState);
  1.1932 +	iSubState = 0;
  1.1933 +	return ENext;
  1.1934 +	}
  1.1935 +
  1.1936 +/**
  1.1937 + @SYMTestCaseID				GRAPHICS-WSERV-0438 
  1.1938 + @SYMDEF					INC103472
  1.1939 + @SYMTestCaseDesc			CRedrawRegion::ContainsDrawers does not look for all drawers 
  1.1940 + @SYMTestPriority			Medium
  1.1941 + @SYMTestStatus				Implemented
  1.1942 + @SYMTestActions			Create ECom-plugins to enable the scenario, in which there is one simple and one container drawer. 
  1.1943 + 							In the container drawer, two other simple drawers are enabled. Each drawer draws a coloured ellipse.
  1.1944 + 							In this case, when the contained drawer is requested to change the colour of the ellipse, the screen will not be updated
  1.1945 + 							without the fix.  
  1.1946 + 							Action step:
  1.1947 +							-Create four CRP graphics.
  1.1948 +							-Call the simple drawer and container drawer to draw ellipses. The container drawer
  1.1949 +							 also enables two other simple drawers to draw ellipses in different colors.
  1.1950 +							-Update the color of each ellipse in turn. 
  1.1951 +							-Check that the screen display is as required.						
  1.1952 + @SYMTestExpectedResults	The colour of each ellipse residing in the drawers is successfully updated. Those for the contained drawers wont be updated without the fix. 
  1.1953 +*/	
  1.1954 +void CTWsGraphs::TestNestedDrawerCRP()
  1.1955 +	{
  1.1956 +	_LIT(KTestContainDrawer, "Test INC103472: A Contained Drawer");
  1.1957 +	INFO_PRINTF1(KTestContainDrawer);
  1.1958 +
  1.1959 +	RWindow window1(TheClient->iWs);
  1.1960 +	CleanupClosePushL(window1);
  1.1961 +	User::LeaveIfError(window1.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
  1.1962 +	
  1.1963 +	window1.EnableRedrawStore(ETrue);	// Force to enable the redraw storing
  1.1964 +	window1.SetRequiredDisplayMode(EColor256);	 // Do not set window size here to avoid hardware test failure
  1.1965 +	window1.SetBackgroundColor(KRgbDarkGreen);
  1.1966 +	window1.Activate();
  1.1967 +	
  1.1968 +	// A simple graphic
  1.1969 +	CWsSimpleGraphicBitmap* wsGraphic1 = CWsSimpleGraphicBitmap::NewL(KSimpleDrawerInterfaceId);
  1.1970 +	CleanupStack::PushL(wsGraphic1);
  1.1971 +	// A container graphic
  1.1972 +	CWsContainGraphicBitmap* wsGraphic2 = CWsContainGraphicBitmap::NewL(KContainDrawerInterfaceId);
  1.1973 +	CleanupStack::PushL(wsGraphic2);
  1.1974 +	// A contained graphic residing in the container graphic wsGraphic2 
  1.1975 + 	CWsSimpleGraphicBitmap* wsGraphic3 = CWsInvisibleGraphicBitmap1::NewL(KInvisibleDrawerInterfaceId1);
  1.1976 + 	CleanupStack::PushL(wsGraphic3);
  1.1977 +	// A contained graphic residing in the container graphic wsGraphic2
  1.1978 + 	CWsSimpleGraphicBitmap* wsGraphic4 = CWsInvisibleGraphicBitmap2::NewL(KInvisibleDrawerInterfaceId2);
  1.1979 + 	CleanupStack::PushL(wsGraphic4);
  1.1980 +
  1.1981 +    window1.Invalidate();
  1.1982 +	window1.BeginRedraw();
  1.1983 +	TheClient->iGc->Activate(window1);
  1.1984 +	TheClient->iGc->Clear();
  1.1985 +	// Call CRP drawer to draw the coloured ellipses	
  1.1986 +	TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),TRect(TPoint(20,20),TSize(300,100)));
  1.1987 +	TheClient->iGc->DrawWsGraphic(wsGraphic2->Id(),TRect(TPoint(20,100),TSize(300,100)));	
  1.1988 +
  1.1989 +    TheClient->iGc->Deactivate();
  1.1990 +	window1.EndRedraw();
  1.1991 +	TheClient->Flush();			   
  1.1992 +	
  1.1993 +	// Update the colour of four ellipses residing in four CRP drawers. 
  1.1994 +	TInt err = wsGraphic1->UpdateColor(KRgbRed);
  1.1995 +	TEST(KErrNone == err);
  1.1996 +	err = wsGraphic2->UpdateColor(KRgbDarkBlue);
  1.1997 +	TEST(KErrNone == err);
  1.1998 +	// If the fix is not inserted, the colour of the third and fourth ellipses residing in the contained drawers wont be updated
  1.1999 +	err = wsGraphic3->UpdateColor(KRgbDarkMagenta);
  1.2000 +	TEST(KErrNone == err);
  1.2001 +	err = wsGraphic4->UpdateColor(KRgbDarkCyan);	  //won't change the displayed color if there is a right place for flush()
  1.2002 +	TEST(KErrNone == err);
  1.2003 +	
  1.2004 +	TheClient->Flush();
  1.2005 + 	// Force some delays to wait until the color change
  1.2006 +    User::After(2000000);
  1.2007 +    // Test whether the screen content is changed as required
  1.2008 +    CheckResult();
  1.2009 +   	CleanupStack::PopAndDestroy(5,&window1);
  1.2010 +	}
  1.2011 +
  1.2012 +// Check the screen display with the reference bitmap to ensure the color to be updated correctly
  1.2013 +void CTWsGraphs::CheckResult()
  1.2014 +	{
  1.2015 +    TSize size = TSize(320,200);//The maximum size of the screen content we are looking at
  1.2016 +
  1.2017 +    // Create a reference bitmap
  1.2018 +    CFbsBitmap* bitmapRef = new(ELeave) CFbsBitmap;
  1.2019 +   	CleanupStack::PushL(bitmapRef);
  1.2020 +	User::LeaveIfError(bitmapRef->Create(size, EColor256));
  1.2021 +	CFbsBitGc* gc;
  1.2022 +	CFbsBitmapDevice* bitmapDev = CFbsBitmapDevice::NewL(bitmapRef);
  1.2023 +	TEST(bitmapDev!=NULL);
  1.2024 +   	CleanupStack::PushL(bitmapDev);
  1.2025 +	User::LeaveIfError(bitmapDev->CreateContext(gc));
  1.2026 +   	CleanupStack::PushL(gc);
  1.2027 +	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2028 +	gc->SetBrushColor(KRgbDarkGreen);
  1.2029 +	gc->Clear(TRect(TPoint(0,0), size));//background dark green
  1.2030 +	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2031 +    gc->SetBrushColor(KRgbRed);
  1.2032 +	gc->DrawEllipse(TRect(TPoint(20,20),TSize(300,100)));  //map to the simple drawer
  1.2033 +	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2034 +	gc->SetBrushColor(KRgbDarkBlue);
  1.2035 +	gc->DrawEllipse(TRect(TPoint(20,100),TSize(300,100)));	//map to the container drawer
  1.2036 +	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2037 +	gc->SetBrushColor(KRgbDarkMagenta);
  1.2038 +	gc->DrawEllipse(TRect(TPoint(100,150),TSize(50,50)));	//map to the contained drawer
  1.2039 +	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2040 + 	gc->SetBrushColor(KRgbDarkCyan);
  1.2041 +	gc->DrawEllipse(TRect(TPoint(200,150),TSize(50,50)));	//map to the contained drawer
  1.2042 +    TInt bitmapHeight = bitmapRef->SizeInPixels().iHeight;
  1.2043 +	TInt bitmapWidth = bitmapRef->SizeInPixels().iWidth;
  1.2044 +  
  1.2045 +   	// Copy the screen content to bitmap
  1.2046 +	INFO_PRINTF1(_L("Capture screen content."));
  1.2047 +	CFbsBitmap* screenBitmap = new(ELeave) CFbsBitmap();
  1.2048 +	CleanupStack::PushL(screenBitmap);
  1.2049 +	User::LeaveIfError(screenBitmap->Create(size, TheClient->iScreen->DisplayMode()));
  1.2050 +	TRect rct = TRect(TPoint(0,0), size);
  1.2051 +	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(screenBitmap,rct));
  1.2052 +
  1.2053 +	// Compare the displayed bitmap against the reference one
  1.2054 +	INFO_PRINTF1(_L("Compare the displayed bitmap against the expected one."));
  1.2055 +	TInt lineLength=bitmapRef->ScanLineLength(bitmapWidth, EColor256);
  1.2056 +	HBufC8* compareLineBuf=HBufC8::NewLC(lineLength);
  1.2057 +	TPtr8 compareLinePtr(compareLineBuf->Des());
  1.2058 +	HBufC8* screenLineBuf=HBufC8::NewLC(lineLength);
  1.2059 +	TPtr8 screenLinePtr(screenLineBuf->Des());
  1.2060 +	for (TInt index=0; index<bitmapHeight; index++)
  1.2061 +		{
  1.2062 +		bitmapRef->GetScanLine(compareLinePtr, TPoint(0,index), bitmapWidth, EColor256);
  1.2063 +		screenBitmap->GetScanLine(screenLinePtr, TPoint(0,index),bitmapWidth, EColor256);
  1.2064 +		TInt compareResult=compareLinePtr.Compare(screenLinePtr);
  1.2065 +		if (compareResult!=0)
  1.2066 +			{
  1.2067 +			INFO_PRINTF2(_L("Scanline compare failed: %d"),index);
  1.2068 +			TEST(EFalse);
  1.2069 +			break;
  1.2070 +			}
  1.2071 +		}
  1.2072 +	CleanupStack::PopAndDestroy(6,bitmapRef);  
  1.2073 +
  1.2074 +	} 
  1.2075 +
  1.2076 +void ResetScreenMode(TAny* aAny)
  1.2077 +	{
  1.2078 +	CWsScreenDevice* screen=static_cast<CWsScreenDevice*>(aAny);
  1.2079 +	screen->SetScreenMode(0);
  1.2080 +	screen->SetAppScreenMode(0);
  1.2081 +	}
  1.2082 +
  1.2083 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
  1.2084 +
  1.2085 +void CTWsGraphs::TestScreenModeChangeL()
  1.2086 +	{
  1.2087 +	_LIT(KLog,"Screen Doesn't match bitmap.  Size=(%d,%d) winSizeMode=%d redrawMode=%d modeIndex=%d");
  1.2088 +// A simple CRP graphic to draw in the test
  1.2089 +	CWsSimpleGraphicBitmap* wsGraphic1=CWsSimpleGraphicBitmap::NewL(KSimpleDrawerInterfaceId);
  1.2090 +	CleanupStack::PushL(wsGraphic1);
  1.2091 +	RWindow testWin(TheClient->iWs);
  1.2092 +	CleanupClosePushL(testWin);
  1.2093 +	User::LeaveIfError(testWin.Construct(*TheClient->iGroup->GroupWin(),0xbadbad));
  1.2094 +	testWin.SetRequiredDisplayMode(EColor64K);
  1.2095 +	testWin.Activate();
  1.2096 +// Cleanup display mode by setting back to 0 if we leave in the tests
  1.2097 +	CleanupStack::PushL(TCleanupItem(ResetScreenMode,TheClient->iScreen));
  1.2098 +	TInt numScreenModes=TheClient->iScreenModes.Count();
  1.2099 +	TBool match;
  1.2100 +
  1.2101 +	for(TInt winSizeMode=0;winSizeMode<2;winSizeMode++)
  1.2102 +		{ // Two size modes, fullScreen and non-full screen
  1.2103 +		for(TInt redrawMode=0;redrawMode<2;redrawMode++)
  1.2104 +			{ // Two redraw modes to test drawing inside and outside of a redraw.
  1.2105 +			const TBool drawInsideRedraw=(redrawMode==0);
  1.2106 +			for(TInt modeIndex=0;modeIndex<numScreenModes;modeIndex++)
  1.2107 +				{
  1.2108 +				const TInt screenMode=TheClient->iScreenModes[modeIndex];
  1.2109 +				const TPoint origin=TheClient->iScreen->GetScreenModeScaledOrigin(screenMode);
  1.2110 +				if (origin.iX!=0 || origin.iY!=0)
  1.2111 +					continue;
  1.2112 +				// Enable redirection before changing screen mode as this is what we are testing
  1.2113 +				iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
  1.2114 +				TheClient->iScreen->SetAppScreenMode(screenMode);
  1.2115 +				TheClient->iScreen->SetScreenMode(screenMode);
  1.2116 +
  1.2117 +				TPixelsAndRotation sizeAndRotation;
  1.2118 +				TheClient->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
  1.2119 +//
  1.2120 +				TSize screenSize(TheClient->iScreen->SizeInPixels());
  1.2121 +				if(sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationRotated90 || 
  1.2122 +						sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationRotated270)
  1.2123 +					{
  1.2124 +					screenSize.iWidth = Min(screenSize.iWidth, 240);//to make sure we won't exceed physical screen size
  1.2125 +					}
  1.2126 +				TSize winSize(screenSize);
  1.2127 +				TPoint winPos;
  1.2128 +				if (winSizeMode==1)
  1.2129 +					{
  1.2130 +					winSize.iWidth=winSize.iWidth*2/3;
  1.2131 +					winSize.iHeight=winSize.iHeight*3/4;
  1.2132 +					winPos.iX=(screenSize.iWidth-winSize.iWidth)/4;
  1.2133 +					winPos.iY=(screenSize.iHeight-winSize.iHeight)*3/4;
  1.2134 +					}
  1.2135 +				testWin.SetExtent(winPos,winSize);
  1.2136 +				TSize halfSize(winSize.iWidth/2,winSize.iHeight);
  1.2137 +				TRect leftHalf(halfSize);
  1.2138 +				TRect rightHalf(TPoint(halfSize.iWidth,0),halfSize);
  1.2139 +				TRect leftEllipse(leftHalf);
  1.2140 +				leftEllipse.Shrink(4,4);
  1.2141 +				TRect rightEllipse(rightHalf);
  1.2142 +				rightEllipse.Shrink(4,4);
  1.2143 +				// Draw half the screen with redirection on, should only go to redirection test bitmap
  1.2144 +				// Then draw again with redirection off, this time should go to the screen
  1.2145 +				// The two steps are drawn with the color of the left/right rectangles swapped.
  1.2146 +				for(TInt drawStep=0;drawStep<2;drawStep++)
  1.2147 +					{
  1.2148 +					TRgb leftColor;
  1.2149 +					TRgb rightColor;
  1.2150 +					if (drawStep==0)
  1.2151 +						{
  1.2152 +						leftColor=KRgbGreen;
  1.2153 +						rightColor=KRgbRed;
  1.2154 +						}
  1.2155 +					else
  1.2156 +						{ // Turn re-direction off for second time around loop
  1.2157 +						iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
  1.2158 +						leftColor=KRgbRed;
  1.2159 +						rightColor=KRgbGreen;
  1.2160 +						}
  1.2161 +					testWin.Invalidate();
  1.2162 +					testWin.BeginRedraw();
  1.2163 +					if (!drawInsideRedraw)
  1.2164 +						testWin.EndRedraw();
  1.2165 +					CWindowGc* testWinGc=TheClient->iGc;
  1.2166 +					testWinGc->Activate(testWin);
  1.2167 +					testWinGc->SetBrushColor(leftColor);
  1.2168 +					testWinGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1.2169 +					testWinGc->DrawRect(leftHalf);
  1.2170 +					// Call CRP drawer to draw the coloured ellipses
  1.2171 +					TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),leftEllipse);
  1.2172 +					testWinGc->SetBrushColor(rightColor);
  1.2173 +					testWinGc->DrawRect(rightHalf);
  1.2174 +					TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),rightEllipse);
  1.2175 +					testWinGc->Deactivate();
  1.2176 +					if (drawInsideRedraw)
  1.2177 +						testWin.EndRedraw();
  1.2178 +					TheClient->iWs.Flush();
  1.2179 +					}
  1.2180 +				// We now check that the left rect of the re-directed drawing matches the right half
  1.2181 +				// of the on-screen drawing
  1.2182 +				CFbsBitmap* screenCopy=new(ELeave) CFbsBitmap;
  1.2183 +				CleanupStack::PushL(screenCopy);
  1.2184 +				User::LeaveIfError(screenCopy->Create(screenSize, EColor64K));
  1.2185 +				TheClient->iScreen->CopyScreenToBitmap(screenCopy);
  1.2186 +				match=CompareBitmapArea16Bpp(iFrontCopy,winPos,screenCopy,TPoint(winPos.iX+rightHalf.iTl.iX,winPos.iY),halfSize);
  1.2187 +				TEST(match);
  1.2188 +				if (!match)
  1.2189 +					LOG_MESSAGE6(KLog,screenSize.iWidth,screenSize.iHeight,winSizeMode,redrawMode,modeIndex);
  1.2190 +				// As a double check also check the right half of the off-screen drawing matches the
  1.2191 +				// on-screen left half.
  1.2192 +				match=CompareBitmapArea16Bpp(iFrontCopy,TPoint(winPos.iX+rightHalf.iTl.iX,winPos.iY),screenCopy,winPos,halfSize);
  1.2193 +				TEST(match);
  1.2194 +				if (!match)
  1.2195 +					LOG_MESSAGE6(KLog,screenSize.iWidth,screenSize.iHeight,winSizeMode,redrawMode,modeIndex);
  1.2196 +				CleanupStack::PopAndDestroy(screenCopy);
  1.2197 +				}
  1.2198 +			}
  1.2199 +		}
  1.2200 + 	CleanupStack::PopAndDestroy(3,wsGraphic1);
  1.2201 + 	
  1.2202 +	TEST(iNotify1->iResult);
  1.2203 +	if(iNotify1->iResult==EFalse)
  1.2204 +		{
  1.2205 +		INFO_PRINTF1(iNotify1->iError);
  1.2206 +		}
  1.2207 +	TEST(iNotify2->iResult);
  1.2208 +	if(iNotify1->iResult==EFalse)
  1.2209 +		{
  1.2210 +		INFO_PRINTF1(iNotify2->iError);
  1.2211 +		}
  1.2212 +	}
  1.2213 +
  1.2214 +#endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
  1.2215 +
  1.2216 +/**
  1.2217 +@SYMTestCaseID 		GRAPHICS-WSERV-0443
  1.2218 +
  1.2219 +@SYMDEF     		INC109263
  1.2220 +
  1.2221 +@SYMTestCaseDesc	TWindowServerEvent::NotifyDrawer can refer to a deleted array index causing a crash
  1.2222 +
  1.2223 +@SYMTestPriority 	High
  1.2224 +
  1.2225 +@SYMTestStatus		Implemented
  1.2226 +
  1.2227 +@SYMTestActions		Cause an event that will generate the following behaviour through TWindowServerEvent::NotifyDrawer()
  1.2228 +		
  1.2229 +					The for loop performs the following:
  1.2230 +					0) Drawer handler 1: Remove handle 1 ; 					Drawer handler 2: Do nothing
  1.2231 +					1) Drawer handler 1: Remove handle 1,Add handle 1 ;		Drawer handler 2: Do nothing
  1.2232 +					2) Drawer handler 1: Add handle 1 ; 					Drawer handler 2: Do nothing
  1.2233 +					3) Drawer handler 1: Remove handle 2 ; 					Drawer handler 2: Do nothing
  1.2234 +					4) Drawer handler 1: Remove handle 2,Add handle 2 ; 	Drawer handler 2: Do nothing
  1.2235 +					5) Drawer handler 1: Add handle 2 ; 					Drawer handler 2: Do nothing
  1.2236 +					6) Drawer handler 1: Remove handle 1,Remove handle 2 ; 	Drawer handler 2: Do nothing
  1.2237 +			
  1.2238 +					Repeat with handlers 1 and 2 swapped
  1.2239 +
  1.2240 +@SYMTestExpectedResults		Loops through TWindowServerEvent::NotifyDrawer() should complete without crashing wserv
  1.2241 +*/
  1.2242 +
  1.2243 +void CTWsGraphs::TestNotifyRemoval()
  1.2244 +	{
  1.2245 +	_LIT(KTestEventNotification, "TestDrawerEventHandler");
  1.2246 +	INFO_PRINTF1(KTestEventNotification);
  1.2247 +	++iSubState;
  1.2248 +
  1.2249 +	for (TInt ii = 0; ii<KNotifyDoNothing; ii++)
  1.2250 +		{
  1.2251 +		INFO_PRINTF2(_L("For loop %d"), ii);
  1.2252 +		iNotify1->SetBehaviour(ii);					//Enable this plugin and set it to an event handling method
  1.2253 +		iNotify2->SetBehaviour(KNotifyDoNothing);	//Add a second drawer handler which is enabled but does nothing
  1.2254 +		CreateWindowL();							//Change visibility activating the event handlers - Fails if wserv crashes!
  1.2255 +		iNotify1->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
  1.2256 +		iNotify2->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
  1.2257 +		DestroyWindowL();
  1.2258 +		}
  1.2259 +	INFO_PRINTF1(_L("Swap handlers"));
  1.2260 +	for (TInt ii = 0; ii<KNotifyDoNothing; ii++)
  1.2261 +		{
  1.2262 +		INFO_PRINTF2(_L("For loop %d"), ii);
  1.2263 +		iNotify2->SetBehaviour(KNotifyDoNothing);	//Add a first drawer handler which is enabled but does nothing
  1.2264 +		iNotify1->SetBehaviour(ii);					//Enable this plugin and set it to an event handling method
  1.2265 +		CreateWindowL();							//Change visibility activating the event handlers - Fails if wserv crashes!
  1.2266 +		iNotify2->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
  1.2267 +		iNotify1->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
  1.2268 +		DestroyWindowL();
  1.2269 +		}
  1.2270 +
  1.2271 +	TEST(ETrue);		// If the test has failed WServ will have paniced.
  1.2272 +	}
  1.2273 +
  1.2274 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
  1.2275 +/**
  1.2276 +@SYMTestCaseID           GRAPHICS-WSERV-0491
  1.2277 +@SYMPREQ                 PREQ39
  1.2278 +@SYMTestPriority         High
  1.2279 +@SYMTestCaseDesc         Draw using a ECom-plugin which has direct access to the screen/OSB buffer 
  1.2280 +@SYMTestActions          Create the plugin
  1.2281 +						 Draw using the plugin
  1.2282 +						 Update the position of the white line to line 70 and test
  1.2283 +						 Update the position of the white line to line 80 and test
  1.2284 +@SYMTestExpectedResults  White lines are drawn on the correct positions.
  1.2285 +*/
  1.2286 +void CTWsGraphs::TestMWsUiBufferL()
  1.2287 +	{
  1.2288 +	const TInt KWhiteLinePos = 70;
  1.2289 +	const TRect KBlueRect(TPoint(50,50),TSize(100,100));
  1.2290 +		
  1.2291 +	// Construct and setup window to be drawn to
  1.2292 +	RWindow window1 = RWindow(TheClient->iWs);
  1.2293 +	CleanupClosePushL(window1);
  1.2294 +    User::LeaveIfError(window1.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle));
  1.2295 +    TSize winSize=TSize(TheClient->iScreen->SizeInPixels());
  1.2296 +    window1.SetExtent(TPoint(0,0),winSize);
  1.2297 +    window1.Activate();
  1.2298 +    
  1.2299 +	CWsBufferGraphic* graphic = CWsBufferGraphic::NewL();
  1.2300 +	CleanupStack::PushL(graphic);
  1.2301 +    
  1.2302 +	// Draw inital drawing with a Crp which is blue rect and a white line at line 0
  1.2303 +	TheGc->Activate(window1);
  1.2304 +	TheGc->Clear();
  1.2305 +	window1.BeginRedraw();
  1.2306 +	TheGc->DrawWsGraphic(graphic->Id(),KBlueRect);
  1.2307 +	window1.EndRedraw();
  1.2308 +	TheGc->Deactivate();
  1.2309 +	
  1.2310 +    TheClient->iWs.Finish();
  1.2311 +    User::After(2000000);
  1.2312 +	
  1.2313 +	// Update the position of the white line to line 70
  1.2314 +	INFO_PRINTF1(_L("Update position of white line to line 70"));
  1.2315 +	graphic->UpdateWhiteLinePos(KWhiteLinePos);
  1.2316 +	TheClient->iWs.Finish();
  1.2317 +	// Force some delays to wait until the line position changes
  1.2318 +    User::After(2000000);
  1.2319 +    //Test white line has been drawn and is in the correct postion
  1.2320 +    TBool res1 = IsWhiteLine(KWhiteLinePos);
  1.2321 +    TEST(res1);
  1.2322 +    
  1.2323 +	// Update the position of the white line to line 80
  1.2324 +    INFO_PRINTF1(_L("Update position of white line to line 80"));
  1.2325 +	graphic->UpdateWhiteLinePos(KWhiteLinePos+10);
  1.2326 +	TheClient->iWs.Finish();
  1.2327 +	// Force some delays to wait until the line position changes
  1.2328 +	User::After(2000000);
  1.2329 +	// Test white line has been drawn and is in the correct postion
  1.2330 +    TBool res2 = IsWhiteLine(KWhiteLinePos+10);
  1.2331 +    TEST(res2);
  1.2332 +   
  1.2333 +	graphic->Destroy();
  1.2334 +	CleanupStack::PopAndDestroy(2, &window1);
  1.2335 +	}
  1.2336 +
  1.2337 +// Test whether a line is completely white
  1.2338 +TBool CTWsGraphs::IsWhiteLine(TInt aWhiteLinePos)
  1.2339 +	{
  1.2340 +    TRgb color;
  1.2341 +    TPoint pixel;
  1.2342 +    
  1.2343 +    for(TInt xPos = 0; xPos < TheClient->iScreen->SizeInPixels().iWidth; xPos++)
  1.2344 +    	{
  1.2345 +    	pixel = TPoint(xPos,aWhiteLinePos);
  1.2346 +    	TheClient->iScreen->GetPixel(color,pixel);
  1.2347 +    	if(color.Red() != 255 && color.Blue() != 255 && color.Green() != 255)
  1.2348 +    		{
  1.2349 +    		return EFalse;
  1.2350 +    		}
  1.2351 +    	}
  1.2352 +    return ETrue;
  1.2353 +	}
  1.2354 +#endif //TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
  1.2355 +
  1.2356 +/**
  1.2357 +	DoTestL() method, called by the WSERV Test Framework.
  1.2358 +*/
  1.2359 +void CTWsGraphs::RunTestCaseL(TInt /*aCurTestCase*/)
  1.2360 +	{
  1.2361 +	_LIT(KTest1,"DoTestWsGraphics");
  1.2362 +	_LIT(KTest2,"DoTestOOMWsGraphics");
  1.2363 +	_LIT(KTest3,"Interface Extension");
  1.2364 +	_LIT(KTest4,"Screen Redirection");
  1.2365 +	_LIT(KTest5,"TextCursor1");
  1.2366 +	_LIT(KTest6,"TextCursor2");
  1.2367 +	_LIT(KTest7,"Flicker Redirection");
  1.2368 +	_LIT(KTest8,"Event Notification");
  1.2369 +	_LIT(KTest9,"Successive Message");
  1.2370 +	_LIT(KTest10,"Redirection Using WsBackBuffer");
  1.2371 +	_LIT(KTest11,"Group Change");
  1.2372 +	_LIT(KTest12,"Frame Rate");
  1.2373 +	_LIT(KTest13,"Leak In Service");
  1.2374 +	_LIT(KTest14,"Add/Swap GDArray");
  1.2375 +	_LIT(KTest15,"Nested Drawer CRP");
  1.2376 +	_LIT(KTest16,"Notify Removal");
  1.2377 +	_LIT(KTest17,"Screen Mode Change");
  1.2378 +	_LIT(KTest18,"UI Buffer");
  1.2379 +	_LIT(KTest19,"Graphics Drawer Coverage");
  1.2380 +	CFbsBitmap bitmap1;
  1.2381 +	CFbsBitmap mask1;
  1.2382 +	CWsGraphicBitmap* bTest=NULL;
  1.2383 +	TSize screenSize=TheClient->iScreen->SizeInPixels();
  1.2384 +
  1.2385 +	bitmap1.Create(screenSize,TheClient->iScreen->DisplayMode());
  1.2386 +	mask1.Create(screenSize,TheClient->iScreen->DisplayMode());
  1.2387 +	((CTWsGraphsStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
  1.2388 +
  1.2389 +	switch(++iTest->iState)
  1.2390 +		{
  1.2391 +	case 1:
  1.2392 +/**
  1.2393 +	@SYMTestCaseID	GRAPHICS-WSERV-0528
  1.2394 +*/
  1.2395 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0528"));
  1.2396 +		// Launch new process with PROTSERV capability to run CWSGraphics tests in
  1.2397 +		iTest->LogSubTest(KTest1);
  1.2398 +		// This process only launches succesfully when _DEBUG is defined for the build, because it depends
  1.2399 +		// on the existance of debug macros such as _UHEAP_MARK, _UHEAP_MARKEND, _UHEAP_FAILNEXT, ... etc
  1.2400 +		LaunchNewProcess(KTestExe);
  1.2401 +		break;
  1.2402 +	case 2:
  1.2403 +		{
  1.2404 +		/**
  1.2405 +   		@SYMTestCaseID GRAPHICS-WSERV-0017
  1.2406 +
  1.2407 +		@SYMPREQ	PREQ1246
  1.2408 +
  1.2409 +		@SYMDEF		DEF081259
  1.2410 +
  1.2411 +		@SYMTestCaseDesc Out of memery test when creating a CWsGraphic.
  1.2412 +
  1.2413 +		@SYMTestPriority High
  1.2414 +
  1.2415 +		@SYMTestStatus Implemented
  1.2416 +
  1.2417 +		@SYMTestActions Out of memory test when creating a CWsGraphic.
  1.2418 +
  1.2419 +		@SYMTestExpectedResults Whenever an API call fails, it should leave the number
  1.2420 +				of allocated heap cells unchanged.
  1.2421 +		*/
  1.2422 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0017"));
  1.2423 +
  1.2424 +		iTest->LogSubTest(KTest2);
  1.2425 +		TInt failRate;
  1.2426 +		for(failRate=1;;failRate++)
  1.2427 +			{
  1.2428 +			__UHEAP_RESET;
  1.2429 +			__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
  1.2430 +			__UHEAP_MARK;
  1.2431 +
  1.2432 +			TRAPD(ret,bTest=CWsGraphicBitmap::NewL(&bitmap1,&mask1));
  1.2433 +			TEST((ret==KErrNone || ret==KErrNoMemory));
  1.2434 +			if (ret!=KErrNone && ret!=KErrNoMemory)
  1.2435 +				{
  1.2436 +				_LIT(KLog,"Failed to create CWsGraphicBitmap  error=%d");
  1.2437 +				LOG_MESSAGE2(KLog,ret);
  1.2438 +				}
  1.2439 +			if (ret!=KErrNone)
  1.2440 +				{
  1.2441 +				__UHEAP_MARKEND;
  1.2442 +				}
  1.2443 +			else
  1.2444 +				{
  1.2445 +				TEST(bTest!=NULL);
  1.2446 +				if (bTest==NULL)
  1.2447 +					{
  1.2448 +					_LIT(KLog,"Object creation didn't leave but returned NULL");
  1.2449 +					LOG_MESSAGE(KLog);
  1.2450 +					}
  1.2451 +				delete bTest;
  1.2452 +				bTest=NULL;
  1.2453 +				__UHEAP_MARKEND;
  1.2454 +				TLogMessageText logMessageText;
  1.2455 +				_LIT(KSet,"OOM test succeds after %d allocations.");
  1.2456 +				logMessageText.Format(KSet,failRate);
  1.2457 +				LOG_MESSAGE(logMessageText);
  1.2458 +				break;
  1.2459 +				}
  1.2460 +			}
  1.2461 +		__UHEAP_RESET;
  1.2462 +		}
  1.2463 +		break;
  1.2464 +	case 3:
  1.2465 +		iTest->LogSubTest(KTest3);
  1.2466 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0371"));
  1.2467 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
  1.2468 +			
  1.2469 +			if (TestInterfaceExtensionL()==EWait)
  1.2470 +				--iTest->iState;
  1.2471 +#endif
  1.2472 +		break;
  1.2473 +	case 4:
  1.2474 +		iTest->LogSubTest(KTest4);
  1.2475 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0372"));
  1.2476 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA			
  1.2477 +			if (TestScreenRedirectionL()==EWait)
  1.2478 +				--iTest->iState;
  1.2479 +#endif
  1.2480 +		break;
  1.2481 +	case 5:
  1.2482 +		iTest->LogSubTest(KTest5);
  1.2483 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0363"));
  1.2484 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA	
  1.2485 +			if (TestTextCursorUnderRedirectionL(ETestStandardTextCursor) == EWait)
  1.2486 +				--iTest->iState;
  1.2487 +#endif
  1.2488 +		break;
  1.2489 +	case 6:
  1.2490 +		iTest->LogSubTest(KTest6);
  1.2491 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0363"));
  1.2492 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA	
  1.2493 +			if (TestTextCursorUnderRedirectionL(ETestCustomTextCursor) == EWait)
  1.2494 +				--iTest->iState;
  1.2495 +#endif
  1.2496 +		break;
  1.2497 +	case 7:
  1.2498 +		iTest->LogSubTest(KTest7);
  1.2499 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0376"));
  1.2500 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA			
  1.2501 +			if (TestFlickerRedirectionL()==EWait)
  1.2502 +				--iTest->iState;
  1.2503 +#endif
  1.2504 +		break;
  1.2505 +	case 8:
  1.2506 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0378"));
  1.2507 +		iTest->LogSubTest(KTest8);
  1.2508 +		if (TestEventNotificationL()==EWait)
  1.2509 +			--iTest->iState;
  1.2510 +		break;
  1.2511 +	case 9:
  1.2512 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0381"));
  1.2513 +		iTest->LogSubTest(KTest9);
  1.2514 +		if (TestSuccessiveMessageL()==EWait)
  1.2515 +			--iTest->iState;
  1.2516 +		break;
  1.2517 +	case 10:
  1.2518 +		iTest->LogSubTest(KTest10);
  1.2519 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0527"));
  1.2520 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
  1.2521 +		if(TestRedirectionUsingWsBackBufferL()==EWait)
  1.2522 +			--iTest->iState;
  1.2523 +#endif
  1.2524 +		break;
  1.2525 +	case 11:
  1.2526 +/**
  1.2527 +	@SYMTestCaseID	GRAPHICS-WSERV-0529
  1.2528 +*/
  1.2529 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0529"));
  1.2530 +		iTest->LogSubTest(KTest11);
  1.2531 +		if(TestWindowGroupChangeL()==EWait)
  1.2532 +			--iTest->iState;
  1.2533 +		break;
  1.2534 +	case 12:
  1.2535 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0382"));
  1.2536 +		iTest->LogSubTest(KTest12);
  1.2537 +		if(TestFrameRateL()==EWait)
  1.2538 +			--iTest->iState;
  1.2539 +		break;
  1.2540 +	case 13:
  1.2541 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-LeakInService-0001"));
  1.2542 +		iTest->LogSubTest(KTest13);
  1.2543 +		DoTestLeakInServiceL();
  1.2544 +		break;
  1.2545 +	case 14:
  1.2546 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-NegAddSwapGDArray-0001"));
  1.2547 +		iTest->LogSubTest(KTest14);
  1.2548 +		TestAddSwapGDArrayL();
  1.2549 +		break;
  1.2550 +	case 15:
  1.2551 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0438"));
  1.2552 +		iTest->LogSubTest(KTest15);
  1.2553 +		TestNestedDrawerCRP();
  1.2554 +		break;
  1.2555 +	case 16:
  1.2556 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0443"));
  1.2557 +		iTest->LogSubTest(KTest16);
  1.2558 +		TestNotifyRemoval();
  1.2559 +		break;
  1.2560 +	case 17:
  1.2561 +		iTest->LogSubTest(KTest17);
  1.2562 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0530"));
  1.2563 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
  1.2564 +/**
  1.2565 +	@SYMTestCaseID	GRAPHICS-WSERV-0530
  1.2566 +*/
  1.2567 +			
  1.2568 +			TestScreenModeChangeL();
  1.2569 +#endif
  1.2570 +		break;
  1.2571 +	case 18:
  1.2572 +		iTest->LogSubTest(KTest18);
  1.2573 +		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0491"));
  1.2574 +#ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
  1.2575 +			
  1.2576 +			TestMWsUiBufferL();
  1.2577 +#endif
  1.2578 +			break;
  1.2579 +		case 19:
  1.2580 +			iTest->LogSubTest(KTest19);
  1.2581 +/**
  1.2582 +	@SYMTestCaseID	GRAPHICS-WSERV-0531
  1.2583 +*/
  1.2584 +			((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0531"));
  1.2585 +			TestGraphicDrawerCoverage();
  1.2586 +			break;
  1.2587 +		default:
  1.2588 +			((CTWsGraphsStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
  1.2589 +			((CTWsGraphsStep*)iStep)->CloseTMSGraphicsStep();
  1.2590 +			TestComplete();
  1.2591 +			break;
  1.2592 +		}
  1.2593 +	((CTWsGraphsStep*)iStep)->RecordTestResultL();
  1.2594 +	}
  1.2595 +
  1.2596 +__WS_CONSTRUCT_STEP__(WsGraphs)