os/security/cryptoservices/filebasedcertificateandkeystores/test/ttesttools/ttesttoolstep.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/ttesttools/ttesttoolstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,982 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* test tool step implementation
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 +*/
1.26 +
1.27 +
1.28 +#include <e32std.h>
1.29 +#include "ttesttoolstep.h"
1.30 +
1.31 +_LIT8(KLabel,"label");
1.32 +
1.33 +const TChar KCarriageReturn = '\r';
1.34 +const TChar KLineReturn = '\n';
1.35 +const TChar KDelemeter = ':';
1.36 +
1.37 +HBufC8* ParseOutputFileLC(const TPtrC& aFileName);
1.38 +TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine);
1.39 +void ConstuctExpectedArrayL(RPointerArray<HBufC>& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException = EFalse);
1.40 +void ResetAndDestroyHBufCList(TAny* aList);
1.41 +
1.42 +//
1.43 +// CTestToolListCertStep
1.44 +//
1.45 +
1.46 +CTestToolListCertStep::~CTestToolListCertStep()
1.47 + {
1.48 +
1.49 + }
1.50 +
1.51 +
1.52 +CTestToolListCertStep::CTestToolListCertStep()
1.53 + {
1.54 + // Call base class method to set up the human readable name for logging
1.55 + SetTestStepName(KTestToolListCertStep);
1.56 + }
1.57 +
1.58 +/**
1.59 + * Override of base class virtual. Prepares for the test run of Filetokens
1.60 + * @return TVerdict code
1.61 + */
1.62 +TVerdict CTestToolListCertStep::doTestStepPreambleL()
1.63 + {
1.64 + _LIT(KActualOutput, "actualoutput");
1.65 + GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput);
1.66 +
1.67 + // construct name of the cert
1.68 + if (GetStringFromConfig(ConfigSection(), KExpectedOwner, iExpectedOwner))
1.69 + {
1.70 + iOwnerExist = 1;
1.71 + }
1.72 + if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist))
1.73 + {
1.74 + iListStoreExist = 0;
1.75 + }
1.76 + if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore))
1.77 + {
1.78 + iExpectedStore = -1;
1.79 + }
1.80 + if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel))
1.81 + {
1.82 + iExpectedNumLabel = 1;
1.83 + }
1.84 + if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1))
1.85 + {
1.86 + iLabel1Exist = 1;
1.87 + }
1.88 + if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2))
1.89 + {
1.90 + iLabel2Exist = 1;
1.91 + }
1.92 + return TestStepResult();
1.93 + }
1.94 +
1.95 +/**
1.96 + * Override of base class pure virtual
1.97 + * Demonstrates reading configuration parameters from an ini file section
1.98 + * @return TVerdict code
1.99 + */
1.100 +TVerdict CTestToolListCertStep::doTestStepL()
1.101 + {
1.102 + if (TestStepResult() != EPass)
1.103 + {
1.104 + return TestStepResult();
1.105 + }
1.106 +
1.107 + CActiveScheduler* sched = NULL;
1.108 + sched = new (ELeave) CActiveScheduler;
1.109 + CleanupStack::PushL(sched);
1.110 + CActiveScheduler::Install(sched);
1.111 + CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
1.112 +
1.113 + if (iLabel1Exist && !iLabel2Exist)
1.114 + {
1.115 + iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedNumLabel);
1.116 + }
1.117 + else if (iLabel2Exist && iLabel1Exist)
1.118 + {
1.119 + iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel);
1.120 + }
1.121 + else
1.122 + {
1.123 + RPointerArray<HBufC> CertList;
1.124 + CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &CertList));
1.125 + HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
1.126 + if (iListStoreExist)
1.127 + {
1.128 + _LIT8(KLabel1, "label:");
1.129 + TLex8 lex(*fileContents);
1.130 + while(!lex.Eos())
1.131 + {
1.132 + TPtrC8 token = lex.NextToken();
1.133 + if(token.CompareF(KLabel1) == KErrNone)
1.134 + {
1.135 + TInt offset = lex.Offset();
1.136 + TChar c = lex.Get();
1.137 + while(c != KCarriageReturn && c != KLineReturn)
1.138 + {
1.139 + c = lex.Get();
1.140 + }
1.141 + TInt end = lex.Offset();
1.142 + TPtrC8 newtoken;
1.143 + TInt tokenLen = end-offset-1;
1.144 + newtoken.Set(&fileContents->Des()[offset], tokenLen);
1.145 +
1.146 + HBufC* tmp = HBufC::NewLC(tokenLen);
1.147 + tmp->Des().Copy(newtoken);
1.148 + tmp->Des().Trim();
1.149 + CertList.Append(tmp);
1.150 + CleanupStack::Pop(tmp);
1.151 + }
1.152 + }
1.153 + CleanupStack::PopAndDestroy(fileContents);
1.154 + iVerdict = activeEngine->ListStore(CertList);
1.155 + }
1.156 + else
1.157 + {
1.158 + ConstuctExpectedArrayL(CertList, fileContents->Des(), ETrue);
1.159 + CleanupStack::PopAndDestroy(fileContents);
1.160 + if (iOwnerExist)
1.161 + {
1.162 + iVerdict = activeEngine->ListCerts(CertList, iExpectedOwner);
1.163 + }
1.164 + else if (iExpectedStore != -1)
1.165 + {
1.166 + iVerdict = activeEngine->ListCerts(CertList, iExpectedStore);
1.167 + }
1.168 + else
1.169 + {
1.170 + iVerdict = activeEngine->ListCerts(CertList);
1.171 + }
1.172 + }
1.173 + CleanupStack::PopAndDestroy(&CertList);
1.174 + }
1.175 +
1.176 +
1.177 + CleanupStack::PopAndDestroy(2, sched);
1.178 +
1.179 + if (iVerdict == EFail)
1.180 + {
1.181 + INFO_PRINTF1(_L("Expected Certificate does not Exist"));
1.182 + }
1.183 + SetTestStepResult(iVerdict);
1.184 +
1.185 + return TestStepResult();
1.186 + }
1.187 +
1.188 +/**
1.189 + * Override of base class virtual
1.190 + * @return TVerdict code
1.191 + */
1.192 +TVerdict CTestToolListCertStep::doTestStepPostambleL()
1.193 + {
1.194 + CActiveScheduler::Install(NULL);
1.195 + return TestStepResult();
1.196 + }
1.197 +
1.198 +
1.199 +//
1.200 +// CTestToolGetTrustAppsStep
1.201 +//
1.202 +
1.203 +CTestToolGetTrustAppsStep::~CTestToolGetTrustAppsStep()
1.204 + {
1.205 + iApps.ResetAndDestroy();
1.206 + }
1.207 +
1.208 +
1.209 +CTestToolGetTrustAppsStep::CTestToolGetTrustAppsStep()
1.210 + {
1.211 + // Call base class method to set up the human readable name for logging
1.212 + SetTestStepName(KTestToolGetTrustAppsStep);
1.213 + }
1.214 +
1.215 +/**
1.216 + * Override of base class virtual. Prepares for the test run of Filetokens
1.217 + * @return TVerdict code
1.218 + */
1.219 +TVerdict CTestToolGetTrustAppsStep::doTestStepPreambleL()
1.220 + {
1.221 + _LIT(KNumApps, "numapps"); // this specifies how many commands to read
1.222 + _LIT(KAppsBase, "apps"); // + number (0-based) = file to check for
1.223 +
1.224 + if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
1.225 + {
1.226 + INFO_PRINTF1(_L("label name is missing"));
1.227 + SetTestStepResult(EFail);
1.228 + }
1.229 + TInt numApps = 0;
1.230 + if (GetIntFromConfig(ConfigSection(), KNumApps, numApps) && numApps!=0)
1.231 + {
1.232 + TPtrC appName;
1.233 + for (TInt i=0; i<numApps; i++)
1.234 + {
1.235 + // construct name of the key
1.236 + const TInt KKeyBufSize=64;
1.237 + TBuf<KKeyBufSize> keyBuf(KAppsBase);
1.238 + keyBuf.AppendNum(i);
1.239 +
1.240 + if (GetStringFromConfig(ConfigSection(), keyBuf, appName))
1.241 + {
1.242 + HBufC* apps = appName.AllocLC();
1.243 + iApps.AppendL(apps);
1.244 + CleanupStack::Pop(apps);
1.245 + }
1.246 + else
1.247 + {
1.248 + SetTestStepResult(EFail);
1.249 + // the string must exist, otherwise the config is invalid
1.250 + ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf);
1.251 + }
1.252 + }
1.253 + }
1.254 + return TestStepResult();
1.255 + }
1.256 +
1.257 +/**
1.258 + * Override of base class pure virtual
1.259 + * Demonstrates reading configuration parameters from an ini file section
1.260 + * @return TVerdict code
1.261 + */
1.262 +TVerdict CTestToolGetTrustAppsStep::doTestStepL()
1.263 + {
1.264 + if (TestStepResult() != EPass)
1.265 + {
1.266 + return TestStepResult();
1.267 + }
1.268 +
1.269 + CActiveScheduler* sched = NULL;
1.270 + sched = new (ELeave) CActiveScheduler;
1.271 + CleanupStack::PushL(sched);
1.272 + CActiveScheduler::Install(sched);
1.273 + CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
1.274 + iVerdict = activeEngine->CheckApps(iApps, iExpectedLabel);
1.275 +
1.276 + CleanupStack::PopAndDestroy(2, sched);
1.277 + if (iVerdict == EFail)
1.278 + {
1.279 + INFO_PRINTF1(_L("Certificate is not trusted for the applicaion"));
1.280 + }
1.281 + SetTestStepResult(iVerdict);
1.282 +
1.283 + return TestStepResult();
1.284 + }
1.285 +
1.286 +/**
1.287 + * Override of base class virtual
1.288 + * @return TVerdict code
1.289 + */
1.290 +TVerdict CTestToolGetTrustAppsStep::doTestStepPostambleL()
1.291 + {
1.292 + CActiveScheduler::Install(NULL);
1.293 + return TestStepResult();
1.294 + }
1.295 +
1.296 +//
1.297 +// CTestToolListKeyStep
1.298 +//
1.299 +
1.300 +CTestToolListKeyStep::~CTestToolListKeyStep()
1.301 + {
1.302 + }
1.303 +
1.304 +
1.305 +CTestToolListKeyStep::CTestToolListKeyStep()
1.306 + {
1.307 + // Call base class method to set up the human readable name for logging
1.308 + SetTestStepName(KTestToolListKeyStep);
1.309 + }
1.310 +
1.311 +/**
1.312 + * Override of base class virtual. Prepares for the test run of Filetokens
1.313 + * @return TVerdict code
1.314 + */
1.315 +TVerdict CTestToolListKeyStep::doTestStepPreambleL()
1.316 + {
1.317 + // construct name of the key
1.318 +
1.319 + GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput);
1.320 + if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist))
1.321 + {
1.322 + iListStoreExist = 0;
1.323 + }
1.324 + if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore))
1.325 + {
1.326 + iExpectedStore = -1;
1.327 + }
1.328 + if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel))
1.329 + {
1.330 + iExpectedNumLabel = 1;
1.331 + }
1.332 + if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1))
1.333 + {
1.334 + iLabel1Exist = 1;
1.335 + }
1.336 + if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2))
1.337 + {
1.338 + iLabel2Exist = 1;
1.339 + }
1.340 + return TestStepResult();
1.341 + }
1.342 +
1.343 +/**
1.344 + * Override of base class pure virtual
1.345 + * Demonstrates reading configuration parameters from an ini file section
1.346 + * @return TVerdict code
1.347 + */
1.348 +TVerdict CTestToolListKeyStep::doTestStepL()
1.349 + {
1.350 + if (TestStepResult() != EPass)
1.351 + {
1.352 + return TestStepResult();
1.353 + }
1.354 +
1.355 + CActiveScheduler* sched = NULL;
1.356 + sched = new (ELeave) CActiveScheduler;
1.357 + CleanupStack::PushL(sched);
1.358 + CActiveScheduler::Install(sched);
1.359 + CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
1.360 + if (iLabel1Exist && !iLabel2Exist)
1.361 + {
1.362 + iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedNumLabel);
1.363 + }
1.364 + else if (iLabel2Exist && iLabel1Exist)
1.365 + {
1.366 + iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel);
1.367 + }
1.368 + else
1.369 + {
1.370 + RPointerArray<HBufC> KeyList;
1.371 + CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &KeyList));
1.372 + HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
1.373 + if (iListStoreExist)
1.374 + {
1.375 + _LIT8(KLabel1, "label:");
1.376 + TLex8 lex(*fileContents);
1.377 + while(!lex.Eos())
1.378 + {
1.379 + TPtrC8 token = lex.NextToken();
1.380 + if(token.CompareF(KLabel1) == KErrNone)
1.381 + {
1.382 + TInt offset = lex.Offset();
1.383 + TChar c = lex.Get();
1.384 + while(c != KCarriageReturn && c != KLineReturn)
1.385 + {
1.386 + c = lex.Get();
1.387 + }
1.388 + TInt end = lex.Offset();
1.389 + TPtrC8 newtoken;
1.390 + TInt tokenLen = end-offset-1;
1.391 + newtoken.Set(&fileContents->Des()[offset], tokenLen);
1.392 +
1.393 + HBufC* tmp = HBufC::NewLC(tokenLen);
1.394 + tmp->Des().Copy(newtoken);
1.395 + tmp->Des().Trim();
1.396 + KeyList.Append(tmp);
1.397 + CleanupStack::Pop(tmp);
1.398 + }
1.399 + }
1.400 + CleanupStack::PopAndDestroy(fileContents);
1.401 + iVerdict = activeEngine->ListStoreKey(KeyList);
1.402 + }
1.403 + else
1.404 + {
1.405 + ConstuctExpectedArrayL(KeyList, fileContents->Des(), EFalse);
1.406 + CleanupStack::PopAndDestroy(fileContents);
1.407 + if (iExpectedStore != -1)
1.408 + {
1.409 + iVerdict = activeEngine->ListKeys(KeyList, iExpectedStore);
1.410 + }
1.411 + else
1.412 + {
1.413 + iVerdict = activeEngine->ListKeys(KeyList);
1.414 + }
1.415 + }
1.416 + CleanupStack::PopAndDestroy(&KeyList);
1.417 + }
1.418 +
1.419 + CleanupStack::PopAndDestroy(2, sched);
1.420 +
1.421 + if (iVerdict == EFail)
1.422 + {
1.423 + INFO_PRINTF1(_L("Expected Keys do not Exist"));
1.424 + }
1.425 + SetTestStepResult(iVerdict);
1.426 +
1.427 + return TestStepResult();
1.428 + }
1.429 +
1.430 +/**
1.431 + * Override of base class virtual
1.432 + * @return TVerdict code
1.433 + */
1.434 +TVerdict CTestToolListKeyStep::doTestStepPostambleL()
1.435 + {
1.436 + CActiveScheduler::Install(NULL);
1.437 + return TestStepResult();
1.438 + }
1.439 +
1.440 +
1.441 +//
1.442 +// CTestToolGetPolicyStep
1.443 +//
1.444 +
1.445 +CTestToolGetPolicyStep::~CTestToolGetPolicyStep()
1.446 + {
1.447 + }
1.448 +
1.449 +
1.450 +CTestToolGetPolicyStep::CTestToolGetPolicyStep()
1.451 + {
1.452 + // Call base class method to set up the human readable name for logging
1.453 + SetTestStepName(KTestToolGetPolicyStep);
1.454 + }
1.455 +
1.456 +/**
1.457 + * Override of base class virtual. Prepares for the test run of Filetokens
1.458 + * @return TVerdict code
1.459 + */
1.460 +TVerdict CTestToolGetPolicyStep::doTestStepPreambleL()
1.461 + {
1.462 + // construct name of the key
1.463 + if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
1.464 + {
1.465 + iLabelExist = 1;
1.466 + }
1.467 + if (!GetStringFromConfig(ConfigSection(), KExpectedUser, iExpectedUser))
1.468 + {
1.469 + INFO_PRINTF1(_L("policy user name is missing"));
1.470 + SetTestStepResult(EFail);
1.471 + }
1.472 + if (!GetIntFromConfig(ConfigSection(), KExpectedUserExist, iExpectedUserExist))
1.473 + {
1.474 + iExpectedUserExist = 0;
1.475 + }
1.476 + return TestStepResult();
1.477 + }
1.478 +
1.479 +/**
1.480 + * Override of base class pure virtual
1.481 + * Demonstrates reading configuration parameters from an ini file section
1.482 + * @return TVerdict code
1.483 + */
1.484 +TVerdict CTestToolGetPolicyStep::doTestStepL()
1.485 + {
1.486 + if (TestStepResult() != EPass)
1.487 + {
1.488 + return TestStepResult();
1.489 + }
1.490 +
1.491 + CActiveScheduler* sched = NULL;
1.492 + sched = new (ELeave) CActiveScheduler;
1.493 + CleanupStack::PushL(sched);
1.494 + CActiveScheduler::Install(sched);
1.495 + CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
1.496 + if (iLabelExist)
1.497 + {
1.498 + iVerdict = activeEngine->GetPolicy(iExpectedLabel, iExpectedUser, iExpectedUserExist);
1.499 + }
1.500 +
1.501 + CleanupStack::PopAndDestroy(2, sched);
1.502 + if (iVerdict == EFail)
1.503 + {
1.504 + INFO_PRINTF1(_L("Exptected Keys are not Exist"));
1.505 + }
1.506 + SetTestStepResult(iVerdict);
1.507 +
1.508 + return TestStepResult();
1.509 + }
1.510 +
1.511 +/**
1.512 + * Override of base class virtual
1.513 + * @return TVerdict code
1.514 + */
1.515 +TVerdict CTestToolGetPolicyStep::doTestStepPostambleL()
1.516 + {
1.517 + CActiveScheduler::Install(NULL);
1.518 + return TestStepResult();
1.519 + }
1.520 +
1.521 +
1.522 +
1.523 +//
1.524 +// CTestToolParseFileStep
1.525 +//
1.526 +
1.527 +CTestToolParseFileStep::~CTestToolParseFileStep()
1.528 + {
1.529 + iArgs.ResetAndDestroy();
1.530 + }
1.531 +
1.532 +
1.533 +CTestToolParseFileStep::CTestToolParseFileStep()
1.534 + {
1.535 + // Call base class method to set up the human readable name for logging
1.536 + SetTestStepName(KTestToolParseFileStep);
1.537 + }
1.538 +
1.539 +/**
1.540 + * Override of base class virtual. Prepares for the test run of Filetokens
1.541 + * @return TVerdict code
1.542 + */
1.543 +TVerdict CTestToolParseFileStep::doTestStepPreambleL()
1.544 + {
1.545 + _LIT(KNumLines, "numlines"); // this specifies how many commands to read
1.546 + _LIT(KLineBase, "line"); // + number (0-based) = file to check for
1.547 +
1.548 +
1.549 + TInt numlines = 0;
1.550 + if (GetIntFromConfig(ConfigSection(), KNumLines, numlines) && numlines!=0)
1.551 + {
1.552 + TPtrC lineContent;
1.553 + for (TInt i=0; i<numlines; i++)
1.554 + {
1.555 + // construct name of the key
1.556 + const TInt KKeyBufSize=64;
1.557 + TBuf<KKeyBufSize> keyBuf(KLineBase);
1.558 + keyBuf.AppendNum(i);
1.559 +
1.560 + if (GetStringFromConfig(ConfigSection(), keyBuf, lineContent))
1.561 + {
1.562 + HBufC* line = lineContent.AllocLC();
1.563 + line->Des().Trim();
1.564 + iArgs.AppendL(line);
1.565 + CleanupStack::Pop(line);
1.566 + }
1.567 + else
1.568 + {
1.569 + SetTestStepResult(EFail);
1.570 + // the string must exist, otherwise the config is invalid
1.571 + ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf);
1.572 + }
1.573 + }
1.574 + }
1.575 + if (!GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput))
1.576 + {
1.577 + INFO_PRINTF1(_L("actual output filename is missing"));
1.578 + SetTestStepResult(EFail);
1.579 + }
1.580 + if (numlines == 0)
1.581 + {
1.582 + if (!GetStringFromConfig(ConfigSection(), KExpectedError, iExpectedError))
1.583 + {
1.584 + INFO_PRINTF1(_L("error value is missing"));
1.585 + SetTestStepResult(EFail);
1.586 + }
1.587 + }
1.588 + return TestStepResult();
1.589 + }
1.590 +
1.591 +/**
1.592 + * Override of base class pure virtual
1.593 + * Demonstrates reading configuration parameters from an ini file section
1.594 + * @return TVerdict code
1.595 + */
1.596 +TVerdict CTestToolParseFileStep::doTestStepL()
1.597 + {
1.598 + if (TestStepResult() != EPass)
1.599 + {
1.600 + return TestStepResult();
1.601 + }
1.602 + if (iArgs.Count() == 0)
1.603 + {
1.604 + HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
1.605 + HBufC8* actualError = GetErrorFromOutputFileLC(*fileContents);
1.606 + if (actualError == NULL)
1.607 + {
1.608 + INFO_PRINTF1(_L("Failed to parse the output File"));
1.609 + SetTestStepResult(EFail);
1.610 + }
1.611 +
1.612 + HBufC* actual16 = HBufC::NewLC(actualError->Length());
1.613 + actual16->Des().Copy(*actualError);
1.614 +
1.615 + if (iExpectedError.CompareF(*actual16) != KErrNone)
1.616 + {
1.617 + INFO_PRINTF1(_L("Expected Error is Different from Actual"));
1.618 + SetTestStepResult(EFail);
1.619 + }
1.620 + CleanupStack::PopAndDestroy(3, fileContents); //actual16, actualError, fileContents
1.621 + }
1.622 + else
1.623 + {
1.624 + HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
1.625 + RPointerArray<HBufC> actualoutput;
1.626 + CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &actualoutput));
1.627 + ConstuctExpectedArrayL(actualoutput, fileContents->Des(), EFalse, ETrue);
1.628 + TBool result = EFalse;
1.629 + for (TInt i = 0; i < iArgs.Count(); i++)
1.630 + {
1.631 + result = EFalse;
1.632 + for (TInt j = 5; j < actualoutput.Count(); j++)
1.633 + {
1.634 + if (iArgs[i]->Des().CompareF(actualoutput[j]->Des()) == KErrNone)
1.635 + {
1.636 + result = ETrue;
1.637 + break;
1.638 + }
1.639 + }
1.640 + if (!result)
1.641 + {
1.642 + break;
1.643 + }
1.644 + }
1.645 + if (!result)
1.646 + {
1.647 + INFO_PRINTF1(_L("expected output and actual output is not matching"));
1.648 + SetTestStepResult(EFail);
1.649 + }
1.650 + CleanupStack::PopAndDestroy(2, fileContents); // fileContents ,actualoutput
1.651 + }
1.652 +
1.653 + return TestStepResult();
1.654 + }
1.655 +
1.656 +
1.657 +HBufC8* CTestToolParseFileStep::GetErrorFromOutputFileLC(const TDesC8& aBuffer)
1.658 + {
1.659 + _LIT8(KOutput, "output");
1.660 + TInt readPos = 0;
1.661 + TPtrC8 wordContents;
1.662 +
1.663 + HBufC8* wordBuf = NULL;
1.664 + while (!ReadWordL(aBuffer, readPos, wordContents))
1.665 + {
1.666 + wordBuf = wordContents.AllocLC();
1.667 + wordBuf->Des().Trim();
1.668 + if (wordBuf->Des().CompareF(KOutput) == KErrNone)
1.669 + {
1.670 + readPos+=1;
1.671 + if (!ReadWordL(aBuffer, readPos, wordContents))
1.672 + {
1.673 + CleanupStack::PopAndDestroy(wordBuf);
1.674 + wordBuf = wordContents.AllocLC();
1.675 + wordBuf->Des().Trim();
1.676 + break;
1.677 + }
1.678 + }
1.679 + CleanupStack::PopAndDestroy(wordBuf);
1.680 + }
1.681 + return wordBuf;
1.682 + }
1.683 +
1.684 +/**
1.685 + * Override of base class virtual
1.686 + * @return TVerdict code
1.687 + */
1.688 +TVerdict CTestToolParseFileStep::doTestStepPostambleL()
1.689 + {
1.690 + CActiveScheduler::Install(NULL);
1.691 + return TestStepResult();
1.692 + }
1.693 +
1.694 +
1.695 +
1.696 +//
1.697 +// global public methods
1.698 +//
1.699 +
1.700 +// Reads the words from the Buffer either ended with : or \n
1.701 +// if the word is "label", then read the next word and add to the array
1.702 +// if the word is not label read upto the end of the line then go to next loop
1.703 +// if exception is on , reads the entire line
1.704 +void ConstuctExpectedArrayL(RPointerArray<HBufC>& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException)
1.705 + {
1.706 + TInt readPos = 0;
1.707 + TPtrC8 wordContents;
1.708 +
1.709 + TInt bufferLength = aBuffer.Length();
1.710 + while (!ReadWordL(aBuffer, readPos, wordContents))
1.711 + {
1.712 + HBufC8* wordBuf = wordContents.AllocLC();
1.713 + wordBuf->Des().Trim();
1.714 + if (aException)
1.715 + {
1.716 + HBufC* currentLabel = HBufC::NewLC(wordBuf->Length());
1.717 + currentLabel->Des().Copy(*wordBuf);
1.718 + currentLabel->Des().Trim();
1.719 + aArray.AppendL(currentLabel);
1.720 + CleanupStack::Pop(currentLabel);
1.721 + }
1.722 + else if (wordBuf->Des().CompareF(KLabel) == KErrNone)
1.723 + {
1.724 + if (!ReadWordL(aBuffer, readPos, wordContents))
1.725 + {
1.726 + TPtrC8 word;
1.727 + TInt len = wordContents.Length();
1.728 + // aCheck is on for reading the certool output file,because the output will be like this
1.729 + // label: abc format:.... , so we need to exclude format
1.730 + if (aCheck) // certdetails
1.731 + {
1.732 + len = len - 6;
1.733 + }
1.734 + word.Set(wordContents.Ptr(), len);
1.735 + HBufC* currentLabel = HBufC::NewLC(word.Length());
1.736 + currentLabel->Des().Copy(word);
1.737 + currentLabel->Des().Trim();
1.738 + aArray.AppendL(currentLabel);
1.739 + CleanupStack::Pop(currentLabel);
1.740 + }
1.741 + else
1.742 + {
1.743 + break;
1.744 + }
1.745 + }
1.746 + else
1.747 + {
1.748 + readPos--;
1.749 + while (readPos < bufferLength)
1.750 + {
1.751 + TChar c = aBuffer[readPos];
1.752 +
1.753 + if (c == KCarriageReturn || c == KLineReturn)
1.754 + {
1.755 + readPos += 1;
1.756 + break;
1.757 + }
1.758 + readPos++;
1.759 + }
1.760 + }
1.761 + CleanupStack::PopAndDestroy(wordBuf);
1.762 + }
1.763 + }
1.764 +
1.765 +// Reads the output file and return into the buffer.
1.766 +HBufC8* ParseOutputFileLC(const TPtrC& aFileName)
1.767 + {
1.768 + RFs fs;
1.769 + RFile file;
1.770 + User::LeaveIfError(fs.Connect());
1.771 + CleanupClosePushL(fs);
1.772 + User::LeaveIfError(file.Open(fs, aFileName, EFileRead));
1.773 + CleanupClosePushL(file);
1.774 + TInt fSize;
1.775 + file.Size(fSize);
1.776 +
1.777 + HBufC8* fileContents = HBufC8::NewLC(fSize);
1.778 + TPtr8 ptr(fileContents->Des());
1.779 + ptr.SetLength(fSize);
1.780 +
1.781 + // create file stream and Read the content from the file
1.782 + RFileReadStream inputFileStream(file);
1.783 + CleanupClosePushL(inputFileStream);
1.784 + inputFileStream.ReadL(ptr, fSize);
1.785 + CleanupStack::PopAndDestroy(&inputFileStream);
1.786 + CleanupStack::Pop(fileContents);
1.787 + CleanupStack::PopAndDestroy(2, &fs);
1.788 + CleanupStack::PushL(fileContents);
1.789 +
1.790 + return fileContents;
1.791 + }
1.792 +
1.793 +// Reads the words from the aBuffer either ended with : or \n or \r
1.794 +TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
1.795 + {
1.796 + TBool endOfBuffer = EFalse;
1.797 +
1.798 + TInt bufferLength = aBuffer.Length();
1.799 + if ( aPos > bufferLength || aPos < 0 )
1.800 + {
1.801 + return ETrue; // End of buffer
1.802 + }
1.803 +
1.804 + TInt endPos = aPos;
1.805 + // find the position of the next delimeter
1.806 + endPos = aPos;
1.807 + while (endPos < bufferLength)
1.808 + {
1.809 + TChar c = aBuffer[endPos];
1.810 +
1.811 + if (c == KCarriageReturn || c == KLineReturn || c == KDelemeter)
1.812 + {
1.813 + // exception when comes like c:\filename
1.814 + if ((bufferLength > (endPos + 1)) && aBuffer[endPos+1] != '\\')
1.815 + {
1.816 + break;
1.817 + }
1.818 + }
1.819 + endPos++;
1.820 + }
1.821 +
1.822 + if (endPos != aPos)
1.823 + {
1.824 + TInt tokenLen = endPos - aPos;
1.825 + aLine.Set(&aBuffer[aPos], tokenLen);
1.826 + endPos += 1;
1.827 + }
1.828 + else if (endPos == bufferLength)
1.829 + {
1.830 + return ETrue; // End of buffer
1.831 + }
1.832 + else
1.833 + {
1.834 + endPos++;
1.835 + }
1.836 + aPos = endPos;
1.837 + return endOfBuffer;
1.838 + }
1.839 +
1.840 +
1.841 +void ResetAndDestroyHBufCList(TAny* aList)
1.842 + {
1.843 + RPointerArray<HBufC>* list = static_cast<RPointerArray<HBufC>*>(aList);
1.844 +
1.845 + list->ResetAndDestroy();
1.846 + list->Close();
1.847 + }
1.848 +
1.849 +
1.850 +
1.851 +
1.852 +
1.853 +
1.854 +
1.855 +
1.856 +
1.857 +//
1.858 +// CTestToolGetTrustStep
1.859 +//
1.860 +
1.861 +CTestToolGetTrustStep::~CTestToolGetTrustStep()
1.862 + {
1.863 +
1.864 + }
1.865 +
1.866 +
1.867 +CTestToolGetTrustStep::CTestToolGetTrustStep()
1.868 + {
1.869 + // Call base class method to set up the human readable name for logging
1.870 + SetTestStepName(KTestToolGetTrustStep);
1.871 + }
1.872 +
1.873 +/**
1.874 + * Override of base class virtual. Prepares for the test run of Filetokens
1.875 + * @return TVerdict code
1.876 + */
1.877 +TVerdict CTestToolGetTrustStep::doTestStepPreambleL()
1.878 + {
1.879 +
1.880 + if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
1.881 + {
1.882 + INFO_PRINTF1(_L("label name is missing"));
1.883 + SetTestStepResult(EFail);
1.884 + }
1.885 + if (!GetIntFromConfig(ConfigSection(), KExpectedTrust, iExpectedTrust))
1.886 + {
1.887 + INFO_PRINTF1(_L("Expected trust is missing"));
1.888 + SetTestStepResult(EFail);
1.889 + }
1.890 + return TestStepResult();
1.891 + }
1.892 +
1.893 +/**
1.894 + * Override of base class pure virtual
1.895 + * Demonstrates reading configuration parameters from an ini file section
1.896 + * @return TVerdict code
1.897 + */
1.898 +TVerdict CTestToolGetTrustStep::doTestStepL()
1.899 + {
1.900 + if (TestStepResult() != EPass)
1.901 + {
1.902 + return TestStepResult();
1.903 + }
1.904 +
1.905 + CActiveScheduler* sched = NULL;
1.906 + sched = new (ELeave) CActiveScheduler;
1.907 + CleanupStack::PushL(sched);
1.908 + CActiveScheduler::Install(sched);
1.909 + CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
1.910 + iVerdict = activeEngine->CheckTrust(iExpectedLabel,iExpectedTrust);
1.911 + CleanupStack::PopAndDestroy(2, sched);
1.912 + if (iVerdict == EFail)
1.913 + {
1.914 + INFO_PRINTF1(_L("Certificate is not trusted for the applicaion"));
1.915 + }
1.916 + SetTestStepResult(iVerdict);
1.917 +
1.918 + return TestStepResult();
1.919 + }
1.920 +
1.921 +/**
1.922 + * Override of base class virtual
1.923 + * @return TVerdict code
1.924 + */
1.925 +TVerdict CTestToolGetTrustStep::doTestStepPostambleL()
1.926 + {
1.927 + CActiveScheduler::Install(NULL);
1.928 + return TestStepResult();
1.929 + }
1.930 +
1.931 +CTestToolCheckFileStep::CTestToolCheckFileStep()
1.932 + {}
1.933 +
1.934 +CTestToolCheckFileStep::~CTestToolCheckFileStep()
1.935 + {}
1.936 +
1.937 +TVerdict CTestToolCheckFileStep::doTestStepPreambleL()
1.938 + {
1.939 + if (!GetStringFromConfig(ConfigSection(), KFileName,iFileName))
1.940 + {
1.941 + INFO_PRINTF1(_L("file name is missing"));
1.942 + SetTestStepResult(EFail);
1.943 + }
1.944 + if (!GetStringFromConfig(ConfigSection(), KCheckType,iCheckType))
1.945 + {
1.946 + INFO_PRINTF1(_L("chek type for file is missing"));
1.947 + SetTestStepResult(EFail);
1.948 + }
1.949 + return TestStepResult();
1.950 + }
1.951 +
1.952 +TVerdict CTestToolCheckFileStep::doTestStepPostambleL()
1.953 + {
1.954 + return TestStepResult();
1.955 + }
1.956 +
1.957 +TVerdict CTestToolCheckFileStep::doTestStepL()
1.958 + {
1.959 + if (TestStepResult() != EPass)
1.960 + {
1.961 + return TestStepResult();
1.962 + }
1.963 +
1.964 + RFs fs;
1.965 + User::LeaveIfError(fs.Connect());
1.966 + CleanupClosePushL(fs);
1.967 + RFile file;
1.968 + CleanupClosePushL(file);
1.969 +
1.970 + TInt error = file.Open(fs,iFileName,EFileRead);
1.971 + if( ( iCheckType.Compare(_L("present")) == 0 && error == KErrNone ) ||
1.972 + ( iCheckType.Compare(_L("absent")) == 0 && error == KErrNotFound )
1.973 + )
1.974 + {
1.975 + SetTestStepResult(EPass);
1.976 + }
1.977 + else
1.978 + {
1.979 + SetTestStepResult(EFail);
1.980 + }
1.981 +
1.982 + CleanupStack::PopAndDestroy(2,&fs); // file
1.983 + return TestStepResult();
1.984 + }
1.985 +// End of file