os/graphics/windowing/windowserver/test/tdynamicres/src/wsdynamicresbasic.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-2010 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 //
    15 
    16 /**
    17  @file
    18 */
    19 #include "wsdynamicresbasic.h"
    20 #include <test/extendtef.h>
    21 #include "globalsettings.h"
    22 #include <w32debug.h>
    23 #include <w32stdgraphic.h>
    24 #include "regionextend.h"
    25 #include <fbs.h>
    26 #include <e32svr.h>
    27 #include <u32hal.h>
    28 #include <graphics/surfaceconfiguration.h>
    29 #include "surfaceutility.h"
    30 #include <graphics/testscreencapture.h>
    31 
    32 //verify which base code is available to the test
    33 #include <dispchannel.h>
    34 #if (!defined(K_DISPLAY_CH_MAJOR_VERSION_NUMBER) && !defined(K_DISPLAY_CH_MINOR_VERSION_NUMBER))
    35 #define MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
    36 #endif
    37 
    38 
    39 //#define VISIBLE_PAUSES 1000
    40 #define OVERLAPPING_CELL	0	//'m'	//0 indicates cells do not overlap
    41 /*
    42  * CWsGceTestPlaceSurfExtra implementation
    43  * 
    44  * 
    45  * 
    46  * 
    47  */
    48 CWsDynamicResBasic::CWsDynamicResBasic()
    49 {
    50 }
    51 
    52 CWsDynamicResBasic::~CWsDynamicResBasic()
    53 {
    54 }
    55 
    56 void CWsDynamicResBasic::SetupL()
    57 	{
    58 	MyBase::SetupL();
    59 	}
    60 void CWsDynamicResBasic::TearDownL()
    61 	{
    62 	MyBase::TearDownL();
    63 	
    64 	}
    65 void CWsDynamicResBasic::TearDownFromDeleteL()
    66 	{
    67 	MyBase::TearDownFromDeleteL();
    68 	}
    69 
    70 
    71 CTestSuite* CWsDynamicResBasic::CreateSuiteL( const TDesC& aName )
    72 	{
    73 	//Create the surface manager here, before the test suite creates additional threads
    74 	if (GCEIsSupportedStatic())
    75 		{
    76 		TRAP_IGNORE(PostTestCleanupInstance().CreateSharedUtilityL());
    77 		}
    78 	
    79 	SUB_SUITE_OPT(CWsDynamicResBasic,NULL);
    80 
    81 		//BASIC
    82 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0001L);
    83 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0002L);
    84 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0003L);
    85 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0004L);
    86 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0005L);
    87 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0006L);
    88 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0007L);
    89 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0008L);
    90 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0009L);
    91 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0010L);	//only run on screen 1
    92 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0011L);
    93 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0012L);	//only run on screen 0
    94 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0013L);
    95 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0014L);	//only run on screen 1
    96 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0015L);	//only run with no scaling
    97 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0016L);	//only run with anisotropic scaling
    98 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0017L);	//only run with integer scaling
    99 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0018L);
   100 
   101 		ADD_TEST_STEP_PARAM_BOOL(GRAPHICS_WSERV_DYNAMICRES_0021L);	//only run on screen 1
   102 		
   103 		//OOM
   104 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0031L);
   105 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0032L);
   106 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0033L);
   107 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0034L);	//dont run with no scaling on screen 0
   108 
   109 		//SCREEN CAPTURE
   110 		ADD_TEST_STEP_PARAM_BOOL(GRAPHICS_WSERV_DYNAMICRES_0041L);
   111 		ADD_TEST_STEP_PARAM_BOOL(GRAPHICS_WSERV_DYNAMICRES_0042L);
   112 		
   113 		//DYNAMIC SCREEN MODE - only run these with no scaling and isotropic scaling
   114 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0051L);	
   115 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0052L);	//only run on screen 1 (multiple resolutions)
   116 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0053L);
   117 
   118 		//DEFECT
   119 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0101L);
   120 		ADD_THIS_TEST_STEP(GRAPHICS_WSERV_DYNAMICRES_0102L);
   121 
   122 	END_SUITE;
   123 	}
   124 
   125 #define LOG_AND_PANIC_IF_NOT_GCE											\
   126 		{																	\
   127 		if (!GCEIsSupported())												\
   128 			{																\
   129 			INFO_PRINTF1(_L("Test skipped: GCE support is not loaded"));	\
   130 			User::Panic(_L("GCE.Wrong.Mode"),1);							\
   131 			return;															\
   132 			}																\
   133 		}
   134 
   135 CWsDisplayEvent::CWsDisplayEvent(RWsSession *aWs):
   136 CActive(EPriorityStandard), iWs(aWs), iConfigSpinner(0), iResListSpinner(0),iReceivedEventCount(0), 
   137 iReceivedPointerEventCount(0), iPointerPosTestPass(ETrue) 
   138 	{
   139 	CActiveScheduler::Add(this);
   140 	}
   141 CWsDisplayEvent::~CWsDisplayEvent()
   142 	{
   143 	Cancel();
   144 	}
   145 
   146 void CWsDisplayEvent::DoCancel()
   147 	{
   148 	iWs->EventReadyCancel();
   149 	}
   150 
   151 void CWsDisplayEvent::Request()
   152 	{
   153 	iWs->EventReady(&iStatus);
   154 	SetActive();
   155 	}
   156 
   157 void CWsDisplayEvent::RunL()
   158 	{
   159 	TWsEvent event;
   160 	iWs->GetEvent(event);
   161 	
   162 	if(iStatus == KErrNone)
   163 		{
   164 		switch(event.Type())
   165 			{
   166 			case EEventScreenDeviceChanged:
   167 				{
   168 				iReceivedDeviceEventCount++;
   169 				}
   170 			case EEventPointer:
   171 				{
   172 				iReceivedPointerEventCount++;
   173 				TPointerEvent* ptEvent = event.Pointer();
   174 				//make 1 pixels distance allowance, as non integer scalling from composition to app may occur
   175 				//1 pixels allowance because we never scale greater than 2 times
   176 				if(ptEvent->iPosition.iX < iPointerPos.iX - 1 && ptEvent->iPosition.iX > iPointerPos.iX + 1
   177 						&& ptEvent->iPosition.iY < iPointerPos.iY - 1 &&ptEvent->iPosition.iY > iPointerPos.iY + 1)
   178 					{
   179 					iPointerPosTestPass = EFalse;
   180 					}
   181 				}
   182 			case EEventDisplayChanged:
   183 				{
   184 				iConfigSpinner = event.DisplayChanged()->iConfigurationChangeId;
   185 				iResListSpinner = event.DisplayChanged()->iResolutionListChangeId;
   186 				iReceivedEventCount++;
   187 				}
   188 				break;
   189 			default:
   190 				break;
   191 			}
   192 		}
   193 	else
   194 		User::Leave(iStatus.Int());
   195 	
   196 	Request();
   197 	}
   198 
   199 CEventTimer* CEventTimer::NewL()
   200 	{
   201 	CEventTimer* self = new (ELeave) CEventTimer;
   202 	CleanupStack::PushL(self);
   203 	self->ConstructL();
   204 	CleanupStack::Pop(self);
   205 	return self;
   206 	}
   207       
   208 void CEventTimer::ConstructL()
   209 	{
   210 	User::LeaveIfError(iTimer.CreateLocal());
   211 	CActiveScheduler::Add(this);
   212 	}
   213  
   214 CEventTimer::CEventTimer() : CActive(EPriorityStandard)
   215 	{
   216 	
   217 	}
   218 
   219 CEventTimer::~CEventTimer()
   220 	{
   221 	Cancel();
   222 	iTimer.Close();
   223 	}
   224 
   225 void CEventTimer::DoCancel()
   226 	{
   227 	iTimer.Cancel();
   228 	CActiveScheduler::Stop();
   229 	}
   230 
   231 void CEventTimer::RunL()
   232 	{
   233 	CActiveScheduler::Stop();
   234 	}
   235 
   236 void CEventTimer::Wait(TInt aDelay)
   237 	{
   238 	iTimer.After(iStatus, aDelay);
   239 	SetActive();
   240 	CActiveScheduler::Start();
   241 	}
   242 
   243 //Set display state to normal and to the first decent resolution
   244 //A failed test could leave it in a bad state
   245 void CWsDynamicResBasic::ResetScreens()
   246 	{
   247 	Pause(1000);
   248 #ifndef MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
   249 	TInt displayState = ENormalResolution; 
   250 	UserSvr::HalFunction(EHalGroupDisplay | (iScreenDevice->GetScreenNumber()<<16), EDisplayHalSetDisplayState, &displayState, NULL);
   251 #endif
   252 	MDisplayControl* interface = static_cast<MDisplayControl*>
   253 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   254 	ASSERT_TRUE(interface);
   255 	
   256 	RArray<TInt> appModeIndexList;
   257 	TInt currMode=iScreenDevice->CurrentScreenMode();
   258 	iScreenDevice->GetScreenSizeModeList(&appModeIndexList);
   259 	if (appModeIndexList[0]!=currMode)
   260 		{
   261 		iScreenDevice->SetAppScreenMode(appModeIndexList[0]);
   262 		iScreenDevice->SetScreenMode(appModeIndexList[0]);
   263 		}
   264 	appModeIndexList.Close();
   265 	
   266 	TInt resolutions = interface->NumberOfResolutions();
   267 	ASSERT_TRUE (resolutions > 0);
   268 	RArray<MDisplayControl::TResolution> resolutionList1;
   269 	TInt error = interface->GetResolutions(resolutionList1);
   270 	ASSERT_EQUALS(error,KErrNone);
   271 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
   272 	TDisplayConfiguration config;
   273 	TInt goodRes=0;
   274 	if (resolutionList1[goodRes].iPixelSize==TSize())
   275 		{
   276 		goodRes++;
   277 		ASSERT_TRUE(resolutions>goodRes);		//First res was blank, and no more to choose!
   278 		}
   279 	config.SetResolution(resolutionList1[goodRes].iPixelSize);
   280 	error=interface->SetConfiguration(config);
   281 	ASSERT_EQUALS(error,KErrNone);
   282 	resolutionList1.Close();
   283 	}
   284 
   285 /**
   286 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0001L
   287 @SYMTestCaseDesc		WSERV Screen Device GetInterface returns known interface
   288 @SYMREQ					REQ10325
   289 @SYMPREQ				PREQ2102
   290 @SYMTestType			CT
   291 @SYMTestPriority		1
   292 @SYMTestPurpose			Basic classic behaviour
   293 @SYMTestActions			
   294 	Call GetInterface with a well known GUID
   295 @SYMTestExpectedResults	
   296 	Returns a pointer
   297 */
   298 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0001L()
   299 	{
   300 	LOG_AND_PANIC_IF_NOT_GCE;
   301 	MakeTitleAndCompareWindowsL(_L("GRAPHICS_WSERV_DYNAMICRES_0001L"),_L("Basic Dynamic Resolution test"));
   302 	
   303 	MDisplayControlBase* interface1 = static_cast<MDisplayControlBase*>
   304 			(iScreenDevice->GetInterface(MDisplayControlBase::ETypeId));
   305 	ASSERT_TRUE(interface1);
   306 	
   307 	MDisplayControl* interface2 = static_cast<MDisplayControl*>
   308 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   309 	ASSERT_TRUE(interface2);
   310 	
   311 	MDisplayMappingBase* interface3 = static_cast<MDisplayMappingBase*>
   312 			(iScreenDevice->GetInterface(MDisplayMappingBase::ETypeId));
   313 	ASSERT_TRUE(interface3);
   314 	
   315 	MDisplayMapping* interface4 = static_cast<MDisplayMapping*>
   316 			(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
   317 	ASSERT_TRUE(interface4);
   318 	}
   319 
   320 /**
   321 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0002L
   322 @SYMTestCaseDesc		Basic test for NumberOfResolutions
   323 @SYMREQ					REQ10328
   324 @SYMPREQ				PREQ2102
   325 @SYMTestType			CT
   326 @SYMTestPriority		1
   327 @SYMTestPurpose			NumberOfResolutions returns correctly
   328 @SYMTestActions			
   329 	GetInterface
   330 	then call NumberOfResolutions.
   331 @SYMTestExpectedResults	
   332 	It shouldn't return KErrNotSupported
   333 */
   334 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0002L()
   335 	{
   336 	LOG_AND_PANIC_IF_NOT_GCE;
   337 	MDisplayControl* interface = static_cast<MDisplayControl*>
   338 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   339 	ASSERT_TRUE(interface);
   340 	TInt resolutions = interface->NumberOfResolutions();
   341 	ASSERT_TRUE (resolutions != KErrNotSupported);
   342 	}
   343 
   344 /**
   345 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0003L
   346 @SYMTestCaseDesc		Basic test for GetResolutions
   347 @SYMREQ					REQ10328
   348 @SYMPREQ				PREQ2102
   349 @SYMTestType			CT
   350 @SYMTestPriority		
   351 @SYMTestPurpose			Check GetResolutions returns a valid TSize RArray
   352 @SYMTestActions			
   353 	GetInterface
   354 	Call NumberOfResolutions
   355 	Create an array and garbage fill based on amount of resolutions
   356 	Call GetResolutions on this array
   357 	Create an array (dont garbage fill)
   358 	Call GetResolutions on this empty array
   359 	Create an array with smaller size than required
   360 	Call GetResolutions on this array
   361 	Create an array with larger size than required
   362 	Call GetResolutions on this array
   363 @SYMTestExpectedResults	
   364 	For both GetResolutions calls, it should allocate memory if needed, and fill
   365 	with correct sizes
   366 */
   367 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0003L()
   368 	{
   369 	LOG_AND_PANIC_IF_NOT_GCE;
   370 	TInt count;
   371 	TInt error;
   372 	
   373 	MDisplayControl* interface = static_cast<MDisplayControl*>
   374 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   375 	ASSERT_TRUE(interface);
   376 	
   377 	TInt resolutions = interface->NumberOfResolutions();
   378 	ASSERT_TRUE (resolutions > 0);
   379 	
   380 	RArray<MDisplayControl::TResolution> resolutionList1;
   381 	for (count=0;count<resolutions;count++)
   382 		{
   383 		resolutionList1.Append(MDisplayControl::TResolution(TSize(),TSize()));
   384 		}
   385 	error = interface->GetResolutions(resolutionList1);
   386 	ASSERT_EQUALS(error,KErrNone);
   387 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
   388 	
   389 	RArray<MDisplayControl::TResolution> resolutionList2;
   390 	error = interface->GetResolutions(resolutionList2);
   391 	ASSERT_EQUALS(error,KErrNone);
   392 	ASSERT_EQUALS(resolutionList2.Count(), resolutions);
   393 	
   394 	RArray<MDisplayControl::TResolution> resolutionList3;
   395 	for (count=0;count<resolutions-1;count++)
   396 		{
   397 		resolutionList3.Append(MDisplayControl::TResolution(TSize(),TSize()));
   398 		}
   399 	error = interface->GetResolutions(resolutionList3);
   400 	ASSERT_EQUALS(error,KErrNone);
   401 	ASSERT_EQUALS(resolutionList3.Count(), resolutions);
   402 	
   403 	RArray<MDisplayControl::TResolution> resolutionList4;
   404 	for (count=0;count<resolutions+2;count++)
   405 		{
   406 		resolutionList4.Append(MDisplayControl::TResolution(TSize(),TSize()));
   407 		}
   408 	error = interface->GetResolutions(resolutionList4);
   409 	ASSERT_EQUALS(error,KErrNone);
   410 	ASSERT_EQUALS(resolutionList4.Count(), resolutions);
   411 	
   412 	for (count=0;count<resolutions;count++)
   413 		{
   414 		ASSERT_EQUALS(resolutionList1[count].iPixelSize,resolutionList2[count].iPixelSize);
   415 		ASSERT_EQUALS(resolutionList1[count].iPixelSize,resolutionList3[count].iPixelSize);
   416 		ASSERT_EQUALS(resolutionList1[count].iPixelSize,resolutionList4[count].iPixelSize);
   417 		
   418 		ASSERT_EQUALS(resolutionList1[count].iTwipsSize,resolutionList2[count].iTwipsSize);
   419 		ASSERT_EQUALS(resolutionList1[count].iTwipsSize,resolutionList3[count].iTwipsSize);
   420 		ASSERT_EQUALS(resolutionList1[count].iTwipsSize,resolutionList4[count].iTwipsSize);
   421 		
   422 		if (!(resolutionList1[count].iFlags == resolutionList2[count].iFlags))
   423 			{
   424 			ASSERT_TRUE(EFalse);
   425 			}
   426 		if (!(resolutionList1[count].iFlags == resolutionList3[count].iFlags))
   427 			{
   428 			ASSERT_TRUE(EFalse);
   429 			}
   430 		if (!(resolutionList1[count].iFlags == resolutionList4[count].iFlags))
   431 			{
   432 			ASSERT_TRUE(EFalse);
   433 			}
   434 		}
   435 	resolutionList1.Close();
   436 	resolutionList2.Close();
   437 	resolutionList3.Close();
   438 	resolutionList4.Close();
   439 	}
   440 
   441 /**
   442 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0004L
   443 @SYMTestCaseDesc		Test for GetConfiguration
   444 @SYMREQ					REQ10328
   445 @SYMPREQ				PREQ2102
   446 @SYMTestType			CT
   447 @SYMTestPriority		1
   448 @SYMTestPurpose			Check GetConfiguration returns a configuration object
   449 @SYMTestActions			
   450 	GetInterface
   451 	GetConfiguration with standard TDisplayConfiguration
   452 	GetResolution from the TDisplayConfiguration object
   453 	GetConfiguration with TDisplayConfiguration object with a greater version/size
   454 	GetResolution from the TDisplayConfiguration object
   455 	GetConfiguration with TDisplayConfiguration object with a smaller version/size -- equal to TDisplayConfiguration1
   456 	GetResolution from the TDisplayConfiguration object
   457 	Check all the resolutions should be same
   458 @SYMTestExpectedResults	
   459 	
   460 */
   461 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0004L()
   462 	{
   463 	LOG_AND_PANIC_IF_NOT_GCE;
   464 			
   465 	MDisplayControl* interface = static_cast<MDisplayControl*>
   466 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   467 	ASSERT_TRUE(interface);
   468 	
   469 	TDisplayConfiguration dispConfig;
   470 	interface->GetConfiguration(dispConfig);
   471 	ASSERT_TRUE(dispConfig.IsDefined(TDisplayConfigurationBase::EResolution));
   472 	TSize size;
   473 	TSize twips;
   474 	ASSERT_TRUE(dispConfig.GetResolution(size));
   475 	ASSERT_TRUE(dispConfig.GetResolutionTwips(twips));
   476 	
   477 	TDisplayConfiguration dispConfig1(TDisplayConfiguration().Version() + 10);
   478 	interface->GetConfiguration(dispConfig1);
   479 	ASSERT_TRUE(dispConfig1.IsDefined(TDisplayConfigurationBase::EResolution));
   480 	TSize size1;
   481 	TSize twips1;
   482 	ASSERT_TRUE(dispConfig1.GetResolution(size1));
   483 	ASSERT_TRUE(dispConfig1.GetResolutionTwips(twips1));
   484 	
   485 	TDisplayConfiguration dispConfig2(TDisplayConfiguration1().Version());
   486 	interface->GetConfiguration(dispConfig2);
   487 	ASSERT_TRUE(dispConfig2.IsDefined(TDisplayConfigurationBase::EResolution));
   488 	TSize size2;
   489 	TSize twips2;
   490 	ASSERT_TRUE(dispConfig2.GetResolution(size2));
   491 	ASSERT_TRUE(dispConfig2.GetResolutionTwips(twips2));
   492 	
   493 	ASSERT_EQUALS(size, size1);
   494 	ASSERT_EQUALS(size, size2);
   495 	ASSERT_EQUALS(twips, twips1);
   496 	ASSERT_EQUALS(twips, twips2);
   497 	}
   498 
   499 /**
   500 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0005L
   501 @SYMTestCaseDesc		Test getting display change event from event queue
   502 @SYMREQ					REQ10329 REQ10330
   503 @SYMPREQ				PREQ2102
   504 @SYMTestType			CT
   505 @SYMTestPriority		1
   506 @SYMTestPurpose			Verify the correct behaviour of display change notification
   507 @SYMTestActions			
   508 	Run through various ways of changing resolution
   509 	For each, check if event has been received
   510 @SYMTestExpectedResults	
   511 	Based on type of change, check event
   512 	@note Test uses HAL to simulate display disconnection. Not supported on production platforms.
   513 */
   514 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0005L()
   515 	{
   516 	LOG_AND_PANIC_IF_NOT_GCE;
   517 	ResetScreens();
   518 #ifdef MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
   519 	ASSERT_FALSE("Display connection test not compiled because MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER");
   520 #else
   521 	TInt screenNo = iScreenDevice->GetScreenNumber();
   522 	
   523 	MDisplayControl* interface = static_cast<MDisplayControl*>
   524 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   525 	ASSERT_TRUE(interface);
   526 	interface->EnableDisplayChangeEvents(ETrue);
   527 	ASSERT_TRUE(interface->DisplayChangeEventsEnabled());
   528 	
   529 	CWsDisplayEvent* displayEventAO = new(ELeave) CWsDisplayEvent(&iSession);
   530 	CleanupStack::PushL(displayEventAO);
   531 	displayEventAO->Request();
   532 	CEventTimer *timer = CEventTimer::NewL();
   533 	CleanupStack::PushL(timer);
   534 	TInt dispSpinnerValue = displayEventAO->ResListSpinner();
   535 	TInt configSpinnerValue = displayEventAO->ConfigSpinner();
   536 	
   537 	iSession.Flush();		
   538 	TInt displayState = EDisconnect;
   539 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
   540 	
   541 	timer->Wait(100000);
   542 	ASSERT_TRUE(displayEventAO->ConfigSpinner() >= configSpinnerValue); //this is also a config change
   543 	ASSERT_TRUE(displayEventAO->ResListSpinner() > dispSpinnerValue); //1st display change event
   544 	dispSpinnerValue = displayEventAO->ResListSpinner();
   545 	configSpinnerValue = displayEventAO->ConfigSpinner();
   546 	
   547 	
   548 	interface->EnableDisplayChangeEvents(ETrue);//enable again
   549 	ASSERT_TRUE(interface->DisplayChangeEventsEnabled());
   550 	interface->EnableDisplayChangeEvents(EFalse);//disable
   551 	ASSERT_FALSE(interface->DisplayChangeEventsEnabled());
   552 	interface->EnableDisplayChangeEvents(EFalse);//disable again
   553 	interface->EnableDisplayChangeEvents(ETrue);//enable again
   554 	iSession.Flush();
   555 	
   556 	TDisplayConfiguration disconnectedConfig;
   557 	disconnectedConfig.SetResolution(TSize(10,11));
   558 	disconnectedConfig.SetResolutionTwips(TSize(12,13));
   559 	disconnectedConfig.SetRotation(TDisplayConfiguration1::ERotationNormal);
   560 	interface->GetConfiguration(disconnectedConfig);
   561 	ASSERT_FALSE(disconnectedConfig.IsDefined(disconnectedConfig.EResolution));
   562 	ASSERT_FALSE(disconnectedConfig.IsDefined(disconnectedConfig.EResolutionTwips));
   563 	ASSERT_FALSE(disconnectedConfig.IsDefined(disconnectedConfig.ERotation));
   564 	
   565 	displayState = ENormalResolution; 
   566 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
   567 	
   568 	timer->Wait(1000000);
   569 	ASSERT_TRUE(displayEventAO->ConfigSpinner() >= configSpinnerValue); //this is a config change if display policy is enabled. not a change otherwise
   570 	ASSERT_TRUE(displayEventAO->ResListSpinner() > dispSpinnerValue); //display change event	
   571 	dispSpinnerValue = displayEventAO->ResListSpinner();
   572 	configSpinnerValue = displayEventAO->ConfigSpinner();
   573 	
   574 	TDisplayConfiguration dispConfig, dispConfig2;
   575 	TSize resolution,resolution2;
   576 	interface->GetConfiguration(dispConfig2);
   577 	dispConfig2.GetResolution(resolution2);
   578 	RArray<MDisplayControl::TResolution> resolutions;
   579 	TInt err = interface->GetResolutions(resolutions);
   580 	ASSERT_EQUALS(err, KErrNone);
   581 	dispConfig.SetResolution(resolutions[resolutions.Count()/2].iPixelSize);
   582 	err = interface->SetConfiguration(dispConfig);
   583 	ASSERT_EQUALS(err, KErrNone);
   584 	interface->GetConfiguration(dispConfig);
   585 	
   586 	timer->Wait(100000);
   587 	
   588 	if(!(dispConfig2 == dispConfig))
   589 		{
   590 		ASSERT_TRUE(displayEventAO->ConfigSpinner() > configSpinnerValue); //a config change, but on screen 0 with DP disabled, as we only have 1 resolution when DP disabled
   591 		}
   592 	else
   593 		{
   594 		ASSERT_TRUE(displayEventAO->ConfigSpinner() == configSpinnerValue);
   595 		}
   596 	ASSERT_EQUALS(displayEventAO->ResListSpinner(), dispSpinnerValue); //this is not a display change event	
   597 	dispSpinnerValue = displayEventAO->ResListSpinner();
   598 	configSpinnerValue = displayEventAO->ConfigSpinner();
   599 	resolutions.Close();
   600 	
   601 	//here we flood the event queue with key events, so the next display change
   602 	//can't put event and queue and force the retry AO on server side to kick off
   603 	iSession.SetFocusScreen(TGlobalSettings::Instance().iScreen);
   604 	for(TInt scanCode = 'a'; scanCode < 't'; scanCode ++)
   605 		{
   606 		TRawEvent rawEvent;
   607 		rawEvent.Set(TRawEvent::EKeyDown,scanCode);
   608 		iSession.SimulateRawEvent(rawEvent);
   609 		rawEvent.Set(TRawEvent::EKeyUp,scanCode);
   610 		iSession.SimulateRawEvent(rawEvent);
   611 		}
   612 	iSession.Flush();
   613 
   614 	TInt eventCount1 = displayEventAO->ReceivedEventCount(); 
   615 	//we should still receive this
   616 	displayState = EDisconnect; 
   617 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
   618 	//let retry AO retry more times before we try to get it
   619 	User::After(1000000);
   620 	
   621 	timer->Wait(10000000);
   622 	ASSERT_TRUE(displayEventAO->ConfigSpinner()> configSpinnerValue ); //4th config change
   623 	ASSERT_TRUE(displayEventAO->ResListSpinner() > dispSpinnerValue); //4th display change event
   624 	
   625 	//This part is doomed as well. Now the received event count includes all the pointer, device and display change event
   626 	/*
   627 	TInt eventCount2 = displayEventAO->ReceivedEventCount();
   628 	//make sure retry AO is stopped - we only receive 1 display event
   629 	ASSERT_EQUALS(eventCount1 + 1, eventCount2);
   630 	*/
   631 	displayState = ENormalResolution; 
   632 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
   633 	
   634 	CleanupStack::PopAndDestroy(2, displayEventAO);
   635 #endif
   636 	}
   637 
   638 //Adds the first rotation defined in the TResolution to the display configuration
   639 void CWsDynamicResBasic::SetRotation (TDisplayConfiguration& aConfig, const MDisplayControl::TResolution& aResolution)
   640 	{
   641 	if (aResolution.iFlags.IsSet(MDisplayControlBase::TResolution::ERotationNormalSupported))
   642 		{
   643 		aConfig.SetRotation(TDisplayConfiguration1::ERotationNormal);
   644 		}
   645 	else if (aResolution.iFlags.IsSet(MDisplayControlBase::TResolution::ERotation90Supported))
   646 		{
   647 		aConfig.SetRotation(TDisplayConfiguration1::ERotation90CW);
   648 		}
   649 	else if (aResolution.iFlags.IsSet(MDisplayControlBase::TResolution::ERotation180Supported))
   650 		{
   651 		aConfig.SetRotation(TDisplayConfiguration1::ERotation180);
   652 		}
   653 	else if (aResolution.iFlags.IsSet(MDisplayControlBase::TResolution::ERotation270Supported))
   654 		{
   655 		aConfig.SetRotation(TDisplayConfiguration1::ERotation270CW);
   656 		}
   657 	ASSERT_TRUE(aConfig.IsDefined(aConfig.ERotation));
   658 	}
   659 	
   660 /**
   661 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0006L
   662 @SYMTestCaseDesc		Set Screen display res
   663 @SYMREQ					REQ10326
   664 @SYMPREQ				PREQ2102
   665 @SYMTestType			CT
   666 @SYMTestPriority		
   667 @SYMTestPurpose			Checking window and layer extents continue working
   668 @SYMTestActions			
   669 	Get resolution list
   670 	For every resolution
   671 		Set resolution
   672 		Draw many rectangles that shrink to demonstrate scaling issues
   673 		Draw surface
   674 		Move window around
   675 @SYMTestExpectedResults	
   676 	Every resolution that is supported by current app mode should successfully be set
   677 	All rectangles and surface should be visible
   678 	As the window moves, the rectangles and surface should move with it, keeping visible
   679 */
   680 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0006L()
   681 	{
   682 	LOG_AND_PANIC_IF_NOT_GCE;
   683 	ResetScreens();
   684 	TInt error;
   685 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0006L"),_L("Change Resolution"));
   686 
   687 	iTestBack=RBlankWindow(iSession);
   688 	ASSERT_EQUALS(iTestBack.Construct(iGroup, ++iWindowHandle), KErrNone);
   689 	iTestBack.SetRequiredDisplayMode(iDisplayMode);
   690 	iTestBack.SetColor(TRgb(255,0,0));
   691 	iTestBack.SetExtent(iTestPos.iTl,iTestPos.Size());
   692 	iTestBack.Activate();
   693 	iTestBack.SetVisible(ETrue);
   694 	
   695 	struct DrawCompare
   696 		{
   697 		static void Draw(CWindowGc*	aGc)
   698 			{
   699 			aGc->SetPenStyle(aGc->ESolidPen);
   700 			aGc->SetPenColor(TRgb(255,255,255));
   701 			aGc->SetBrushColor(TRgb(0,0,0));
   702 			TRect r(2,2,82,82);
   703 			while(r.Width()>0)
   704 				{
   705 				aGc->DrawRect(r);
   706 				r.Shrink(2,2);
   707 				}
   708 			}
   709 		};
   710 	TSurfaceId surfaceID;
   711 	TRAPD(err, surfaceID = iUtility->CreateSurfaceL(TSize(200,200), 
   712 			KSurfaceFormat, 200 * KBytesPerPixel));
   713 	ASSERT_EQUALS(err,KErrNone);
   714 	TRAP(err,iUtility->FanFillSurfaceL(surfaceID,iYellow,iRed,iMagenta));
   715 	ASSERT_EQUALS(err,KErrNone);
   716 	TSurfaceConfiguration surfConf;
   717 	surfConf.SetSurfaceId(surfaceID);
   718 	
   719 	surfConf.SetExtent(TRect(2,84,82,166));
   720 	iCompare.SetBackgroundSurface(surfConf,EFalse);
   721 	
   722 	if (CWindowGc*	gc=BeginActivateWithWipe(ETrue,iCompare,TRgb(128,128,128)))
   723 		{
   724 		DrawCompare::Draw(gc);
   725 		gc->Deactivate();
   726 		iCompare.EndRedraw();
   727 		
   728 		}
   729 	iSession.Finish(ETrue);
   730 	Pause(1000);
   731 	
   732 	MDisplayControl* interface = static_cast<MDisplayControl*>
   733 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   734 	ASSERT_TRUE(interface);
   735 	
   736 	TInt resolutions = interface->NumberOfResolutions();
   737 	ASSERT_TRUE (resolutions > 0);
   738 	
   739 	RArray<MDisplayControl::TResolution> resolutionList1;
   740 	error = interface->GetResolutions(resolutionList1);
   741 	ASSERT_EQUALS(error,KErrNone);
   742 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
   743 	
   744 	TDisplayConfiguration dispConfigBefore;
   745 	interface->GetConfiguration(dispConfigBefore);
   746 	ASSERT_TRUE(dispConfigBefore.IsDefined(dispConfigBefore.EResolution))
   747 	if (resolutions>1)
   748 		{
   749 		//Got a mode to change to!
   750 		TSize resBefore;
   751 		TBool ok=dispConfigBefore.GetResolution(resBefore);
   752 		ASSERT_TRUE(ok);	//we "know" this should be ok, as we just asserted the flag
   753 		TBool foundBeforeRes=EFalse;
   754 		for (TInt res=0;res<resolutionList1.Count();res++)
   755 			{
   756 //			if (resolutionList1[res].iPixelSize!=resBefore)
   757 				{
   758 				if (resolutionList1[res].iPixelSize!=TSize(0,0))	//this test is not about turning the display off
   759 					{
   760 					TDisplayConfiguration dispConfigReq;
   761 					dispConfigReq.SetResolution(resolutionList1[res].iPixelSize);
   762 					ASSERT_TRUE(dispConfigReq.IsDefined(dispConfigReq.EResolution));
   763 					
   764 					SetRotation(dispConfigReq,resolutionList1[res]);	//set rotation to first defined in res list
   765 					
   766 					TInt errCode=interface->SetConfiguration(dispConfigReq);
   767 					//ASSERT_EQUALS(errCode,KErrNone);
   768 					if (errCode != KErrNone)
   769 						{
   770 						//Probably current size mode does not support the rotation of the passed in configuration
   771 						
   772 						ASSERT_EQUALS(errCode,KErrArgument);	//failed to find compatible res in the policy
   773 						continue;
   774 						}
   775 					Pause(300);
   776 					TRect outerrect(iTestPos.iTl,resolutionList1[res].iPixelSize.AsPoint());
   777 					iTestBack.SetExtent(outerrect.iTl,outerrect.Size());
   778 					iSession.Finish(ETrue);
   779 					Pause(300);
   780 					if (CWindowGc*	gc=BeginActivateWithWipe(ETrue,iCompare,TRgb(128,128,128)))
   781 						{
   782 						DrawCompare::Draw(gc);
   783 						gc->Deactivate();
   784 						iCompare.EndRedraw();
   785 						}
   786 					TBuf16<20> s;
   787 					s.AppendNum(res);
   788 					UpdateTitleWindowL(s,2);
   789 					s.Zero();
   790 					s.AppendNum(resolutionList1[res].iPixelSize.iWidth);
   791 					s.Append('x');
   792 					s.AppendNum(resolutionList1[res].iPixelSize.iHeight);
   793 					UpdateTitleWindowL(s,3);
   794 					
   795 					iSession.Finish(ETrue);
   796 					Pause(300);
   797 					outerrect.iBr.iX-=5;
   798 					outerrect.iBr.iY-=5;
   799 					iTestBack.SetExtent(outerrect.iTl,outerrect.Size());
   800 					iSession.Finish(ETrue);
   801 					Pause(300);
   802 					TPoint winpos=iCompare.AbsPosition();
   803 					TSize winsize=iCompare.Size();
   804 //					iInfoScreenDevice->ReleaseTwipsCache();
   805 					RepaintTitleWindowL();
   806 					for (TSize z=TSize(1,1);z!=TSize(-1,-1);)
   807 						{
   808 						for (TInt i=0;i<15;i++)
   809 							{
   810 							winpos+=z;
   811 							iCompare.SetExtent(winpos,winsize);
   812 							iSession.Finish(ETrue);
   813 							Pause(100);
   814 							}
   815 						if (z.iHeight && z.iWidth)
   816 							z=TSize(0,-1);
   817 						else
   818 						if (z.iHeight)
   819 							z=TSize(-1,0);
   820 						else
   821 							z=TSize(-1,-1);
   822 						}
   823 					TDisplayConfiguration dispConfigAfter;
   824 					interface->GetConfiguration(dispConfigAfter);
   825 					TSize resAfter;
   826 					TBool ok=dispConfigAfter.GetResolution(resAfter);
   827 					ASSERT_TRUE(ok);
   828 					if (resolutionList1[res].iPixelSize!=resAfter)
   829 						{
   830 						INFO_PRINTF3(_L("Did not receive expected resolution %ix%i"),resolutionList1[res].iPixelSize.iWidth,resolutionList1[res].iPixelSize.iHeight);
   831 						INFO_PRINTF3(_L("Instead got %ix%i"),resAfter.iWidth,resAfter.iHeight);
   832 						}
   833 					}
   834 				}
   835 			if (resolutionList1[res].iPixelSize==resBefore)
   836 				{
   837 				foundBeforeRes=ETrue;
   838 				}
   839 			}
   840 		ASSERT_TRUE(foundBeforeRes);
   841 		//restore initial res
   842 		interface->SetConfiguration(dispConfigBefore);
   843 		Pause(1000);
   844 		TDisplayConfiguration dispConfigAfter;
   845 		interface->GetConfiguration(dispConfigAfter);
   846 		TSize resAfter;
   847 		ok=dispConfigAfter.GetResolution(resAfter);
   848 		ASSERT_TRUE(ok);	
   849 		ASSERT_EQUALS(resBefore,resAfter);
   850 		}
   851 	else
   852 		{
   853 		INFO_PRINTF1(_L("Only 1 resolution configured on this screen - res change test skipped."));
   854 		}
   855 	resolutionList1.Close();
   856 	}
   857 
   858 /**
   859 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0007L
   860 @SYMTestCaseDesc		Coordinates Mapping
   861 @SYMREQ					REQ10336
   862 @SYMPREQ				PREQ2102
   863 @SYMTestType			CT
   864 @SYMTestPurpose			Basic call to mapcoordinates
   865 @SYMTestActions			
   866 	Call mapCoordinates
   867 @SYMTestExpectedResults	
   868 	targetRect should be correctly filled in with same rect as sourceRect
   869 */
   870 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0007L()
   871 	{
   872 	MDisplayMapping* interface = static_cast<MDisplayMapping*>
   873 			(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
   874 	ASSERT_TRUE(interface);
   875 	TRect sourceRect(10, 10, 30, 50);
   876 	TRect targetRect(5,5,10,10);
   877 	TInt err = interface->MapCoordinates(EApplicationSpace, sourceRect, EApplicationSpace, targetRect);
   878 	ASSERT_EQUALS(err, KErrNone);
   879 	ASSERT_EQUALS(sourceRect, targetRect);
   880 	}
   881 
   882 /**
   883 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0008L
   884 @SYMTestCaseDesc		SetModes and mapCoordinates
   885 @SYMREQ					REQ10336
   886 @SYMPREQ				PREQ2102
   887 @SYMTestType			CT
   888 @SYMTestPurpose			Basic SetSizeMode and complex MapCoordinates function
   889 @SYMTestActions			
   890 	Set a new size mode
   891 	Perform many rect conversions using MapCoordinates
   892 @SYMTestExpectedResults	
   893 	Ensure that through multiple conversions, accuracy is not lost
   894 */
   895 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0008L()
   896 	{
   897 	LOG_AND_PANIC_IF_NOT_GCE;
   898 	ResetScreens();
   899 	TInt error;
   900 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0008L"),_L("Change Size Mode"));
   901 
   902     iTestBack=RBlankWindow(iSession);
   903     ASSERT_EQUALS(iTestBack.Construct(iGroup, ++iWindowHandle), KErrNone);
   904     iTestBack.SetRequiredDisplayMode(iDisplayMode);
   905     iTestBack.SetColor(TRgb(255,0,0));
   906     iTestBack.SetExtent(iTestPos.iTl,iTestPos.Size());
   907     iTestBack.Activate();
   908     iTestBack.SetVisible(ETrue);
   909     iSession.Finish(ETrue);
   910 	
   911 	
   912 	if (CWindowGc*	gc=BeginActivateWithWipe(ETrue,iCompare,TRgb(128,128,128)))
   913 		{
   914 		gc->SetPenStyle(gc->ESolidPen);
   915 		gc->SetPenColor(TRgb(255,255,255));
   916 		gc->SetBrushColor(TRgb(0,0,0));
   917 		TRect r(2,2,22,22);
   918 		while(r.Width()>0)
   919 			{
   920 			gc->DrawRect(r);
   921 			r.Shrink(2,2);
   922 			}
   923 		gc->Deactivate();
   924 		iCompare.EndRedraw();
   925 		
   926 		}
   927 	iSession.Finish(ETrue);
   928 	Pause(1000);
   929 	
   930 	MDisplayControl* interface = static_cast<MDisplayControl*>
   931 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
   932 	ASSERT_TRUE(interface);
   933 	
   934 	TInt resolutions = interface->NumberOfResolutions();
   935 	ASSERT_TRUE (resolutions > 0);
   936 	
   937 	RArray<MDisplayControl::TResolution> resolutionList1;
   938 	error = interface->GetResolutions(resolutionList1);
   939 	ASSERT_EQUALS(error,KErrNone);
   940 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
   941 	
   942 	TDisplayConfiguration dispConfigBefore;
   943 	interface->GetConfiguration(dispConfigBefore);
   944 	ASSERT_TRUE(dispConfigBefore.IsDefined(dispConfigBefore.EResolution));
   945 	
   946 	RArray<TInt> screenModeList;
   947 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
   948 	ASSERT_TRUE (screenModeList.Count() > 1);
   949 	iScreenDevice->SetAppScreenMode(screenModeList[1]);
   950 	iScreenDevice->SetScreenMode(screenModeList[1]);
   951 	iSession.Finish(ETrue);
   952 	Pause(1000);
   953 	
   954 	MDisplayMapping* interfaceM = static_cast<MDisplayMapping*>
   955 			(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
   956 	TRect appRect(20, 40, 193, 110);
   957 	TRect uiRect(1,2,3,4);
   958 	TRect compRect(5,6,7,8);
   959 	TRect tempRect(10,11,12,13);
   960 	TInt err;
   961 	while (ETrue)
   962 		{
   963 		//quick get for a print
   964 		err = interfaceM->MapCoordinates(EApplicationSpace, appRect, EFullScreenSpace, uiRect);
   965 		err = interfaceM->MapCoordinates(EApplicationSpace, appRect, ECompositionSpace, compRect);
   966 		
   967 //		print
   968 //		INFO_PRINTF5(_L("appRect : %d , %d - %d , %d"),appRect.iTl.iX,appRect.iTl.iY,appRect.iBr.iX,appRect.iBr.iY);
   969 //		INFO_PRINTF5(_L("uiRect : %d , %d - %d , %d"),uiRect.iTl.iX,uiRect.iTl.iY,uiRect.iBr.iX,uiRect.iBr.iY);
   970 //		INFO_PRINTF5(_L("compRect : %d , %d - %d , %d"),compRect.iTl.iX,compRect.iTl.iY,compRect.iBr.iX,compRect.iBr.iY);
   971 //		INFO_PRINTF1(_L("  "));
   972 		
   973 		//longer process to insure conversions both ways dont lose accuracy
   974 		err = interfaceM->MapCoordinates(EApplicationSpace, appRect, EFullScreenSpace, uiRect);
   975 		err = interfaceM->MapCoordinates(EFullScreenSpace, uiRect, EApplicationSpace, tempRect);
   976 		ASSERT_EQUALS(tempRect,appRect);
   977 		
   978 		err = interfaceM->MapCoordinates(EApplicationSpace, appRect, ECompositionSpace, compRect);
   979 		err = interfaceM->MapCoordinates(ECompositionSpace, compRect, EApplicationSpace, tempRect);
   980 		ASSERT_EQUALS(tempRect,appRect);
   981 		
   982 		err = interfaceM->MapCoordinates(EApplicationSpace, appRect, EFullScreenSpace, uiRect);
   983 		err = interfaceM->MapCoordinates(EFullScreenSpace, uiRect, ECompositionSpace, compRect);
   984 		err = interfaceM->MapCoordinates(ECompositionSpace, compRect, EFullScreenSpace, tempRect);
   985 		ASSERT_EQUALS(tempRect,uiRect);
   986 		
   987 		appRect.iBr.iX--;
   988 		appRect.iBr.iY--;
   989 		if (appRect.IsEmpty())
   990 			{
   991 			break;
   992 			}
   993 		}
   994 	
   995 	TRect rect1(5,5,10,10);
   996 	TRect rect2(15,15,20,20);
   997 	TRect rect3(50,50,50,50);
   998 	//1
   999 	err = interfaceM->MapCoordinates(ECompositionSpace, rect1, ECompositionSpace, rect2);
  1000 	err = interfaceM->MapCoordinates(EFullScreenSpace, rect2, ECompositionSpace, rect3);
  1001 	ASSERT_EQUALS(rect1,rect2);
  1002 	
  1003 	err = interfaceM->MapCoordinates(ECompositionSpace, rect1, EFullScreenSpace, rect2);
  1004 	err = interfaceM->MapCoordinates(EFullScreenSpace, rect2, ECompositionSpace, rect3);
  1005 	ASSERT_EQUALS(rect1,rect3);
  1006 
  1007 	err = interfaceM->MapCoordinates(ECompositionSpace, rect1, EApplicationSpace, rect2);
  1008 	err = interfaceM->MapCoordinates(EApplicationSpace, rect2, ECompositionSpace, rect3);
  1009 	ASSERT_EQUALS(rect1,rect3);
  1010 	
  1011 	err = interfaceM->MapCoordinates(ECompositionSpace, rect1, EDirectScreenAccessSpace, rect2);
  1012 	err = interfaceM->MapCoordinates(EDirectScreenAccessSpace, rect2, ECompositionSpace, rect3);
  1013 	ASSERT_EQUALS(rect1,rect3);
  1014 	
  1015 	//2
  1016 	err = interfaceM->MapCoordinates(EFullScreenSpace, rect1, EFullScreenSpace, rect2);
  1017 	ASSERT_EQUALS(rect1,rect2);
  1018 	
  1019 	err = interfaceM->MapCoordinates(EFullScreenSpace, rect1, EApplicationSpace, rect2);
  1020 	err = interfaceM->MapCoordinates(EApplicationSpace, rect2, EFullScreenSpace, rect3);
  1021 	ASSERT_EQUALS(rect1,rect3);
  1022 	
  1023 	err = interfaceM->MapCoordinates(EFullScreenSpace, rect1, EDirectScreenAccessSpace, rect2);
  1024 	err = interfaceM->MapCoordinates(EDirectScreenAccessSpace, rect2, EFullScreenSpace, rect3);
  1025 	ASSERT_EQUALS(rect1,rect3);
  1026 	
  1027 	//3
  1028 	err = interfaceM->MapCoordinates(EApplicationSpace, rect1, EApplicationSpace, rect2);
  1029 	ASSERT_EQUALS(rect1,rect2);
  1030 	
  1031 	err = interfaceM->MapCoordinates(EApplicationSpace, rect1, EDirectScreenAccessSpace, rect2);
  1032 	err = interfaceM->MapCoordinates(EDirectScreenAccessSpace, rect2, EApplicationSpace, rect3);
  1033 	ASSERT_EQUALS(rect1,rect3);
  1034 	
  1035 	//4
  1036 	err = interfaceM->MapCoordinates(EDirectScreenAccessSpace, rect1, EDirectScreenAccessSpace, rect2);
  1037 	ASSERT_EQUALS(rect1,rect2);
  1038 	
  1039 	//invalid
  1040 	err = interfaceM->MapCoordinates(ECompositionSpace, rect1, (TCoordinateSpace)0, rect2);
  1041 	ASSERT_EQUALS(err,KErrNotSupported);
  1042 	err = interfaceM->MapCoordinates(EFullScreenSpace, rect1, (TCoordinateSpace)0, rect2);
  1043 	ASSERT_EQUALS(err,KErrNotSupported);
  1044 	err = interfaceM->MapCoordinates(EApplicationSpace, rect1, (TCoordinateSpace)0, rect2);
  1045 	ASSERT_EQUALS(err,KErrNotSupported);
  1046 	err = interfaceM->MapCoordinates(EDirectScreenAccessSpace, rect1, (TCoordinateSpace)0, rect2);
  1047 	ASSERT_EQUALS(err,KErrNotSupported);
  1048 	err = interfaceM->MapCoordinates((TCoordinateSpace)0, rect1, EDirectScreenAccessSpace, rect2);
  1049 	ASSERT_EQUALS(err,KErrNotSupported);
  1050 	
  1051 	TDisplayConfiguration dispConfigAfter;
  1052 	interface->GetConfiguration(dispConfigAfter);
  1053 
  1054 	screenModeList.Close();
  1055 	resolutionList1.Close();
  1056 	iScreenDevice->SetAppScreenMode(0);
  1057 	iScreenDevice->SetScreenMode(0);
  1058 	}
  1059 
  1060 /**
  1061 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0009L
  1062 @SYMTestCaseDesc		Set Screen display res using app mode
  1063 @SYMREQ					REQ10336
  1064 @SYMPREQ				PREQ2102
  1065 @SYMTestType			CT
  1066 @SYMTestPurpose			SetScreenMode functions correctly
  1067 @SYMTestActions			
  1068 	Similar to 0006, but setting every available screen mode instead of resolution
  1069 @SYMTestExpectedResults	
  1070 	Every set should work, including modes that involve a rotation!
  1071 */
  1072 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0009L()
  1073 	{
  1074 	LOG_AND_PANIC_IF_NOT_GCE;
  1075 	ResetScreens();
  1076 	TInt error;
  1077 	iSession.Finish(ETrue);
  1078 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0009L"),_L("Change Size Mode"));
  1079 	iSession.Finish(ETrue);
  1080 
  1081     iTestBack=RBlankWindow(iSession);
  1082     ASSERT_EQUALS(iTestBack.Construct(iGroup, ++iWindowHandle), KErrNone);
  1083     iTestBack.SetRequiredDisplayMode(iDisplayMode);
  1084     iTestBack.SetColor(TRgb(255,0,0));
  1085     iTestBack.SetExtent(iTestPos.iTl,iTestPos.Size());
  1086     iTestBack.Activate();
  1087     iTestBack.SetVisible(ETrue);
  1088 	iSession.Finish(ETrue);
  1089 	
  1090 	struct DrawCompare
  1091 		{
  1092 		static void Draw(CWindowGc*	aGc)
  1093 			{
  1094 			aGc->SetPenStyle(aGc->ESolidPen);
  1095 			aGc->SetPenColor(TRgb(255,255,255));
  1096 			aGc->SetBrushColor(TRgb(0,0,0));
  1097 			TRect r(2,2,82,82);
  1098 			while(r.Width()>0)
  1099 				{
  1100 				aGc->DrawRect(r);
  1101 				r.Shrink(2,2);
  1102 				}
  1103 			}
  1104 		};
  1105 	TSurfaceId surfaceID;
  1106 	TRAPD(err, surfaceID = iUtility->CreateSurfaceL(TSize(200,200), 
  1107 			KSurfaceFormat, 200 * KBytesPerPixel));
  1108 	ASSERT_EQUALS(err,KErrNone);
  1109 	TRAP(err,iUtility->FanFillSurfaceL(surfaceID,iYellow,iRed,iMagenta));
  1110 	ASSERT_EQUALS(err,KErrNone);
  1111 	TSurfaceConfiguration surfConf;
  1112 	surfConf.SetSurfaceId(surfaceID);
  1113 	
  1114 	surfConf.SetExtent(TRect(2,84,82,166));
  1115 	iCompare.SetBackgroundSurface(surfConf,EFalse);
  1116 	
  1117 	if (CWindowGc*	gc=BeginActivateWithWipe(ETrue,iCompare,TRgb(128,128,128)))
  1118 		{
  1119 		DrawCompare::Draw(gc);
  1120 		gc->Deactivate();
  1121 		iCompare.EndRedraw();
  1122 		
  1123 		}
  1124 	iSession.Finish(ETrue);
  1125 	Pause(1000);
  1126 	RArray<TInt> screenModeList;
  1127 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  1128 	MDisplayControl* interface = static_cast<MDisplayControl*>
  1129 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  1130 	ASSERT_TRUE(interface);
  1131 	
  1132 	TInt resolutions = interface->NumberOfResolutions();
  1133 	ASSERT_TRUE (resolutions > 0);
  1134 	
  1135 	RArray<MDisplayControl::TResolution> resolutionList1;
  1136 	error = interface->GetResolutions(resolutionList1);
  1137 	ASSERT_EQUALS(error,KErrNone);
  1138 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  1139 	
  1140 	TDisplayConfiguration dispConfigBefore;
  1141 	interface->GetConfiguration(dispConfigBefore);
  1142 	ASSERT_TRUE(dispConfigBefore.IsDefined(dispConfigBefore.EResolution))
  1143 	if (screenModeList.Count()>1)
  1144 		{
  1145 		//Got a mode to change to!
  1146 		TSize resBefore;
  1147 		TBool ok=dispConfigBefore.GetResolution(resBefore);
  1148 		ASSERT_TRUE(ok);	//we "know" this should be ok, as we just asserted the flag
  1149 		for (TInt res=0;res<screenModeList.Count();res++)
  1150 			{
  1151 				{
  1152 					{
  1153 					TDisplayConfiguration dispConfigReq;
  1154 					iInfoScreenDevice->SetAppScreenMode(screenModeList[res]);
  1155 					iInfoScreenDevice->SetScreenMode(screenModeList[res]);
  1156 					iSession.Finish(ETrue);
  1157 					Pause(300);
  1158 					
  1159 					TPixelsAndRotation pr;
  1160 					iInfoScreenDevice->GetDefaultScreenSizeAndRotation(pr);
  1161 					TPoint 	origin=iInfoScreenDevice->GetDefaultScreenModeOrigin();
  1162 					Pause(300);
  1163 					
  1164 					if (CWindowGc*	gc=BeginActivateWithWipe(ETrue,iCompare,TRgb(128,128,128)))
  1165 						{
  1166 						DrawCompare::Draw(gc);
  1167 						gc->Deactivate();
  1168 						iCompare.EndRedraw();
  1169 						}
  1170 					if (iTitle.WsHandle())
  1171 						{
  1172 						TPoint	infoWinPos;
  1173 						TSize	infoWinSize;
  1174 						infoWinPos=iTitle.AbsPosition();
  1175 						infoWinSize=iTitle.Size();
  1176 						infoWinSize.iHeight=pr.iPixelSize.iHeight-2*infoWinPos.iY;
  1177 						iTitle.SetSize(infoWinSize);
  1178 						}
  1179 					TBuf16<20> s;
  1180 					s.AppendNum(res);
  1181 					UpdateTitleWindowL(s,1);
  1182 					s.Zero();
  1183 					s.AppendNum(pr.iPixelSize.iWidth);
  1184 					s.Append('x');
  1185 					s.AppendNum(pr.iPixelSize.iHeight);
  1186 					UpdateTitleWindowL(s,2);
  1187 					s.Zero();
  1188 					s.AppendNum(origin.iX);
  1189 					s.Append(',');
  1190 					s.AppendNum(origin.iY);
  1191 					UpdateTitleWindowL(s,3);
  1192 					
  1193 					iSession.Finish(ETrue);
  1194 					Pause(300);
  1195 					
  1196 					TPoint winpos=iCompare.AbsPosition();
  1197 					TSize winsize=iCompare.Size();
  1198 
  1199 					for (TSize z=TSize(1,1);z!=TSize(-1,-1);)
  1200 						{
  1201 						for (TInt i=0;i<15;i++)
  1202 							{
  1203 							winpos+=z;
  1204 							iCompare.SetExtent(winpos,winsize);
  1205 							iSession.Finish(ETrue);
  1206 							Pause(100);
  1207 							}
  1208 						if (z.iHeight && z.iWidth)
  1209 							z=TSize(0,-1);
  1210 						else
  1211 						if (z.iHeight)
  1212 							z=TSize(-1,0);
  1213 						else
  1214 							z=TSize(-1,-1);
  1215 						}
  1216 					}
  1217 				}
  1218 			}
  1219 		//restore initial res
  1220 		if (screenModeList.Count() > 1)
  1221             {   //set back to basics
  1222             iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  1223             iInfoScreenDevice->SetScreenMode(screenModeList[0]);
  1224             Pause(300);
  1225             }
  1226 		
  1227 		interface->SetConfiguration(dispConfigBefore);
  1228 		Pause(1000);
  1229 		TDisplayConfiguration dispConfigAfter;
  1230 		interface->GetConfiguration(dispConfigAfter);
  1231 		TSize resAfter;
  1232 		ok=dispConfigAfter.GetResolution(resAfter);
  1233 		ASSERT_TRUE(ok);	
  1234 		ASSERT_EQUALS(resBefore,resAfter);
  1235 		}
  1236 	else
  1237 		{
  1238 		INFO_PRINTF1(_L("Only 1 screen size mode configured on this screen - res change test skipped."));
  1239 		}
  1240 
  1241 	screenModeList.Close();
  1242 	resolutionList1.Close();
  1243 	}
  1244 
  1245 /**
  1246 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0010L
  1247 @SYMTestCaseDesc		Test app mode setting during attach/detach
  1248 @SYMREQ					REQ10330
  1249 @SYMPREQ				PREQ2102
  1250 @SYMTestType			CT
  1251 @SYMTestPurpose			Make sure display resumes last app mode when reattached
  1252 @SYMTestActions			
  1253 	Save app mode and display configuration before detach and compare it with those after reattach.
  1254 	Repeat for a second app mode
  1255 	If available, repeat with dynamic app mode
  1256 @SYMTestExpectedResults	
  1257 	For normal app mode, on reconnect it should re apply the old configuration
  1258 	For dynamic app mode, on reconnect it should be 0x0	
  1259 */
  1260 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0010L()
  1261 	{
  1262 	LOG_AND_PANIC_IF_NOT_GCE;
  1263 	ResetScreens();
  1264 #ifdef MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
  1265 	ASSERT_FALSE("Test not compiled because MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER");
  1266 #else
  1267 	TInt error;
  1268 	iSession.Finish(ETrue);
  1269 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0010L"),_L("detach/attach"));
  1270 	iSession.Finish(ETrue);
  1271 
  1272 	Pause(1000);
  1273 	TInt screenNo = iScreenDevice->GetScreenNumber();
  1274 	RArray<TInt> screenModeList;
  1275 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  1276 	
  1277 	//Find 2 real app modes and 1 dynamic app mode
  1278 	TInt firstAvailableAppMode = -1;
  1279 	TInt secondAvailableAppMode = -1;
  1280 	TInt dynamicAppMode = -1;
  1281 	for (TInt ii = 0; ii < screenModeList.Count(); ii++)
  1282 		{
  1283 		TBool dynamic = iInfoScreenDevice->IsModeDynamic(screenModeList[ii]);
  1284 		if (dynamic && dynamicAppMode == -1)
  1285 			{
  1286 			dynamicAppMode = screenModeList[ii];
  1287 			}
  1288 		if (!dynamic)
  1289 			{
  1290 			if (firstAvailableAppMode == -1)
  1291 				{
  1292 				firstAvailableAppMode = screenModeList[ii];
  1293 				}
  1294 			else if (secondAvailableAppMode == -1)
  1295 				{
  1296 				secondAvailableAppMode = screenModeList[ii];
  1297 				}
  1298 			}
  1299 		}
  1300 	ASSERT_TRUE(firstAvailableAppMode!=-1);
  1301 	ASSERT_TRUE(secondAvailableAppMode!=-1);
  1302 	
  1303 	MDisplayControl* interface = static_cast<MDisplayControl*>
  1304 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  1305 	ASSERT_TRUE(interface);
  1306 	
  1307 	MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  1308 				(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  1309 	ASSERT_TRUE(mappingInterface);
  1310 	
  1311 	TInt resolutions = interface->NumberOfResolutions();
  1312 	ASSERT_TRUE (resolutions > 0);
  1313 	
  1314 	RArray<MDisplayControl::TResolution> resolutionList1;
  1315 	error = interface->GetResolutions(resolutionList1);
  1316 	ASSERT_EQUALS(error,KErrNone);
  1317 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  1318 	
  1319 	TDisplayConfiguration configBeforeDetach, configAfterReattach;
  1320 	TInt appModeBeforeDetach, appModeAfterReattach;
  1321 
  1322 	//
  1323 	//1st detach - attach sequence
  1324 	appModeBeforeDetach = firstAvailableAppMode;
  1325 	iScreenDevice->SetAppScreenMode(appModeBeforeDetach );
  1326 	iScreenDevice->SetScreenMode(appModeBeforeDetach );
  1327 	Pause(200);
  1328 	interface->GetConfiguration(configBeforeDetach);
  1329 	
  1330 	TInt displayState = EDisconnect;
  1331 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1332 	Pause(300);
  1333 	
  1334 	//dummy mapping should return KErrNotReady if display is disconnected
  1335 	TRect dummyRect(1,2,5,8);
  1336 	error = mappingInterface->MapCoordinates(ECompositionSpace, dummyRect, EFullScreenSpace, dummyRect);
  1337 	ASSERT_EQUALS(error, KErrNotReady);
  1338 	
  1339 	displayState = ENormalResolution;
  1340 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1341 	Pause(300);
  1342 	
  1343 	interface->GetConfiguration(configAfterReattach);
  1344 	ASSERT_TRUE(configBeforeDetach==configAfterReattach);
  1345 	appModeAfterReattach = iScreenDevice->CurrentScreenMode();
  1346 	ASSERT_EQUALS(appModeBeforeDetach, appModeAfterReattach);
  1347 	//1st detach - attach sequence ends here
  1348 	//
  1349 	
  1350 	configBeforeDetach.ClearAll();
  1351 	configAfterReattach.ClearAll();
  1352 	
  1353 	//
  1354 	//2nd detach-attach sequence - non dynamic app mode
  1355 	iScreenDevice->SetAppScreenMode(secondAvailableAppMode);
  1356 	iScreenDevice->SetScreenMode(secondAvailableAppMode);
  1357 	Pause(200);
  1358 	appModeBeforeDetach = iScreenDevice->CurrentScreenMode();
  1359 	interface->GetConfiguration(configBeforeDetach);
  1360 	displayState = EDisconnect;
  1361 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1362 	Pause(300);
  1363 	//dummy mapping should return KErrNotReady if display is disconnected
  1364 	error = mappingInterface->MapCoordinates(ECompositionSpace, dummyRect, EFullScreenSpace, dummyRect);
  1365 	ASSERT_EQUALS(error, KErrNotReady);
  1366 	
  1367 	displayState = ENoResolution;
  1368 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1369 	Pause(300);
  1370 	//dummy mapping should return KErrNotReady if display is disconnected
  1371 	error = mappingInterface->MapCoordinates(ECompositionSpace, dummyRect, EFullScreenSpace, dummyRect);
  1372 	ASSERT_EQUALS(error, KErrNotReady);
  1373 	
  1374 	displayState = ENormalResolution;
  1375 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1376 	Pause(300);
  1377 	
  1378 	interface->GetConfiguration(configAfterReattach);
  1379 	ASSERT_TRUE(configBeforeDetach==configAfterReattach);
  1380 	appModeAfterReattach = iScreenDevice->CurrentScreenMode();
  1381 	ASSERT_EQUALS(appModeBeforeDetach, appModeAfterReattach);
  1382 	//2nd detach-attach sequence ends here
  1383 	//
  1384 	
  1385 	configBeforeDetach.ClearAll();
  1386 	configAfterReattach.ClearAll();
  1387 	
  1388 	//
  1389 	//3rd detach-attach sequence - dynamic app mode
  1390 	if (dynamicAppMode == -1)
  1391 		{
  1392 		screenModeList.Close();
  1393 		resolutionList1.Close();
  1394 		INFO_PRINTF1(_L("No dynamic app mode, end test"));	//not a fail if there isn't a dynamic app mode
  1395 		return;
  1396 		}
  1397 	
  1398 	iScreenDevice->SetAppScreenMode(dynamicAppMode);
  1399 	iScreenDevice->SetScreenMode(dynamicAppMode);
  1400 	Pause(200);
  1401 	appModeBeforeDetach = iScreenDevice->CurrentScreenMode();
  1402 	interface->GetConfiguration(configBeforeDetach);
  1403 	displayState = EDisconnect;
  1404 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1405 	Pause(300);
  1406 	//dummy mapping should return KErrNotReady if display is disconnected
  1407 	error = mappingInterface->MapCoordinates(ECompositionSpace, dummyRect, EFullScreenSpace, dummyRect);
  1408 	ASSERT_EQUALS(error, KErrNotReady);
  1409 	
  1410 	displayState = ENoResolution;
  1411 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1412 	Pause(300);
  1413 	//dummy mapping should return KErrNotReady if display is disconnected
  1414 	error = mappingInterface->MapCoordinates(ECompositionSpace, dummyRect, EFullScreenSpace, dummyRect);
  1415 	ASSERT_EQUALS(error, KErrNotReady);
  1416 	
  1417 	displayState = ENormalResolution;
  1418 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  1419 	Pause(300);
  1420 	
  1421 	interface->GetConfiguration(configAfterReattach);
  1422 	ASSERT_FALSE(configBeforeDetach==configAfterReattach);
  1423 	TSize afterReattachSize;
  1424 	ASSERT_TRUE(configAfterReattach.GetResolution(afterReattachSize));
  1425 	ASSERT_EQUALS(afterReattachSize,TSize(0,0));
  1426 	ASSERT_TRUE(configAfterReattach.GetResolutionTwips(afterReattachSize));
  1427 	ASSERT_EQUALS(afterReattachSize,TSize(0,0));
  1428 	
  1429 	appModeAfterReattach = iScreenDevice->CurrentScreenMode();
  1430 	ASSERT_EQUALS(appModeBeforeDetach, appModeAfterReattach);
  1431 	//3rd detach-attach sequence ends here
  1432 	//
  1433 	
  1434 	screenModeList.Close();
  1435 	resolutionList1.Close();
  1436 #endif
  1437 	}
  1438 
  1439 
  1440 CDSATestDrawing::CDSATestDrawing():CTimer(EPriorityStandard)
  1441 	{}
  1442 
  1443 CDSATestDrawing::~CDSATestDrawing()
  1444 	{
  1445 	Cancel();
  1446 	}
  1447 CDSATestDrawing* CDSATestDrawing::NewL()
  1448 	{
  1449 	CDSATestDrawing *self = new(ELeave) CDSATestDrawing();
  1450 	CleanupStack::PushL(self);
  1451 	self->ConstructL();
  1452 	CleanupStack::Pop(self);
  1453 	return self;
  1454 	}
  1455 
  1456 void CDSATestDrawing::ConstructL()
  1457 	{
  1458 	CTimer::ConstructL();
  1459 	CActiveScheduler::Add(this);
  1460 	}
  1461 
  1462 void CDSATestDrawing::StartDrawingL(CDirectScreenAccess *aDSA)
  1463 	{
  1464 	
  1465 	if(aDSA)
  1466 		{
  1467 		iDSA = aDSA;
  1468 		}
  1469 	
  1470 	if(iDSA)
  1471 		{
  1472 		iDSA->StartL();
  1473 		
  1474 		iRect = TRect(TPoint(0,0), iDSA->DrawingRegion()->BoundingRect().Size());
  1475 		
  1476 		iWin->Invalidate();
  1477 		iWin->BeginRedraw();
  1478 		CFbsBitGc* gc = iDSA->Gc();
  1479 		gc->SetBrushColor(TRgb(220,220,220));
  1480 		gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
  1481 		gc->Clear();
  1482 		iWin->EndRedraw();
  1483 		After(500000);
  1484 		}
  1485 	
  1486 	}
  1487 
  1488 void CDSATestDrawing::RunL()
  1489 	{
  1490 	Draw();
  1491 	After(500000);
  1492 	}
  1493 
  1494 void CDSATestDrawing::Draw()
  1495 	{
  1496 	//Should not invalidate the window containing DSA drawing. That's the whole point!
  1497 	CFbsBitGc* gc = iDSA->Gc();
  1498 	gc->SetPenStyle(gc->ESolidPen);
  1499 	gc->SetPenColor(TRgb(255,0,0));
  1500 	gc->SetBrushStyle(gc->ENullBrush);
  1501 	iRect.Shrink(1, 1);
  1502 	gc->DrawRect(iRect);
  1503 	iDSA->ScreenDevice()->Update();
  1504 	
  1505 	}
  1506 void CDSATestDrawing::Restart(RDirectScreenAccess::TTerminationReasons /*aReason*/) 
  1507 	{
  1508 	
  1509 	StartDrawingL(NULL);
  1510 	}
  1511 
  1512 void CDSATestDrawing::AbortNow(RDirectScreenAccess::TTerminationReasons /*aReason*/)
  1513 	{
  1514 	Cancel();
  1515 	}
  1516 
  1517 /**
  1518 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0011L
  1519 @SYMTestCaseDesc		Test DSA drawing in different App Mode
  1520 @SYMREQ					REQ10332 REQ10336
  1521 @SYMPREQ				PREQ2102
  1522 @SYMTestType			CT
  1523 @SYMTestPurpose			Test DSA can restart and draw at correct place when screen mode changes
  1524 @SYMTestActions			
  1525 	A rectangle will be drawn 1 pixel inside the DSA drawing region, and continue to shrink before the drawing
  1526 	time runs out. when screen mode changes, DSA should restart and the rectangle should be reset to 1 pixel inside
  1527 	the new drawing region.
  1528 	
  1529 	note: DSA drawing region is clipped by DSA buffer, App Size and the visible area of the window which it drawns in
  1530 @SYMTestExpectedResults	
  1531 	All tests should pass.
  1532 	
  1533 */
  1534 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0011L()
  1535 	{
  1536 	LOG_AND_PANIC_IF_NOT_GCE;
  1537 	ResetScreens();
  1538 
  1539 	Pause(1000);
  1540 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0011L"),_L("DSA drawing"));
  1541 	CDSATestDrawing *dsaDraw = CDSATestDrawing::NewL();
  1542 	CleanupStack::PushL(dsaDraw);
  1543 	CDirectScreenAccess *dsa = CDirectScreenAccess::NewL(iSession, *iScreenDevice, iCompare, *dsaDraw);
  1544 	CleanupStack::PushL(dsa);
  1545 	dsaDraw->SetWindow(iCompare);
  1546 	dsaDraw->StartDrawingL(dsa);
  1547 	
  1548 	CEventTimer *timer = CEventTimer::NewL();
  1549 	CleanupStack::PushL(timer);
  1550 	
  1551 	RArray<TInt> screenModeList;
  1552 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  1553 	MDisplayControl* interface = static_cast<MDisplayControl*>
  1554 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  1555 	ASSERT_TRUE(interface);
  1556 	
  1557 	MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  1558 				(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  1559 	ASSERT_TRUE(mappingInterface);
  1560 	
  1561 	CFbsScreenDevice *pixelReadBackDevice = CFbsScreenDevice::NewL(iScreenDevice->GetScreenNumber(), iScreenDevice->DisplayMode());
  1562 	CleanupStack::PushL(pixelReadBackDevice);
  1563 	
  1564 	for (TInt res=0;res<screenModeList.Count();res++)
  1565 		{
  1566 		iScreenDevice->SetAppScreenMode(screenModeList[res]);
  1567 		iScreenDevice->SetScreenMode(screenModeList[res]);
  1568 		dsa->ScreenDevice()->Update();
  1569 		Pause(300);
  1570 		//wait for DSA to restart
  1571 		timer->Wait(500000);
  1572 		TRect regionRect(dsa->DrawingRegion()->BoundingRect());
  1573 
  1574 		TPoint winpos = iCompare.AbsPosition();
  1575 		TSize winsize = iCompare.Size();
  1576 		
  1577 		TPixelsAndRotation pr;
  1578 		iInfoScreenDevice->GetDefaultScreenSizeAndRotation(pr);
  1579 		TPoint 	origin=iInfoScreenDevice->GetDefaultScreenModeOrigin();
  1580 		Pause(300);
  1581 		if (iTitle.WsHandle())
  1582 			{
  1583 			TPoint	infoWinPos;
  1584 			TSize	infoWinSize;
  1585 			infoWinPos=iTitle.AbsPosition();
  1586 			infoWinSize=iTitle.Size();
  1587 			infoWinSize.iHeight=pr.iPixelSize.iHeight-2*infoWinPos.iY;
  1588 			iTitle.SetSize(infoWinSize);
  1589 			}
  1590 		TBuf16<20> s;
  1591 		s.AppendNum(res);
  1592 		UpdateTitleWindowL(s,1);
  1593 		s.Zero();
  1594 		s.AppendNum(pr.iPixelSize.iWidth);
  1595 		s.Append('x');
  1596 		s.AppendNum(pr.iPixelSize.iHeight);
  1597 		UpdateTitleWindowL(s,2);
  1598 		s.Zero();
  1599 		s.AppendNum(origin.iX);
  1600 		s.Append(',');
  1601 		s.AppendNum(origin.iY);
  1602 		UpdateTitleWindowL(s,3);
  1603 		
  1604 		INFO_PRINTF2(_L("---------test %i---------"), res);
  1605 		INFO_PRINTF3(_L("resolution %i x %i"), pr.iPixelSize.iWidth, pr.iPixelSize.iHeight);
  1606 		INFO_PRINTF3(_L("Origin (%i, %i)"), origin.iX, origin.iY);
  1607 		//INFO_PRINTF3(_L("Test Window Origin (%i, %i)"), iCompare.AbsPosition().iX, iCompare.AbsPosition().iY);
  1608 		INFO_PRINTF3(_L("DSA drawing region bounding rect origin (%i, %i)"), dsa->DrawingRegion()->BoundingRect().iTl.iX,
  1609 				dsa->DrawingRegion()->BoundingRect().iTl.iY);
  1610 		INFO_PRINTF3(_L("DSA drawing region bounding rect size (%i x %i)"), dsa->DrawingRegion()->BoundingRect().Width(),
  1611 						dsa->DrawingRegion()->BoundingRect().Height());
  1612 		//give time so DSA AO can start drawing
  1613 		timer->Wait(5000000);
  1614 		
  1615 
  1616 		TRect readBackRect;
  1617 		mappingInterface->MapCoordinates(EApplicationSpace, TRect(0,0,1,1), EDirectScreenAccessSpace, readBackRect);
  1618 		pixelReadBackDevice->SetDrawDeviceOffset(readBackRect.iTl);
  1619 		pixelReadBackDevice->SetDeviceOrientation((TDeviceOrientation)(1 << pr.iRotation));
  1620 		readBackRect.SetRect(dsa->DrawingRegion()->BoundingRect().iTl, dsa->DrawingRegion()->BoundingRect().iBr);
  1621 		
  1622 		if(readBackRect.IsEmpty())
  1623 			{
  1624 			INFO_PRINTF1(_L("DSA drawing region is empty, skip checking pixel colour"));
  1625 			continue;
  1626 			}
  1627 		
  1628 		//Ruo: Oh I almost believe iBr is exclusive now
  1629 		TDisplayConfiguration dispConfigAfter2;
  1630 		interface->GetConfiguration(dispConfigAfter2);
  1631 		TSize theSize;
  1632 		dispConfigAfter2.GetResolution(theSize);
  1633 		TDisplayConfiguration1::TRotation orient;
  1634 		dispConfigAfter2.GetRotation(orient);
  1635 		if (orient == TDisplayConfiguration1::ERotation90CW || orient == TDisplayConfiguration1::ERotation270CW)
  1636 			{
  1637 			TInt temp = theSize.iHeight;
  1638 			theSize.iHeight = theSize.iWidth;
  1639 			theSize.iWidth = temp;
  1640 			}
  1641 		TRect uiSize(TPoint(0,0), theSize);
  1642 		MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  1643 					(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  1644 		ASSERT_TRUE(mappingInterface);
  1645 		TRect finalSize;
  1646 		mappingInterface->MapCoordinates(EApplicationSpace, uiSize, ECompositionSpace, finalSize);
  1647 				
  1648 		CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  1649 		CleanupStack::PushL(bmp2);
  1650 		User::LeaveIfError(bmp2->Create(finalSize.Size(), EColor16MU));
  1651 		MTestScreenCapture
  1652 				* csc =
  1653 						static_cast<MTestScreenCapture*> (iScreenDevice->GetInterface(MTestScreenCapture::KUidTestScreenCaptureIf));
  1654 	
  1655 		if (csc)
  1656 			{
  1657 			TInt errr = csc->ComposeScreen(*bmp2);
  1658 			ASSERT_TRUE(errr == KErrNone);
  1659 			}
  1660 		else
  1661 			{
  1662 			if (!cSCLogged)
  1663 				{
  1664 				cSCLogged = ETrue;
  1665 				_LIT(KNoCSC, "CSC testing not enabled as CSC render stage not defined");
  1666 				Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrAll, KNoCSC);
  1667 				}
  1668 			}
  1669 
  1670 		readBackRect.iBr = readBackRect.iBr - TPoint(1,1);
  1671 		//check 4 outter corners
  1672 		TRgb pixelRgb;
  1673 		TRgb cornerRgb(220, 220, 220);
  1674 		TRgb innerRgb(255, 0, 0);
  1675 		readBackRect.Grow(1, 1);
  1676 		TRect compSpaceReadBackRect;
  1677 		mappingInterface->MapCoordinates(EApplicationSpace, readBackRect, ECompositionSpace, compSpaceReadBackRect);
  1678 
  1679 			
  1680 		if (csc)
  1681 			{
  1682 			if (finalSize.Contains(compSpaceReadBackRect.iTl))
  1683 				{
  1684 				bmp2->GetPixel(pixelRgb, compSpaceReadBackRect.iTl);
  1685 				if(!(pixelRgb != cornerRgb))
  1686 					{
  1687 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1688 					TBuf<256> x;
  1689 					x.Format(KCompareFailed, res+1);
  1690 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1691 					CleanupStack::PopAndDestroy(bmp2);
  1692 					continue;
  1693 					}
  1694 				}
  1695 			if (finalSize.Contains(TPoint(compSpaceReadBackRect.iBr.iX, compSpaceReadBackRect.iTl.iY)))
  1696 				{
  1697 				bmp2->GetPixel(pixelRgb, TPoint(compSpaceReadBackRect.iBr.iX, compSpaceReadBackRect.iTl.iY));
  1698 				if(!(pixelRgb != cornerRgb))
  1699 					{
  1700 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1701 					TBuf<256> x;
  1702 					x.Format(KCompareFailed, res+1);
  1703 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1704 					CleanupStack::PopAndDestroy(bmp2);
  1705 					continue;
  1706 					}
  1707 				}
  1708 			if (finalSize.Contains(compSpaceReadBackRect.iBr))
  1709 				{
  1710 				bmp2->GetPixel(pixelRgb, compSpaceReadBackRect.iBr);
  1711 				if(!(pixelRgb != cornerRgb))
  1712 					{
  1713 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1714 					TBuf<256> x;
  1715 					x.Format(KCompareFailed, res+1);
  1716 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1717 					CleanupStack::PopAndDestroy(bmp2);
  1718 					continue;
  1719 					}
  1720 				}
  1721 			if (finalSize.Contains(TPoint(compSpaceReadBackRect.iTl.iX, compSpaceReadBackRect.iBr.iY)))
  1722 				{
  1723 				bmp2->GetPixel(pixelRgb, TPoint(compSpaceReadBackRect.iTl.iX, compSpaceReadBackRect.iBr.iY));
  1724 				if(!(pixelRgb != cornerRgb))
  1725 					{
  1726 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1727 					TBuf<256> x;
  1728 					x.Format(KCompareFailed, res+1);
  1729 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1730 					CleanupStack::PopAndDestroy(bmp2);
  1731 					continue;
  1732 					}
  1733 				}
  1734 			}
  1735 		
  1736 		pixelReadBackDevice->GetPixel(pixelRgb, readBackRect.iTl);
  1737 		ASSERT_TRUE(pixelRgb != cornerRgb);
  1738 		pixelReadBackDevice->GetPixel(pixelRgb, TPoint(readBackRect.iBr.iX, readBackRect.iTl.iY));
  1739 		ASSERT_TRUE(pixelRgb != cornerRgb);
  1740 		pixelReadBackDevice->GetPixel(pixelRgb, readBackRect.iBr);
  1741 		ASSERT_TRUE(pixelRgb != cornerRgb);
  1742 		pixelReadBackDevice->GetPixel(pixelRgb, TPoint(readBackRect.iTl.iX, readBackRect.iBr.iY));
  1743 		ASSERT_TRUE(pixelRgb != cornerRgb);
  1744 		
  1745 		//check 4 inner corners
  1746 		readBackRect.Shrink(1,1);
  1747 		mappingInterface->MapCoordinates(EApplicationSpace, readBackRect, ECompositionSpace, compSpaceReadBackRect);
  1748 	
  1749 		if (csc)
  1750 			{
  1751 			if (finalSize.Contains(compSpaceReadBackRect.iTl))
  1752 				{
  1753 				bmp2->GetPixel(pixelRgb, compSpaceReadBackRect.iTl);
  1754 				if(!(pixelRgb == cornerRgb))
  1755 					{
  1756 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1757 					TBuf<256> x;
  1758 					x.Format(KCompareFailed, res+1);
  1759 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1760 					CleanupStack::PopAndDestroy(bmp2);
  1761 					continue;
  1762 					}
  1763 				}
  1764 			if (finalSize.Contains(TPoint(compSpaceReadBackRect.iBr.iX, compSpaceReadBackRect.iTl.iY)))
  1765 				{
  1766 				bmp2->GetPixel(pixelRgb, TPoint(compSpaceReadBackRect.iBr.iX, compSpaceReadBackRect.iTl.iY));
  1767 				if(!(pixelRgb == cornerRgb))
  1768 					{
  1769 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1770 					TBuf<256> x;
  1771 					x.Format(KCompareFailed, res+1);
  1772 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1773 					CleanupStack::PopAndDestroy(bmp2);
  1774 					continue;
  1775 					}
  1776 				}
  1777 			if (finalSize.Contains(compSpaceReadBackRect.iBr))
  1778 				{
  1779 				bmp2->GetPixel(pixelRgb, compSpaceReadBackRect.iBr);
  1780 				if(!(pixelRgb == cornerRgb))
  1781 					{
  1782 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1783 					TBuf<256> x;
  1784 					x.Format(KCompareFailed, res+1);
  1785 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1786 					CleanupStack::PopAndDestroy(bmp2);
  1787 					continue;
  1788 					}
  1789 				}
  1790 			if (finalSize.Contains(TPoint(compSpaceReadBackRect.iTl.iX, compSpaceReadBackRect.iBr.iY)))
  1791 				{
  1792 				bmp2->GetPixel(pixelRgb, TPoint(compSpaceReadBackRect.iTl.iX, compSpaceReadBackRect.iBr.iY));
  1793 				if(!(pixelRgb == cornerRgb))
  1794 					{
  1795 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1796 					TBuf<256> x;
  1797 					x.Format(KCompareFailed, res+1);
  1798 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1799 					CleanupStack::PopAndDestroy(bmp2);
  1800 					continue;
  1801 					}
  1802 				}
  1803 			}
  1804 		
  1805 		pixelReadBackDevice->GetPixel(pixelRgb, readBackRect.iTl);
  1806 		ASSERT_TRUE(pixelRgb == cornerRgb);
  1807 		pixelReadBackDevice->GetPixel(pixelRgb, TPoint(readBackRect.iBr.iX, readBackRect.iTl.iY));
  1808 		ASSERT_TRUE(pixelRgb == cornerRgb);
  1809 		pixelReadBackDevice->GetPixel(pixelRgb, readBackRect.iBr);
  1810 		ASSERT_TRUE(pixelRgb == cornerRgb);
  1811 		pixelReadBackDevice->GetPixel(pixelRgb, TPoint(readBackRect.iTl.iX, readBackRect.iBr.iY));
  1812 		ASSERT_TRUE(pixelRgb == cornerRgb);
  1813 		//check inner colour
  1814 		if(readBackRect.Width() < 3 || readBackRect.Height() < 3)
  1815 			{
  1816 			INFO_PRINTF1(_L("DSA drawing region is too small for drawing inner rectangle skip checking inner colour"));
  1817 			CleanupStack::PopAndDestroy(bmp2);
  1818 			continue;
  1819 			}
  1820 		
  1821 		readBackRect.Shrink(1,1);
  1822 		mappingInterface->MapCoordinates(EApplicationSpace, readBackRect, ECompositionSpace, compSpaceReadBackRect);
  1823 		
  1824 		if (csc)
  1825 			{
  1826 			if (finalSize.Contains(compSpaceReadBackRect.iTl))
  1827 				{
  1828 				bmp2->GetPixel(pixelRgb, compSpaceReadBackRect.iTl);
  1829 				if(!(pixelRgb == innerRgb))
  1830 					{
  1831 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1832 					TBuf<256> x;
  1833 					x.Format(KCompareFailed, res+1);
  1834 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1835 					CleanupStack::PopAndDestroy(bmp2);
  1836 					continue;
  1837 					}
  1838 				}
  1839 			if (finalSize.Contains(TPoint(compSpaceReadBackRect.iBr.iX, compSpaceReadBackRect.iTl.iY)))
  1840 				{
  1841 				bmp2->GetPixel(pixelRgb, TPoint(compSpaceReadBackRect.iBr.iX, compSpaceReadBackRect.iTl.iY));
  1842 				if(!(pixelRgb == innerRgb))
  1843 					{
  1844 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1845 					TBuf<256> x;
  1846 					x.Format(KCompareFailed, res+1);
  1847 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1848 					CleanupStack::PopAndDestroy(bmp2);
  1849 					continue;
  1850 					}
  1851 				}
  1852 			if (finalSize.Contains(compSpaceReadBackRect.iBr))
  1853 				{
  1854 				bmp2->GetPixel(pixelRgb, compSpaceReadBackRect.iBr);
  1855 				if(!(pixelRgb == innerRgb))
  1856 					{
  1857 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1858 					TBuf<256> x;
  1859 					x.Format(KCompareFailed, res+1);
  1860 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1861 					CleanupStack::PopAndDestroy(bmp2);
  1862 					continue;
  1863 					}
  1864 				}
  1865 			if (finalSize.Contains(TPoint(compSpaceReadBackRect.iTl.iX, compSpaceReadBackRect.iBr.iY)))
  1866 				{
  1867 				bmp2->GetPixel(pixelRgb, TPoint(compSpaceReadBackRect.iTl.iX, compSpaceReadBackRect.iBr.iY));
  1868 				if(!(pixelRgb == innerRgb))
  1869 					{
  1870 					_LIT(KCompareFailed, "Corner check failed on app mode: %d");
  1871 					TBuf<256> x;
  1872 					x.Format(KCompareFailed, res+1);
  1873 					Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  1874 					CleanupStack::PopAndDestroy(bmp2);
  1875 					continue;
  1876 					}
  1877 				}
  1878 			}
  1879 		
  1880 		pixelReadBackDevice->GetPixel(pixelRgb, readBackRect.iTl);
  1881 		ASSERT_TRUE(pixelRgb == innerRgb);
  1882 		pixelReadBackDevice->GetPixel(pixelRgb, TPoint(readBackRect.iBr.iX, readBackRect.iTl.iY));
  1883 		ASSERT_TRUE(pixelRgb == innerRgb);
  1884 		pixelReadBackDevice->GetPixel(pixelRgb, readBackRect.iBr);
  1885 		ASSERT_TRUE(pixelRgb == innerRgb);
  1886 		pixelReadBackDevice->GetPixel(pixelRgb, TPoint(readBackRect.iTl.iX, readBackRect.iBr.iY));
  1887 		ASSERT_TRUE(pixelRgb == innerRgb);
  1888 
  1889 		CleanupStack::PopAndDestroy(bmp2);
  1890 		}
  1891 	screenModeList.Close();
  1892 	CleanupStack::PopAndDestroy(4, dsaDraw);
  1893 	}
  1894 
  1895 /**
  1896 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0012L
  1897 @SYMTestCaseDesc		Test Pointer event coordinates are correct in different screen modes.
  1898 @SYMREQ					REQ10336
  1899 @SYMPREQ				PREQ2102
  1900 @SYMTestType			CT
  1901 @SYMTestPriority		1
  1902 @SYMTestPurpose			Test Pointer event coordinates are correct in different screen mode
  1903 @SYMTestActions			
  1904 	In each screen mode, the simulated pointer event should always at the same relative position
  1905 	inside iCompare window
  1906 @SYMTestExpectedResults	
  1907 	All test should pass
  1908 	**NOTE  Can only be tested in screen 0 **
  1909 */
  1910 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0012L()
  1911 	{
  1912 	LOG_AND_PANIC_IF_NOT_GCE;
  1913 	ResetScreens();
  1914 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0012L"),_L("Pointer coordinates"));		
  1915 	Pause(300);
  1916 
  1917 	CWsDisplayEvent* displayEventAO = new(ELeave) CWsDisplayEvent(&iSession);
  1918 	CleanupStack::PushL(displayEventAO);
  1919 	displayEventAO->Request();
  1920 	CEventTimer *timer = CEventTimer::NewL();
  1921 	CleanupStack::PushL(timer);
  1922 	
  1923 	MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  1924 				(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  1925 	ASSERT_TRUE(mappingInterface);
  1926 	
  1927 	RArray<TInt> screenModeList;
  1928 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  1929 	iSession.SetFocusScreen(TGlobalSettings::Instance().iScreen);
  1930 	
  1931 	for (TInt res=0;res<screenModeList.Count();res++)
  1932 		{
  1933 		iScreenDevice->SetAppScreenMode(screenModeList[res]);
  1934 		iScreenDevice->SetScreenMode(screenModeList[res]);
  1935 		Pause(300);
  1936 		
  1937 		//win position in app space
  1938 		TPoint winPos = iCompare.AbsPosition();
  1939 		TSize winSize = iCompare.Size();
  1940 		
  1941 		//pointer event at the origin of window
  1942 		TRect rectNearWinOrigin(winPos+TPoint(1,1), TSize(1,1));
  1943 		//the expected pointer position received by client to compare with the actual point received.
  1944 		//it's (1,1) because it's relative to window
  1945 		displayEventAO->SetExpectedPointPos(TPoint(1, 1)); 
  1946 		TRect rectInComp, rectBackInApp;
  1947 		mappingInterface->MapCoordinates(EApplicationSpace, rectNearWinOrigin, ECompositionSpace, rectInComp);
  1948 		//as we got the physical coordinates at where we simulate pointer event
  1949 		TRawEvent rawEvent;
  1950 		rawEvent.Set(TRawEvent::EButton1Down, rectInComp.iTl.iX, rectInComp.iTl.iY);
  1951 		iSession.SimulateRawEvent(rawEvent);
  1952 		rawEvent.Set(TRawEvent::EButton1Up, rectInComp.iTl.iX, rectInComp.iTl.iY);
  1953 		iSession.SimulateRawEvent(rawEvent);
  1954 		iSession.Flush();
  1955 		timer->Wait(1000);
  1956 		
  1957 		ASSERT_EQUALS(displayEventAO->ReceivedPointerEventCount(), res*4+2);
  1958 		ASSERT_TRUE(displayEventAO->PointerTestPassed());
  1959 		
  1960 		//pointer event at 1/2 width and height inside the window
  1961 		TRect rectAtWinCenter(winPos+TPoint(winSize.iWidth/2, winSize.iHeight/2), TSize(1,1));
  1962 		displayEventAO->SetExpectedPointPos(rectAtWinCenter.iTl - winPos);
  1963 		mappingInterface->MapCoordinates(EApplicationSpace, rectAtWinCenter, ECompositionSpace, rectInComp);
  1964 		//as we got the physical coordinates at where we simulate pointer event
  1965 		rawEvent.Set(TRawEvent::EButton1Down, rectInComp.iTl.iX, rectInComp.iTl.iY);
  1966 		iSession.SimulateRawEvent(rawEvent);
  1967 		rawEvent.Set(TRawEvent::EButton1Up, rectInComp.iTl.iX, rectInComp.iTl.iY);
  1968 		iSession.SimulateRawEvent(rawEvent);
  1969 		iSession.Flush();
  1970 		timer->Wait(1000);
  1971 		
  1972 		ASSERT_EQUALS(displayEventAO->ReceivedPointerEventCount(), res*4 + 4);
  1973 		ASSERT_TRUE(displayEventAO->PointerTestPassed());
  1974 		}
  1975 	screenModeList.Close();
  1976 	CleanupStack::PopAndDestroy(2, displayEventAO);
  1977 	}
  1978 
  1979 /**
  1980 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0013L
  1981 @SYMTestCaseDesc		Test the twips size after detach
  1982 @SYMREQ					REQ10329
  1983 @SYMPREQ				PREQ2102
  1984 @SYMTestType			CT
  1985 @SYMTestPurpose			Make sure the twips size is undefined after detach.
  1986 @SYMTestActions			
  1987 	Save display configuration before detach and compare it with the display configuration after detach.
  1988 @SYMTestExpectedResults	
  1989 	all tests should pass
  1990 */
  1991 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0013L()
  1992 	{
  1993 	LOG_AND_PANIC_IF_NOT_GCE;
  1994 	ResetScreens();
  1995 #ifdef MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
  1996 	ASSERT_FALSE("Test not compiled because MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER");
  1997 #else
  1998 	TInt error;
  1999 	iSession.Finish(ETrue);
  2000 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0013L"),_L("detach/attach - twips size"));
  2001 	iSession.Finish(ETrue);
  2002 
  2003 	Pause(1000);
  2004 	TInt screenNo = iScreenDevice->GetScreenNumber();
  2005 	RArray<TInt> screenModeList;
  2006 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  2007 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2008 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2009 	ASSERT_TRUE(interface);
  2010 	
  2011 	MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  2012 				(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  2013 	ASSERT_TRUE(mappingInterface);
  2014 	
  2015 	TInt resolutions = interface->NumberOfResolutions();
  2016 	ASSERT_TRUE (resolutions > 0);
  2017 	
  2018 	RArray<MDisplayControl::TResolution> resolutionList1;
  2019 	error = interface->GetResolutions(resolutionList1);
  2020 	ASSERT_EQUALS(error,KErrNone);
  2021 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  2022 	
  2023 	TDisplayConfiguration configBeforeDetach;
  2024 	
  2025 	// detach the display
  2026 	interface->GetConfiguration(configBeforeDetach);
  2027 	TInt displayState = EDisconnect;
  2028 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  2029 	Pause(300);
  2030 	
  2031 	// retrieve the display configuration
  2032 	interface->GetConfiguration(configBeforeDetach);
  2033 	ASSERT_FALSE(configBeforeDetach.IsDefined(TDisplayConfiguration::EResolutionTwips));
  2034 	
  2035 	error = interface->GetResolutions(resolutionList1);
  2036 	ASSERT_EQUALS(error,KErrDisconnected);
  2037 	
  2038 	configBeforeDetach.ClearAll();
  2039 	
  2040 	screenModeList.Close();
  2041 	resolutionList1.Close();
  2042 	
  2043 	displayState = ENormalResolution;
  2044 	UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  2045 #endif
  2046 	}
  2047 
  2048 /**
  2049 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0014L
  2050 @SYMTestCaseDesc		Test GetConfiguration immediatly after SetConfiguration
  2051 @SYMREQ					REQ10328
  2052 @SYMPREQ				PREQ2102
  2053 @SYMTestType			CT
  2054 @SYMTestPurpose			Make sure the twips size is buffered so immediate GetConfiguration can get correct twip size
  2055 @SYMTestActions			
  2056 	successive SetConfiguration/GetConfiguration pair 
  2057 @SYMTestExpectedResults	
  2058 	all tests should pass
  2059 */
  2060 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0014L()
  2061 	{
  2062 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2063 					(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2064 	ASSERT_TRUE(interface);
  2065 	
  2066 	RArray<MDisplayControl::TResolution> resolutions;
  2067 	TInt err = interface->GetResolutions(resolutions);
  2068 	ASSERT_EQUALS(err, KErrNone);
  2069 	TDisplayConfiguration configSet, configGet;
  2070 	TSize twipsGet, resolutionGet;
  2071 	
  2072 	TInt screenNo = iScreenDevice->GetScreenNumber();
  2073 	iSession.SetFocusScreen(TGlobalSettings::Instance().iScreen);
  2074 	for(TInt testIndex = 0; testIndex < 2; testIndex++)
  2075 		{//run twice
  2076 #ifdef MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
  2077 	INFO_PRINTF1(_L("Test not compiled because MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER"));
  2078 #else
  2079 		TInt displayState;
  2080 		displayState = ENormalResolution;
  2081 		UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  2082 #endif
  2083 		for (TInt i=0;i<resolutions.Count();i++)
  2084 			{
  2085 			INFO_PRINTF2(_L("i = %i"), i);
  2086 			INFO_PRINTF3(_L("resolutions: %i x %i"), resolutions[i].iPixelSize.iWidth, resolutions[i].iPixelSize.iHeight);
  2087 			INFO_PRINTF3(_L("twips: %i x %i"), resolutions[i].iTwipsSize.iWidth, resolutions[i].iTwipsSize.iHeight);
  2088 			configSet.ClearAll();
  2089 			configGet.ClearAll();
  2090 			configSet.SetResolution(resolutions[i].iPixelSize);
  2091 			err = interface->SetConfiguration(configSet);
  2092 			if(err != KErrNone)
  2093 				{
  2094 				//with scaling, KErrArgument means current config is not compatible with appmode. 
  2095 				//In none scaling, it does mean an error,
  2096 				//but the purpose of this test is to see if twips size is buffered so we can read it back instantly
  2097 				//let other tests test the functionality of SetConfiguration.
  2098 				ASSERT_EQUALS(err, KErrArgument); 
  2099 												
  2100 				INFO_PRINTF1(_L("this configuration is not compatible with current appmode, skip"));
  2101 				continue;
  2102 				}
  2103 			interface->GetConfiguration(configGet);
  2104 			ASSERT_TRUE(configGet.IsDefined(TDisplayConfigurationBase::EResolutionTwips));
  2105 			ASSERT_TRUE(configGet.IsDefined(TDisplayConfigurationBase::EResolution));
  2106 			configGet.GetResolutionTwips(twipsGet);
  2107 			configGet.GetResolution(resolutionGet);
  2108 			INFO_PRINTF3(_L("resolution readback: %i x %i"), resolutionGet.iWidth, resolutionGet.iHeight);
  2109 			INFO_PRINTF3(_L("twips readback: %i x %i"), twipsGet.iWidth, twipsGet.iHeight);
  2110 			ASSERT_EQUALS(twipsGet, resolutions[i].iTwipsSize);
  2111 			Pause(300);
  2112 			}
  2113 #ifdef MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER
  2114 	INFO_PRINTF1(_L("Test not compiled because MODE_CHANGE_BASE_FUNCTIONALITY_NOT_PRESENT_IN_HEADER"));
  2115 #else
  2116 		displayState = EDisconnect;
  2117 		UserSvr::HalFunction(EHalGroupDisplay | (screenNo<<16), EDisplayHalSetDisplayState, &displayState, NULL);
  2118 #endif		
  2119 		}
  2120 	resolutions.Close();
  2121 	
  2122 	}
  2123 
  2124 /**
  2125 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0015L
  2126 @SYMTestCaseDesc		No Scaling doesnt return virtual resolutions
  2127 @SYMREQ					REQ10336
  2128 @SYMPREQ				PREQ2102
  2129 @SYMTestType			CT
  2130 @SYMTestPriority		1
  2131 @SYMTestPurpose			no scaling should mean basic resolution selection
  2132 @SYMTestActions			
  2133 	Get resolution list
  2134 	Should not contain virtual resolutions
  2135 	Set every app mode
  2136 	Should not change resolution
  2137 @SYMTestExpectedResults	
  2138 	All test should pass
  2139 	**SENSITIVE TO CHANGES IN EPOC.INI and WSINI.INI**
  2140 */
  2141 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0015L()
  2142 	{	//ONLY RUN WITH 'NO SCALING' WSINI.INI, can be found in resources
  2143 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2144 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2145 	ASSERT_TRUE(interface);
  2146 	
  2147 	TInt resolutions = interface->NumberOfResolutions();
  2148 	TInt screenNumber = iScreenDevice->GetScreenNumber();
  2149 	if (screenNumber == 0)
  2150 		{
  2151 		ASSERT_EQUALS(resolutions,1);
  2152 		}
  2153 	else if (screenNumber == 1)
  2154 		{
  2155 		ASSERT_EQUALS(resolutions,4);
  2156 		}	
  2157 	
  2158 	RArray<MDisplayControl::TResolution> resolutionList1;
  2159 	TInt error = interface->GetResolutions(resolutionList1);
  2160 	ASSERT_EQUALS(error,KErrNone);
  2161 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  2162 	
  2163 	RArray<TInt> screenModeList;
  2164 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  2165 	
  2166 	TDisplayConfiguration dispConfig1;
  2167 	interface->GetConfiguration(dispConfig1);
  2168 	TSize size1;
  2169 	ASSERT_TRUE(dispConfig1.GetResolution(size1));
  2170 	
  2171 	for (TInt ii = 0; ii < screenModeList.Count(); ii++)
  2172 		{
  2173 		iInfoScreenDevice->SetAppScreenMode(screenModeList[ii]);
  2174 		iInfoScreenDevice->SetScreenMode(screenModeList[ii]);
  2175 		iSession.Finish(ETrue);
  2176 		Pause(300);
  2177 		
  2178 		TDisplayConfiguration newConfig;
  2179 		interface->GetConfiguration(newConfig);
  2180 		TSize newSize;
  2181 		ASSERT_TRUE(dispConfig1.GetResolution(newSize));
  2182 		ASSERT_EQUALS(size1,newSize);
  2183 		}
  2184 	iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  2185 	iInfoScreenDevice->SetScreenMode(screenModeList[0]);
  2186 	iSession.Finish(ETrue);
  2187 	Pause(300);
  2188 	
  2189 	screenModeList.Close();
  2190 	resolutionList1.Close();
  2191 	}
  2192 
  2193 /**
  2194 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0016L
  2195 @SYMTestCaseDesc		Anisotropic scaling
  2196 @SYMREQ					REQ10336
  2197 @SYMPREQ				PREQ2102
  2198 @SYMTestType			CT
  2199 @SYMTestPriority		1
  2200 @SYMTestPurpose			Check using twips will cause virtual resolutions to possibly be different
  2201 @SYMTestActions			
  2202 	Check the virtual resolution for XXX is correctly XXX
  2203 	Check when setting the appmode, it choses the correct resolution
  2204 @SYMTestExpectedResults	
  2205 	Tests should pass
  2206 	**SENSITIVE TO CHANGES IN EPOC.INI and WSINI.INI**
  2207 */
  2208 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0016L()
  2209 	{	//ONLY RUN WITH ANISOTROPIC WSINI.INI
  2210 
  2211 	}
  2212 
  2213 /**
  2214 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0017L
  2215 @SYMTestCaseDesc		Integer scales correctly in policy
  2216 @SYMREQ					REQ10336
  2217 @SYMPREQ				PREQ2102
  2218 @SYMTestType			CT
  2219 @SYMTestPriority		1
  2220 @SYMTestPurpose			Integer scaling should not create resolutions of non integer value!
  2221 @SYMTestActions			
  2222 	For every virtual resolution
  2223 		Check its an integer size of a real resolution
  2224 @SYMTestExpectedResults	
  2225 	All should be integers (1:1 , 1:2 , 1:3 or 1:4 in current policy)
  2226 	**NOTE ONLY RUN WITH INTEGER WSINI.INI**
  2227 */
  2228 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0017L()
  2229 	{	//ONLY RUN WITH INTEGER WSINI.INI
  2230 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2231 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2232 	ASSERT_TRUE(interface);
  2233 	
  2234 	TInt resolutions = interface->NumberOfResolutions();
  2235 	ASSERT_TRUE(resolutions>1);
  2236 	
  2237 	RArray<MDisplayControl::TResolution> resolutionList1;
  2238 	TInt error = interface->GetResolutions(resolutionList1);
  2239 	ASSERT_EQUALS(error,KErrNone);
  2240 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  2241 	
  2242 	TInt index;
  2243 	for (index=0;index<resolutions;index++)
  2244 		{
  2245 		if (resolutionList1[index].iFlags.IsSet(MDisplayControlBase::TResolution::EIsVirtual))
  2246 			{
  2247 			TBool foundMatch = EFalse;
  2248 			for (TInt index2=0;index2<resolutions;index2++)
  2249 				{
  2250 				if (resolutionList1[index2].iFlags.IsClear(MDisplayControlBase::TResolution::EIsVirtual))
  2251 					{
  2252 					for (TInt scale=1;scale<=4;scale++)
  2253 						{
  2254 						TSize compare;
  2255 						compare.iWidth=resolutionList1[index].iPixelSize.iWidth/scale;
  2256 						compare.iHeight=resolutionList1[index].iPixelSize.iHeight/scale;
  2257 						if (resolutionList1[index2].iPixelSize == compare)
  2258 							{
  2259 							foundMatch = ETrue;
  2260 							break;
  2261 							}
  2262 						}
  2263 					}
  2264 				if (foundMatch)
  2265 					{
  2266 					break;
  2267 					}
  2268 				}
  2269 			ASSERT_TRUE(foundMatch);
  2270 			}
  2271 		}
  2272 	resolutionList1.Close();
  2273 	}
  2274 
  2275 /**
  2276 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0018L
  2277 @SYMTestCaseDesc		MDisplayMapping interface function test
  2278 @SYMREQ					REQ10336
  2279 @SYMPREQ				PREQ2102
  2280 @SYMTestType			CT
  2281 @SYMTestPriority		1
  2282 @SYMTestPurpose			All the MDisplayMapping interface functions are consistent
  2283 @SYMTestActions			
  2284 	Check different mapping functions are consistent
  2285 @SYMTestExpectedResults	
  2286 	All test should pass
  2287 */
  2288 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0018L()
  2289 	{
  2290 	
  2291 	LOG_AND_PANIC_IF_NOT_GCE;
  2292 	ResetScreens();
  2293 	TInt error;
  2294 	iSession.Finish(ETrue);
  2295 	MakeTitleAndCompareWindowsL(_L("GFX_WSERV_DYNAMICRES_0020L"),_L("Mapping function consistency"));
  2296 	iSession.Finish(ETrue);
  2297 	
  2298 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2299 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2300 	ASSERT_TRUE(interface);
  2301 	
  2302 	MDisplayMapping* mapInterface = static_cast<MDisplayMapping*>
  2303 			(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  2304 	ASSERT_TRUE(mapInterface);
  2305 	
  2306 	RArray<TInt> screenModeList;
  2307 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  2308 	
  2309 	TRect maxWinExtent, refMaxWinExtent;
  2310 	TSize surfaceSize, surfaceTwips, refSurfaceSize, refSurfaceTwips;
  2311 	TRect displayWinExtent, refDisplayWinExtent;
  2312 	for (TInt i = 0; i < screenModeList.Count(); i++)
  2313 		{
  2314 		iInfoScreenDevice->SetAppScreenMode(screenModeList[i]);
  2315 		iInfoScreenDevice->SetScreenMode(screenModeList[i]);
  2316 		iSession.Finish(ETrue);
  2317 		Pause(300);
  2318 		
  2319 		INFO_PRINTF1(_L("---------------"));
  2320 		INFO_PRINTF2(_L("screen mode : %i"), screenModeList[i]);
  2321 		
  2322 		mapInterface->GetMaximumWindowExtent(maxWinExtent);
  2323 		INFO_PRINTF3(_L("MaximumWindowExtent Origin: (%i, %i)"), maxWinExtent.iTl.iX, maxWinExtent.iTl.iY);
  2324 		INFO_PRINTF3(_L("MaximumWindowExtent Size: %i x %i"), maxWinExtent.Width(), maxWinExtent.Height());
  2325 		
  2326 		
  2327 		TDisplayConfiguration config;
  2328 		interface->GetConfiguration(config);
  2329 		ASSERT_TRUE(config.IsDefined(TDisplayConfigurationBase::EResolution));
  2330 		TSize fullUiSize;
  2331 		config.GetResolution(fullUiSize);
  2332 		error = mapInterface->MapCoordinates(EFullScreenSpace, fullUiSize, EApplicationSpace, refMaxWinExtent);
  2333 		ASSERT_EQUALS(error, KErrNone);
  2334 		INFO_PRINTF3(_L("ref MaximumWindowExtent Origin: (%i, %i)"), refMaxWinExtent.iTl.iX, refMaxWinExtent.iTl.iY);
  2335 		INFO_PRINTF3(_L("ref MaximumWindowExtent Size: %i x %i"), refMaxWinExtent.Width(), refMaxWinExtent.Height());
  2336 		ASSERT_EQUALS(maxWinExtent, refMaxWinExtent);
  2337 		INFO_PRINTF1(_L("Match"));
  2338 		
  2339 		mapInterface->GetMaximumSurfaceSize(surfaceSize, surfaceTwips);
  2340 		INFO_PRINTF3(_L("MaxSurfaceSize: %i x %i"), surfaceSize.iWidth, surfaceSize.iHeight);
  2341 		INFO_PRINTF3(_L("MaxSurfaceTwips: %i x %i"), surfaceTwips.iWidth, surfaceSize.iHeight);
  2342 		TRect compositionRect;
  2343 		error = mapInterface->MapCoordinates(EFullScreenSpace, fullUiSize, ECompositionSpace, compositionRect);
  2344 		ASSERT_EQUALS(error, KErrNone);
  2345 		refSurfaceSize = compositionRect.Size();
  2346 		INFO_PRINTF3(_L("RefSurfaceSize: %i x %i"), refSurfaceSize.iWidth, refSurfaceSize.iHeight);
  2347 		ASSERT_TRUE(config.IsDefined(TDisplayConfigurationBase::EResolutionTwips));
  2348 		config.GetResolutionTwips(refSurfaceTwips);
  2349 		INFO_PRINTF3(_L("RefSurfaceTwips: %i x %i"), refSurfaceTwips.iWidth, refSurfaceTwips.iHeight);
  2350 		ASSERT_EQUALS(surfaceSize, refSurfaceSize);
  2351 		ASSERT_EQUALS(surfaceTwips, refSurfaceTwips);
  2352 		INFO_PRINTF1(_L("Match"));
  2353 		
  2354 		mapInterface->GetDisplayExtentOfWindow(iCompare, displayWinExtent);
  2355 		INFO_PRINTF3(_L("DisplayWin origin: (%i, %i)"), displayWinExtent.iTl.iX, displayWinExtent.iTl.iY);
  2356 		INFO_PRINTF3(_L("DisplayWin Size: (%i x %i"), displayWinExtent.Width(), displayWinExtent.Height());
  2357 		error = mapInterface->MapCoordinates(EApplicationSpace, TRect(TPoint(iCompare.AbsPosition()),iCompare.Size()), ECompositionSpace, refDisplayWinExtent);
  2358 		ASSERT_EQUALS(error, KErrNone);
  2359 		INFO_PRINTF3(_L("RefDisplayWin origin: (%i, %i)"), refDisplayWinExtent.iTl.iX, refDisplayWinExtent.iTl.iY);
  2360 		INFO_PRINTF3(_L("RefDisplayWin Size: (%i x %i"), refDisplayWinExtent.Width(), refDisplayWinExtent.Height());
  2361 		ASSERT_EQUALS(displayWinExtent, refDisplayWinExtent);
  2362 		INFO_PRINTF1(_L("Match"));
  2363 		}
  2364 	iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  2365 	iInfoScreenDevice->SetScreenMode(screenModeList[0]);
  2366 	screenModeList.Close();
  2367 	}
  2368 
  2369 /*
  2370 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0021L
  2371 @SYMTestCaseDesc		SetResolution negative test
  2372 @SYMREQ					REQ10326
  2373 @SYMPREQ				PREQ2102
  2374 @SYMTestType			CT
  2375 @SYMTestPriority		1
  2376 @SYMTestPurpose			Invalid configurations should return error and change nothing!
  2377 @SYMTestActions			
  2378 	Set config with rubbish resolution
  2379 	Set config with rubbish twips
  2380 	Set config with valid resolution, rubbish twips
  2381 	Set config with valid twips, rubbish resolution
  2382 	Set config with nothing defined
  2383 @SYMTestExpectedResults	
  2384 	Should all fail safely and not change any settings.
  2385 	Config with nothing defined in a scaled mode will reset the resolution to current modes
  2386 	equivilent virtual resolution
  2387 	**NOTE ONLY RUN IN SCREEN 1 - we need multiple resolutions available**
  2388 */
  2389 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0021L(TBool aScaleMode)
  2390 	{	//aScaleMode 0 = no scaling, 1 = integer,isotropic or anisotropic
  2391 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2392 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2393 	ASSERT_TRUE(interface);
  2394 	
  2395 	TInt resolutions = interface->NumberOfResolutions();
  2396 	ASSERT_TRUE (resolutions > 1);
  2397 		
  2398 	RArray<MDisplayControl::TResolution> resolutionList1;
  2399 	TInt error = interface->GetResolutions(resolutionList1);
  2400 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  2401 	
  2402 	TDisplayConfiguration original;
  2403 	original.SetResolution(resolutionList1[0].iPixelSize);
  2404 	error = interface->SetConfiguration(original);
  2405 	ASSERT_EQUALS(error,KErrNone);
  2406 	
  2407 	TDisplayConfiguration beforeConfig;
  2408 	TDisplayConfiguration afterConfig;
  2409 	interface->GetConfiguration(beforeConfig);
  2410 	
  2411 	TInt differentRes;
  2412 	for (differentRes = 1; differentRes < resolutions; differentRes++)
  2413 		{
  2414 		if (!(resolutionList1[differentRes].iPixelSize == resolutionList1[0].iPixelSize))
  2415 			{
  2416 			break;
  2417 			}
  2418 		}
  2419 	ASSERT_TRUE(differentRes < resolutions);	//otherwise it didnt find a resolution different to the one set
  2420 	
  2421 	TDisplayConfiguration test1;
  2422 	test1.SetResolution(TSize(5,6));	//rubbish resolution!
  2423 	error = interface->SetConfiguration(test1);
  2424 
  2425 	ASSERT_EQUALS(error,KErrArgument);
  2426 
  2427 	ASSERT_EQUALS(error,KErrArgument);
  2428 	iSession.Flush();
  2429 	interface->GetConfiguration(afterConfig);
  2430 	ASSERT_TRUE(beforeConfig == afterConfig);
  2431 	
  2432 	TDisplayConfiguration test2;
  2433 	test2.SetResolutionTwips(TSize(7,8));	//rubbish twips!
  2434 	error = interface->SetConfiguration(test2);
  2435 	ASSERT_EQUALS(error,KErrArgument);
  2436 	iSession.Flush();
  2437 	interface->GetConfiguration(afterConfig);
  2438 	ASSERT_TRUE(beforeConfig == afterConfig);
  2439 	
  2440 	TDisplayConfiguration test3;
  2441 	test3.SetResolution(resolutionList1[differentRes].iPixelSize);	//ok resolution!
  2442 	test3.SetResolutionTwips(TSize(9,10));	//rubbish twips!
  2443 	error = interface->SetConfiguration(test3);
  2444 	//ASSERT_EQUALS(error,KErrArgument);
  2445 	if (error != KErrArgument)
  2446 		{
  2447 		ASSERT_EQUALS (aScaleMode,0);	//if no policy, we currently have issue with confing not being validated
  2448 		INFO_PRINTF1(_L("config was not honoured!"));
  2449 		error = interface->SetConfiguration(original);
  2450 		ASSERT_EQUALS(error,KErrNone);
  2451 		iSession.Flush();
  2452 		Pause(200);
  2453 		}
  2454 	else
  2455 		{
  2456 		iSession.Flush();
  2457 		Pause(200);
  2458 		interface->GetConfiguration(afterConfig);
  2459 		ASSERT_TRUE(beforeConfig == afterConfig);
  2460 		}
  2461 
  2462 	TDisplayConfiguration test4;
  2463 	test4.SetResolution(TSize(11,12));	//rubbish resolution!
  2464 	test4.SetResolutionTwips(resolutionList1[differentRes].iTwipsSize);	//ok twips!
  2465 	error = interface->SetConfiguration(test4);
  2466 	if (error != KErrArgument)
  2467 		{
  2468 		ASSERT_EQUALS (aScaleMode,0);	//if no policy, we currently have issue with config not being validated
  2469 		INFO_PRINTF1(_L("config was not honoured!"));
  2470 		error = interface->SetConfiguration(original);
  2471 		ASSERT_EQUALS(error,KErrNone);
  2472 		iSession.Flush();
  2473 		Pause(200);
  2474 		}
  2475 	else
  2476 		{
  2477 		iSession.Flush();
  2478 		Pause(200);
  2479 		interface->GetConfiguration(afterConfig);
  2480 		ASSERT_TRUE(beforeConfig == afterConfig);
  2481 		}
  2482 	
  2483 	if (aScaleMode)
  2484 		{
  2485 		RArray<TInt> screenModeList;
  2486 		iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  2487 		ASSERT_TRUE(screenModeList.Count()>1);
  2488 		//set default screen mode, sets resolution to best fit for this mode
  2489 		iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  2490 		iInfoScreenDevice->SetScreenMode(screenModeList[0]);	//also sets its best resolution
  2491 		iSession.Finish(ETrue);
  2492 		Pause(200);
  2493 		
  2494 		TDisplayConfiguration newModeConfig;
  2495 		interface->GetConfiguration(newModeConfig);
  2496 		//get best fit resolution
  2497 		TSize newModeRes;
  2498 		ASSERT_TRUE(newModeConfig.GetResolution(newModeRes));
  2499 		
  2500 		//find a different resolution
  2501 		TInt i;
  2502 		for (i = 0; i < resolutions; i++)
  2503 			{
  2504 			if (!(resolutionList1[i].iPixelSize == newModeRes))
  2505 				{
  2506 				break;
  2507 				}
  2508 			}
  2509 		ASSERT_TRUE(i < resolutions);	//otherwise it didnt find a resolution different to the one set
  2510 		TDisplayConfiguration newSetConfig;
  2511 		
  2512 		//set the different resolution
  2513 		newSetConfig.SetResolution(resolutionList1[i].iPixelSize);
  2514 		error = interface->SetConfiguration(newSetConfig);
  2515 		ASSERT_TRUE(error == KErrNone);
  2516 		iSession.Flush();
  2517 		Pause(200);
  2518 		TDisplayConfiguration checkConfig;
  2519 		
  2520 		//check its set this new resolution
  2521 		interface->GetConfiguration(checkConfig);
  2522 		TSize checkSize;
  2523 		checkConfig.GetResolution(checkSize);
  2524 		ASSERT_TRUE (checkSize == resolutionList1[i].iPixelSize);
  2525 		
  2526 		TDisplayConfiguration emptyConfig;
  2527 		TDisplayConfiguration newModeConfig2(newModeConfig);
  2528 		newModeConfig2.Clear(newModeConfig2.EResolutionTwips);
  2529 		//set empty config, which should reset resolution to current modes default
  2530 		error = interface->SetConfiguration(emptyConfig);//emptyConfig);
  2531 		ASSERT_TRUE(error == KErrNone);
  2532 		iSession.Finish();
  2533 		Pause(200);
  2534 	
  2535 		interface->GetConfiguration(checkConfig);
  2536 		ASSERT_TRUE (newModeConfig == checkConfig);	//empty config reset res to modes default res
  2537 
  2538 		screenModeList.Close();
  2539 		}
  2540 	else
  2541 		{
  2542 		TDisplayConfiguration test5;
  2543 		error = interface->SetConfiguration(test5);
  2544 		ASSERT_EQUALS(error,KErrArgument);
  2545 		}
  2546 	resolutionList1.Close();	
  2547 	}
  2548 
  2549 /**
  2550 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0031L
  2551 @SYMTestCaseDesc		SetConfiguration in OOM (changing resolution)
  2552 @SYMREQ					REQ10326
  2553 @SYMPREQ				PREQ2102
  2554 @SYMTestType			CT
  2555 @SYMTestPriority		1
  2556 @SYMTestPurpose			Safety check against OOM
  2557 @SYMTestActions			
  2558 	Set OOM failure
  2559 	Set a resolution that will definately cause a change of resolution
  2560 	Increase length of time to failure, repeat
  2561 	Finish after 5 successful changes of resolution
  2562 @SYMTestExpectedResults	
  2563 	Set resolution should either return a fail and not have cause a change in resolution,
  2564 	or it should have returned no fail and have set the new resolution
  2565 */
  2566 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0031L()
  2567 	{
  2568 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2569 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2570 	ASSERT_TRUE(interface);
  2571 	INFO_PRINTF1(_L("Interface obtained sucessfully."));
  2572 	
  2573 	TInt resolutions = interface->NumberOfResolutions();
  2574 	ASSERT_TRUE (resolutions > 0);
  2575 	INFO_PRINTF1(_L("NumberOfResolutions obtained sucessfully."));
  2576 	
  2577 	RArray<MDisplayControl::TResolution> resolutionList1;
  2578 	TInt error = interface->GetResolutions(resolutionList1);
  2579 	ASSERT_EQUALS(error,KErrNone);
  2580 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  2581 	INFO_PRINTF1(_L("resolutionList1 has correct number of resolutions."));
  2582 	
  2583 	TInt index;
  2584 	TDisplayConfiguration dispConfigBefore;
  2585 	TDisplayConfiguration dispConfigAfter;
  2586 	
  2587 	dispConfigBefore.SetResolution(resolutionList1[0].iPixelSize);
  2588 	interface->SetConfiguration(dispConfigBefore);
  2589 	interface->GetConfiguration(dispConfigBefore);
  2590 	ASSERT_TRUE(dispConfigBefore.IsDefined(dispConfigBefore.EResolution));
  2591 	INFO_PRINTF1(_L("dispConfigBefore is defined."));
  2592 	TSize dispResBefore;
  2593 	TSize dispResAfter;
  2594 	dispConfigBefore.GetResolution(dispResBefore);
  2595 	TDisplayConfiguration::TRotation dispRotBefore;
  2596 	TDisplayConfiguration::TRotation dispRotReq;
  2597 	dispConfigBefore.GetRotation(dispRotBefore);
  2598 
  2599 	for (index = 0; index < resolutionList1.Count(); index++)
  2600 		{
  2601 		INFO_PRINTF2(_L("Starting resolution %d."), index);
  2602 		if (resolutionList1[index].iPixelSize.iWidth == 0)
  2603 			{
  2604 			continue;
  2605 			}
  2606 		TInt heapFail = 1;
  2607 		TBool notComplete = ETrue;
  2608 		TInt completeCount = 0;
  2609 		while (notComplete)
  2610 			{
  2611 			TDisplayConfiguration dispConfigReq;
  2612 			dispConfigReq.SetResolution(resolutionList1[index].iPixelSize);
  2613 			ASSERT_TRUE(dispConfigReq.IsDefined(dispConfigReq.EResolution));
  2614 			SetRotation(dispConfigReq,resolutionList1[index]);	//set rotation to first defined in res list
  2615 			dispConfigReq.GetRotation(dispRotReq);
  2616 			INFO_PRINTF2(_L("Before heap failure, value of heapfail is %d."), heapFail);
  2617 			
  2618 			iSession.Finish(ETrue);
  2619 			iSession.HeapSetFail(RHeap::EDeterministic,heapFail);
  2620 			TInt errCode=interface->SetConfiguration(dispConfigReq);
  2621 			iSession.HeapSetFail(RHeap::ENone,0);
  2622 			INFO_PRINTF1(_L("After Heap Failure."));
  2623 			iSession.Finish(ETrue);
  2624 			Pause (100);
  2625 			INFO_PRINTF1(_L("After Session Finish."));
  2626 			
  2627 			interface->GetConfiguration(dispConfigAfter);
  2628 			ASSERT_TRUE(dispConfigAfter.IsDefined(dispConfigAfter.EResolution));
  2629 			dispConfigAfter.GetResolution(dispResAfter);
  2630 			
  2631 			TBool worked = ETrue;
  2632 			if (errCode < KErrNone)
  2633 				{			
  2634 				worked = EFalse;
  2635 				ASSERT_EQUALS(dispResAfter,dispResBefore);
  2636 				if (dispRotReq != dispRotBefore)
  2637 					{	//didnt expect it work-KErrGeneral can mean a memory allocation fail
  2638 					if (errCode == KErrArgument)
  2639 						{	//if it didnt panic, that is a good enough pass in this instance
  2640 						worked = ETrue;
  2641 						}
  2642 					}
  2643 				}
  2644 			else
  2645 				{				
  2646 				ASSERT_EQUALS(dispResAfter,resolutionList1[index].iPixelSize);
  2647 				}
  2648 			if (worked)
  2649 				{	
  2650 				completeCount++;
  2651 				if (completeCount == 5)
  2652 					{
  2653 					notComplete = EFalse;
  2654 					}
  2655 				}
  2656 			else
  2657 				{
  2658 				completeCount = 0;
  2659 				}
  2660 			interface->SetConfiguration(dispConfigBefore);
  2661 			INFO_PRINTF1(_L("After Setting Original Configuration."));
  2662 			heapFail++;
  2663 			if (heapFail == 80)
  2664 				{
  2665 				ASSERT_TRUE(0);	//worrying amount of fails
  2666 				}
  2667 			}
  2668 		}
  2669 	resolutionList1.Close();
  2670 	}
  2671 
  2672 /**
  2673 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0032L
  2674 @SYMTestCaseDesc		SetAppMode in OOM
  2675 @SYMREQ					REQ10326 REQ10336
  2676 @SYMPREQ				PREQ2102
  2677 @SYMTestType			CT
  2678 @SYMTestPriority		1
  2679 @SYMTestPurpose			Safety check against OOM
  2680 @SYMTestActions			
  2681 	Set OOM failure
  2682 	Set new app mode
  2683 	Increase length of time to failure, repeat
  2684 	Finish after 5 successful changes of mode
  2685 @SYMTestExpectedResults	
  2686 	SetAppMode should either return a fail and not have cause a change in resolution,
  2687 	or it should have returned no fail and have set the new resolution
  2688 */
  2689 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0032L()
  2690 	{
  2691 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2692 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2693 	ASSERT_TRUE(interface);
  2694 	
  2695 	TInt resolutions = interface->NumberOfResolutions();
  2696 	ASSERT_TRUE (resolutions > 0);
  2697 	RArray<TInt> screenModeList;
  2698 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  2699 	ASSERT_TRUE (screenModeList.Count()>0);
  2700 	
  2701 	iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  2702 	iInfoScreenDevice->SetScreenMode(screenModeList[0]);
  2703 	
  2704 	for (TInt index = 1; index < screenModeList.Count(); index++)
  2705 		{	//skip index 0, as that wouldn't be changing mode
  2706 		TInt heapFail = 1;
  2707 		TBool notComplete = ETrue;
  2708 		TInt completeCount = 0;
  2709 		while (notComplete)
  2710 			{
  2711             RDebug::Printf("iInfoScreenDevice->SetAppScreenMode");
  2712 			iInfoScreenDevice->SetAppScreenMode(screenModeList[index]);
  2713 			iSession.Finish(ETrue);
  2714 			iSession.HeapSetFail(RHeap::EDeterministic,heapFail);
  2715             RDebug::Printf("iInfoScreenDevice->SetAppScreenMode");
  2716 			iInfoScreenDevice->SetScreenMode(screenModeList[index]);
  2717             RDebug::Printf("SetScreenMode done");
  2718 			iSession.HeapSetFail(RHeap::ENone,0);
  2719 			iSession.Finish(ETrue);
  2720             RDebug::Printf("Finish done");
  2721 			Pause(50);
  2722 			TInt newMode = iInfoScreenDevice->CurrentScreenMode();
  2723 
  2724 			if (screenModeList[index] == newMode)
  2725 				{
  2726 				completeCount++;
  2727 				if (completeCount == 5)
  2728 					{
  2729 					INFO_PRINTF3(_L("Mode %i Succeeded with heapFail = %d"),index, heapFail);
  2730 					notComplete = EFalse;
  2731 					}
  2732 				iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  2733 				iInfoScreenDevice->SetScreenMode(screenModeList[0]);
  2734 				iSession.Finish(ETrue);
  2735 				Pause(50);
  2736 				}
  2737 			else
  2738 				{
  2739 				completeCount = 0;
  2740 				}
  2741 			heapFail++;
  2742 			if (heapFail == 80)
  2743 				{
  2744 				ASSERT_TRUE(0);	//worrying amount of fails
  2745 				}
  2746 			}
  2747 		}
  2748 	screenModeList.Close();
  2749 	}
  2750 
  2751 /**
  2752 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0033L
  2753 @SYMTestCaseDesc		GetConfiguration in OOM
  2754 @SYMREQ					REQ10328
  2755 @SYMPREQ				PREQ2102
  2756 @SYMTestType			CT
  2757 @SYMTestPriority		1
  2758 @SYMTestPurpose			Safety check against OOM
  2759 @SYMTestActions			
  2760 	Set OOM failure
  2761 	GetConfiguration
  2762 	Check config
  2763 	Increase time till failure
  2764 	Success after 5 completed gets
  2765 @SYMTestExpectedResults	
  2766 	Should always succeed
  2767 */
  2768 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0033L()
  2769 	{
  2770 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2771 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2772 	ASSERT_TRUE(interface);
  2773 	
  2774 	TInt heapFail = 1;
  2775 	for (TInt i=0;i<5;i++)
  2776 		{
  2777 		TDisplayConfiguration config;
  2778 		iSession.Finish(ETrue);
  2779 		iSession.HeapSetFail(RHeap::EDeterministic,heapFail);
  2780 		interface->GetConfiguration(config);
  2781 		iSession.HeapSetFail(RHeap::ENone,0);
  2782 		iSession.Finish(ETrue);
  2783 		ASSERT_TRUE(config.IsDefined(config.ERotation));
  2784 		ASSERT_TRUE(config.IsDefined(config.EResolution));
  2785 		ASSERT_TRUE(config.IsDefined(config.EResolutionTwips));
  2786 		heapFail++;
  2787 		}
  2788 	}
  2789 
  2790 /**
  2791 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0034L
  2792 @SYMTestCaseDesc		GetResolutions in OOM
  2793 @SYMREQ					REQ10328
  2794 @SYMPREQ				PREQ2102
  2795 @SYMTestType			CT
  2796 @SYMTestPriority		1
  2797 @SYMTestPurpose			Safety check against OOM
  2798 @SYMTestActions			
  2799 	Set OOM failure
  2800 	GetResolutions
  2801 	Check resolutions filled in
  2802 	Success after 5 completed gets
  2803 @SYMTestExpectedResults	
  2804 	Should never panic!
  2805 */
  2806 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0034L()
  2807 	{
  2808 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2809 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2810 	ASSERT_TRUE(interface);
  2811 	
  2812 	TInt resolutions = interface->NumberOfResolutions();
  2813 	ASSERT_TRUE(resolutions>1);
  2814 	
  2815 	RArray<MDisplayControl::TResolution> resolutionList1;
  2816 	TInt error = interface->GetResolutions(resolutionList1);
  2817 	ASSERT_EQUALS(error,KErrNone);
  2818 	ASSERT_TRUE(resolutionList1.Count() > 0);
  2819 
  2820 	TInt heapFail = 1;
  2821 	TInt completeCount = 0;
  2822 	TBool notComplete = ETrue;
  2823 	while (notComplete)
  2824 		{
  2825 		RArray<MDisplayControl::TResolution> resolutionList2;
  2826 		iSession.Finish(ETrue);
  2827 		iSession.HeapSetFail(RHeap::EDeterministic,heapFail);
  2828 		error = interface->GetResolutions(resolutionList2);
  2829 		iSession.HeapSetFail(RHeap::ENone,0);
  2830 		iSession.Finish(ETrue);
  2831 		if (error<KErrNone)
  2832 			{
  2833 			ASSERT_EQUALS(error,KErrNoMemory);
  2834 			completeCount = 0;
  2835 			}
  2836 		else
  2837 			{
  2838 			ASSERT_EQUALS(resolutionList2.Count(),resolutionList1.Count());
  2839 			for (TInt i=0;i<resolutionList2.Count();i++)
  2840 				{
  2841 				ASSERT_EQUALS(resolutionList1[i].iPixelSize,resolutionList2[i].iPixelSize);
  2842 				ASSERT_EQUALS(resolutionList1[i].iTwipsSize,resolutionList2[i].iTwipsSize);
  2843 				if (!(resolutionList1[i].iFlags==resolutionList2[i].iFlags))
  2844 					{
  2845 					ASSERT_TRUE(0);
  2846 					}
  2847 				}
  2848 			completeCount++;
  2849 			}
  2850 		heapFail++;
  2851 		resolutionList2.Close();
  2852 		if (completeCount == 5)
  2853 			{
  2854 			notComplete = EFalse;
  2855 			}
  2856 		if (heapFail == 20)
  2857 			{
  2858 			ASSERT_TRUE(0);	//worrying amount of fails
  2859 			}
  2860 		}
  2861 	resolutionList1.Close();
  2862 	}
  2863 
  2864 /**
  2865 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0041L
  2866 @SYMTestCaseDesc		Test Drawing of bitmaps (case 0) and surfaces (case 1) in all different AppModes
  2867 @SYMREQ					REQ10332 REQ10336
  2868 @SYMPREQ				PREQ2102
  2869 @SYMTestType			CT
  2870 @SYMTestPurpose			Check to see if Bitmaps and Surfaces are drawn correctly in different app modes
  2871 @SYMTestActions			
  2872 	A Simple pattern will be drawn by a bitmap on the left and a surface on the right, about half the window size each. The Composited Screen Capture code will be used to compare the drawing to a unchanged copy of the bitmap to see if they are drawn correctly
  2873 	
  2874 	Note, add .0 to test name to test bitmap drawing and .1 to test surface drawing
  2875 @SYMTestExpectedResults	
  2876 	All tests should pass.
  2877 	
  2878 */
  2879 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0041L(TBool aIsSurface)
  2880 	{
  2881 	LOG_AND_PANIC_IF_NOT_GCE;
  2882 	ResetScreens();
  2883 	TInt error;
  2884 	iSession.Finish(ETrue);
  2885 	
  2886 	TRect screenSize(iInfoScreenDevice->SizeInPixels());
  2887 	screenSize.Shrink(5,5);
  2888 	
  2889 	RBlankWindow testWindow;
  2890 	if (iInfoGc)
  2891 		{
  2892 		testWindow=RBlankWindow(iSession);
  2893 		ASSERT_EQUALS(testWindow.Construct(*iInfoGroup, ++iWindowHandle), KErrNone);
  2894 		testWindow.SetColor(iBlue);
  2895 		testWindow.SetExtent(screenSize.iTl,screenSize.Size());
  2896 		testWindow.Activate();
  2897 		
  2898 		if (testWindow.WsHandle())
  2899 			{		
  2900 			iSession.Flush();
  2901 			iSession.Finish();
  2902 			}
  2903 		testWindow.SetVisible(ETrue);
  2904 		}
  2905 	
  2906 	iSession.Finish(ETrue);
  2907 	
  2908 	RArray<TInt> screenModeList;
  2909 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  2910 	MDisplayControl* interface = static_cast<MDisplayControl*>
  2911 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  2912 	ASSERT_TRUE(interface);
  2913 	
  2914 	TInt resolutions = interface->NumberOfResolutions();
  2915 	ASSERT_TRUE (resolutions > 0);
  2916 	
  2917 	RArray<MDisplayControl::TResolution> resolutionList1;
  2918 	error = interface->GetResolutions(resolutionList1);
  2919 	ASSERT_EQUALS(error,KErrNone);
  2920 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  2921 	
  2922 	TDisplayConfiguration dispConfigBefore;
  2923 	interface->GetConfiguration(dispConfigBefore);
  2924 	ASSERT_TRUE(dispConfigBefore.IsDefined(dispConfigBefore.EResolution))
  2925 	if (screenModeList.Count()>1)
  2926 		{
  2927 		//Got a mode to change to!
  2928 		TSize resBefore;
  2929 		TBool ok=dispConfigBefore.GetResolution(resBefore);
  2930 		ASSERT_TRUE(ok);	//we "know" this should be ok, as we just asserted the flag
  2931 		for (TInt res=0;res<screenModeList.Count();res++)
  2932 			{
  2933 				{
  2934 					{
  2935 					TDisplayConfiguration dispConfigReq;
  2936 					iInfoScreenDevice->SetAppScreenMode(screenModeList[res]);
  2937 					iInfoScreenDevice->SetScreenMode(screenModeList[res]);
  2938 					iSession.Finish(ETrue);
  2939 					Pause(300);
  2940 					
  2941 
  2942 					TSize pr = iInfoScreenDevice->SizeInPixels();
  2943 					TPoint 	origin=iInfoScreenDevice->GetDefaultScreenModeOrigin();					
  2944 					Pause(300);
  2945 					TSize winpos;
  2946 					
  2947 					TSize surfaceSize = pr;
  2948 					surfaceSize.iWidth /= 2;
  2949 					surfaceSize.iWidth -= 20;
  2950 					surfaceSize.iHeight -= 20;
  2951 					TSurfaceId surfaceID;
  2952 					TRAPD(err, surfaceID = iUtility->CreateSurfaceL(surfaceSize, 
  2953 								KSurfaceFormat, surfaceSize.iWidth * KBytesPerPixel));
  2954 					ASSERT_EQUALS(err,KErrNone);
  2955 					TRAP(err,iUtility->PatternFillSurfaceL(surfaceID));
  2956 					ASSERT_EQUALS(err,KErrNone);
  2957 								
  2958 					CFbsBitmap* equivalentBitmap=NULL;
  2959 					TRAP(err,equivalentBitmap=iUtility->EquivalentBitmapL(surfaceID));
  2960 					CleanupStack::PushL(equivalentBitmap);
  2961 					ASSERT_EQUALS(err,KErrNone);
  2962 					
  2963 					screenSize = iInfoScreenDevice->SizeInPixels();
  2964 					TSize testSize = iScreenDevice->SizeInPixels();
  2965 					screenSize.Shrink(5,5);
  2966 					
  2967 					if (iInfoGc)
  2968 						{
  2969 						testWindow.SetExtent(screenSize.iTl,screenSize.Size());
  2970 						
  2971 						if (testWindow.WsHandle())
  2972 							{
  2973 							
  2974 							iSession.Flush();
  2975 							iSession.Finish();
  2976 							}
  2977 						testWindow.SetVisible(ETrue);
  2978 						}
  2979 					Pause(200);			
  2980 					iSession.Finish(ETrue);
  2981 					
  2982 					RWindow surfWindow;
  2983 					if (iInfoGc)
  2984 						{
  2985 						surfWindow=RWindow(iSession);
  2986 						ASSERT_EQUALS(surfWindow.Construct(*iInfoGroup, ++iWindowHandle), KErrNone);
  2987 						surfWindow.SetBackgroundSurface(surfaceID);
  2988 						surfWindow.SetExtent(screenSize.iTl+TPoint( screenSize.Width()/2 +5,5),surfaceSize);
  2989 						surfWindow.Activate();
  2990 						
  2991 						if (surfWindow.WsHandle())
  2992 							{
  2993 							surfWindow.Invalidate();
  2994 						
  2995 							surfWindow.BeginRedraw();
  2996 							ActivateWithWipe(iInfoGc,surfWindow,iRed);
  2997 							surfWindow.EndRedraw();
  2998 						
  2999 							iSession.Flush();
  3000 							iSession.Finish();
  3001 							}
  3002 						surfWindow.SetVisible(ETrue);
  3003 						iInfoGc->Deactivate();
  3004 						}
  3005 					
  3006 					iSession.Finish(ETrue);
  3007 					
  3008 					TRect bitmapDrawRect;
  3009 					bitmapDrawRect = surfaceSize;
  3010 					
  3011 					RWindow bmpWindow;
  3012 					if (iInfoGc)
  3013 						{
  3014 						bmpWindow=RWindow(iSession);
  3015 						ASSERT_EQUALS(bmpWindow.Construct(*iInfoGroup, ++iWindowHandle), KErrNone);
  3016 						bmpWindow.SetBackgroundColor(iRed);
  3017 						bmpWindow.SetExtent(screenSize.iTl+TPoint(5,5),surfaceSize);
  3018 						bmpWindow.Activate();
  3019 						
  3020 						if (bmpWindow.WsHandle())
  3021 							{
  3022 							bmpWindow.Invalidate();
  3023 						
  3024 							bmpWindow.BeginRedraw();
  3025 							ActivateWithWipe(iInfoGc,bmpWindow,iRed);
  3026 							// Not drawing, draw twice??
  3027 							iInfoGc->DrawBitmap(bitmapDrawRect, equivalentBitmap);
  3028 							bmpWindow.EndRedraw();
  3029 						
  3030 							iSession.Flush();
  3031 							iSession.Finish();
  3032 							}
  3033 						bmpWindow.SetVisible(ETrue);
  3034 						iInfoGc->Deactivate();
  3035 						}
  3036 					Pause(200);			
  3037 					iSession.Finish(ETrue);
  3038 
  3039 					
  3040 					if (iInfoGc)
  3041 						{
  3042 						
  3043 						if (bmpWindow.WsHandle())
  3044 							{
  3045 							bmpWindow.Invalidate();
  3046 						
  3047 							bmpWindow.BeginRedraw();
  3048 							ActivateWithWipe(iInfoGc,bmpWindow,iRed);
  3049 							// Not drawing, draw twice??
  3050 							iInfoGc->DrawBitmap(bitmapDrawRect, equivalentBitmap);
  3051 							bmpWindow.EndRedraw();
  3052 							
  3053 							iSession.Flush();
  3054 							iSession.Finish();
  3055 							}
  3056 						bmpWindow.SetVisible(ETrue);
  3057 						iInfoGc->Deactivate();
  3058 						}
  3059 					Pause(200);			
  3060 					iSession.Finish(ETrue);
  3061 					
  3062 					if (iInfoGc)
  3063 						{
  3064 								
  3065 						if (bmpWindow.WsHandle())
  3066 							{
  3067 							bmpWindow.Invalidate();
  3068 											
  3069 							bmpWindow.BeginRedraw();
  3070 							ActivateWithWipe(iInfoGc,bmpWindow,iRed);
  3071 							// Not drawing, draw twice??
  3072 							iInfoGc->DrawBitmap(bitmapDrawRect, equivalentBitmap);
  3073 							bmpWindow.EndRedraw();
  3074 							iSession.Flush();
  3075 							iSession.Finish();
  3076 							}
  3077 						bmpWindow.SetVisible(ETrue);
  3078 						iInfoGc->Deactivate();
  3079 						}
  3080 					Pause(200);			
  3081 					iSession.Finish(ETrue);
  3082 
  3083 					RArray<TBitmapRegionPair> regionArray;					
  3084 
  3085 					RRegion equivRegion;
  3086 					TBitmapRegionPair bitmap1Region;
  3087 					bitmap1Region.bitmap = equivalentBitmap;
  3088 					bitmap1Region.drawRect = TRect(TPoint(0,0),surfaceSize);
  3089 					equivRegion.AddRect(TRect(TPoint(0,0),surfaceSize));
  3090 					bitmap1Region.region = &equivRegion;
  3091 
  3092 					regionArray.Append(bitmap1Region);
  3093 
  3094 
  3095 					TDisplayConfiguration dispConfigAfter2;
  3096 					interface->GetConfiguration(dispConfigAfter2);
  3097 					TSize theSize;
  3098 					dispConfigAfter2.GetResolution(theSize);
  3099 					TDisplayConfiguration1::TRotation orient;
  3100 					dispConfigAfter2.GetRotation(orient);
  3101 					if (orient == TDisplayConfiguration1::ERotation90CW || orient == TDisplayConfiguration1::ERotation270CW)
  3102 						{
  3103 						TInt temp = theSize.iHeight;
  3104 						theSize.iHeight = theSize.iWidth;
  3105 						theSize.iWidth = temp;
  3106 						}
  3107 					TRect uiSize(TPoint(0,0), theSize);
  3108 					MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  3109 								(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  3110 					ASSERT_TRUE(mappingInterface);
  3111 					TRect finalSize;
  3112 					mappingInterface->MapCoordinates(EApplicationSpace, uiSize, ECompositionSpace, finalSize);
  3113 						
  3114 
  3115 					CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  3116 					CleanupStack::PushL(bmp2);
  3117 					User::LeaveIfError(bmp2->Create(finalSize.Size(), EColor16MU));
  3118 
  3119 					MTestScreenCapture
  3120 							* csc =
  3121 									static_cast<MTestScreenCapture*> (iScreenDevice->GetInterface(MTestScreenCapture::KUidTestScreenCaptureIf));
  3122 					if (csc)
  3123 						{
  3124 						TInt errr = csc->ComposeScreen(*bmp2);
  3125 						ASSERT_TRUE(errr == KErrNone);
  3126 						}
  3127 					else
  3128 						{
  3129 						if (!cSCLogged)
  3130 							{
  3131 							cSCLogged = ETrue;
  3132 							_LIT(KNoCSC, "CSC testing not enabled as CSC render stage not defined");
  3133 							Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrAll, KNoCSC);
  3134 							}
  3135 						}
  3136 					
  3137 					
  3138 					TRect compareRect(bmpWindow.AbsPosition(), bmpWindow.Size());
  3139 					TRect testRect(surfWindow.AbsPosition(), surfWindow.Size());
  3140 
  3141 					if (csc)
  3142 						{
  3143 						if(!Compare(*bmp2, compareRect, testRect, regionArray, aIsSurface))
  3144 							{
  3145 							_LIT(KCompareFailed, "Compare Failed on app mode: %d");
  3146 							TBuf<256> x;
  3147 							x.Format(KCompareFailed, res+1);
  3148 							Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  3149 							}
  3150 						}
  3151 
  3152 					CleanupStack::PopAndDestroy(bmp2);
  3153 
  3154 					equivRegion.Close();
  3155 					regionArray.Close();
  3156 					
  3157 					CleanupStack::PopAndDestroy(equivalentBitmap);
  3158 					surfWindow.Close();
  3159 					bmpWindow.Close();
  3160 					}
  3161 				}
  3162 			}
  3163 		//restore initial res
  3164 		if (screenModeList.Count() > 1)
  3165             {   //set back to basics
  3166             iInfoScreenDevice->SetAppScreenMode(screenModeList[0]);
  3167             iInfoScreenDevice->SetScreenMode(screenModeList[0]);
  3168             Pause(300);
  3169             }
  3170 		
  3171 		interface->SetConfiguration(dispConfigBefore);
  3172 		Pause(1000);
  3173 		TDisplayConfiguration dispConfigAfter;
  3174 		interface->GetConfiguration(dispConfigAfter);
  3175 		TSize resAfter;
  3176 		ok=dispConfigAfter.GetResolution(resAfter);
  3177 		ASSERT_TRUE(ok);	
  3178 		ASSERT_EQUALS(resBefore,resAfter);
  3179 		}
  3180 	else
  3181 		{
  3182 		INFO_PRINTF1(_L("Only 1 screen size mode configured on this screen - res change test skipped."));
  3183 		}
  3184 	testWindow.Close();
  3185 	screenModeList.Close();
  3186 	resolutionList1.Close();
  3187 	}
  3188 	
  3189 
  3190 /**
  3191 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0042L
  3192 @SYMTestCaseDesc		Test Drawing of bitmaps (case 0) and surfaces (case 1) in all different resolutions
  3193 @SYMREQ					REQ10332
  3194 @SYMPREQ				PREQ2102
  3195 @SYMTestType			CT
  3196 @SYMTestPurpose			Check to see if Bitmaps and Surfaces are drawn correctly in different resolutions
  3197 @SYMTestActions			
  3198 	A Simple pattern will be drawn by a bitmap on the left and a surface on the right, about half the window size each. The Composited Screen Capture code will be used to compare the drawing to a unchanged copy of the bitmap to see if they are drawn correctly
  3199 	
  3200 	Note, add .0 to test name to test bitmap drawing and .1 to test surface drawing
  3201 @SYMTestExpectedResults	
  3202 	All tests should pass.
  3203 	
  3204 */
  3205 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0042L(TBool aIsSurface)
  3206 	{
  3207 	LOG_AND_PANIC_IF_NOT_GCE;
  3208 	ResetScreens();
  3209 	TInt error;
  3210 	iSession.Finish(ETrue);
  3211 	
  3212 	TRect screenSize(iInfoScreenDevice->SizeInPixels());
  3213 	screenSize.Shrink(5,5);
  3214 	
  3215 	RBlankWindow testWindow;
  3216 	if (iInfoGc)
  3217 		{
  3218 		testWindow=RBlankWindow(iSession);
  3219 		ASSERT_EQUALS(testWindow.Construct(*iInfoGroup, ++iWindowHandle), KErrNone);
  3220 		testWindow.SetColor(iBlue);
  3221 		testWindow.SetExtent(screenSize.iTl,screenSize.Size());
  3222 		testWindow.Activate();
  3223 		
  3224 		if (testWindow.WsHandle())
  3225 			{		
  3226 			iSession.Flush();
  3227 			iSession.Finish();
  3228 			}
  3229 		testWindow.SetVisible(ETrue);
  3230 		}
  3231 	
  3232 	iSession.Finish(ETrue);
  3233 	
  3234 	RArray<TInt> screenModeList;
  3235 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  3236 	MDisplayControl* interface = static_cast<MDisplayControl*>
  3237 				(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  3238 	ASSERT_TRUE(interface);
  3239 	
  3240 	TInt resolutions = interface->NumberOfResolutions();
  3241 	ASSERT_TRUE (resolutions > 0);
  3242 	
  3243 	RArray<MDisplayControl::TResolution> resolutionList1;
  3244 	error = interface->GetResolutions(resolutionList1);
  3245 	ASSERT_EQUALS(error,KErrNone);
  3246 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  3247 	
  3248 	TDisplayConfiguration dispConfigBefore;
  3249 	interface->GetConfiguration(dispConfigBefore);
  3250 
  3251 	iInfoScreenDevice->SetAppScreenMode(screenModeList[1]);
  3252 	iInfoScreenDevice->SetScreenMode(screenModeList[1]);
  3253 	iSession.Finish();
  3254 	Pause(50);
  3255 	
  3256 	if (resolutions>1)
  3257 		{
  3258 		//Got a mode to change to!
  3259 		TSize resBefore;
  3260 		TBool ok=dispConfigBefore.GetResolution(resBefore);
  3261 		ASSERT_TRUE(ok);	//we "know" this should be ok, as we just asserted the flag
  3262 		for (TInt res=0;res<resolutionList1.Count();res++)
  3263 			{
  3264 			if (resolutionList1[res].iPixelSize!=TSize(0,0))	//this test is not about turning the display off
  3265 				{
  3266 				TDisplayConfiguration dispConfigReq;
  3267 				dispConfigReq.SetResolution(resolutionList1[res].iPixelSize);
  3268 				ASSERT_TRUE(dispConfigReq.IsDefined(dispConfigReq.EResolution));
  3269 				
  3270 				SetRotation(dispConfigReq,resolutionList1[res]);	//set rotation to first defined in res list
  3271 				
  3272 				
  3273 				
  3274 
  3275 				TInt errCode=interface->SetConfiguration(dispConfigReq);
  3276 				//ASSERT_EQUALS(errCode,KErrNone);
  3277 				if (errCode != KErrNone)
  3278 					{
  3279 					//Probably current size mode does not support the rotation of the passed in configuration
  3280 					
  3281 					ASSERT_EQUALS(errCode,KErrArgument);	//failed to find compatible res in the policy
  3282 					continue;
  3283 					}
  3284 				
  3285 				
  3286 				TSize pr = iInfoScreenDevice->SizeInPixels();
  3287 				TPoint 	origin=iInfoScreenDevice->GetDefaultScreenModeOrigin();					
  3288 				Pause(300);
  3289 				TSize winpos;
  3290 				
  3291 				TSize surfaceSize = pr;
  3292 				surfaceSize.iWidth /= 2;
  3293 				surfaceSize.iWidth -= 20;
  3294 				surfaceSize.iHeight -= 20;
  3295 				TSurfaceId surfaceID;
  3296 				TRAPD(err, surfaceID = iUtility->CreateSurfaceL(surfaceSize, 
  3297 							KSurfaceFormat, surfaceSize.iWidth * KBytesPerPixel));
  3298 				ASSERT_EQUALS(err,KErrNone);
  3299 				TRAP(err,iUtility->PatternFillSurfaceL(surfaceID));
  3300 				ASSERT_EQUALS(err,KErrNone);
  3301 							
  3302 				CFbsBitmap* equivalentBitmap=NULL;
  3303 				TRAP(err,equivalentBitmap=iUtility->EquivalentBitmapL(surfaceID));
  3304 				CleanupStack::PushL(equivalentBitmap);
  3305 				ASSERT_EQUALS(err,KErrNone);
  3306 				
  3307 				screenSize = iInfoScreenDevice->SizeInPixels();
  3308 				screenSize.Shrink(5,5);
  3309 				
  3310 				if (iInfoGc)
  3311 					{
  3312 					testWindow.SetExtent(screenSize.iTl,screenSize.Size());
  3313 					
  3314 					if (testWindow.WsHandle())
  3315 						{
  3316 						
  3317 						iSession.Flush();
  3318 						iSession.Finish();
  3319 						}
  3320 					testWindow.SetVisible(ETrue);
  3321 					}
  3322 				Pause(200);			
  3323 				iSession.Finish(ETrue);
  3324 				
  3325 				RWindow surfWindow;
  3326 				if (iInfoGc)
  3327 					{
  3328 					surfWindow=RWindow(iSession);
  3329 					ASSERT_EQUALS(surfWindow.Construct(*iInfoGroup, ++iWindowHandle), KErrNone);
  3330 					surfWindow.SetBackgroundSurface(surfaceID);
  3331 					surfWindow.SetExtent(screenSize.iTl+TPoint( screenSize.Width()/2 +5,5),surfaceSize);
  3332 					surfWindow.Activate();
  3333 					
  3334 					if (surfWindow.WsHandle())
  3335 						{
  3336 						surfWindow.Invalidate();
  3337 					
  3338 						surfWindow.BeginRedraw();
  3339 						ActivateWithWipe(iInfoGc,surfWindow,iRed);
  3340 						surfWindow.EndRedraw();
  3341 					
  3342 						iSession.Flush();
  3343 						iSession.Finish();
  3344 						}
  3345 					surfWindow.SetVisible(ETrue);
  3346 					iInfoGc->Deactivate();
  3347 					}
  3348 				
  3349 				iSession.Finish(ETrue);
  3350 				
  3351 				TRect bitmapDrawRect;
  3352 				bitmapDrawRect = surfaceSize;
  3353 				
  3354 				RWindow bmpWindow;
  3355 				if (iInfoGc)
  3356 					{
  3357 					bmpWindow=RWindow(iSession);
  3358 					ASSERT_EQUALS(bmpWindow.Construct(*iInfoGroup, ++iWindowHandle), KErrNone);
  3359 					bmpWindow.SetBackgroundColor(iRed);
  3360 					bmpWindow.SetExtent(screenSize.iTl+TPoint(5,5),surfaceSize);
  3361 					bmpWindow.Activate();
  3362 					
  3363 					if (bmpWindow.WsHandle())
  3364 						{
  3365 						bmpWindow.Invalidate();
  3366 					
  3367 						bmpWindow.BeginRedraw();
  3368 						ActivateWithWipe(iInfoGc,bmpWindow,iRed);
  3369 						// Not drawing, draw twice??
  3370 						iInfoGc->DrawBitmap(bitmapDrawRect, equivalentBitmap);
  3371 						bmpWindow.EndRedraw();
  3372 					
  3373 						iSession.Flush();
  3374 						iSession.Finish();
  3375 						}
  3376 					bmpWindow.SetVisible(ETrue);
  3377 					iInfoGc->Deactivate();
  3378 					}
  3379 				Pause(200);			
  3380 				iSession.Finish(ETrue);
  3381 				
  3382 				
  3383 				if (iInfoGc)
  3384 					{
  3385 					
  3386 					if (bmpWindow.WsHandle())
  3387 						{
  3388 						bmpWindow.Invalidate();
  3389 							
  3390 						bmpWindow.BeginRedraw();
  3391 						ActivateWithWipe(iInfoGc,bmpWindow,iRed);
  3392 						// Not drawing, draw twice??
  3393 						iInfoGc->DrawBitmap(bitmapDrawRect, equivalentBitmap);
  3394 						bmpWindow.EndRedraw();
  3395 											
  3396 						iSession.Flush();
  3397 						iSession.Finish();
  3398 						}
  3399 					bmpWindow.SetVisible(ETrue);
  3400 					iInfoGc->Deactivate();
  3401 					}
  3402 				Pause(200);			
  3403 				iSession.Finish(ETrue);
  3404 									
  3405 
  3406 				
  3407 
  3408 				RArray<TBitmapRegionPair> regionArray;					
  3409 
  3410 				RRegion equivRegion;
  3411 				TBitmapRegionPair bitmap1Region;
  3412 				bitmap1Region.bitmap = equivalentBitmap;
  3413 				bitmap1Region.drawRect = TRect(TPoint(0,0),surfaceSize);
  3414 				equivRegion.AddRect(TRect(TPoint(0,0),surfaceSize));
  3415 				bitmap1Region.region = &equivRegion;
  3416 
  3417 				regionArray.Append(bitmap1Region);
  3418 
  3419 
  3420 				TDisplayConfiguration dispConfigAfter2;
  3421 				interface->GetConfiguration(dispConfigAfter2);
  3422 				TSize theSize;
  3423 				dispConfigAfter2.GetResolution(theSize);
  3424 				TDisplayConfiguration1::TRotation orient;
  3425 				dispConfigAfter2.GetRotation(orient);
  3426 				if (orient & 0x1)
  3427 					{
  3428 					TInt temp = theSize.iHeight;
  3429 					theSize.iHeight = theSize.iWidth;
  3430 					theSize.iWidth = temp;
  3431 					}
  3432 				TRect uiSize(TPoint(0,0), theSize);
  3433 				MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  3434 							(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  3435 				ASSERT_TRUE(mappingInterface);
  3436 				TRect finalSize;
  3437 				mappingInterface->MapCoordinates(EApplicationSpace, uiSize, ECompositionSpace, finalSize);
  3438 
  3439 				
  3440 				
  3441 
  3442 				CFbsBitmap* bmp2 = new (ELeave) CFbsBitmap;
  3443 				CleanupStack::PushL(bmp2);
  3444 				TInt bmpErr = bmp2->Create(finalSize.Size(), EColor16MU);
  3445 				ASSERT_EQUALS(bmpErr, KErrNone);
  3446 
  3447 				MTestScreenCapture
  3448 						* csc =
  3449 								static_cast<MTestScreenCapture*> (iScreenDevice->GetInterface(MTestScreenCapture::KUidTestScreenCaptureIf));
  3450 				if (csc)
  3451 					{
  3452 					TInt errr = csc->ComposeScreen(*bmp2);
  3453 					}
  3454 				else
  3455 					{
  3456 					if (!cSCLogged)
  3457 						{
  3458 						cSCLogged = ETrue;
  3459 						_LIT(KNoCSC, "CSC testing not enabled as CSC render stage not defined");
  3460 						Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrAll, KNoCSC);
  3461 						}
  3462 					}
  3463 				TRect compareRect(bmpWindow.AbsPosition(), bmpWindow.Size());
  3464 				TRect testRect(surfWindow.AbsPosition(), surfWindow.Size());
  3465 
  3466 				if (csc)
  3467 					{
  3468 					if(!Compare(*bmp2, compareRect, testRect, regionArray, aIsSurface))
  3469 						{
  3470 						_LIT(KCompareFailed, "Compare Failed on resolution: %d");
  3471 						TBuf<256> x;
  3472 						x.Format(KCompareFailed, res+1);
  3473 						Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, x);
  3474 						}
  3475 					}
  3476 				CleanupStack::PopAndDestroy(bmp2);
  3477 
  3478 				equivRegion.Close();
  3479 				regionArray.Close();
  3480 				
  3481 				CleanupStack::PopAndDestroy(equivalentBitmap);
  3482 				surfWindow.Close();
  3483 				bmpWindow.Close();
  3484 				}
  3485 			}
  3486 			//restore initial res
  3487 			iInfoScreenDevice->SetAppScreenMode(0);
  3488 			iInfoScreenDevice->SetScreenMode(0);
  3489 			}
  3490 		else
  3491 			{
  3492 			INFO_PRINTF1(_L("Only 1 screen size mode configured on this screen - res change test skipped."));
  3493 			}
  3494 		testWindow.Close();
  3495 		screenModeList.Close();
  3496 		resolutionList1.Close();
  3497 	}
  3498 
  3499 
  3500 /**
  3501  Tests to see if the pixels in the bitmap match what should be drawn with regards to the bitmaps and regions in aBitmapRegionPairArray
  3502  It does this by in the case of non-scaled bitmaps, performing a pixel by pixel comparison between what has been drawn to the CSC created bitmap and either the pixels of the bitmap if they are contained within the related region or the pixels of the simulation screen. In the case of scalingm only certain pixels are compared from the CSC bitmap to the comparison drawing as the scaling algorithm is hard to replicate.
  3503 
  3504 
  3505  @param aBitmap a bitmap of the entire screen which should be generated using the Composited Screen Capture code
  3506  @param aRect1 A rectangle representing the middle window in the comparison triple
  3507  @param aRect2 A rectangle represneting the right window in the comparison triple
  3508  @param aBitmapRegionPairArray An array of the different regions that are being drawn on the screen. They should be placed in order such that the closest to the foreground is first and the furthest away is last in the queue. Each member of the array is a misleadingly titled TBitmapRegion pair, the bitmap member of this should be the bitmap that is being drawn to the region of the screen, if the region is just a blank color then a blank color bitmap should be drawn. The region should be the region that the bitmap is being drawn to and should be the same as the clipping region which is set jsut before the bitmap is drawn to screen. Finally the draw rect is the basic rectangle the bitmap is being drawn to and is mainly used to test if the bitmap is being scaled
  3509  @return True
  3510  */
  3511 TBool CWsDynamicResBasic::Compare(const CFbsBitmap& aBitmap,
  3512 		const TRect& aRect1, const TRect& aRect2,
  3513 		RArray<TBitmapRegionPair>& aBitmapRegionPairArray, TBool aIsSurface)
  3514 	{
  3515 	MDisplayMapping* mappingInterface = static_cast<MDisplayMapping*>
  3516 				(iScreenDevice->GetInterface(MDisplayMapping::ETypeId));
  3517 	ASSERT_TRUE(mappingInterface);
  3518 		
  3519 	
  3520 	TRgb color1;
  3521 	TRgb color2;
  3522 
  3523 	TInt errorPixels =0;
  3524 	TInt diffPixels = 0;
  3525 	RRegion ignoreDueToResizing;
  3526 	TInt regionCount = aBitmapRegionPairArray.Count();
  3527 	for (TInt i=regionCount-1; i>=0; i--)
  3528 		{
  3529 		if (aBitmapRegionPairArray[i].bitmap->SizeInPixels()
  3530 				!= aBitmapRegionPairArray[i].drawRect.Size())
  3531 			{
  3532 			RArray<TPoint> corners;
  3533 			corners.Append(aBitmapRegionPairArray[i].drawRect.iTl);
  3534 			corners.Append(TPoint(aBitmapRegionPairArray[i].drawRect.iBr.iX-1,
  3535 					aBitmapRegionPairArray[i].drawRect.iTl.iY));
  3536 			corners.Append(TPoint(aBitmapRegionPairArray[i].drawRect.iTl.iX,
  3537 					aBitmapRegionPairArray[i].drawRect.iBr.iY-1));
  3538 			corners.Append(aBitmapRegionPairArray[i].drawRect.iBr- TPoint(1,1));
  3539 			for (TInt j=0; j<corners.Count(); j++)
  3540 				{
  3541 				TBool inOther=EFalse;
  3542 				for (TInt k=0; k<i; k++)
  3543 					{
  3544 					if (aBitmapRegionPairArray[k].region->Contains(corners[j]))
  3545 						{
  3546 						inOther = ETrue;
  3547 						}
  3548 					}
  3549 				if (inOther)
  3550 					{
  3551 					continue;
  3552 					}
  3553 				aBitmap.GetPixel(color1, aRect2.iTl + corners[j]);
  3554 				aBitmap.GetPixel(color2, aRect1.iTl + corners[j]);
  3555 				TRgb color3 = GreatestColor(color1);
  3556 				TRgb color4 = GreatestColor(color2);
  3557 				if (color3 != color4)
  3558 					{
  3559 					// Bitmap copy can be off by a pixel on grid filled surface so allow for green and yellow to be treated equally as they are the background colours, this may allow a misfunctioning gce to pass the test though.
  3560 					if (color4 == TRgb(0, 1, 0) && color3 == TRgb(1, 1, 0))
  3561 						{
  3562 						}
  3563 					else
  3564 						if (color4 == TRgb(1, 1, 0) && color3 == TRgb(0, 1, 0))
  3565 							{
  3566 							}
  3567 						else
  3568 							{
  3569 							corners.Close();
  3570 							return EFalse;
  3571 							}
  3572 					}
  3573 
  3574 				}
  3575 			// testPoints contains first the pixel within the destRect followed by the pixel in the original position for comparison to
  3576 			RArray<TPoint> testPoints;
  3577 			testPoints.Append(aBitmapRegionPairArray[i].drawRect.Center());
  3578 			testPoints.Append(TPoint(
  3579 					aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth/2,
  3580 					aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight/2));
  3581 			testPoints.Append(TPoint(aBitmapRegionPairArray[i].drawRect.iTl.iX,
  3582 					aBitmapRegionPairArray[i].drawRect.Center().iY));
  3583 			testPoints.Append(TPoint(0,
  3584 					aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight/2));
  3585 			testPoints.Append(TPoint(aBitmapRegionPairArray[i].drawRect.iBr.iX
  3586 					-1, aBitmapRegionPairArray[i].drawRect.Center().iY));
  3587 			testPoints.Append(TPoint(
  3588 					aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth-1,
  3589 					aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight/2));
  3590 			TSize sizeee = aBitmapRegionPairArray[i].drawRect.Size();
  3591 			if (aBitmapRegionPairArray[i].drawRect.Size().iWidth > 11 && aBitmapRegionPairArray[i].drawRect.Size().iHeight > 20)
  3592 				{
  3593 				testPoints.Append(TPoint(
  3594 						aBitmapRegionPairArray[i].drawRect.Center().iX, aBitmapRegionPairArray[i].drawRect.iTl.iY));
  3595 				testPoints.Append(TPoint(
  3596 						aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth/2, 0));
  3597 
  3598 				testPoints.Append(TPoint(
  3599 						aBitmapRegionPairArray[i].drawRect.Center().iX, aBitmapRegionPairArray[i].drawRect.iBr.iY-1));
  3600 				testPoints.Append(TPoint(
  3601 						aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth/2,
  3602 						aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight-1));
  3603 
  3604 				if (aBitmapRegionPairArray[i].drawRect.Size().iWidth > 34
  3605 						&& aBitmapRegionPairArray[i].drawRect.Size().iHeight > 43)
  3606 					{
  3607 					testPoints.Append(aBitmapRegionPairArray[i].drawRect.iTl
  3608 							+ TPoint(5, 5));
  3609 					testPoints.Append(TPoint(5, 5));
  3610 					testPoints.Append(TPoint(
  3611 							aBitmapRegionPairArray[i].drawRect.iBr.iX - 6,
  3612 							aBitmapRegionPairArray[i].drawRect.iTl.iY + 5));
  3613 					testPoints.Append(TPoint(
  3614 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth-6, 5));
  3615 					testPoints.Append(TPoint(
  3616 							aBitmapRegionPairArray[i].drawRect.iTl.iX + 5,
  3617 							aBitmapRegionPairArray[i].drawRect.iBr.iY -6));
  3618 					testPoints.Append(TPoint(5,
  3619 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight - 6));
  3620 					testPoints.Append(aBitmapRegionPairArray[i].drawRect.iBr
  3621 							- TPoint(6, 6));
  3622 					testPoints.Append(TPoint(
  3623 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth-6,
  3624 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight-6));
  3625 					}
  3626 				else
  3627 					{
  3628 					testPoints.Append(aBitmapRegionPairArray[i].drawRect.iTl
  3629 							+ TPoint(2, 3));
  3630 					testPoints.Append(TPoint(5, 5));
  3631 					testPoints.Append(TPoint(
  3632 							aBitmapRegionPairArray[i].drawRect.iBr.iX - 3,
  3633 							aBitmapRegionPairArray[i].drawRect.iTl.iY + 3));
  3634 					testPoints.Append(TPoint(
  3635 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth-6, 5));
  3636 					testPoints.Append(TPoint(
  3637 							aBitmapRegionPairArray[i].drawRect.iTl.iX + 2,
  3638 							aBitmapRegionPairArray[i].drawRect.iBr.iY -4));
  3639 					testPoints.Append(TPoint(5,
  3640 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight - 6));
  3641 					testPoints.Append(aBitmapRegionPairArray[i].drawRect.iBr
  3642 							- TPoint(3, 4));
  3643 					testPoints.Append(TPoint(
  3644 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iWidth-6,
  3645 							aBitmapRegionPairArray[i].bitmap->SizeInPixels().iHeight-6));
  3646 					}
  3647 				}
  3648 			for (int jj=0; jj<testPoints.Count(); jj+=2)
  3649 				{
  3650 				TBool inOther=EFalse;
  3651 				if (!aBitmapRegionPairArray[i].region->Contains(testPoints[jj]))
  3652 					{
  3653 					continue;
  3654 					}
  3655 				for (TInt k=0; k<i; k++)
  3656 					{
  3657 					if (aBitmapRegionPairArray[k].region->Contains(testPoints[jj]))
  3658 						{
  3659 						inOther = ETrue;
  3660 						}
  3661 					}
  3662 				if (inOther)
  3663 					{
  3664 					continue;
  3665 					}
  3666 				TPoint currentPoint = testPoints[jj];
  3667 				TRect bound = aBitmapRegionPairArray[i].region->BoundingRect();
  3668 				TBool
  3669 						contat =
  3670 								aBitmapRegionPairArray[i].region->Contains(testPoints[jj]);
  3671 				aBitmap.GetPixel(color1, aRect2.iTl + testPoints[jj]);
  3672 				aBitmapRegionPairArray[i].bitmap->GetPixel(color2,
  3673 						testPoints[jj+1]);
  3674 				TRgb color5 = GreatestColor(color1);
  3675 				TRgb color6 = GreatestColor(color2);
  3676 				if (color5 != color6)
  3677 					{
  3678 					// Bitmap copy can be off by a pixel on grid filled surface so allow for green and yellow to be treated equally as they are the background colours, this may allow a misfunctioning gce to pass the test though.
  3679 					if (color6 == TRgb(0, 1, 0) && color5 == TRgb(1, 1, 0))
  3680 						{
  3681 						}
  3682 					else
  3683 						if (color6 == TRgb(1, 1, 0) && color5 == TRgb(0, 1, 0))
  3684 							{
  3685 							}
  3686 						else
  3687 							{
  3688 							testPoints.Close();
  3689 							return EFalse;
  3690 							}
  3691 					}
  3692 				}
  3693 
  3694 			testPoints.Close();
  3695 			corners.Close();
  3696 			ignoreDueToResizing.Union(*aBitmapRegionPairArray[i].region);
  3697 			aBitmapRegionPairArray.Remove(i);
  3698 			}
  3699 		}
  3700 
  3701 	RRegion superRegion;
  3702 
  3703 	regionCount = aBitmapRegionPairArray.Count();
  3704 
  3705 	for (TInt i=0; i<regionCount; i++)
  3706 		{
  3707 		superRegion.Union(*(aBitmapRegionPairArray[i].region));
  3708 		}
  3709 	TRect boundingRect = superRegion.BoundingRect();
  3710 	superRegion.Close();
  3711 	TInt width = boundingRect.Width();
  3712 	TInt height = boundingRect.Height();
  3713 	TInt xStart = boundingRect.iTl.iX;
  3714 	TInt yStart = boundingRect.iTl.iY;
  3715 	
  3716 	TSize superSize = aBitmap.SizeInPixels();
  3717 	TRgb HHH1;
  3718 	TInt nonWhiteCount = 0;
  3719 	for (TInt iii = 0; iii<superSize.iWidth; iii++)
  3720 		{
  3721 		for (TInt jjj=0; jjj<superSize.iHeight; jjj++)
  3722 			{
  3723 			aBitmap.GetPixel(HHH1, TPoint(iii,jjj));
  3724 			if (HHH1 != TRgb (255, 255, 255))
  3725 				{
  3726 				nonWhiteCount++;
  3727 				}
  3728 			}
  3729 		}
  3730 
  3731 	if (aBitmapRegionPairArray.Count()>0)
  3732 		{
  3733         RDebug::Printf("Checking");
  3734         TInt countchecks=0;
  3735 		for (TInt i=0; i<width; i++)
  3736 			{
  3737 			for (TInt j=0; j<height; j++)
  3738 				{
  3739 				TInt arrayIndex = 0;
  3740 				TBool pointInArray= EFalse;
  3741 				TPoint currentPoint(xStart + i, yStart + j);
  3742 				if (!ignoreDueToResizing.Contains(currentPoint))
  3743 					{
  3744 					do
  3745 						{
  3746 						if (aBitmapRegionPairArray[arrayIndex].region->Contains(currentPoint))
  3747 							{							
  3748 							if (aIsSurface)
  3749 								{
  3750 								TPoint checkPoint = currentPoint + aRect2.iTl;
  3751 								TRect readBackRect;
  3752 								mappingInterface->MapCoordinates(EApplicationSpace, TRect(checkPoint, TSize(1,1)), ECompositionSpace, readBackRect);
  3753 								aBitmap.GetPixel(color1, readBackRect.iTl);
  3754 								}
  3755 							else 
  3756 								{
  3757 								TPoint checkPoint = currentPoint + aRect1.iTl;
  3758 								TRect readBackRect;
  3759 								mappingInterface->MapCoordinates(EApplicationSpace, TRect(checkPoint, TSize(1,1)), ECompositionSpace, readBackRect);
  3760 								aBitmap.GetPixel(color1, readBackRect.iTl);
  3761 								}
  3762 
  3763 							aBitmapRegionPairArray[arrayIndex].bitmap->GetPixel(color2,	currentPoint
  3764 																		- aBitmapRegionPairArray[arrayIndex].drawRect.iTl);
  3765 							
  3766 							TRgb color7 = GreatestColor(color1);
  3767 							TRgb color8 = GreatestColor(color2);
  3768 
  3769 							if (color7 != color8)
  3770 								{
  3771 								diffPixels++;
  3772 								//return EFalse;
  3773 								}
  3774 							pointInArray = ETrue;
  3775 							}
  3776 						arrayIndex++;
  3777 						}
  3778 					while (!pointInArray && !(arrayIndex
  3779 							>= aBitmapRegionPairArray.Count()));
  3780 
  3781 					if (!pointInArray)
  3782 						{
  3783 						aBitmap.GetPixel(color1, TPoint(i + aRect2.iTl.iX
  3784 								+ xStart, j +aRect2.iTl.iY +yStart));
  3785 						aBitmap.GetPixel(color2, TPoint(i + aRect1.iTl.iX
  3786 								+xStart, j +aRect1.iTl.iY+yStart));
  3787 						// Bitmap copy is duller on first few iterations so just pick the greatest color or two colors and see if they match
  3788 						TRgb color3 = GreatestColor(color1);
  3789 						TRgb color4 = GreatestColor(color2);
  3790 
  3791 						if (color3 != color4)
  3792 							{
  3793 							// Bitmap copy can be off by a pixel on grid filled surface so allow for green and yellow to be treated equally as they are the background colours, this may allow a misfunctioning gce to pass the test though.
  3794 							if (GreatestColor(color2) == TRgb(0, 1, 0)
  3795 									&& GreatestColor(color1) == TRgb(1, 1, 0))
  3796 								{
  3797 								continue;
  3798 								}
  3799 							else
  3800 								if (GreatestColor(color2) == TRgb(1, 1, 0)
  3801 										&& GreatestColor(color1) == TRgb(0, 1,
  3802 												0))
  3803 									{
  3804 									continue;
  3805 									}
  3806 								else
  3807 									{
  3808 									errorPixels++;
  3809 									//return EFalse;
  3810 									}
  3811 							}
  3812 						}
  3813 					}
  3814 				}
  3815 			}
  3816 		}
  3817 	
  3818 	ignoreDueToResizing.Close();
  3819 	if (errorPixels+diffPixels < 2)
  3820 		{
  3821 		return ETrue;
  3822 		}
  3823 	else
  3824 		{
  3825 		return EFalse;
  3826 		}
  3827 
  3828 	}
  3829 
  3830 
  3831 /*
  3832   Creates a rough apprxoiamtion to the color pass in. This is used because of issues with the bitmap drwaing in the comparison window. If these issues are fixed then this method can be changed to simply return aColor.
  3833 
  3834  @param aColor the color to be approximated
  3835  @return an approximation of aColor.
  3836  */
  3837 TRgb CWsDynamicResBasic::GreatestColor(TRgb& aColor) const
  3838 	{
  3839 	TInt test = aColor.Difference(TRgb(0, 0, 0));
  3840 	// Accounts for a case when Rgb = 20,20,20 due to poor bitmap drawing
  3841 	if (aColor == TRgb(32, 32, 32))
  3842 		{
  3843 		return TRgb(0, 0, 0);
  3844 		}
  3845 	if (aColor == TRgb(0, 0, 0))
  3846 		{
  3847 		return TRgb(0, 0, 0);
  3848 		}
  3849 	TRgb test2;
  3850 	test2.SetInternal(0xFFFEDF01);
  3851 	if (aColor == test2)
  3852 		{
  3853 		return TRgb(1, 1, 0);
  3854 		}
  3855 
  3856 	if (test < 70)
  3857 		{
  3858 		return TRgb(0, 0, 0);
  3859 		}
  3860 	if (aColor.Green() > aColor.Blue())
  3861 		{
  3862 		if (aColor.Green() > aColor.Red())
  3863 			{
  3864 			return TRgb(0, 1, 0);
  3865 			}
  3866 		else
  3867 			if (aColor.Green() == aColor.Red())
  3868 				{
  3869 				return TRgb(1, 1, 0);
  3870 				}
  3871 		}
  3872 	if (aColor.Green() > aColor.Red())
  3873 		{
  3874 		if (aColor.Green() > aColor.Blue())
  3875 			{
  3876 			return TRgb(0, 1, 0);
  3877 			}
  3878 		else
  3879 			if (aColor.Green() == aColor.Blue())
  3880 				{
  3881 				return TRgb(0, 1, 1);
  3882 				}
  3883 		}
  3884 
  3885 	if (aColor.Red() > aColor.Green())
  3886 		{
  3887 		if (aColor.Red() > aColor.Blue())
  3888 			{
  3889 			return TRgb(1, 0, 0);
  3890 			}
  3891 		else
  3892 			if (aColor.Red() == aColor.Blue())
  3893 				{
  3894 				return TRgb(1, 0, 1);
  3895 				}
  3896 		}
  3897 	if (aColor.Red() > aColor.Blue())
  3898 		{
  3899 		if (aColor.Red() > aColor.Green())
  3900 			{
  3901 			return TRgb(1, 0, 0);
  3902 			}
  3903 		else
  3904 			if (aColor.Red() == aColor.Green())
  3905 				{
  3906 				return TRgb(1, 1, 0);
  3907 				}
  3908 		}
  3909 
  3910 	if (aColor.Blue() > aColor.Red())
  3911 		{
  3912 		if (aColor.Blue() > aColor.Green())
  3913 			{
  3914 			return TRgb(0, 0, 1);
  3915 			}
  3916 		else
  3917 			if (aColor.Blue() == aColor.Green())
  3918 				{
  3919 				return TRgb(0, 1, 1);
  3920 				}
  3921 		}
  3922 	if (aColor.Blue() > aColor.Green())
  3923 		{
  3924 		if (aColor.Blue() > aColor.Red())
  3925 			{
  3926 			return TRgb(0, 0, 1);
  3927 			}
  3928 		else
  3929 			if (aColor.Blue() == aColor.Red())
  3930 				{
  3931 				return TRgb(1, 0, 1);
  3932 				}
  3933 		}
  3934 
  3935 	// Should never reach here, but the compiler cannot be sure
  3936 	return TRgb(0, 0, 0);
  3937 	}
  3938 
  3939 /*
  3940 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0051L
  3941 @SYMTestCaseDesc		Getting if a mode is dynamic
  3942 @SYMREQ					REQ11554
  3943 @SYMPREQ				PREQ2102
  3944 @SYMTestType			CT
  3945 @SYMTestPriority		1
  3946 @SYMTestPurpose			Check functions work correctly
  3947 @SYMTestActions			
  3948 	Do IsModeDynamic for a wrong mode number
  3949 	Do IsModeDynamic for a mode that isnt dynamic
  3950 	Do IsModeDynamic for a mode that is dynamic
  3951 	Do IsCurrentModeDynamic when current mode is not dynamic
  3952 	Do IsCurrentModeDynamic when current mode is dynamic
  3953 	MODE 10 must be dynamic
  3954 @SYMTestExpectedResults	
  3955 	All should return as expected.
  3956 */
  3957 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0051L()
  3958 	{
  3959 	RArray<TInt> screenModeList;
  3960 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  3961 	iInfoScreenDevice->SetAppScreenMode(0);
  3962 	iInfoScreenDevice->SetScreenMode(0);
  3963 	iSession.Flush();
  3964 	Pause(50);
  3965 	ASSERT_FALSE(iInfoScreenDevice->IsModeDynamic(25));
  3966 	ASSERT_FALSE(iInfoScreenDevice->IsModeDynamic(1));
  3967 	ASSERT_TRUE(iInfoScreenDevice->IsModeDynamic(10));
  3968 	ASSERT_FALSE(iInfoScreenDevice->IsCurrentModeDynamic());
  3969 	iInfoScreenDevice->SetAppScreenMode(10);
  3970 	iInfoScreenDevice->SetScreenMode(10);
  3971 	iSession.Flush();
  3972 	Pause(50);
  3973 	ASSERT_TRUE(iInfoScreenDevice->IsCurrentModeDynamic());
  3974 	screenModeList.Close();
  3975 	iInfoScreenDevice->SetAppScreenMode(0);
  3976 	iInfoScreenDevice->SetScreenMode(0);
  3977 	}
  3978 
  3979 /* Takes any 0x0 resolutions out of the res list, useful for some tests
  3980 */
  3981 void ResListCleanup(RArray<MDisplayControl::TResolution>& aResList)
  3982 	{
  3983 	for (TInt ii=0; ii<aResList.Count(); ii++)
  3984 		{
  3985 		if (aResList[ii].iPixelSize.iWidth == 0 ||
  3986 				aResList[ii].iPixelSize.iHeight == 0)
  3987 			{
  3988 			aResList.Remove(ii);
  3989 			ii--;
  3990 			}
  3991 		}
  3992 	}
  3993 
  3994 /*
  3995 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0052L
  3996 @SYMTestCaseDesc		Getting if a mode is dynamic
  3997 @SYMREQ					REQ11554
  3998 @SYMPREQ				PREQ2102
  3999 @SYMTestType			CT
  4000 @SYMTestPriority		1
  4001 @SYMTestPurpose			Check functions work correctly
  4002 @SYMTestActions			
  4003 	For every standard screen mode
  4004 		Check twips and pixel conversions are correct based on screen mode values
  4005 	Set dynamic app mode
  4006 	For every resolution
  4007 		Check twips and pixel conversions are correct based on physical screen values
  4008 @SYMTestExpectedResults	
  4009 	All should return as expected.
  4010 	NOTE- there must be a dynamic screen mode available
  4011 	NOTE- only run on a screen with multiple resolutions available
  4012 */
  4013 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0052L()
  4014 	{
  4015 	MDisplayControl* interface = static_cast<MDisplayControl*>
  4016 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  4017 	ASSERT_TRUE(interface);
  4018 	
  4019 	TInt resolutions = interface->NumberOfResolutions();
  4020 	ASSERT_TRUE (resolutions > 1);
  4021 		
  4022 	RArray<MDisplayControl::TResolution> resolutionList1;
  4023 	TInt error = interface->GetResolutions(resolutionList1);
  4024 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  4025 	ResListCleanup(resolutionList1);	//remove any 0x0
  4026 	ASSERT_TRUE (resolutionList1.Count() > 1);	//without multiple proper res this test is pointless
  4027 	
  4028 	TDisplayConfiguration newResolution;
  4029 	newResolution.SetResolution(resolutionList1[0].iPixelSize);
  4030 	error = interface->SetConfiguration(newResolution);
  4031 	ASSERT_EQUALS(error,KErrNone);
  4032 	
  4033 	TSizeMode info;
  4034 	RArray<TInt> screenModes;
  4035 	error = iInfoScreenDevice->GetScreenSizeModeList(&screenModes);
  4036 	ASSERT_TRUE(error>KErrNone);
  4037 	TInt dynamicMode1 = -1;
  4038 	TInt dynamicMode2 = -1;
  4039 	TPixelsTwipsAndRotation modeAttributes;
  4040 	
  4041 	//for every app mode, check calculations update correctly
  4042 	for (TInt ii=0;ii<screenModes.Count();ii++)
  4043 		{
  4044 		TInt screenMode = screenModes[ii];
  4045 		if (iInfoScreenDevice->IsModeDynamic(screenMode))
  4046 			{
  4047 			CArrayFixFlat<TInt>* rotations=new(ELeave) CArrayFixFlat<TInt>(1);
  4048 			CleanupStack::PushL(rotations);
  4049 			TInt error = iInfoScreenDevice->GetRotationsList(screenMode,rotations);
  4050 			ASSERT_EQUALS(error,KErrNone);
  4051 			ASSERT_TRUE(rotations->Count()>0);
  4052 			for (TInt jj = 0; jj < rotations->Count(); jj++)
  4053 			    {
  4054 			    if ((*rotations)[jj] == (TInt)CFbsBitGc::EGraphicsOrientationNormal ||
  4055 			            (*rotations)[jj] == (TInt)CFbsBitGc::EGraphicsOrientationRotated180)
  4056                     {
  4057                     dynamicMode1 = screenMode;
  4058                     }
  4059 			    else if ((*rotations)[jj] == (TInt)CFbsBitGc::EGraphicsOrientationRotated90 ||
  4060 			            (*rotations)[jj] == (TInt)CFbsBitGc::EGraphicsOrientationRotated270)
  4061                     {
  4062                     dynamicMode2 = screenMode;
  4063                     }
  4064 			    }
  4065 			CleanupStack::PopAndDestroy(rotations);
  4066 			continue;	//dont want to test dynamic modes
  4067 			}
  4068 		
  4069 		INFO_PRINTF2(_L("ScreenMode %d"),screenMode);
  4070 		newResolution.ClearAll();
  4071 		
  4072 		iInfoScreenDevice->SetAppScreenMode(screenMode);
  4073 		iInfoScreenDevice->SetScreenMode(screenMode);
  4074 		iSession.Flush();
  4075 		Pause(50);
  4076 		
  4077 		info = iInfoScreenDevice->GetCurrentScreenModeAttributes();
  4078 		//These 2 asserts relate to DEF136304 - disconnect on startup causes invalid
  4079 		//twips values.  They need to be calculated when the screen is connected
  4080 		ASSERT_TRUE(info.iScreenTwipsSize.iWidth < 40000);
  4081 		ASSERT_TRUE(info.iScreenTwipsSize.iHeight < 40000);
  4082 		
  4083 		//test that conversions correlate to values reported by config
  4084 		TInt test = iInfoScreenDevice->HorizontalTwipsToPixels(
  4085 				info.iScreenTwipsSize.iWidth);
  4086 		ASSERT_EQUALS (test,info.iScreenSize.iWidth);
  4087 		
  4088 		test = iInfoScreenDevice->VerticalTwipsToPixels(
  4089 				info.iScreenTwipsSize.iHeight);
  4090 		ASSERT_EQUALS (test,info.iScreenSize.iHeight);
  4091 		
  4092 		test = iInfoScreenDevice->HorizontalPixelsToTwips(
  4093 				info.iScreenSize.iWidth);
  4094 		ASSERT_EQUALS (test,info.iScreenTwipsSize.iWidth);
  4095 		
  4096 		test = iInfoScreenDevice->VerticalPixelsToTwips(
  4097 				info.iScreenSize.iHeight);
  4098 		ASSERT_EQUALS (test,info.iScreenTwipsSize.iHeight);
  4099 		}
  4100 
  4101 	if (dynamicMode1 == -1 && dynamicMode2 == -1)	//expected to find at least 1 dynamic mode
  4102 		{
  4103 		ASSERT_TRUE(0);
  4104 		}
  4105 
  4106 	for (TInt jj=0;jj<2;jj++)  //for dynamic mode 1 and 2
  4107 	    {
  4108 	    TInt dynMode = (jj == 0) ? dynamicMode1 : dynamicMode2;
  4109 	    if (dynMode == -1)
  4110 	        continue;
  4111         //set dynamic app mode
  4112 	    iInfoScreenDevice->SetAppScreenMode(dynMode);
  4113 	    iInfoScreenDevice->SetScreenMode(dynMode);
  4114 	    iSession.Flush();
  4115 	    Pause(50);
  4116 	    ASSERT_TRUE(iInfoScreenDevice->IsModeDynamic(dynMode));
  4117 	    ASSERT_TRUE(iInfoScreenDevice->IsCurrentModeDynamic());
  4118 	    ASSERT_EQUALS(dynMode,iInfoScreenDevice->CurrentScreenMode());
  4119         for (TInt ii=0;ii<resolutionList1.Count();ii++)
  4120             {
  4121             INFO_PRINTF2(_L("ResIndex %d"),ii);
  4122             newResolution.ClearAll();
  4123             //set config
  4124             newResolution.SetResolution(resolutionList1[ii].iPixelSize);
  4125             newResolution.SetResolutionTwips(resolutionList1[ii].iTwipsSize);
  4126             SetRotation(newResolution,resolutionList1[ii]);
  4127             TDisplayConfiguration1::TRotation tempSetRot;
  4128             newResolution.GetRotation(tempSetRot);
  4129             
  4130             error = interface->SetConfiguration(newResolution);
  4131 
  4132             if (jj == 0)
  4133                 {
  4134                 if (tempSetRot == TDisplayConfiguration1::ERotation90CW ||
  4135                         tempSetRot == TDisplayConfiguration1::ERotation270CW) //mode rotation will not work with config rotation
  4136                     {
  4137                     ASSERT_EQUALS(error,KErrArgument);
  4138                     continue;
  4139                     }
  4140                 }
  4141             else    //jj == 1
  4142                 {
  4143                 if (tempSetRot == TDisplayConfiguration1::ERotationNormal ||
  4144                         tempSetRot == TDisplayConfiguration1::ERotation180) //mode rotation will not work with config rotation
  4145                     {
  4146                     ASSERT_EQUALS(error,KErrArgument);
  4147                     continue;
  4148                     }
  4149                 }
  4150             ASSERT_EQUALS(error,KErrNone);
  4151             interface->GetConfiguration(newResolution);
  4152             iSession.Flush();
  4153             Pause(50);
  4154             
  4155             //test that conversions correlate to values reported by config
  4156             TInt test = iInfoScreenDevice->HorizontalTwipsToPixels(
  4157                     resolutionList1[ii].iTwipsSize.iWidth);
  4158             ASSERT_EQUALS (test,resolutionList1[ii].iPixelSize.iWidth);
  4159             
  4160             test = iInfoScreenDevice->VerticalTwipsToPixels(
  4161                     resolutionList1[ii].iTwipsSize.iHeight);
  4162             ASSERT_EQUALS (test,resolutionList1[ii].iPixelSize.iHeight);
  4163             
  4164             test = iInfoScreenDevice->HorizontalPixelsToTwips(
  4165                     resolutionList1[ii].iPixelSize.iWidth);
  4166             ASSERT_EQUALS (test,resolutionList1[ii].iTwipsSize.iWidth);
  4167             
  4168             test = iInfoScreenDevice->VerticalPixelsToTwips(
  4169                     resolutionList1[ii].iPixelSize.iHeight);
  4170             ASSERT_EQUALS (test,resolutionList1[ii].iTwipsSize.iHeight);
  4171             }
  4172 	    }
  4173 
  4174 	resolutionList1.Close();
  4175 	screenModes.Close();
  4176 	}
  4177 
  4178 /*
  4179 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0053L
  4180 @SYMTestCaseDesc		SetScreenSizeAndRotation
  4181 @SYMREQ					REQ11554
  4182 @SYMPREQ				PREQ2102
  4183 @SYMTestType			CT
  4184 @SYMTestPriority		1
  4185 @SYMTestPurpose			Check functions work correctly
  4186 @SYMTestActions			
  4187 	Perform calls to SetScreenSizeAndRotation with the various structure types
  4188 	MODE 10 must be dynamic
  4189 @SYMTestExpectedResults	
  4190 	Cannt fail, used for debugging and coverage.
  4191 */
  4192 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0053L()
  4193 	{
  4194 	MDisplayControl* interface = static_cast<MDisplayControl*>
  4195 			(iScreenDevice->GetInterface(MDisplayControl::ETypeId));
  4196 	ASSERT_TRUE(interface);
  4197 	
  4198 	TInt resolutions = interface->NumberOfResolutions();
  4199 	ASSERT_TRUE (resolutions > 1);
  4200 		
  4201 	RArray<MDisplayControl::TResolution> resolutionList1;
  4202 	TInt error = interface->GetResolutions(resolutionList1);
  4203 	ASSERT_EQUALS(resolutionList1.Count(), resolutions);
  4204 	
  4205 	//set default app mode and default resolution
  4206 	iInfoScreenDevice->SetAppScreenMode(0);
  4207 	iInfoScreenDevice->SetScreenMode(0);
  4208 	iSession.Flush();
  4209 	Pause(50);
  4210 	TDisplayConfiguration original;
  4211 	original.SetResolution(resolutionList1[0].iPixelSize);
  4212 	interface->SetConfiguration(original);
  4213 	iSession.Flush();
  4214 	Pause(50);
  4215 	
  4216 	TPixelsAndRotation setup0;
  4217 	setup0.iPixelSize = TSize(30,40);
  4218 	setup0.iRotation = CFbsBitGc::EGraphicsOrientationNormal;
  4219 	
  4220 	TPixelsTwipsAndRotation setup1;
  4221 	setup1.iPixelSize = TSize(50,60);
  4222 	setup1.iTwipsSize = TSize(70,80);
  4223 	setup1.iRotation = CFbsBitGc::EGraphicsOrientationNormal;
  4224 	
  4225 	iInfoScreenDevice->SetScreenSizeAndRotation(setup0);
  4226 	iInfoScreenDevice->SetScreenSizeAndRotation(setup1);
  4227 	
  4228 	//set dynamic app mode
  4229 	iInfoScreenDevice->SetAppScreenMode(10);
  4230 	iInfoScreenDevice->SetScreenMode(10);
  4231 	iSession.Flush();
  4232 	Pause(50);
  4233 	
  4234 	iInfoScreenDevice->SetScreenSizeAndRotation(setup0);
  4235 	iInfoScreenDevice->SetScreenSizeAndRotation(setup1);
  4236 
  4237 	const CWsScreenDevice* newDevice = iScreenDevice;
  4238 	const MDisplayControl* interface2 = (MDisplayControl*)
  4239 			newDevice->GetInterface(MDisplayControl::ETypeId);
  4240 	TInt version = interface2->PreferredDisplayVersion();	//for coverage!
  4241 	(void)version;
  4242 
  4243 	//set default app mode and default resolution
  4244 	iInfoScreenDevice->SetAppScreenMode(1);
  4245 	iInfoScreenDevice->SetScreenMode(1);
  4246 	iSession.Flush();
  4247 	Pause(50);
  4248 	interface->SetConfiguration(original);
  4249 	iSession.Flush();
  4250 	Pause(50);
  4251 	
  4252 	resolutionList1.Close();
  4253 	}
  4254 
  4255 /**
  4256 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0101L
  4257 @SYMTestCaseDesc		Quick demonstration of app modes sizes and positions on screen
  4258 @SYMREQ					
  4259 @SYMPREQ				PREQ2102
  4260 @SYMTestType			CT (manual visual test)
  4261 @SYMTestPurpose			To show app modes
  4262 @SYMTestActions			
  4263 	For every app mode
  4264 	Draw a blue box showing the full size and position of the app mode.
  4265 	Draw thin red lines demonstrating a window can be drawn outside of the app area to fill
  4266 	the screen.
  4267 	Green borders at the edge of the appmode, to show we are drawing up to the edges of the
  4268 	appmode.
  4269 @SYMTestExpectedResults	
  4270 	Blue window should represent appmode (with offset and size)
  4271 	Red windows should be visible across screen
  4272 	Green border (made of windows) around the appmode (blue window)
  4273 */
  4274 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0101L()
  4275 	{
  4276 	RArray<TInt> screenModeList;
  4277 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  4278 
  4279 	if (screenModeList.Count()>1)
  4280 		{
  4281 		//Got modes to change between!
  4282 		TSize resBefore;
  4283 		for (TInt res=0;res<screenModeList.Count();res++)
  4284 			{
  4285 			TDisplayConfiguration dispConfigReq;
  4286 			iInfoScreenDevice->SetAppScreenMode(screenModeList[res]);
  4287 			iInfoScreenDevice->SetScreenMode(screenModeList[res]);
  4288 			iSession.Flush();
  4289 			Pause(50);
  4290 
  4291 			TSize appSize = iInfoScreenDevice->SizeInPixels();
  4292 			RWindow backWindow(iSession);
  4293 			ASSERT_EQUALS(backWindow.Construct(iGroup, 123455), KErrNone);
  4294 			backWindow.SetRequiredDisplayMode(iDisplayMode);
  4295 			backWindow.SetBackgroundColor(iCyan);
  4296 			backWindow.SetExtent(TPoint(40,40),appSize-TSize(40,40));	//shows size of the apparea
  4297 			backWindow.Activate();
  4298 		
  4299 			TSurfaceId surfaceID;
  4300 			TRAPD(err, surfaceID = iUtility->CreateSurfaceL(TSize(200,200), 
  4301 					KSurfaceFormat, 200 * KBytesPerPixel));
  4302 			ASSERT_EQUALS(err,KErrNone);
  4303 			TRAP(err,iUtility->FanFillSurfaceL(surfaceID,iYellow,iRed,iMagenta));
  4304 			ASSERT_EQUALS(err,KErrNone);
  4305 			TSurfaceConfiguration surfConf;
  4306 			surfConf.SetSurfaceId(surfaceID);
  4307 			
  4308 			backWindow.SetBackgroundSurface(surfaceID);
  4309 			
  4310 			DrawPlainUI(backWindow,ETrue,iBlue);
  4311 			iSession.Flush();
  4312 			Pause(200);
  4313 
  4314 			RWindow longWindow1(iSession);
  4315 			ASSERT_EQUALS(longWindow1.Construct(iGroup, 123456), KErrNone);
  4316 			longWindow1.SetRequiredDisplayMode(iDisplayMode);
  4317 			longWindow1.SetBackgroundColor(iRed);
  4318 			longWindow1.SetExtent(TPoint(-2000,10),TSize(5000,5));	//shows you can draw outside the apparea
  4319 			longWindow1.Activate();
  4320 			DrawPlainUI(longWindow1,ETrue,iRed);
  4321 
  4322 			iBackground.SetColor(TRgb(0x001000*res|0x800000));
  4323 			iSession.SetBackgroundColor(TRgb(0x001000*res+0x40));
  4324 			iSession.Flush();
  4325 			Pause(100);
  4326 			
  4327 			RWindow longWindow2(iSession);
  4328 			ASSERT_EQUALS(longWindow2.Construct(iGroup, 123457), KErrNone);
  4329 			longWindow2.SetRequiredDisplayMode(iDisplayMode);
  4330 			longWindow2.SetBackgroundColor(iRed);
  4331 			longWindow2.SetExtent(TPoint(20,-2000),TSize(5,5000));	//shows you can draw outside the apparea
  4332 			longWindow2.Activate();
  4333 			DrawPlainUI(longWindow2,ETrue,iRed);
  4334 			
  4335 			//borders
  4336 			RWindow borderTop(iSession);
  4337 			ASSERT_EQUALS(borderTop.Construct(iGroup, 123460), KErrNone);
  4338 			borderTop.SetRequiredDisplayMode(iDisplayMode);
  4339 			borderTop.SetBackgroundColor(iGreen);
  4340 			borderTop.SetExtent(TPoint(0,0),TSize(appSize.iWidth,5));	//border
  4341 			borderTop.Activate();
  4342 			DrawPlainUI(borderTop,ETrue,iGreen);
  4343 			
  4344 			RWindow borderLeft(iSession);
  4345 			ASSERT_EQUALS(borderLeft.Construct(iGroup, 123461), KErrNone);
  4346 			borderLeft.SetRequiredDisplayMode(iDisplayMode);
  4347 			borderLeft.SetBackgroundColor(iGreen);
  4348 			borderLeft.SetExtent(TPoint(0,0),TSize(5,appSize.iHeight));	//border
  4349 			borderLeft.Activate();
  4350 			DrawPlainUI(borderLeft,ETrue,iGreen);
  4351 						
  4352 			RWindow borderRight(iSession);
  4353 			ASSERT_EQUALS(borderRight.Construct(iGroup, 123462), KErrNone);
  4354 			borderRight.SetRequiredDisplayMode(iDisplayMode);
  4355 			borderRight.SetBackgroundColor(iGreen);
  4356 			borderRight.SetExtent(TPoint(appSize.iWidth-5,0),TSize(5,appSize.iHeight));	//border
  4357 			borderRight.Activate();
  4358 			DrawPlainUI(borderRight,ETrue,iGreen);
  4359 									
  4360 			RWindow borderBottom(iSession);
  4361 			ASSERT_EQUALS(borderBottom.Construct(iGroup, 123463), KErrNone);
  4362 			borderBottom.SetRequiredDisplayMode(iDisplayMode);
  4363 			borderBottom.SetBackgroundColor(iGreen);
  4364 			borderBottom.SetExtent(TPoint(0,appSize.iHeight-5),TSize(appSize.iWidth,5));	//border
  4365 			borderBottom.Activate();
  4366 			DrawPlainUI(borderBottom,ETrue,iGreen);
  4367 
  4368 			iSession.Flush();
  4369 			Pause(100);
  4370 
  4371 			backWindow.Close();
  4372 			longWindow1.Close();
  4373 			longWindow2.Close();
  4374 			borderTop.Close();
  4375 			borderLeft.Close();
  4376 			borderRight.Close();
  4377 			borderBottom.Close();
  4378 			
  4379 			iSession.Finish();
  4380 			Pause(50);
  4381 			}
  4382 		}
  4383 	else
  4384 		{
  4385 		INFO_PRINTF1(_L("Only 1 screen size mode configured on this screen - test skipped."));
  4386 		}
  4387 
  4388 	screenModeList.Close();
  4389 	iInfoScreenDevice->SetAppScreenMode(0);
  4390 	iInfoScreenDevice->SetScreenMode(0);
  4391 	iSession.Finish(ETrue);
  4392 	Pause(100);
  4393 	INFO_PRINTF1(_L("Drawing to borderBottom completed."));
  4394 	}
  4395 
  4396 /**
  4397 @SYMTestCaseID			GRAPHICS_WSERV_DYNAMICRES_0102L
  4398 @SYMTestCaseDesc		Quick demonstration of square app modes in all 4 rotations
  4399 @SYMREQ					
  4400 @SYMPREQ				PREQ2102
  4401 @SYMTestType			CT (manual visual test)
  4402 @SYMTestPurpose			To show square app mode in all 4 rotations
  4403 @SYMTestActions			
  4404 	Draw a blue box showing the full size and position of the app mode.
  4405 	Draw thin red lines demonstrating a window can be drawn outside of the app area to fill
  4406 	the screen.
  4407 	Green borders at the edge of the appmode, to show we are drawing up to the edges of the
  4408 	appmode.
  4409 @SYMTestExpectedResults	
  4410 	Blue window should represent appmode (with offset and size)
  4411 	Red windows should be visible across screen
  4412 	Green border (made of windows) around the appmode (blue window)
  4413 */
  4414 void	CWsDynamicResBasic::GRAPHICS_WSERV_DYNAMICRES_0102L()
  4415 	{
  4416 	RArray<TInt> screenModeList;
  4417 	iInfoScreenDevice->GetScreenSizeModeList(&screenModeList);
  4418 
  4419 
  4420 	TSize resBefore;
  4421 	TInt res;
  4422 	for (res=0;res<screenModeList.Count();res++)
  4423 		{
  4424 		iInfoScreenDevice->SetAppScreenMode(screenModeList[res]);
  4425 		iInfoScreenDevice->SetScreenMode(screenModeList[res]);
  4426 
  4427 		iSession.Finish(ETrue);
  4428 		iSession.Flush();
  4429 		Pause(50);
  4430 		
  4431 		TPixelsAndRotation pr;
  4432 		iInfoScreenDevice->GetDefaultScreenSizeAndRotation(pr);
  4433 		if(pr.iPixelSize.iHeight == pr.iPixelSize.iWidth)
  4434 			{
  4435 			//found square appmode
  4436 			break;
  4437 			}
  4438 		}
  4439 	
  4440 	for(TInt rotation = CFbsBitGc::EGraphicsOrientationNormal; rotation <= CFbsBitGc::EGraphicsOrientationRotated270; rotation++)
  4441 		{
  4442 		iScreenDevice->SetCurrentRotations(screenModeList[res], (CFbsBitGc::TGraphicsOrientation)rotation);
  4443 		iSession.Flush();
  4444 		Pause(50);
  4445 		TDisplayConfiguration dispConfigReq;
  4446 		TSize appSize = iInfoScreenDevice->SizeInPixels();
  4447 		RWindow backWindow(iSession);
  4448 		ASSERT_EQUALS(backWindow.Construct(iGroup, 123455), KErrNone);
  4449 		backWindow.SetRequiredDisplayMode(iDisplayMode);
  4450 		backWindow.SetBackgroundColor(iBlue);
  4451 		backWindow.SetExtent(TPoint(0,0),appSize);	//shows size of the apparea
  4452 		backWindow.Activate();
  4453 		DrawPlainUI(backWindow,ETrue,iBlue);
  4454 		iSession.Flush();
  4455 		Pause(200);
  4456 
  4457 		RWindow longWindow1(iSession);
  4458 		ASSERT_EQUALS(longWindow1.Construct(iGroup, 123456), KErrNone);
  4459 		longWindow1.SetRequiredDisplayMode(iDisplayMode);
  4460 		longWindow1.SetBackgroundColor(iRed);
  4461 		longWindow1.SetExtent(TPoint(-2000,10),TSize(5000,5));	//shows you can draw outside the apparea
  4462 		longWindow1.Activate();
  4463 		DrawPlainUI(longWindow1,ETrue,iRed);
  4464 
  4465 		iBackground.SetColor(TRgb(0x001000*res|0x800000));
  4466 		iSession.SetBackgroundColor(TRgb(0x001000*res+0x40));
  4467 		iSession.Flush();
  4468 		Pause(100);
  4469 		
  4470 		RWindow longWindow2(iSession);
  4471 		ASSERT_EQUALS(longWindow2.Construct(iGroup, 123457), KErrNone);
  4472 		longWindow2.SetRequiredDisplayMode(iDisplayMode);
  4473 		longWindow2.SetBackgroundColor(iRed);
  4474 		longWindow2.SetExtent(TPoint(20,-2000),TSize(5,5000));	//shows you can draw outside the apparea
  4475 		longWindow2.Activate();
  4476 		DrawPlainUI(longWindow2,ETrue,iRed);
  4477 		
  4478 		//borders
  4479 		RWindow borderTop(iSession);
  4480 		ASSERT_EQUALS(borderTop.Construct(iGroup, 123460), KErrNone);
  4481 		borderTop.SetRequiredDisplayMode(iDisplayMode);
  4482 		borderTop.SetBackgroundColor(iGreen);
  4483 		borderTop.SetExtent(TPoint(0,0),TSize(appSize.iWidth,5));	//border
  4484 		borderTop.Activate();
  4485 		DrawPlainUI(borderTop,ETrue,iGreen);
  4486 		
  4487 		RWindow borderLeft(iSession);
  4488 		ASSERT_EQUALS(borderLeft.Construct(iGroup, 123461), KErrNone);
  4489 		borderLeft.SetRequiredDisplayMode(iDisplayMode);
  4490 		borderLeft.SetBackgroundColor(iGreen);
  4491 		borderLeft.SetExtent(TPoint(0,0),TSize(5,appSize.iHeight));	//border
  4492 		borderLeft.Activate();
  4493 		DrawPlainUI(borderLeft,ETrue,iGreen);
  4494 					
  4495 		RWindow borderRight(iSession);
  4496 		ASSERT_EQUALS(borderRight.Construct(iGroup, 123462), KErrNone);
  4497 		borderRight.SetRequiredDisplayMode(iDisplayMode);
  4498 		borderRight.SetBackgroundColor(iGreen);
  4499 		borderRight.SetExtent(TPoint(appSize.iWidth-5,0),TSize(5,appSize.iHeight));	//border
  4500 		borderRight.Activate();
  4501 		DrawPlainUI(borderRight,ETrue,iGreen);
  4502 								
  4503 		RWindow borderBottom(iSession);
  4504 		ASSERT_EQUALS(borderBottom.Construct(iGroup, 123463), KErrNone);
  4505 		borderBottom.SetRequiredDisplayMode(iDisplayMode);
  4506 		borderBottom.SetBackgroundColor(iGreen);
  4507 		borderBottom.SetExtent(TPoint(0,appSize.iHeight-5),TSize(appSize.iWidth,5));	//border
  4508 		borderBottom.Activate();
  4509 		DrawPlainUI(borderBottom,ETrue,iGreen);
  4510 
  4511 		iSession.Flush();
  4512 		Pause(100);
  4513 
  4514 		backWindow.Close();
  4515 		longWindow1.Close();
  4516 		longWindow2.Close();
  4517 		borderTop.Close();
  4518 		borderLeft.Close();
  4519 		borderRight.Close();
  4520 		borderBottom.Close();
  4521 		
  4522 		iSession.Finish();
  4523 		Pause(50);
  4524 		
  4525 		}
  4526 
  4527 
  4528 	screenModeList.Close();
  4529 	iInfoScreenDevice->SetAppScreenMode(0);
  4530 	iInfoScreenDevice->SetScreenMode(0);
  4531 	iSession.Finish(ETrue);
  4532 	Pause(100);
  4533 	}