1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "T_DataWsEvent.h" |
|
19 #include "T_GraphicsUtil.h" |
|
20 |
|
21 /*@{*/ |
|
22 /// Commands |
|
23 _LIT(KCmdnew, "new"); |
|
24 _LIT(KCmdDestructor, "~"); |
|
25 _LIT(KCmdErrorMessage, "ErrorMessage"); |
|
26 _LIT(KCmdEventData, "EventData"); |
|
27 _LIT(KCmdHandle, "Handle"); |
|
28 _LIT(KCmdInt, "Int"); |
|
29 _LIT(KCmdKey, "Key"); |
|
30 _LIT(KCmdModifiersChanged, "ModifiersChanged"); |
|
31 _LIT(KCmdPointer, "Pointer"); |
|
32 _LIT(KCmdSetHandle, "SetHandle"); |
|
33 _LIT(KCmdSetTimeNow, "SetTimeNow"); |
|
34 _LIT(KCmdSetType, "SetType"); |
|
35 _LIT(KCmdTime, "Time"); |
|
36 _LIT(KCmdType, "Type"); |
|
37 _LIT(KCmdVisibilityChanged, "VisibilityChanged"); |
|
38 |
|
39 /// Fields |
|
40 _LIT(KFldExpected, "expected"); |
|
41 _LIT(KFldType, "type"); |
|
42 _LIT(KFldError, "error"); |
|
43 _LIT(KFldErrorCategory, "errorcategory"); |
|
44 _LIT(KFldExpectedCategory, "expectedcategory"); |
|
45 _LIT(KFldExpectedError, "expectederror"); |
|
46 _LIT(KFldExpected_Code, "expected_code"); |
|
47 _LIT(KFldExpected_ChangedModifier, "expected_changedmodifier"); |
|
48 _LIT(KFldExpected_Modifier, "expected_modifier"); |
|
49 _LIT(KFldExpected_Repeats, "expected_repeats"); |
|
50 _LIT(KFldExpected_ScanCode, "expected_scancode"); |
|
51 _LIT(KFldExpected_Type, "expected_type"); |
|
52 _LIT(KFldExpected_Pos, "expected_pos"); |
|
53 _LIT(KFldHandle, "handle"); |
|
54 _LIT(KFldNew_Value, "new_value"); |
|
55 _LIT(KFldUseConst, "useconst"); |
|
56 |
|
57 /// Logging |
|
58 _LIT(KLogMissingParameter, "Missing parameter %S"); |
|
59 _LIT(KLogMissingExpectedValue, "Missing expected value '%S'"); |
|
60 _LIT(KLogNotExpectedValue, "Not expected value"); |
|
61 _LIT(KLogNotExpectedValueInt, "'%S' is not as expected=%d, actual=%d"); |
|
62 _LIT(KLogNotExpectedValueHex, "'%S' is not as expected=0x%x, actual=0x%x"); |
|
63 /*@}*/ |
|
64 |
|
65 ////////////////////////////////////////////////////////////////////// |
|
66 // Construction/Destruction |
|
67 ////////////////////////////////////////////////////////////////////// |
|
68 |
|
69 CT_DataWsEvent* CT_DataWsEvent::NewL() |
|
70 /** |
|
71 * Two phase constructor |
|
72 */ |
|
73 { |
|
74 CT_DataWsEvent* ret=new (ELeave) CT_DataWsEvent(); |
|
75 CleanupStack::PushL(ret); |
|
76 ret->ConstructL(); |
|
77 CleanupStack::Pop(ret); |
|
78 return ret; |
|
79 } |
|
80 |
|
81 CT_DataWsEvent::CT_DataWsEvent() |
|
82 /** |
|
83 * Protected constructor. First phase construction |
|
84 */ |
|
85 : CDataWrapperBase() |
|
86 , iWsEvent(NULL) |
|
87 { |
|
88 } |
|
89 |
|
90 void CT_DataWsEvent::ConstructL() |
|
91 /** |
|
92 * Second phase construction |
|
93 */ |
|
94 { |
|
95 } |
|
96 |
|
97 CT_DataWsEvent::~CT_DataWsEvent() |
|
98 /** |
|
99 * Public destructor |
|
100 */ |
|
101 { |
|
102 DestroyData(); |
|
103 } |
|
104 |
|
105 TAny* CT_DataWsEvent::GetObject() |
|
106 /** |
|
107 * Return a pointer to the object that the data wraps |
|
108 * |
|
109 * @return pointer to the object that the data wraps |
|
110 */ |
|
111 { |
|
112 return iWsEvent; |
|
113 } |
|
114 |
|
115 void CT_DataWsEvent::SetObjectL(TAny* aAny) |
|
116 /** |
|
117 * Set the object that the data wraps |
|
118 * |
|
119 * @param aObject object that the wrapper is testing |
|
120 * |
|
121 */ |
|
122 { |
|
123 DestroyData(); |
|
124 iWsEvent = static_cast<TWsEvent*> (aAny); |
|
125 } |
|
126 |
|
127 void CT_DataWsEvent::DisownObjectL() |
|
128 /** |
|
129 * The object will no longer be owned by this |
|
130 * |
|
131 * @leave KErrNotSupported if the the function is not supported |
|
132 */ |
|
133 { |
|
134 iWsEvent = NULL; |
|
135 } |
|
136 |
|
137 void CT_DataWsEvent::DestroyData() |
|
138 { |
|
139 delete iWsEvent; |
|
140 iWsEvent=NULL; |
|
141 } |
|
142 |
|
143 /** |
|
144 * Process a command read from the ini file |
|
145 * |
|
146 * @param aCommand the command to process |
|
147 * @param aSection the entry in the ini file requiring the command to be processed |
|
148 * @param aAsyncErrorIndex index of command. used for async calls |
|
149 * |
|
150 * @return ETrue if the command is processed |
|
151 */ |
|
152 TBool CT_DataWsEvent::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) |
|
153 { |
|
154 TBool ret = ETrue; |
|
155 if ( aCommand==KCmdnew ) |
|
156 { |
|
157 DoCmdnew(); |
|
158 } |
|
159 else if ( aCommand==KCmdDestructor ) |
|
160 { |
|
161 DestroyData(); |
|
162 } |
|
163 else if ( aCommand==KCmdErrorMessage ) |
|
164 { |
|
165 DoCmdErrorMessage(aSection); |
|
166 } |
|
167 else if ( aCommand==KCmdEventData ) |
|
168 { |
|
169 DoCmdEventData(aSection); |
|
170 } |
|
171 else if ( aCommand==KCmdHandle ) |
|
172 { |
|
173 DoCmdHandle(aSection); |
|
174 } |
|
175 else if ( aCommand==KCmdInt ) |
|
176 { |
|
177 DoCmdInt(aSection); |
|
178 } |
|
179 else if ( aCommand==KCmdKey ) |
|
180 { |
|
181 DoCmdKey(aSection); |
|
182 } |
|
183 else if ( aCommand==KCmdModifiersChanged ) |
|
184 { |
|
185 DoCmdModifiersChanged(aSection); |
|
186 } |
|
187 else if ( aCommand==KCmdPointer ) |
|
188 { |
|
189 DoCmdPointer(aSection); |
|
190 } |
|
191 else if ( aCommand==KCmdSetHandle ) |
|
192 { |
|
193 DoCmdSetHandle(aSection); |
|
194 } |
|
195 else if ( aCommand==KCmdSetTimeNow ) |
|
196 { |
|
197 DoCmdSetTimeNow(); |
|
198 } |
|
199 else if ( aCommand==KCmdSetType ) |
|
200 { |
|
201 DoCmdSetType(aSection); |
|
202 } |
|
203 else if ( aCommand==KCmdTime ) |
|
204 { |
|
205 DoCmdTime(); |
|
206 } |
|
207 else if ( aCommand==KCmdType ) |
|
208 { |
|
209 DoCmdType(aSection); |
|
210 } |
|
211 else if ( aCommand==KCmdVisibilityChanged ) |
|
212 { |
|
213 DoCmdVisibilityChanged(aSection); |
|
214 } |
|
215 else |
|
216 { |
|
217 ret=EFalse; |
|
218 } |
|
219 |
|
220 return ret; |
|
221 } |
|
222 |
|
223 void CT_DataWsEvent::DoCmdnew() |
|
224 { |
|
225 INFO_PRINTF1(_L("new TWsEvent()")); |
|
226 DestroyData(); |
|
227 TRAPD(err, iWsEvent = new (ELeave) TWsEvent()); |
|
228 if(err != KErrNone) |
|
229 { |
|
230 ERR_PRINTF2(_L("**** TWsEvent Constructor failed with error %d"), err); |
|
231 SetError(err); |
|
232 } |
|
233 } |
|
234 |
|
235 void CT_DataWsEvent::DoCmdErrorMessage(const TDesC& aSection) |
|
236 { |
|
237 const TWsEvent* wsEvent=iWsEvent; |
|
238 TWsErrorMessage* actual=wsEvent->ErrorMessage(); |
|
239 INFO_PRINTF3(_L("ErrorMessage: Category %d. Error %d"), actual->iErrorCategory, actual->iError); |
|
240 |
|
241 TWsErrorMessage expected; |
|
242 if ( CT_GraphicsUtil::ReadErrorCategory(*this, aSection, KFldExpectedCategory(), expected.iErrorCategory) ) |
|
243 { |
|
244 if ( actual->iErrorCategory!=expected.iErrorCategory ) |
|
245 { |
|
246 ERR_PRINTF1(KLogNotExpectedValue); |
|
247 SetBlockResult(EFail); |
|
248 } |
|
249 } |
|
250 |
|
251 TWsErrorMessage::TErrorCategory expectedError; |
|
252 if ( CT_GraphicsUtil::ReadErrorCategory(*this, aSection, KFldExpectedError(), expectedError) ) |
|
253 { |
|
254 if ( actual->iErrorCategory!=expectedError ) |
|
255 { |
|
256 ERR_PRINTF1(KLogNotExpectedValue); |
|
257 SetBlockResult(EFail); |
|
258 } |
|
259 } |
|
260 |
|
261 CT_GraphicsUtil::ReadErrorCategory(*this, aSection, KFldErrorCategory(), actual->iErrorCategory); |
|
262 |
|
263 TInt error; |
|
264 if ( GetIntFromConfig(aSection, KFldError(), error) ) |
|
265 { |
|
266 actual->iError=(TUint)error; |
|
267 } |
|
268 } |
|
269 |
|
270 void CT_DataWsEvent::DoCmdEventData(const TDesC& aSection) |
|
271 { |
|
272 TBuf<KMaxTestExecuteCommandLength> tempStore; |
|
273 |
|
274 TUint8* actual=iWsEvent->EventData(); |
|
275 INFO_PRINTF2(_L("EventData: FirstByte %d"), *actual); |
|
276 |
|
277 TInt index=0; |
|
278 for ( index=0; index<TWsEvent::EWsEventDataSize; ++index ) |
|
279 { |
|
280 TInt expected; |
|
281 tempStore.Format(_L("%S%d"), &KFldExpected, index+1); |
|
282 if ( GetIntFromConfig(aSection, tempStore, expected) ) |
|
283 { |
|
284 if ( *(actual+index)!=expected ) |
|
285 { |
|
286 ERR_PRINTF1(KLogNotExpectedValue); |
|
287 SetBlockResult(EFail); |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 for ( index=0; index<TWsEvent::EWsEventDataSize; ++index ) |
|
293 { |
|
294 TInt actualInt; |
|
295 tempStore.Format(_L("%S%d"), &KFldNew_Value, index+1); |
|
296 if ( GetIntFromConfig(aSection, tempStore, actualInt) ) |
|
297 { |
|
298 *(actual+index)=(TUint8)actualInt; |
|
299 } |
|
300 } |
|
301 } |
|
302 |
|
303 void CT_DataWsEvent::DoCmdSetHandle(const TDesC& aSection) |
|
304 { |
|
305 TInt handle=0; |
|
306 if ( !GetIntFromConfig(aSection, KFldHandle(), handle) ) |
|
307 { |
|
308 ERR_PRINTF2(KLogMissingParameter, &KFldHandle()); |
|
309 SetBlockResult(EFail); |
|
310 } |
|
311 else |
|
312 { |
|
313 INFO_PRINTF1(_L("TWsEvent::SetHandle")); |
|
314 iWsEvent->SetHandle((TUint)handle); |
|
315 } |
|
316 } |
|
317 |
|
318 void CT_DataWsEvent::DoCmdHandle(const TDesC& aSection) |
|
319 { |
|
320 TUint actual=iWsEvent->Handle(); |
|
321 INFO_PRINTF2(_L("Handle() actual=%d"), actual); |
|
322 SetHandle(actual); |
|
323 |
|
324 TInt expected; |
|
325 if ( !GetIntFromConfig(aSection, KFldExpected(), expected) ) |
|
326 { |
|
327 ERR_PRINTF2(KLogMissingParameter, &KFldExpected()); |
|
328 SetBlockResult(EFail); |
|
329 } |
|
330 else |
|
331 { |
|
332 if ( expected!=(TInt)actual ) |
|
333 { |
|
334 ERR_PRINTF1(KLogNotExpectedValue); |
|
335 SetBlockResult(EFail); |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 void CT_DataWsEvent::DoCmdSetType(const TDesC& aSection) |
|
341 { |
|
342 TEventCode eventCode; |
|
343 if ( !CT_GraphicsUtil::ReadEventCode(*this, aSection, KFldType(), eventCode) ) |
|
344 { |
|
345 ERR_PRINTF2(KLogMissingParameter, &KFldType()); |
|
346 SetBlockResult(EFail); |
|
347 } |
|
348 else |
|
349 { |
|
350 INFO_PRINTF1(_L("SetType()")); |
|
351 iWsEvent->SetType(eventCode); |
|
352 } |
|
353 } |
|
354 |
|
355 void CT_DataWsEvent::DoCmdType(const TDesC& aSection) |
|
356 { |
|
357 TInt actual=iWsEvent->Type(); |
|
358 INFO_PRINTF2(_L("Type() actual Type:%d"), actual); |
|
359 |
|
360 TEventCode expected; |
|
361 if ( !CT_GraphicsUtil::ReadEventCode(*this, aSection, KFldExpected(), expected) ) |
|
362 { |
|
363 ERR_PRINTF2(KLogMissingParameter, &KFldExpected()); |
|
364 SetBlockResult(EFail); |
|
365 } |
|
366 else |
|
367 { |
|
368 if ( actual!=expected ) |
|
369 { |
|
370 ERR_PRINTF1(KLogNotExpectedValue); |
|
371 SetBlockResult(EFail); |
|
372 } |
|
373 } |
|
374 } |
|
375 |
|
376 void CT_DataWsEvent::DoCmdVisibilityChanged(const TDesC& aSection) |
|
377 { |
|
378 const TWsVisibilityChangedEvent* actual=NULL; |
|
379 |
|
380 TBool useConst=EFalse; |
|
381 GetBoolFromConfig(aSection, KFldUseConst(), useConst); |
|
382 if ( useConst ) |
|
383 { |
|
384 INFO_PRINTF1(_L("const VisibilityChanged")); |
|
385 const TWsEvent* wsEvent=iWsEvent; |
|
386 actual=wsEvent->VisibilityChanged(); |
|
387 } |
|
388 else |
|
389 { |
|
390 INFO_PRINTF1(_L("VisibilityChanged")); |
|
391 TWsVisibilityChangedEvent* actualNonConst=iWsEvent->VisibilityChanged(); |
|
392 actual=actualNonConst; |
|
393 } |
|
394 INFO_PRINTF2(_L("VisibilityChanged:%d"), actual->iFlags); |
|
395 |
|
396 TWsVisibilityChangedEvent expected; |
|
397 if ( CT_GraphicsUtil::ReadWsVisibilityChangedEvent(*this, aSection, KFldExpected(), expected) ) |
|
398 { |
|
399 if ( actual->iFlags!=expected.iFlags ) |
|
400 { |
|
401 ERR_PRINTF1(KLogNotExpectedValue); |
|
402 SetBlockResult(EFail); |
|
403 } |
|
404 } |
|
405 } |
|
406 |
|
407 void CT_DataWsEvent::DoCmdSetTimeNow() |
|
408 { |
|
409 INFO_PRINTF1(_L("SetTimeNow()")); |
|
410 iWsEvent->SetTimeNow(); |
|
411 } |
|
412 |
|
413 void CT_DataWsEvent::DoCmdTime() |
|
414 { |
|
415 INFO_PRINTF1(_L("Time()")); |
|
416 TTime eventTime=iWsEvent->Time(); |
|
417 |
|
418 TDateTime dateTime = eventTime.DateTime(); |
|
419 INFO_PRINTF4(_L("Time() returned %d/%d/%d"), dateTime.Year(), dateTime.Month(), dateTime.Day()); |
|
420 INFO_PRINTF5(_L("Time() returned %d:%d:%d.%d"), dateTime.Hour(), dateTime.Minute(), dateTime.Second(), dateTime.MicroSecond()); |
|
421 } |
|
422 |
|
423 void CT_DataWsEvent::DoCmdInt(const TDesC& aSection) |
|
424 { |
|
425 TInt* actual=iWsEvent->Int(); |
|
426 INFO_PRINTF2(_L("Int:0x%x"), *actual); |
|
427 |
|
428 TInt expected; |
|
429 if ( GetIntFromConfig(aSection, KFldExpected(), expected) ) |
|
430 { |
|
431 if ( *actual!=expected ) |
|
432 { |
|
433 ERR_PRINTF1(KLogNotExpectedValue); |
|
434 SetBlockResult(EFail); |
|
435 } |
|
436 } |
|
437 |
|
438 GetIntFromConfig(aSection, KFldNew_Value(), *actual); |
|
439 } |
|
440 |
|
441 void CT_DataWsEvent::DoCmdKey(const TDesC& aSection) |
|
442 { |
|
443 INFO_PRINTF1(_L("Key()")); |
|
444 TKeyEvent* eventKey=iWsEvent->Key(); |
|
445 |
|
446 TKeyCode keyCode; |
|
447 if ( CT_GraphicsUtil::ReadKeyCode(*this, aSection, KFldExpected_Code, keyCode) ) |
|
448 { |
|
449 if ( (TUint)keyCode != eventKey->iCode ) |
|
450 { |
|
451 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_Code, keyCode, eventKey->iCode); |
|
452 SetBlockResult(EFail); |
|
453 } |
|
454 } |
|
455 else |
|
456 { |
|
457 ERR_PRINTF2(KLogMissingExpectedValue, &KFldExpected_Code); |
|
458 SetBlockResult(EFail); |
|
459 } |
|
460 |
|
461 TStdScanCode scanCode; |
|
462 if ( CT_GraphicsUtil::ReadStdScanCode(*this, aSection, KFldExpected_ScanCode, scanCode) ) |
|
463 { |
|
464 if ( scanCode != eventKey->iScanCode ) |
|
465 { |
|
466 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_ScanCode, scanCode, eventKey->iScanCode); |
|
467 SetBlockResult(EFail); |
|
468 } |
|
469 } |
|
470 |
|
471 TUint modifiers; |
|
472 if ( CT_GraphicsUtil::ReadEventModifier(*this, aSection, KFldExpected_Modifier, modifiers) ) |
|
473 { |
|
474 if ( modifiers != eventKey->iModifiers ) |
|
475 { |
|
476 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_Modifier, modifiers, eventKey->iModifiers); |
|
477 SetBlockResult(EFail); |
|
478 } |
|
479 } |
|
480 |
|
481 TInt repeats; |
|
482 if ( GetIntFromConfig(aSection, KFldExpected_Repeats, repeats) ) |
|
483 { |
|
484 if ( repeats != eventKey->iRepeats ) |
|
485 { |
|
486 ERR_PRINTF4(KLogNotExpectedValueInt, &KFldExpected_Repeats, repeats, eventKey->iRepeats); |
|
487 SetBlockResult(EFail); |
|
488 } |
|
489 } |
|
490 } |
|
491 |
|
492 void CT_DataWsEvent::DoCmdModifiersChanged(const TDesC& aSection) |
|
493 { |
|
494 INFO_PRINTF1(_L("ModifiersChanged()")); |
|
495 TModifiersChangedEvent* event=iWsEvent->ModifiersChanged(); |
|
496 INFO_PRINTF3(_L("TModifiersChangedEvent: iChangedModifiers=0x%x iModifiers=0x%x"), event->iChangedModifiers, event->iModifiers); |
|
497 |
|
498 TUint changedModifiers; |
|
499 if ( CT_GraphicsUtil::ReadEventModifier(*this, aSection, KFldExpected_ChangedModifier, changedModifiers) ) |
|
500 { |
|
501 if ( changedModifiers!=event->iChangedModifiers ) |
|
502 { |
|
503 ERR_PRINTF4(KLogNotExpectedValueHex, &KFldExpected_Modifier, changedModifiers, event->iChangedModifiers); |
|
504 SetBlockResult(EFail); |
|
505 } |
|
506 } |
|
507 |
|
508 TUint modifiers; |
|
509 if ( CT_GraphicsUtil::ReadEventModifier(*this, aSection, KFldExpected_Modifier, modifiers) ) |
|
510 { |
|
511 if ( modifiers!=(event->iModifiers&event->iChangedModifiers) ) |
|
512 { |
|
513 ERR_PRINTF4(KLogNotExpectedValueHex, &KFldExpected_Modifier, modifiers, event->iModifiers); |
|
514 SetBlockResult(EFail); |
|
515 } |
|
516 } |
|
517 } |
|
518 |
|
519 void CT_DataWsEvent::DoCmdPointer(const TDesC& aSection) |
|
520 { |
|
521 INFO_PRINTF1(_L("Pointer()")); |
|
522 TPointerEvent* actual=iWsEvent->Pointer(); |
|
523 INFO_PRINTF2(_L("iType =%d"), actual->iType); |
|
524 INFO_PRINTF2(_L("iModifiers =0x%x"), actual->iModifiers); |
|
525 INFO_PRINTF3(_L("iPosition =(%d,%d)"), actual->iPosition.iX, actual->iPosition.iY); |
|
526 INFO_PRINTF3(_L("iParentPosition =(%d,%d)"), actual->iParentPosition.iX, actual->iParentPosition.iY); |
|
527 |
|
528 TPointerEvent::TType expectedType; |
|
529 if ( CT_GraphicsUtil::ReadType(*this, aSection, KFldExpected_Type, expectedType) ) |
|
530 { |
|
531 if ( actual->iType!=expectedType ) |
|
532 { |
|
533 ERR_PRINTF4(KLogNotExpectedValueHex, &KFldExpected_Type, expectedType, actual->iType); |
|
534 SetBlockResult(EFail); |
|
535 } |
|
536 } |
|
537 |
|
538 TUint modifiers; |
|
539 if ( CT_GraphicsUtil::ReadEventModifier(*this, aSection, KFldExpected_Modifier, modifiers) ) |
|
540 { |
|
541 if ( modifiers!=(actual->iModifiers&actual->iType) ) |
|
542 { |
|
543 ERR_PRINTF4(KLogNotExpectedValueHex, &KFldExpected_Modifier, modifiers, actual->iModifiers); |
|
544 SetBlockResult(EFail); |
|
545 } |
|
546 } |
|
547 |
|
548 TPoint position; |
|
549 if ( GetPointFromConfig(aSection, KFldExpected_Pos, position) ) |
|
550 { |
|
551 if ( position!=actual->iPosition ) |
|
552 { |
|
553 ERR_PRINTF1(KLogNotExpectedValue); |
|
554 SetBlockResult(EFail); |
|
555 } |
|
556 } |
|
557 } |
|