Update contrib.
2 // Copyright (c) 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 the License "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".
9 // Initial Contributors:
10 // Nokia Corporation - initial contribution.
19 #include "t_tefinput.h"
20 #include "t_errorconverter.h"
21 #include "tScriptSetup.h"
22 #include <securityerr.h>
23 #include <keystore_errs.h>
25 #ifdef SYMBIAN_AUTH_SERVER
26 #include <auth_srv_errs.h>
32 _LIT8(KNewline, "\n");
34 _LIT8(KCloseBrk, "]");
36 _LIT8(KUnderScore, "_");
37 _LIT8(KSectionIDTag, "[SEC");
39 #define KIniSectionIdLength 512
40 #define KResultLength 512
42 // Extracts RUN_TESTSTEP from the whole of script file passed in
44 EXPORT_C TPtrC8 Tefinput::ParseRunTestStep(const TDesC8& aBuf,
54 TPtrC8 data = aBuf.Mid(aPos);
56 tempPos = data.Find(aTag);
58 if (tempPos != KErrNotFound)
60 tempPos += aTag.Length();
62 TPtrC8 temprunStepData = data.Mid(tempPos);
64 endPos = temprunStepData.Find(KNewline);
65 if (endPos == KErrNotFound)
67 endPos = temprunStepData.Find(KReturn);
69 if (endPos == KErrNotFound)
71 endPos = temprunStepData.Length();
75 len = (endPos - startPos) + 1;
76 TPtrC8 runStepData = temprunStepData.Mid(startPos,len);
77 aPos += tempPos + runStepData.Length();
82 aError = KErrNotFound;
91 // Extracts the nth word from the given descritor
92 EXPORT_C TPtrC8 Tefinput::ParseNthElement(const TDesC8& aBuf,
98 TInt startPos = KErrNotFound, endPos = KErrNotFound;
100 TBool inWord = EFalse;
102 for(i = 0; i < aBuf.Length() ; i ++)
104 TPtrC8 tmpChar = aBuf.Mid(i,1);
105 if(tmpChar == KSpace || tmpChar == KTab || tmpChar == KReturn || tmpChar == KNewline )
109 if(wordCounter == aWordPos)
123 if(wordCounter == aWordPos)
131 if(startPos < 0 || endPos < 0)
133 aError = KErrNotFound;
138 return aBuf.Mid(startPos,(endPos-startPos+1));
142 // Extracts testCaseID from the whole script file
143 EXPORT_C TPtrC8 Tefinput::ParseTestCaseID(const TDesC8& aBuf,
153 TInt startPos = 0, endPos = 0;
157 TPtrC8 data = aBuf.Mid(aPos);
158 TInt len = aTag.Length();
159 startPos = data.Find(aTag);
161 TInt filePos = startPos + aPos;
163 if(startPos != KErrNotFound)
168 datatemp.Set(data.Mid(startPos));
170 endPos = datatemp.Find(KNewline);
171 if(endPos == KErrNotFound)
173 endPos = datatemp.Find(KReturn);
175 templen = endPos - temp;
176 testID.Set(datatemp.Mid(temp,templen));
177 filePos += testID.Length();
186 templen = endPos - temp;
187 testID.Set(datatemp.Mid(temp,templen));
188 filePos += testID.Length();
198 aError = KErrNotFound;
206 // Generates the path for .ini file from the .script file path
207 EXPORT_C TInt Tefinput::ParseiniPath(const TDesC8& aIniFileName,
208 const TDesC& aScriptPath,
213 TInt endPos = aScriptPath.LocateReverse('\\');
214 if (endPos == KErrNotFound)
220 aIniFilePath.Copy(aIniFileName);
221 aIniFilePath.Insert(0, aScriptPath.Left(endPos+1));
226 // Reads the whole of .ini file contents, calls ParseActionbody()
227 // to extract info between <actionbody></actionbody>tags
228 EXPORT_C HBufC8* Tefinput::GetiniFile(RFs& aFs,
229 const TDesC& aIniFilePath,
233 err = iniFile.Open(aFs, aIniFilePath, EFileStream | EFileRead | EFileShareReadersOnly);
236 return NULL; // Bad exit ...
238 // gets size of ini file
243 // reads ini into iTestInput
244 HBufC8* testInput = HBufC8::NewLC(size);
246 TPtr8 aInput = testInput->Des(); // Appoint our local 8 bit pointer descriptor to the heap area to work with
247 aInput.SetLength(size);
249 RFileReadStream stream;
250 User::LeaveIfError(stream.Open(aFs, aIniFilePath, EFileStream | EFileRead | EFileShareReadersOnly));
251 CleanupClosePushL(stream);
252 stream.ReadL(aInput, size); // Load in the inifile into Heap buffer
254 // TPtrC8 iniFileread = ParseElement(pInput, tempsectID, pos, err );
255 // TPtrC8 iniFileread = ParseActionbody(pInput, aIniSectionName, err);
256 // iniFileread.TDesC8();
258 CleanupStack::PopAndDestroy(1); // stream,
260 return testInput; // Return a valid HBuf8 pointer where the ini file has been loaded (on the heap)
263 // Extracts info between <actionbody></actionbody>tags from the inifile contents
264 EXPORT_C TInt Tefinput::ParseActionbody( TPtrC8& aBuf,
265 const TDesC8& aIniTag,
266 TPtrC8& aSectionBody)
268 TInt len =0, startPos =0, endPos = 0;
269 TPtrC8 inifile = aBuf.Mid(startPos);
271 TBuf8<KIniSectionIdLength> tempsectID(KOpenBrk);
272 tempsectID.Append(aIniTag);
273 tempsectID.Append(KCloseBrk);
275 startPos = inifile.Find(tempsectID);
277 if (startPos != KErrNotFound)
279 TPtrC8 actionblk = inifile.Mid(startPos + tempsectID.Length());
280 endPos = actionblk.Find(KSectionIDTag);
281 if (endPos == KErrNotFound)
283 endPos = actionblk.Length();
287 aSectionBody.Set(aBuf.Mid(startPos + tempsectID.Length(),len));
297 // Takes in an integer and returns the appropriate error code with <return></return> tags
298 EXPORT_C TInt Tefinput::GetActionResult(TInt aErrCode, TDes8& aReturnTag)
302 if(aErrCode == KErrNone)
304 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNone</return>"));
306 else if(aErrCode == KErrNotFound)
308 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNotFound</return>"));
310 else if(aErrCode == KErrGeneral)
312 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrGeneral</return>"));
314 else if(aErrCode == KErrCancel)
316 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCancel</return>"));
318 else if(aErrCode == KErrNoMemory)
320 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNoMemory</return>"));
323 else if(aErrCode == KErrNotSupported)
325 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNotSupported</return>"));
328 else if(aErrCode == KErrArgument)
330 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrArgument</return>"));
333 else if(aErrCode == KErrTotalLossOfPrecision)
335 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrTotalLossOfPrecision</return>"));
338 else if(aErrCode == KErrBadHandle)
340 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadHandle</return>"));
343 else if(aErrCode == KErrOverflow)
345 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrOverflow</return>"));
348 else if(aErrCode == KErrUnderflow)
350 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrUnderflow</return>"));
353 else if(aErrCode == KErrAlreadyExists)
355 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAlreadyExists</return>"));
358 else if(aErrCode == KErrPathNotFound)
360 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrPathNotFound</return>"));
363 else if(aErrCode == KErrDied)
365 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrDied</return>"));
368 else if(aErrCode == KErrInUse)
370 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrInUse</return>"));
373 else if(aErrCode == KErrServerTerminated)
375 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrServerTerminated</return>"));
378 else if(aErrCode == KErrServerBusy)
380 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrServerBusy</return>"));
383 else if(aErrCode == KErrCompletion)
385 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCompletion</return>"));
388 else if(aErrCode == KErrNotReady)
390 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNotReady</return>"));
393 else if(aErrCode == KErrUnknown)
395 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrUnknown</return>"));
398 else if(aErrCode == KErrCorrupt)
400 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCorrupt</return>"));
403 else if(aErrCode == KErrAccessDenied)
405 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAccessDenied</return>"));
408 else if(aErrCode == KErrLocked)
410 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrLocked</return>"));
413 else if(aErrCode == KErrWrite)
415 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrWrite</return>"));
418 else if(aErrCode == KErrDisMounted)
420 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrDisMounted</return>"));
423 else if(aErrCode == KErrEof)
425 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrEof</return>"));
428 else if(aErrCode == KErrDiskFull)
430 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrDiskFull</return>"));
433 else if(aErrCode == KErrBadDriver)
435 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadDriver</return>"));
438 else if(aErrCode == KErrBadName)
440 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadName</return>"));
443 else if(aErrCode == KErrCommsLineFail)
445 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCommsLineFail</return>"));
448 else if(aErrCode == KErrCommsFrame)
450 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCommsFrame</return>"));
453 else if(aErrCode == KErrCommsOverrun)
455 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCommsOverrun</return>"));
458 else if(aErrCode == KErrCommsParity)
460 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCommsParity</return>"));
463 else if(aErrCode == KErrTimedOut)
465 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrTimedOut</return>"));
468 else if(aErrCode == KErrCouldNotConnect)
470 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCouldNotConnect</return>"));
473 else if(aErrCode == KErrCouldNotDisconnect)
475 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrCouldNotDisconnect</return>"));
478 else if(aErrCode == KErrDisconnected)
480 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrDisconnected</return>"));
483 else if(aErrCode == KErrBadLibraryEntryPoint)
485 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadLibraryEntryPoint</return>"));
488 else if(aErrCode == KErrBadDescriptor)
490 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadDescriptor</return>"));
493 else if(aErrCode == KErrAbort)
495 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAbort</return>"));
498 else if(aErrCode == KErrTooBig)
500 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrTooBig</return>"));
503 else if(aErrCode == KErrDivideByZero)
505 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrDivideByZero</return>"));
508 else if(aErrCode == KErrBadPower)
510 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadPower</return>"));
513 else if(aErrCode == KErrDirFull)
515 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrDirFull</return>"));
518 else if(aErrCode == KErrHardwareNotAvailable)
520 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrHardwareNotAvailable</return>"));
522 else if(aErrCode == KErrPermissionDenied)
524 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrPermissionDenied</return>"));
526 else if(aErrCode == KErrBadPassphrase)
528 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrBadPassphrase</return>"));
530 else if(aErrCode == KErrNotSecure)
532 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNotSecure</return>"));
534 else if(aErrCode == KErrKeyNotWeakEnough)
536 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrKeyNotWeakEnough</return>"));
538 else if(aErrCode == KErrInvalidPadding)
540 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrInvalidPadding</return>"));
542 else if(aErrCode == KErrWeakKey)
544 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrWeakKey</return>"));
546 else if(aErrCode == KErrNegativeExportNotSupported)
548 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrNegativeExportNotSupported</return>"));
550 else if(aErrCode == KErrKeyAlgorithm)
552 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrKeyAlgorithm</return>"));
554 else if(aErrCode == KErrKeyUsage)
556 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrKeyUsage</return>"));
558 else if(aErrCode == KErrKeyValidity)
560 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrKeyValidity</return>"));
562 else if(aErrCode == KErrKeySize)
564 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrKeySize</return>"));
566 else if(aErrCode == KErrKeyAccess)
568 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrKeyAccess</return>"));
570 else if(aErrCode == KErrPrivateKeyNotFound)
572 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrPrivateKeyNotFound</return>"));
574 else if(aErrCode == KErrAuthenticationFailure)
576 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthenticationFailure</return>"));
579 #ifdef SYMBIAN_AUTH_SERVER
580 else if(aErrCode == KErrAuthServUnsupportedExprVersion)
582 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServUnsupportedExprVersion</return>"));
584 else if(aErrCode == KErrAuthServNoSuchPlugin)
586 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServNoSuchPlugin</return>"));
588 else if(aErrCode == KErrAuthServNoSuchIdentity)
590 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServNoSuchIdentity</return>"));
592 else if(aErrCode == KErrAuthServPluginCancelled)
594 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServPluginCancelled</return>"));
596 else if(aErrCode == KErrAuthServPluginQuit)
598 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServPluginQuit</return>"));
600 else if(aErrCode == KErrAuthServAuthenticationRequired)
602 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServAuthenticationRequired</return>"));
604 else if(aErrCode == KErrAuthServIdentityAlreadyExists)
606 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServIdentityAlreadyExists</return>"));
608 else if(aErrCode == KErrAuthServIdentityNotFound)
610 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServIdentityNotFound</return>"));
612 else if(aErrCode == KErrAuthServTrainingNotFound)
614 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServTrainingNotFound</return>"));
616 else if(aErrCode == KErrAuthServRegistrationFailed)
618 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServRegistrationFailed</return>"));
620 else if(aErrCode == KErrAuthServCanNotRemoveLastIdentity)
622 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServCanNotRemoveLastIdentity</return>"));
624 else if(aErrCode == KErrAuthServCanNotRemoveLastPlugin)
626 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServCanNotRemoveLastPlugin</return>"));
628 else if(aErrCode == KErrAuthServPluginNotActive)
630 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServPluginNotActive</return>"));
632 else if(aErrCode == KErrAuthServDescTooLong)
634 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServDescTooLong</return>"));
636 else if(aErrCode == KErrUnknownAuthStrengthAlias)
638 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrUnknownAuthStrengthAlias</return>"));
640 else if(aErrCode == KErrAuthStrengthAliasNotDefined)
642 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthStrengthAliasNotDefined</return>"));
644 else if(aErrCode == KErrAuthServInvalidAliasStringExpression)
646 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServInvalidAliasStringExpression/return>"));
648 else if(aErrCode == KErrAuthServResetMayLoseIdentity)
650 aReturnTag.Copy(_L8("\r\n\t\t<return>KErrAuthServResetMayLoseIdentity/return>"));
660 // Checks if the first word in RUN_TEST_STEP is an error code. If, then calls GetActionResult().
661 EXPORT_C TInt Tefinput::ParseActionResult(const TDesC8& aBuf, TDes8& aActionResult)
666 TPtrC8 data = aBuf.Mid(startPos);
667 startPos = data.Find(KEquals);
668 if (startPos != KErrNotFound)
671 TPtrC8 tmpErrCode = data.Mid(startPos+1);
672 TLex8 lex8(tmpErrCode);
673 tmp = lex8.Val(errorCode);
680 return GetActionResult(errorCode, aActionResult);
683 // Removes any /t, /n and empty spaces from any extracted data.
684 EXPORT_C TPtrC8 Tefinput::Trim(const TDesC8& aBuf)
690 for(i = 0; i < aBuf.Length() ; i ++)
692 TPtrC8 tmpChar = aBuf.Mid(i,1);
693 if(tmpChar != KSpace && tmpChar != KTab && tmpChar != KReturn && tmpChar != KNewline )
699 for(j = aBuf.Length()-1; j >= 0 ; j --)
701 TPtrC8 tmpChar1 = aBuf.Mid(j,1);
702 if(tmpChar1 != KSpace && tmpChar1 != KTab && tmpChar1 != KReturn && tmpChar1 != KNewline )
708 if(endPos < startPos)
710 endPos = aBuf.Length();
714 return aBuf.Mid(startPos, endPos - startPos + 1);
718 //Removes '_' between 2 words and adds a space
719 EXPORT_C TDes8 Tefinput::TrimActionType(const TDesC8& aBuf, TDes8& aType)
724 // Allocating on heap - since 1024 bytes on stack could be too much for the target.
725 HBufC* temp = HBufC::NewLC(512);
726 HBufC* temp2 = HBufC::NewLC(512);
728 startPos = aBuf.Find(KUnderScore);
729 if(startPos != KErrNotFound)
731 temp->Des().Copy(aBuf.Mid(pos,(startPos-pos)));
732 temp2->Des().Copy(aBuf.Mid(startPos+1));
733 aType.Copy(temp->Des());
734 aType.Append(KSpace);
735 aType.Append(temp2->Des());
742 CleanupStack::PopAndDestroy(temp2);
743 CleanupStack::PopAndDestroy(temp);
747 //Checks if END_TESTCASE has been reached
748 EXPORT_C TBool Tefinput::EndTestCase(const TDesC8& aBuf, const TDesC8& aRunStep, const TDesC8& aTag, TInt& aPos)
752 TInt lenRunStep = aRunStep.Length();
754 TPtrC8 tempScriptFile;
755 tempScriptFile.Set(aBuf.Mid(aPos));
757 startPos = tempScriptFile.Find(aTag);
758 if(startPos != KErrNotFound)