windowing/windowserver/tauto/TWSGRAPHS.CPP
changeset 110 7f25ef56562d
parent 98 bf7481649c98
child 111 29ddb8a72f0e
equal deleted inserted replaced
98:bf7481649c98 110:7f25ef56562d
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // This test step contains a series of tests cases to validate the correct behaviour of PREQ1246 implementation.
       
    15 // In order to create these test cases, basic implementations of the objects involved in this PREQ will be created,
       
    16 // .i.e. CWsGraphic-derived objects (generically named CWsGraphicTest) and CWsGraphicDrawer-derived objects
       
    17 // (generically named CWsGraphicDrawerTest).
       
    18 // Actual construction is performed by a UI-specific entity such as a theme manager. The test code shall replace
       
    19 // that theme manager functionality, in terms of being the test code who owns a collection of CWsGraphicTest
       
    20 // objects.
       
    21 // 
       
    22 //
       
    23 
       
    24 /**
       
    25  @file
       
    26  @test
       
    27  @internalComponent - Internal Symbian test code
       
    28 */
       
    29 
       
    30 #include "TWSGRAPHS.H"
       
    31 #include "../inc/WSGRAPHICDRAWERARRAY.H"
       
    32 #include "../../nga/graphicdrawer/panics.h"
       
    33 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
       
    34 #include "wsbufferdrawer.h"
       
    35 #endif
       
    36 
       
    37 _LIT(KTestExe, "TWSGRAPHICTEST.exe");
       
    38 _LIT(KSpace, " ");
       
    39 
       
    40 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
    41 const TInt KCustomTextCursorId = TTextCursor::ETypeLastBasic + 57; // 57 is arbitrary
       
    42 #endif
       
    43 
       
    44 CCrWin* CCrWin::NewL(TInt aScreenId, TBool aDraw)
       
    45 	{
       
    46 	CCrWin* win = new(ELeave) CCrWin;
       
    47 	CleanupStack::PushL(win);
       
    48 	win->ConstructL(aScreenId, aDraw);
       
    49 	CleanupStack::Pop(win);
       
    50 	return win;
       
    51 	}
       
    52 
       
    53 CCrWin::~CCrWin()
       
    54 	{
       
    55 	iWin.Close();
       
    56 	iGroup.Close();
       
    57 	delete iGc;
       
    58 	delete iScr;
       
    59 	iWs.Close();
       
    60 	}
       
    61 
       
    62 void CCrWin::ConstructL(TInt aScreenId, TBool aDraw)
       
    63 	{
       
    64 	User::LeaveIfError(iWs.Connect());
       
    65 	iScr = new(ELeave) CWsScreenDevice(iWs);
       
    66 	User::LeaveIfError(iScr->Construct(aScreenId));
       
    67 	User::LeaveIfError(iScr->CreateContext(iGc));
       
    68 	iGroup = RWindowGroup(iWs);
       
    69 	User::LeaveIfError(iGroup.Construct(0xbadbabe,ETrue));
       
    70 	iGroup.SetOrdinalPosition(0,100);
       
    71 	iWin = RWindow(iWs);
       
    72 	User::LeaveIfError(iWin.Construct(iGroup,0xbadcafe));
       
    73 	iWin.SetRequiredDisplayMode(EColor64K);
       
    74 	iWin.Activate();
       
    75 	iWs.Flush();
       
    76 	if (aDraw)
       
    77 	Draw();
       
    78 	}
       
    79 
       
    80 void CCrWin::Draw()
       
    81 	{
       
    82 	iWin.BeginRedraw();
       
    83 	iGc->Activate(iWin);
       
    84 	iGc->SetBrushColor(KRgbRed);
       
    85 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
    86 	TRect rect(iScr->SizeInPixels());
       
    87 	iGc->DrawRect(rect);
       
    88 	iGc->SetBrushColor(KRgbBlue);
       
    89 	iGc->DrawEllipse(TRect(rect.iTl.iX,rect.iTl.iY,rect.iBr.iX/2,rect.iBr.iY));
       
    90 	iGc->DrawEllipse(TRect(rect.iBr.iX/2,rect.iTl.iY,rect.iBr.iX,rect.iBr.iY));
       
    91 	iGc->Deactivate();
       
    92 	iWin.EndRedraw();
       
    93 	iWs.Flush();
       
    94 	}
       
    95 
       
    96 
       
    97 void CCrWin::DrawFirstHalf()
       
    98 	{
       
    99 	iWin.BeginRedraw();
       
   100 	iGc->Activate(iWin);
       
   101 	iGc->SetBrushColor(KRgbRed);
       
   102 	iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   103 	TRect rect(TPoint(0,0),TSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight));
       
   104 	iGc->DrawRect(rect);
       
   105 	iWs.Flush();	
       
   106 	}
       
   107 
       
   108 void CCrWin::DrawSecondHalf()
       
   109 	{
       
   110 	TRect rect(TPoint(iScr->SizeInPixels().iWidth/2,0),TSize(iScr->SizeInPixels().iWidth/2,iScr->SizeInPixels().iHeight));
       
   111 	iGc->DrawRect(rect);
       
   112 	iGc->Deactivate();
       
   113 	iWin.EndRedraw();	
       
   114 	iWs.Flush();		
       
   115 	}
       
   116 
       
   117 /** 
       
   118 The objective of this function is, two animations should run independently
       
   119 with respective frame rate in the given time interval.
       
   120 The time delay allows to draw animations freely and the plug-in
       
   121 calculates number of times DoDraw() function called during this interval.
       
   122 
       
   123 @param TInt Wsgrphic test plug-in id.
       
   124 */
       
   125 void CCrWin::DrawGraphic(TInt aWsId)
       
   126 	{
       
   127 	// draw the animation in two positions
       
   128 	const TSize screenSize = iScr->SizeInPixels();	
       
   129 	const TRect position(0,0,screenSize.iWidth/2,screenSize.iHeight);
       
   130 	const TRect position2((screenSize.iWidth/2)+1,0,screenSize.iWidth,screenSize.iHeight);
       
   131 	//PeterI if CWsGraphic animation areas overlap then when one redraws the other will as well.
       
   132 	//2 separate positions are needed otherwise the framerates will be identical.
       
   133 	
       
   134 	iWin.BeginRedraw();
       
   135 	iGc->Activate(iWin);
       
   136 	const TUint8 animid1=0;
       
   137 	const TUint8 fps1=20;
       
   138 	TBuf8<2> animData1;
       
   139 	animData1.Append(animid1);   //animId1
       
   140 	animData1.Append(fps1); //20fps
       
   141 	iGc->DrawWsGraphic(aWsId,position,animData1);
       
   142 	iWs.Flush();
       
   143 	User::After(200000);
       
   144 	const TUint8 animid2=1;
       
   145 	const TUint8 fps2=60;
       
   146 	TBuf8<2> animData2;
       
   147 	animData2.Append(animid2);   //animId2
       
   148 	animData2.Append(fps2); //60fps
       
   149 	iGc->DrawWsGraphic(aWsId,position2,animData2);
       
   150 	iWs.Flush();
       
   151 	User::After(200000);
       
   152 	iGc->Deactivate();
       
   153 	iWin.EndRedraw();
       
   154 	iWs.Flush();
       
   155 	}
       
   156 
       
   157 /**
       
   158  * Set a standard text cursor on this window.
       
   159  * @see RWindowGroup::SetTextCursor()
       
   160  */
       
   161 void CCrWin::SetTextCursor(const TPoint &aPos, const TTextCursor &aCursor)
       
   162 	{
       
   163 	iGroup.SetTextCursor(iWin, aPos, aCursor);
       
   164 	}
       
   165 
       
   166 /**
       
   167  * Cancel a text cursor from this window.
       
   168  * @see RWindowGroup::CancelTextCursor()
       
   169  */
       
   170 void CCrWin::CancelTextCursor()
       
   171 	{
       
   172 	iGroup.CancelTextCursor();
       
   173 	}
       
   174 
       
   175 CCrAlphaWin* CCrAlphaWin::NewL(TInt aScreenId)
       
   176 	{
       
   177 	CCrAlphaWin* win = new(ELeave) CCrAlphaWin;
       
   178 	CleanupStack::PushL(win);
       
   179 	win->ConstructL(aScreenId);
       
   180 	CleanupStack::Pop(win);
       
   181 	return win;
       
   182 	}
       
   183 
       
   184 CCrAlphaWin::~CCrAlphaWin()
       
   185 	{
       
   186 	iWin.Close();
       
   187 	iGroup.Close();
       
   188 	delete iScr;
       
   189 	iWs.Close();
       
   190 	}
       
   191 
       
   192 void CCrAlphaWin::ConstructL(TInt aScreenId)
       
   193 	{
       
   194 	User::LeaveIfError(iWs.Connect());
       
   195 	iScr = new(ELeave) CWsScreenDevice(iWs);
       
   196 	User::LeaveIfError(iScr->Construct(aScreenId));
       
   197 	iGroup = RWindowGroup(iWs);
       
   198 	User::LeaveIfError(iGroup.Construct(0xbadc0de,ETrue));
       
   199 	iGroup.SetOrdinalPosition(0,100);
       
   200 	iWin = RWindow(iWs);
       
   201 	User::LeaveIfError(iWin.Construct(iGroup,0xbadbeef));
       
   202 	iWin.SetRequiredDisplayMode(EColor64K);
       
   203 	iWin.SetTransparencyAlphaChannel();
       
   204 	iWin.SetBackgroundColor(TRgb(0xff,0xff,0,0x80));
       
   205 	iWin.Activate();
       
   206 	iWs.Flush();
       
   207 	}
       
   208 
       
   209 
       
   210 //
       
   211 //  CTWsGraphs
       
   212 //
       
   213 
       
   214 CTWsGraphs::CTWsGraphs(CTestStep* aStep):
       
   215 	CTWsGraphicsBase(aStep)
       
   216 	{
       
   217 	}
       
   218 
       
   219 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   220 LOCAL_D void DeleteSpriteMember(TAny* aSpriteMember)
       
   221 	{
       
   222 	TSpriteMember* member=reinterpret_cast<TSpriteMember*>(aSpriteMember);
       
   223 	delete member->iBitmap;
       
   224 	member->iBitmap=NULL;
       
   225 	delete member->iMaskBitmap;
       
   226 	member->iMaskBitmap=NULL;
       
   227 	}
       
   228 #endif
       
   229 
       
   230 CTWsGraphs::~CTWsGraphs()
       
   231 	{
       
   232 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   233 	DeleteSpriteMember(&iSpriteMemberArray[0]);
       
   234 	iSpriteMemberArray.Close();
       
   235 #endif
       
   236 	delete iGdCoverage;
       
   237 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   238 	delete iAfter;
       
   239 	delete iBefore;
       
   240 	delete iBackCopy;
       
   241 	delete iFrontCopy;
       
   242 #endif
       
   243 	delete iListen;
       
   244 	delete iNotify2;
       
   245 	delete iNotify1;
       
   246 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   247 	delete iRedir;
       
   248 #endif
       
   249 	}
       
   250 
       
   251 void CTWsGraphs::ConstructL()
       
   252 	{
       
   253 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   254 	iRedir = CWsRedir::NewL(iTest->iScreenNumber,ETrue);
       
   255 	iRedir->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
       
   256 #endif
       
   257 	iNotify1 = CWsNotify::NewL(EFalse);
       
   258 	iNotify2 = CWsNotify::NewL(ETrue);
       
   259 	iListen = CWsListen::NewL(ETrue);
       
   260 	iListen->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
       
   261 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   262 	iFrontCopy = new(ELeave) CFbsBitmap;
       
   263 	iBackCopy = new(ELeave) CFbsBitmap;
       
   264 	iBefore = new(ELeave) CFbsBitmap;
       
   265 	User::LeaveIfError(iBefore->Create(TheClient->iScreen->SizeInPixels(), EColor64K));
       
   266 	iAfter = new(ELeave) CFbsBitmap;
       
   267 	User::LeaveIfError(iAfter->Create(TheClient->iScreen->SizeInPixels(), EColor64K));
       
   268 #endif
       
   269 	iGdCoverage = CWsGdCoverage::NewL();
       
   270 	iGdCoverage->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
       
   271 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   272 	TSpriteMember spriteMember;
       
   273 	spriteMember.iBitmap = NULL;
       
   274 	spriteMember.iMaskBitmap = NULL;
       
   275 	spriteMember.iInvertMask =EFalse;
       
   276 	spriteMember.iDrawMode = CGraphicsContext::EDrawModePEN;
       
   277 	spriteMember.iOffset = TPoint();
       
   278 	spriteMember.iInterval = TTimeIntervalMicroSeconds32(0);
       
   279 	CleanupStack::PushL(TCleanupItem(DeleteSpriteMember, &spriteMember));
       
   280 	spriteMember.iBitmap = new (ELeave) CFbsBitmap;
       
   281 	User::LeaveIfError(spriteMember.iBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1));
       
   282 	spriteMember.iMaskBitmap = new (ELeave) CFbsBitmap;
       
   283 	User::LeaveIfError(spriteMember.iMaskBitmap->Load(TEST_BITMAP_NAME, EMbmWsautotestBmp1mask));
       
   284 	User::LeaveIfError(iSpriteMemberArray.Append(spriteMember));
       
   285 	CleanupStack::Pop(&spriteMember);
       
   286 #endif
       
   287 	}
       
   288 
       
   289 void CTWsGraphs::LaunchNewProcess(const TDesC& aExecutable)
       
   290 	{
       
   291 	TBuf<128> args;
       
   292  	args.Append(KSpace);
       
   293 	args.AppendNum(iTest->iScreenNumber);
       
   294 	RProcess pr;
       
   295 	TInt err = pr.Create(aExecutable,args);
       
   296 	if (err == KErrNone)
       
   297 		{
       
   298 		TRequestStatus status;
       
   299 		pr.Logon(status);
       
   300 		pr.Resume();
       
   301 		User::WaitForRequest(status);
       
   302 		err = pr.ExitReason();
       
   303 		pr.Close();
       
   304 		if (err != KErrNone)
       
   305 			{
       
   306 			_LIT(KLog,"%S returned error: %d. Check RDebug output.");
       
   307 			LOG_MESSAGE3(KLog, &aExecutable, err);
       
   308 			}
       
   309 		}
       
   310 	else
       
   311 		{
       
   312 		_LIT(KLog,"Can't create the process (%S), err=%d");
       
   313 		LOG_MESSAGE3(KLog, &aExecutable, err);
       
   314 		}
       
   315 	TEST(err == KErrNone);
       
   316 	// Restore main test group to foreground.
       
   317 	TheClient->iGroup->GroupWin()->SetOrdinalPosition(0);
       
   318 	}
       
   319 
       
   320 TInt CTWsGraphs::PluginCallBack(TAny* /*aArg*/)
       
   321 	{
       
   322 	return (TInt)EWait;
       
   323 	}
       
   324 
       
   325 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   326 
       
   327 /**
       
   328  @SYMTestCaseID				GRAPHICS-WSERV-0371
       
   329  @SYMREQ					GT247-CR0714
       
   330  @SYMTestCaseDesc			Test interface extension
       
   331  @SYMTestPriority			High
       
   332  @SYMTestStatus				Implemented
       
   333  @SYMTestActions			Retrieves object interfaces from Content Rendering Plugin (plugin).
       
   334 							Actions step:
       
   335 							-Create plugin
       
   336 							-Query interfaces obtained from plugin side
       
   337  @SYMTestExpectedResults	Supported interfaces should return non null
       
   338 */
       
   339 TestState CTWsGraphs::TestInterfaceExtensionL()
       
   340 	{
       
   341 	if (iSubState==0)
       
   342 		{
       
   343 		_LIT(KTestInterfaceExtension, "TestInterfaceExtension");
       
   344 		INFO_PRINTF1(KTestInterfaceExtension);
       
   345 
       
   346 		++iSubState;
       
   347 		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));
       
   348 		iRedir->QueryPlugin(iRedirInfo);
       
   349 		return EWait;
       
   350 		}
       
   351 	TEST(iRedirInfo.iScreenConfigInterface!=NULL);
       
   352 	TEST(iRedirInfo.iFrontBufferInterface!=NULL);
       
   353 	TEST(iRedirInfo.iScreenBitmapHandle!=0);
       
   354 	iFrontCopy->Duplicate(iRedirInfo.iScreenBitmapHandle);
       
   355 
       
   356 	if (TransparencySupportedL()!=KErrNotSupported)
       
   357 		{
       
   358 		TEST(iRedirInfo.iBackBufferInterface!=NULL);
       
   359 		TEST(iRedirInfo.iFlickerBitmapHandle!=0);
       
   360 		iBackCopy->Duplicate(iRedirInfo.iFlickerBitmapHandle);
       
   361 		}
       
   362 
       
   363 	++(iTest->iState);
       
   364 	iSubState = 0;
       
   365 	return ENext;
       
   366 	}
       
   367 
       
   368 #endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   369 
       
   370 void CTWsGraphs::CreateWindowL(TBool aDraw)
       
   371 	{
       
   372 	iWin = CCrWin::NewL(iTest->iScreenNumber, aDraw);
       
   373 	}
       
   374 
       
   375 void CTWsGraphs::DestroyWindowL()
       
   376 	{
       
   377 	delete iWin;
       
   378 	iWin = NULL;
       
   379 	}
       
   380 
       
   381 void CTWsGraphs::CreateAlphaWindowL()
       
   382 	{
       
   383 	iAlpha = CCrAlphaWin::NewL(iTest->iScreenNumber);
       
   384 	}
       
   385 
       
   386 void CTWsGraphs::DestroyAlphaWindowL()
       
   387 	{
       
   388 	delete iAlpha;
       
   389 	iAlpha = NULL;
       
   390 	}
       
   391 
       
   392 TBool CTWsGraphs::CompareBitmapArea16Bpp(CFbsBitmap* aBmp1, const TPoint& aPos1, CFbsBitmap* aBmp2, const TPoint& aPos2, const TSize& aSize)
       
   393 	{
       
   394 	const TDisplayMode dispmode = aBmp1->DisplayMode();
       
   395 	if (dispmode!=aBmp2->DisplayMode())
       
   396 		return EFalse;
       
   397 	const TInt stride1 = aBmp1->DataStride();
       
   398 	const TInt stride2 = aBmp2->DataStride();
       
   399 	const TInt linebytes = aSize.iWidth * 2;
       
   400 	const TInt pixelbytes = 2;
       
   401 	aBmp1->LockHeap();
       
   402 	const TUint8* p1 = ((const TUint8*)aBmp1->DataAddress())+aPos1.iY*stride1+aPos1.iX*pixelbytes;
       
   403 	const TUint8* p2 = ((const TUint8*)aBmp2->DataAddress())+aPos2.iY*stride2+aPos2.iX*pixelbytes;
       
   404 	for (TInt y=0; y<aSize.iHeight; ++y)
       
   405 		{
       
   406 		if (Mem::Compare(p1+y*stride1,linebytes,p2+y*stride2,linebytes)!=0)
       
   407 			{
       
   408 			aBmp1->UnlockHeap();
       
   409 			return EFalse;
       
   410 			}
       
   411 		}
       
   412 	aBmp1->UnlockHeap();
       
   413 	return ETrue;
       
   414 	}
       
   415 
       
   416 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   417 TestState CTWsGraphs::TestScreenRedirectionL()
       
   418 	{
       
   419 	if (iSubState==0)
       
   420 		{
       
   421 		_LIT(KTestScreenRedirection, "TestScreenRedirection");
       
   422 		INFO_PRINTF1(KTestScreenRedirection);
       
   423 
       
   424 		++iSubState;
       
   425 		/**
       
   426 		 @SYMTestCaseID				GRAPHICS-WSERV-0372
       
   427 		 @SYMREQ					GT247-CR0714
       
   428 		 @SYMTestCaseDesc			Redirect wserv screen drawing to custom graphics context
       
   429 		 @SYMTestPriority			High
       
   430 		 @SYMTestStatus				Implemented
       
   431 		 @SYMTestActions			Redirects wserv screen drawing to bitmap context owned by plugin.
       
   432 									Actions step:
       
   433 									-Draw opaque window.
       
   434 									-Save screen content to a bitmap
       
   435 									-Instruct plugin to redirect wserv screen drawing to a bitmap device
       
   436 									-Draw the same window again
       
   437 									-Retrieve plugin bitmap and compare against  the saved bitmap
       
   438 		 @SYMTestExpectedResults	Bitmap content match
       
   439 		*/
       
   440 		CreateWindowL();		
       
   441 		TheClient->iScreen->CopyScreenToBitmap(iBefore);
       
   442 		DestroyWindowL();
       
   443 		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
       
   444 		return EWait;
       
   445 		}
       
   446 
       
   447 	if (iSubState==1)
       
   448 		{
       
   449 		++iSubState;
       
   450 		CreateWindowL();
       
   451 		TSize sz = iBefore->SizeInPixels();
       
   452 		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
       
   453 		iBefore->LockHeap();
       
   454 		TEST(Mem::Compare((const TUint8*)iFrontCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
       
   455 		iBefore->UnlockHeap();
       
   456 
       
   457 		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));			
       
   458 		iRedir->QueryPlugin(iRedirInfo);
       
   459 		return EWait;
       
   460 		}
       
   461 
       
   462 	if (iSubState==2)
       
   463 		{
       
   464 		++iSubState;
       
   465 		/**
       
   466 		 @SYMTestCaseID				GRAPHICS-WSERV-0047
       
   467 		 @SYMTestCaseDesc			Screen update event
       
   468 		 @SYMTestPriority			Medium
       
   469 		 @SYMTestStatus				Implemented
       
   470 		 @SYMTestActions			Check plugin receive screen update event during redirection
       
   471 		 @SYMTestExpectedResults	Counter is non-zero
       
   472 		*/
       
   473 		TEST(iRedirInfo.iUpdateCounter>0);
       
   474 
       
   475 		DestroyWindowL();
       
   476 		/**
       
   477 		 @SYMTestCaseID				GRAPHICS-WSERV-0373
       
   478 		 @SYMREQ					GT247-CR0714
       
   479 		 @SYMTestCaseDesc			Stop wserv screen drawing redirection
       
   480 		 @SYMTestPriority			High
       
   481 		 @SYMTestStatus				Implemented
       
   482 		 @SYMTestActions			Stop wserv screen drawing redirection.
       
   483 									Actions step:
       
   484 									-Instruct plugin to stop wserv screen drawing redirection
       
   485 									-Draw the same window again
       
   486 									-Save screen content to another bitmap
       
   487 									-Compare the saved bitmap against newly saved bitmap
       
   488 		 @SYMTestExpectedResults	Bitmap content match
       
   489 		*/
       
   490 		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
       
   491 		return EWait;
       
   492 		}
       
   493 
       
   494 	if (iSubState==3)
       
   495 		{
       
   496 		++iSubState;
       
   497 		CreateWindowL();
       
   498 		TheClient->iScreen->CopyScreenToBitmap(iAfter);
       
   499 		TSize sz = iBefore->SizeInPixels();	
       
   500 		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K	
       
   501 		iAfter->LockHeap();
       
   502 		TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
       
   503 		iAfter->UnlockHeap();
       
   504 		DestroyWindowL();
       
   505 
       
   506 		Mem::FillZ(&iRedirInfo, sizeof(TRedirectorInfo));			
       
   507 		iRedir->QueryPlugin(iRedirInfo);
       
   508 		return EWait;
       
   509 		}
       
   510 
       
   511 	/**
       
   512 	 @SYMTestCaseID				GRAPHICS-WSERV-0374
       
   513 	 @SYMTestCaseDesc			Screen update event
       
   514 	 @SYMTestPriority			Medium
       
   515 	 @SYMTestStatus				Implemented
       
   516 	 @SYMTestActions			Check plugin receive no screen update event when redirection is terminated
       
   517 	 @SYMTestExpectedResults	Counter is zero
       
   518 	*/
       
   519 	TEST(iRedirInfo.iUpdateCounter==0);
       
   520 
       
   521 	++(iTest->iState);
       
   522 	iSubState = 0;
       
   523 
       
   524 	return ENext;
       
   525 	}
       
   526 
       
   527 TestState CTWsGraphs::TestTextCursorUnderRedirectionL(TTestCursorType aCursorType)
       
   528 	{
       
   529 	/**
       
   530 	 @SYMTestCaseID				GRAPHICS-WSERV-0363
       
   531 	 @SYMTestCaseDesc			Text Cursor when drawing redirected
       
   532 	 @SYMTestPriority			Medium
       
   533 	 @SYMTestStatus				Implemented
       
   534 	 @SYMTestActions			Action steps:
       
   535 	 							- Draw the text cursor in the left side of the screen
       
   536 	 							- Re-direct the Front Buffer
       
   537 	 							- Move the text cursor to the right side of the screen
       
   538 	 							- Pause 0.5 seconds because this amount of time is needed
       
   539 								  to change from the flash ON phase to the flash OFF phase
       
   540 	 							- Stop re-directing
       
   541 	 							- See if when we exit re-direction in a different place in
       
   542 	 							  the phase of the text cursor flashing, whether we get
       
   543 	 							  non-text cursor drawing artefacts in the old location
       
   544 	 							  where the text cursor used to be
       
   545 	 @SYMTestExpectedResults	Left side of the screen does not show a Text Cursor
       
   546 	 */
       
   547 	
       
   548 	ASSERT(aCursorType == ETestStandardTextCursor || aCursorType == ETestCustomTextCursor);
       
   549 	
       
   550 	// Cursor Flash Period is 1 second (comprising two phases; ON and OFF)
       
   551 	const TInt KCursorFlashPeriod = 1000000;
       
   552 	const TInt KWaitForNextFlashPhase = KCursorFlashPeriod / 2;
       
   553 	
       
   554 	// Size of the cursor; it may be either a standard or custom text cursor
       
   555 	TSize cursorSize = (aCursorType == ETestStandardTextCursor) ? TSize(15, 20) : TSize(80, 80);
       
   556 		
       
   557 	// Original Text Cursor position in the left part of the screen
       
   558 	const TPoint originalCursorPos(45, 40);
       
   559 	
       
   560 	// New Text Cursor position in the right half of the screen
       
   561 	const TPoint newCursorPos((TheClient->iScreen->SizeInPixels().iWidth/2) + 45, 40);
       
   562 	
       
   563 	// Clean area of the screen which never had a text cursor
       
   564 	const TPoint cleanReferencePos(45, 40 + 80);
       
   565 	
       
   566 	/* Initial setup to get a window with a standard flashing text cursor */
       
   567 	if (iSubState == 0)
       
   568 		{
       
   569 		++iSubState;			
       
   570 		CreateWindowL(ETrue);
       
   571 		
       
   572 		if (aCursorType == ETestStandardTextCursor)
       
   573 			{
       
   574 			_LIT(KTestTextCursorUnderRedirection, "TestTextCursorUnderRedirection(Standard Cursor)");
       
   575 			INFO_PRINTF1(KTestTextCursorUnderRedirection);	
       
   576 			iTextCursor.iType=TTextCursor::ETypeRectangle;
       
   577 			iTextCursor.iHeight=cursorSize.iHeight;
       
   578 			iTextCursor.iAscent=0;
       
   579 			iTextCursor.iWidth=cursorSize.iWidth;
       
   580 			iTextCursor.iFlags=0; 			// means flash the cursor
       
   581 			iTextCursor.iColor=KRgbGreen;
       
   582 			iWin->SetTextCursor(originalCursorPos, iTextCursor);
       
   583 			}
       
   584 		else if (aCursorType == ETestCustomTextCursor)
       
   585 			{
       
   586 			_LIT(KTestTextCursorUnderRedirection, "TestTextCursorUnderRedirection(Custom Cursor)");
       
   587 			INFO_PRINTF1(KTestTextCursorUnderRedirection);	
       
   588 
       
   589 			TInt err = TheClient->iWs.SetCustomTextCursor(
       
   590 					KCustomTextCursorId,
       
   591 					iSpriteMemberArray.Array(),
       
   592 					ESpriteFlash,
       
   593 					RWsSession::ECustomTextCursorAlignTop
       
   594 					);
       
   595 			iTextCursor.iType=KCustomTextCursorId;
       
   596 			iTextCursor.iHeight=cursorSize.iHeight;
       
   597 			iTextCursor.iAscent=0;
       
   598 			iTextCursor.iWidth=cursorSize.iWidth;
       
   599 			iTextCursor.iFlags=TTextCursor::EFlagClipHorizontal; // means flash the cursor and clip the sprite
       
   600 			iTextCursor.iColor=KRgbCyan;
       
   601 			iWin->SetTextCursor(originalCursorPos, iTextCursor);
       
   602 			}
       
   603 		else
       
   604 			{
       
   605 			// unknown type of test being requested
       
   606 			ASSERT(0);
       
   607 			}
       
   608 		iWin->DrawFirstHalf();	
       
   609 		return EWait;
       
   610 		}
       
   611 	/*
       
   612 	 * Re-direct drawing to another Front Buffer.  Whilst re-directed, change the
       
   613 	 * position of the text cursor.  Then pause 0.5 seconds because this is how
       
   614 	 * long it will take to enter the next phase in the flashing cycle.  Finally
       
   615 	 * stop re-directing.  We exit the re-direction in a different point in the
       
   616 	 * phase of the text cursor from when we entered it.
       
   617 	 * This is key to testing for faulty behaviour.
       
   618 	 */
       
   619 	if (iSubState==1)
       
   620 		{
       
   621 		++iSubState;
       
   622 		User::After(KCursorFlashPeriod * 2);  // so its easy to visually review progress
       
   623 		iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
       
   624 		iWin->SetTextCursor(newCursorPos, iTextCursor);
       
   625 		User::After(KWaitForNextFlashPhase);
       
   626 		iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
       
   627 		return EWait;
       
   628 		}
       
   629 	/*
       
   630 	 * Paint the right hand side of the screen which should now have a text cursor.
       
   631 	 */
       
   632 	if (iSubState==2)
       
   633 		{
       
   634 		++iSubState;
       
   635 		iWin->DrawSecondHalf();
       
   636 		return EWait;
       
   637 		}
       
   638 	/*
       
   639 	 * Let the cursor flash a few times, as it assists manual viewing of the progress
       
   640 	 * of the test.
       
   641 	 */
       
   642 	if (iSubState==3)
       
   643 		{
       
   644 		++iSubState;
       
   645 		User::After(KCursorFlashPeriod * 3);
       
   646 		return EWait;
       
   647 		}
       
   648 	/*
       
   649 	 * Check to see if the text cursor did move to the right of the screen.
       
   650 	 */
       
   651 	if (iSubState==4)
       
   652 		{
       
   653 		++iSubState;
       
   654 		
       
   655 		/* When we do a screen comparison, we supply flag 0, which means
       
   656 		 * don't include the text cursor.  We do this because we are interested
       
   657 		 * in screen artefacts.
       
   658 		 */
       
   659 		TEST(TheClient->iScreen->RectCompare(
       
   660 				TRect(originalCursorPos, cursorSize),
       
   661 				TRect(cleanReferencePos, cursorSize),
       
   662 				0)); // must not supply CWsScreenDevice::EIncludeTextCursor
       
   663 		
       
   664 		return EWait;
       
   665 		}
       
   666 	/* Clean up */
       
   667 	if (iSubState==5)
       
   668 		{
       
   669 		++iSubState;
       
   670 		iWin->CancelTextCursor();
       
   671 		DestroyWindowL();
       
   672 		}
       
   673 	
       
   674 	iSubState = 0;
       
   675 
       
   676 	return ENext;
       
   677 	}
       
   678 
       
   679 /**
       
   680  @SYMTestCaseID				GRAPHICS-WSERV-0375
       
   681  @SYMREQ					GT247-CR0714
       
   682  @SYMTestCaseDesc			Redirect wserv flickerfree drawing to custom graphics context
       
   683  @SYMTestPriority			Medium
       
   684  @SYMTestStatus				Implemented
       
   685  @SYMTestActions			Redirect wserv flickerfree buffer drawing.
       
   686 							Action step:
       
   687 							-Draw opaque window (as background) and transparent window
       
   688 							-Save screen content to a bitmap
       
   689 							-Instruct plugin to redirect wserv flickerfree buffer drawing
       
   690 							-Draw the same opaque window and transparent window again
       
   691 							-Retrieve plugin bitmap and compare against the saved bitmap
       
   692  @SYMTestExpectedResults	Bitmap content match
       
   693 */
       
   694 /**
       
   695  @SYMTestCaseID				GRAPHICS-WSERV-0376
       
   696  @SYMREQ					GT247-CR0714
       
   697  @SYMTestCaseDesc			Stop wserv flickerfree drawing redirection
       
   698  @SYMTestPriority			Medium
       
   699  @SYMTestStatus				Implemented
       
   700  @SYMTestActions			Stop wserv flickerfree buffer drawing redirection.
       
   701 							Action step:
       
   702 							-Instruct plugin to stop wserv filckerfree drawing redirection
       
   703 							-Draw the same opaque and transparent window
       
   704 							-Save screen content to another bitmap
       
   705 							-Compare saved bitmap against newly saved bitmap
       
   706  @SYMTestExpectedResults	Bitmap content match
       
   707 */
       
   708 
       
   709 TestState CTWsGraphs::TestFlickerRedirectionL()
       
   710 	{
       
   711 	if (TransparencySupportedL()==KErrNotSupported)
       
   712 		{
       
   713 		++(iTest->iState);
       
   714 		return ENext;
       
   715 		}
       
   716 
       
   717 	// flush transparent window destruction created in TransparencySupportedL before
       
   718 	// proceeding with the test
       
   719 
       
   720 	TheClient->iWs.Flush();
       
   721 
       
   722 	if (iSubState==0)
       
   723 		{
       
   724 		_LIT(KTestFlickerRedirection, "TestFlickerRedirection");
       
   725 		INFO_PRINTF1(KTestFlickerRedirection);
       
   726 
       
   727 		++iSubState;
       
   728 
       
   729 		CreateWindowL();
       
   730 		CreateAlphaWindowL();
       
   731 		TheClient->iScreen->CopyScreenToBitmap(iBefore);
       
   732 		DestroyAlphaWindowL();
       
   733 		DestroyWindowL();
       
   734 		iRedir->Redirect(CWsRedir::EBackBuffer, ETrue);
       
   735 		return EWait;
       
   736 		}
       
   737 
       
   738 	if (iSubState==1)
       
   739 		{
       
   740 		++iSubState;
       
   741 		CreateWindowL();
       
   742 		CreateAlphaWindowL();
       
   743 		TSize sz = iBefore->SizeInPixels();
       
   744 		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
       
   745 		iBefore->LockHeap();
       
   746 		TInt ret=Mem::Compare((const TUint8*)iBackCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes);
       
   747 		TEST(ret==0);
       
   748 		if (ret!=0)
       
   749 			{
       
   750 			_LIT(KLog,"The memory of two bitmaps doesn't match");
       
   751 			LOG_MESSAGE(KLog);
       
   752 			}
       
   753 		iBefore->UnlockHeap();
       
   754 		DestroyAlphaWindowL();
       
   755 		DestroyWindowL();
       
   756 		iRedir->Redirect(CWsRedir::EBackBuffer, EFalse);
       
   757 		return EWait;
       
   758 		}
       
   759 
       
   760 	CreateWindowL();
       
   761 	CreateAlphaWindowL();
       
   762 	TheClient->iScreen->CopyScreenToBitmap(iAfter);
       
   763 	TSize sz = iBefore->SizeInPixels();
       
   764 	TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
       
   765 	iAfter->LockHeap();
       
   766 	TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
       
   767 	iAfter->UnlockHeap();
       
   768 	DestroyAlphaWindowL();
       
   769 	DestroyWindowL();
       
   770 
       
   771 	++(iTest->iState);
       
   772 	iSubState = 0;
       
   773 	return ENext;
       
   774 	}
       
   775 
       
   776 #endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   777 
       
   778 /**
       
   779  @SYMTestCaseID				GRAPHICS-WSERV-0377
       
   780  @SYMREQ					GT247-CR0714
       
   781  @SYMTestCaseDesc			Enable event notification
       
   782  @SYMTestPriority			Medium
       
   783  @SYMTestStatus				Implemented
       
   784  @SYMTestActions			Enable plugin to register to event notification.
       
   785 							Action step:
       
   786 							-Instruct plugin to register event handler
       
   787 							-Draw fullscreen window (plugin will receive window visibility changed event)
       
   788 							-Query visibility region from plugin side
       
   789 							-Compare window visible region against value obtained by plugin
       
   790  @SYMTestExpectedResults	Visible region match
       
   791 */
       
   792 /**
       
   793  @SYMTestCaseID				GRAPHICS-WSERV-0378
       
   794  @SYMREQ					GT247-CR0714
       
   795  @SYMTestCaseDesc			Disable event notification
       
   796  @SYMTestPriority			Medium
       
   797  @SYMTestStatus				Implemented
       
   798  @SYMTestActions			Disable plugin to register to event notification.
       
   799 							Action step:
       
   800 							-Instruct plugin to unregister event handler
       
   801 							-Destroy fullscreen window (plugin will not receive window visibility changed event)
       
   802 							-Query visibility region from plugin side
       
   803 
       
   804  @SYMTestExpectedResults	Plugin does not receive events notification
       
   805 */
       
   806 TestState CTWsGraphs::TestEventNotificationL()
       
   807 	{
       
   808 	if (iSubState==0)
       
   809 		{
       
   810 		_LIT(KTestEventNotification, "TestEventNotification");
       
   811 		INFO_PRINTF1(KTestEventNotification);
       
   812 
       
   813 		++iSubState;
       
   814 		iListen->Enable(ETrue);
       
   815 		CreateWindowL();
       
   816 		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
       
   817 		TheClient->iWs.Finish();
       
   818 		TheClient->WaitForRedrawsToFinish();
       
   819 		iListen->QueryPlugin(iListenInfo);
       
   820 		return EWait;
       
   821 		}
       
   822 
       
   823 	if (iSubState==1)
       
   824 		{
       
   825 		++iSubState;
       
   826 		iListen->Enable(EFalse);
       
   827 		TEST(iListenInfo.iNumRect==1);
       
   828 		TEST(iListenInfo.iRect==TRect(TPoint(0,0),TheClient->iScreen->SizeInPixels()));
       
   829 		DestroyWindowL();
       
   830 		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
       
   831 		iListen->QueryPlugin(iListenInfo);
       
   832 		iListen->Enable(EFalse);
       
   833 		DestroyWindowL();
       
   834 		return EWait;
       
   835 		}
       
   836 		
       
   837 	TEST(iListenInfo.iNumRect==0);
       
   838 	
       
   839 	++(iTest->iState);
       
   840 	iSubState = 0;
       
   841 	return ENext;
       
   842 	}
       
   843 
       
   844 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   845 
       
   846 TestState CTWsGraphs::TestRedirectionUsingWsBackBufferL()
       
   847 	{
       
   848 	if (TransparencySupportedL()==KErrNotSupported)
       
   849 		{
       
   850 		++(iTest->iState);
       
   851 		return ENext;
       
   852 		}
       
   853 
       
   854 	// flush transparent window destruction created in TransparencySupportedL before
       
   855 	// proceeding with the test
       
   856 
       
   857 	TheClient->iWs.Flush();
       
   858 
       
   859 	if (iSubState==0)
       
   860 		{
       
   861 		_LIT(KTestRedirectionWsBack, "TestRedirectionUsingWsBackBuffer");
       
   862 		INFO_PRINTF1(KTestRedirectionWsBack);
       
   863 		
       
   864 		++iSubState;
       
   865 
       
   866 		/**
       
   867 		 @SYMTestCaseID				GRAPHICS-WSERV-0379
       
   868 		 @SYMTestCaseDesc			Redirect wserv flickerfree to MWsBackBuffer object
       
   869 		 @SYMTestPriority			Medium
       
   870 		 @SYMTestStatus				Implemented
       
   871 		 @SYMTestActions			-Draw opaque window (as background) and transparent window
       
   872 									-Save screen content to a bitmap
       
   873 									-Instruct plugin to redirect flickerfree buffer to MWsBackBuffer object
       
   874 									-Draw the same opaque window and transparent window again
       
   875 									-Retrieve plugin bitmap and compare against the saved bitmap
       
   876 		 @SYMTestExpectedResults	Bitmap content match
       
   877 		*/
       
   878 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0379"));
       
   879 		CreateWindowL();
       
   880 		CreateAlphaWindowL();
       
   881 		TheClient->iScreen->CopyScreenToBitmap(iBefore);
       
   882 		DestroyAlphaWindowL();		
       
   883 		DestroyWindowL();		
       
   884 		iRedir->RedirectUsingWsBackBuffer(ETrue);
       
   885 		return EWait;
       
   886 		}
       
   887 
       
   888 	if (iSubState==1)
       
   889 		{
       
   890 		++iSubState;
       
   891 		CreateWindowL();
       
   892 		CreateAlphaWindowL();
       
   893 		TSize sz = iBefore->SizeInPixels();
       
   894 		TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
       
   895 		iBefore->LockHeap();
       
   896 		TInt ret=Mem::Compare((const TUint8*)iBackCopy->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes);
       
   897 		TEST(ret==0);
       
   898 		if (ret!=0)
       
   899 			{
       
   900 			_LIT(KLog,"The memory of two bitmaps doesn't match");
       
   901 			LOG_MESSAGE(KLog);
       
   902 			}
       
   903 		iBefore->UnlockHeap();
       
   904 		DestroyAlphaWindowL();
       
   905 		DestroyWindowL();
       
   906 
       
   907 		/**
       
   908 		 @SYMTestCaseID				GRAPHICS-WSERV-0380
       
   909 		 @SYMTestCaseDesc			Restore wserv flickerfree redirection from MWsBackBuffer object
       
   910 		 @SYMTestPriority			Medium
       
   911 		 @SYMTestStatus				Implemented
       
   912 		 @SYMTestActions			-Instruct plugin to stop wserv filckerfree drawing redirection
       
   913 									-Draw the same opaque and transparent window
       
   914 									-Save screen content to another bitmap
       
   915 									-Compare saved bitmap against newly saved bitmap
       
   916 		 @SYMTestExpectedResults	Bitmap content match
       
   917 		*/
       
   918 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0380"));
       
   919 		iRedir->RedirectUsingWsBackBuffer(EFalse);
       
   920 		return EWait;
       
   921 		}
       
   922 
       
   923 	CreateWindowL();
       
   924 	CreateAlphaWindowL();
       
   925 	TheClient->iScreen->CopyScreenToBitmap(iAfter);
       
   926 	TSize sz = iBefore->SizeInPixels();
       
   927 	TInt bytes = sz.iWidth*sz.iHeight*2; // EColor64K
       
   928 	iAfter->LockHeap();
       
   929 	TEST(Mem::Compare((const TUint8*)iAfter->DataAddress(),bytes,(const TUint8*)iBefore->DataAddress(),bytes)==0);
       
   930 	iAfter->UnlockHeap();
       
   931 	DestroyAlphaWindowL();
       
   932 	DestroyWindowL();
       
   933 /**
       
   934 	@SYMTestCaseID	GRAPHICS-WSERV-0527
       
   935 */
       
   936 	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0527"));
       
   937 	++(iTest->iState);
       
   938 	iSubState = 0;
       
   939 	return ENext;
       
   940 	}
       
   941 
       
   942 #endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
   943 
       
   944 //A call to do coverage through a plugin. 
       
   945 //This can serve as a basis for future coverage to objects exposed by the
       
   946 //plugin. For now a single simple test is implmeneted.
       
   947 TestState CTWsGraphs::TestGraphicDrawerCoverage()
       
   948 	{
       
   949 	__ASSERT_ALWAYS(iGdCoverage->RunTest(1)==KErrNone||KErrNotReady, User::Invariant());
       
   950 	return ENext;
       
   951 	}
       
   952 
       
   953 //Simplified non-functional class to create a few dummy CWsGraphicDrawer instances.
       
   954 //This code is intended to test the Array class, not the Drawer.
       
   955 //Note that this object is not at all functional! The only guaranteed method is Id().
       
   956 //WsGraphicDrawer is declared as a friend and is actually intended to be the factory class for CWsGraphicDrawer
       
   957 class WsGraphicDrawer:public CWsGraphicDrawer
       
   958 	{
       
   959 public:
       
   960 	WsGraphicDrawer()
       
   961 		{
       
   962 		}
       
   963 	//stub for virtual construction. Most members are ignored
       
   964 	virtual void ConstructL(MWsGraphicDrawerEnvironment& ,const TGraphicDrawerId& id,MWsClient& ,const TDesC8& )
       
   965 		{
       
   966 		ConstructL(id);
       
   967 		}
       
   968 	//simplified custom construction
       
   969 	void ConstructL(const TGraphicDrawerId& id)
       
   970 		{
       
   971 		MWsGraphicDrawerEnvironment* nullEnv=NULL;
       
   972 		MWsGraphicDrawerEnvironment& aEnv=*nullEnv;
       
   973 		MWsClient* nullClient=NULL;
       
   974 		MWsClient& aOwner=*nullClient;
       
   975 		this->BaseConstructL(aEnv,id,aOwner);
       
   976 		this->iDtor_ID_Key=TUid::Null();
       
   977 		
       
   978 		}
       
   979 	//stubs for pure virtual methods
       
   980 	virtual void HandleMessage(const TDesC8& )
       
   981 		{}
       
   982 	virtual void DoDraw(MWsGc& ,const TRect& ,const TDesC8& ) const
       
   983 		{}
       
   984 	
       
   985 	};
       
   986 //Class to allow me to pre-allocate the CWsGraphicDrawerArray so it doesn't pop up a false-positive memory allocation!
       
   987 class DummyCleanup:public TCleanupItem
       
   988 	{
       
   989 public:
       
   990 	static void CleanUp(TAny*)		{}
       
   991 	DummyCleanup(): TCleanupItem(CleanUp,this)	{}
       
   992 	operator DummyCleanup*()	{	return this;	}
       
   993 	
       
   994 	};
       
   995 
       
   996 //Helper function to explain test fails. Most other tests are against KErrNone
       
   997 void CTWsGraphs::ReportNegativeResultfail(TInt aLine,TInt aResult,TInt aExpectedResult)
       
   998 	{
       
   999 	testBooleanTrue((aResult==aExpectedResult), (TText8*)__FILE__, aLine);
       
  1000 	if (aResult!=aExpectedResult)
       
  1001 		{
       
  1002 		INFO_PRINTF3(_L("Expected return code %i, got %i"),aExpectedResult,aResult);	
       
  1003 		}
       
  1004 	
       
  1005 	}
       
  1006 	
       
  1007 //This is an attempt to use wserv test's pre-existing Panic handler to perform some negative tests.
       
  1008 //At present this handler appears to be broken:
       
  1009 // 1) It doesn't write to the correct html log file
       
  1010 // 2) It no longer writes to the WSERV.LOG file it was writing to a few versions ago
       
  1011 // 3) It doesn't close the panic window so subsequent tests that check the display output fail.
       
  1012 //That was a waste of effort.
       
  1013 struct CTWsGraphs::WrapTestCall
       
  1014 	{
       
  1015 	CTWsGraphs* thisThis;
       
  1016 	TUint		testCount;
       
  1017 	TBool		continueTests;
       
  1018 	TUint 		testFailedLine;
       
  1019 	//This field was intended to allow threaded panicing tests to report other errors
       
  1020 	//As I can't get threaded panicing tests to operate correctly, I have not implemented support for the field.
       
  1021 	//TBuf<1024>	errorMessages;	
       
  1022 		
       
  1023 	WrapTestCall (	CTWsGraphs* thisThis,	TUint		testCount):
       
  1024 		thisThis(thisThis),	testCount(testCount)
       
  1025 		{	continueTests=false;testFailedLine=0;	}
       
  1026 	};
       
  1027 	
       
  1028 TInt	CTWsGraphs::DoNegTestCall(TInt /*aInt*/, TAny *aPtr)
       
  1029 	{
       
  1030 	CTWsGraphs::WrapTestCall* aWrap=static_cast<CTWsGraphs::WrapTestCall*>(aPtr);
       
  1031 	aWrap->continueTests=aWrap->thisThis->NegTestAddSwapGDArrayL(aWrap->testCount,aWrap);	
       
  1032 	return 0;
       
  1033 	}
       
  1034 	
       
  1035 TBool	CTWsGraphs::LaunchNegTestCall(TUint		aTestCount,TUint PanicCode,const TDesC &aPanicCategory)
       
  1036 	{
       
  1037 	WrapTestCall wt(this,aTestCount);
       
  1038 	(void)PanicCode;
       
  1039 	(void)aPanicCategory;
       
  1040 //I have disabled the panicing tests because they don't output diagnostics 
       
  1041 //and the open panic window causes subsequent screen bitmap comparrisson tests to fail.
       
  1042 //	iTest->TestPanicL(DoNegTestCall,aPanicCode,3,&wt,aPanicCategory);
       
  1043 	return wt.continueTests;	
       
  1044 	}
       
  1045 
       
  1046 /**
       
  1047 	Loops through all the positive and negative tests associated with the  GraphicDrawerArray.
       
  1048 	The aim is to perform isolated testing of these classes as some are not currently being used.
       
  1049 	
       
  1050 **/
       
  1051 void CTWsGraphs::TestAddSwapGDArrayL()
       
  1052 	{
       
  1053 
       
  1054 
       
  1055 	INFO_PRINTF1(_L("Positive tests for GraphicDrawerArray"));
       
  1056 	for (TInt i=0;PosTestAddSwapGDArrayL(i);i++)
       
  1057 		{}
       
  1058 
       
  1059 
       
  1060 
       
  1061 	INFO_PRINTF1(_L("Verifying that negative tests for GraphicDrawerArray don't actually panic"));
       
  1062 	for (TInt i=1;NegTestAddSwapGDArrayL(i);i++)
       
  1063 		{}
       
  1064 	}
       
  1065 /**
       
  1066 	Resets and deallocates the GDA withoud deleting the objects.
       
  1067 	@param 	 testArray	the array to reset
       
  1068 	@return true if the array was already empty.
       
  1069 **/
       
  1070 static bool	ResetArray(CWsGraphicDrawerArray& testArray)
       
  1071 {
       
  1072 	bool rv=(testArray.IsEmpty());
       
  1073 	MWsClient* nullClient=NULL;
       
  1074 	testArray.RemoveAll(*nullClient);
       
  1075 	testArray.ResetAndDestroy();		
       
  1076 	return rv;
       
  1077 }
       
  1078 /**
       
  1079    @SYMTestCaseID GRAPHICS-WSERV-AddSwapGDArray-0001
       
  1080    @SYMDEF			DEF093926  
       
  1081   
       
  1082    @SYMTestCaseDesc DEF093926: Check for stability of Add and Swap unwind methods in isolation.
       
  1083    		Note that this code is testing the functionality of a class internal to CWindowServer.
       
  1084    		At present CWindowServer presents just a simple shim on this class, 
       
  1085    		but if that implementation of  CWindowServer changes than this test will be redudant.
       
  1086    
       
  1087    @SYMTestPriority High
       
  1088    
       
  1089    @SYMTestStatus Implemented
       
  1090    
       
  1091    @SYMTestActions
       
  1092 	The sequence for each of these positive test sections is pretty much the same:
       
  1093 	Add one record with id 1234(test for errors)
       
  1094 	Add one record with id Badf00d
       
  1095 	Swap with another record with id Badf00d
       
  1096 	Remove 2 records
       
  1097 	result=no leaks
       
  1098 	
       
  1099 		Add/Swap: no Cleanup item - no leaks after Remove the added items
       
  1100    	    AddTLC/SwapTLC: Cleanup item requires Commit - check for no leaks after Remove.
       
  1101    	    AddTLC/SwapTLC: Cleanup item gets executed by forced Leave  - check for no leaks after.
       
  1102 		AddTLC, SwapTLC in allocation failure scenarios. Add/Swap don't allocate anything!
       
  1103 		obsoleted AddLC/SwapLC to ensure correct function when forced Leave - check for no leaks after
       
  1104 		obsoleted AddLC/SwapLC to ensure correct function. These will always leak in good case.
       
  1105    @SYMTestExpectedResults 
       
  1106    		no exceptions or panics within this fn. 
       
  1107    		only the old AddLC and SwapLC should leak as indicated.
       
  1108  */
       
  1109 TBool CTWsGraphs::PosTestAddSwapGDArrayL(TInt testcase)
       
  1110 	{
       
  1111 	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-AddSwapGDArray-0001"));
       
  1112     CWsGraphicDrawerArray testArray;
       
  1113     //Represents the memory cached in the array once it has been used even when it is then resized to zero
       
  1114 #if defined(_DEBUG)
       
  1115     const TInt KArrayMemUseBaseline=1;
       
  1116 #endif
       
  1117     //Use testArray.IsEmpty() to prove the array is clear when it should be!
       
  1118     TGraphicDrawerId id1234=  	{  	1234,		EFalse    	};
       
  1119     TGraphicDrawerId idBADF00D=	{  	0xBADF00D,	EFalse    	};
       
  1120     WsGraphicDrawer dg1234;		
       
  1121     dg1234.ConstructL(id1234);
       
  1122     WsGraphicDrawer dgBADF00D;	
       
  1123     dgBADF00D.ConstructL(idBADF00D);
       
  1124     WsGraphicDrawer dgBADF00D_2;
       
  1125     dgBADF00D_2.ConstructL(idBADF00D);
       
  1126     CWsGraphicDrawerArray::XRollBackBase* rollBack1;
       
  1127  	TInt errCode=KErrAbort;
       
  1128 	TInt leaveCode=KErrNone;
       
  1129 	DummyCleanup markerCleanup;
       
  1130 	CleanupStack::PushL(markerCleanup);	 //This allows me to check the stack is clear!
       
  1131 	//expected result of this fn: no exceptions or panics. 
       
  1132 	//Put as much as you like in here, so long as it shouldn't fail.
       
  1133 	
       
  1134 	__UHEAP_MARK;
       
  1135 			__UHEAP_CHECK(0);
       
  1136 	TUint expectedLeakCount=0;
       
  1137 	TBool returnCode=ETrue;
       
  1138 	switch (testcase)
       
  1139 		{
       
  1140 		case 0:
       
  1141 
       
  1142 			INFO_PRINTF1(_L("Sub test P0: AddL/Swap: no Cleanup item"));
       
  1143 			TEST(testArray.IsEmpty());
       
  1144 				TRAP(leaveCode,errCode=testArray.Add(&dg1234));
       
  1145 			TEST(errCode==KErrNone);
       
  1146 			TEST(leaveCode==KErrNone);
       
  1147 			TEST(!testArray.IsEmpty());
       
  1148 				TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
       
  1149 			TEST(errCode==KErrNone);
       
  1150 			TEST(leaveCode==KErrNone);
       
  1151 				TRAP(leaveCode,errCode=testArray.Swap(&dgBADF00D_2));
       
  1152 			TEST(errCode==KErrNone);
       
  1153 			TEST(leaveCode==KErrNone);
       
  1154 				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
       
  1155 			TEST(errCode==KErrNone);
       
  1156 			TEST(leaveCode==KErrNone);
       
  1157 				//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
       
  1158 				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
       
  1159 			TEST(errCode==KErrNone);
       
  1160 			TEST(leaveCode==KErrNone);
       
  1161 			TEST(testArray.IsEmpty());
       
  1162 		break;
       
  1163 		//
       
  1164 		case 1:
       
  1165 			INFO_PRINTF1(_L("Sub test P1: AddTLC/SwapTLC: Cleanup item requires Commit."));
       
  1166 			
       
  1167 			rollBack1=NULL;
       
  1168 			TEST(testArray.IsEmpty());
       
  1169 			TRAP(leaveCode,
       
  1170 				rollBack1=testArray.AddTLC(&dg1234);
       
  1171 				CleanupStack::Check(rollBack1);
       
  1172 				testArray.CommitP(rollBack1);	
       
  1173 				)
       
  1174 			TEST(rollBack1!=NULL);
       
  1175 			TEST(leaveCode==KErrNone);
       
  1176 			TEST(!testArray.IsEmpty());
       
  1177 			rollBack1=NULL;
       
  1178 			TRAP(leaveCode,
       
  1179 				rollBack1=testArray.AddTLC(&dgBADF00D);
       
  1180 				CleanupStack::Check(rollBack1);
       
  1181 				testArray.CommitP(rollBack1);	
       
  1182 				)
       
  1183 			TEST(rollBack1!=NULL);
       
  1184 			TEST(leaveCode==KErrNone);
       
  1185 			rollBack1=NULL;
       
  1186 			TRAP(leaveCode,
       
  1187 				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
       
  1188 				CleanupStack::Check(rollBack1);
       
  1189 				testArray.CommitP(rollBack1);	
       
  1190 				)
       
  1191 			TEST(rollBack1!=NULL);
       
  1192 			TEST(leaveCode==KErrNone);
       
  1193 			rollBack1=NULL;
       
  1194 			TRAP(leaveCode,
       
  1195 				rollBack1=testArray.RemoveTLC(dg1234.Id());
       
  1196 				CleanupStack::Check(rollBack1);
       
  1197 				testArray.CommitP(rollBack1);	
       
  1198 				)
       
  1199 			TEST(rollBack1!=NULL);
       
  1200 			TEST(leaveCode==KErrNone);
       
  1201 			rollBack1=NULL;
       
  1202 				TRAP(leaveCode,
       
  1203 				rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());			
       
  1204 				CleanupStack::Check(rollBack1);
       
  1205 				testArray.CommitP(rollBack1);	
       
  1206 				)
       
  1207 			TEST(rollBack1!=NULL);
       
  1208 			TEST(leaveCode==KErrNone);
       
  1209 			rollBack1=NULL;
       
  1210 			TEST(testArray.IsEmpty());
       
  1211 		break;
       
  1212 		//
       
  1213 		case 2:
       
  1214 			INFO_PRINTF1(_L("Sub test P2: AddTLC/SwapTLC: Cleanup item gets executed."));
       
  1215 			
       
  1216 			rollBack1=NULL;
       
  1217 			TEST(testArray.IsEmpty());
       
  1218 			TRAP(leaveCode,
       
  1219 				rollBack1=testArray.AddTLC(&dg1234);
       
  1220 				User::Leave(1234);
       
  1221 				);	
       
  1222 			TEST(rollBack1!=NULL);
       
  1223 			TEST(leaveCode==1234);
       
  1224 			TEST(testArray.IsEmpty());
       
  1225 			rollBack1=NULL;
       
  1226 			CleanupStack::Check(markerCleanup);
       
  1227 			__UHEAP_CHECK(KArrayMemUseBaseline);
       
  1228 
       
  1229 			TRAP(leaveCode,	errCode=testArray.Add(&dgBADF00D));
       
  1230 			TEST(errCode==KErrNone);
       
  1231 			TEST(leaveCode==KErrNone);
       
  1232 			rollBack1=NULL;
       
  1233 			TRAP(leaveCode,
       
  1234 				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
       
  1235 				User::Leave(1234);
       
  1236 				);	
       
  1237 			TEST(rollBack1!=NULL);
       
  1238 			TEST(leaveCode==1234);
       
  1239 			TEST(!testArray.IsEmpty());
       
  1240 			rollBack1=NULL;
       
  1241 			TRAP(leaveCode,
       
  1242 				rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());
       
  1243 				TEST(testArray.IsEmpty());
       
  1244 				User::Leave(1234);
       
  1245 				);	
       
  1246 			TEST(rollBack1!=NULL);
       
  1247 			TEST(leaveCode==1234);
       
  1248 			TEST(!testArray.IsEmpty());
       
  1249 			
       
  1250 			
       
  1251 				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
       
  1252 			TEST(errCode==KErrNone);
       
  1253 			TEST(leaveCode==KErrNone);
       
  1254 			TEST(testArray.IsEmpty());
       
  1255 			rollBack1=NULL;
       
  1256 		break;
       
  1257 		//
       
  1258 		case 3:
       
  1259 			INFO_PRINTF1(_L("Sub test P3: AddLC/SwapLC: Cleanup item gets executed - doesn't leak"));
       
  1260 			TEST(testArray.IsEmpty());
       
  1261 			TRAP(leaveCode,
       
  1262 				testArray.AddLC(&dg1234);
       
  1263 				User::Leave(1234);
       
  1264 				);	
       
  1265 			TEST(leaveCode==1234);
       
  1266 			TEST(testArray.IsEmpty());
       
  1267 			rollBack1=NULL;
       
  1268 		__UHEAP_CHECK(KArrayMemUseBaseline);	  //because it threw it didn't leak
       
  1269 			
       
  1270 			//use my new method to add the object to be swapped out so no leak
       
  1271 			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
       
  1272 			TEST(errCode==KErrNone);
       
  1273 			TEST(leaveCode==KErrNone);
       
  1274 		__UHEAP_CHECK(KArrayMemUseBaseline);	  //new method doesn't leak.
       
  1275 			rollBack1=NULL;
       
  1276 			TRAP(leaveCode,
       
  1277 				errCode=testArray.SwapLC(&dgBADF00D_2);
       
  1278 				User::Leave(1234);
       
  1279 				);	
       
  1280 			TEST(errCode==KErrNone);
       
  1281 			TEST(leaveCode==1234);
       
  1282 			TEST(!testArray.IsEmpty());
       
  1283 			
       
  1284 				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
       
  1285 			TEST(errCode==KErrNone);
       
  1286 			TEST(leaveCode==KErrNone);
       
  1287 			TEST(testArray.IsEmpty());
       
  1288 			rollBack1=NULL;
       
  1289 		break;
       
  1290 		//
       
  1291 		case 4:
       
  1292 	
       
  1293 		//I don't really care whether the individual calls succeed or fail, 
       
  1294 		//just whether it leaks overall, and that the error codes correspond to no-action
       
  1295 		for (TInt faultRate=1;faultRate<5;faultRate++)
       
  1296 			{
       
  1297 			INFO_PRINTF2(_L("Sub test P4: Add/Swap: memory faulting %i"),faultRate);
       
  1298 			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
       
  1299 			TInt err1=KErrNone;
       
  1300 			rollBack1=NULL;
       
  1301 			TRAP(leaveCode,
       
  1302 				errCode=testArray.Add(&dg1234);
       
  1303 				)
       
  1304 			err1=errCode;
       
  1305 			__UHEAP_SETFAIL(RAllocator::ENone,0);
       
  1306 			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
       
  1307 			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
       
  1308 			rollBack1=NULL;
       
  1309 			TRAP(leaveCode,
       
  1310 				errCode=testArray.Swap(&dgBADF00D_2);
       
  1311 				)
       
  1312 			__UHEAP_SETFAIL(RAllocator::ENone,0);
       
  1313 			//If the first Add fails then the object should not be removed
       
  1314 			if (!err1)
       
  1315 				{
       
  1316 				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
       
  1317 				TEST(errCode==KErrNone);
       
  1318 				TEST(leaveCode==KErrNone);
       
  1319 				}
       
  1320 			//If the swap fails, then the add still needs to be removed
       
  1321 			//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
       
  1322 			TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
       
  1323 			TEST(errCode==KErrNone);
       
  1324 			TEST(leaveCode==KErrNone);
       
  1325 			TEST(testArray.IsEmpty());
       
  1326 			ResetArray(testArray);
       
  1327 			CleanupStack::Check(markerCleanup);
       
  1328 			__UHEAP_CHECK(0);
       
  1329 			}
       
  1330 		break;
       
  1331 		//
       
  1332 		case 5:
       
  1333 				
       
  1334 		//I don't really care whether the individual calls succeed or fail, 
       
  1335 		//just whether it leaks overall, and that the error codes correspond to no-action
       
  1336 		for (TInt faultRate=1;faultRate<5;faultRate++)
       
  1337 			{
       
  1338 			INFO_PRINTF2(_L("Sub test P5: AddTLC/SwapTLC: memory faulting %i"),faultRate);
       
  1339 			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
       
  1340 			TInt err1=KErrNone,err2=KErrNone,err3=KErrNone;
       
  1341 			rollBack1=NULL;
       
  1342 			TRAP(leaveCode,
       
  1343 				rollBack1=testArray.AddTLC(&dg1234);
       
  1344 				CleanupStack::Check(rollBack1);
       
  1345 				testArray.CommitP(rollBack1);	
       
  1346 				)
       
  1347 			err1=leaveCode;
       
  1348 			__UHEAP_SETFAIL(RAllocator::ENone,0);
       
  1349 			TRAP(leaveCode,errCode=testArray.Add(&dgBADF00D));
       
  1350 			__UHEAP_SETFAIL(RAllocator::EDeterministic,faultRate);
       
  1351 			rollBack1=NULL;
       
  1352 			TRAP(leaveCode,
       
  1353 				rollBack1=testArray.SwapTLC(&dgBADF00D_2);
       
  1354 				CleanupStack::Check(rollBack1);
       
  1355 				testArray.CommitP(rollBack1);	
       
  1356 				)
       
  1357 			//If the first Add fails then the object should not be removed
       
  1358 			if (!err1)
       
  1359 				{
       
  1360 				TRAP(leaveCode,
       
  1361 					rollBack1=testArray.RemoveTLC(dg1234.Id());			
       
  1362 					CleanupStack::Check(rollBack1);
       
  1363 					testArray.CommitP(rollBack1);	
       
  1364 					)
       
  1365 				err2=leaveCode;
       
  1366 				}
       
  1367 			//If the swap fails, then the add still needs to be removed
       
  1368 			//Note that it is the ID that matters here... dgBADF00D & dgBADF00D_2 have same id.
       
  1369 			TRAP(leaveCode,
       
  1370 					rollBack1=testArray.RemoveTLC(dgBADF00D_2.Id());
       
  1371 					CleanupStack::Check(rollBack1);
       
  1372 					testArray.CommitP(rollBack1);	
       
  1373 					)
       
  1374 			err3=leaveCode;
       
  1375 			
       
  1376 			
       
  1377 			__UHEAP_SETFAIL(RAllocator::ENone,0);
       
  1378 			//If the Removes failed then the object should be removed again
       
  1379 			if (err2)
       
  1380 				{
       
  1381 				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
       
  1382 				TEST(errCode==KErrNone);
       
  1383 				TEST(leaveCode==KErrNone);
       
  1384 				}
       
  1385 			if (err3)
       
  1386 				{
       
  1387 				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
       
  1388 				TEST(errCode==KErrNone);
       
  1389 				TEST(leaveCode==KErrNone);
       
  1390 				}
       
  1391 			TEST(testArray.IsEmpty());
       
  1392 			ResetArray(testArray);
       
  1393 			CleanupStack::Check(markerCleanup);
       
  1394 			__UHEAP_CHECK(0);
       
  1395 			}
       
  1396 				
       
  1397 		break;
       
  1398 		//
       
  1399 		case 6:
       
  1400 	//this set does leak:
       
  1401 	
       
  1402 		INFO_PRINTF1(_L("Sub test P6: AddLC/SwapLC: Cleanup item gets popped - unfixable leaks"));
       
  1403 			TEST(testArray.IsEmpty());
       
  1404 			TRAP(leaveCode,
       
  1405 				testArray.AddLC(&dg1234);
       
  1406 				CleanupStack::Pop();
       
  1407 				);	
       
  1408 			TEST(leaveCode==KErrNone);
       
  1409 			TEST(!testArray.IsEmpty());
       
  1410 		
       
  1411 		CleanupStack::Check(markerCleanup);
       
  1412 		__UHEAP_CHECK(KArrayMemUseBaseline+1);	
       
  1413 			
       
  1414 			TRAP(leaveCode,
       
  1415 				testArray.AddLC(&dgBADF00D);
       
  1416 				CleanupStack::Pop();
       
  1417 				)
       
  1418 			TEST(leaveCode==KErrNone);
       
  1419 		CleanupStack::Check(markerCleanup);
       
  1420 		__UHEAP_CHECK(KArrayMemUseBaseline+2);	
       
  1421 			rollBack1=NULL;
       
  1422 			TRAP(leaveCode,
       
  1423 				errCode=testArray.SwapLC(&dgBADF00D_2);
       
  1424 				CleanupStack::Pop();
       
  1425 				);	
       
  1426 			TEST(errCode==KErrNone);
       
  1427 			TEST(leaveCode==KErrNone);
       
  1428 			TEST(!testArray.IsEmpty());
       
  1429 				TRAP(leaveCode,errCode=testArray.Remove(dg1234.Id()));			
       
  1430 			TEST(errCode==KErrNone);
       
  1431 			TEST(leaveCode==KErrNone);
       
  1432 				TRAP(leaveCode,errCode=testArray.Remove(dgBADF00D_2.Id()));			
       
  1433 			TEST(errCode==KErrNone);
       
  1434 			TEST(leaveCode==KErrNone);
       
  1435 			TEST(testArray.IsEmpty());
       
  1436 			rollBack1=NULL;
       
  1437 			expectedLeakCount=3;
       
  1438 		break;
       
  1439 		//
       
  1440 		case 7:
       
  1441 			returnCode=EFalse;
       
  1442 		break;
       
  1443 		}
       
  1444 	ResetArray(testArray);
       
  1445 	CleanupStack::Check(markerCleanup);
       
  1446 	__UHEAP_CHECK(expectedLeakCount);
       
  1447 	__UHEAP_MARKENDC(expectedLeakCount);
       
  1448 	if (expectedLeakCount!=0)
       
  1449 		{	//Ensure that the leaked items are no longer associated with this debug level.
       
  1450 			//Note that __DbgSetAllocFail(FALSE,RAllocator::EReset,1) resets the debug level to 0, 
       
  1451 			//so levels can't be nested when using this call.
       
  1452 		__UHEAP_MARK;			
       
  1453 	    __UHEAP_TOTAL_RESET;	
       
  1454 		INFO_PRINTF2(_L("Anticipated %i leaks declassified"),expectedLeakCount);	//can't get here if wrong
       
  1455 		}
       
  1456 			
       
  1457 	CleanupStack::PopAndDestroy(markerCleanup);
       
  1458 	((CTWsGraphsStep*)iStep)->RecordTestResultL();
       
  1459 	return returnCode;
       
  1460 	}
       
  1461 
       
  1462 /**
       
  1463 	@param 	failcase		index to test to perform
       
  1464 	@param	aWrappedParams  represents inter-thread information when test is run on a private thread
       
  1465 				if aWrappedParams is NULL then the test is running on the main thread.
       
  1466 	@return true if there are higher-numbered fail cases.
       
  1467 
       
  1468    @SYMTestCaseID GRAPHICS-WSERV-NegAddSwapGDArray-0001
       
  1469    @SYMDEF			DEF093926  
       
  1470   
       
  1471    @SYMTestCaseDesc DEF093926: Check for stability of Add and Swap unwind methods in isolation,
       
  1472    					specifically checking that bad inputs are rejected gracefully.
       
  1473    		Note that this code is testing the functionality of a class internal to CWindowServer.
       
  1474    		At present CWindowServer presents just a simple shim on this class, 
       
  1475    		but if that implementation of  CWindowServer changes than this test will be redudant.
       
  1476    
       
  1477    @SYMTestPriority High
       
  1478    
       
  1479    @SYMTestStatus Implemented
       
  1480    
       
  1481    @SYMTestActions
       
  1482    
       
  1483 		Add/Swap: no Cleanup item - no leaks after Remove the added items
       
  1484    	    AddTLC/SwapTLC: Cleanup item requires Commit - check for no leaks after Remove.
       
  1485    	    AddTLC/SwapTLC: Cleanup item gets executed by forced Leave  - check for no leaks after.
       
  1486 		AddTLC, SwapTLC in allocation failure scenarios. Add/Swap don't allocate anything!
       
  1487 		obsoleted AddLC/SwapLC to ensure correct function when forced Leave - check for no leaks after
       
  1488 		obsoleted AddLC/SwapLC to ensure correct function. These will always leak in good case.
       
  1489 	Calls NegTestAddSwapGDArrayL.	
       
  1490 	case 1/2/3: Tests AddL, AddLC, AddTLC that a NULL input is rejected
       
  1491 	case 4/5/6: Tests SwapL, SwapLC, SwapTLC that a NULL input is rejected
       
  1492 	case 7/8/9: Tests AddL, AddLC, AddTLC that a repeat input is rejected
       
  1493 	case 10/11/12: Tests SwapL, SwapLC, SwapTLC that a non-repeat input is rejected
       
  1494    @SYMTestExpectedResults 
       
  1495  */
       
  1496 TBool CTWsGraphs::NegTestAddSwapGDArrayL(TInt failcase,WrapTestCall*aWrappedParams)
       
  1497 	{
       
  1498 	((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-NegAddSwapGDArray-0001"));
       
  1499 	_LIT(KCategory,"WsGraphicDrawer");
       
  1500 	if (!aWrappedParams)
       
  1501 		{
       
  1502 		INFO_PRINTF2(_L("NegTestAddSwapGDArrayL Negative sub test %i"),failcase);
       
  1503 		};
       
  1504     CWsGraphicDrawerArray testArray;
       
  1505     TGraphicDrawerId id1234=  	{  	1234,		EFalse    	};
       
  1506     TGraphicDrawerId idBADF00D=	{  	0xBADF00D,	EFalse    	};
       
  1507     WsGraphicDrawer dg1234;		
       
  1508     dg1234.ConstructL(id1234);
       
  1509     WsGraphicDrawer dgBADF00D;	
       
  1510     dgBADF00D.ConstructL(idBADF00D);
       
  1511     WsGraphicDrawer dgBADF00D_2;
       
  1512     dgBADF00D_2.ConstructL(idBADF00D);
       
  1513     CWsGraphicDrawerArray::XRollBackBase* rollBack1=NULL;
       
  1514  	TInt errCode=KErrAbort;
       
  1515 	TInt leaveCode=KErrNone;
       
  1516 	TBool	returnMoreTests=ETrue;
       
  1517 	DummyCleanup markerCleanup;
       
  1518 	TBool mayPanic=EFalse;
       
  1519 #ifdef __WINS__
       
  1520 	mayPanic=ETrue;
       
  1521 #endif
       
  1522 
       
  1523 	CleanupStack::PushL(markerCleanup);	 //This allows me to check the stack is clear!
       
  1524 	__UHEAP_MARK;
       
  1525 	
       
  1526 	switch (failcase)
       
  1527 		{
       
  1528 		case 1:	//NULL arg: expected result:  returns KErrArgument
       
  1529 	    	TRAP(leaveCode,
       
  1530 	    		errCode=testArray.Add(NULL);
       
  1531 	    		)
       
  1532 			TEST(leaveCode==KErrNone);
       
  1533 	    	ReportNegativeResultfail(__LINE__,errCode,KErrArgument);
       
  1534 	    break;
       
  1535 		case 2:	//NULL arg: expected result: throws KErrArgument
       
  1536 			TRAP(leaveCode,	
       
  1537 				rollBack1=testArray.AddTLC(NULL);
       
  1538 				TEST(EFalse);	//Should never get here!
       
  1539 				)
       
  1540 			TEST(rollBack1==NULL);
       
  1541 	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrArgument);
       
  1542 	    break;
       
  1543 		case 3:	//NULL arg: expected result: debug: panic. In release doesn't return any information!
       
  1544 			if (!aWrappedParams && mayPanic)
       
  1545 				{
       
  1546 			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
       
  1547 				}
       
  1548 			else
       
  1549 				{
       
  1550 				TRAP(leaveCode,
       
  1551 					testArray.AddLC(NULL);
       
  1552 					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
       
  1553 					);	
       
  1554 				TEST(leaveCode==1234);	//Panics before here in debug
       
  1555 				}
       
  1556 	    break;
       
  1557 		//
       
  1558 		case 4:	//NULL arg: expected result: returns KErrArgument
       
  1559 	    	TRAP(leaveCode,
       
  1560 	    		errCode=testArray.Swap(NULL)
       
  1561 	    		)
       
  1562 			TEST(leaveCode==KErrNone);
       
  1563 	    	ReportNegativeResultfail(__LINE__,errCode,KErrArgument);
       
  1564 	    break;
       
  1565 		case 5:	//expected result:  throws KErrArgument
       
  1566 			TRAP(leaveCode,
       
  1567 				rollBack1=testArray.SwapTLC(NULL);
       
  1568 				testArray.CommitP(rollBack1);
       
  1569 				)
       
  1570 			TEST(rollBack1==NULL);
       
  1571 	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrArgument);
       
  1572 	    break;
       
  1573 		case 6:	//NULL arg: expected result: debug: panic. In release doesn't return any information!
       
  1574 			if (!aWrappedParams && mayPanic)
       
  1575 				{
       
  1576 			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
       
  1577 				}
       
  1578 			else
       
  1579 				{
       
  1580 				TRAP(leaveCode,
       
  1581 					errCode=testArray.SwapLC(NULL);
       
  1582 					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
       
  1583 					);
       
  1584 				TEST(leaveCode==1234);	//Panics before here in debug
       
  1585 				TEST(errCode==KErrNotFound);
       
  1586 				}
       
  1587 		break;
       
  1588 		//
       
  1589 		case 7:	//Add overwrites: expected result: returns KErrAlreadyExists
       
  1590 	    	TRAP(leaveCode,
       
  1591 	    		errCode=testArray.Add(&dg1234);
       
  1592 	    		)
       
  1593 			TEST(errCode==KErrNone);
       
  1594 			TEST(leaveCode==KErrNone);
       
  1595 	    	TRAP(leaveCode,
       
  1596 	    		errCode=testArray.Add(&dg1234);		//oops! Already added!
       
  1597 	    		)
       
  1598 			TEST(leaveCode==KErrNone);
       
  1599 	    	ReportNegativeResultfail(__LINE__,errCode,KErrAlreadyExists);
       
  1600 	    break;
       
  1601 		case 8:	//Add overwrites: expected result:  throws KErrAlreadyExists
       
  1602 	    	TRAP(leaveCode,
       
  1603 	    		errCode=testArray.Add(&dg1234);
       
  1604 	    		)
       
  1605 			TEST(errCode==KErrNone);
       
  1606 			TEST(leaveCode==KErrNone);
       
  1607 			TRAP(leaveCode,	
       
  1608 				rollBack1=testArray.AddTLC(&dg1234);		//oops! Already added!
       
  1609 				testArray.CommitP(rollBack1);
       
  1610 				)
       
  1611 			TEST(rollBack1==NULL);
       
  1612 	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrAlreadyExists);
       
  1613 	    break;
       
  1614 		case 9:	//Add overwrites: expected result: debug: does not panic, but throws KErrAlreadyExists.
       
  1615 	    	TRAP(leaveCode,
       
  1616 	    		errCode=testArray.Add(&dg1234);
       
  1617 	    		)
       
  1618 			TEST(errCode==KErrNone);
       
  1619 			TEST(leaveCode==KErrNone);
       
  1620 			TRAP(leaveCode,
       
  1621 					testArray.AddLC(&dg1234);		//oops! Already added! Should leave.
       
  1622 					User::Leave(1234);  //Should leave before here! No leak if cleanup is taken.
       
  1623 				);	
       
  1624 	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrAlreadyExists);
       
  1625 	    break;
       
  1626 		//
       
  1627 		case 10:	//Swap empty slot: expected result:  returns KErrNotFound
       
  1628 	    	TRAP(leaveCode,
       
  1629 	    		errCode=testArray.Swap(&dg1234) 		//oops! Nothing to swap with!
       
  1630 	    		)
       
  1631 			TEST(leaveCode==KErrNone);
       
  1632 	    	ReportNegativeResultfail(__LINE__,errCode,KErrNotFound);
       
  1633 	    break;
       
  1634 		case 11:	//Swap empty slot: expected result: throws KErrNotFound
       
  1635 			TRAP(leaveCode,
       
  1636 				rollBack1=testArray.SwapTLC(&dg1234);		//oops! Nothing to swap with!
       
  1637 				testArray.CommitP(rollBack1);
       
  1638 				)
       
  1639 			TEST(rollBack1==NULL);
       
  1640 	    	ReportNegativeResultfail(__LINE__,leaveCode,KErrNotFound);
       
  1641 	    break;
       
  1642 		case 12:	//Swap empty slot: expected result: debug: panic. In release doesn't return any information!
       
  1643 			if (!aWrappedParams && mayPanic)
       
  1644 				{
       
  1645 			    LaunchNegTestCall(failcase,EWsGraphicDrawerPanicBadArgument,KCategory);
       
  1646 				}
       
  1647 			else
       
  1648 				{
       
  1649 				TRAP(leaveCode,
       
  1650 					errCode=testArray.SwapLC(&dg1234);		//oops! Nothing to swap with!
       
  1651 					User::Leave(1234);  //Panics before here in debug. No leak if cleanup is taken.
       
  1652 					);	
       
  1653 				TEST(leaveCode==1234);			//Panics before here in debug
       
  1654 				TEST(errCode==KErrNotFound);	//Panics before here in debug
       
  1655 				}
       
  1656 	    break;
       
  1657 	    
       
  1658 		//
       
  1659 		default:
       
  1660 			returnMoreTests=EFalse;
       
  1661 		}
       
  1662 	ResetArray(testArray);
       
  1663 	CleanupStack::Check(markerCleanup);
       
  1664 	__UHEAP_CHECK(0);
       
  1665 	__UHEAP_MARKENDC(0);
       
  1666     testArray.Close();
       
  1667 //    CWsGraphicDrawerArray::testArrayValidator::ResetArray(&testArray);
       
  1668 	CleanupStack::PopAndDestroy(markerCleanup);
       
  1669 	return returnMoreTests;
       
  1670 	}
       
  1671 
       
  1672 /**
       
  1673    @SYMTestCaseID 	GRAPHICS-WSERV-LeakInService-0001
       
  1674    @SYMDEF			DEF093926  
       
  1675    @SYMTestCaseDesc Check for leaks over repeated re-assignments.
       
  1676    
       
  1677    @SYMTestPriority High
       
  1678    
       
  1679    @SYMTestStatus Implemented
       
  1680    
       
  1681    @SYMTestActions 
       
  1682    Repeatedly create the same bitmap instance
       
  1683    After a few initial wobbles in the server-side HeapCount it should not increase
       
  1684    5 calls are made without checking the level, then 5 more check the level.
       
  1685    Note that as we are testing the main server heap, 
       
  1686    other threads may interrupt and perform operations that change the memory figures.
       
  1687    
       
  1688    @SYMTestExpectedResults The CWsGraphicBitmap objects are created and no leaks are reported.
       
  1689  */	
       
  1690 void CTWsGraphs::DoTestLeakInServiceL()
       
  1691 	{
       
  1692 		INFO_PRINTF1(_L("DoTestLeakInServiceL"));
       
  1693 		const TInt prepCount=5;
       
  1694 		const TInt testCount=5;
       
  1695 		
       
  1696 				
       
  1697 		TUid uid1 = {0x10000001};
       
  1698 		TUid uid2 = {0x10000002};
       
  1699 		 
       
  1700 		TWsGraphicId twsGraphicId1(uid1);
       
  1701 		TEST(twsGraphicId1.Uid()==uid1);
       
  1702 		
       
  1703 		TWsGraphicId twsGraphicId2(uid2);
       
  1704 		TEST(twsGraphicId2.Uid()==uid2);
       
  1705 		
       
  1706 		TWsGraphicId twsGraphicId3(twsGraphicId2);
       
  1707 		TEST(twsGraphicId3.Uid()==uid2);
       
  1708 		
       
  1709 		TWsGraphicId twsGraphicId4(1);
       
  1710 		twsGraphicId4.Set(uid1);
       
  1711 		TEST(twsGraphicId4.Uid()==uid1);		
       
  1712 
       
  1713 		TSize screenSize = TheClient->iScreen->SizeInPixels();
       
  1714 		
       
  1715 		__UHEAP_RESET;
       
  1716 		__UHEAP_MARK;
       
  1717 		// Create local shared CWsGraphicBitmap	
       
  1718 		// Repeat operation for any sign of memory leak...	
       
  1719 		CFbsBitmap bitmap2;
       
  1720 		CFbsBitmap mask2;		
       
  1721 		
       
  1722 		bitmap2.Create(screenSize,TheClient->iScreen->DisplayMode());
       
  1723 		mask2.Create(bitmap2.SizeInPixels(),TheClient->iScreen->DisplayMode());
       
  1724 			
       
  1725 		TInt c0=TheClient->iWs.HeapCount();
       
  1726 		CWsGraphicBitmap* bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
       
  1727 		for (TInt i=0;i<prepCount;i++)
       
  1728 			{
       
  1729 			//TInt c2=TheClient->iWs.HeapCount();
       
  1730 			delete bTestX; 								
       
  1731 			//TInt c3=TheClient->iWs.HeapCount();
       
  1732 			bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
       
  1733 			//TInt c4=TheClient->iWs.HeapCount();
       
  1734 			}
       
  1735 		// Give WSERV a chance to settle.
       
  1736 		TheClient->iWs.Finish();
       
  1737 		User::After (1000000); //1s
       
  1738 		
       
  1739 		TInt c1=TheClient->iWs.HeapCount();
       
  1740 		TInt failures=0;
       
  1741 		for (TInt i=0;i<testCount;i++)
       
  1742 			{
       
  1743 			TInt c2=TheClient->iWs.HeapCount();
       
  1744 			delete bTestX;
       
  1745 			//TInt c3=TheClient->iWs.HeapCount();
       
  1746 			//The heap count doesn't go down after delete operation
       
  1747 			//because the delete message is buffered by the server, because it does not have a return value.
       
  1748 			//Aparrently, although CWsGraphicBitmap and TheClient terminate at the same server,
       
  1749 			//and use the same general heap (I have tested this under debug),
       
  1750 			//they do not share the same session, so flushing TheClient does not effect CWsGraphicBitmap
       
  1751 			bTestX = CWsGraphicBitmap::NewL(twsGraphicId2.Uid(), &bitmap2,&mask2);		
       
  1752 			
       
  1753 			// Give WSERV a chance to settle.
       
  1754 			TheClient->iWs.Finish();
       
  1755 			User::After (1000000); //1s
       
  1756 
       
  1757 			TInt c4=TheClient->iWs.HeapCount();   
       
  1758 			//Can compare immediately after allocation as the server doesn't buffer the create command.
       
  1759 			if (!(c2==c4))
       
  1760 				{
       
  1761 				if (c4 > c2) // only fail the test if the count has increased
       
  1762 					{
       
  1763 					failures++;
       
  1764 					}
       
  1765 				INFO_PRINTF2(_L("Server Heap count change accross delete/new = %i"),c4-c2);
       
  1766 				}
       
  1767 			}
       
  1768 		// Outside of main loop to avoid client/wserv interaction during test.
       
  1769 		TEST(failures==0);
       
  1770 		TInt c5=TheClient->iWs.HeapCount();
       
  1771 		TEST((c1-c5)/testCount==0);	   //If every call leaked.
       
  1772 		if ((c1-c5)/testCount)
       
  1773 			{
       
  1774 			INFO_PRINTF3(_L("Server Heap count change accross %i delete/new cycles = %i"),testCount,c5-c1);
       
  1775 			INFO_PRINTF3(_L("Before %i / After %i"),c1,c5);
       
  1776 			}
       
  1777 		
       
  1778 		delete bTestX; 
       
  1779 		
       
  1780 		__UHEAP_CHECK(0);
       
  1781 		__UHEAP_MARKEND;
       
  1782 		
       
  1783 	}
       
  1784 /**
       
  1785  @SYMTestCaseID				GRAPHICS-WSERV-0381 
       
  1786  @SYMDEF					DEF095063
       
  1787  @SYMTestCaseDesc			Test case for INC098114 CWsGraphicDrawer::SendMessage panics window server
       
  1788  @SYMTestPriority			Medium
       
  1789  @SYMTestStatus				Implemented
       
  1790  @SYMTestActions			Enable the test flag and reproduce the defect
       
  1791 							Action step:
       
  1792 							-Instruct plugin to register event handler
       
  1793 							-Draw fullscreen window (plugin will receive window visibility changed event)
       
  1794 							-Set the test flag 
       
  1795 							-Query visibility region from plugin side
       
  1796 							-Instruct plugin to unregister event handler
       
  1797 							-Destroy fullscreen window (plugin will not receive window visibility changed event)
       
  1798 						
       
  1799  @SYMTestExpectedResults	wserv should not panic with the fix
       
  1800 */	
       
  1801 
       
  1802 TestState CTWsGraphs::TestSuccessiveMessageL()
       
  1803 	{
       
  1804 	if (iSubState==0)
       
  1805 		{
       
  1806 		_LIT(KTestSuccessiveMessage, "TestSuccessiveMessage");
       
  1807 		INFO_PRINTF1(KTestSuccessiveMessage);
       
  1808 
       
  1809 		++iSubState;
       
  1810 		iListen->Enable(ETrue);
       
  1811 		CreateWindowL();
       
  1812 		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
       
  1813 		//Set the test flag to enable the reproduction of defect
       
  1814 		iListen->SetTestFlag();
       
  1815 		iListen->QueryPlugin(iListenInfo);
       
  1816 		iListen->Enable(EFalse);
       
  1817 		DestroyWindowL();
       
  1818 		return EWait;
       
  1819 		}
       
  1820 
       
  1821 	++(iTest->iState);
       
  1822 	iSubState = 0;
       
  1823 	return ENext;
       
  1824 	}
       
  1825 
       
  1826 TestState CTWsGraphs::TestWindowGroupChangeL()
       
  1827 	{
       
  1828 	if (iSubState==0)
       
  1829 		{
       
  1830 		_LIT(KTestWindowGroupChange, "TestWindowGroupChange");
       
  1831 		INFO_PRINTF1(KTestWindowGroupChange);
       
  1832 
       
  1833 		++iSubState;
       
  1834 		iListen->Enable(ETrue);
       
  1835 		CreateWindowL();
       
  1836 		Mem::FillZ(&iListenInfo, sizeof(TListenerInfo));
       
  1837 		iListen->QueryPlugin(iListenInfo);
       
  1838 		return EWait;
       
  1839 		}
       
  1840 
       
  1841 	if (iSubState==1)
       
  1842 		{
       
  1843 		++iSubState;
       
  1844 		iOriginalWindowGroupId = iListenInfo.iWindowGroupId;
       
  1845 		iNewWin = CCrWin::NewL(iTest->iScreenNumber, ETrue);
       
  1846 		iListen->QueryPlugin(iListenInfo);
       
  1847 		return EWait;
       
  1848 		}
       
  1849 
       
  1850 	TEST(iListenInfo.iWindowGroupId != iOriginalWindowGroupId);
       
  1851 	
       
  1852 	delete iNewWin;
       
  1853 	iNewWin = NULL;
       
  1854 	iListen->Enable(EFalse);
       
  1855 	DestroyWindowL();
       
  1856 	++(iTest->iState);
       
  1857 	iSubState = 0;
       
  1858 	return ENext;
       
  1859 	}
       
  1860 
       
  1861 /**
       
  1862  @SYMTestCaseID				GRAPHICS-WSERV-0382
       
  1863  @SYMDEF 					INC085451
       
  1864  @SYMTestCaseDesc			Test Animation frame rate
       
  1865  @SYMTestPriority			Medium
       
  1866  @SYMTestStatus				Implemented
       
  1867  @SYMTestActions			Simulate an Animation artwork by calling DrawWsGraphic and DoDraw.
       
  1868 							Action step:
       
  1869 							-Calls DrawWsGraphic for two different animations with different frame rates
       
  1870 							-Retrieve the frame count for two differnt frames per seconds
       
  1871 							-Test the two frame rate shouldn't be same.
       
  1872 
       
  1873  @SYMTestExpectedResults	Animation Frame rate should be different for different frames per second
       
  1874 */
       
  1875 TestState CTWsGraphs::TestFrameRateL()
       
  1876 	{
       
  1877 	//Check for Transparency enabled in wsini.ini
       
  1878 	if (TransparencySupportedL()==KErrNotSupported)
       
  1879 		{
       
  1880 		++(iTest->iState);
       
  1881 		return ENext;
       
  1882 		}
       
  1883 
       
  1884 	// flush transparent window destruction created in TransparencySupportedL before
       
  1885 	// proceeding with the test
       
  1886 	TheClient->iWs.Flush();
       
  1887 
       
  1888 	//Here 	iSubState is 0, when this functions executes first time 
       
  1889 	//		iSubState is 1 means the call is from a callback function.
       
  1890 	if(iSubState == 0)
       
  1891 		{
       
  1892 		_LIT(KTestFrameRate, "TestFrameRate");
       
  1893 		INFO_PRINTF1(KTestFrameRate);
       
  1894 
       
  1895 		++iSubState;
       
  1896 		iTestframerate = CGraphicTestFrameRate::NewL(iTest->iScreenNumber);
       
  1897 
       
  1898 		//Set the callback function
       
  1899 		iTestframerate->SetCallBack(TCallBack(CTWsGraphs::PluginCallBack,this));
       
  1900 
       
  1901 		//Create the window and call the graphic animation
       
  1902 		CreateWindowL(EFalse);
       
  1903 		iWin->DrawGraphic(iTestframerate->Id().Id());
       
  1904 		return EWait;
       
  1905 		}
       
  1906 
       
  1907 	//PeterI wait a while for animations to redraw then query the plugin
       
  1908 	User::After(2000000);
       
  1909 	TheClient->iWs.Flush();
       
  1910 	TheClient->WaitForRedrawsToFinish();
       
  1911 	TheClient->iWs.Finish();
       
  1912 
       
  1913 	//Invoke the plug-in and get the counter value
       
  1914 	Mem::FillZ(&iAnimCount, sizeof(TAnimRate));
       
  1915 
       
  1916 	iTestframerate->QueryPlugin(iAnimCount);
       
  1917 	TheClient->iWs.Flush();
       
  1918 	TheClient->WaitForRedrawsToFinish();
       
  1919 	TheClient->iWs.Finish();
       
  1920 
       
  1921 	//Compare and test the total frame rate for two different frame counts....
       
  1922 	TEST((iAnimCount.iAnim1>0 && iAnimCount.iAnim2>0) && iAnimCount.iAnim1 !=iAnimCount.iAnim2);
       
  1923 	if(iSubState == 1)
       
  1924 		{
       
  1925 		DestroyWindowL();
       
  1926 		delete iTestframerate;
       
  1927 		}
       
  1928 	++(iTest->iState);
       
  1929 	iSubState = 0;
       
  1930 	return ENext;
       
  1931 	}
       
  1932 
       
  1933 /**
       
  1934  @SYMTestCaseID				GRAPHICS-WSERV-0438 
       
  1935  @SYMDEF					INC103472
       
  1936  @SYMTestCaseDesc			CRedrawRegion::ContainsDrawers does not look for all drawers 
       
  1937  @SYMTestPriority			Medium
       
  1938  @SYMTestStatus				Implemented
       
  1939  @SYMTestActions			Create ECom-plugins to enable the scenario, in which there is one simple and one container drawer. 
       
  1940  							In the container drawer, two other simple drawers are enabled. Each drawer draws a coloured ellipse.
       
  1941  							In this case, when the contained drawer is requested to change the colour of the ellipse, the screen will not be updated
       
  1942  							without the fix.  
       
  1943  							Action step:
       
  1944 							-Create four CRP graphics.
       
  1945 							-Call the simple drawer and container drawer to draw ellipses. The container drawer
       
  1946 							 also enables two other simple drawers to draw ellipses in different colors.
       
  1947 							-Update the color of each ellipse in turn. 
       
  1948 							-Check that the screen display is as required.						
       
  1949  @SYMTestExpectedResults	The colour of each ellipse residing in the drawers is successfully updated. Those for the contained drawers wont be updated without the fix. 
       
  1950 */	
       
  1951 void CTWsGraphs::TestNestedDrawerCRP()
       
  1952 	{
       
  1953 	_LIT(KTestContainDrawer, "Test INC103472: A Contained Drawer");
       
  1954 	INFO_PRINTF1(KTestContainDrawer);
       
  1955 
       
  1956 	RWindow window1(TheClient->iWs);
       
  1957 	CleanupClosePushL(window1);
       
  1958 	User::LeaveIfError(window1.Construct(*TheClient->iGroup->GroupWin(), ENullWsHandle));
       
  1959 	
       
  1960 	window1.EnableRedrawStore(ETrue);	// Force to enable the redraw storing
       
  1961 	window1.SetRequiredDisplayMode(EColor256);	 // Do not set window size here to avoid hardware test failure
       
  1962 	window1.SetBackgroundColor(KRgbDarkGreen);
       
  1963 	window1.Activate();
       
  1964 	
       
  1965 	// A simple graphic
       
  1966 	CWsSimpleGraphicBitmap* wsGraphic1 = CWsSimpleGraphicBitmap::NewL(KSimpleDrawerInterfaceId);
       
  1967 	CleanupStack::PushL(wsGraphic1);
       
  1968 	// A container graphic
       
  1969 	CWsContainGraphicBitmap* wsGraphic2 = CWsContainGraphicBitmap::NewL(KContainDrawerInterfaceId);
       
  1970 	CleanupStack::PushL(wsGraphic2);
       
  1971 	// A contained graphic residing in the container graphic wsGraphic2 
       
  1972  	CWsSimpleGraphicBitmap* wsGraphic3 = CWsInvisibleGraphicBitmap1::NewL(KInvisibleDrawerInterfaceId1);
       
  1973  	CleanupStack::PushL(wsGraphic3);
       
  1974 	// A contained graphic residing in the container graphic wsGraphic2
       
  1975  	CWsSimpleGraphicBitmap* wsGraphic4 = CWsInvisibleGraphicBitmap2::NewL(KInvisibleDrawerInterfaceId2);
       
  1976  	CleanupStack::PushL(wsGraphic4);
       
  1977 
       
  1978     window1.Invalidate();
       
  1979 	window1.BeginRedraw();
       
  1980 	TheClient->iGc->Activate(window1);
       
  1981 	TheClient->iGc->Clear();
       
  1982 	// Call CRP drawer to draw the coloured ellipses	
       
  1983 	TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),TRect(TPoint(20,20),TSize(300,100)));
       
  1984 	TheClient->iGc->DrawWsGraphic(wsGraphic2->Id(),TRect(TPoint(20,100),TSize(300,100)));	
       
  1985 
       
  1986     TheClient->iGc->Deactivate();
       
  1987 	window1.EndRedraw();
       
  1988 	TheClient->Flush();			   
       
  1989 	
       
  1990 	// Update the colour of four ellipses residing in four CRP drawers. 
       
  1991 	TInt err = wsGraphic1->UpdateColor(KRgbRed);
       
  1992 	TEST(KErrNone == err);
       
  1993 	err = wsGraphic2->UpdateColor(KRgbDarkBlue);
       
  1994 	TEST(KErrNone == err);
       
  1995 	// If the fix is not inserted, the colour of the third and fourth ellipses residing in the contained drawers wont be updated
       
  1996 	err = wsGraphic3->UpdateColor(KRgbDarkMagenta);
       
  1997 	TEST(KErrNone == err);
       
  1998 	err = wsGraphic4->UpdateColor(KRgbDarkCyan);	  //won't change the displayed color if there is a right place for flush()
       
  1999 	TEST(KErrNone == err);
       
  2000 	
       
  2001 	TheClient->Flush();
       
  2002  	// Force some delays to wait until the color change
       
  2003     User::After(2000000);
       
  2004     // Test whether the screen content is changed as required
       
  2005     CheckResult();
       
  2006    	CleanupStack::PopAndDestroy(5,&window1);
       
  2007 	}
       
  2008 
       
  2009 // Check the screen display with the reference bitmap to ensure the color to be updated correctly
       
  2010 void CTWsGraphs::CheckResult()
       
  2011 	{
       
  2012     TSize size = TSize(320,200);//The maximum size of the screen content we are looking at
       
  2013 
       
  2014     // Create a reference bitmap
       
  2015     CFbsBitmap* bitmapRef = new(ELeave) CFbsBitmap;
       
  2016    	CleanupStack::PushL(bitmapRef);
       
  2017 	User::LeaveIfError(bitmapRef->Create(size, EColor256));
       
  2018 	CFbsBitGc* gc;
       
  2019 	CFbsBitmapDevice* bitmapDev = CFbsBitmapDevice::NewL(bitmapRef);
       
  2020 	TEST(bitmapDev!=NULL);
       
  2021    	CleanupStack::PushL(bitmapDev);
       
  2022 	User::LeaveIfError(bitmapDev->CreateContext(gc));
       
  2023    	CleanupStack::PushL(gc);
       
  2024 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  2025 	gc->SetBrushColor(KRgbDarkGreen);
       
  2026 	gc->Clear(TRect(TPoint(0,0), size));//background dark green
       
  2027 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  2028     gc->SetBrushColor(KRgbRed);
       
  2029 	gc->DrawEllipse(TRect(TPoint(20,20),TSize(300,100)));  //map to the simple drawer
       
  2030 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  2031 	gc->SetBrushColor(KRgbDarkBlue);
       
  2032 	gc->DrawEllipse(TRect(TPoint(20,100),TSize(300,100)));	//map to the container drawer
       
  2033 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  2034 	gc->SetBrushColor(KRgbDarkMagenta);
       
  2035 	gc->DrawEllipse(TRect(TPoint(100,150),TSize(50,50)));	//map to the contained drawer
       
  2036 	gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  2037  	gc->SetBrushColor(KRgbDarkCyan);
       
  2038 	gc->DrawEllipse(TRect(TPoint(200,150),TSize(50,50)));	//map to the contained drawer
       
  2039     TInt bitmapHeight = bitmapRef->SizeInPixels().iHeight;
       
  2040 	TInt bitmapWidth = bitmapRef->SizeInPixels().iWidth;
       
  2041   
       
  2042    	// Copy the screen content to bitmap
       
  2043 	INFO_PRINTF1(_L("Capture screen content."));
       
  2044 	CFbsBitmap* screenBitmap = new(ELeave) CFbsBitmap();
       
  2045 	CleanupStack::PushL(screenBitmap);
       
  2046 	User::LeaveIfError(screenBitmap->Create(size, TheClient->iScreen->DisplayMode()));
       
  2047 	TRect rct = TRect(TPoint(0,0), size);
       
  2048 	User::LeaveIfError(TheClient->iScreen->CopyScreenToBitmap(screenBitmap,rct));
       
  2049 
       
  2050 	// Compare the displayed bitmap against the reference one
       
  2051 	INFO_PRINTF1(_L("Compare the displayed bitmap against the expected one."));
       
  2052 	TInt lineLength=bitmapRef->ScanLineLength(bitmapWidth, EColor256);
       
  2053 	HBufC8* compareLineBuf=HBufC8::NewLC(lineLength);
       
  2054 	TPtr8 compareLinePtr(compareLineBuf->Des());
       
  2055 	HBufC8* screenLineBuf=HBufC8::NewLC(lineLength);
       
  2056 	TPtr8 screenLinePtr(screenLineBuf->Des());
       
  2057 	for (TInt index=0; index<bitmapHeight; index++)
       
  2058 		{
       
  2059 		bitmapRef->GetScanLine(compareLinePtr, TPoint(0,index), bitmapWidth, EColor256);
       
  2060 		screenBitmap->GetScanLine(screenLinePtr, TPoint(0,index),bitmapWidth, EColor256);
       
  2061 		TInt compareResult=compareLinePtr.Compare(screenLinePtr);
       
  2062 		if (compareResult!=0)
       
  2063 			{
       
  2064 			INFO_PRINTF2(_L("Scanline compare failed: %d"),index);
       
  2065 			TEST(EFalse);
       
  2066 			break;
       
  2067 			}
       
  2068 		}
       
  2069 	CleanupStack::PopAndDestroy(6,bitmapRef);  
       
  2070 
       
  2071 	} 
       
  2072 
       
  2073 void ResetScreenMode(TAny* aAny)
       
  2074 	{
       
  2075 	CWsScreenDevice* screen=static_cast<CWsScreenDevice*>(aAny);
       
  2076 	screen->SetScreenMode(0);
       
  2077 	screen->SetAppScreenMode(0);
       
  2078 	}
       
  2079 
       
  2080 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
  2081 
       
  2082 void CTWsGraphs::TestScreenModeChangeL()
       
  2083 	{
       
  2084 	_LIT(KLog,"Screen Doesn't match bitmap.  Size=(%d,%d) winSizeMode=%d redrawMode=%d modeIndex=%d");
       
  2085 // A simple CRP graphic to draw in the test
       
  2086 	CWsSimpleGraphicBitmap* wsGraphic1=CWsSimpleGraphicBitmap::NewL(KSimpleDrawerInterfaceId);
       
  2087 	CleanupStack::PushL(wsGraphic1);
       
  2088 	RWindow testWin(TheClient->iWs);
       
  2089 	CleanupClosePushL(testWin);
       
  2090 	User::LeaveIfError(testWin.Construct(*TheClient->iGroup->GroupWin(),0xbadbad));
       
  2091 	testWin.SetRequiredDisplayMode(EColor64K);
       
  2092 	testWin.Activate();
       
  2093 // Cleanup display mode by setting back to 0 if we leave in the tests
       
  2094 	CleanupStack::PushL(TCleanupItem(ResetScreenMode,TheClient->iScreen));
       
  2095 	TInt numScreenModes=TheClient->iScreenModes.Count();
       
  2096 	TBool match;
       
  2097 
       
  2098 	for(TInt winSizeMode=0;winSizeMode<2;winSizeMode++)
       
  2099 		{ // Two size modes, fullScreen and non-full screen
       
  2100 		for(TInt redrawMode=0;redrawMode<2;redrawMode++)
       
  2101 			{ // Two redraw modes to test drawing inside and outside of a redraw.
       
  2102 			const TBool drawInsideRedraw=(redrawMode==0);
       
  2103 			for(TInt modeIndex=0;modeIndex<numScreenModes;modeIndex++)
       
  2104 				{
       
  2105 				const TInt screenMode=TheClient->iScreenModes[modeIndex];
       
  2106 				const TPoint origin=TheClient->iScreen->GetScreenModeScaledOrigin(screenMode);
       
  2107 				if (origin.iX!=0 || origin.iY!=0)
       
  2108 					continue;
       
  2109 				// Enable redirection before changing screen mode as this is what we are testing
       
  2110 				iRedir->Redirect(CWsRedir::EFrontBuffer, ETrue);
       
  2111 				TheClient->iScreen->SetAppScreenMode(screenMode);
       
  2112 				TheClient->iScreen->SetScreenMode(screenMode);
       
  2113 
       
  2114 				TPixelsAndRotation sizeAndRotation;
       
  2115 				TheClient->iScreen->GetDefaultScreenSizeAndRotation(sizeAndRotation);
       
  2116 //
       
  2117 				TSize screenSize(TheClient->iScreen->SizeInPixels());
       
  2118 				if(sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationRotated90 || 
       
  2119 						sizeAndRotation.iRotation == CFbsBitGc::EGraphicsOrientationRotated270)
       
  2120 					{
       
  2121 					screenSize.iWidth = Min(screenSize.iWidth, 240);//to make sure we won't exceed physical screen size
       
  2122 					}
       
  2123 				TSize winSize(screenSize);
       
  2124 				TPoint winPos;
       
  2125 				if (winSizeMode==1)
       
  2126 					{
       
  2127 					winSize.iWidth=winSize.iWidth*2/3;
       
  2128 					winSize.iHeight=winSize.iHeight*3/4;
       
  2129 					winPos.iX=(screenSize.iWidth-winSize.iWidth)/4;
       
  2130 					winPos.iY=(screenSize.iHeight-winSize.iHeight)*3/4;
       
  2131 					}
       
  2132 				testWin.SetExtent(winPos,winSize);
       
  2133 				TSize halfSize(winSize.iWidth/2,winSize.iHeight);
       
  2134 				TRect leftHalf(halfSize);
       
  2135 				TRect rightHalf(TPoint(halfSize.iWidth,0),halfSize);
       
  2136 				TRect leftEllipse(leftHalf);
       
  2137 				leftEllipse.Shrink(4,4);
       
  2138 				TRect rightEllipse(rightHalf);
       
  2139 				rightEllipse.Shrink(4,4);
       
  2140 				// Draw half the screen with redirection on, should only go to redirection test bitmap
       
  2141 				// Then draw again with redirection off, this time should go to the screen
       
  2142 				// The two steps are drawn with the color of the left/right rectangles swapped.
       
  2143 				for(TInt drawStep=0;drawStep<2;drawStep++)
       
  2144 					{
       
  2145 					TRgb leftColor;
       
  2146 					TRgb rightColor;
       
  2147 					if (drawStep==0)
       
  2148 						{
       
  2149 						leftColor=KRgbGreen;
       
  2150 						rightColor=KRgbRed;
       
  2151 						}
       
  2152 					else
       
  2153 						{ // Turn re-direction off for second time around loop
       
  2154 						iRedir->Redirect(CWsRedir::EFrontBuffer, EFalse);
       
  2155 						leftColor=KRgbRed;
       
  2156 						rightColor=KRgbGreen;
       
  2157 						}
       
  2158 					testWin.Invalidate();
       
  2159 					testWin.BeginRedraw();
       
  2160 					if (!drawInsideRedraw)
       
  2161 						testWin.EndRedraw();
       
  2162 					CWindowGc* testWinGc=TheClient->iGc;
       
  2163 					testWinGc->Activate(testWin);
       
  2164 					testWinGc->SetBrushColor(leftColor);
       
  2165 					testWinGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
       
  2166 					testWinGc->DrawRect(leftHalf);
       
  2167 					// Call CRP drawer to draw the coloured ellipses
       
  2168 					TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),leftEllipse);
       
  2169 					testWinGc->SetBrushColor(rightColor);
       
  2170 					testWinGc->DrawRect(rightHalf);
       
  2171 					TheClient->iGc->DrawWsGraphic(wsGraphic1->Id(),rightEllipse);
       
  2172 					testWinGc->Deactivate();
       
  2173 					if (drawInsideRedraw)
       
  2174 						testWin.EndRedraw();
       
  2175 					TheClient->iWs.Flush();
       
  2176 					}
       
  2177 				// We now check that the left rect of the re-directed drawing matches the right half
       
  2178 				// of the on-screen drawing
       
  2179 				CFbsBitmap* screenCopy=new(ELeave) CFbsBitmap;
       
  2180 				CleanupStack::PushL(screenCopy);
       
  2181 				User::LeaveIfError(screenCopy->Create(screenSize, EColor64K));
       
  2182 				TheClient->iScreen->CopyScreenToBitmap(screenCopy);
       
  2183 				match=CompareBitmapArea16Bpp(iFrontCopy,winPos,screenCopy,TPoint(winPos.iX+rightHalf.iTl.iX,winPos.iY),halfSize);
       
  2184 				TEST(match);
       
  2185 				if (!match)
       
  2186 					LOG_MESSAGE6(KLog,screenSize.iWidth,screenSize.iHeight,winSizeMode,redrawMode,modeIndex);
       
  2187 				// As a double check also check the right half of the off-screen drawing matches the
       
  2188 				// on-screen left half.
       
  2189 				match=CompareBitmapArea16Bpp(iFrontCopy,TPoint(winPos.iX+rightHalf.iTl.iX,winPos.iY),screenCopy,winPos,halfSize);
       
  2190 				TEST(match);
       
  2191 				if (!match)
       
  2192 					LOG_MESSAGE6(KLog,screenSize.iWidth,screenSize.iHeight,winSizeMode,redrawMode,modeIndex);
       
  2193 				CleanupStack::PopAndDestroy(screenCopy);
       
  2194 				}
       
  2195 			}
       
  2196 		}
       
  2197  	CleanupStack::PopAndDestroy(3,wsGraphic1);
       
  2198  	
       
  2199 	TEST(iNotify1->iResult);
       
  2200 	if(iNotify1->iResult==EFalse)
       
  2201 		{
       
  2202 		INFO_PRINTF1(iNotify1->iError);
       
  2203 		}
       
  2204 	TEST(iNotify2->iResult);
       
  2205 	if(iNotify1->iResult==EFalse)
       
  2206 		{
       
  2207 		INFO_PRINTF1(iNotify2->iError);
       
  2208 		}
       
  2209 	}
       
  2210 
       
  2211 #endif // TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
  2212 
       
  2213 /**
       
  2214 @SYMTestCaseID 		GRAPHICS-WSERV-0443
       
  2215 
       
  2216 @SYMDEF     		INC109263
       
  2217 
       
  2218 @SYMTestCaseDesc	TWindowServerEvent::NotifyDrawer can refer to a deleted array index causing a crash
       
  2219 
       
  2220 @SYMTestPriority 	High
       
  2221 
       
  2222 @SYMTestStatus		Implemented
       
  2223 
       
  2224 @SYMTestActions		Cause an event that will generate the following behaviour through TWindowServerEvent::NotifyDrawer()
       
  2225 		
       
  2226 					The for loop performs the following:
       
  2227 					0) Drawer handler 1: Remove handle 1 ; 					Drawer handler 2: Do nothing
       
  2228 					1) Drawer handler 1: Remove handle 1,Add handle 1 ;		Drawer handler 2: Do nothing
       
  2229 					2) Drawer handler 1: Add handle 1 ; 					Drawer handler 2: Do nothing
       
  2230 					3) Drawer handler 1: Remove handle 2 ; 					Drawer handler 2: Do nothing
       
  2231 					4) Drawer handler 1: Remove handle 2,Add handle 2 ; 	Drawer handler 2: Do nothing
       
  2232 					5) Drawer handler 1: Add handle 2 ; 					Drawer handler 2: Do nothing
       
  2233 					6) Drawer handler 1: Remove handle 1,Remove handle 2 ; 	Drawer handler 2: Do nothing
       
  2234 			
       
  2235 					Repeat with handlers 1 and 2 swapped
       
  2236 
       
  2237 @SYMTestExpectedResults		Loops through TWindowServerEvent::NotifyDrawer() should complete without crashing wserv
       
  2238 */
       
  2239 
       
  2240 void CTWsGraphs::TestNotifyRemoval()
       
  2241 	{
       
  2242 	_LIT(KTestEventNotification, "TestDrawerEventHandler");
       
  2243 	INFO_PRINTF1(KTestEventNotification);
       
  2244 	++iSubState;
       
  2245 
       
  2246 	for (TInt ii = 0; ii<KNotifyDoNothing; ii++)
       
  2247 		{
       
  2248 		INFO_PRINTF2(_L("For loop %d"), ii);
       
  2249 		iNotify1->SetBehaviour(ii);					//Enable this plugin and set it to an event handling method
       
  2250 		iNotify2->SetBehaviour(KNotifyDoNothing);	//Add a second drawer handler which is enabled but does nothing
       
  2251 		CreateWindowL();							//Change visibility activating the event handlers - Fails if wserv crashes!
       
  2252 		iNotify1->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
       
  2253 		iNotify2->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
       
  2254 		DestroyWindowL();
       
  2255 		}
       
  2256 	INFO_PRINTF1(_L("Swap handlers"));
       
  2257 	for (TInt ii = 0; ii<KNotifyDoNothing; ii++)
       
  2258 		{
       
  2259 		INFO_PRINTF2(_L("For loop %d"), ii);
       
  2260 		iNotify2->SetBehaviour(KNotifyDoNothing);	//Add a first drawer handler which is enabled but does nothing
       
  2261 		iNotify1->SetBehaviour(ii);					//Enable this plugin and set it to an event handling method
       
  2262 		CreateWindowL();							//Change visibility activating the event handlers - Fails if wserv crashes!
       
  2263 		iNotify2->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
       
  2264 		iNotify1->SetBehaviour(KNotifyDisable);		//Disable plugin if still enabled
       
  2265 		DestroyWindowL();
       
  2266 		}
       
  2267 
       
  2268 	TEST(ETrue);		// If the test has failed WServ will have paniced.
       
  2269 	}
       
  2270 
       
  2271 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
       
  2272 /**
       
  2273 @SYMTestCaseID           GRAPHICS-WSERV-0491
       
  2274 @SYMPREQ                 PREQ39
       
  2275 @SYMTestPriority         High
       
  2276 @SYMTestCaseDesc         Draw using a ECom-plugin which has direct access to the screen/OSB buffer 
       
  2277 @SYMTestActions          Create the plugin
       
  2278 						 Draw using the plugin
       
  2279 						 Update the position of the white line to line 70 and test
       
  2280 						 Update the position of the white line to line 80 and test
       
  2281 @SYMTestExpectedResults  White lines are drawn on the correct positions.
       
  2282 */
       
  2283 void CTWsGraphs::TestMWsUiBufferL()
       
  2284 	{
       
  2285 	const TInt KWhiteLinePos = 70;
       
  2286 	const TRect KBlueRect(TPoint(50,50),TSize(100,100));
       
  2287 		
       
  2288 	// Construct and setup window to be drawn to
       
  2289 	RWindow window1 = RWindow(TheClient->iWs);
       
  2290 	CleanupClosePushL(window1);
       
  2291     User::LeaveIfError(window1.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle));
       
  2292     TSize winSize=TSize(TheClient->iScreen->SizeInPixels());
       
  2293     window1.SetExtent(TPoint(0,0),winSize);
       
  2294     window1.Activate();
       
  2295     
       
  2296 	CWsBufferGraphic* graphic = CWsBufferGraphic::NewL();
       
  2297 	CleanupStack::PushL(graphic);
       
  2298     
       
  2299 	// Draw inital drawing with a Crp which is blue rect and a white line at line 0
       
  2300 	TheGc->Activate(window1);
       
  2301 	TheGc->Clear();
       
  2302 	window1.BeginRedraw();
       
  2303 	TheGc->DrawWsGraphic(graphic->Id(),KBlueRect);
       
  2304 	window1.EndRedraw();
       
  2305 	TheGc->Deactivate();
       
  2306 	
       
  2307     TheClient->iWs.Finish();
       
  2308     User::After(2000000);
       
  2309 	
       
  2310 	// Update the position of the white line to line 70
       
  2311 	INFO_PRINTF1(_L("Update position of white line to line 70"));
       
  2312 	graphic->UpdateWhiteLinePos(KWhiteLinePos);
       
  2313 	TheClient->iWs.Finish();
       
  2314 	// Force some delays to wait until the line position changes
       
  2315     User::After(2000000);
       
  2316     //Test white line has been drawn and is in the correct postion
       
  2317     TBool res1 = IsWhiteLine(KWhiteLinePos);
       
  2318     TEST(res1);
       
  2319     
       
  2320 	// Update the position of the white line to line 80
       
  2321     INFO_PRINTF1(_L("Update position of white line to line 80"));
       
  2322 	graphic->UpdateWhiteLinePos(KWhiteLinePos+10);
       
  2323 	TheClient->iWs.Finish();
       
  2324 	// Force some delays to wait until the line position changes
       
  2325 	User::After(2000000);
       
  2326 	// Test white line has been drawn and is in the correct postion
       
  2327     TBool res2 = IsWhiteLine(KWhiteLinePos+10);
       
  2328     TEST(res2);
       
  2329    
       
  2330 	graphic->Destroy();
       
  2331 	CleanupStack::PopAndDestroy(2, &window1);
       
  2332 	}
       
  2333 
       
  2334 // Test whether a line is completely white
       
  2335 TBool CTWsGraphs::IsWhiteLine(TInt aWhiteLinePos)
       
  2336 	{
       
  2337     TRgb color;
       
  2338     TPoint pixel;
       
  2339     
       
  2340     for(TInt xPos = 0; xPos < TheClient->iScreen->SizeInPixels().iWidth; xPos++)
       
  2341     	{
       
  2342     	pixel = TPoint(xPos,aWhiteLinePos);
       
  2343     	TheClient->iScreen->GetPixel(color,pixel);
       
  2344     	if(color.Red() != 255 && color.Blue() != 255 && color.Green() != 255)
       
  2345     		{
       
  2346     		return EFalse;
       
  2347     		}
       
  2348     	}
       
  2349     return ETrue;
       
  2350 	}
       
  2351 #endif //TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
       
  2352 
       
  2353 /**
       
  2354 	DoTestL() method, called by the WSERV Test Framework.
       
  2355 */
       
  2356 void CTWsGraphs::RunTestCaseL(TInt /*aCurTestCase*/)
       
  2357 	{
       
  2358 	_LIT(KTest1,"DoTestWsGraphics");
       
  2359 	_LIT(KTest2,"DoTestOOMWsGraphics");
       
  2360 	_LIT(KTest3,"Interface Extension");
       
  2361 	_LIT(KTest4,"Screen Redirection");
       
  2362 	_LIT(KTest5,"TextCursor1");
       
  2363 	_LIT(KTest6,"TextCursor2");
       
  2364 	_LIT(KTest7,"Flicker Redirection");
       
  2365 	_LIT(KTest8,"Event Notification");
       
  2366 	_LIT(KTest9,"Successive Message");
       
  2367 	_LIT(KTest10,"Redirection Using WsBackBuffer");
       
  2368 	_LIT(KTest11,"Group Change");
       
  2369 	_LIT(KTest12,"Frame Rate");
       
  2370 	_LIT(KTest13,"Leak In Service");
       
  2371 	_LIT(KTest14,"Add/Swap GDArray");
       
  2372 	_LIT(KTest15,"Nested Drawer CRP");
       
  2373 	_LIT(KTest16,"Notify Removal");
       
  2374 	_LIT(KTest17,"Screen Mode Change");
       
  2375 	_LIT(KTest18,"UI Buffer");
       
  2376 	_LIT(KTest19,"Graphics Drawer Coverage");
       
  2377 	CFbsBitmap bitmap1;
       
  2378 	CFbsBitmap mask1;
       
  2379 	CWsGraphicBitmap* bTest=NULL;
       
  2380 	TSize screenSize=TheClient->iScreen->SizeInPixels();
       
  2381 
       
  2382 	bitmap1.Create(screenSize,TheClient->iScreen->DisplayMode());
       
  2383 	mask1.Create(screenSize,TheClient->iScreen->DisplayMode());
       
  2384 	((CTWsGraphsStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
  2385 
       
  2386 	switch(++iTest->iState)
       
  2387 		{
       
  2388 	case 1:
       
  2389 /**
       
  2390 	@SYMTestCaseID	GRAPHICS-WSERV-0528
       
  2391 */
       
  2392 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0528"));
       
  2393 		// Launch new process with PROTSERV capability to run CWSGraphics tests in
       
  2394 		iTest->LogSubTest(KTest1);
       
  2395 		// This process only launches succesfully when _DEBUG is defined for the build, because it depends
       
  2396 		// on the existance of debug macros such as _UHEAP_MARK, _UHEAP_MARKEND, _UHEAP_FAILNEXT, ... etc
       
  2397 		LaunchNewProcess(KTestExe);
       
  2398 		break;
       
  2399 	case 2:
       
  2400 		{
       
  2401 		/**
       
  2402    		@SYMTestCaseID GRAPHICS-WSERV-0017
       
  2403 
       
  2404 		@SYMPREQ	PREQ1246
       
  2405 
       
  2406 		@SYMDEF		DEF081259
       
  2407 
       
  2408 		@SYMTestCaseDesc Out of memery test when creating a CWsGraphic.
       
  2409 
       
  2410 		@SYMTestPriority High
       
  2411 
       
  2412 		@SYMTestStatus Implemented
       
  2413 
       
  2414 		@SYMTestActions Out of memory test when creating a CWsGraphic.
       
  2415 
       
  2416 		@SYMTestExpectedResults Whenever an API call fails, it should leave the number
       
  2417 				of allocated heap cells unchanged.
       
  2418 		*/
       
  2419 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0017"));
       
  2420 
       
  2421 		iTest->LogSubTest(KTest2);
       
  2422 		TInt failRate;
       
  2423 		for(failRate=1;;failRate++)
       
  2424 			{
       
  2425 			__UHEAP_RESET;
       
  2426 			__UHEAP_SETFAIL(RHeap::EDeterministic,failRate);
       
  2427 			__UHEAP_MARK;
       
  2428 
       
  2429 			TRAPD(ret,bTest=CWsGraphicBitmap::NewL(&bitmap1,&mask1));
       
  2430 			TEST((ret==KErrNone || ret==KErrNoMemory));
       
  2431 			if (ret!=KErrNone && ret!=KErrNoMemory)
       
  2432 				{
       
  2433 				_LIT(KLog,"Failed to create CWsGraphicBitmap  error=%d");
       
  2434 				LOG_MESSAGE2(KLog,ret);
       
  2435 				}
       
  2436 			if (ret!=KErrNone)
       
  2437 				{
       
  2438 				__UHEAP_MARKEND;
       
  2439 				}
       
  2440 			else
       
  2441 				{
       
  2442 				TEST(bTest!=NULL);
       
  2443 				if (bTest==NULL)
       
  2444 					{
       
  2445 					_LIT(KLog,"Object creation didn't leave but returned NULL");
       
  2446 					LOG_MESSAGE(KLog);
       
  2447 					}
       
  2448 				delete bTest;
       
  2449 				bTest=NULL;
       
  2450 				__UHEAP_MARKEND;
       
  2451 				TLogMessageText logMessageText;
       
  2452 				_LIT(KSet,"OOM test succeds after %d allocations.");
       
  2453 				logMessageText.Format(KSet,failRate);
       
  2454 				LOG_MESSAGE(logMessageText);
       
  2455 				break;
       
  2456 				}
       
  2457 			}
       
  2458 		__UHEAP_RESET;
       
  2459 		}
       
  2460 		break;
       
  2461 	case 3:
       
  2462 		iTest->LogSubTest(KTest3);
       
  2463 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0371"));
       
  2464 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
  2465 			
       
  2466 			if (TestInterfaceExtensionL()==EWait)
       
  2467 				--iTest->iState;
       
  2468 #endif
       
  2469 		break;
       
  2470 	case 4:
       
  2471 		iTest->LogSubTest(KTest4);
       
  2472 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0372"));
       
  2473 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA			
       
  2474 			if (TestScreenRedirectionL()==EWait)
       
  2475 				--iTest->iState;
       
  2476 #endif
       
  2477 		break;
       
  2478 	case 5:
       
  2479 		iTest->LogSubTest(KTest5);
       
  2480 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0363"));
       
  2481 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA	
       
  2482 			if (TestTextCursorUnderRedirectionL(ETestStandardTextCursor) == EWait)
       
  2483 				--iTest->iState;
       
  2484 #endif
       
  2485 		break;
       
  2486 	case 6:
       
  2487 		iTest->LogSubTest(KTest6);
       
  2488 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0363"));
       
  2489 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA	
       
  2490 			if (TestTextCursorUnderRedirectionL(ETestCustomTextCursor) == EWait)
       
  2491 				--iTest->iState;
       
  2492 #endif
       
  2493 		break;
       
  2494 	case 7:
       
  2495 		iTest->LogSubTest(KTest7);
       
  2496 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0376"));
       
  2497 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA			
       
  2498 			if (TestFlickerRedirectionL()==EWait)
       
  2499 				--iTest->iState;
       
  2500 #endif
       
  2501 		break;
       
  2502 	case 8:
       
  2503 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0378"));
       
  2504 		iTest->LogSubTest(KTest8);
       
  2505 		if (TestEventNotificationL()==EWait)
       
  2506 			--iTest->iState;
       
  2507 		break;
       
  2508 	case 9:
       
  2509 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0381"));
       
  2510 		iTest->LogSubTest(KTest9);
       
  2511 		if (TestSuccessiveMessageL()==EWait)
       
  2512 			--iTest->iState;
       
  2513 		break;
       
  2514 	case 10:
       
  2515 		iTest->LogSubTest(KTest10);
       
  2516 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0527"));
       
  2517 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
  2518 		if(TestRedirectionUsingWsBackBufferL()==EWait)
       
  2519 			--iTest->iState;
       
  2520 #endif
       
  2521 		break;
       
  2522 	case 11:
       
  2523 /**
       
  2524 	@SYMTestCaseID	GRAPHICS-WSERV-0529
       
  2525 */
       
  2526 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0529"));
       
  2527 		iTest->LogSubTest(KTest11);
       
  2528 		if(TestWindowGroupChangeL()==EWait)
       
  2529 			--iTest->iState;
       
  2530 		break;
       
  2531 	case 12:
       
  2532 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0382"));
       
  2533 		iTest->LogSubTest(KTest12);
       
  2534 		if(TestFrameRateL()==EWait)
       
  2535 			--iTest->iState;
       
  2536 		break;
       
  2537 	case 13:
       
  2538 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-LeakInService-0001"));
       
  2539 		iTest->LogSubTest(KTest13);
       
  2540 		DoTestLeakInServiceL();
       
  2541 		break;
       
  2542 	case 14:
       
  2543 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-NegAddSwapGDArray-0001"));
       
  2544 		iTest->LogSubTest(KTest14);
       
  2545 		TestAddSwapGDArrayL();
       
  2546 		break;
       
  2547 	case 15:
       
  2548 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0438"));
       
  2549 		iTest->LogSubTest(KTest15);
       
  2550 		TestNestedDrawerCRP();
       
  2551 		break;
       
  2552 	case 16:
       
  2553 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0443"));
       
  2554 		iTest->LogSubTest(KTest16);
       
  2555 		TestNotifyRemoval();
       
  2556 		break;
       
  2557 	case 17:
       
  2558 		iTest->LogSubTest(KTest17);
       
  2559 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0530"));
       
  2560 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NONNGA
       
  2561 /**
       
  2562 	@SYMTestCaseID	GRAPHICS-WSERV-0530
       
  2563 */
       
  2564 			
       
  2565 			TestScreenModeChangeL();
       
  2566 #endif
       
  2567 		break;
       
  2568 	case 18:
       
  2569 		iTest->LogSubTest(KTest18);
       
  2570 		((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0491"));
       
  2571 #ifdef TEST_GRAPHICS_WSERV_TAUTOSERVER_NGA
       
  2572 			
       
  2573 			TestMWsUiBufferL();
       
  2574 #endif
       
  2575 			break;
       
  2576 		case 19:
       
  2577 			iTest->LogSubTest(KTest19);
       
  2578 /**
       
  2579 	@SYMTestCaseID	GRAPHICS-WSERV-0531
       
  2580 */
       
  2581 			((CTWsGraphsStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0531"));
       
  2582 			TestGraphicDrawerCoverage();
       
  2583 			break;
       
  2584 		default:
       
  2585 			((CTWsGraphsStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
  2586 			((CTWsGraphsStep*)iStep)->CloseTMSGraphicsStep();
       
  2587 			TestComplete();
       
  2588 			break;
       
  2589 		}
       
  2590 	((CTWsGraphsStep*)iStep)->RecordTestResultL();
       
  2591 	}
       
  2592 
       
  2593 __WS_CONSTRUCT_STEP__(WsGraphs)