|
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 * Contains the CTestStep base class implementation |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 /** |
|
22 @file TestStepBase.cpp |
|
23 */ |
|
24 |
|
25 #include "testexecutestepbase.h" |
|
26 |
|
27 /** |
|
28 * Default virtual implementation for pre-processing within test steps |
|
29 * Virtual - May be overidden by subclass |
|
30 * @return One of TVerdict enum values defined |
|
31 */ |
|
32 EXPORT_C enum TVerdict CTestStep::doTestStepPreambleL(void) |
|
33 { |
|
34 SetTestStepResult(EPass); |
|
35 SetTestStepError(0); |
|
36 return TestStepResult(); |
|
37 } |
|
38 |
|
39 /** |
|
40 * Default virtual implementation for post-processing within test steps |
|
41 * Virtual - May be overidden by subclass |
|
42 * @return One of TVerdict enum values defined |
|
43 */ |
|
44 EXPORT_C enum TVerdict CTestStep::doTestStepPostambleL(void) |
|
45 { |
|
46 return TestStepResult(); |
|
47 } |
|
48 |
|
49 /** |
|
50 * Sets the current heap's to fail upon the subsequent "aFailureIndex" attempt |
|
51 * Virtual - may be overridden by derived test step |
|
52 * @param aFailureIndex - Index within heap allocation table that needs to be failed |
|
53 */ |
|
54 EXPORT_C void CTestStep::SetHeapFailNext(TInt aFailureIndex) |
|
55 { |
|
56 if (aFailureIndex >= 0) |
|
57 { |
|
58 __UHEAP_FAILNEXT(aFailureIndex); |
|
59 } |
|
60 } |
|
61 |
|
62 /** |
|
63 * Resets the the current heap's simulated "fail next" mode (if active) |
|
64 * Virtual - may be overridden by derived test step |
|
65 */ |
|
66 EXPORT_C void CTestStep::ResetHeapFailNext() |
|
67 { |
|
68 __UHEAP_RESET; |
|
69 } |
|
70 |
|
71 /** |
|
72 * Tests whether the current heap is in "fail next" mode. Used to check whether |
|
73 * the code-under-test has "consumed" the simulated failure when OOM looping. |
|
74 * Virtual - may be overridden by derived test step |
|
75 * @return Boolean true if code has comsumed a simulated failure, false otherwise |
|
76 */ |
|
77 EXPORT_C TBool CTestStep::CheckForHeapFailNext() |
|
78 { |
|
79 TBool finishedCorrectly(EFalse); |
|
80 TInt* myInt = new TInt; |
|
81 if (myInt == NULL) |
|
82 finishedCorrectly = ETrue; // NULL means no memory |
|
83 delete myInt; |
|
84 return finishedCorrectly; |
|
85 } |
|
86 |
|
87 /** |
|
88 * Destructor |
|
89 * Only heap resource is the Ini file data |
|
90 */ |
|
91 EXPORT_C CTestStep::~CTestStep() |
|
92 { |
|
93 CloseLogger(); |
|
94 delete iConfigData; |
|
95 delete iIniFileName; |
|
96 delete iLogger ; |
|
97 } |
|
98 |
|
99 /** |
|
100 * Constructor |
|
101 */ |
|
102 EXPORT_C CTestStep::CTestStep() |
|
103 { |
|
104 // current logger can't using to log infomation. |
|
105 // because SetLoggerL must called before write logs. |
|
106 // the initial operation codes at SetLoggerL() |
|
107 iLogger = new CTestExecuteLogger(); |
|
108 } |
|
109 |
|
110 /** |
|
111 * Called by server base code that loads the test step |
|
112 * Can be called multiple times for any loaded test step instance. |
|
113 * Sets up the instance variables |
|
114 * @param aStepArgs - The arguments to the RUN_TEST_STEP command |
|
115 * @param aServerName - Name of the server that requested initialisation of its test step object |
|
116 * @param aSharedDataMode - Boolean true or false indicating the mode in which the test step is running |
|
117 * @Leave system wide errors |
|
118 */ |
|
119 void CTestStep::InitialiseL(const TDesC& aStepArgs, const TDesC& aServerName, TBool& aSharedDataMode) |
|
120 { |
|
121 // Assume pass |
|
122 iTestStepResult = EPass; |
|
123 iSharedDataMode = aSharedDataMode; |
|
124 iSection.SetLength(0); |
|
125 // In the case of re-initialise we need to free the existing resource |
|
126 if(iIniFileName) |
|
127 { |
|
128 delete iIniFileName; |
|
129 iIniFileName = NULL; |
|
130 } |
|
131 if(iConfigData) |
|
132 { |
|
133 delete iConfigData; |
|
134 iConfigData = NULL; |
|
135 } |
|
136 |
|
137 TLex lex(aStepArgs); |
|
138 |
|
139 // Extract the first token for OOM request status |
|
140 TPtrC oomRequestString(lex.NextToken()); |
|
141 _LIT(KTEFOomOff,"OOM=0"); |
|
142 if (oomRequestString.CompareF(KTEFOomOff) == 0) |
|
143 { |
|
144 // Not required to run OOM tests if OOM=0 |
|
145 iOOMRequestStatus = EFalse; |
|
146 } |
|
147 else |
|
148 { |
|
149 // Required to run OOM tests if OOM=1 |
|
150 iOOMRequestStatus = ETrue; |
|
151 } |
|
152 |
|
153 // Extract the second token for !Setup value |
|
154 TLex setupParamValue(lex.NextToken().Mid(7)); |
|
155 TInt err = setupParamValue.Val(iSetupParamValue); |
|
156 if (err != KErrNone) |
|
157 { |
|
158 iSetupParamValue = TTestSetupState(ESetupNone); |
|
159 } |
|
160 |
|
161 // Extract the third token from aStepArgs for loop index |
|
162 TLex loopIndex(lex.NextToken()); |
|
163 loopIndex.Val(iLoopIndex); |
|
164 |
|
165 iTestCaseID.Copy(lex.NextToken()); |
|
166 |
|
167 TPtrC path(lex.NextToken()); |
|
168 iScriptDriveName.Copy(path); |
|
169 |
|
170 path.Set(lex.NextToken()); |
|
171 iSystemDrive.Copy(path); |
|
172 |
|
173 path.Set(lex.NextToken()); |
|
174 iSystemDriveForTest.Copy(path); |
|
175 |
|
176 // Set the logger instance |
|
177 //before SetLogger(). iSystemDrive is needed, because SetLogger() will using iSystemDrive |
|
178 //before LoadConfigFileL(). SetLogger() is needed, because LoadConfigFileL() may needs write logs. |
|
179 SetLoggerL(); |
|
180 // Get the ini file name if any |
|
181 TPtrC configFile(lex.NextToken()); |
|
182 if(configFile.Length()) |
|
183 { |
|
184 LoadConfigFileL(configFile); |
|
185 TPtrC iniSection(lex.NextToken()); |
|
186 // In the case of re-initialise zero the old one |
|
187 ConfigSection().SetLength(0); |
|
188 // Get the ini section name if any |
|
189 if(iniSection.Length() && iniSection.Length() <= ConfigSection().MaxLength()) |
|
190 ConfigSection().Copy(iniSection); |
|
191 } |
|
192 // Set the inifile name. |
|
193 iIniFileName = configFile.AllocL(); |
|
194 // Set the server name |
|
195 iServerName = aServerName; |
|
196 } |
|
197 |
|
198 /** |
|
199 * Creates a Cinidata instance for the ini file path specified for a particular test step |
|
200 * @param aFilePath - Full pathname of the ini file |
|
201 * @Leave system wide errors |
|
202 */ |
|
203 void CTestStep::LoadConfigFileL(const TDesC& aFilePath) |
|
204 { |
|
205 if(!aFilePath.Length()) |
|
206 User::Leave(KErrNotFound); |
|
207 |
|
208 // Pass the system drive letter finalised to the Cinidata construction |
|
209 // So, that the ini files can be expanded for the ${SYSDRIVE} variables |
|
210 TRAPD(err,iConfigData = CIniData::NewL(aFilePath, GetSystemDrive())); |
|
211 if(err != KErrNone) |
|
212 { |
|
213 //defect 121613: TEF will report ini file too large |
|
214 ERR_PRINTF3(_L("Leave when loading %S . Error Code = %d"),&aFilePath,err); |
|
215 // This is a hit message to user to split ini file to smaller one |
|
216 if (err == KErrNoMemory ) // -4 |
|
217 { |
|
218 _LIT(KTEFLOADINIFILENOENOUGHMEM,"The configuration file is too large that TEF don't have enough memory to load. Please consider split the configuration file into smaller one or load the file in your own test codes."); |
|
219 INFO_PRINTF1(KTEFLOADINIFILENOENOUGHMEM); |
|
220 } |
|
221 User::Leave(err); |
|
222 } |
|
223 } |
|
224 |
|
225 /** |
|
226 * Reads the value present from the test steps ini file within the mentioned section name and key name |
|
227 * Copies the value to the TBool reference passed in |
|
228 * @param aSectName - Section within the test steps ini file |
|
229 * @param aKeyName - Name of a key within a section |
|
230 * @return aResult - The value of the boolean |
|
231 * @return TBool - ETrue for found, EFalse for not found |
|
232 */ |
|
233 EXPORT_C TBool CTestStep::GetBoolFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TBool& aResult) |
|
234 { |
|
235 TPtrC result; |
|
236 if(!iConfigData) |
|
237 return EFalse; |
|
238 if(!iConfigData->FindVar(aSectName, aKeyName, result)) |
|
239 return EFalse; |
|
240 _LIT(KTrue,"true"); |
|
241 if (result.FindF(KTrue) == KErrNotFound) |
|
242 aResult = EFalse; |
|
243 else |
|
244 aResult = ETrue; |
|
245 |
|
246 if (iEnableIniAccessLog) |
|
247 { |
|
248 INFO_PRINTF5(KTEFIniReadInteger,iIniFileName, &aSectName, &aKeyName , aResult); |
|
249 } |
|
250 return(ETrue); |
|
251 } |
|
252 |
|
253 /** |
|
254 * Reads the value present from the test steps ini file within the mentioned section name and key name |
|
255 * Copies the value to the TInt reference passed in |
|
256 * @param aSectName - Section within the test steps ini file |
|
257 * @param aKeyName - Name of a key within a section |
|
258 * @return aResult - The value of the integer |
|
259 * @return TBool - ETrue for found, EFalse for not found |
|
260 */ |
|
261 EXPORT_C TBool CTestStep::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
262 { |
|
263 if(!iConfigData) |
|
264 return EFalse; |
|
265 if(!iConfigData->FindVar(aSectName, aKeyName, aResult)) |
|
266 return EFalse; |
|
267 if (iEnableIniAccessLog) |
|
268 { |
|
269 INFO_PRINTF5(KTEFIniReadInteger,iIniFileName, &aSectName, &aKeyName , aResult); |
|
270 } |
|
271 return ETrue; |
|
272 } |
|
273 /** |
|
274 * Reads the value present from the test steps ini file within the mentioned section name and key name |
|
275 * Copies the value to the TInt64 reference passed in |
|
276 * @param aSectName - Section within the test steps ini file |
|
277 * @param aKeyName - Name of a key within a section |
|
278 * @return aResult - The value of the 64-bit integer |
|
279 * @return TBool - ETrue for found, EFalse for not found |
|
280 */ |
|
281 EXPORT_C TBool CTestStep::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt64& aResult) |
|
282 { |
|
283 if(!iConfigData) |
|
284 return EFalse; |
|
285 if(!iConfigData->FindVar(aSectName, aKeyName, aResult)) |
|
286 return EFalse; |
|
287 if (iEnableIniAccessLog) |
|
288 { |
|
289 INFO_PRINTF5(KTEFIniReadInt64,iIniFileName, &aSectName, &aKeyName , aResult); |
|
290 } |
|
291 return ETrue; |
|
292 } |
|
293 |
|
294 /** |
|
295 * Reads the value present from the test steps ini file within the mentioned section name and key name |
|
296 * Copies the value to the TPtrC reference passed in |
|
297 * @param aSectName - Section within the test steps ini file |
|
298 * @param aKeyName - Name of a key within a section |
|
299 * @return aResult - Reference to the string on the heap |
|
300 * @return TBool - ETrue for found, EFalse for not found |
|
301 */ |
|
302 EXPORT_C TBool CTestStep::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) |
|
303 { |
|
304 if(!iConfigData) |
|
305 return EFalse; |
|
306 if(!iConfigData->FindVar(aSectName, aKeyName, aResult)) |
|
307 return EFalse; |
|
308 if (iEnableIniAccessLog) |
|
309 { |
|
310 INFO_PRINTF5(KTEFIniReadString,iIniFileName, &aSectName, &aKeyName , &aResult); |
|
311 } |
|
312 return ETrue; |
|
313 } |
|
314 |
|
315 /** |
|
316 * Reads the value present from the test steps ini file within the mentioned section name and key name |
|
317 * Copies the value to the TInt reference passed in |
|
318 * @param aSectName - Section within the test steps ini file |
|
319 * @param aKeyName - Name of a key within a section |
|
320 * @return aResult - The integer value of the Hex input |
|
321 * @return TBool - ETrue for found, EFalse for not found |
|
322 */ |
|
323 EXPORT_C TBool CTestStep::GetHexFromConfig(const TDesC& aSectName,const TDesC& aKeyName,TInt& aResult) |
|
324 { |
|
325 TPtrC result; |
|
326 if(!iConfigData) |
|
327 return EFalse; |
|
328 if(!iConfigData->FindVar(aSectName, aKeyName, result)) |
|
329 return EFalse; |
|
330 TLex lex(result); |
|
331 TInt err = lex.Val((TUint &)aResult, EHex); |
|
332 if(err) |
|
333 return EFalse; |
|
334 if (iEnableIniAccessLog) |
|
335 { |
|
336 INFO_PRINTF5(KTEFIniReadInteger,iIniFileName, &aSectName, &aKeyName , aResult); |
|
337 } |
|
338 return(ETrue); |
|
339 } |
|
340 |
|
341 /** |
|
342 * Writes the integer value passed in to the test steps ini file under the section and key name mentioned |
|
343 * Creates a new section or key name if it does not existing already |
|
344 * @param aSectName - Section within the test steps ini file |
|
345 * @param aKeyName - Name of a key within a section |
|
346 * @return aValue - Reference to the integer to be written on to the test steps ini file |
|
347 * @return TBool - ETrue for found, EFalse for not found |
|
348 */ |
|
349 EXPORT_C TBool CTestStep::WriteIntToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TInt& aValue) |
|
350 { |
|
351 TBuf<KMaxTestExecuteNameLength> value; |
|
352 TBool retVal(ETrue); |
|
353 TInt err(KErrNone); |
|
354 value.AppendNum(aValue); |
|
355 |
|
356 if(!iConfigData) |
|
357 { |
|
358 retVal = EFalse; |
|
359 } |
|
360 else if(iConfigData->SetValue(aSectName,aKeyName,value)==KErrNotFound) |
|
361 { |
|
362 err = iConfigData->AddValue(aSectName,aKeyName,value); |
|
363 } |
|
364 |
|
365 if(retVal && KErrNone==err) |
|
366 { |
|
367 TRAP(err, iConfigData->WriteToFileL()); |
|
368 if (iEnableIniAccessLog) |
|
369 { |
|
370 if (KErrNone == err) |
|
371 { |
|
372 INFO_PRINTF5(KTEFIniWriteInteger,iIniFileName, &aSectName, &aKeyName , aValue); |
|
373 } |
|
374 } |
|
375 } |
|
376 |
|
377 if (!retVal || KErrNone!=err) |
|
378 { |
|
379 retVal = EFalse; |
|
380 if (iEnableIniAccessLog) |
|
381 { |
|
382 _LIT(KWriteIntegerError, "Error occurs when writing integer to file, error code=%d"); |
|
383 ERR_PRINTF2(KWriteIntegerError, err); |
|
384 } |
|
385 } |
|
386 return retVal; |
|
387 } |
|
388 /** |
|
389 * Writes the 64-bit integer value passed in to the test steps ini file under the section and key name mentioned |
|
390 * Creates a new section or key name if it does not existing already |
|
391 * @param aSectName - Section within the test steps ini file |
|
392 * @param aKeyName - Name of a key within a section |
|
393 * @return aValue - Reference to the 64-bit integer to be written on to the test steps ini file |
|
394 * @return TBool - ETrue for found, EFalse for not found |
|
395 */ |
|
396 EXPORT_C TBool CTestStep::WriteIntToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TInt64& aValue) |
|
397 { |
|
398 TBuf<KMaxTestExecuteNameLength> value; |
|
399 TBool retVal(ETrue); |
|
400 TInt err(KErrNone); |
|
401 value.AppendNum(aValue); |
|
402 |
|
403 if(!iConfigData) |
|
404 { |
|
405 retVal = EFalse; |
|
406 } |
|
407 else if(iConfigData->SetValue(aSectName,aKeyName,value)==KErrNotFound) |
|
408 { |
|
409 err = iConfigData->AddValue(aSectName,aKeyName,value); |
|
410 } |
|
411 |
|
412 if(retVal && KErrNone==err) |
|
413 { |
|
414 TRAP(err, iConfigData->WriteToFileL()); |
|
415 if (iEnableIniAccessLog) |
|
416 { |
|
417 if (KErrNone == err) |
|
418 { |
|
419 INFO_PRINTF5(KTEFIniWriteInt64,iIniFileName, &aSectName, &aKeyName , aValue); |
|
420 } |
|
421 } |
|
422 } |
|
423 |
|
424 if (!retVal || KErrNone!=err) |
|
425 { |
|
426 retVal = EFalse; |
|
427 if (iEnableIniAccessLog) |
|
428 { |
|
429 _LIT(KWriteIntegerError, "Error occurs when writing integer to file, error code=%d"); |
|
430 ERR_PRINTF2(KWriteIntegerError, err); |
|
431 } |
|
432 } |
|
433 return retVal; |
|
434 } |
|
435 |
|
436 /** |
|
437 * Writes the string value passed in to the test steps ini file under the section and key name mentioned |
|
438 * Creates a new section or key name if it does not existing already |
|
439 * @param aSectName - Section within the test steps ini file |
|
440 * @param aKeyName - Name of a key within a section |
|
441 * @return aValue - Reference to the string to be written on to the test steps ini file |
|
442 * @return TBool - ETrue for found, EFalse for not found |
|
443 */ |
|
444 EXPORT_C TBool CTestStep::WriteStringToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TPtrC& aValue) |
|
445 { |
|
446 TBool retVal(ETrue); |
|
447 TInt err(KErrNone); |
|
448 |
|
449 if(!iConfigData) |
|
450 { |
|
451 retVal = EFalse; |
|
452 } |
|
453 else if(iConfigData->SetValue(aSectName,aKeyName,aValue)==KErrNotFound) |
|
454 { |
|
455 err = iConfigData->AddValue(aSectName,aKeyName,aValue); |
|
456 } |
|
457 |
|
458 if(retVal && KErrNone==err) |
|
459 { |
|
460 TRAP(err, iConfigData->WriteToFileL()); |
|
461 if (iEnableIniAccessLog) |
|
462 { |
|
463 if (KErrNone == err) |
|
464 { |
|
465 INFO_PRINTF5(KTEFIniWriteString,iIniFileName, &aSectName, &aKeyName , &aValue); |
|
466 } |
|
467 } |
|
468 } |
|
469 |
|
470 if (!retVal || KErrNone!=err) |
|
471 { |
|
472 retVal = EFalse; |
|
473 if (iEnableIniAccessLog) |
|
474 { |
|
475 _LIT(KWriteIntegerError, "Error occurs when writing string to file, error code=%d"); |
|
476 ERR_PRINTF2(KWriteIntegerError, err); |
|
477 } |
|
478 } |
|
479 return retVal; |
|
480 } |
|
481 |
|
482 /** |
|
483 * Writes the boolean value passed in to the test steps ini file under the section and key name mentioned |
|
484 * Creates a new section or key name if it does not existing already |
|
485 * @param aSectName - Section within the test steps ini file |
|
486 * @param aKeyName - Name of a key within a section |
|
487 * @return aValue - Reference to the boolean value to be written onto the test steps ini file |
|
488 * @return TBool - ETrue for found, EFalse for not found |
|
489 */ |
|
490 EXPORT_C TBool CTestStep::WriteBoolToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TBool& aValue) |
|
491 { |
|
492 TBuf<KMaxTestExecuteNameLength> value; |
|
493 TBool retVal(ETrue); |
|
494 TInt err(KErrNone); |
|
495 if(aValue==1) |
|
496 { |
|
497 _LIT(KTrue,"True"); |
|
498 value.Append(KTrue); |
|
499 } |
|
500 else if(aValue==0) |
|
501 { |
|
502 _LIT(KFalse,"False"); |
|
503 value.Append(KFalse); |
|
504 } |
|
505 else |
|
506 { |
|
507 return(EFalse); |
|
508 } |
|
509 |
|
510 if(!iConfigData) |
|
511 { |
|
512 retVal = EFalse; |
|
513 } |
|
514 else if(iConfigData->SetValue(aSectName,aKeyName,value)==KErrNotFound) |
|
515 { |
|
516 err = iConfigData->AddValue(aSectName,aKeyName,value); |
|
517 } |
|
518 |
|
519 if(retVal && KErrNone==err) |
|
520 { |
|
521 TRAP(err, iConfigData->WriteToFileL()); |
|
522 if (iEnableIniAccessLog) |
|
523 { |
|
524 if (KErrNone == err) |
|
525 { |
|
526 INFO_PRINTF5(KTEFIniWriteInteger,iIniFileName, &aSectName, &aKeyName , aValue); |
|
527 } |
|
528 } |
|
529 } |
|
530 |
|
531 if (!retVal || KErrNone!=err) |
|
532 { |
|
533 retVal = EFalse; |
|
534 if (iEnableIniAccessLog) |
|
535 { |
|
536 _LIT(KWriteIntegerError, "Error occurs when writing bool to file, error code=%d"); |
|
537 ERR_PRINTF2(KWriteIntegerError, err); |
|
538 } |
|
539 } |
|
540 return retVal; |
|
541 } |
|
542 |
|
543 /** |
|
544 * Writes the hex equivalent of the integer value passed in to the test steps ini file |
|
545 * under the section and key name mentioned |
|
546 * Creates a new section or key name if it does not existing already |
|
547 * @param aSectName - Section within the test steps ini file |
|
548 * @param aKeyName - Name of a key within a section |
|
549 * @return aValue - Reference to the integer equivalent of the hex value to be written onto the test steps ini file |
|
550 * @return TBool - ETrue for found, EFalse for not found |
|
551 */ |
|
552 EXPORT_C TBool CTestStep::WriteHexToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TInt& aValue) |
|
553 { |
|
554 TBuf<KMaxTestExecuteNameLength> value; |
|
555 TBool retVal(ETrue); |
|
556 TInt err(KErrNone); |
|
557 value.Num(aValue,EHex); |
|
558 |
|
559 if(!iConfigData) |
|
560 { |
|
561 retVal = EFalse; |
|
562 } |
|
563 else if(iConfigData->SetValue(aSectName,aKeyName,value)==KErrNotFound) |
|
564 { |
|
565 iConfigData->AddValue(aSectName,aKeyName,value); |
|
566 } |
|
567 |
|
568 if(retVal && KErrNone==err) |
|
569 { |
|
570 TRAP(err, iConfigData->WriteToFileL()); |
|
571 if (iEnableIniAccessLog) |
|
572 { |
|
573 if (KErrNone == err) |
|
574 { |
|
575 INFO_PRINTF5(KTEFIniWriteInteger,iIniFileName, &aSectName, &aKeyName , aValue); |
|
576 } |
|
577 } |
|
578 } |
|
579 |
|
580 if (!retVal || KErrNone!=err) |
|
581 { |
|
582 retVal = EFalse; |
|
583 if (iEnableIniAccessLog) |
|
584 { |
|
585 _LIT(KWriteIntegerError, "Error occurs when writing hex to file, error code=%d"); |
|
586 ERR_PRINTF2(KWriteIntegerError, err); |
|
587 } |
|
588 } |
|
589 return retVal; |
|
590 } |
|
591 |
|
592 /** |
|
593 * Updates the data to the shared data name passed either in Copy Mode/Append Mode |
|
594 * @param aShareName - Shared data name to be written |
|
595 * @param aSharedDataVal - Descriptor value to be used for updating the shared data |
|
596 * @param aModeCopy - Enum value indicating the descriptor value to be overwritten/appended |
|
597 * @Leave system wide errors |
|
598 */ |
|
599 EXPORT_C void CTestStep::WriteSharedDataL(const TDesC& aShareName, TDesC& aSharedDataVal, TModeCopy aModeCopy) |
|
600 { |
|
601 CTestSharedData* sharedObject = NULL; |
|
602 CTEFSharedData<CTestSharedData>* sharedData1 = CTEFSharedData<CTestSharedData>::NewLC(sharedObject, aShareName); |
|
603 sharedData1->EnterCriticalSection(); |
|
604 switch(aModeCopy) |
|
605 { |
|
606 case ESetText: |
|
607 { |
|
608 sharedObject->SetText(aSharedDataVal); |
|
609 break; |
|
610 } |
|
611 case EAppendText: |
|
612 { |
|
613 sharedObject->AppendText(aSharedDataVal); |
|
614 break; |
|
615 } |
|
616 default: |
|
617 break; |
|
618 } |
|
619 sharedData1->ExitCriticalSection(); |
|
620 CleanupStack::PopAndDestroy(sharedData1); |
|
621 } |
|
622 |
|
623 /** |
|
624 * Reads the data from the specified shared data object |
|
625 * Copies it to the reference descriptor passed in |
|
626 * @param aShareName - Shared Data Name to be read |
|
627 * @param aSharedDataVal - Descriptor reference passed in for reading the data from shared data |
|
628 * @Leave system wide errors |
|
629 */ |
|
630 EXPORT_C void CTestStep::ReadSharedDataL(const TDesC& aShareName, TDes& aSharedDataVal) |
|
631 { |
|
632 CTestSharedData* sharedObject = NULL; |
|
633 CTEFSharedData<CTestSharedData>* sharedData1 = CTEFSharedData<CTestSharedData>::NewLC(sharedObject, aShareName); |
|
634 sharedData1->EnterCriticalSection(); |
|
635 sharedObject->GetText(aSharedDataVal); |
|
636 sharedData1->ExitCriticalSection(); |
|
637 CleanupStack::PopAndDestroy(sharedData1); |
|
638 } |
|
639 |
|
640 /** |
|
641 * Sets the test step class with a user-friendly name to be referred from the script file |
|
642 * @param aStepName - Name of the test step |
|
643 */ |
|
644 EXPORT_C void CTestStep::SetTestStepName(const TDesC& aStepName) |
|
645 { |
|
646 iTestStepName.Copy(aStepName); |
|
647 } |
|
648 |
|
649 /** |
|
650 * Used to set the actual error value within the test step object |
|
651 * @param aStepError - Test Step Error |
|
652 */ |
|
653 EXPORT_C void CTestStep::SetTestStepError(const TInt& aStepError) |
|
654 { |
|
655 iTestStepError = aStepError; |
|
656 if (aStepError < 0) |
|
657 SetTestStepResult(EFail); |
|
658 } |
|
659 |
|
660 /** |
|
661 * Initialise the File Logger server |
|
662 * Secure and Non-secure variants |
|
663 * @Leave system wide errors |
|
664 */ |
|
665 void CTestStep::SetLoggerL() |
|
666 { |
|
667 if(iLogger) |
|
668 { |
|
669 CloseLogger(); |
|
670 delete iLogger ; |
|
671 iLogger = NULL; |
|
672 } |
|
673 TRAPD(err1,iLogger = CTestExecuteLogger::NewL()); |
|
674 if(err1 != KErrNone) |
|
675 { |
|
676 User::Leave(err1); |
|
677 } |
|
678 |
|
679 // Create a cinidata object for parsing the testexecute.ini |
|
680 CTestExecuteIniData* parseTestExecuteIni = NULL; |
|
681 TBuf<KMaxTestExecuteNameLength> resultFilePath; |
|
682 TBuf<KMaxTestExecuteNameLength> xmlFilePath; |
|
683 TInt logMode; |
|
684 TInt loggerChannel ; |
|
685 TInt logLevel; |
|
686 TInt ChanneloutPort;// serial port |
|
687 |
|
688 TRAPD(err,parseTestExecuteIni = CTestExecuteIniData::NewL(iSystemDrive)); |
|
689 if (err == KErrNone) |
|
690 { |
|
691 CleanupStack::PushL(parseTestExecuteIni); |
|
692 parseTestExecuteIni->ExtractValuesFromIni(); |
|
693 parseTestExecuteIni->GetKeyValueFromIni(KTEFHtmlKey, resultFilePath); |
|
694 parseTestExecuteIni->GetKeyValueFromIni(KTEFXmlKey, xmlFilePath); |
|
695 parseTestExecuteIni->GetKeyValueFromIni(KTEFLogMode, logMode); |
|
696 parseTestExecuteIni->GetKeyValueFromIni(KTEFLogSeverityKey, logLevel); |
|
697 parseTestExecuteIni->GetKeyValueFromIni(KTEFEnableIniAccessLog, iEnableIniAccessLog); |
|
698 parseTestExecuteIni->GetKeyValueFromIni(KTEFLogChannel, loggerChannel); |
|
699 parseTestExecuteIni->GetKeyValueFromIni(KTEFOutputPort,ChanneloutPort); |
|
700 } |
|
701 else |
|
702 { |
|
703 TBuf<KMaxTestExecuteNameLength> testExecuteLogPath(KTestExecuteLogPath); |
|
704 testExecuteLogPath.Replace(0, 2, iSystemDrive); |
|
705 resultFilePath.Copy(testExecuteLogPath); |
|
706 xmlFilePath.Copy(testExecuteLogPath); |
|
707 logMode = TLoggerOptions(ELogHTMLOnly); |
|
708 logLevel = RFileFlogger::TLogSeverity(ESevrAll); |
|
709 iEnableIniAccessLog = ETrue; |
|
710 } |
|
711 Logger().SetLoggerOptions(logMode); |
|
712 Logger().SetLoggerChannel(loggerChannel) ; |
|
713 if( loggerChannel == ESerial || loggerChannel == EBoth) |
|
714 { |
|
715 //InitialiseLoggingL |
|
716 Logger().OpenSerialPortL(ChanneloutPort); |
|
717 } |
|
718 |
|
719 // Initialise a handle to the file logger |
|
720 User::LeaveIfError(Logger().Connect()); |
|
721 RFs fS; |
|
722 User::LeaveIfError(fS.Connect()); |
|
723 CleanupClosePushL(fS); |
|
724 RFile file; |
|
725 TBuf<KMaxTestExecuteNameLength> xmlLogFile(xmlFilePath); |
|
726 TBuf<KMaxTestStepNameLength> logFile; |
|
727 TBuf<KMaxTestExecuteNameLength> logFileNameFile(resultFilePath); |
|
728 logFileNameFile.Append(KTestExecuteScheduleTestLogCompatibilityNameFile); |
|
729 if(file.Open(fS,logFileNameFile,EFileRead | EFileShareAny) != KErrNone) |
|
730 { |
|
731 // For the old flogger we have to create an individual file |
|
732 logFile.Copy(iTestStepName); |
|
733 _LIT(KTxtExtension,".txt"); |
|
734 logFile.Append(KTxtExtension); |
|
735 logMode = TLoggerOptions(0); |
|
736 Logger().SetLoggerOptions(logMode); |
|
737 } |
|
738 else |
|
739 { |
|
740 CleanupClosePushL(file); |
|
741 TBuf8<KMaxTestExecuteNameLength> logFile8; |
|
742 TInt fileSize; |
|
743 User::LeaveIfError(file.Size(fileSize)); |
|
744 User::LeaveIfError(file.Read(logFile8,fileSize)); |
|
745 logFile.Copy(logFile8); |
|
746 xmlLogFile.Append(logFile); |
|
747 _LIT(KXmlExtension,".xml"); |
|
748 xmlLogFile.Append(KXmlExtension); |
|
749 _LIT(KHtmExtension,".htm"); |
|
750 logFile.Append(KHtmExtension); |
|
751 CleanupStack::Pop(&file); |
|
752 file.Close(); |
|
753 } |
|
754 TBuf<KMaxTestExecuteLogFilePath> logFilePath(resultFilePath); |
|
755 logFilePath.Append(logFile); |
|
756 CleanupStack::Pop(&fS); |
|
757 fS.Close(); |
|
758 |
|
759 if (logMode == 0 || logMode == 2) |
|
760 { |
|
761 TRAPD(err1,Logger().HtmlLogger().CreateLog(logFilePath,RTestExecuteLogServ::ELogModeAppend)); |
|
762 if(err1 != KErrPathNotFound) |
|
763 { |
|
764 User::LeaveIfError(err1) ; |
|
765 } |
|
766 else |
|
767 { |
|
768 // if its other than an htm file , ignore it |
|
769 _LIT(KHtmExtension,".htm"); |
|
770 if(logFilePath.Find(KHtmExtension)>-1) |
|
771 { |
|
772 User::LeaveIfError(err1) ; |
|
773 } |
|
774 } |
|
775 |
|
776 Logger().HtmlLogger().SetLogLevel(TLogSeverity(logLevel)); |
|
777 } |
|
778 if (logMode == 1 || logMode == 2) |
|
779 { |
|
780 User::LeaveIfError(Logger().XmlLogger().CreateLog(xmlLogFile,RFileFlogger::ELogModeAppend)); |
|
781 Logger().XmlLogger().SetLogLevel(RFileFlogger::TLogSeverity(logLevel)); |
|
782 } |
|
783 if (parseTestExecuteIni != NULL) |
|
784 { |
|
785 CleanupStack::PopAndDestroy(parseTestExecuteIni); |
|
786 } |
|
787 } |
|
788 |
|
789 /** |
|
790 * Just close our handle to Flogger |
|
791 */ |
|
792 void CTestStep::CloseLogger() |
|
793 { |
|
794 Logger().Close(); |
|
795 // if(iLogger) |
|
796 // { |
|
797 // delete iLogger; |
|
798 // iLogger = NULL; |
|
799 // } |
|
800 } |
|
801 |
|
802 /////// |
|
803 // LEGACY methods from scheduletest & autotest |
|
804 /////// |
|
805 EXPORT_C void CTestStep::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) |
|
806 ///< TEST(a) |
|
807 { |
|
808 if(TestStepResult() == EPass && !aCondition) // If not true, change to fail! |
|
809 { |
|
810 SetTestStepResult(EFail); |
|
811 _LIT(KMessage,"ERROR: Test Failed"); |
|
812 Logger().LogExtra(aFile, aLine, ESevrErr,KMessage); |
|
813 } |
|
814 } |
|
815 |
|
816 EXPORT_C void CTestStep::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine, TBool aIgnoreStepResult) |
|
817 ///< TEST(a) |
|
818 { |
|
819 if (aIgnoreStepResult) |
|
820 { |
|
821 if (!aCondition) |
|
822 { |
|
823 SetTestStepResult(EFail); |
|
824 _LIT(KMessage,"ERROR: Test Failed"); |
|
825 Logger().LogExtra(aFile, aLine, ESevrErr,KMessage); |
|
826 } |
|
827 } |
|
828 else |
|
829 { |
|
830 testBooleanTrue(aCondition, aFile, aLine); |
|
831 } |
|
832 } |
|
833 |
|
834 EXPORT_C void CTestStep::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine) |
|
835 ///< TESTL(a) |
|
836 { |
|
837 testBooleanTrue(aCondition, aFile, aLine); |
|
838 if(!aCondition) |
|
839 User::Leave(TEST_ERROR_CODE); // leave with standard error code |
|
840 } |
|
841 |
|
842 EXPORT_C void CTestStep::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine, TBool aIgnoreStepResult) |
|
843 ///< TESTL(a) |
|
844 { |
|
845 testBooleanTrue(aCondition, aFile, aLine, aIgnoreStepResult); |
|
846 if(!aCondition) |
|
847 User::Leave(TEST_ERROR_CODE); // leave with standard error code |
|
848 } |
|
849 |
|
850 EXPORT_C void CTestStep::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine) |
|
851 ///< TESTEL(a,b) |
|
852 { |
|
853 testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine); |
|
854 if(!aCondition) |
|
855 User::Leave(aErrorCode); |
|
856 } |
|
857 |
|
858 EXPORT_C void CTestStep::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine, TBool aIgnoreStepResult) |
|
859 ///< TESTEL(a,b) |
|
860 { |
|
861 testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine, aIgnoreStepResult); |
|
862 if(!aCondition) |
|
863 User::Leave(aErrorCode); |
|
864 } |
|
865 |
|
866 EXPORT_C void CTestStep::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine) |
|
867 ///< TESTE(a,b) |
|
868 { |
|
869 if(TestStepResult() == EPass && !aCondition) // If not true, change to fail! |
|
870 { |
|
871 SetTestStepResult(EFail); |
|
872 _LIT(KMessage,"Test Failed with error [%d]"); |
|
873 //START defect 116178 |
|
874 Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode); |
|
875 //END defect 116178 |
|
876 } |
|
877 } |
|
878 |
|
879 EXPORT_C void CTestStep::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine, TBool aIgnoreStepResult) |
|
880 ///< TESTE(a,b) |
|
881 { |
|
882 if (aIgnoreStepResult) |
|
883 { |
|
884 if(!aCondition) |
|
885 { |
|
886 SetTestStepResult(EFail); |
|
887 _LIT(KMessage,"Test Failed with error [%d]"); |
|
888 // START defect 116178 |
|
889 Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode); |
|
890 // END defect 116178 |
|
891 } |
|
892 } |
|
893 else |
|
894 { |
|
895 testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine); |
|
896 } |
|
897 } |
|
898 |
|
899 EXPORT_C void CTestStep::TestCheckPointCompareL(TInt aVal,TInt aExpectedVal, const TDesC& aText, const TText8* aFile,TInt aLine) |
|
900 { |
|
901 if(aVal != aExpectedVal) |
|
902 { |
|
903 // decode formated data for display on console |
|
904 TBuf <KMaxTestExecuteLogLineLength> LineBuf; |
|
905 _LIT(KMessage,"FAILED test: Val = %d Exp Val = %d %S"); |
|
906 LineBuf.AppendFormat(KMessage,aVal,aExpectedVal,&aText); |
|
907 // send the data to the log system via the suite |
|
908 Logger().LogExtra((TText8*)aFile, aLine, ESevrErr, LineBuf ); |
|
909 User::Leave(aVal); |
|
910 } |
|
911 } |
|
912 |
|
913 /** |
|
914 * Returns the server name that instantiated the test step |
|
915 * @return TDesC - CTestServer name |
|
916 */ |
|
917 EXPORT_C const TDesC& CTestStep::GetServerName() const |
|
918 { |
|
919 return iServerName; |
|
920 } |
|
921 |
|
922 /** |
|
923 * TestCaseName |
|
924 * Returns boolean true if testcase name is available, false otherwise. |
|
925 * Updates the TDes& to the testcase name if available, blank string otherwise. |
|
926 * @param aTestCaseName - TDes reference to update the test case name |
|
927 * @return TBool - Boolean value indicating presense of test case name |
|
928 */ |
|
929 EXPORT_C TBool CTestStep::TestCaseName(TDes& aTestCaseName) |
|
930 { |
|
931 if (iTestCaseID.CompareF(KTEFTestCaseDefault) == 0) |
|
932 { |
|
933 aTestCaseName.Copy(KTEFNull); |
|
934 return EFalse; |
|
935 } |
|
936 else |
|
937 { |
|
938 aTestCaseName.Copy(iTestCaseID); |
|
939 return ETrue; |
|
940 } |
|
941 } |