|
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 * @file |
|
16 * This is the test class for TEF (PREQ1521). |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 #include "te_RegBlockTestWrapper.h" |
|
23 |
|
24 /*@{*/ |
|
25 /// Enumerations |
|
26 #define TESTA(a) \ |
|
27 if(a) {INFO_PRINTF1(_L("Test Passed!"));} \ |
|
28 else {SetBlockResult(EFail); ERR_PRINTF1(_L("Test Failed!"));} \ |
|
29 |
|
30 #define Macro(s) _LIT(K##s, #s) |
|
31 Macro(WriteHexValue); |
|
32 Macro(WriteIntValue); |
|
33 Macro(WriteBoolValue); |
|
34 Macro(WriteStringValue); |
|
35 Macro(TestNullController); |
|
36 Macro(WriteSharedData); |
|
37 Macro(ReadSharedData); |
|
38 Macro(SetDataObject); |
|
39 //Macro(SerialWriter); |
|
40 |
|
41 _LIT(KSharedName, "SharedName"); |
|
42 _LIT(KSharedValue, "Shard data value"); |
|
43 |
|
44 _LIT(KFail, "EFail"); |
|
45 _LIT(KPass, "EPass"); |
|
46 |
|
47 /// Commands |
|
48 _LIT(KSetBlockResult, "SetBlockResult"); |
|
49 _LIT(KSetError, "SetError"); |
|
50 _LIT(KDummyFunction, "DummyFunction"); |
|
51 _LIT(KGetDataObject, "GetDataObject"); |
|
52 _LIT(KGetDataWrapper, "GetDataWrapper"); |
|
53 _LIT(KPanickingFunction, "PanickingFunction"); |
|
54 _LIT(KLeaveFunction, "LeaveFunction"); |
|
55 _LIT(KModify, "Modify"); |
|
56 _LIT(KModifyByName, "ModifyByName"); |
|
57 _LIT(KNew, "New"); |
|
58 _LIT(KStartTimer, "StartTimer"); |
|
59 _LIT(KCheckTimer, "CheckTimer"); |
|
60 _LIT(KIncreaseObjectValue, "IncreaseObjectValue"); |
|
61 _LIT(KAddActiveObjectToScheduler, "AddActiveObjectToScheduler"); |
|
62 _LIT(KActivateActiveObject, "ActivateActiveObject"); |
|
63 _LIT(KCancelActiveObject, "CancelActiveObject"); |
|
64 _LIT(KCheckActiveObjectWorkIsComplete, "CheckActiveObjectWorkIsComplete"); |
|
65 _LIT(KCallMeFirstMkDir, "CallMeFirstMkDir"); |
|
66 _LIT(KCallMeSecondRmDir, "CallMeSecondRmDir"); |
|
67 |
|
68 |
|
69 /// command parameters |
|
70 _LIT(KMaxIntervalSec, "max_interval_sec"); |
|
71 _LIT(KMinIntervalSec, "min_interval_sec"); |
|
72 _LIT(KPanicNumber, "panic_number"); |
|
73 _LIT(KLeaveNumber, "leave_number"); |
|
74 _LIT(KPanicString, "panic_string"); |
|
75 _LIT(KNullExpected, "null_expected"); |
|
76 _LIT(KObjectValue, "object_value"); |
|
77 _LIT(KErrorCode, "error_code"); |
|
78 _LIT(KBlockResult, "block_result"); |
|
79 _LIT(KMicrosecondsOfWork, "microseconds_of_work"); |
|
80 _LIT(KMustBeComplete, "must_be_complete"); |
|
81 _LIT(KDirectoryPath, "directory_path"); |
|
82 |
|
83 /*@}*/ |
|
84 |
|
85 CTe_RegBlockTestWrapper::CTe_RegBlockTestWrapper() |
|
86 : iActiveCallback(NULL) |
|
87 , iObject(NULL) |
|
88 , iActiveObject(NULL) |
|
89 { |
|
90 } |
|
91 |
|
92 CTe_RegBlockTestWrapper::~CTe_RegBlockTestWrapper() |
|
93 { |
|
94 delete iActiveCallback; |
|
95 iActiveCallback = NULL; |
|
96 |
|
97 delete iActiveObject; |
|
98 iActiveObject = NULL; |
|
99 |
|
100 delete iObject; |
|
101 iObject = NULL; |
|
102 } |
|
103 |
|
104 CTe_RegBlockTestWrapper* CTe_RegBlockTestWrapper::NewL() |
|
105 { |
|
106 CTe_RegBlockTestWrapper* ret = new (ELeave) CTe_RegBlockTestWrapper(); |
|
107 CleanupStack::PushL(ret); |
|
108 ret->ConstructL(); |
|
109 CleanupStack::Pop(ret); |
|
110 return ret; |
|
111 } |
|
112 |
|
113 void CTe_RegBlockTestWrapper::ConstructL() |
|
114 { |
|
115 iActiveCallback = CActiveCallback::NewL(*this); |
|
116 iObject = new (ELeave) TInt; |
|
117 } |
|
118 |
|
119 TBool CTe_RegBlockTestWrapper::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex) |
|
120 { |
|
121 TBool ret = ETrue; |
|
122 |
|
123 // Print out the parameters for debugging |
|
124 INFO_PRINTF2( _L("aCommand = %S"), &aCommand ); |
|
125 INFO_PRINTF2( _L("aSection = %S"), &aSection ); |
|
126 INFO_PRINTF2( _L("aAsyncErrorIndex = %D"), aAsyncErrorIndex ); |
|
127 |
|
128 if(KModify() == aCommand) |
|
129 { |
|
130 DoCmdModify(aSection); |
|
131 } |
|
132 else if(KModifyByName() == aCommand) |
|
133 { |
|
134 DoCmdModifyByName(aSection); |
|
135 } |
|
136 else if(KNew() == aCommand) |
|
137 { |
|
138 DoCmdNewL(aSection); |
|
139 } |
|
140 else if(KSetBlockResult() == aCommand) |
|
141 { |
|
142 DoCmdSetBlockResult(aSection); |
|
143 } |
|
144 else if(KSetError() == aCommand) |
|
145 { |
|
146 DoCmdSetError(aSection); |
|
147 } |
|
148 else if(KDummyFunction() == aCommand) |
|
149 { |
|
150 DoCmdDummyFunction(); |
|
151 } |
|
152 else if(KGetDataObject() == aCommand) |
|
153 { |
|
154 DoCmdGetDataObject(aSection); |
|
155 } |
|
156 else if(KGetDataWrapper() == aCommand) |
|
157 { |
|
158 DoCmdGetDataWrapper(aSection); |
|
159 } |
|
160 else if(KPanickingFunction() == aCommand) |
|
161 { |
|
162 DoCmdPanickingFunction(aSection); |
|
163 } |
|
164 else if(KLeaveFunction() == aCommand) |
|
165 { |
|
166 DoCmdLeaveFunction(aSection); |
|
167 } |
|
168 else if(KStartTimer() == aCommand) |
|
169 { |
|
170 DoCmdStartTimer(); |
|
171 } |
|
172 else if(KCheckTimer() == aCommand) |
|
173 { |
|
174 DoCmdCheckTimer(aSection); |
|
175 } |
|
176 else if(KIncreaseObjectValue() == aCommand) |
|
177 { |
|
178 DoCmdIncreaseObjectValue(); |
|
179 } |
|
180 else if(KAddActiveObjectToScheduler() == aCommand) |
|
181 { |
|
182 DoCmdAddActiveObjectToScheduler(); |
|
183 } |
|
184 else if(KActivateActiveObject() == aCommand) |
|
185 { |
|
186 DoCmdActivateActiveObject(aSection, aAsyncErrorIndex); |
|
187 } |
|
188 else if(KCancelActiveObject() == aCommand) |
|
189 { |
|
190 DoCmdCancelActiveObject(); |
|
191 } |
|
192 else if(KCheckActiveObjectWorkIsComplete() == aCommand) |
|
193 { |
|
194 DoCmdCheckActiveObjectWorkIsComplete(aSection); |
|
195 } |
|
196 else if(KCallMeFirstMkDir() == aCommand) |
|
197 { |
|
198 DoCmdCallMeFirstMkDir(aSection); |
|
199 } |
|
200 else if(KCallMeSecondRmDir() == aCommand) |
|
201 { |
|
202 DoCmdCallMeSecondRmDir(aSection); |
|
203 } |
|
204 else if (KWriteIntValue() == aCommand) |
|
205 { |
|
206 DoCmdWriteIntToConfig(aSection); |
|
207 } |
|
208 |
|
209 else if (KWriteBoolValue() == aCommand) |
|
210 { |
|
211 DoCmdWriteBoolToConfig(aSection); |
|
212 } |
|
213 |
|
214 else if (KWriteHexValue() == aCommand) |
|
215 { |
|
216 DoCmdWriteHexToConfig(aSection); |
|
217 } |
|
218 |
|
219 else if (KWriteStringValue() == aCommand) |
|
220 { |
|
221 DoCmdWriteStringToConfig(aSection); |
|
222 } |
|
223 else if (KTestNullController() == aCommand) |
|
224 { |
|
225 DoCmdTestNullController(aSection); |
|
226 } |
|
227 else if (aCommand == KWriteSharedData) |
|
228 { |
|
229 DoCmdWriteSharedData(); |
|
230 } |
|
231 else if (aCommand == KReadSharedData) |
|
232 { |
|
233 DoCmdReadSharedData(); |
|
234 } |
|
235 else if (aCommand == KSetDataObject) |
|
236 { |
|
237 DoCmdSetDataObject(aSection); |
|
238 } |
|
239 else |
|
240 { |
|
241 ret = EFalse; |
|
242 } |
|
243 |
|
244 return ret; |
|
245 } |
|
246 |
|
247 /** |
|
248 Purpose: |
|
249 |
|
250 Ini file options: |
|
251 iniData - The data from the ini file at the section provided. |
|
252 |
|
253 @internalComponent |
|
254 @param aSection Current ini file command section |
|
255 */ |
|
256 void CTe_RegBlockTestWrapper::DoCmdModify(const TDesC& aSection) |
|
257 { |
|
258 TInt objectValue = 0; |
|
259 if (!GetIntFromConfig(aSection, KObjectValue(), objectValue)) |
|
260 { |
|
261 ERR_PRINTF2(_L("No parameter %S"), &KObjectValue()); |
|
262 SetBlockResult(EFail); |
|
263 } |
|
264 else |
|
265 { |
|
266 *iObject = objectValue; |
|
267 } |
|
268 } |
|
269 |
|
270 |
|
271 |
|
272 /** |
|
273 Purpose: calls SetBlockResult() to set block result |
|
274 |
|
275 @internalComponent |
|
276 @param aSection Current ini file command section |
|
277 */ |
|
278 void CTe_RegBlockTestWrapper::DoCmdSetBlockResult(const TDesC& aSection) |
|
279 { |
|
280 TVerdict verdict = EFail; |
|
281 if (!GetVerdictFromConfig(aSection, KBlockResult(), verdict)) |
|
282 { |
|
283 ERR_PRINTF2(_L("No parameter %S"), &KBlockResult()); |
|
284 SetBlockResult(EFail); |
|
285 } |
|
286 |
|
287 WARN_PRINTF2(_L("Setting test block result: %d"), verdict); |
|
288 SetBlockResult(verdict); |
|
289 TESTA(BlockResult() == verdict); |
|
290 } |
|
291 |
|
292 |
|
293 |
|
294 /** |
|
295 Purpose: remembers current time, so that it can be used for comparison in a subsequent CheckTime command call |
|
296 |
|
297 @internalComponent |
|
298 @param aSection Current ini file command section |
|
299 */ |
|
300 void CTe_RegBlockTestWrapper::DoCmdStartTimer() |
|
301 { |
|
302 iTimerStart.HomeTime(); |
|
303 } |
|
304 |
|
305 |
|
306 |
|
307 /** |
|
308 Purpose: remembers current time, so compares difference in time between the call and the previous call to Start Timer command |
|
309 |
|
310 @internalComponent |
|
311 @param aSection Current ini file command section |
|
312 */ |
|
313 void CTe_RegBlockTestWrapper::DoCmdCheckTimer(const TDesC& aSection) |
|
314 { |
|
315 TInt maxIntervalSec = 0; |
|
316 if (!GetIntFromConfig(aSection, KMaxIntervalSec(), maxIntervalSec)) |
|
317 { |
|
318 ERR_PRINTF2(_L("No parameter %S"), &KMaxIntervalSec()); |
|
319 SetBlockResult(EFail); |
|
320 return; |
|
321 } |
|
322 |
|
323 TInt minIntervalSec = 0; |
|
324 if (!GetIntFromConfig(aSection, KMinIntervalSec(), minIntervalSec)) |
|
325 { |
|
326 ERR_PRINTF2(_L("No parameter %S"), &KMinIntervalSec()); |
|
327 SetBlockResult(EFail); |
|
328 return; |
|
329 } |
|
330 |
|
331 |
|
332 TTime now; |
|
333 TTimeIntervalSeconds secs; |
|
334 now.HomeTime(); |
|
335 |
|
336 _LIT(KDateString,"%D%M%Y%/0%1%/1%2%/2%3%/3 %-B %:0%J%:1%T%:2%S %+B"); |
|
337 TBuf<50> dateString2; |
|
338 iTimerStart.FormatL(dateString2, KDateString); |
|
339 INFO_PRINTF2(_L("Timer start time: %S"), &dateString2); |
|
340 |
|
341 TBuf<50> dateString; |
|
342 now.FormatL(dateString, KDateString); |
|
343 INFO_PRINTF2(_L("Timer check time: %S"), &dateString); |
|
344 |
|
345 |
|
346 TInt err = now.SecondsFrom(iTimerStart, secs); |
|
347 if (err != KErrNone) |
|
348 { |
|
349 ERR_PRINTF2(_L("Call to TTime::SecondsFrom returned error: %d"), err); |
|
350 SetBlockResult(EFail); |
|
351 return; |
|
352 } |
|
353 |
|
354 |
|
355 if (secs > TTimeIntervalSeconds(maxIntervalSec)) |
|
356 { |
|
357 ERR_PRINTF3(_L("The time interval is longer than expected. expected=%d, actual=%d"), maxIntervalSec, secs.Int()); |
|
358 SetBlockResult(EFail); |
|
359 } |
|
360 |
|
361 if (secs < TTimeIntervalSeconds(minIntervalSec)) |
|
362 { |
|
363 ERR_PRINTF3(_L("The time interval is shorter than expected. expected=%d, actual=%d"), minIntervalSec, secs.Int()); |
|
364 SetBlockResult(EFail); |
|
365 } |
|
366 } |
|
367 |
|
368 |
|
369 |
|
370 /** |
|
371 Purpose: increases a counter value, that can be checked using GetDataObject command |
|
372 |
|
373 @internalComponent |
|
374 */ |
|
375 void CTe_RegBlockTestWrapper::DoCmdIncreaseObjectValue() |
|
376 { |
|
377 (*iObject)++; |
|
378 INFO_PRINTF2(_L("Counter value: %d"), *iObject); |
|
379 } |
|
380 |
|
381 |
|
382 |
|
383 /** |
|
384 Purpose: A function that sets an error code (given in the ini-file). |
|
385 |
|
386 @internalComponent |
|
387 */ |
|
388 void CTe_RegBlockTestWrapper::DoCmdSetError(const TDesC& aSection) |
|
389 { |
|
390 TInt errorCode = 0; |
|
391 if (!GetIntFromConfig(aSection, KErrorCode(), errorCode)) |
|
392 { |
|
393 ERR_PRINTF2(_L("No parameter %S"), &KErrorCode()); |
|
394 SetBlockResult(EFail); |
|
395 } |
|
396 else |
|
397 { |
|
398 WARN_PRINTF2(_L("Setting an error: %d"), errorCode); |
|
399 SetError(errorCode); |
|
400 } |
|
401 } |
|
402 |
|
403 |
|
404 /** |
|
405 Purpose: An implementation of a dummy functions that doesn nothing |
|
406 |
|
407 @internalComponent |
|
408 */ |
|
409 void CTe_RegBlockTestWrapper::DoCmdDummyFunction() |
|
410 { |
|
411 } |
|
412 |
|
413 |
|
414 |
|
415 /** |
|
416 Purpose: A function that throws panic |
|
417 |
|
418 @internalComponent |
|
419 */ |
|
420 void CTe_RegBlockTestWrapper::DoCmdPanickingFunction(const TDesC& aSection) |
|
421 { |
|
422 TInt panicNumber = 0; |
|
423 if (!GetIntFromConfig(aSection, KPanicNumber(), panicNumber)) |
|
424 { |
|
425 ERR_PRINTF2(_L("No parameter %S"), &KPanicNumber()); |
|
426 SetBlockResult(EFail); |
|
427 } |
|
428 else |
|
429 { |
|
430 TPtrC panicString; |
|
431 if (!GetStringFromConfig(aSection, KPanicString(), panicString)) |
|
432 { |
|
433 ERR_PRINTF2(_L("No parameter %S"), &KPanicString()); |
|
434 SetBlockResult(EFail); |
|
435 } |
|
436 WARN_PRINTF3(_L("Calling panic: %S %d"), &panicString, panicNumber); |
|
437 User::Panic(panicString, panicNumber); |
|
438 } |
|
439 } |
|
440 |
|
441 /** |
|
442 Purpose: A function that Leaves |
|
443 |
|
444 @internalComponent |
|
445 */ |
|
446 void CTe_RegBlockTestWrapper::DoCmdLeaveFunction(const TDesC& aSection) |
|
447 { |
|
448 TInt LeaveNumber = 0; |
|
449 if (!GetIntFromConfig(aSection, KLeaveNumber(), LeaveNumber)) |
|
450 { |
|
451 ERR_PRINTF2(_L("No parameter %S"), &KLeaveNumber()); |
|
452 SetBlockResult(EFail); |
|
453 } |
|
454 else |
|
455 { |
|
456 WARN_PRINTF2(_L("Calling panic:%d"),LeaveNumber); |
|
457 User::Leave(LeaveNumber); |
|
458 } |
|
459 } |
|
460 |
|
461 /** |
|
462 Purpose: A function that creates a directory |
|
463 |
|
464 @internalComponent |
|
465 */ |
|
466 void CTe_RegBlockTestWrapper::DoCmdCallMeFirstMkDir(const TDesC& aSection) |
|
467 { |
|
468 TPtrC dirPath; |
|
469 if (!GetStringFromConfig(aSection, KDirectoryPath(), dirPath)) |
|
470 { |
|
471 ERR_PRINTF2(_L("No parameter %S"), &KDirectoryPath()); |
|
472 SetBlockResult(EFail); |
|
473 } |
|
474 INFO_PRINTF2(_L("MkDir %S"), &dirPath); |
|
475 RFs fs; |
|
476 fs.Connect(); |
|
477 TInt err = fs.MkDir(dirPath); |
|
478 if (err != KErrNone) |
|
479 { |
|
480 ERR_PRINTF2(_L("Failed to create a directory: %d"), err); |
|
481 SetBlockResult(EFail); |
|
482 } |
|
483 fs.Close(); |
|
484 } |
|
485 |
|
486 |
|
487 /** |
|
488 Purpose: A function that removes a directory |
|
489 |
|
490 @internalComponent |
|
491 */ |
|
492 void CTe_RegBlockTestWrapper::DoCmdCallMeSecondRmDir(const TDesC& aSection) |
|
493 { |
|
494 TPtrC dirPath; |
|
495 if (!GetStringFromConfig(aSection, KDirectoryPath(), dirPath)) |
|
496 { |
|
497 ERR_PRINTF2(_L("No parameter %S"), &KDirectoryPath()); |
|
498 SetBlockResult(EFail); |
|
499 } |
|
500 INFO_PRINTF2(_L("RmDir %S"), &dirPath); |
|
501 RFs fs; |
|
502 fs.Connect(); |
|
503 TInt err = fs.RmDir(dirPath); |
|
504 if (err != KErrNone) |
|
505 { |
|
506 ERR_PRINTF2(_L("Failed to remove a directory: %d. The function was called before CallMeFirstMkDir?"), err); |
|
507 SetBlockResult(EFail); |
|
508 } |
|
509 fs.Close(); |
|
510 } |
|
511 |
|
512 /** |
|
513 Purpose: |
|
514 |
|
515 Ini file options: |
|
516 iniData - The data from the ini file at the section provided. |
|
517 |
|
518 @internalComponent |
|
519 @param aSection Current ini file command section |
|
520 */ |
|
521 void CTe_RegBlockTestWrapper::DoCmdModifyByName(const TDesC& aSection) |
|
522 { |
|
523 TInt objectValue = 0; |
|
524 if (!GetIntFromConfig(aSection, KObjectValue(), objectValue)) |
|
525 { |
|
526 ERR_PRINTF2(_L("No parameter %S"), &KObjectValue()); |
|
527 SetBlockResult(EFail); |
|
528 } |
|
529 else |
|
530 { |
|
531 // call GetObject() and check that the wrapped object is found |
|
532 TInt* wrappedObject = NULL; |
|
533 TRAPD(err, wrappedObject = static_cast<TInt*>(GetDataObjectL(aSection))); |
|
534 if (err != KErrNone) |
|
535 { |
|
536 ERR_PRINTF2(_L("GetDataObjectL() error: %d"), err); |
|
537 SetError(err); |
|
538 return; |
|
539 } |
|
540 |
|
541 if (wrappedObject == NULL) |
|
542 { |
|
543 ERR_PRINTF2(_L("Wrapped object is not found using GetDataObject(). section=%S"), &aSection); |
|
544 SetBlockResult(EFail); |
|
545 } |
|
546 else |
|
547 { |
|
548 *wrappedObject = objectValue; |
|
549 } |
|
550 } |
|
551 } |
|
552 |
|
553 |
|
554 /** |
|
555 Purpose: To create a new object of the CTEFTest type through the API. |
|
556 |
|
557 Ini file options: |
|
558 iniData - The data from the ini file at the section provided. |
|
559 |
|
560 @internalComponent |
|
561 @param aSection Current ini file command section |
|
562 */ |
|
563 void CTe_RegBlockTestWrapper::DoCmdNewL(const TDesC& aSection) |
|
564 { |
|
565 TInt objectValue = 0; |
|
566 if (!GetIntFromConfig(aSection, KObjectValue(), objectValue)) |
|
567 { |
|
568 ERR_PRINTF2(_L("No parameter %S"), &KObjectValue()); |
|
569 SetBlockResult(EFail); |
|
570 } |
|
571 else |
|
572 { |
|
573 delete iObject; |
|
574 iObject = new (ELeave) TInt(objectValue); |
|
575 } |
|
576 } |
|
577 |
|
578 |
|
579 /** |
|
580 Purpose: To test that an data wrapper object exists in the dictionary. |
|
581 |
|
582 @internalComponent |
|
583 @param aSection Current ini file command section |
|
584 */ |
|
585 void CTe_RegBlockTestWrapper::DoCmdGetDataWrapper(const TDesC& aSection) |
|
586 { |
|
587 // check if null is expected |
|
588 TBool nullExpected = EFalse; |
|
589 GetBoolFromConfig(aSection, KNullExpected(), nullExpected); |
|
590 |
|
591 // call GetDataWrapper() and check that the wrapper is found |
|
592 CDataWrapper* wrapper = NULL; |
|
593 TRAPD(err, wrapper = GetDataWrapperL(aSection)); |
|
594 if (err != KErrNone) |
|
595 { |
|
596 ERR_PRINTF2(_L("GetDataWrapperL() error: %d"), err); |
|
597 SetError(err); |
|
598 } |
|
599 |
|
600 // check if is null if is expetced to be null and vice versa |
|
601 if (wrapper == NULL && !nullExpected) |
|
602 { |
|
603 ERR_PRINTF1(_L("Wrapper is not expected to be null!")); |
|
604 SetBlockResult(EFail); |
|
605 } |
|
606 else if (wrapper != NULL && nullExpected) |
|
607 { |
|
608 ERR_PRINTF1(_L("Wrapper is expected to be null!")); |
|
609 SetBlockResult(EFail); |
|
610 } |
|
611 } |
|
612 |
|
613 /** |
|
614 Purpose: To test that set object value is correct and also check the object's value. |
|
615 |
|
616 @internalComponent |
|
617 @param aSection Current ini file command section |
|
618 */ |
|
619 void CTe_RegBlockTestWrapper::DoCmdSetDataObject(const TTEFSectionName& aSection) |
|
620 { |
|
621 TInt* object = new TInt(10); |
|
622 TRAPD(err, SetDataObjectL(aSection, object)); |
|
623 TESTA(err==KErrNone); |
|
624 object = NULL; |
|
625 TRAP(err, object=(TInt*)GetDataObjectL(aSection)); |
|
626 TESTA(*object==10); |
|
627 } |
|
628 |
|
629 |
|
630 /** |
|
631 Purpose: To test that an wrapped object exists in the dictionary. And optionally to check the object's value. |
|
632 |
|
633 @internalComponent |
|
634 @param aSection Current ini file command section |
|
635 */ |
|
636 void CTe_RegBlockTestWrapper::DoCmdGetDataObject(const TDesC& aSection) |
|
637 { |
|
638 // check if null is expected |
|
639 TBool nullExpected = EFalse; |
|
640 GetBoolFromConfig(aSection, KNullExpected(), nullExpected); |
|
641 |
|
642 // call GetDataObject() and check that the wrapped object is found |
|
643 TInt* wrappedObject = NULL; |
|
644 TRAPD(err, wrappedObject = static_cast<TInt*>(GetDataObjectL(aSection))); |
|
645 if (err != KErrNone) |
|
646 { |
|
647 ERR_PRINTF2(_L("GetDataObjectL() error: %d"), err); |
|
648 SetError(err); |
|
649 } |
|
650 |
|
651 // check if is null if is expetced to be null and vice versa |
|
652 if (wrappedObject == NULL && !nullExpected) |
|
653 { |
|
654 ERR_PRINTF1(_L("Wrapped object is not expected to be null!")); |
|
655 SetBlockResult(EFail); |
|
656 } |
|
657 else if (wrappedObject != NULL) |
|
658 { |
|
659 if (nullExpected) |
|
660 { |
|
661 ERR_PRINTF1(_L("Wrapped object is expected to be null!")); |
|
662 SetBlockResult(EFail); |
|
663 } |
|
664 else |
|
665 { |
|
666 // check expected value |
|
667 TInt objectValue = 0; |
|
668 if (GetIntFromConfig(aSection, KObjectValue(), objectValue)) |
|
669 { |
|
670 if (*wrappedObject != objectValue) |
|
671 { |
|
672 ERR_PRINTF3(_L("Wrapped object's value is not as expected. expected=%d, actual=%d"), objectValue, *wrappedObject); |
|
673 SetBlockResult(EFail); |
|
674 } |
|
675 } |
|
676 } |
|
677 } |
|
678 } |
|
679 |
|
680 |
|
681 /** |
|
682 Create an active object and add it to the current active scheduler |
|
683 */ |
|
684 void CTe_RegBlockTestWrapper::DoCmdAddActiveObjectToScheduler() |
|
685 { |
|
686 if (iActiveObject != NULL) |
|
687 { |
|
688 delete iActiveObject; |
|
689 iActiveObject = NULL; |
|
690 } |
|
691 |
|
692 TRAPD(err, iActiveObject = new (ELeave) RTimer); |
|
693 if (err != KErrNone) |
|
694 { |
|
695 ERR_PRINTF2(_L("RTimer creation failed with error: %d"), err); |
|
696 SetBlockResult(EFail); |
|
697 return; |
|
698 } |
|
699 |
|
700 iActiveObject->CreateLocal(); |
|
701 } |
|
702 |
|
703 /** |
|
704 Check that the active object is already added to the active scheduler |
|
705 */ |
|
706 void CTe_RegBlockTestWrapper::DoCmdActivateActiveObject(const TDesC& aSection, const TInt aAsyncErrorIndex) |
|
707 { |
|
708 TInt microsecondsOfWork = 0; |
|
709 if (!GetIntFromConfig(aSection, KMicrosecondsOfWork(), microsecondsOfWork)) |
|
710 { |
|
711 ERR_PRINTF2(_L("No parameter %S"), &KMicrosecondsOfWork()); |
|
712 SetBlockResult(EFail); |
|
713 } |
|
714 |
|
715 iActiveObject->After(iActiveCallback->iStatus, microsecondsOfWork); |
|
716 iActiveCallback->Activate(aAsyncErrorIndex); |
|
717 IncOutstanding(); |
|
718 } |
|
719 |
|
720 |
|
721 /** |
|
722 Cancel active object |
|
723 */ |
|
724 void CTe_RegBlockTestWrapper::DoCmdCancelActiveObject() |
|
725 { |
|
726 iActiveObject->Cancel(); |
|
727 } |
|
728 |
|
729 |
|
730 /** |
|
731 Check that the active object work is finished (or not finished depending on the expectation) |
|
732 */ |
|
733 void CTe_RegBlockTestWrapper::DoCmdCheckActiveObjectWorkIsComplete(const TDesC& aSection) |
|
734 { |
|
735 INFO_PRINTF1(_L("CTe_RegBlockTestWrapper::DoCmdCheckActiveObjectWorkIsComplete")); |
|
736 TBool mustBeComplete = EFalse; |
|
737 if (!GetBoolFromConfig(aSection, KMustBeComplete(), mustBeComplete)) |
|
738 { |
|
739 ERR_PRINTF2(_L("No parameter %S"), &KMustBeComplete()); |
|
740 SetBlockResult(EFail); |
|
741 } |
|
742 |
|
743 if (Outstanding() == mustBeComplete) |
|
744 { |
|
745 ERR_PRINTF3(_L("Outstanding status is not as expected. expected=%d, actual=%d"), mustBeComplete, !Outstanding()); |
|
746 SetBlockResult(EFail); |
|
747 } |
|
748 } |
|
749 |
|
750 |
|
751 void CTe_RegBlockTestWrapper::DoCmdWriteIntToConfig(const TTEFSectionName& aSection) |
|
752 { |
|
753 INFO_PRINTF1(_L("Test WriteIntToConfig...")); |
|
754 TInt intValue = 36; |
|
755 TInt getIntValue = 0; |
|
756 GetIntFromConfig(aSection, KWriteIntValue, getIntValue); |
|
757 TESTA(intValue!=getIntValue); |
|
758 WriteIntToConfig(aSection, KWriteIntValue, intValue); |
|
759 intValue = 0; |
|
760 GetIntFromConfig(aSection, KWriteIntValue, intValue); |
|
761 TESTA(intValue==36); |
|
762 WriteIntToConfig(aSection, KWriteIntValue, getIntValue); |
|
763 } |
|
764 |
|
765 void CTe_RegBlockTestWrapper::DoCmdWriteBoolToConfig(const TTEFSectionName& aSection) |
|
766 { |
|
767 INFO_PRINTF1(_L("Test WriteBoolToConfig...")); |
|
768 TBool boolValue = EFalse; |
|
769 TBool getBoolValue = EFalse; |
|
770 GetBoolFromConfig(aSection, KWriteBoolValue, getBoolValue); |
|
771 TESTA(boolValue!=getBoolValue); |
|
772 WriteBoolToConfig(aSection, KWriteBoolValue, boolValue); |
|
773 boolValue = ETrue; |
|
774 GetBoolFromConfig(aSection, KWriteBoolValue, boolValue); |
|
775 TESTA(!boolValue); |
|
776 WriteBoolToConfig(aSection, KWriteBoolValue, getBoolValue); |
|
777 } |
|
778 |
|
779 void CTe_RegBlockTestWrapper::DoCmdWriteHexToConfig(const TTEFSectionName& aSection) |
|
780 { |
|
781 INFO_PRINTF1(_L("Test WriteHexToConfig...")); |
|
782 TInt hexValue = 0x00AB; |
|
783 TInt getHexValue = 0; |
|
784 GetHexFromConfig(aSection, KWriteHexValue, getHexValue); |
|
785 TESTA(hexValue!=getHexValue); |
|
786 WriteHexToConfig(aSection, KWriteHexValue, hexValue); |
|
787 hexValue = 0; |
|
788 GetHexFromConfig(aSection, KWriteHexValue, hexValue); |
|
789 TESTA(hexValue==0xAB); |
|
790 WriteHexToConfig(aSection, KWriteHexValue, getHexValue); |
|
791 } |
|
792 |
|
793 void CTe_RegBlockTestWrapper::DoCmdWriteStringToConfig(const TTEFSectionName& aSection) |
|
794 { |
|
795 INFO_PRINTF1(_L("Test WriteStringToConfig...")); |
|
796 _LIT(KChangedString, "Here is the changed string"); |
|
797 TPtrC string; |
|
798 TPtrC getString; |
|
799 TBuf<64> stringBuf; |
|
800 GetStringFromConfig(aSection, KWriteStringValue, getString); |
|
801 stringBuf.Copy(getString); |
|
802 TESTA(getString!=KChangedString()); |
|
803 WriteStringToConfig(aSection, KWriteStringValue, KChangedString()); |
|
804 GetStringFromConfig(aSection, KWriteStringValue, string); |
|
805 TESTA(string==KChangedString()); |
|
806 WriteStringToConfig(aSection, KWriteStringValue, stringBuf); |
|
807 } |
|
808 |
|
809 void CTe_RegBlockTestWrapper::DoCmdWriteSharedData() |
|
810 { |
|
811 INFO_PRINTF1(_L("Test WriteSharedDataL...")); |
|
812 TPtrC sharedValue(KSharedValue); |
|
813 CTestSharedData* sharedObject = NULL; |
|
814 CTEFSharedData<CTestSharedData>::NewL(sharedObject, 64, KSharedName); |
|
815 TRAPD(err, WriteSharedDataL(KSharedName, sharedValue, ESetText)); |
|
816 TESTA(err==KErrNone); |
|
817 } |
|
818 |
|
819 void CTe_RegBlockTestWrapper::DoCmdReadSharedData() |
|
820 { |
|
821 INFO_PRINTF1(_L("Test ReadSharedDataL...")); |
|
822 TBuf<64> sharedData; |
|
823 TRAP_IGNORE(ReadSharedDataL(KSharedName, sharedData)); |
|
824 TESTA(sharedData==KSharedValue); |
|
825 } |
|
826 |
|
827 void CTe_RegBlockTestWrapper::DoCmdTestNullController(const TTEFSectionName& aSection) |
|
828 { |
|
829 INFO_PRINTF1(_L("Test with null controller...")); |
|
830 CTe_RegBlockTestWrapper* testWrapper = new (ELeave) CTe_RegBlockTestWrapper(); |
|
831 TBool testRet = ETrue; |
|
832 |
|
833 TInt getIntValue = 0; |
|
834 testRet = testWrapper->WriteIntToConfig(aSection, KWriteIntValue, getIntValue); |
|
835 getIntValue = 10; |
|
836 testRet |= testWrapper->GetIntFromConfig(aSection, KWriteIntValue, getIntValue); |
|
837 TESTA(!testRet && 10==getIntValue); |
|
838 |
|
839 testRet = ETrue; |
|
840 TBool getBoolValue = EFalse; |
|
841 testRet = testWrapper->WriteBoolToConfig(aSection, KWriteBoolValue, getBoolValue); |
|
842 getBoolValue = ETrue; |
|
843 testRet |= testWrapper->GetBoolFromConfig(aSection, KWriteBoolValue, getBoolValue); |
|
844 TESTA(!testRet && getBoolValue); |
|
845 |
|
846 testRet = ETrue; |
|
847 TInt getHexValue = 0; |
|
848 testRet = testWrapper->WriteHexToConfig(aSection, KWriteHexValue, getHexValue); |
|
849 getHexValue = 0xFFFF; |
|
850 testRet |= testWrapper->GetHexFromConfig(aSection, KWriteHexValue, getHexValue); |
|
851 TESTA(!testRet && 0xFFFF==getHexValue); |
|
852 |
|
853 testRet = ETrue; |
|
854 TPtrC getString = KNullDesC(); |
|
855 testRet = testWrapper->WriteStringToConfig(aSection, KWriteStringValue, getString); |
|
856 _LIT(KString, "String"); |
|
857 getString.Set(KString()); |
|
858 testRet |= testWrapper->GetStringFromConfig(aSection, KWriteStringValue, getString); |
|
859 TESTA(!testRet && getString==KString()); |
|
860 |
|
861 delete testWrapper; |
|
862 } |
|
863 void CTe_RegBlockTestWrapper::RunL(CActive* aActive, TInt aIndex) |
|
864 { |
|
865 INFO_PRINTF1(_L("CTe_RegBlockTestWrapper::RunL")); |
|
866 TInt err = aActive->iStatus.Int(); |
|
867 SetAsyncError( aIndex, err ); |
|
868 DecOutstanding(); |
|
869 } |
|
870 |
|
871 |
|
872 /** Reads drive mapping operation name from INI-file */ |
|
873 TBool CTe_RegBlockTestWrapper::GetVerdictFromConfig(const TDesC& aSection, const TDesC& aParameterName, TVerdict& aVerdict) |
|
874 { |
|
875 // Read drives mapping operation name from INI file |
|
876 TPtrC verdictStr; |
|
877 TBool ret = GetStringFromConfig(aSection, aParameterName, verdictStr); |
|
878 if (ret) |
|
879 { |
|
880 if (verdictStr == KPass()) |
|
881 { |
|
882 aVerdict = EPass; |
|
883 } |
|
884 else if (verdictStr == KFail()) |
|
885 { |
|
886 aVerdict = EFail; |
|
887 } |
|
888 else |
|
889 { |
|
890 TInt verdict = 0; |
|
891 ret = GetIntFromConfig(aSection, aParameterName, verdict); |
|
892 if (ret) |
|
893 { |
|
894 aVerdict = (TVerdict) verdict; |
|
895 } |
|
896 } |
|
897 } |
|
898 |
|
899 return ret; |
|
900 } |
|
901 |