|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Emulate key and pointer event. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikon.hrh> |
|
20 |
|
21 #include "AutotestCommands.h" // test commands are defined in here |
|
22 #include "bctestkeyfeeder.h" |
|
23 #include "bctestlogger.h" |
|
24 #include "bctestsuite.h" |
|
25 |
|
26 const TInt KInitDelay = 1000000; // 1 second |
|
27 const TInt KInterval = 100000; // 1/10 second |
|
28 const TInt KTickCount = 10; // default one second between key feeds |
|
29 const TText KKey1 = '1'; |
|
30 const TText KKey2 = '2'; |
|
31 const TText KKey3 = '3'; |
|
32 const TText KKey4 = '4'; |
|
33 const TText KKey5 = '5'; |
|
34 const TText KKey6 = '6'; |
|
35 const TText KKey7 = '7'; |
|
36 const TText KKey8 = '8'; |
|
37 const TText KKey9 = '9'; |
|
38 const TText KKey0 = '0'; |
|
39 const TText KKeyAsterisk = '*'; |
|
40 const TText KKeyHash = '#'; |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS ============================= |
|
43 |
|
44 // --------------------------------------------------------------------------- |
|
45 // C++ default constructor |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CBCTestKeyFeeder::CBCTestKeyFeeder() |
|
49 { |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // Destructor |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CBCTestKeyFeeder::~CBCTestKeyFeeder() |
|
57 { |
|
58 if ( iPeriodic ) |
|
59 { |
|
60 iPeriodic->Cancel(); |
|
61 delete iPeriodic; |
|
62 } |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CBCTestKeyFeeder::StartAutoTestL |
|
67 // Initialize member variables and start timer. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void CBCTestKeyFeeder::StartAutoTestL( SAutoTest* aAutoTest ) |
|
71 { |
|
72 if ( aAutoTest ) |
|
73 { |
|
74 iAutoTest = aAutoTest; |
|
75 iScriptCommands = iAutoTest->scripts[0]; |
|
76 } |
|
77 if ( !iAutoTest || !iScriptCommands ) |
|
78 { |
|
79 return; |
|
80 } |
|
81 |
|
82 iSuite->HandleTestEventL( ETestCaseStart, iScriptIndex ); |
|
83 |
|
84 if ( iPeriodic ) |
|
85 { |
|
86 iPeriodic->Cancel(); |
|
87 delete iPeriodic; |
|
88 iPeriodic = NULL; |
|
89 } |
|
90 iPeriodic=CPeriodic::NewL( CActive::EPriorityHigh ); |
|
91 // Start periodic function after 1 seconds and after that call |
|
92 // it every 1/10th of second |
|
93 iPeriodic->Start( KInitDelay, KInterval, TCallBack( |
|
94 PeriodicKeyFeederL, this ) ); |
|
95 |
|
96 // member variables don't need to be cleared before use, |
|
97 // but do it anyway - just in case |
|
98 iIndex = 0; |
|
99 iScriptIndex = 0; |
|
100 iCommand = 0; |
|
101 iRepeatCommand = 0; |
|
102 iRepeat = 0; |
|
103 iWaitCount = 0; |
|
104 |
|
105 iTickCount = KTickCount; |
|
106 iTickCounter = iTickCount; |
|
107 |
|
108 iKeyUp = EFalse; |
|
109 iKeyDown = EFalse; |
|
110 |
|
111 // ensure sane values for conditional stuff |
|
112 iIfCount = 0; |
|
113 |
|
114 if ( !iEikEnv ) |
|
115 { |
|
116 iEikEnv = CEikonEnv::Static(); |
|
117 } |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // CBCTestKeyFeeder::PeriodicKeyFeeder |
|
122 // This method is called every 0.1 seconds, calls HandleAutoCommand |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 TInt CBCTestKeyFeeder::PeriodicKeyFeederL( TAny* aThis ) |
|
126 { |
|
127 CBCTestKeyFeeder* feeder = |
|
128 static_cast<CBCTestKeyFeeder*>( aThis ); |
|
129 |
|
130 feeder->HandleAutoCommandL(); |
|
131 return 0; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CBCTestKeyFeeder::HandleAutoCommand |
|
136 // Does the actual key feeding |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CBCTestKeyFeeder::HandleAutoCommandL() |
|
140 { |
|
141 if ( iTimerPaused ) // timer paused, do nothing |
|
142 { |
|
143 return; |
|
144 } |
|
145 if ( iTickCounter > 0 ) |
|
146 { |
|
147 iTickCounter--; |
|
148 return; // tick count not yet full, do nothing |
|
149 } |
|
150 iTickCounter=iTickCount; // reset tick counter and continue |
|
151 |
|
152 //commands in one script done |
|
153 if ( iIndex >= iAutoTest->countArray[iScriptIndex] ) |
|
154 { |
|
155 iSuite->HandleTestEventL( ETestCaseEnd, iScriptIndex ); |
|
156 iScriptIndex++; |
|
157 TBool continueRun = ETrue; |
|
158 if ( iScriptIndex >= iAutoTest->scriptCount ) // all scripts done |
|
159 { |
|
160 continueRun = EFalse; |
|
161 } |
|
162 else |
|
163 { |
|
164 iScriptCommands = iAutoTest->scripts[iScriptIndex]; |
|
165 iIndex = 0; |
|
166 if ( !iScriptCommands ) |
|
167 { |
|
168 iSuite->HandleTestEventL( ETestCaseNoScript, iScriptIndex ); |
|
169 iIndex = iAutoTest->countArray[iScriptIndex]; |
|
170 } |
|
171 else |
|
172 { |
|
173 iSuite->HandleTestEventL( ETestCaseStart, iScriptIndex ); |
|
174 } |
|
175 } |
|
176 |
|
177 if ( iIfCount != 0 ) |
|
178 { |
|
179 iSuite->HandleTestEventL( |
|
180 ETestCaseUnbalancedIf, iScriptIndex - 1 ); |
|
181 iIfCount = 0; |
|
182 } |
|
183 |
|
184 if ( !continueRun ) |
|
185 { |
|
186 iPeriodic->Cancel(); // stop periodic timer |
|
187 } |
|
188 |
|
189 return; |
|
190 } |
|
191 |
|
192 if ( iWaitCount > 0 ) // still waiting (WAIT command) |
|
193 { |
|
194 iWaitCount--; |
|
195 return; // waiting - do nothing |
|
196 } |
|
197 |
|
198 if ( iRepeat == 0 ) // not repeating, parse next command |
|
199 { |
|
200 iCommand = iScriptCommands[iIndex]; |
|
201 iIndex++; |
|
202 } |
|
203 else // still doing REPEAT |
|
204 { |
|
205 iCommand = iRepeatCommand; // command being repeated |
|
206 iRepeat--; |
|
207 } |
|
208 |
|
209 switch ( iCommand ) |
|
210 { |
|
211 case LeftCBA: |
|
212 KeyPress( EKeyDevice0, EStdKeyDevice0 ); |
|
213 break; |
|
214 case RightCBA: |
|
215 KeyPress( EKeyDevice1, EStdKeyDevice1 ); |
|
216 break; |
|
217 case KeyOK: |
|
218 KeyPress( EKeyDevice3, EStdKeyDevice3 ); |
|
219 break; |
|
220 case Up: |
|
221 KeyPress( EKeyUpArrow, EStdKeyUpArrow ); |
|
222 break; |
|
223 case Down: |
|
224 KeyPress( EKeyDownArrow, EStdKeyDownArrow ); |
|
225 break; |
|
226 case Left: |
|
227 KeyPress( EKeyLeftArrow, EStdKeyLeftArrow ); |
|
228 break; |
|
229 case Right: |
|
230 KeyPress( EKeyRightArrow, EStdKeyRightArrow ); |
|
231 break; |
|
232 case Key1: |
|
233 KeyPress( KKey1, KKey1 ); |
|
234 break; |
|
235 case Key2: |
|
236 KeyPress( KKey2, KKey2 ); |
|
237 break; |
|
238 case Key3: |
|
239 KeyPress( KKey3, KKey3 ); |
|
240 break; |
|
241 case Key4: |
|
242 KeyPress( KKey4, KKey4 ); |
|
243 break; |
|
244 case Key5: |
|
245 KeyPress( KKey5, KKey5 ); |
|
246 break; |
|
247 case Key6: |
|
248 KeyPress( KKey6, KKey6 ); |
|
249 break; |
|
250 case Key7: |
|
251 KeyPress( KKey7, KKey7 ); |
|
252 break; |
|
253 case Key8: |
|
254 KeyPress( KKey8, KKey8 ); |
|
255 break; |
|
256 case Key9: |
|
257 KeyPress( KKey9, KKey9 ); |
|
258 break; |
|
259 case Key0: |
|
260 KeyPress( KKey0, KKey0 ); |
|
261 break; |
|
262 case KeyAsterisk: |
|
263 KeyPress( KKeyAsterisk, EStdKeyNkpAsterisk ); |
|
264 break; |
|
265 case KeyHash: |
|
266 KeyPress( KKeyHash, EStdKeyHash ); |
|
267 break; |
|
268 case KeyApplication: |
|
269 KeyPress( EKeyApplication, EStdKeyApplication0 ); |
|
270 break; |
|
271 case KeyPhoneSend: |
|
272 KeyPress( EKeyPhoneSend, EStdKeyYes ); |
|
273 break; |
|
274 case KeyPhoneEnd: |
|
275 KeyPress( EKeyPhoneEnd, EStdKeyNo ); |
|
276 break; |
|
277 case KeyPower: |
|
278 KeyPress( EKeyPowerOff, EStdKeyDevice2 ); |
|
279 break; |
|
280 case KeyVoice: |
|
281 KeyPress( EKeySide, EStdKeyDevice6 ); |
|
282 break; |
|
283 case KeyBackspace: |
|
284 KeyPress( EKeyBackspace, EStdKeyBackspace ); |
|
285 break; |
|
286 case KeyABC: // may not work as ABC key, should work as shift, tough |
|
287 KeyPress( EStdKeyRightShift, EStdKeyRightShift ); |
|
288 break; |
|
289 case GripOpen: |
|
290 KeyPress( EKeyGripOpen, EStdKeyDevice4 ); |
|
291 break; |
|
292 case GripClose: |
|
293 KeyPress( EKeyGripClose, EStdKeyDevice5 ); |
|
294 break; |
|
295 case REPEAT: // one round missed because no commands executed |
|
296 iRepeatCommand = iScriptCommands[iIndex++]; |
|
297 iRepeat = iScriptCommands[iIndex++]; |
|
298 break; |
|
299 case WAITCOMMAND: |
|
300 iWaitCount = iScriptCommands[iIndex++]; |
|
301 break; |
|
302 case SETTICKCOUNT: |
|
303 iTickCount = iScriptCommands[iIndex++]; |
|
304 iTickCounter = iTickCount; |
|
305 break; |
|
306 case JUSTKEYDOWN: |
|
307 iKeyDown = ETrue; |
|
308 break; |
|
309 case JUSTKEYUP: |
|
310 iKeyUp = ETrue; |
|
311 break; |
|
312 case PointerDown: |
|
313 { |
|
314 TInt pointerX = iScriptCommands[iIndex++]; |
|
315 TInt pointerY = iScriptCommands[iIndex++]; |
|
316 TRawEvent event; |
|
317 event.Set( TRawEvent::EButton1Down, pointerX, pointerY ); |
|
318 PointerEvent( event ); |
|
319 } |
|
320 break; |
|
321 case PointerUp: |
|
322 { |
|
323 TInt pointerX = iScriptCommands[iIndex++]; |
|
324 TInt pointerY = iScriptCommands[iIndex++]; |
|
325 TRawEvent event; |
|
326 event.Set( TRawEvent::EButton1Up, pointerX, pointerY ); |
|
327 PointerEvent( event ); |
|
328 } |
|
329 break; |
|
330 case PointerMove: |
|
331 { |
|
332 TInt pointerX = iScriptCommands[iIndex++]; |
|
333 TInt pointerY = iScriptCommands[iIndex++]; |
|
334 TRawEvent event; |
|
335 event.Set( TRawEvent::EPointerMove, pointerX, pointerY ); |
|
336 PointerEvent( event ); |
|
337 break; |
|
338 } |
|
339 default: |
|
340 break; |
|
341 } |
|
342 } |
|
343 |
|
344 /******************* autotest key feeder implementations ********************/ |
|
345 |
|
346 // --------------------------------------------------------------------------- |
|
347 // CBCTestKeyFeeder::KeyDown |
|
348 // --------------------------------------------------------------------------- |
|
349 // |
|
350 void CBCTestKeyFeeder::KeyDown( TInt aScanCode ) |
|
351 { |
|
352 if ( aScanCode == EStdKeyRightShift ) |
|
353 { |
|
354 iOldModifiers = iEikEnv->WsSession().GetModifierState(); |
|
355 iModifiers = EModifierShift | iOldModifiers; |
|
356 } |
|
357 |
|
358 TRawEvent event; |
|
359 event.Set( TRawEvent::EKeyDown, aScanCode ); |
|
360 iEikEnv->WsSession().SimulateRawEvent( event ); |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // CBCTestKeyFeeder::KeyUp |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 void CBCTestKeyFeeder::KeyUp( TInt aScanCode ) |
|
368 { |
|
369 if ( aScanCode == EStdKeyRightShift ) |
|
370 { |
|
371 iModifiers = iOldModifiers; |
|
372 } |
|
373 |
|
374 TRawEvent event; |
|
375 event.Set( TRawEvent::EKeyUp, aScanCode ); |
|
376 iEikEnv->WsSession().SimulateRawEvent( event ); |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------------------------- |
|
380 // CBCTestKeyFeeder::KeyPress |
|
381 // --------------------------------------------------------------------------- |
|
382 // |
|
383 void CBCTestKeyFeeder::KeyPress( TInt aCode, TInt aScanCode ) |
|
384 { |
|
385 User::ResetInactivityTime();// Reset user inactivity timers |
|
386 |
|
387 if ( iKeyDown ) // Long key press -> do just key down |
|
388 { |
|
389 KeyDown( aScanCode ); |
|
390 iKeyDown = EFalse; |
|
391 return; // ends key press |
|
392 } |
|
393 |
|
394 if ( iKeyUp ) // Ends long key press -> do just key up |
|
395 { |
|
396 KeyUp( aScanCode ); |
|
397 iKeyUp = EFalse; |
|
398 return; // ends key press |
|
399 } |
|
400 |
|
401 // there seems to be no keycode for abc-key, simulate by pressing |
|
402 // key down and up |
|
403 if ( aCode == EStdKeyRightShift ) |
|
404 { |
|
405 KeyDown( aCode ); |
|
406 KeyUp( aCode ); |
|
407 return; |
|
408 } |
|
409 |
|
410 // Do normal key press |
|
411 TKeyEvent event = { aCode, aScanCode, iModifiers, 0 }; |
|
412 iEikEnv->WsSession().SimulateKeyEvent( event ); |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------------------------- |
|
416 // CBCTestKeyFeeder::PauseTimer |
|
417 // --------------------------------------------------------------------------- |
|
418 // |
|
419 void CBCTestKeyFeeder::PauseTimer() |
|
420 { |
|
421 iTimerPaused = ETrue; |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // CBCTestKeyFeeder::ResumeTimer |
|
426 // --------------------------------------------------------------------------- |
|
427 // |
|
428 void CBCTestKeyFeeder::ResumeTimer() |
|
429 { |
|
430 iTimerPaused = EFalse; |
|
431 } |
|
432 |
|
433 // --------------------------------------------------------------------------- |
|
434 // CBCTestKeyFeeder::PointerEvent |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 void CBCTestKeyFeeder::PointerEvent( TRawEvent& aEvent ) |
|
438 { |
|
439 iEikEnv->WsSession().SimulateRawEvent( aEvent ); |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------------------------- |
|
443 // CBCTestKeyFeeder::SetSuite |
|
444 // --------------------------------------------------------------------------- |
|
445 // |
|
446 void CBCTestKeyFeeder::SetSuite( CBCTestSuite* aSuite ) |
|
447 { |
|
448 iSuite = aSuite; |
|
449 } |