os/graphics/windowing/windowserver/test/tauto/TCapKey.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) 1996-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 // Test capture key
    15 // Coverted from TMan test code (TMCAPKEY.CPP) October 2000
    16 // 
    17 //
    18 
    19 /**
    20  @file
    21  @test
    22  @internalComponent - Internal Symbian test code
    23 */
    24 
    25 
    26 #include "TCapKey.H"
    27 
    28 #define LOGGING on
    29 
    30 //
    31 // CAbortHandler
    32 
    33 CAbortHandler::CAbortHandler(RWsSession *aWs, CCKAbortConnection *aConnection) : CTEventBase(aWs, 10), iConnection(aConnection)
    34 	{
    35 	}
    36 
    37 CAbortHandler::~CAbortHandler()
    38 	{
    39 	Cancel();
    40 	}
    41 
    42 void CAbortHandler::Request()
    43 	{
    44 	iWs->PriorityKeyReady(&iStatus);
    45 	SetActive();
    46 	}
    47 
    48 void CAbortHandler::DoCancel()
    49 	{
    50 	iWs->PriorityKeyReadyCancel();
    51 	}
    52 
    53 void CAbortHandler::doRunL()
    54 	{
    55 	TWsPriorityKeyEvent abortEvent;
    56 	iWs->GetPriorityKey(abortEvent);
    57 	iConnection->ReceivedAbortEvent(abortEvent.Handle(),abortEvent.Key());
    58 	}
    59 
    60 //
    61 // CCKConnection
    62 
    63 CCKConnectionBase::CCKConnectionBase(CTCaptureKey *aTest) : iTest(aTest)
    64 	{
    65 	}
    66 
    67 void CCKConnectionBase::ConstructL()
    68 	{
    69 	CTClient::SetScreenNumber(iTest->ScreenNumber());
    70 	CTClient::ConstructL();
    71 	iGroup=new(ELeave) CCKWindowGroup(this, iTest);
    72 	iGroup->ConstructL();
    73 	}
    74 
    75 CCKConnection::CCKConnection(CTCaptureKey *aTest, TInt aConnIndex) : CCKConnectionBase(aTest), iConnIndex(aConnIndex)
    76 	{
    77 	}
    78 
    79 CCKConnection::~CCKConnection()
    80 	{
    81 	for(TInt index=0;index<numCapKeys;index++)
    82 		if (capKeys[index].connIndex==iConnIndex)
    83 			iGroup->GroupWin()->CancelCaptureKey(capKeyHandle[index]);
    84 	for(TInt index1=0;index1<numCapKeysWithPriority;index1++)
    85 		if (capKeysWithPriority[index1].connIndex==iConnIndex)
    86 			iGroup->GroupWin()->CancelCaptureKey(capKeyWithPriorityHandle[index1]);
    87 	for(TInt index2=0;index2<numUpDownKeys;index2++)
    88 		if (capUpAndDownKeys[index2].connIndex==iConnIndex)
    89 			iGroup->GroupWin()->CancelCaptureKeyUpAndDowns(capUpDownKeyHandle[index2]);
    90 	for(TInt index3=0;index3<numUpDownKeysWithPriority;index3++)
    91 		if (capUpAndDownKeysWithPriority[index3].connIndex==iConnIndex)
    92 			iGroup->GroupWin()->CancelCaptureKeyUpAndDowns(capUpDownKeyWithPriorityHandle[index3]);
    93 	CTWin::Delete(iWin);
    94 	}
    95 
    96 void CCKConnection::SubStateChanged()
    97 	{
    98 	iWin->Invalidate();
    99 	iWs.Flush();
   100 	}
   101 
   102 void CCKConnection::ConstructL()
   103 	{
   104 	CCKConnectionBase::ConstructL();
   105 	for(TInt index=0;index<numCapKeys;index++)
   106 		if (capKeys[index].connIndex==iConnIndex)
   107 			capKeyHandle[index]=User::LeaveIfError(iGroup->GroupWin()->CaptureKey(capKeys[index].keyCode,capKeys[index].modifier_mask,capKeys[index].modifiers));
   108 	for(TInt index1=0;index1<numCapKeysWithPriority;index1++)
   109 		if (capKeysWithPriority[index1].connIndex==iConnIndex)
   110 			capKeyWithPriorityHandle[index1]=User::LeaveIfError(iGroup->GroupWin()->CaptureKey(capKeysWithPriority[index1].keyCode,capKeysWithPriority[index1].modifier_mask,capKeysWithPriority[index1].modifiers,capKeysWithPriority[index1].priority));
   111 	for(TInt index2=0;index2<numUpDownKeys;index2++)
   112 		if (capUpAndDownKeys[index2].connIndex==iConnIndex)
   113 			capUpDownKeyHandle[index2]=User::LeaveIfError(iGroup->GroupWin()->CaptureKeyUpAndDowns(capUpAndDownKeys[index2].keyCode,
   114 								capUpAndDownKeys[index2].modifier_mask,capUpAndDownKeys[index2].modifiers));
   115 	for(TInt index3=0;index3<numUpDownKeysWithPriority;index3++)
   116 		if (capUpAndDownKeysWithPriority[index3].connIndex==iConnIndex)
   117 			capUpDownKeyWithPriorityHandle[index3]=User::LeaveIfError(iGroup->GroupWin()->CaptureKeyUpAndDowns(capUpAndDownKeysWithPriority[index3].keyCode,
   118 								capUpAndDownKeysWithPriority[index3].modifier_mask,capUpAndDownKeysWithPriority[index3].modifiers,capUpAndDownKeysWithPriority[index3].priority));
   119 	TSize screenSize=iGroup->Size();
   120 	TInt winWidth=screenSize.iWidth/2;
   121 	TInt winHeight=screenSize.iHeight-10;
   122 	iGroup->GroupWin()->AutoForeground(EFalse);		// Don't allow clicking to cause foreground, might mess up test
   123 	CCKWindow *win=new(ELeave) CCKWindow(iTest, iConnIndex);
   124 	win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc);
   125 	iWin=win;
   126 	}
   127 
   128 void CCKConnection::KeyTestL(TInt aBool)
   129 	{
   130 	if (!aBool)
   131 		{
   132 		CTDialog *dialog= new(ELeave) CTDialog();
   133 		TInt ret=0;
   134 		if (dialog)
   135 			{
   136 			dialog->ConstructLD(*iGroup,*iGc);
   137 			dialog->SetTitle(_L("Invalid key press"));
   138 			dialog->SetLine1(_L("Try again?"));
   139 			dialog->SetNumButtons(2);
   140 			dialog->SetButtonText(0,_L("Fail"));
   141 			dialog->SetButtonText(1,_L("Retry"));
   142 			ret=dialog->Display();
   143 			}
   144 		User::Leave(ret==1 ? ECapKeyRetry : ECapKeyFail);
   145 		}
   146 	}
   147 
   148 void CCKConnection::CheckKeyL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey)
   149 	{
   150 	KeyTestL(aKeyTest.keyCode==aKey.iCode);
   151 	KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask));
   152 	}
   153 
   154 void CCKConnection::CheckUpDownL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey)
   155 	{
   156 	if(iTest->Mode()==EModeKeyUpsAndDownsWithPriority)
   157 		KeyTestL(aKeyTest.connIndex==iTest->SubState()-15);
   158 	KeyTestL(aKeyTest.connIndex==iConnIndex);
   159 	KeyTestL(aKeyTest.keyCode==(TUint)aKey.iScanCode);
   160 	KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask));
   161 	}
   162 
   163 void CCKConnection::KeyL(const TKeyEvent &aKey,const TTime &)
   164 	{
   165 #if defined(LOGGING)
   166 	_LIT(KLog,"CCKConnection::KeyL  State=%d  SubState=%d  Mode=%d  KeyCode=%d  ScanCode=%d  Mod=0x%x");
   167 	iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers);
   168 #endif
   169 	if (iTest->Mode()==EModeNormalCapture || iTest->Mode()==EModeNormalCaptureWithPriority)
   170 		{
   171 		//if (aKey.iCode==EKeyEscape)
   172 		//	iTest->Abort();
   173 		if(iTest->Mode()==EModeNormalCaptureWithPriority)
   174 			{
   175 			SCapKeyTestParams tmpCapKeyTest=capKeyTests[iTest->SubState()];
   176 			KeyTestL(tmpCapKeyTest.connIndex==iTest->SubState()-8);
   177 			}
   178 		TRAPD(ret,CheckKeyL(capKeyTests[iTest->SubState()],aKey));
   179 		if (ret==ECapKeyOkay)
   180 			iTest->IncSubState();
   181 		else
   182 			{
   183 			iTest->TEST(ret==ECapKeyRetry);
   184 			if (ret!=ECapKeyRetry)
   185 				iTest->INFO_PRINTF3(_L("CheckKeyL(capKeyTests[iTest->SubState()],aKey) return value - Expected: %d, Actual: %d"), ECapKeyRetry, ret);		
   186 			}
   187 			
   188 		}
   189 	}
   190 
   191 void CCKConnection::CheckUpDownL(const TKeyEvent &aKey)
   192 	{
   193 	CheckUpDownL(capKeyTests[iTest->SubState()],aKey);
   194 	}
   195 
   196 CCKAbortConnection::CCKAbortConnection(CTCaptureKey *aTest) : CCKConnectionBase(aTest)
   197 	{
   198 	}
   199 
   200 CCKAbortConnection::~CCKAbortConnection()
   201 	{
   202 	iGroup->GroupWin()->RemovePriorityKey(3,EModifierCtrl,EModifierCtrl);
   203 	delete iAbortHandler;
   204 	}
   205 
   206 void CCKAbortConnection::ConstructL()
   207 	{
   208 	CCKConnectionBase::ConstructL();
   209 	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[0].keyCode,abortKeyTests[0].modifier_mask,abortKeyTests[0].modifiers));
   210 	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[1].keyCode,abortKeyTests[1].modifier_mask,abortKeyTests[1].modifiers));
   211 	User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[2].keyCode,abortKeyTests[2].modifier_mask,abortKeyTests[2].modifiers));
   212 	iAbortHandler=new(ELeave) CAbortHandler(&iWs, this);
   213 	iAbortHandler->Construct();
   214 	iWs.Flush();
   215 	}
   216 
   217 void CCKAbortConnection::ReceivedAbortEvent(TInt aHandle,TKeyEvent* aKey)
   218 	{
   219 #if defined(LOGGING)
   220 	_LIT(KLog,"CCKAbortConnection::ReceivedAbortEvent  State=%d  SubState=%d  Mode=%d  KeyCode=%d  ScanCode=%d  Mod=0x%x");
   221 	iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey->iCode,aKey->iScanCode,aKey->iModifiers);
   222 #endif
   223 	TInt group=reinterpret_cast<TInt>(iGroup);
   224 	iTest->TEST(aHandle==group);
   225 	if (aHandle!=group)
   226 		{
   227 		_LIT(KLog,"Event Handle is not for the right group, expected=%d actual=%d");
   228 		iTest->LOG_MESSAGE3(KLog,group,aHandle);
   229 		}
   230 
   231 	iTest->TEST(aKey->iCode==abortKeyTests[iAbortKeyIndex].keyCode);
   232 	if (aKey->iCode!=abortKeyTests[iAbortKeyIndex].keyCode)
   233 		{
   234 		_LIT(KLog,"The event KeyCode is not right, expected=%d actual=%d");
   235 		iTest->LOG_MESSAGE3(KLog,abortKeyTests[iAbortKeyIndex].keyCode,aKey->iCode);
   236 		}
   237 
   238 	iTest->TEST((aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask)==abortKeyTests[iAbortKeyIndex].modifiers);
   239 	if ((aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask)!=abortKeyTests[iAbortKeyIndex].modifiers)
   240 		{
   241 		_LIT(KLog,"The event modifiers are not right, expected=0x%x actual=0x%x (0x%x) mask=0x%x");
   242 		iTest->LOG_MESSAGE5(KLog,abortKeyTests[iAbortKeyIndex].modifiers,aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask
   243 									,aKey->iModifiers,abortKeyTests[iAbortKeyIndex].modifier_mask);
   244 		}
   245 	iAbortKeyIndex++;
   246 	iTest->IncSubState();
   247 	}
   248 
   249 void CCKAbortConnection::Foreground()
   250 	{
   251 	iGroup->GroupWin()->SetOrdinalPosition(0);
   252 	iWs.Flush();
   253 	}
   254 
   255 //
   256 // CCKWindowGroup class //
   257 //
   258 
   259 CCKWindowGroup::CCKWindowGroup(CTClient *aClient, CTCaptureKey *aTest) : CTWindowGroup(aClient), iTest(aTest)
   260 	{}
   261 
   262 void CCKWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &time)
   263 	{
   264 #if defined(LOGGING)
   265 	_LIT(KLog,"CCKWindowGroup::KeyL  State=%d  SubState=%d  Mode=%d  KeyCode=%d  ScanCode=%d  Mod=0x%x");
   266 	iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers);
   267 #endif
   268 	if (iTest->Mode()==EModeWaitingForFirstNormalCapWithPriority)
   269 		iTest->SetMode(EModeNormalCaptureWithPriority);
   270 	if (iCurWin)
   271 		iCurWin->WinKeyL(aKey,time);
   272 	else
   273 		((CCKConnection *)iClient)->KeyL(aKey,time);
   274 	}
   275 
   276 void CCKWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &)
   277 	{
   278 #if defined(LOGGING)
   279 	_LIT(KLog,"CCKWindowGroup::KeyDownL  State=%d  SubState=%d  Mode=%d  KeyCode=%d  ScanCode=%d  Mod=0x%x");
   280 	iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers);
   281 #endif
   282 	if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift)
   283 		{
   284 		if (iTest->Mode()==EModeWaitingForFirstDown)
   285 			iTest->SetMode(EModeKeyUpsAndDowns);
   286 		if (iTest->Mode()==EModeWaitingForFirstDownWithPriority)
   287 			iTest->SetMode(EModeKeyUpsAndDownsWithPriority);
   288 		if (iTest->Mode()==EModeKeyUpsAndDowns || iTest->Mode()==EModeKeyUpsAndDownsWithPriority)
   289 			((CCKConnection *)iClient)->CheckUpDownL(aKey);
   290 		}
   291 	}
   292 
   293 void CCKWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &)
   294 	{
   295 #if defined(LOGGING)
   296 	_LIT(KLog,"CCKWindowGroup::KeyUpL  State=%d  SubState=%d  Mode=%d  KeyCode=%d  ScanCode=%d  Mod=0x%x");
   297 	iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers);
   298 #endif
   299 	if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift)
   300 		{
   301 		if (iTest->Mode()==EModeKeyUpsAndDowns || iTest->Mode()==EModeKeyUpsAndDownsWithPriority)
   302 			{
   303 			((CCKConnection *)iClient)->CheckUpDownL(aKey);
   304 			iTest->IncSubState();
   305 			}
   306 		}
   307 	}
   308 
   309 //
   310 // CCKWindow, class //
   311 //
   312 
   313 CCKWindow::CCKWindow(CTCaptureKey *aTest, TInt aConnIndex) : CTWin(), iConnIndex(aConnIndex), iTest(aTest)
   314 	{
   315 	iBack=TRgb::Gray256(230);
   316 	}
   317 
   318 void CCKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc)
   319 	{
   320 	ConstructExtLD(*parent,pos,size);
   321 	iWin.SetBackgroundColor(iBack);
   322 	Activate();
   323 	AssignGC(aGc);
   324 	}
   325 
   326 void CCKWindow::Draw()
   327 	{
   328 	iGc->Clear();
   329 	if (iConnIndex==0)
   330 		{
   331 		TInt test=iTest->SubState();
   332 		if (test<numTests)
   333 			iGc->DrawText(TPtrC(capKeyTests[test].txt), TPoint(10,20));
   334 		}
   335 	}
   336 
   337 //
   338 
   339 CTCaptureKey::CTCaptureKey(CTestStep* aStep) : CTWsGraphicsBase(aStep)
   340 	{
   341 	}
   342 	
   343 CTCaptureKey::~CTCaptureKey()
   344 	{
   345 	((CTCaptureKeyStep*)iStep)->CloseTMSGraphicsStep();
   346 	delete iConn1;
   347 	delete iConn2;
   348 	delete iConn3;
   349 	delete iAbortConn;
   350 	}
   351 
   352 void CTCaptureKey::ConstructL()
   353 	{
   354 	iAbortConn=new(ELeave) CCKAbortConnection(this);
   355 	iAbortConn->ConstructL();
   356 	iConn3=new(ELeave) CCKConnection(this,2);
   357 	iConn3->ConstructL();
   358 	iConn2=new(ELeave) CCKConnection(this,1);
   359 	iConn2->ConstructL();
   360 	iConn1=new(ELeave) CCKConnection(this,0);
   361 	iConn1->ConstructL();
   362 	iMode=EModeNormalCapture;
   363 	SetSelfDrive(ETrue);
   364 	TUint mods=TheClient->iWs.GetModifierState();
   365 	_LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)");
   366 	LOG_MESSAGE2(KLog,mods);
   367 	}
   368 
   369 TInt CTCaptureKey::SubState() const
   370 	{
   371 	return(iSubState);
   372 	}
   373 
   374 void CTCaptureKey::IncSubState()
   375 	{
   376 	iSubState++;
   377 #if defined(LOGGING)
   378 	_LIT(KLog,"IncSubState  State=%d  SubState=%d  Mode=%d");
   379 	LOG_MESSAGE4(KLog,iState,iSubState,iMode);
   380 #endif
   381 	iConn1->SubStateChanged();
   382 	iConn2->SubStateChanged();
   383 	iConn3->SubStateChanged();
   384 	switch(iMode)
   385 		{
   386 		case EModeNormalCapture:
   387 			if (iSubState==numCapKeyTests)
   388 				{
   389 				CaseComplete();
   390 				return;
   391 				}
   392 			break;
   393 		case EModeNormalCaptureWithPriority:
   394 			if (iSubState==numCapKeyTests+numCapKeyWithPriorityTests)
   395 				{
   396 				CaseComplete();
   397 				return;
   398 				}
   399 			break;
   400 		case EModeKeyUpsAndDowns:
   401 			if (iSubState==(numCapKeyTests+numCapKeyWithPriorityTests+numUpDownKeyTests))
   402 				{
   403 				CaseComplete();
   404 				return;
   405 				}
   406 			break;
   407 		case EModeKeyUpsAndDownsWithPriority:
   408 			if (iSubState==(numCapKeyTests+numCapKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests))
   409 				{
   410 				SetSelfDrive(EFalse);
   411 				return;
   412 				}
   413 			break;
   414 		case EModeAbortKeys:
   415 			if (iSubState==(numCapKeyTests+numCapKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests+numAbortKeyTests))
   416 				++iState;
   417 			TheClient->WaitForRedrawsToFinish();
   418 			return;
   419 		default:
   420 			break;
   421 		}
   422 	TheClient->WaitForRedrawsToFinish();
   423 	SendEvents();
   424 	}
   425 
   426 void CTCaptureKey::CapKeyPurgingL()
   427 	{
   428 	TInt base=Client()->iWs.ResourceCount();
   429 	RWindowGroup groupWin(Client()->iWs);
   430 	User::LeaveIfError(groupWin.Construct(ENullWsHandle));
   431 	TInt capHandle=User::LeaveIfError(groupWin.CaptureKey('a',EModifierFunc,EModifierFunc));
   432 	User::LeaveIfError(groupWin.CaptureKey('b',EModifierFunc,EModifierFunc));
   433 	TInt retVal = Client()->iWs.ResourceCount();
   434 	TEST(retVal==(base+3));
   435 	if (retVal!=(base+3))
   436 		INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), retVal, (base+3));		
   437 
   438 	groupWin.CancelCaptureKey(capHandle);
   439 	retVal = Client()->iWs.ResourceCount();
   440 	TEST(retVal==(base+2));
   441 	if (retVal!=(base+2))
   442 		INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), retVal, (base+2));		
   443 
   444 	groupWin.Close();
   445 	// Check it also freed the extra capture key
   446 	retVal = Client()->iWs.ResourceCount();
   447 	TEST(retVal==base);
   448 	if (retVal!=base)
   449 		INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), retVal, base);		
   450 
   451 	}
   452 
   453 void CTCaptureKey::BadParams()
   454 	{
   455 	TInt retVal;
   456 	TInt resCount=Client()->iWs.ResourceCount();
   457 	for(TInt index=0;index<numErrorKeys;index++)
   458 		{
   459 		retVal = Client()->iGroup->GroupWin()->CaptureKey(errorKeys[index].keyCode,errorKeys[index].modifier_mask,errorKeys[index].modifiers, errorKeys[index].priority);
   460 		TEST(retVal==KErrArgument);
   461 		if (retVal!=KErrArgument)
   462 			{
   463 			_LIT(KMsg, "CaptureKey() with bad parameter set %d returned %d - expected KErrArgument (%d)");
   464 			LOG_MESSAGE4(KMsg, index, retVal, KErrArgument);	
   465 			}
   466 
   467 		retVal = Client()->iGroup->GroupWin()->CaptureKeyUpAndDowns(errorKeys[index].keyCode, errorKeys[index].modifier_mask, errorKeys[index].modifiers, errorKeys[index].priority);
   468 		TEST(retVal == KErrArgument);
   469 		if (retVal != KErrArgument)
   470 			{
   471 			_LIT(KMsg, "CaptureKeyUpAndDowns() with bad parameter set %d returned %d - expected KErrArgument (%d)");
   472 			LOG_MESSAGE4(KMsg, index, retVal, KErrArgument);	
   473 			}
   474 
   475 		retVal = Client()->iGroup->GroupWin()->CaptureLongKey(errorKeys[index].keyCode, errorKeys[index].keyCode, errorKeys[index].modifier_mask, errorKeys[index].modifiers, errorKeys[index].priority, ELongCaptureNormal);
   476 		TEST(retVal == KErrArgument);
   477 		if (retVal != KErrArgument)
   478 			{
   479 			_LIT(KMsg, "CaptureLongKey() with bad parameter set %d returned %d - expected KErrArgument (%d)");
   480 			LOG_MESSAGE4(KMsg, index, retVal, KErrArgument);	
   481 			}
   482 		}
   483 
   484 	retVal = Client()->iWs.ResourceCount();
   485 	TEST(retVal==resCount);
   486 	if (retVal!=resCount)
   487 		{
   488 		_LIT(KMsg, "Resource count %d - expected %d");
   489 		LOG_MESSAGE3(KMsg, retVal, resCount);	
   490 		}
   491 	}
   492 
   493 void CTCaptureKey::SetMode(TTestMode aMode)
   494 	{
   495 #if defined(LOGGING)
   496 	_LIT(KLog,"SetMode  State=%d  SubState=%d  OldMode=%d  NewMode=%d");
   497 	LOG_MESSAGE5(KLog,State(),SubState(),iMode,aMode);
   498 #endif
   499 	iMode=aMode;
   500 	}
   501 
   502 TTestMode CTCaptureKey::Mode()
   503 	{
   504 	return(iMode);
   505 	}
   506 
   507 void CTCaptureKey::SetUpPriorityKeyTest()
   508 	{
   509 	iMode=EModeAbortKeys;
   510 	iAbortConn->Foreground();
   511 	}
   512 
   513 void CTCaptureKey::CaptureWithPriorityTest() //normal key capture but with priority
   514 	{
   515 	iMode=EModeWaitingForFirstNormalCapWithPriority;
   516 	}
   517 
   518 void CTCaptureKey::CaptureUpsAndDownsTest()
   519 	{
   520 	iMode=EModeWaitingForFirstDown;
   521 	}
   522 
   523 void CTCaptureKey::CaptureUpsAndDownsWithPriorityTest()
   524 	{
   525 	iMode=EModeWaitingForFirstDownWithPriority;
   526 	}
   527 
   528 void CTCaptureKey::SendEvents()
   529 	{
   530 #if defined(LOGGING)
   531 	_LIT(KLog,"SendEvents  State=%d  SubState=%d");
   532 	LOG_MESSAGE3(KLog,iState,iSubState);
   533 #endif
   534 	switch (iSubState)
   535 		{
   536 	case 0:
   537 		iTest->SimulateKeyDownUp('Q');
   538 		break;
   539 	case 1:
   540 		iTest->SimulateKeyDownUpWithModifiers('W',EModifierAlt);
   541 		break;
   542 	case 2:
   543 		iTest->SimulateKeyDownUp('A');
   544 		break;
   545 	case 3:
   546 		iTest->SimulateKeyDownUpWithModifiers('S',EModifierAlt|EModifierCtrl);
   547 		break;
   548 	case 4:
   549 		iTest->SimulateKeyDownUpWithModifiers('N',EModifierAlt);
   550 		break;
   551 	case 5:
   552 		iTest->SimulateKeyDownUpWithModifiers('B',EModifierAlt|EModifierCtrl);
   553 		break;
   554 	case 6:
   555 		iTest->SimulateKeyDownUpWithModifiers('D',EModifierAlt);
   556 		break;
   557 	case 7:
   558 		iTest->SimulateKeyDownUpWithModifiers('C',EModifierAlt|EModifierCtrl);
   559 		break;
   560 	case 8:
   561 		iTest->SimulateKeyDownUp('H');//state EModeNormalCaptureWithPriority
   562 		break;
   563 	case 9:
   564 		iTest->SimulateKeyDownUp('J');
   565 		break;
   566 	case 10:
   567 		iTest->SimulateKeyDownUp('K');
   568 		break;
   569 	case 11:
   570 		iTest->SimulateKeyDownUp(EStdKeySpace);
   571 		break;
   572 	case 12:
   573 		iTest->SimulateKeyDownUp(EStdKeyEnter);
   574 		break;
   575 	case 13:
   576 		iTest->SimulateKeyDownUpWithModifiers(EStdKeySpace,EModifierShift);
   577 		break;
   578 	case 14:
   579 		iTest->SimulateKeyDownUpWithModifiers(EStdKeyEnter,EModifierShift);
   580 		break;
   581 	case 15:
   582 		iTest->SimulateKeyDownUp('H');//state EModeKeyUpsAndDownsWithPriority
   583 		break;
   584 	case 16:
   585 		iTest->SimulateKeyDownUp('J');
   586 		break;
   587 	case 17:
   588 		iTest->SimulateKeyDownUp('K');
   589 		break;
   590 	case 18:
   591 		iTest->SimulateKeyDownUpWithModifiers('C',EModifierCtrl);
   592 		break;
   593 	case 19:
   594 		iTest->SimulateKeyDownUpWithModifiers('D',EModifierCtrl);
   595 		break;
   596 	case 20:
   597 		iTest->SimulateKeyDownUp('Z');
   598 		break;
   599 	default:
   600 		TEST(EFalse);
   601 		}
   602 	TheClient->iWs.Flush();
   603 	}
   604 
   605 void CTCaptureKey::CapKeyPowerOffL()
   606 	{
   607 	const TUint protKey=0xF844;		//This value needs to be defined in the WSINI.INI file as a key only capturable by a certain application
   608 	RWsSession ws;
   609 	User::LeaveIfError(ws.Connect());
   610 	CleanupClosePushL(ws);
   611 	
   612 	// assign to the correct screen
   613 	CWsScreenDevice* screen = new (ELeave) CWsScreenDevice(ws);
   614 	CleanupStack::PushL(screen);
   615 	User::LeaveIfError(screen->Construct(iTest->iScreenNumber));
   616 	
   617 	RWindowGroup group(ws);
   618 	group.Construct(ENullWsHandle);
   619 	CleanupClosePushL(group);
   620 	group.EnableReceiptOfFocus(EFalse);
   621 	group.SetOrdinalPosition(0,5);
   622 	RBlankWindow blank(ws);
   623 	blank.Construct(group,ENullWsHandle);
   624 	CleanupClosePushL(blank);
   625 	blank.EnableBackup();
   626 	blank.Activate();
   627 	_LIT(kGroupName1,"Hello");
   628 	group.SetName(kGroupName1);
   629 	TInt capHandle = group.CaptureKey(EKeyDevice2,EModifierFunc,EModifierFunc);
   630 	TEST(capHandle==KErrPermissionDenied);
   631 	if (capHandle!=KErrPermissionDenied)
   632 		{
   633 		_LIT(KLog1,"Capture Key suceeded when it should of failed, Error/Handle=%d (expected: %d)");
   634 		LOG_MESSAGE3(KLog1,capHandle,KErrPermissionDenied);
   635 		_LIT(KLog2,"This is indicative of a bad WSINI file");
   636 		LOG_MESSAGE(KLog2);
   637 		}
   638 
   639 	capHandle=group.CaptureKeyUpAndDowns(protKey,0,0);
   640 	TEST(capHandle==KErrPermissionDenied);
   641 	if (capHandle!=KErrPermissionDenied)
   642 		{
   643 		_LIT(KLog,"Capture Key Up & Down suceeded when it should of failed, Error/Handle=%d (expected: %d)");
   644 		LOG_MESSAGE3(KLog,capHandle,KErrPermissionDenied);
   645 		}
   646 	
   647 	_LIT(kGroupName2,"SysApp");
   648 	group.SetName(kGroupName2);
   649 	capHandle = group.CaptureKey(EKeyDevice2,EModifierFunc,EModifierFunc);
   650 	TEST(capHandle > 0);
   651 	if (capHandle<=0)
   652 		{
   653 		_LIT(KLog,"Capture Key failed when it should of succeeded, Error=%d");
   654 		LOG_MESSAGE2(KLog,capHandle);
   655 		}
   656 
   657 	group.CancelCaptureKey(capHandle);
   658 	capHandle=group.CaptureKeyUpAndDowns(protKey,0,0);
   659 	TEST(capHandle > 0);
   660 	if (capHandle<=0)
   661 		{
   662 		_LIT(KLog,"Capture Key Up & Down failed when it should of succeeded, Error=%d");
   663 		LOG_MESSAGE2(KLog,capHandle);
   664 		}
   665 
   666 	group.CancelCaptureKeyUpAndDowns(capHandle);
   667 	CleanupStack::PopAndDestroy(4,&ws);
   668 	}
   669 
   670 
   671 void CTCaptureKey::RunTestCaseL(TInt /*aCurTestCase*/)
   672 	{
   673 	_LIT(Test0,"Normal capture with priority");
   674 	_LIT(TestNormalCaptureWithPriority,"Normal capture with priority");
   675 	_LIT(TestUpDown,"Capture ups and downs");
   676 	_LIT(TestUpDownWithPriority,"Capture ups and downs with priority");
   677 	_LIT(TestAbort,"Abort key");
   678 	_LIT(TestAbort2,"Abort key extended");
   679 	_LIT(TestErrors,"Errors");
   680 	_LIT(TestCaptureKey,"Capture Key");
   681 	_LIT(TestCapturePowerOffKey,"Capture PowerOff Key");
   682 
   683 	iTest->iState=iState;
   684 	((CTCaptureKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   685 	switch(iState)
   686 		{
   687 /**
   688 @SYMTestCaseID		GRAPHICS-WSERV-0140
   689 
   690 
   691 @SYMDEF             DEF081259
   692 
   693 @SYMTestCaseDesc    Normal key capture test
   694 
   695 @SYMTestPriority    High
   696 
   697 @SYMTestStatus      Implemented
   698 
   699 @SYMTestActions     The test uses 3 wserv clients with their own window groups. The 
   700 					clients are registered for different keys to capture. The test 
   701 					simulates key presses.
   702 
   703 @SYMTestExpectedResults Checks that the key presses are captured correctly .
   704 */
   705 		case 0:	// Dummy one to let capture key tests run
   706 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0140"));
   707 			iTest->LogSubTest(Test0);
   708 			iState++;
   709 			SendEvents();
   710 			break;
   711 /**
   712 @SYMTestCaseID		GRAPHICS-WSERV-0141
   713 
   714 @SYMDEF             DEF081259
   715 
   716 @SYMTestCaseDesc    Normal key capture test with priorities
   717 
   718 @SYMTestPriority    High
   719 
   720 @SYMTestStatus      Implemented
   721 
   722 @SYMTestActions     The test uses 3 wserv clients with their own window groups. The 
   723 					clients are registered for different keys to capture and with
   724 					different priorities. The test simulates key presses.
   725 
   726 @SYMTestExpectedResults Checks that the key presses are captured correctly .
   727 */
   728 		case 1:
   729 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0141"));
   730 			iTest->LogSubTest(TestNormalCaptureWithPriority);
   731 			CaptureWithPriorityTest();
   732 			iState++;
   733 			SendEvents();
   734 			break;
   735 /**
   736 @SYMTestCaseID		GRAPHICS-WSERV-0142
   737 
   738 @SYMDEF             DEF081259
   739 
   740 @SYMTestCaseDesc    Up-down key capture test
   741 
   742 @SYMTestPriority    High
   743 
   744 @SYMTestStatus      Implemented
   745 
   746 @SYMTestActions     The test uses 3 wserv clients with their own window groups. The 
   747 					clients are registered for different keys to capture their
   748 					up and down events. The test simulates key presses and releases.
   749 
   750 @SYMTestExpectedResults Checks that the key presses and releases are captured correctly .
   751 */
   752 		case 2:
   753 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0142"));
   754 			iTest->LogSubTest(TestUpDown);
   755 			CaptureUpsAndDownsTest();
   756 			iState++;
   757 			SendEvents();
   758 			break;
   759 /**
   760 @SYMTestCaseID		GRAPHICS-WSERV-0143
   761 
   762 @SYMDEF             DEF081259
   763 
   764 @SYMTestCaseDesc    Up-down key capture test with priorities
   765 
   766 @SYMTestPriority    High
   767 
   768 @SYMTestStatus      Implemented
   769 
   770 @SYMTestActions     The test uses 3 wserv clients with their own window groups. The 
   771 					clients are registered with different priorities for different keys to capture their
   772 					up and down events. The test simulates key presses and releases.
   773 
   774 @SYMTestExpectedResults Checks that the key presses and releases are captured correctly .
   775 */
   776 		case 3:
   777 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0143"));
   778 			iTest->LogSubTest(TestUpDownWithPriority);
   779 			CaptureUpsAndDownsWithPriorityTest();
   780 			iState++;
   781 			SendEvents();
   782 			break;
   783 /**
   784 @SYMTestCaseID		GRAPHICS-WSERV-0144
   785 
   786 @SYMDEF             DEF081259
   787 
   788 @SYMTestCaseDesc    Priority key events test
   789 
   790 @SYMTestPriority    High
   791 
   792 @SYMTestStatus      Implemented
   793 
   794 @SYMTestActions     The test simulates key events and make sure that the events are 
   795 					recieved by the registered wserv client.
   796 
   797 @SYMTestExpectedResults Makes sure that key code is the same as a key simulated, event modifiers comply
   798 					with registered priority key's modifirs and mask, and that event handle 
   799 					is a window group of the session.
   800 					
   801 */
   802 		case 4:
   803 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0144"));
   804 			if (iSubState==numCapKeyTests+numUpDownKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests)
   805 				{
   806 				iTest->LogSubTest(TestAbort);
   807 				SetUpPriorityKeyTest();
   808 				}
   809 			else
   810 				iTest->LogSubTest(TestAbort2);
   811 			//iState++;
   812 			SendEvents();
   813 			TheClient->WaitUntilEventPending();
   814 			break;
   815 /**
   816 @SYMTestCaseID		GRAPHICS-WSERV-0145
   817 
   818 @SYMDEF             DEF081259
   819 
   820 @SYMTestCaseDesc    Invalid capture keys test
   821 
   822 @SYMTestPriority    High
   823 
   824 @SYMTestStatus      Implemented
   825 
   826 @SYMTestActions     Memorizes amount of objects that the server has allocated for that client.
   827 					Tries to register capture keys with invalid modifiers and
   828 					modifier mask pairs, using each of the RWindowGroup capture
   829 					functions CaptureKey(), CaptureKeyUpAndDowns() and
   830 					CaptureLongKey().
   831 
   832 @SYMTestExpectedResults Makes sure that the number of server-side objects for the 
   833 					session didn't change.
   834 */
   835 		case 5:
   836 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0145"));
   837 			iTest->LogSubTest(TestErrors);
   838 			BadParams();
   839 			((CTCaptureKeyStep*)iStep)->RecordTestResultL();
   840 /**
   841 @SYMTestCaseID		GRAPHICS-WSERV-0146
   842 
   843 @SYMDEF             DEF081259
   844 
   845 @SYMTestCaseDesc    Capture keys clean up test
   846 
   847 @SYMTestPriority    High
   848 
   849 @SYMTestStatus      Implemented
   850 
   851 @SYMTestActions     Memorizes amount of objects that the server has allocated for that client.
   852 					Creates a window group and requests two keys to be captured.
   853 					Cancels one key capture request and closes the window group.
   854 
   855 @SYMTestExpectedResults Checks that creation of the group or registering a capture key
   856 					increased this amount by 1 each time.
   857 					Makes sure that the number of server-side objects for the 
   858 					session in the end of the test is the same as in the beginning.
   859 */
   860 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0146"));
   861 			iTest->LogSubTest(TestCaptureKey);
   862 			CapKeyPurgingL();
   863 			iState++;
   864 			break;
   865 /**
   866 @SYMTestCaseID		GRAPHICS-WSERV-0147
   867 
   868 @SYMDEF             DEF081259
   869 
   870 @SYMTestCaseDesc    Capture power off key test
   871 
   872 @SYMTestPriority    High
   873 
   874 @SYMTestStatus      Implemented
   875 
   876 @SYMTestActions     The test creates a new session, new window group and a new window
   877 					in the group. After that the test gives "Hello" name to the group
   878 					and tries to register for key capture of FN+EKeyDevice2 and 0xF844
   879 					buttons. Makes sure that registration fails due to KErrPermissionDenied
   880 					error.
   881 					Then the test changes the name of the window group to "SysApp"
   882 					and tries the registration again. Makes sure that operation 
   883 					completed successfully.
   884 
   885 @SYMTestExpectedResults See actions
   886 */
   887 		case 6:
   888 			((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0147"));
   889 			iTest->LogSubTest(TestCapturePowerOffKey);
   890 			CapKeyPowerOffL();
   891 			iState++;
   892 			break;
   893 		default:
   894 			((CTCaptureKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   895 			TestComplete();
   896 		}
   897 	((CTCaptureKeyStep*)iStep)->RecordTestResultL();
   898 
   899 	}
   900 
   901 
   902 __WS_CONSTRUCT_STEP__(CaptureKey)