|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <e32base.h> |
|
24 #include <gdi.h> |
|
25 #include <w32std.h> |
|
26 #include <coemain.h> |
|
27 #include <coeaui.h> |
|
28 #include <coecntrl.h> |
|
29 #include <coeinput.h> |
|
30 #include <e32math.h> |
|
31 #include <eikenv.h> |
|
32 |
|
33 #include "KEYBOARDLOGGER.H" |
|
34 |
|
35 |
|
36 //Timer dealy after which event is requested.\n |
|
37 const TInt KClearerDelay(1000000); |
|
38 |
|
39 enum |
|
40 { |
|
41 EGapLeftOfEachLine =10, |
|
42 EGapAboveTopLine =1, |
|
43 EGapBetweenEachLine =3, |
|
44 EGapBelowBottomLine =3 |
|
45 }; |
|
46 |
|
47 //String literal to represent the name of the typeface used.\n |
|
48 _LIT(KLitFontTypefaceName, "publicDomainUnicode"); |
|
49 |
|
50 |
|
51 #if defined(_DEBUG) |
|
52 |
|
53 _LIT(KLitKEYBOARDLOGGER, "KEYBOARDLOGGER"); |
|
54 |
|
55 enum TPanic |
|
56 { |
|
57 EPanicBadHeight=1 |
|
58 }; |
|
59 |
|
60 LOCAL_C void Panic(TPanic aPanic) |
|
61 { |
|
62 User::Panic(KLitKEYBOARDLOGGER, aPanic); |
|
63 } |
|
64 |
|
65 #endif |
|
66 |
|
67 |
|
68 /************************************************************* |
|
69 ** |
|
70 ** TTstOverflowIgnorer |
|
71 ** |
|
72 *************************************************************/ |
|
73 |
|
74 void TTstOverflowIgnorer::Overflow(TDes16&) |
|
75 { |
|
76 } |
|
77 |
|
78 |
|
79 /************************************************************* |
|
80 ** |
|
81 ** CTstControl |
|
82 ** |
|
83 *************************************************************/ |
|
84 |
|
85 CTstControl* CTstControl::NewL() |
|
86 { |
|
87 CTstControl* const control=new(ELeave) CTstControl; |
|
88 CleanupStack::PushL(control); |
|
89 control->ConstructL(); |
|
90 CleanupStack::Pop(control); |
|
91 return control; |
|
92 } |
|
93 |
|
94 CTstControl::~CTstControl() |
|
95 { |
|
96 iCoeEnv->ReleaseScreenFont(iFont); |
|
97 iArrayOfKeyDownEvents.Close(); |
|
98 iArrayOfKeyEvents.Close(); |
|
99 iArrayOfKeyUpEvents.Close(); |
|
100 delete iClearer; |
|
101 } |
|
102 |
|
103 CTstControl::CTstControl() |
|
104 :iFont(NULL), |
|
105 iArrayOfKeyDownEvents(2), |
|
106 iArrayOfKeyEvents(2), |
|
107 iArrayOfKeyUpEvents(2), |
|
108 iClearer(NULL) |
|
109 { |
|
110 } |
|
111 |
|
112 /** |
|
113 Create a control window \n Enable to receive pointer drag and move events.\n |
|
114 Ensures that all subsequent pointer events are delivered \n |
|
115 Gets the control's associated drawable window and set its shadow height\n |
|
116 Create a font for the device.\n Set the screen size and font height \n |
|
117 Set controls extent with size and position and set the control readt to be drawn \n |
|
118 */ |
|
119 void CTstControl::ConstructL() |
|
120 { |
|
121 CreateWindowL(); |
|
122 EnableDragEvents(); |
|
123 ClaimPointerGrab(); |
|
124 DrawableWindow()->SetShadowHeight(3); |
|
125 iFont=iCoeEnv->CreateScreenFontL(TFontSpec(KLitFontTypefaceName, 200)); |
|
126 iClearer=CClearer::NewL(*this); |
|
127 const TSize screenSize(iCoeEnv->ScreenDevice()->SizeInPixels()); |
|
128 const TInt fontHeightInPixels=iFont->HeightInPixels(); |
|
129 SetExtent(TPoint(10, 10), TSize(screenSize.iWidth-(10*2), 1+EGapAboveTopLine+(2*(fontHeightInPixels+EGapBetweenEachLine))+fontHeightInPixels+EGapBelowBottomLine+1)); |
|
130 ActivateL(); |
|
131 } |
|
132 |
|
133 /** |
|
134 @return - Event handling flag.(EKeyWasConsumed)\n |
|
135 The control handles the key events\n |
|
136 Draw the control\n |
|
137 When a key event occurs, the control framework calls this function for each control on the control stack,\n |
|
138 until one of them can process the key event.\n |
|
139 */ |
|
140 TKeyResponse CTstControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aEventCode) |
|
141 { |
|
142 iClearer->Cancel(); |
|
143 iClearer->After(TTimeIntervalMicroSeconds32(KClearerDelay)); |
|
144 |
|
145 switch (aEventCode) |
|
146 { |
|
147 case EEventKeyDown: |
|
148 User::LeaveIfError(iArrayOfKeyDownEvents.Append(aKeyEvent)); |
|
149 break; |
|
150 case EEventKey: |
|
151 if (aKeyEvent.iCode==EKeyEscape) |
|
152 { |
|
153 CBaActiveScheduler::Exit(); |
|
154 return EKeyWasConsumed; |
|
155 } |
|
156 User::LeaveIfError(iArrayOfKeyEvents.Append(aKeyEvent)); |
|
157 break; |
|
158 case EEventKeyUp: |
|
159 User::LeaveIfError(iArrayOfKeyUpEvents.Append(aKeyEvent)); |
|
160 break; |
|
161 default: |
|
162 __DEBUGGER(); |
|
163 break; |
|
164 } |
|
165 |
|
166 DrawNow(); |
|
167 return EKeyWasConsumed; |
|
168 } |
|
169 |
|
170 /** |
|
171 Auxiliary Function for Test Case ID TestKeyBoardLoggerUi-RunTestStepL.\n |
|
172 Return the capability that indicated support for all types of text.\n |
|
173 */ |
|
174 TCoeInputCapabilities CTstControl::InputCapabilities() const |
|
175 { |
|
176 return TCoeInputCapabilities(TCoeInputCapabilities::EAllText); |
|
177 } |
|
178 |
|
179 /** |
|
180 The screen appearance of control is changed by overriding the method Draw().\n |
|
181 By default, this draws a border of the appropriate type around the control. |
|
182 */ |
|
183 void CTstControl::Draw(const TRect&) const |
|
184 { |
|
185 CWindowGc& graphicsContext=SystemGc(); |
|
186 graphicsContext.SetPenStyle(CGraphicsContext::ESolidPen); |
|
187 graphicsContext.SetPenColor(KRgbBlack); |
|
188 graphicsContext.SetBrushStyle(CGraphicsContext::ENullBrush); |
|
189 TRect rectangle(Rect()); |
|
190 graphicsContext.DrawRect(rectangle); |
|
191 rectangle.Shrink(1, 1); |
|
192 graphicsContext.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
193 TRect temp(rectangle); |
|
194 temp.iBr.iY=temp.iTl.iY; |
|
195 const TInt fontHeightInPixels=iFont->HeightInPixels(); |
|
196 const TInt fontAscentInPixels=iFont->AscentInPixels(); |
|
197 graphicsContext.SetBrushColor(KRgbGray); |
|
198 graphicsContext.UseFont(iFont); |
|
199 TBuf<200> textToDisplay; |
|
200 TTstOverflowIgnorer overflowIgnorer; |
|
201 TInt i; |
|
202 TInt n; |
|
203 n=iArrayOfKeyDownEvents.Count(); |
|
204 textToDisplay.Format(_L("Key-down events (%d): "), n); |
|
205 for (i=0; i<n; ++i) |
|
206 { |
|
207 textToDisplay.AppendFormat(_L("0x%x "), &overflowIgnorer, iArrayOfKeyDownEvents[i].iScanCode); |
|
208 } |
|
209 temp.iTl.iY=temp.iBr.iY; |
|
210 temp.iBr.iY+=EGapAboveTopLine+fontHeightInPixels+EGapBetweenEachLine; |
|
211 graphicsContext.DrawText(textToDisplay, temp, EGapAboveTopLine+fontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine); |
|
212 n=iArrayOfKeyEvents.Count(); |
|
213 textToDisplay.Format(_L("Key events (%d): "), n); |
|
214 for (i=0; i<n; ++i) |
|
215 { |
|
216 textToDisplay.AppendFormat(_L("[0x%x,%c] "), &overflowIgnorer, iArrayOfKeyEvents[i].iScanCode, iArrayOfKeyEvents[i].iCode); |
|
217 } |
|
218 temp.iTl.iY=temp.iBr.iY; |
|
219 temp.iBr.iY+=fontHeightInPixels+EGapBetweenEachLine; |
|
220 graphicsContext.DrawText(textToDisplay, temp, fontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine); |
|
221 n=iArrayOfKeyUpEvents.Count(); |
|
222 textToDisplay.Format(_L("Key-up events (%d): "), n); |
|
223 for (i=0; i<n; ++i) |
|
224 { |
|
225 textToDisplay.AppendFormat(_L("0x%x "), &overflowIgnorer, iArrayOfKeyUpEvents[i].iScanCode); |
|
226 } |
|
227 temp.iTl.iY=temp.iBr.iY; |
|
228 temp.iBr.iY=rectangle.iBr.iY; |
|
229 __ASSERT_DEBUG(temp.iBr.iY==temp.iTl.iY+fontHeightInPixels+EGapBelowBottomLine, Panic(EPanicBadHeight)); |
|
230 graphicsContext.DrawText(textToDisplay, temp, fontAscentInPixels, CGraphicsContext::ELeft, EGapLeftOfEachLine); |
|
231 graphicsContext.DiscardFont(); |
|
232 } |
|
233 |
|
234 |
|
235 // CTstControl::CClearer |
|
236 |
|
237 CTstControl::CClearer* CTstControl::CClearer::NewL(CTstControl& aControl) |
|
238 { |
|
239 CClearer* clearer=new(ELeave) CClearer(aControl); |
|
240 CleanupStack::PushL(clearer); |
|
241 clearer->ConstructL(); |
|
242 CleanupStack::Pop(clearer); |
|
243 return clearer; |
|
244 } |
|
245 |
|
246 CTstControl::CClearer::CClearer(CTstControl& aControl) |
|
247 :CTimer(EActivePriorityDefault), |
|
248 iControl(aControl) |
|
249 { |
|
250 CActiveScheduler::Add(this); |
|
251 } |
|
252 |
|
253 /** |
|
254 The function is called by the active scheduler when a request completion event occurs. \n |
|
255 Reset the events to default and call the DrawNow()\n |
|
256 */ |
|
257 void CTstControl::CClearer::RunL() |
|
258 { |
|
259 iControl.iArrayOfKeyDownEvents.Reset(); |
|
260 iControl.iArrayOfKeyEvents.Reset(); |
|
261 iControl.iArrayOfKeyUpEvents.Reset(); |
|
262 iControl.DrawNow(); |
|
263 } |
|
264 |
|
265 |
|
266 /************************************************************* |
|
267 ** |
|
268 ** CTestKeyBoardLoggerUi |
|
269 ** |
|
270 *************************************************************/ |
|
271 |
|
272 CTestKeyBoardLoggerUi::~CTestKeyBoardLoggerUi() |
|
273 { |
|
274 if(iControl) |
|
275 { |
|
276 RemoveFromStack(iControl); |
|
277 } |
|
278 delete iControl; |
|
279 } |
|
280 |
|
281 /** |
|
282 Call ConstructL() of CTestAppUi \n |
|
283 Initialize the CTstControl object \nCall ConstructL of CTstControl \n |
|
284 Install the FEP\n |
|
285 */ |
|
286 void CTestKeyBoardLoggerUi::ConstructL() |
|
287 { |
|
288 CTestAppUi::ConstructL(); |
|
289 iControl= new (ELeave) CTstControl; |
|
290 AddToStackL(iControl,ECoeStackPriorityDialog); |
|
291 iControl->ConstructL(); |
|
292 |
|
293 const TUid KUidTFep1 = { 0x102024D0 }; |
|
294 iCoeEnv->InstallFepL(KUidTFep1); |
|
295 |
|
296 AutoTestManager().StartAutoTest(); |
|
297 } |
|
298 |
|
299 |
|
300 |
|
301 /** |
|
302 @SYMTestCaseID UIF-FEPTEST-0002 |
|
303 @SYMPREQ 0000 |
|
304 @SYMTestCaseDesc Launch the application and offer events. |
|
305 @SYMTestPriority High |
|
306 @SYMTestStatus Implemented |
|
307 @SYMTestActions Launch an application and load the FEP. |
|
308 Create character codes that represent the Key events, Key up and down events. |
|
309 Offer these Key events to the application. |
|
310 The FEP intercepts these events and gets displayed on the application view. |
|
311 @SYMTestExpectedResults Failure in FEP will cause crashing of the application |
|
312 */ |
|
313 void CTestKeyBoardLoggerUi::RunTestStepL(TInt aNumStep) |
|
314 { |
|
315 TWsEvent theEvent; |
|
316 TKeyEvent *theKey = theEvent.Key(); |
|
317 |
|
318 switch(aNumStep) |
|
319 { |
|
320 case 1: |
|
321 SetTestStepID(_L("UIF-FEPTEST-0002")); |
|
322 case 2: case 4: case 5: |
|
323 { |
|
324 theKey->iScanCode = 0; |
|
325 theKey->iModifiers= 0; |
|
326 theKey->iRepeats=0; |
|
327 theKey->iCode = 'A' + aNumStep - 1; |
|
328 |
|
329 SendEventToWindowGroups(theEvent); |
|
330 INFO_PRINTF2(_L("Simulate Key Event with code %d"), theKey->iCode); |
|
331 } |
|
332 break; |
|
333 |
|
334 case 3: case 6: |
|
335 { |
|
336 |
|
337 theKey->iScanCode = 0; |
|
338 theKey->iModifiers= 0; |
|
339 theKey->iRepeats=0; |
|
340 theKey->iCode = EKeyEnter; |
|
341 |
|
342 INFO_PRINTF1(_L("Simulate Key Enter Event")); |
|
343 SendEventToWindowGroups(theEvent); |
|
344 } |
|
345 break; |
|
346 |
|
347 case 7: case 8: |
|
348 { |
|
349 |
|
350 theKey->iScanCode = EKeyTab; |
|
351 theKey->iModifiers= 0; |
|
352 theKey->iRepeats=0; |
|
353 theKey->iCode = EKeyTab; |
|
354 |
|
355 INFO_PRINTF1(_L("Move to next editor")); |
|
356 SendEventToWindowGroups(theEvent); |
|
357 } |
|
358 break; |
|
359 |
|
360 case 9: |
|
361 iCoeEnv->InstallFepL(KNullUid); |
|
362 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
363 RecordTestResultL(); |
|
364 CloseTMSGraphicsStep(); |
|
365 break; |
|
366 } |
|
367 } |
|
368 |
|
369 /** |
|
370 Handle the window events.\n |
|
371 Create a window server session and connect the client\n |
|
372 Set the event type and call the SendEventToWindowGroup().\n |
|
373 Close the session on completion \n |
|
374 */ |
|
375 void CTestKeyBoardLoggerUi::SendEventToWindowGroups(TWsEvent& aEvent) |
|
376 { |
|
377 RWsSession ws; |
|
378 TInt theRes = ws.Connect(); |
|
379 TEST(theRes == KErrNone); |
|
380 |
|
381 RWindowGroup& winGroup = iCoeEnv->RootWin(); |
|
382 TInt theId = winGroup.Identifier(); |
|
383 |
|
384 aEvent.SetType(EEventKeyDown); |
|
385 aEvent.SetTimeNow(); |
|
386 ws.SendEventToWindowGroup(theId, aEvent); |
|
387 |
|
388 aEvent.SetType(EEventKey); |
|
389 aEvent.SetTimeNow(); |
|
390 ws.SendEventToWindowGroup(theId, aEvent); |
|
391 |
|
392 aEvent.SetType(EEventKeyUp); |
|
393 aEvent.SetTimeNow(); |
|
394 ws.SendEventToWindowGroup(theId, aEvent); |
|
395 |
|
396 ws.Close(); |
|
397 } |
|
398 |
|
399 |
|
400 /************************************************************* |
|
401 ** |
|
402 ** CTestKeyboardLoggerStep |
|
403 ** |
|
404 *************************************************************/ |
|
405 |
|
406 CTestKeyboardLoggerStep::CTestKeyboardLoggerStep() |
|
407 { |
|
408 SetTestStepName(KKeyboardLoggerStep); |
|
409 } |
|
410 |
|
411 CTestKeyboardLoggerStep::~CTestKeyboardLoggerStep() |
|
412 { |
|
413 } |
|
414 |
|
415 void CTestKeyboardLoggerStep::ConstructAppL(CEikonEnv* aCoe) |
|
416 { // runs inside a TRAP harness |
|
417 aCoe->ConstructL(); |
|
418 |
|
419 CTestAppUi* appUi= new (ELeave) CTestKeyBoardLoggerUi(this); |
|
420 aCoe->SetAppUi(appUi); |
|
421 appUi->ConstructL(); |
|
422 } |
|
423 |
|
424 TVerdict CTestKeyboardLoggerStep::doTestStepL() |
|
425 { |
|
426 PreallocateHALBuffer(); |
|
427 |
|
428 INFO_PRINTF1(_L("TestKeyboardLoggerStep started...")); |
|
429 |
|
430 __UHEAP_MARK; |
|
431 |
|
432 CEikonEnv* coe=new(ELeave) CEikonEnv; |
|
433 TRAPD(err,ConstructAppL(coe)); |
|
434 |
|
435 if (!err) |
|
436 coe->ExecuteD(); |
|
437 else |
|
438 { |
|
439 delete coe; |
|
440 SetTestStepResult(EFail); |
|
441 } |
|
442 |
|
443 __UHEAP_MARKEND; |
|
444 |
|
445 INFO_PRINTF1(_L("...TestKeyboardLoggerStep finished!")); |
|
446 |
|
447 return TestStepResult(); |
|
448 } |