sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * test tool step implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include "ttesttoolstep.h" sl@0: sl@0: _LIT8(KLabel,"label"); sl@0: sl@0: const TChar KCarriageReturn = '\r'; sl@0: const TChar KLineReturn = '\n'; sl@0: const TChar KDelemeter = ':'; sl@0: sl@0: HBufC8* ParseOutputFileLC(const TPtrC& aFileName); sl@0: TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine); sl@0: void ConstuctExpectedArrayL(RPointerArray& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException = EFalse); sl@0: void ResetAndDestroyHBufCList(TAny* aList); sl@0: sl@0: // sl@0: // CTestToolListCertStep sl@0: // sl@0: sl@0: CTestToolListCertStep::~CTestToolListCertStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: sl@0: CTestToolListCertStep::CTestToolListCertStep() sl@0: { sl@0: // Call base class method to set up the human readable name for logging sl@0: SetTestStepName(KTestToolListCertStep); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual. Prepares for the test run of Filetokens sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolListCertStep::doTestStepPreambleL() sl@0: { sl@0: _LIT(KActualOutput, "actualoutput"); sl@0: GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput); sl@0: sl@0: // construct name of the cert sl@0: if (GetStringFromConfig(ConfigSection(), KExpectedOwner, iExpectedOwner)) sl@0: { sl@0: iOwnerExist = 1; sl@0: } sl@0: if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist)) sl@0: { sl@0: iListStoreExist = 0; sl@0: } sl@0: if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore)) sl@0: { sl@0: iExpectedStore = -1; sl@0: } sl@0: if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel)) sl@0: { sl@0: iExpectedNumLabel = 1; sl@0: } sl@0: if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1)) sl@0: { sl@0: iLabel1Exist = 1; sl@0: } sl@0: if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2)) sl@0: { sl@0: iLabel2Exist = 1; sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class pure virtual sl@0: * Demonstrates reading configuration parameters from an ini file section sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolListCertStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CActiveScheduler* sched = NULL; sl@0: sched = new (ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(sched); sl@0: CActiveScheduler::Install(sched); sl@0: CTestToolEngine* activeEngine = CTestToolEngine::NewLC(); sl@0: sl@0: if (iLabel1Exist && !iLabel2Exist) sl@0: { sl@0: iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedNumLabel); sl@0: } sl@0: else if (iLabel2Exist && iLabel1Exist) sl@0: { sl@0: iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel); sl@0: } sl@0: else sl@0: { sl@0: RPointerArray CertList; sl@0: CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &CertList)); sl@0: HBufC8* fileContents = ParseOutputFileLC(iActualOutput); sl@0: if (iListStoreExist) sl@0: { sl@0: _LIT8(KLabel1, "label:"); sl@0: TLex8 lex(*fileContents); sl@0: while(!lex.Eos()) sl@0: { sl@0: TPtrC8 token = lex.NextToken(); sl@0: if(token.CompareF(KLabel1) == KErrNone) sl@0: { sl@0: TInt offset = lex.Offset(); sl@0: TChar c = lex.Get(); sl@0: while(c != KCarriageReturn && c != KLineReturn) sl@0: { sl@0: c = lex.Get(); sl@0: } sl@0: TInt end = lex.Offset(); sl@0: TPtrC8 newtoken; sl@0: TInt tokenLen = end-offset-1; sl@0: newtoken.Set(&fileContents->Des()[offset], tokenLen); sl@0: sl@0: HBufC* tmp = HBufC::NewLC(tokenLen); sl@0: tmp->Des().Copy(newtoken); sl@0: tmp->Des().Trim(); sl@0: CertList.Append(tmp); sl@0: CleanupStack::Pop(tmp); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(fileContents); sl@0: iVerdict = activeEngine->ListStore(CertList); sl@0: } sl@0: else sl@0: { sl@0: ConstuctExpectedArrayL(CertList, fileContents->Des(), ETrue); sl@0: CleanupStack::PopAndDestroy(fileContents); sl@0: if (iOwnerExist) sl@0: { sl@0: iVerdict = activeEngine->ListCerts(CertList, iExpectedOwner); sl@0: } sl@0: else if (iExpectedStore != -1) sl@0: { sl@0: iVerdict = activeEngine->ListCerts(CertList, iExpectedStore); sl@0: } sl@0: else sl@0: { sl@0: iVerdict = activeEngine->ListCerts(CertList); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(&CertList); sl@0: } sl@0: sl@0: sl@0: CleanupStack::PopAndDestroy(2, sched); sl@0: sl@0: if (iVerdict == EFail) sl@0: { sl@0: INFO_PRINTF1(_L("Expected Certificate does not Exist")); sl@0: } sl@0: SetTestStepResult(iVerdict); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolListCertStep::doTestStepPostambleL() sl@0: { sl@0: CActiveScheduler::Install(NULL); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // CTestToolGetTrustAppsStep sl@0: // sl@0: sl@0: CTestToolGetTrustAppsStep::~CTestToolGetTrustAppsStep() sl@0: { sl@0: iApps.ResetAndDestroy(); sl@0: } sl@0: sl@0: sl@0: CTestToolGetTrustAppsStep::CTestToolGetTrustAppsStep() sl@0: { sl@0: // Call base class method to set up the human readable name for logging sl@0: SetTestStepName(KTestToolGetTrustAppsStep); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual. Prepares for the test run of Filetokens sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetTrustAppsStep::doTestStepPreambleL() sl@0: { sl@0: _LIT(KNumApps, "numapps"); // this specifies how many commands to read sl@0: _LIT(KAppsBase, "apps"); // + number (0-based) = file to check for sl@0: sl@0: if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel)) sl@0: { sl@0: INFO_PRINTF1(_L("label name is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: TInt numApps = 0; sl@0: if (GetIntFromConfig(ConfigSection(), KNumApps, numApps) && numApps!=0) sl@0: { sl@0: TPtrC appName; sl@0: for (TInt i=0; i keyBuf(KAppsBase); sl@0: keyBuf.AppendNum(i); sl@0: sl@0: if (GetStringFromConfig(ConfigSection(), keyBuf, appName)) sl@0: { sl@0: HBufC* apps = appName.AllocLC(); sl@0: iApps.AppendL(apps); sl@0: CleanupStack::Pop(apps); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: // the string must exist, otherwise the config is invalid sl@0: ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf); sl@0: } sl@0: } sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class pure virtual sl@0: * Demonstrates reading configuration parameters from an ini file section sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetTrustAppsStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CActiveScheduler* sched = NULL; sl@0: sched = new (ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(sched); sl@0: CActiveScheduler::Install(sched); sl@0: CTestToolEngine* activeEngine = CTestToolEngine::NewLC(); sl@0: iVerdict = activeEngine->CheckApps(iApps, iExpectedLabel); sl@0: sl@0: CleanupStack::PopAndDestroy(2, sched); sl@0: if (iVerdict == EFail) sl@0: { sl@0: INFO_PRINTF1(_L("Certificate is not trusted for the applicaion")); sl@0: } sl@0: SetTestStepResult(iVerdict); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetTrustAppsStep::doTestStepPostambleL() sl@0: { sl@0: CActiveScheduler::Install(NULL); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: // sl@0: // CTestToolListKeyStep sl@0: // sl@0: sl@0: CTestToolListKeyStep::~CTestToolListKeyStep() sl@0: { sl@0: } sl@0: sl@0: sl@0: CTestToolListKeyStep::CTestToolListKeyStep() sl@0: { sl@0: // Call base class method to set up the human readable name for logging sl@0: SetTestStepName(KTestToolListKeyStep); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual. Prepares for the test run of Filetokens sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolListKeyStep::doTestStepPreambleL() sl@0: { sl@0: // construct name of the key sl@0: sl@0: GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput); sl@0: if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist)) sl@0: { sl@0: iListStoreExist = 0; sl@0: } sl@0: if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore)) sl@0: { sl@0: iExpectedStore = -1; sl@0: } sl@0: if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel)) sl@0: { sl@0: iExpectedNumLabel = 1; sl@0: } sl@0: if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1)) sl@0: { sl@0: iLabel1Exist = 1; sl@0: } sl@0: if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2)) sl@0: { sl@0: iLabel2Exist = 1; sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class pure virtual sl@0: * Demonstrates reading configuration parameters from an ini file section sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolListKeyStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CActiveScheduler* sched = NULL; sl@0: sched = new (ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(sched); sl@0: CActiveScheduler::Install(sched); sl@0: CTestToolEngine* activeEngine = CTestToolEngine::NewLC(); sl@0: if (iLabel1Exist && !iLabel2Exist) sl@0: { sl@0: iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedNumLabel); sl@0: } sl@0: else if (iLabel2Exist && iLabel1Exist) sl@0: { sl@0: iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel); sl@0: } sl@0: else sl@0: { sl@0: RPointerArray KeyList; sl@0: CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &KeyList)); sl@0: HBufC8* fileContents = ParseOutputFileLC(iActualOutput); sl@0: if (iListStoreExist) sl@0: { sl@0: _LIT8(KLabel1, "label:"); sl@0: TLex8 lex(*fileContents); sl@0: while(!lex.Eos()) sl@0: { sl@0: TPtrC8 token = lex.NextToken(); sl@0: if(token.CompareF(KLabel1) == KErrNone) sl@0: { sl@0: TInt offset = lex.Offset(); sl@0: TChar c = lex.Get(); sl@0: while(c != KCarriageReturn && c != KLineReturn) sl@0: { sl@0: c = lex.Get(); sl@0: } sl@0: TInt end = lex.Offset(); sl@0: TPtrC8 newtoken; sl@0: TInt tokenLen = end-offset-1; sl@0: newtoken.Set(&fileContents->Des()[offset], tokenLen); sl@0: sl@0: HBufC* tmp = HBufC::NewLC(tokenLen); sl@0: tmp->Des().Copy(newtoken); sl@0: tmp->Des().Trim(); sl@0: KeyList.Append(tmp); sl@0: CleanupStack::Pop(tmp); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(fileContents); sl@0: iVerdict = activeEngine->ListStoreKey(KeyList); sl@0: } sl@0: else sl@0: { sl@0: ConstuctExpectedArrayL(KeyList, fileContents->Des(), EFalse); sl@0: CleanupStack::PopAndDestroy(fileContents); sl@0: if (iExpectedStore != -1) sl@0: { sl@0: iVerdict = activeEngine->ListKeys(KeyList, iExpectedStore); sl@0: } sl@0: else sl@0: { sl@0: iVerdict = activeEngine->ListKeys(KeyList); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(&KeyList); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, sched); sl@0: sl@0: if (iVerdict == EFail) sl@0: { sl@0: INFO_PRINTF1(_L("Expected Keys do not Exist")); sl@0: } sl@0: SetTestStepResult(iVerdict); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolListKeyStep::doTestStepPostambleL() sl@0: { sl@0: CActiveScheduler::Install(NULL); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: // sl@0: // CTestToolGetPolicyStep sl@0: // sl@0: sl@0: CTestToolGetPolicyStep::~CTestToolGetPolicyStep() sl@0: { sl@0: } sl@0: sl@0: sl@0: CTestToolGetPolicyStep::CTestToolGetPolicyStep() sl@0: { sl@0: // Call base class method to set up the human readable name for logging sl@0: SetTestStepName(KTestToolGetPolicyStep); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual. Prepares for the test run of Filetokens sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetPolicyStep::doTestStepPreambleL() sl@0: { sl@0: // construct name of the key sl@0: if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel)) sl@0: { sl@0: iLabelExist = 1; sl@0: } sl@0: if (!GetStringFromConfig(ConfigSection(), KExpectedUser, iExpectedUser)) sl@0: { sl@0: INFO_PRINTF1(_L("policy user name is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: if (!GetIntFromConfig(ConfigSection(), KExpectedUserExist, iExpectedUserExist)) sl@0: { sl@0: iExpectedUserExist = 0; sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class pure virtual sl@0: * Demonstrates reading configuration parameters from an ini file section sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetPolicyStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CActiveScheduler* sched = NULL; sl@0: sched = new (ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(sched); sl@0: CActiveScheduler::Install(sched); sl@0: CTestToolEngine* activeEngine = CTestToolEngine::NewLC(); sl@0: if (iLabelExist) sl@0: { sl@0: iVerdict = activeEngine->GetPolicy(iExpectedLabel, iExpectedUser, iExpectedUserExist); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, sched); sl@0: if (iVerdict == EFail) sl@0: { sl@0: INFO_PRINTF1(_L("Exptected Keys are not Exist")); sl@0: } sl@0: SetTestStepResult(iVerdict); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetPolicyStep::doTestStepPostambleL() sl@0: { sl@0: CActiveScheduler::Install(NULL); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // CTestToolParseFileStep sl@0: // sl@0: sl@0: CTestToolParseFileStep::~CTestToolParseFileStep() sl@0: { sl@0: iArgs.ResetAndDestroy(); sl@0: } sl@0: sl@0: sl@0: CTestToolParseFileStep::CTestToolParseFileStep() sl@0: { sl@0: // Call base class method to set up the human readable name for logging sl@0: SetTestStepName(KTestToolParseFileStep); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual. Prepares for the test run of Filetokens sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolParseFileStep::doTestStepPreambleL() sl@0: { sl@0: _LIT(KNumLines, "numlines"); // this specifies how many commands to read sl@0: _LIT(KLineBase, "line"); // + number (0-based) = file to check for sl@0: sl@0: sl@0: TInt numlines = 0; sl@0: if (GetIntFromConfig(ConfigSection(), KNumLines, numlines) && numlines!=0) sl@0: { sl@0: TPtrC lineContent; sl@0: for (TInt i=0; i keyBuf(KLineBase); sl@0: keyBuf.AppendNum(i); sl@0: sl@0: if (GetStringFromConfig(ConfigSection(), keyBuf, lineContent)) sl@0: { sl@0: HBufC* line = lineContent.AllocLC(); sl@0: line->Des().Trim(); sl@0: iArgs.AppendL(line); sl@0: CleanupStack::Pop(line); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: // the string must exist, otherwise the config is invalid sl@0: ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf); sl@0: } sl@0: } sl@0: } sl@0: if (!GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput)) sl@0: { sl@0: INFO_PRINTF1(_L("actual output filename is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: if (numlines == 0) sl@0: { sl@0: if (!GetStringFromConfig(ConfigSection(), KExpectedError, iExpectedError)) sl@0: { sl@0: INFO_PRINTF1(_L("error value is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class pure virtual sl@0: * Demonstrates reading configuration parameters from an ini file section sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolParseFileStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: if (iArgs.Count() == 0) sl@0: { sl@0: HBufC8* fileContents = ParseOutputFileLC(iActualOutput); sl@0: HBufC8* actualError = GetErrorFromOutputFileLC(*fileContents); sl@0: if (actualError == NULL) sl@0: { sl@0: INFO_PRINTF1(_L("Failed to parse the output File")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: HBufC* actual16 = HBufC::NewLC(actualError->Length()); sl@0: actual16->Des().Copy(*actualError); sl@0: sl@0: if (iExpectedError.CompareF(*actual16) != KErrNone) sl@0: { sl@0: INFO_PRINTF1(_L("Expected Error is Different from Actual")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(3, fileContents); //actual16, actualError, fileContents sl@0: } sl@0: else sl@0: { sl@0: HBufC8* fileContents = ParseOutputFileLC(iActualOutput); sl@0: RPointerArray actualoutput; sl@0: CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &actualoutput)); sl@0: ConstuctExpectedArrayL(actualoutput, fileContents->Des(), EFalse, ETrue); sl@0: TBool result = EFalse; sl@0: for (TInt i = 0; i < iArgs.Count(); i++) sl@0: { sl@0: result = EFalse; sl@0: for (TInt j = 5; j < actualoutput.Count(); j++) sl@0: { sl@0: if (iArgs[i]->Des().CompareF(actualoutput[j]->Des()) == KErrNone) sl@0: { sl@0: result = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: if (!result) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: if (!result) sl@0: { sl@0: INFO_PRINTF1(_L("expected output and actual output is not matching")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(2, fileContents); // fileContents ,actualoutput sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: HBufC8* CTestToolParseFileStep::GetErrorFromOutputFileLC(const TDesC8& aBuffer) sl@0: { sl@0: _LIT8(KOutput, "output"); sl@0: TInt readPos = 0; sl@0: TPtrC8 wordContents; sl@0: sl@0: HBufC8* wordBuf = NULL; sl@0: while (!ReadWordL(aBuffer, readPos, wordContents)) sl@0: { sl@0: wordBuf = wordContents.AllocLC(); sl@0: wordBuf->Des().Trim(); sl@0: if (wordBuf->Des().CompareF(KOutput) == KErrNone) sl@0: { sl@0: readPos+=1; sl@0: if (!ReadWordL(aBuffer, readPos, wordContents)) sl@0: { sl@0: CleanupStack::PopAndDestroy(wordBuf); sl@0: wordBuf = wordContents.AllocLC(); sl@0: wordBuf->Des().Trim(); sl@0: break; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(wordBuf); sl@0: } sl@0: return wordBuf; sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolParseFileStep::doTestStepPostambleL() sl@0: { sl@0: CActiveScheduler::Install(NULL); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: sl@0: // sl@0: // global public methods sl@0: // sl@0: sl@0: // Reads the words from the Buffer either ended with : or \n sl@0: // if the word is "label", then read the next word and add to the array sl@0: // if the word is not label read upto the end of the line then go to next loop sl@0: // if exception is on , reads the entire line sl@0: void ConstuctExpectedArrayL(RPointerArray& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException) sl@0: { sl@0: TInt readPos = 0; sl@0: TPtrC8 wordContents; sl@0: sl@0: TInt bufferLength = aBuffer.Length(); sl@0: while (!ReadWordL(aBuffer, readPos, wordContents)) sl@0: { sl@0: HBufC8* wordBuf = wordContents.AllocLC(); sl@0: wordBuf->Des().Trim(); sl@0: if (aException) sl@0: { sl@0: HBufC* currentLabel = HBufC::NewLC(wordBuf->Length()); sl@0: currentLabel->Des().Copy(*wordBuf); sl@0: currentLabel->Des().Trim(); sl@0: aArray.AppendL(currentLabel); sl@0: CleanupStack::Pop(currentLabel); sl@0: } sl@0: else if (wordBuf->Des().CompareF(KLabel) == KErrNone) sl@0: { sl@0: if (!ReadWordL(aBuffer, readPos, wordContents)) sl@0: { sl@0: TPtrC8 word; sl@0: TInt len = wordContents.Length(); sl@0: // aCheck is on for reading the certool output file,because the output will be like this sl@0: // label: abc format:.... , so we need to exclude format sl@0: if (aCheck) // certdetails sl@0: { sl@0: len = len - 6; sl@0: } sl@0: word.Set(wordContents.Ptr(), len); sl@0: HBufC* currentLabel = HBufC::NewLC(word.Length()); sl@0: currentLabel->Des().Copy(word); sl@0: currentLabel->Des().Trim(); sl@0: aArray.AppendL(currentLabel); sl@0: CleanupStack::Pop(currentLabel); sl@0: } sl@0: else sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: readPos--; sl@0: while (readPos < bufferLength) sl@0: { sl@0: TChar c = aBuffer[readPos]; sl@0: sl@0: if (c == KCarriageReturn || c == KLineReturn) sl@0: { sl@0: readPos += 1; sl@0: break; sl@0: } sl@0: readPos++; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(wordBuf); sl@0: } sl@0: } sl@0: sl@0: // Reads the output file and return into the buffer. sl@0: HBufC8* ParseOutputFileLC(const TPtrC& aFileName) sl@0: { sl@0: RFs fs; sl@0: RFile file; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: User::LeaveIfError(file.Open(fs, aFileName, EFileRead)); sl@0: CleanupClosePushL(file); sl@0: TInt fSize; sl@0: file.Size(fSize); sl@0: sl@0: HBufC8* fileContents = HBufC8::NewLC(fSize); sl@0: TPtr8 ptr(fileContents->Des()); sl@0: ptr.SetLength(fSize); sl@0: sl@0: // create file stream and Read the content from the file sl@0: RFileReadStream inputFileStream(file); sl@0: CleanupClosePushL(inputFileStream); sl@0: inputFileStream.ReadL(ptr, fSize); sl@0: CleanupStack::PopAndDestroy(&inputFileStream); sl@0: CleanupStack::Pop(fileContents); sl@0: CleanupStack::PopAndDestroy(2, &fs); sl@0: CleanupStack::PushL(fileContents); sl@0: sl@0: return fileContents; sl@0: } sl@0: sl@0: // Reads the words from the aBuffer either ended with : or \n or \r sl@0: TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine) sl@0: { sl@0: TBool endOfBuffer = EFalse; sl@0: sl@0: TInt bufferLength = aBuffer.Length(); sl@0: if ( aPos > bufferLength || aPos < 0 ) sl@0: { sl@0: return ETrue; // End of buffer sl@0: } sl@0: sl@0: TInt endPos = aPos; sl@0: // find the position of the next delimeter sl@0: endPos = aPos; sl@0: while (endPos < bufferLength) sl@0: { sl@0: TChar c = aBuffer[endPos]; sl@0: sl@0: if (c == KCarriageReturn || c == KLineReturn || c == KDelemeter) sl@0: { sl@0: // exception when comes like c:\filename sl@0: if ((bufferLength > (endPos + 1)) && aBuffer[endPos+1] != '\\') sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: endPos++; sl@0: } sl@0: sl@0: if (endPos != aPos) sl@0: { sl@0: TInt tokenLen = endPos - aPos; sl@0: aLine.Set(&aBuffer[aPos], tokenLen); sl@0: endPos += 1; sl@0: } sl@0: else if (endPos == bufferLength) sl@0: { sl@0: return ETrue; // End of buffer sl@0: } sl@0: else sl@0: { sl@0: endPos++; sl@0: } sl@0: aPos = endPos; sl@0: return endOfBuffer; sl@0: } sl@0: sl@0: sl@0: void ResetAndDestroyHBufCList(TAny* aList) sl@0: { sl@0: RPointerArray* list = static_cast*>(aList); sl@0: sl@0: list->ResetAndDestroy(); sl@0: list->Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: // sl@0: // CTestToolGetTrustStep sl@0: // sl@0: sl@0: CTestToolGetTrustStep::~CTestToolGetTrustStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: sl@0: CTestToolGetTrustStep::CTestToolGetTrustStep() sl@0: { sl@0: // Call base class method to set up the human readable name for logging sl@0: SetTestStepName(KTestToolGetTrustStep); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual. Prepares for the test run of Filetokens sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetTrustStep::doTestStepPreambleL() sl@0: { sl@0: sl@0: if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel)) sl@0: { sl@0: INFO_PRINTF1(_L("label name is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: if (!GetIntFromConfig(ConfigSection(), KExpectedTrust, iExpectedTrust)) sl@0: { sl@0: INFO_PRINTF1(_L("Expected trust is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class pure virtual sl@0: * Demonstrates reading configuration parameters from an ini file section sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetTrustStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CActiveScheduler* sched = NULL; sl@0: sched = new (ELeave) CActiveScheduler; sl@0: CleanupStack::PushL(sched); sl@0: CActiveScheduler::Install(sched); sl@0: CTestToolEngine* activeEngine = CTestToolEngine::NewLC(); sl@0: iVerdict = activeEngine->CheckTrust(iExpectedLabel,iExpectedTrust); sl@0: CleanupStack::PopAndDestroy(2, sched); sl@0: if (iVerdict == EFail) sl@0: { sl@0: INFO_PRINTF1(_L("Certificate is not trusted for the applicaion")); sl@0: } sl@0: SetTestStepResult(iVerdict); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: * Override of base class virtual sl@0: * @return TVerdict code sl@0: */ sl@0: TVerdict CTestToolGetTrustStep::doTestStepPostambleL() sl@0: { sl@0: CActiveScheduler::Install(NULL); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CTestToolCheckFileStep::CTestToolCheckFileStep() sl@0: {} sl@0: sl@0: CTestToolCheckFileStep::~CTestToolCheckFileStep() sl@0: {} sl@0: sl@0: TVerdict CTestToolCheckFileStep::doTestStepPreambleL() sl@0: { sl@0: if (!GetStringFromConfig(ConfigSection(), KFileName,iFileName)) sl@0: { sl@0: INFO_PRINTF1(_L("file name is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: if (!GetStringFromConfig(ConfigSection(), KCheckType,iCheckType)) sl@0: { sl@0: INFO_PRINTF1(_L("chek type for file is missing")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TVerdict CTestToolCheckFileStep::doTestStepPostambleL() sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TVerdict CTestToolCheckFileStep::doTestStepL() sl@0: { sl@0: if (TestStepResult() != EPass) sl@0: { sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: CleanupClosePushL(fs); sl@0: RFile file; sl@0: CleanupClosePushL(file); sl@0: sl@0: TInt error = file.Open(fs,iFileName,EFileRead); sl@0: if( ( iCheckType.Compare(_L("present")) == 0 && error == KErrNone ) || sl@0: ( iCheckType.Compare(_L("absent")) == 0 && error == KErrNotFound ) sl@0: ) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2,&fs); // file sl@0: return TestStepResult(); sl@0: } sl@0: // End of file