|
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // 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); |
|
460 TEST(retVal==KErrArgument); |
|
461 if (retVal!=KErrArgument) |
|
462 INFO_PRINTF3(_L("Client()->iGroup->GroupWin()->CaptureKey() return value - Expected: %d, Actual: %d"), KErrArgument, retVal); |
|
463 } |
|
464 retVal = Client()->iWs.ResourceCount(); |
|
465 TEST(retVal==resCount); |
|
466 if (retVal!=resCount) |
|
467 INFO_PRINTF3(_L("Client()->iWs.ResourceCount() return value - Expected: %d, Actual: %d"), resCount, retVal); |
|
468 } |
|
469 |
|
470 void CTCaptureKey::SetMode(TTestMode aMode) |
|
471 { |
|
472 #if defined(LOGGING) |
|
473 _LIT(KLog,"SetMode State=%d SubState=%d OldMode=%d NewMode=%d"); |
|
474 LOG_MESSAGE5(KLog,State(),SubState(),iMode,aMode); |
|
475 #endif |
|
476 iMode=aMode; |
|
477 } |
|
478 |
|
479 TTestMode CTCaptureKey::Mode() |
|
480 { |
|
481 return(iMode); |
|
482 } |
|
483 |
|
484 void CTCaptureKey::SetUpPriorityKeyTest() |
|
485 { |
|
486 iMode=EModeAbortKeys; |
|
487 iAbortConn->Foreground(); |
|
488 } |
|
489 |
|
490 void CTCaptureKey::CaptureWithPriorityTest() //normal key capture but with priority |
|
491 { |
|
492 iMode=EModeWaitingForFirstNormalCapWithPriority; |
|
493 } |
|
494 |
|
495 void CTCaptureKey::CaptureUpsAndDownsTest() |
|
496 { |
|
497 iMode=EModeWaitingForFirstDown; |
|
498 } |
|
499 |
|
500 void CTCaptureKey::CaptureUpsAndDownsWithPriorityTest() |
|
501 { |
|
502 iMode=EModeWaitingForFirstDownWithPriority; |
|
503 } |
|
504 |
|
505 void CTCaptureKey::SendEvents() |
|
506 { |
|
507 #if defined(LOGGING) |
|
508 _LIT(KLog,"SendEvents State=%d SubState=%d"); |
|
509 LOG_MESSAGE3(KLog,iState,iSubState); |
|
510 #endif |
|
511 switch (iSubState) |
|
512 { |
|
513 case 0: |
|
514 iTest->SimulateKeyDownUp('Q'); |
|
515 break; |
|
516 case 1: |
|
517 iTest->SimulateKeyDownUpWithModifiers('W',EModifierAlt); |
|
518 break; |
|
519 case 2: |
|
520 iTest->SimulateKeyDownUp('A'); |
|
521 break; |
|
522 case 3: |
|
523 iTest->SimulateKeyDownUpWithModifiers('S',EModifierAlt|EModifierCtrl); |
|
524 break; |
|
525 case 4: |
|
526 iTest->SimulateKeyDownUpWithModifiers('N',EModifierAlt); |
|
527 break; |
|
528 case 5: |
|
529 iTest->SimulateKeyDownUpWithModifiers('B',EModifierAlt|EModifierCtrl); |
|
530 break; |
|
531 case 6: |
|
532 iTest->SimulateKeyDownUpWithModifiers('D',EModifierAlt); |
|
533 break; |
|
534 case 7: |
|
535 iTest->SimulateKeyDownUpWithModifiers('C',EModifierAlt|EModifierCtrl); |
|
536 break; |
|
537 case 8: |
|
538 iTest->SimulateKeyDownUp('H');//state EModeNormalCaptureWithPriority |
|
539 break; |
|
540 case 9: |
|
541 iTest->SimulateKeyDownUp('J'); |
|
542 break; |
|
543 case 10: |
|
544 iTest->SimulateKeyDownUp('K'); |
|
545 break; |
|
546 case 11: |
|
547 iTest->SimulateKeyDownUp(EStdKeySpace); |
|
548 break; |
|
549 case 12: |
|
550 iTest->SimulateKeyDownUp(EStdKeyEnter); |
|
551 break; |
|
552 case 13: |
|
553 iTest->SimulateKeyDownUpWithModifiers(EStdKeySpace,EModifierShift); |
|
554 break; |
|
555 case 14: |
|
556 iTest->SimulateKeyDownUpWithModifiers(EStdKeyEnter,EModifierShift); |
|
557 break; |
|
558 case 15: |
|
559 iTest->SimulateKeyDownUp('H');//state EModeKeyUpsAndDownsWithPriority |
|
560 break; |
|
561 case 16: |
|
562 iTest->SimulateKeyDownUp('J'); |
|
563 break; |
|
564 case 17: |
|
565 iTest->SimulateKeyDownUp('K'); |
|
566 break; |
|
567 case 18: |
|
568 iTest->SimulateKeyDownUpWithModifiers('C',EModifierCtrl); |
|
569 break; |
|
570 case 19: |
|
571 iTest->SimulateKeyDownUpWithModifiers('D',EModifierCtrl); |
|
572 break; |
|
573 case 20: |
|
574 iTest->SimulateKeyDownUp('Z'); |
|
575 break; |
|
576 default: |
|
577 TEST(EFalse); |
|
578 } |
|
579 TheClient->iWs.Flush(); |
|
580 } |
|
581 |
|
582 void CTCaptureKey::CapKeyPowerOffL() |
|
583 { |
|
584 const TUint protKey=0xF844; //This value needs to be defined in the WSINI.INI file as a key only capturable by a certain application |
|
585 RWsSession ws; |
|
586 User::LeaveIfError(ws.Connect()); |
|
587 CleanupClosePushL(ws); |
|
588 |
|
589 // assign to the correct screen |
|
590 CWsScreenDevice* screen = new (ELeave) CWsScreenDevice(ws); |
|
591 CleanupStack::PushL(screen); |
|
592 User::LeaveIfError(screen->Construct(iTest->iScreenNumber)); |
|
593 |
|
594 RWindowGroup group(ws); |
|
595 group.Construct(ENullWsHandle); |
|
596 CleanupClosePushL(group); |
|
597 group.EnableReceiptOfFocus(EFalse); |
|
598 group.SetOrdinalPosition(0,5); |
|
599 RBlankWindow blank(ws); |
|
600 blank.Construct(group,ENullWsHandle); |
|
601 CleanupClosePushL(blank); |
|
602 blank.EnableBackup(); |
|
603 blank.Activate(); |
|
604 _LIT(kGroupName1,"Hello"); |
|
605 group.SetName(kGroupName1); |
|
606 TInt capHandle = group.CaptureKey(EKeyDevice2,EModifierFunc,EModifierFunc); |
|
607 TEST(capHandle==KErrPermissionDenied); |
|
608 if (capHandle!=KErrPermissionDenied) |
|
609 { |
|
610 _LIT(KLog1,"Capture Key suceeded when it should of failed, Error/Handle=%d (expected: %d)"); |
|
611 LOG_MESSAGE3(KLog1,capHandle,KErrPermissionDenied); |
|
612 _LIT(KLog2,"This is indicative of a bad WSINI file"); |
|
613 LOG_MESSAGE(KLog2); |
|
614 } |
|
615 |
|
616 capHandle=group.CaptureKeyUpAndDowns(protKey,0,0); |
|
617 TEST(capHandle==KErrPermissionDenied); |
|
618 if (capHandle!=KErrPermissionDenied) |
|
619 { |
|
620 _LIT(KLog,"Capture Key Up & Down suceeded when it should of failed, Error/Handle=%d (expected: %d)"); |
|
621 LOG_MESSAGE3(KLog,capHandle,KErrPermissionDenied); |
|
622 } |
|
623 |
|
624 _LIT(kGroupName2,"SysApp"); |
|
625 group.SetName(kGroupName2); |
|
626 capHandle = group.CaptureKey(EKeyDevice2,EModifierFunc,EModifierFunc); |
|
627 TEST(capHandle > 0); |
|
628 if (capHandle<=0) |
|
629 { |
|
630 _LIT(KLog,"Capture Key failed when it should of succeeded, Error=%d"); |
|
631 LOG_MESSAGE2(KLog,capHandle); |
|
632 } |
|
633 |
|
634 group.CancelCaptureKey(capHandle); |
|
635 capHandle=group.CaptureKeyUpAndDowns(protKey,0,0); |
|
636 TEST(capHandle > 0); |
|
637 if (capHandle<=0) |
|
638 { |
|
639 _LIT(KLog,"Capture Key Up & Down failed when it should of succeeded, Error=%d"); |
|
640 LOG_MESSAGE2(KLog,capHandle); |
|
641 } |
|
642 |
|
643 group.CancelCaptureKeyUpAndDowns(capHandle); |
|
644 CleanupStack::PopAndDestroy(4,&ws); |
|
645 } |
|
646 |
|
647 |
|
648 void CTCaptureKey::RunTestCaseL(TInt /*aCurTestCase*/) |
|
649 { |
|
650 _LIT(Test0,"Normal capture with priority"); |
|
651 _LIT(TestNormalCaptureWithPriority,"Normal capture with priority"); |
|
652 _LIT(TestUpDown,"Capture ups and downs"); |
|
653 _LIT(TestUpDownWithPriority,"Capture ups and downs with priority"); |
|
654 _LIT(TestAbort,"Abort key"); |
|
655 _LIT(TestAbort2,"Abort key extended"); |
|
656 _LIT(TestErrors,"Errors"); |
|
657 _LIT(TestCaptureKey,"Capture Key"); |
|
658 _LIT(TestCapturePowerOffKey,"Capture PowerOff Key"); |
|
659 |
|
660 iTest->iState=iState; |
|
661 ((CTCaptureKeyStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName); |
|
662 switch(iState) |
|
663 { |
|
664 /** |
|
665 @SYMTestCaseID GRAPHICS-WSERV-0140 |
|
666 |
|
667 |
|
668 @SYMDEF DEF081259 |
|
669 |
|
670 @SYMTestCaseDesc Normal key capture test |
|
671 |
|
672 @SYMTestPriority High |
|
673 |
|
674 @SYMTestStatus Implemented |
|
675 |
|
676 @SYMTestActions The test uses 3 wserv clients with their own window groups. The |
|
677 clients are registered for different keys to capture. The test |
|
678 simulates key presses. |
|
679 |
|
680 @SYMTestExpectedResults Checks that the key presses are captured correctly . |
|
681 */ |
|
682 case 0: // Dummy one to let capture key tests run |
|
683 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0140")); |
|
684 iTest->LogSubTest(Test0); |
|
685 iState++; |
|
686 SendEvents(); |
|
687 break; |
|
688 /** |
|
689 @SYMTestCaseID GRAPHICS-WSERV-0141 |
|
690 |
|
691 @SYMDEF DEF081259 |
|
692 |
|
693 @SYMTestCaseDesc Normal key capture test with priorities |
|
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 and with |
|
701 different priorities. The test simulates key presses. |
|
702 |
|
703 @SYMTestExpectedResults Checks that the key presses are captured correctly . |
|
704 */ |
|
705 case 1: |
|
706 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0141")); |
|
707 iTest->LogSubTest(TestNormalCaptureWithPriority); |
|
708 CaptureWithPriorityTest(); |
|
709 iState++; |
|
710 SendEvents(); |
|
711 break; |
|
712 /** |
|
713 @SYMTestCaseID GRAPHICS-WSERV-0142 |
|
714 |
|
715 @SYMDEF DEF081259 |
|
716 |
|
717 @SYMTestCaseDesc Up-down key capture test |
|
718 |
|
719 @SYMTestPriority High |
|
720 |
|
721 @SYMTestStatus Implemented |
|
722 |
|
723 @SYMTestActions The test uses 3 wserv clients with their own window groups. The |
|
724 clients are registered for different keys to capture their |
|
725 up and down events. The test simulates key presses and releases. |
|
726 |
|
727 @SYMTestExpectedResults Checks that the key presses and releases are captured correctly . |
|
728 */ |
|
729 case 2: |
|
730 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0142")); |
|
731 iTest->LogSubTest(TestUpDown); |
|
732 CaptureUpsAndDownsTest(); |
|
733 iState++; |
|
734 SendEvents(); |
|
735 break; |
|
736 /** |
|
737 @SYMTestCaseID GRAPHICS-WSERV-0143 |
|
738 |
|
739 @SYMDEF DEF081259 |
|
740 |
|
741 @SYMTestCaseDesc Up-down key capture test with priorities |
|
742 |
|
743 @SYMTestPriority High |
|
744 |
|
745 @SYMTestStatus Implemented |
|
746 |
|
747 @SYMTestActions The test uses 3 wserv clients with their own window groups. The |
|
748 clients are registered with different priorities for different keys to capture their |
|
749 up and down events. The test simulates key presses and releases. |
|
750 |
|
751 @SYMTestExpectedResults Checks that the key presses and releases are captured correctly . |
|
752 */ |
|
753 case 3: |
|
754 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0143")); |
|
755 iTest->LogSubTest(TestUpDownWithPriority); |
|
756 CaptureUpsAndDownsWithPriorityTest(); |
|
757 iState++; |
|
758 SendEvents(); |
|
759 break; |
|
760 /** |
|
761 @SYMTestCaseID GRAPHICS-WSERV-0144 |
|
762 |
|
763 @SYMDEF DEF081259 |
|
764 |
|
765 @SYMTestCaseDesc Priority key events test |
|
766 |
|
767 @SYMTestPriority High |
|
768 |
|
769 @SYMTestStatus Implemented |
|
770 |
|
771 @SYMTestActions The test simulates key events and make sure that the events are |
|
772 recieved by the registered wserv client. |
|
773 |
|
774 @SYMTestExpectedResults Makes sure that key code is the same as a key simulated, event modifiers comply |
|
775 with registered priority key's modifirs and mask, and that event handle |
|
776 is a window group of the session. |
|
777 |
|
778 */ |
|
779 case 4: |
|
780 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0144")); |
|
781 if (iSubState==numCapKeyTests+numUpDownKeyWithPriorityTests+numUpDownKeyTests+numUpDownKeyWithPriorityTests) |
|
782 { |
|
783 iTest->LogSubTest(TestAbort); |
|
784 SetUpPriorityKeyTest(); |
|
785 } |
|
786 else |
|
787 iTest->LogSubTest(TestAbort2); |
|
788 //iState++; |
|
789 SendEvents(); |
|
790 TheClient->WaitUntilEventPending(); |
|
791 break; |
|
792 /** |
|
793 @SYMTestCaseID GRAPHICS-WSERV-0145 |
|
794 |
|
795 @SYMDEF DEF081259 |
|
796 |
|
797 @SYMTestCaseDesc Invalid capture keys test |
|
798 |
|
799 @SYMTestPriority High |
|
800 |
|
801 @SYMTestStatus Implemented |
|
802 |
|
803 @SYMTestActions Memorizes amount of objects that the server has allocated for that client. |
|
804 Tries to register 3 different capture keys with invalid |
|
805 modifiers and modifirs mask pair. |
|
806 |
|
807 @SYMTestExpectedResults Makes sure that the number of server-side objects for the |
|
808 session didn't change. |
|
809 */ |
|
810 case 5: |
|
811 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0145")); |
|
812 iTest->LogSubTest(TestErrors); |
|
813 BadParams(); |
|
814 ((CTCaptureKeyStep*)iStep)->RecordTestResultL(); |
|
815 /** |
|
816 @SYMTestCaseID GRAPHICS-WSERV-0146 |
|
817 |
|
818 @SYMDEF DEF081259 |
|
819 |
|
820 @SYMTestCaseDesc Capture keys clean up 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 Creates a window group and requests two keys to be captured. |
|
828 Cancels one key capture request and closes the window group. |
|
829 |
|
830 @SYMTestExpectedResults Checks that creation of the group or registering a capture key |
|
831 increased this amount by 1 each time. |
|
832 Makes sure that the number of server-side objects for the |
|
833 session in the end of the test is the same as in the beginning. |
|
834 */ |
|
835 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0146")); |
|
836 iTest->LogSubTest(TestCaptureKey); |
|
837 CapKeyPurgingL(); |
|
838 iState++; |
|
839 break; |
|
840 /** |
|
841 @SYMTestCaseID GRAPHICS-WSERV-0147 |
|
842 |
|
843 @SYMDEF DEF081259 |
|
844 |
|
845 @SYMTestCaseDesc Capture power off key test |
|
846 |
|
847 @SYMTestPriority High |
|
848 |
|
849 @SYMTestStatus Implemented |
|
850 |
|
851 @SYMTestActions The test creates a new session, new window group and a new window |
|
852 in the group. After that the test gives "Hello" name to the group |
|
853 and tries to register for key capture of FN+EKeyDevice2 and 0xF844 |
|
854 buttons. Makes sure that registration fails due to KErrPermissionDenied |
|
855 error. |
|
856 Then the test changes the name of the window group to "SysApp" |
|
857 and tries the registration again. Makes sure that operation |
|
858 completed successfully. |
|
859 |
|
860 @SYMTestExpectedResults See actions |
|
861 */ |
|
862 case 6: |
|
863 ((CTCaptureKeyStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-0147")); |
|
864 iTest->LogSubTest(TestCapturePowerOffKey); |
|
865 CapKeyPowerOffL(); |
|
866 iState++; |
|
867 break; |
|
868 default: |
|
869 ((CTCaptureKeyStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName); |
|
870 TestComplete(); |
|
871 } |
|
872 ((CTCaptureKeyStep*)iStep)->RecordTestResultL(); |
|
873 |
|
874 } |
|
875 |
|
876 |
|
877 __WS_CONSTRUCT_STEP__(CaptureKey) |