sl@0: // Copyright (c) 1996-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Test capture key sl@0: // Coverted from TMan test code (TMCAPKEY.CPP) October 2000 sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "TCapKey.H" sl@0: sl@0: #define LOGGING on sl@0: sl@0: // sl@0: // CAbortHandler sl@0: sl@0: CAbortHandler::CAbortHandler(RWsSession *aWs, CCKAbortConnection *aConnection) : CTEventBase(aWs, 10), iConnection(aConnection) sl@0: { sl@0: } sl@0: sl@0: CAbortHandler::~CAbortHandler() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: void CAbortHandler::Request() sl@0: { sl@0: iWs->PriorityKeyReady(&iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: void CAbortHandler::DoCancel() sl@0: { sl@0: iWs->PriorityKeyReadyCancel(); sl@0: } sl@0: sl@0: void CAbortHandler::doRunL() sl@0: { sl@0: TWsPriorityKeyEvent abortEvent; sl@0: iWs->GetPriorityKey(abortEvent); sl@0: iConnection->ReceivedAbortEvent(abortEvent.Handle(),abortEvent.Key()); sl@0: } sl@0: sl@0: // sl@0: // CCKConnection sl@0: sl@0: CCKConnectionBase::CCKConnectionBase(CTCaptureKey *aTest) : iTest(aTest) sl@0: { sl@0: } sl@0: sl@0: void CCKConnectionBase::ConstructL() sl@0: { sl@0: CTClient::SetScreenNumber(iTest->ScreenNumber()); sl@0: CTClient::ConstructL(); sl@0: iGroup=new(ELeave) CCKWindowGroup(this, iTest); sl@0: iGroup->ConstructL(); sl@0: } sl@0: sl@0: CCKConnection::CCKConnection(CTCaptureKey *aTest, TInt aConnIndex) : CCKConnectionBase(aTest), iConnIndex(aConnIndex) sl@0: { sl@0: } sl@0: sl@0: CCKConnection::~CCKConnection() sl@0: { sl@0: for(TInt index=0;indexGroupWin()->CancelCaptureKey(capKeyHandle[index]); sl@0: for(TInt index1=0;index1GroupWin()->CancelCaptureKey(capKeyWithPriorityHandle[index1]); sl@0: for(TInt index2=0;index2GroupWin()->CancelCaptureKeyUpAndDowns(capUpDownKeyHandle[index2]); sl@0: for(TInt index3=0;index3GroupWin()->CancelCaptureKeyUpAndDowns(capUpDownKeyWithPriorityHandle[index3]); sl@0: CTWin::Delete(iWin); sl@0: } sl@0: sl@0: void CCKConnection::SubStateChanged() sl@0: { sl@0: iWin->Invalidate(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void CCKConnection::ConstructL() sl@0: { sl@0: CCKConnectionBase::ConstructL(); sl@0: for(TInt index=0;indexGroupWin()->CaptureKey(capKeys[index].keyCode,capKeys[index].modifier_mask,capKeys[index].modifiers)); sl@0: for(TInt index1=0;index1GroupWin()->CaptureKey(capKeysWithPriority[index1].keyCode,capKeysWithPriority[index1].modifier_mask,capKeysWithPriority[index1].modifiers,capKeysWithPriority[index1].priority)); sl@0: for(TInt index2=0;index2GroupWin()->CaptureKeyUpAndDowns(capUpAndDownKeys[index2].keyCode, sl@0: capUpAndDownKeys[index2].modifier_mask,capUpAndDownKeys[index2].modifiers)); sl@0: for(TInt index3=0;index3GroupWin()->CaptureKeyUpAndDowns(capUpAndDownKeysWithPriority[index3].keyCode, sl@0: capUpAndDownKeysWithPriority[index3].modifier_mask,capUpAndDownKeysWithPriority[index3].modifiers,capUpAndDownKeysWithPriority[index3].priority)); sl@0: TSize screenSize=iGroup->Size(); sl@0: TInt winWidth=screenSize.iWidth/2; sl@0: TInt winHeight=screenSize.iHeight-10; sl@0: iGroup->GroupWin()->AutoForeground(EFalse); // Don't allow clicking to cause foreground, might mess up test sl@0: CCKWindow *win=new(ELeave) CCKWindow(iTest, iConnIndex); sl@0: win->SetUpL(TPoint(5,5),TSize(winWidth,winHeight),iGroup,*iGc); sl@0: iWin=win; sl@0: } sl@0: sl@0: void CCKConnection::KeyTestL(TInt aBool) sl@0: { sl@0: if (!aBool) sl@0: { sl@0: CTDialog *dialog= new(ELeave) CTDialog(); sl@0: TInt ret=0; sl@0: if (dialog) sl@0: { sl@0: dialog->ConstructLD(*iGroup,*iGc); sl@0: dialog->SetTitle(_L("Invalid key press")); sl@0: dialog->SetLine1(_L("Try again?")); sl@0: dialog->SetNumButtons(2); sl@0: dialog->SetButtonText(0,_L("Fail")); sl@0: dialog->SetButtonText(1,_L("Retry")); sl@0: ret=dialog->Display(); sl@0: } sl@0: User::Leave(ret==1 ? ECapKeyRetry : ECapKeyFail); sl@0: } sl@0: } sl@0: sl@0: void CCKConnection::CheckKeyL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey) sl@0: { sl@0: KeyTestL(aKeyTest.keyCode==aKey.iCode); sl@0: KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask)); sl@0: } sl@0: sl@0: void CCKConnection::CheckUpDownL(const SCapKeyTestParams &aKeyTest, const TKeyEvent &aKey) sl@0: { sl@0: if(iTest->Mode()==EModeKeyUpsAndDownsWithPriority) sl@0: KeyTestL(aKeyTest.connIndex==iTest->SubState()-15); sl@0: KeyTestL(aKeyTest.connIndex==iConnIndex); sl@0: KeyTestL(aKeyTest.keyCode==(TUint)aKey.iScanCode); sl@0: KeyTestL(aKeyTest.modifiers==(aKey.iModifiers&aKeyTest.modifier_mask)); sl@0: } sl@0: sl@0: void CCKConnection::KeyL(const TKeyEvent &aKey,const TTime &) sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"CCKConnection::KeyL State=%d SubState=%d Mode=%d KeyCode=%d ScanCode=%d Mod=0x%x"); sl@0: iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers); sl@0: #endif sl@0: if (iTest->Mode()==EModeNormalCapture || iTest->Mode()==EModeNormalCaptureWithPriority) sl@0: { sl@0: //if (aKey.iCode==EKeyEscape) sl@0: // iTest->Abort(); sl@0: if(iTest->Mode()==EModeNormalCaptureWithPriority) sl@0: { sl@0: SCapKeyTestParams tmpCapKeyTest=capKeyTests[iTest->SubState()]; sl@0: KeyTestL(tmpCapKeyTest.connIndex==iTest->SubState()-8); sl@0: } sl@0: TRAPD(ret,CheckKeyL(capKeyTests[iTest->SubState()],aKey)); sl@0: if (ret==ECapKeyOkay) sl@0: iTest->IncSubState(); sl@0: else sl@0: { sl@0: iTest->TEST(ret==ECapKeyRetry); sl@0: if (ret!=ECapKeyRetry) sl@0: iTest->INFO_PRINTF3(_L("CheckKeyL(capKeyTests[iTest->SubState()],aKey) return value - Expected: %d, Actual: %d"), ECapKeyRetry, ret); sl@0: } sl@0: sl@0: } sl@0: } sl@0: sl@0: void CCKConnection::CheckUpDownL(const TKeyEvent &aKey) sl@0: { sl@0: CheckUpDownL(capKeyTests[iTest->SubState()],aKey); sl@0: } sl@0: sl@0: CCKAbortConnection::CCKAbortConnection(CTCaptureKey *aTest) : CCKConnectionBase(aTest) sl@0: { sl@0: } sl@0: sl@0: CCKAbortConnection::~CCKAbortConnection() sl@0: { sl@0: iGroup->GroupWin()->RemovePriorityKey(3,EModifierCtrl,EModifierCtrl); sl@0: delete iAbortHandler; sl@0: } sl@0: sl@0: void CCKAbortConnection::ConstructL() sl@0: { sl@0: CCKConnectionBase::ConstructL(); sl@0: User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[0].keyCode,abortKeyTests[0].modifier_mask,abortKeyTests[0].modifiers)); sl@0: User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[1].keyCode,abortKeyTests[1].modifier_mask,abortKeyTests[1].modifiers)); sl@0: User::LeaveIfError(iGroup->GroupWin()->AddPriorityKey(abortKeyTests[2].keyCode,abortKeyTests[2].modifier_mask,abortKeyTests[2].modifiers)); sl@0: iAbortHandler=new(ELeave) CAbortHandler(&iWs, this); sl@0: iAbortHandler->Construct(); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: void CCKAbortConnection::ReceivedAbortEvent(TInt aHandle,TKeyEvent* aKey) sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"CCKAbortConnection::ReceivedAbortEvent State=%d SubState=%d Mode=%d KeyCode=%d ScanCode=%d Mod=0x%x"); sl@0: iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey->iCode,aKey->iScanCode,aKey->iModifiers); sl@0: #endif sl@0: TInt group=reinterpret_cast(iGroup); sl@0: iTest->TEST(aHandle==group); sl@0: if (aHandle!=group) sl@0: { sl@0: _LIT(KLog,"Event Handle is not for the right group, expected=%d actual=%d"); sl@0: iTest->LOG_MESSAGE3(KLog,group,aHandle); sl@0: } sl@0: sl@0: iTest->TEST(aKey->iCode==abortKeyTests[iAbortKeyIndex].keyCode); sl@0: if (aKey->iCode!=abortKeyTests[iAbortKeyIndex].keyCode) sl@0: { sl@0: _LIT(KLog,"The event KeyCode is not right, expected=%d actual=%d"); sl@0: iTest->LOG_MESSAGE3(KLog,abortKeyTests[iAbortKeyIndex].keyCode,aKey->iCode); sl@0: } sl@0: sl@0: iTest->TEST((aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask)==abortKeyTests[iAbortKeyIndex].modifiers); sl@0: if ((aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask)!=abortKeyTests[iAbortKeyIndex].modifiers) sl@0: { sl@0: _LIT(KLog,"The event modifiers are not right, expected=0x%x actual=0x%x (0x%x) mask=0x%x"); sl@0: iTest->LOG_MESSAGE5(KLog,abortKeyTests[iAbortKeyIndex].modifiers,aKey->iModifiers&abortKeyTests[iAbortKeyIndex].modifier_mask sl@0: ,aKey->iModifiers,abortKeyTests[iAbortKeyIndex].modifier_mask); sl@0: } sl@0: iAbortKeyIndex++; sl@0: iTest->IncSubState(); sl@0: } sl@0: sl@0: void CCKAbortConnection::Foreground() sl@0: { sl@0: iGroup->GroupWin()->SetOrdinalPosition(0); sl@0: iWs.Flush(); sl@0: } sl@0: sl@0: // sl@0: // CCKWindowGroup class // sl@0: // sl@0: sl@0: CCKWindowGroup::CCKWindowGroup(CTClient *aClient, CTCaptureKey *aTest) : CTWindowGroup(aClient), iTest(aTest) sl@0: {} sl@0: sl@0: void CCKWindowGroup::KeyL(const TKeyEvent &aKey,const TTime &time) sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"CCKWindowGroup::KeyL State=%d SubState=%d Mode=%d KeyCode=%d ScanCode=%d Mod=0x%x"); sl@0: iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers); sl@0: #endif sl@0: if (iTest->Mode()==EModeWaitingForFirstNormalCapWithPriority) sl@0: iTest->SetMode(EModeNormalCaptureWithPriority); sl@0: if (iCurWin) sl@0: iCurWin->WinKeyL(aKey,time); sl@0: else sl@0: ((CCKConnection *)iClient)->KeyL(aKey,time); sl@0: } sl@0: sl@0: void CCKWindowGroup::KeyDownL(const TKeyEvent &aKey,const TTime &) sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"CCKWindowGroup::KeyDownL State=%d SubState=%d Mode=%d KeyCode=%d ScanCode=%d Mod=0x%x"); sl@0: iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers); sl@0: #endif sl@0: if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift) sl@0: { sl@0: if (iTest->Mode()==EModeWaitingForFirstDown) sl@0: iTest->SetMode(EModeKeyUpsAndDowns); sl@0: if (iTest->Mode()==EModeWaitingForFirstDownWithPriority) sl@0: iTest->SetMode(EModeKeyUpsAndDownsWithPriority); sl@0: if (iTest->Mode()==EModeKeyUpsAndDowns || iTest->Mode()==EModeKeyUpsAndDownsWithPriority) sl@0: ((CCKConnection *)iClient)->CheckUpDownL(aKey); sl@0: } sl@0: } sl@0: sl@0: void CCKWindowGroup::KeyUpL(const TKeyEvent &aKey,const TTime &) sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"CCKWindowGroup::KeyUpL State=%d SubState=%d Mode=%d KeyCode=%d ScanCode=%d Mod=0x%x"); sl@0: iTest->LOG_MESSAGE7(KLog,iTest->State(),iTest->SubState(),iTest->Mode(),aKey.iCode,aKey.iScanCode,aKey.iModifiers); sl@0: #endif sl@0: if (aKey.iScanCode!=EStdKeyLeftShift && aKey.iScanCode!=EStdKeyRightShift) sl@0: { sl@0: if (iTest->Mode()==EModeKeyUpsAndDowns || iTest->Mode()==EModeKeyUpsAndDownsWithPriority) sl@0: { sl@0: ((CCKConnection *)iClient)->CheckUpDownL(aKey); sl@0: iTest->IncSubState(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: // sl@0: // CCKWindow, class // sl@0: // sl@0: sl@0: CCKWindow::CCKWindow(CTCaptureKey *aTest, TInt aConnIndex) : CTWin(), iConnIndex(aConnIndex), iTest(aTest) sl@0: { sl@0: iBack=TRgb::Gray256(230); sl@0: } sl@0: sl@0: void CCKWindow::SetUpL(TPoint pos,TSize size,CTWinBase *parent, CWindowGc &aGc) sl@0: { sl@0: ConstructExtLD(*parent,pos,size); sl@0: iWin.SetBackgroundColor(iBack); sl@0: Activate(); sl@0: AssignGC(aGc); sl@0: } sl@0: sl@0: void CCKWindow::Draw() sl@0: { sl@0: iGc->Clear(); sl@0: if (iConnIndex==0) sl@0: { sl@0: TInt test=iTest->SubState(); sl@0: if (testDrawText(TPtrC(capKeyTests[test].txt), TPoint(10,20)); sl@0: } sl@0: } sl@0: sl@0: // sl@0: sl@0: CTCaptureKey::CTCaptureKey(CTestStep* aStep) : CTWsGraphicsBase(aStep) sl@0: { sl@0: } sl@0: sl@0: CTCaptureKey::~CTCaptureKey() sl@0: { sl@0: ((CTCaptureKeyStep*)iStep)->CloseTMSGraphicsStep(); sl@0: delete iConn1; sl@0: delete iConn2; sl@0: delete iConn3; sl@0: delete iAbortConn; sl@0: } sl@0: sl@0: void CTCaptureKey::ConstructL() sl@0: { sl@0: iAbortConn=new(ELeave) CCKAbortConnection(this); sl@0: iAbortConn->ConstructL(); sl@0: iConn3=new(ELeave) CCKConnection(this,2); sl@0: iConn3->ConstructL(); sl@0: iConn2=new(ELeave) CCKConnection(this,1); sl@0: iConn2->ConstructL(); sl@0: iConn1=new(ELeave) CCKConnection(this,0); sl@0: iConn1->ConstructL(); sl@0: iMode=EModeNormalCapture; sl@0: SetSelfDrive(ETrue); sl@0: TUint mods=TheClient->iWs.GetModifierState(); sl@0: _LIT(KLog,"Initial Modifiers state 0x%x (ideally should be zero)"); sl@0: LOG_MESSAGE2(KLog,mods); sl@0: } sl@0: sl@0: TInt CTCaptureKey::SubState() const sl@0: { sl@0: return(iSubState); sl@0: } sl@0: sl@0: void CTCaptureKey::IncSubState() sl@0: { sl@0: iSubState++; sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"IncSubState State=%d SubState=%d Mode=%d"); sl@0: LOG_MESSAGE4(KLog,iState,iSubState,iMode); sl@0: #endif sl@0: iConn1->SubStateChanged(); sl@0: iConn2->SubStateChanged(); sl@0: iConn3->SubStateChanged(); sl@0: switch(iMode) sl@0: { sl@0: case EModeNormalCapture: sl@0: if (iSubState==numCapKeyTests) sl@0: { sl@0: CaseComplete(); sl@0: return; sl@0: } sl@0: break; sl@0: case EModeNormalCaptureWithPriority: sl@0: if (iSubState==numCapKeyTests+numCapKeyWithPriorityTests) sl@0: { sl@0: CaseComplete(); sl@0: return; sl@0: } sl@0: break; sl@0: case EModeKeyUpsAndDowns: sl@0: if (iSubState==(numCapKeyTests+numCapKeyWithPriorityTests+numUpDownKeyTests)) sl@0: { sl@0: CaseComplete(); sl@0: return; sl@0: } sl@0: break; sl@0: case EModeKeyUpsAndDownsWithPriority: sl@0: if (iSubState==(numCapKeyTests+numCapKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests)) sl@0: { sl@0: SetSelfDrive(EFalse); sl@0: return; sl@0: } sl@0: break; sl@0: case EModeAbortKeys: sl@0: if (iSubState==(numCapKeyTests+numCapKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests+numAbortKeyTests)) sl@0: ++iState; sl@0: TheClient->WaitForRedrawsToFinish(); sl@0: return; sl@0: default: sl@0: break; sl@0: } sl@0: TheClient->WaitForRedrawsToFinish(); sl@0: SendEvents(); sl@0: } sl@0: sl@0: void CTCaptureKey::CapKeyPurgingL() sl@0: { sl@0: TInt base=Client()->iWs.ResourceCount(); sl@0: RWindowGroup groupWin(Client()->iWs); sl@0: User::LeaveIfError(groupWin.Construct(ENullWsHandle)); sl@0: TInt capHandle=User::LeaveIfError(groupWin.CaptureKey('a',EModifierFunc,EModifierFunc)); sl@0: User::LeaveIfError(groupWin.CaptureKey('b',EModifierFunc,EModifierFunc)); sl@0: TInt retVal = Client()->iWs.ResourceCount(); sl@0: TEST(retVal==(base+3)); sl@0: if (retVal!=(base+3)) sl@0: INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), retVal, (base+3)); sl@0: sl@0: groupWin.CancelCaptureKey(capHandle); sl@0: retVal = Client()->iWs.ResourceCount(); sl@0: TEST(retVal==(base+2)); sl@0: if (retVal!=(base+2)) sl@0: INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), retVal, (base+2)); sl@0: sl@0: groupWin.Close(); sl@0: // Check it also freed the extra capture key sl@0: retVal = Client()->iWs.ResourceCount(); sl@0: TEST(retVal==base); sl@0: if (retVal!=base) sl@0: INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), retVal, base); sl@0: sl@0: } sl@0: sl@0: void CTCaptureKey::BadParams() sl@0: { sl@0: TInt retVal; sl@0: TInt resCount=Client()->iWs.ResourceCount(); sl@0: for(TInt index=0;indexiGroup->GroupWin()->CaptureKey(errorKeys[index].keyCode,errorKeys[index].modifier_mask,errorKeys[index].modifiers, errorKeys[index].priority); sl@0: TEST(retVal==KErrArgument); sl@0: if (retVal!=KErrArgument) sl@0: { sl@0: _LIT(KMsg, "CaptureKey() with bad parameter set %d returned %d - expected KErrArgument (%d)"); sl@0: LOG_MESSAGE4(KMsg, index, retVal, KErrArgument); sl@0: } sl@0: sl@0: retVal = Client()->iGroup->GroupWin()->CaptureKeyUpAndDowns(errorKeys[index].keyCode, errorKeys[index].modifier_mask, errorKeys[index].modifiers, errorKeys[index].priority); sl@0: TEST(retVal == KErrArgument); sl@0: if (retVal != KErrArgument) sl@0: { sl@0: _LIT(KMsg, "CaptureKeyUpAndDowns() with bad parameter set %d returned %d - expected KErrArgument (%d)"); sl@0: LOG_MESSAGE4(KMsg, index, retVal, KErrArgument); sl@0: } sl@0: sl@0: retVal = Client()->iGroup->GroupWin()->CaptureLongKey(errorKeys[index].keyCode, errorKeys[index].keyCode, errorKeys[index].modifier_mask, errorKeys[index].modifiers, errorKeys[index].priority, ELongCaptureNormal); sl@0: TEST(retVal == KErrArgument); sl@0: if (retVal != KErrArgument) sl@0: { sl@0: _LIT(KMsg, "CaptureLongKey() with bad parameter set %d returned %d - expected KErrArgument (%d)"); sl@0: LOG_MESSAGE4(KMsg, index, retVal, KErrArgument); sl@0: } sl@0: } sl@0: sl@0: retVal = Client()->iWs.ResourceCount(); sl@0: TEST(retVal==resCount); sl@0: if (retVal!=resCount) sl@0: { sl@0: _LIT(KMsg, "Resource count %d - expected %d"); sl@0: LOG_MESSAGE3(KMsg, retVal, resCount); sl@0: } sl@0: } sl@0: sl@0: void CTCaptureKey::SetMode(TTestMode aMode) sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"SetMode State=%d SubState=%d OldMode=%d NewMode=%d"); sl@0: LOG_MESSAGE5(KLog,State(),SubState(),iMode,aMode); sl@0: #endif sl@0: iMode=aMode; sl@0: } sl@0: sl@0: TTestMode CTCaptureKey::Mode() sl@0: { sl@0: return(iMode); sl@0: } sl@0: sl@0: void CTCaptureKey::SetUpPriorityKeyTest() sl@0: { sl@0: iMode=EModeAbortKeys; sl@0: iAbortConn->Foreground(); sl@0: } sl@0: sl@0: void CTCaptureKey::CaptureWithPriorityTest() //normal key capture but with priority sl@0: { sl@0: iMode=EModeWaitingForFirstNormalCapWithPriority; sl@0: } sl@0: sl@0: void CTCaptureKey::CaptureUpsAndDownsTest() sl@0: { sl@0: iMode=EModeWaitingForFirstDown; sl@0: } sl@0: sl@0: void CTCaptureKey::CaptureUpsAndDownsWithPriorityTest() sl@0: { sl@0: iMode=EModeWaitingForFirstDownWithPriority; sl@0: } sl@0: sl@0: void CTCaptureKey::SendEvents() sl@0: { sl@0: #if defined(LOGGING) sl@0: _LIT(KLog,"SendEvents State=%d SubState=%d"); sl@0: LOG_MESSAGE3(KLog,iState,iSubState); sl@0: #endif sl@0: switch (iSubState) sl@0: { sl@0: case 0: sl@0: iTest->SimulateKeyDownUp('Q'); sl@0: break; sl@0: case 1: sl@0: iTest->SimulateKeyDownUpWithModifiers('W',EModifierAlt); sl@0: break; sl@0: case 2: sl@0: iTest->SimulateKeyDownUp('A'); sl@0: break; sl@0: case 3: sl@0: iTest->SimulateKeyDownUpWithModifiers('S',EModifierAlt|EModifierCtrl); sl@0: break; sl@0: case 4: sl@0: iTest->SimulateKeyDownUpWithModifiers('N',EModifierAlt); sl@0: break; sl@0: case 5: sl@0: iTest->SimulateKeyDownUpWithModifiers('B',EModifierAlt|EModifierCtrl); sl@0: break; sl@0: case 6: sl@0: iTest->SimulateKeyDownUpWithModifiers('D',EModifierAlt); sl@0: break; sl@0: case 7: sl@0: iTest->SimulateKeyDownUpWithModifiers('C',EModifierAlt|EModifierCtrl); sl@0: break; sl@0: case 8: sl@0: iTest->SimulateKeyDownUp('H');//state EModeNormalCaptureWithPriority sl@0: break; sl@0: case 9: sl@0: iTest->SimulateKeyDownUp('J'); sl@0: break; sl@0: case 10: sl@0: iTest->SimulateKeyDownUp('K'); sl@0: break; sl@0: case 11: sl@0: iTest->SimulateKeyDownUp(EStdKeySpace); sl@0: break; sl@0: case 12: sl@0: iTest->SimulateKeyDownUp(EStdKeyEnter); sl@0: break; sl@0: case 13: sl@0: iTest->SimulateKeyDownUpWithModifiers(EStdKeySpace,EModifierShift); sl@0: break; sl@0: case 14: sl@0: iTest->SimulateKeyDownUpWithModifiers(EStdKeyEnter,EModifierShift); sl@0: break; sl@0: case 15: sl@0: iTest->SimulateKeyDownUp('H');//state EModeKeyUpsAndDownsWithPriority sl@0: break; sl@0: case 16: sl@0: iTest->SimulateKeyDownUp('J'); sl@0: break; sl@0: case 17: sl@0: iTest->SimulateKeyDownUp('K'); sl@0: break; sl@0: case 18: sl@0: iTest->SimulateKeyDownUpWithModifiers('C',EModifierCtrl); sl@0: break; sl@0: case 19: sl@0: iTest->SimulateKeyDownUpWithModifiers('D',EModifierCtrl); sl@0: break; sl@0: case 20: sl@0: iTest->SimulateKeyDownUp('Z'); sl@0: break; sl@0: default: sl@0: TEST(EFalse); sl@0: } sl@0: TheClient->iWs.Flush(); sl@0: } sl@0: sl@0: void CTCaptureKey::CapKeyPowerOffL() sl@0: { sl@0: const TUint protKey=0xF844; //This value needs to be defined in the WSINI.INI file as a key only capturable by a certain application sl@0: RWsSession ws; sl@0: User::LeaveIfError(ws.Connect()); sl@0: CleanupClosePushL(ws); sl@0: sl@0: // assign to the correct screen sl@0: CWsScreenDevice* screen = new (ELeave) CWsScreenDevice(ws); sl@0: CleanupStack::PushL(screen); sl@0: User::LeaveIfError(screen->Construct(iTest->iScreenNumber)); sl@0: sl@0: RWindowGroup group(ws); sl@0: group.Construct(ENullWsHandle); sl@0: CleanupClosePushL(group); sl@0: group.EnableReceiptOfFocus(EFalse); sl@0: group.SetOrdinalPosition(0,5); sl@0: RBlankWindow blank(ws); sl@0: blank.Construct(group,ENullWsHandle); sl@0: CleanupClosePushL(blank); sl@0: blank.EnableBackup(); sl@0: blank.Activate(); sl@0: _LIT(kGroupName1,"Hello"); sl@0: group.SetName(kGroupName1); sl@0: TInt capHandle = group.CaptureKey(EKeyDevice2,EModifierFunc,EModifierFunc); sl@0: TEST(capHandle==KErrPermissionDenied); sl@0: if (capHandle!=KErrPermissionDenied) sl@0: { sl@0: _LIT(KLog1,"Capture Key suceeded when it should of failed, Error/Handle=%d (expected: %d)"); sl@0: LOG_MESSAGE3(KLog1,capHandle,KErrPermissionDenied); sl@0: _LIT(KLog2,"This is indicative of a bad WSINI file"); sl@0: LOG_MESSAGE(KLog2); sl@0: } sl@0: sl@0: capHandle=group.CaptureKeyUpAndDowns(protKey,0,0); sl@0: TEST(capHandle==KErrPermissionDenied); sl@0: if (capHandle!=KErrPermissionDenied) sl@0: { sl@0: _LIT(KLog,"Capture Key Up & Down suceeded when it should of failed, Error/Handle=%d (expected: %d)"); sl@0: LOG_MESSAGE3(KLog,capHandle,KErrPermissionDenied); sl@0: } sl@0: sl@0: _LIT(kGroupName2,"SysApp"); sl@0: group.SetName(kGroupName2); sl@0: capHandle = group.CaptureKey(EKeyDevice2,EModifierFunc,EModifierFunc); sl@0: TEST(capHandle > 0); sl@0: if (capHandle<=0) sl@0: { sl@0: _LIT(KLog,"Capture Key failed when it should of succeeded, Error=%d"); sl@0: LOG_MESSAGE2(KLog,capHandle); sl@0: } sl@0: sl@0: group.CancelCaptureKey(capHandle); sl@0: capHandle=group.CaptureKeyUpAndDowns(protKey,0,0); sl@0: TEST(capHandle > 0); sl@0: if (capHandle<=0) sl@0: { sl@0: _LIT(KLog,"Capture Key Up & Down failed when it should of succeeded, Error=%d"); sl@0: LOG_MESSAGE2(KLog,capHandle); sl@0: } sl@0: sl@0: group.CancelCaptureKeyUpAndDowns(capHandle); sl@0: CleanupStack::PopAndDestroy(4,&ws); sl@0: } sl@0: sl@0: sl@0: void CTCaptureKey::RunTestCaseL(TInt /*aCurTestCase*/) sl@0: { sl@0: _LIT(Test0,"Normal capture with priority"); sl@0: _LIT(TestNormalCaptureWithPriority,"Normal capture with priority"); sl@0: _LIT(TestUpDown,"Capture ups and downs"); sl@0: _LIT(TestUpDownWithPriority,"Capture ups and downs with priority"); sl@0: _LIT(TestAbort,"Abort key"); sl@0: _LIT(TestAbort2,"Abort key extended"); sl@0: _LIT(TestErrors,"Errors"); sl@0: _LIT(TestCaptureKey,"Capture Key"); sl@0: _LIT(TestCapturePowerOffKey,"Capture PowerOff Key"); sl@0: sl@0: iTest->iState=iState; sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); sl@0: switch(iState) sl@0: { sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0140 sl@0: sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Normal key capture test sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions The test uses 3 wserv clients with their own window groups. The sl@0: clients are registered for different keys to capture. The test sl@0: simulates key presses. sl@0: sl@0: @SYMTestExpectedResults Checks that the key presses are captured correctly . sl@0: */ sl@0: case 0: // Dummy one to let capture key tests run sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0140")); sl@0: iTest->LogSubTest(Test0); sl@0: iState++; sl@0: SendEvents(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0141 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Normal key capture test with priorities sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions The test uses 3 wserv clients with their own window groups. The sl@0: clients are registered for different keys to capture and with sl@0: different priorities. The test simulates key presses. sl@0: sl@0: @SYMTestExpectedResults Checks that the key presses are captured correctly . sl@0: */ sl@0: case 1: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0141")); sl@0: iTest->LogSubTest(TestNormalCaptureWithPriority); sl@0: CaptureWithPriorityTest(); sl@0: iState++; sl@0: SendEvents(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0142 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Up-down key capture test sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions The test uses 3 wserv clients with their own window groups. The sl@0: clients are registered for different keys to capture their sl@0: up and down events. The test simulates key presses and releases. sl@0: sl@0: @SYMTestExpectedResults Checks that the key presses and releases are captured correctly . sl@0: */ sl@0: case 2: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0142")); sl@0: iTest->LogSubTest(TestUpDown); sl@0: CaptureUpsAndDownsTest(); sl@0: iState++; sl@0: SendEvents(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0143 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Up-down key capture test with priorities sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions The test uses 3 wserv clients with their own window groups. The sl@0: clients are registered with different priorities for different keys to capture their sl@0: up and down events. The test simulates key presses and releases. sl@0: sl@0: @SYMTestExpectedResults Checks that the key presses and releases are captured correctly . sl@0: */ sl@0: case 3: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0143")); sl@0: iTest->LogSubTest(TestUpDownWithPriority); sl@0: CaptureUpsAndDownsWithPriorityTest(); sl@0: iState++; sl@0: SendEvents(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0144 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Priority key events test sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions The test simulates key events and make sure that the events are sl@0: recieved by the registered wserv client. sl@0: sl@0: @SYMTestExpectedResults Makes sure that key code is the same as a key simulated, event modifiers comply sl@0: with registered priority key's modifirs and mask, and that event handle sl@0: is a window group of the session. sl@0: sl@0: */ sl@0: case 4: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0144")); sl@0: if (iSubState==numCapKeyTests+numUpDownKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests) sl@0: { sl@0: iTest->LogSubTest(TestAbort); sl@0: SetUpPriorityKeyTest(); sl@0: } sl@0: else sl@0: iTest->LogSubTest(TestAbort2); sl@0: //iState++; sl@0: SendEvents(); sl@0: TheClient->WaitUntilEventPending(); sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0145 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Invalid capture keys test sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Memorizes amount of objects that the server has allocated for that client. sl@0: Tries to register capture keys with invalid modifiers and sl@0: modifier mask pairs, using each of the RWindowGroup capture sl@0: functions CaptureKey(), CaptureKeyUpAndDowns() and sl@0: CaptureLongKey(). sl@0: sl@0: @SYMTestExpectedResults Makes sure that the number of server-side objects for the sl@0: session didn't change. sl@0: */ sl@0: case 5: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0145")); sl@0: iTest->LogSubTest(TestErrors); sl@0: BadParams(); sl@0: ((CTCaptureKeyStep*)iStep)->RecordTestResultL(); sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0146 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Capture keys clean up test sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions Memorizes amount of objects that the server has allocated for that client. sl@0: Creates a window group and requests two keys to be captured. sl@0: Cancels one key capture request and closes the window group. sl@0: sl@0: @SYMTestExpectedResults Checks that creation of the group or registering a capture key sl@0: increased this amount by 1 each time. sl@0: Makes sure that the number of server-side objects for the sl@0: session in the end of the test is the same as in the beginning. sl@0: */ sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0146")); sl@0: iTest->LogSubTest(TestCaptureKey); sl@0: CapKeyPurgingL(); sl@0: iState++; sl@0: break; sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-WSERV-0147 sl@0: sl@0: @SYMDEF DEF081259 sl@0: sl@0: @SYMTestCaseDesc Capture power off key test sl@0: sl@0: @SYMTestPriority High sl@0: sl@0: @SYMTestStatus Implemented sl@0: sl@0: @SYMTestActions The test creates a new session, new window group and a new window sl@0: in the group. After that the test gives "Hello" name to the group sl@0: and tries to register for key capture of FN+EKeyDevice2 and 0xF844 sl@0: buttons. Makes sure that registration fails due to KErrPermissionDenied sl@0: error. sl@0: Then the test changes the name of the window group to "SysApp" sl@0: and tries the registration again. Makes sure that operation sl@0: completed successfully. sl@0: sl@0: @SYMTestExpectedResults See actions sl@0: */ sl@0: case 6: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0147")); sl@0: iTest->LogSubTest(TestCapturePowerOffKey); sl@0: CapKeyPowerOffL(); sl@0: iState++; sl@0: break; sl@0: default: sl@0: ((CTCaptureKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); sl@0: TestComplete(); sl@0: } sl@0: ((CTCaptureKeyStep*)iStep)->RecordTestResultL(); sl@0: sl@0: } sl@0: sl@0: sl@0: __WS_CONSTRUCT_STEP__(CaptureKey)