os/security/cryptoservices/filebasedcertificateandkeystores/test/ttesttools/ttesttoolstep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * test tool step implementation
    16 *
    17 */
    18 
    19 
    20 /**
    21  @file
    22 */
    23 
    24 
    25 #include <e32std.h>
    26 #include "ttesttoolstep.h"
    27 
    28 _LIT8(KLabel,"label");
    29 
    30 const TChar KCarriageReturn = '\r';
    31 const TChar KLineReturn = '\n';
    32 const TChar KDelemeter = ':';
    33 
    34 HBufC8* ParseOutputFileLC(const TPtrC& aFileName);
    35 TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine);
    36 void ConstuctExpectedArrayL(RPointerArray<HBufC>& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException = EFalse);
    37 void ResetAndDestroyHBufCList(TAny* aList);
    38 
    39 //
    40 // CTestToolListCertStep
    41 //
    42 
    43 CTestToolListCertStep::~CTestToolListCertStep()
    44 	{
    45 
    46 	}
    47 	
    48 
    49 CTestToolListCertStep::CTestToolListCertStep()
    50 	{
    51 	// Call base class method to set up the human readable name for logging
    52 	SetTestStepName(KTestToolListCertStep);
    53 	}
    54 
    55 /**
    56  * Override of base class virtual. Prepares for the test run of Filetokens
    57  * @return TVerdict code
    58  */
    59 TVerdict CTestToolListCertStep::doTestStepPreambleL()
    60 	{
    61 	_LIT(KActualOutput, "actualoutput");
    62 	GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput);	
    63 
    64 	// construct name of the cert
    65 	if (GetStringFromConfig(ConfigSection(), KExpectedOwner, iExpectedOwner))
    66 		{
    67 		iOwnerExist = 1;	
    68 		}
    69 	if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist))
    70 		{
    71 		iListStoreExist = 0;	
    72 		}
    73 	if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore))
    74 		{
    75 		iExpectedStore = -1;
    76 		}
    77 	if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel))
    78 		{
    79 		iExpectedNumLabel = 1;
    80 		}
    81 	if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1))
    82 		{
    83 		iLabel1Exist = 1;		
    84 		}
    85 	if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2))
    86 		{
    87 		iLabel2Exist = 1;		
    88 		}
    89 	return TestStepResult();
    90 	}
    91 
    92 /**
    93  * Override of base class pure virtual
    94  * Demonstrates reading configuration parameters from an ini file section
    95  * @return TVerdict code
    96  */
    97 TVerdict CTestToolListCertStep::doTestStepL()
    98 	{
    99 	if (TestStepResult() != EPass)
   100 		{
   101 		return TestStepResult();
   102 		}
   103 
   104 	CActiveScheduler* sched = NULL;
   105 	sched = new (ELeave) CActiveScheduler;
   106 	CleanupStack::PushL(sched);
   107 	CActiveScheduler::Install(sched);	
   108 	CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
   109 	
   110 	if (iLabel1Exist && !iLabel2Exist)
   111 		{
   112 		iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedNumLabel);
   113 		}
   114 	else if (iLabel2Exist && iLabel1Exist)
   115 		{
   116 		iVerdict = activeEngine->ListCerts(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel);
   117 		}
   118 	else
   119 		{
   120 		RPointerArray<HBufC> CertList;
   121 		CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &CertList));
   122 		HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
   123 		if (iListStoreExist)
   124 			{
   125 			_LIT8(KLabel1, "label:");
   126 			TLex8 lex(*fileContents);
   127 			while(!lex.Eos())
   128                 {
   129                 TPtrC8 token = lex.NextToken();
   130                 if(token.CompareF(KLabel1) == KErrNone)
   131                 	{
   132                 	TInt offset = lex.Offset();
   133                 	TChar c = lex.Get();
   134                 	while(c != KCarriageReturn && c != KLineReturn)
   135                 		{
   136                 		c = lex.Get();
   137                 		} 
   138                 	TInt end = lex.Offset();
   139                 	TPtrC8 newtoken;
   140                 	TInt tokenLen = end-offset-1;
   141 					newtoken.Set(&fileContents->Des()[offset], tokenLen);
   142 		
   143                 	HBufC* tmp = HBufC::NewLC(tokenLen);
   144                 	tmp->Des().Copy(newtoken);
   145                 	tmp->Des().Trim();
   146                 	CertList.Append(tmp);
   147                 	CleanupStack::Pop(tmp);
   148                 	}
   149                 }
   150 			CleanupStack::PopAndDestroy(fileContents);
   151 			iVerdict = activeEngine->ListStore(CertList);
   152 			}
   153 		else
   154 			{
   155 			ConstuctExpectedArrayL(CertList, fileContents->Des(), ETrue);
   156 			CleanupStack::PopAndDestroy(fileContents);
   157 			if (iOwnerExist)
   158 				{
   159 				iVerdict = activeEngine->ListCerts(CertList, iExpectedOwner);
   160 				}
   161 			else if (iExpectedStore != -1)
   162 				{
   163 				iVerdict = activeEngine->ListCerts(CertList, iExpectedStore);
   164 				}
   165 			else
   166 				{
   167 				iVerdict = activeEngine->ListCerts(CertList);	
   168 				}
   169 			}
   170 		CleanupStack::PopAndDestroy(&CertList);
   171 		}
   172 	
   173 	
   174 	CleanupStack::PopAndDestroy(2, sched);
   175 
   176 	if (iVerdict == EFail)
   177 		{
   178 		INFO_PRINTF1(_L("Expected Certificate does not Exist"));
   179 		}
   180 	SetTestStepResult(iVerdict);
   181 
   182 	return TestStepResult();
   183 	}
   184 
   185 /**
   186  * Override of base class virtual
   187  * @return TVerdict code
   188  */
   189 TVerdict CTestToolListCertStep::doTestStepPostambleL()
   190 	{
   191 	CActiveScheduler::Install(NULL);
   192 	return TestStepResult();
   193 	}
   194 
   195 
   196 //
   197 // CTestToolGetTrustAppsStep
   198 //
   199 
   200 CTestToolGetTrustAppsStep::~CTestToolGetTrustAppsStep()
   201 	{
   202 	iApps.ResetAndDestroy();
   203 	}
   204 	
   205 
   206 CTestToolGetTrustAppsStep::CTestToolGetTrustAppsStep()
   207 	{
   208 	// Call base class method to set up the human readable name for logging
   209 	SetTestStepName(KTestToolGetTrustAppsStep);
   210 	}
   211 
   212 /**
   213  * Override of base class virtual. Prepares for the test run of Filetokens
   214  * @return TVerdict code
   215  */
   216 TVerdict CTestToolGetTrustAppsStep::doTestStepPreambleL()
   217 	{
   218 	_LIT(KNumApps, "numapps"); // this specifies how many commands to read
   219 	_LIT(KAppsBase, "apps"); // + number (0-based) = file to check for
   220 	
   221 	if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
   222 		{
   223 		INFO_PRINTF1(_L("label name is missing"));
   224 		SetTestStepResult(EFail);
   225 		}
   226 	TInt numApps = 0;
   227 	if (GetIntFromConfig(ConfigSection(), KNumApps, numApps) && numApps!=0)
   228 		{
   229 		TPtrC appName;
   230 		for (TInt i=0; i<numApps; i++)
   231 			{
   232 			// construct name of the key
   233 			const TInt KKeyBufSize=64;
   234 			TBuf<KKeyBufSize> keyBuf(KAppsBase);
   235 			keyBuf.AppendNum(i);
   236 			
   237 			if (GetStringFromConfig(ConfigSection(), keyBuf, appName))
   238 				{			
   239 				HBufC* apps = appName.AllocLC();
   240 				iApps.AppendL(apps);
   241 				CleanupStack::Pop(apps);								
   242 				}
   243 			else
   244 				{
   245 				SetTestStepResult(EFail);
   246 				// the string must exist, otherwise the config is invalid
   247 				ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf);
   248 				}
   249 			}
   250 		}
   251 	return TestStepResult();
   252 	}
   253 
   254 /**
   255  * Override of base class pure virtual
   256  * Demonstrates reading configuration parameters from an ini file section
   257  * @return TVerdict code
   258  */
   259 TVerdict CTestToolGetTrustAppsStep::doTestStepL()
   260 	{
   261 	if (TestStepResult() != EPass)
   262 		{
   263 		return TestStepResult();
   264 		}
   265 
   266 	CActiveScheduler* sched = NULL;
   267 	sched = new (ELeave) CActiveScheduler;
   268 	CleanupStack::PushL(sched);
   269 	CActiveScheduler::Install(sched);	
   270 	CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
   271 	iVerdict = activeEngine->CheckApps(iApps, iExpectedLabel);
   272 	
   273 	CleanupStack::PopAndDestroy(2, sched);
   274 	if (iVerdict == EFail)
   275 		{
   276 		INFO_PRINTF1(_L("Certificate is not trusted for the applicaion"));
   277 		}
   278 	SetTestStepResult(iVerdict);
   279 
   280 	return TestStepResult();
   281 	}
   282 
   283 /**
   284  * Override of base class virtual
   285  * @return TVerdict code
   286  */
   287 TVerdict CTestToolGetTrustAppsStep::doTestStepPostambleL()
   288 	{
   289 	CActiveScheduler::Install(NULL);
   290 	return TestStepResult();
   291 	}
   292 
   293 //
   294 // CTestToolListKeyStep
   295 //
   296 
   297 CTestToolListKeyStep::~CTestToolListKeyStep()
   298 	{
   299 	}
   300 	
   301 
   302 CTestToolListKeyStep::CTestToolListKeyStep()
   303 	{
   304 	// Call base class method to set up the human readable name for logging
   305 	SetTestStepName(KTestToolListKeyStep);
   306 	}
   307 
   308 /**
   309  * Override of base class virtual. Prepares for the test run of Filetokens
   310  * @return TVerdict code
   311  */
   312 TVerdict CTestToolListKeyStep::doTestStepPreambleL()
   313 	{
   314 	// construct name of the key
   315 
   316 	GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput);	
   317 	if (!GetIntFromConfig(ConfigSection(), KExpectedListStore, iListStoreExist))
   318 		{
   319 		iListStoreExist = 0;	
   320 		}
   321 	if(!GetIntFromConfig(ConfigSection(), KStore, iExpectedStore))
   322 		{
   323 		iExpectedStore = -1;
   324 		}
   325 	if(!GetIntFromConfig(ConfigSection(), KExpectedNumLabel, iExpectedNumLabel))
   326 		{
   327 		iExpectedNumLabel = 1;
   328 		}
   329 	if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel1))
   330 		{
   331 		iLabel1Exist = 1;		
   332 		}
   333 	if (GetStringFromConfig(ConfigSection(), KExpectedLabel2, iExpectedLabel2))
   334 		{
   335 		iLabel2Exist = 1;		
   336 		}
   337 	return TestStepResult();
   338 	}
   339 
   340 /**
   341  * Override of base class pure virtual
   342  * Demonstrates reading configuration parameters from an ini file section
   343  * @return TVerdict code
   344  */
   345 TVerdict CTestToolListKeyStep::doTestStepL()
   346 	{
   347 	if (TestStepResult() != EPass)
   348 		{
   349 		return TestStepResult();
   350 		}
   351 
   352 	CActiveScheduler* sched = NULL;
   353 	sched = new (ELeave) CActiveScheduler;
   354 	CleanupStack::PushL(sched);
   355 	CActiveScheduler::Install(sched);	
   356 	CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
   357 	if (iLabel1Exist && !iLabel2Exist)
   358 		{
   359 		iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedNumLabel);
   360 		}
   361 	else if (iLabel2Exist && iLabel1Exist)
   362 		{
   363 		iVerdict = activeEngine->ListKeys(iExpectedLabel1, iExpectedLabel2, iExpectedNumLabel);
   364 		}
   365 	else
   366 		{
   367 		RPointerArray<HBufC> KeyList;
   368 		CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &KeyList));
   369 		HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
   370 		if (iListStoreExist)
   371 			{
   372 			_LIT8(KLabel1, "label:");
   373 			TLex8 lex(*fileContents);
   374 			while(!lex.Eos())
   375                 {
   376                 TPtrC8 token = lex.NextToken();
   377                 if(token.CompareF(KLabel1) == KErrNone)
   378                 	{
   379                 	TInt offset = lex.Offset();
   380                 	TChar c = lex.Get();
   381                 	while(c != KCarriageReturn && c != KLineReturn)
   382                 		{
   383                 		c = lex.Get();
   384                 		} 
   385                 	TInt end = lex.Offset();
   386                 	TPtrC8 newtoken;
   387                 	TInt tokenLen = end-offset-1;
   388 					newtoken.Set(&fileContents->Des()[offset], tokenLen);
   389 		
   390                 	HBufC* tmp = HBufC::NewLC(tokenLen);
   391                 	tmp->Des().Copy(newtoken);
   392                 	tmp->Des().Trim();
   393                 	KeyList.Append(tmp);
   394                 	CleanupStack::Pop(tmp);
   395                 	}
   396                 }
   397 			CleanupStack::PopAndDestroy(fileContents);
   398 			iVerdict = activeEngine->ListStoreKey(KeyList);
   399 			}
   400 		else
   401 			{
   402 			ConstuctExpectedArrayL(KeyList, fileContents->Des(), EFalse);
   403 			CleanupStack::PopAndDestroy(fileContents);
   404 			if (iExpectedStore != -1)
   405 				{
   406 				iVerdict = activeEngine->ListKeys(KeyList, iExpectedStore);
   407 				}
   408 			else
   409 				{
   410 				iVerdict = activeEngine->ListKeys(KeyList);	
   411 				}
   412 			}
   413 		CleanupStack::PopAndDestroy(&KeyList); 
   414 		}
   415 	
   416 	CleanupStack::PopAndDestroy(2, sched);
   417 
   418 	if (iVerdict == EFail)
   419 		{
   420 		INFO_PRINTF1(_L("Expected Keys do not Exist"));
   421 		}
   422 	SetTestStepResult(iVerdict);
   423 	
   424 	return TestStepResult();
   425 	}
   426 
   427 /**
   428  * Override of base class virtual
   429  * @return TVerdict code
   430  */
   431 TVerdict CTestToolListKeyStep::doTestStepPostambleL()
   432 	{
   433 	CActiveScheduler::Install(NULL);
   434 	return TestStepResult();
   435 	}
   436 
   437 
   438 //
   439 // CTestToolGetPolicyStep
   440 //
   441 
   442 CTestToolGetPolicyStep::~CTestToolGetPolicyStep()
   443 	{
   444 	}
   445 	
   446 
   447 CTestToolGetPolicyStep::CTestToolGetPolicyStep()
   448 	{
   449 	// Call base class method to set up the human readable name for logging
   450 	SetTestStepName(KTestToolGetPolicyStep);
   451 	}
   452 
   453 /**
   454  * Override of base class virtual. Prepares for the test run of Filetokens
   455  * @return TVerdict code
   456  */
   457 TVerdict CTestToolGetPolicyStep::doTestStepPreambleL()
   458 	{
   459 	// construct name of the key
   460 	if (GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
   461 		{
   462 		iLabelExist = 1;		
   463 		}
   464 	if (!GetStringFromConfig(ConfigSection(), KExpectedUser, iExpectedUser))
   465 		{
   466 		INFO_PRINTF1(_L("policy user name is missing"));
   467 		SetTestStepResult(EFail);
   468 		}
   469 	if (!GetIntFromConfig(ConfigSection(), KExpectedUserExist, iExpectedUserExist))
   470 		{
   471 		iExpectedUserExist = 0;
   472 		}
   473 	return TestStepResult();
   474 	}
   475 
   476 /**
   477  * Override of base class pure virtual
   478  * Demonstrates reading configuration parameters from an ini file section
   479  * @return TVerdict code
   480  */
   481 TVerdict CTestToolGetPolicyStep::doTestStepL()
   482 	{
   483 	if (TestStepResult() != EPass)
   484 		{
   485 		return TestStepResult();
   486 		}
   487 
   488 	CActiveScheduler* sched = NULL;
   489 	sched = new (ELeave) CActiveScheduler;
   490 	CleanupStack::PushL(sched);
   491 	CActiveScheduler::Install(sched);	
   492 	CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
   493     if (iLabelExist)
   494 		{
   495 		iVerdict = activeEngine->GetPolicy(iExpectedLabel, iExpectedUser, iExpectedUserExist);
   496 		}
   497 
   498 	CleanupStack::PopAndDestroy(2, sched);
   499 	if (iVerdict == EFail)
   500 		{
   501 		INFO_PRINTF1(_L("Exptected Keys are not Exist"));
   502 		}
   503 	SetTestStepResult(iVerdict);
   504 	
   505 	return TestStepResult();
   506 	}
   507 
   508 /**
   509  * Override of base class virtual
   510  * @return TVerdict code
   511  */
   512 TVerdict CTestToolGetPolicyStep::doTestStepPostambleL()
   513 	{
   514 	CActiveScheduler::Install(NULL);
   515 	return TestStepResult();
   516 	}
   517 
   518 
   519 
   520 //
   521 // CTestToolParseFileStep
   522 //
   523 
   524 CTestToolParseFileStep::~CTestToolParseFileStep()
   525 	{
   526 	iArgs.ResetAndDestroy();
   527 	}
   528 	
   529 
   530 CTestToolParseFileStep::CTestToolParseFileStep()
   531 	{
   532 	// Call base class method to set up the human readable name for logging
   533 	SetTestStepName(KTestToolParseFileStep);
   534 	}
   535 
   536 /**
   537  * Override of base class virtual. Prepares for the test run of Filetokens
   538  * @return TVerdict code
   539  */
   540 TVerdict CTestToolParseFileStep::doTestStepPreambleL()
   541 	{
   542 	_LIT(KNumLines, "numlines"); // this specifies how many commands to read
   543 	_LIT(KLineBase, "line"); // + number (0-based) = file to check for
   544 	
   545 
   546 	TInt numlines = 0;
   547 	if (GetIntFromConfig(ConfigSection(), KNumLines, numlines) && numlines!=0)
   548 		{
   549 		TPtrC lineContent;
   550 		for (TInt i=0; i<numlines; i++)
   551 			{
   552 			// construct name of the key
   553 			const TInt KKeyBufSize=64;
   554 			TBuf<KKeyBufSize> keyBuf(KLineBase);
   555 			keyBuf.AppendNum(i);
   556 			
   557 			if (GetStringFromConfig(ConfigSection(), keyBuf, lineContent))
   558 				{			
   559 				HBufC* line = lineContent.AllocLC();
   560 				line->Des().Trim();
   561 				iArgs.AppendL(line);
   562 				CleanupStack::Pop(line);								
   563 				}
   564 			else
   565 				{
   566 				SetTestStepResult(EFail);
   567 				// the string must exist, otherwise the config is invalid
   568 				ERR_PRINTF2(_L("Missing apps name for key '%S'"), &keyBuf);
   569 				}
   570 			}
   571 		}
   572 	if (!GetStringFromConfig(ConfigSection(), KActualOutput, iActualOutput))
   573 			{
   574 			INFO_PRINTF1(_L("actual output filename is missing"));
   575 			SetTestStepResult(EFail);	
   576 			}
   577 	if (numlines == 0)
   578 		{
   579 		if (!GetStringFromConfig(ConfigSection(), KExpectedError, iExpectedError))
   580 			{
   581 			INFO_PRINTF1(_L("error value is missing"));
   582 			SetTestStepResult(EFail);
   583 			}
   584 		}
   585 	return TestStepResult();
   586 	}
   587 
   588 /**
   589  * Override of base class pure virtual
   590  * Demonstrates reading configuration parameters from an ini file section
   591  * @return TVerdict code
   592  */
   593 TVerdict CTestToolParseFileStep::doTestStepL()
   594 	{
   595 	if (TestStepResult() != EPass)
   596 		{
   597 		return TestStepResult();
   598 		}
   599 	if (iArgs.Count() == 0)
   600 		{
   601 		HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
   602 		HBufC8* actualError = GetErrorFromOutputFileLC(*fileContents);
   603 		if (actualError == NULL)
   604 			{
   605 			INFO_PRINTF1(_L("Failed to parse the output File"));
   606 			SetTestStepResult(EFail);
   607 			}
   608 		
   609 		HBufC* actual16 = HBufC::NewLC(actualError->Length());
   610 		actual16->Des().Copy(*actualError);
   611 	
   612 		if (iExpectedError.CompareF(*actual16) != KErrNone)
   613 			{
   614 			INFO_PRINTF1(_L("Expected Error is Different from Actual"));
   615 			SetTestStepResult(EFail);
   616 			}
   617 		CleanupStack::PopAndDestroy(3, fileContents); //actual16, actualError, fileContents
   618 		}
   619 	else
   620 		{
   621 		HBufC8* fileContents = ParseOutputFileLC(iActualOutput);
   622 		RPointerArray<HBufC> actualoutput;
   623 		CleanupStack::PushL(TCleanupItem(ResetAndDestroyHBufCList, &actualoutput));
   624 		ConstuctExpectedArrayL(actualoutput, fileContents->Des(), EFalse, ETrue);
   625 		TBool result = EFalse;
   626 		for (TInt i = 0; i < iArgs.Count(); i++)
   627 			{
   628 			result = EFalse;
   629 			for (TInt j = 5; j < actualoutput.Count(); j++)
   630 				{
   631 				if (iArgs[i]->Des().CompareF(actualoutput[j]->Des()) == KErrNone)
   632 					{
   633 					result = ETrue;
   634 					break;
   635 					}
   636 				}
   637 			if (!result)
   638 				{
   639 				break;
   640 				}
   641 			}
   642 		if (!result)
   643 			{
   644 			INFO_PRINTF1(_L("expected output and actual output is not matching"));
   645 			SetTestStepResult(EFail);
   646 			}
   647 		CleanupStack::PopAndDestroy(2, fileContents); // fileContents ,actualoutput
   648 		}
   649 		
   650 	return TestStepResult();
   651 	}
   652 
   653 
   654 HBufC8* CTestToolParseFileStep::GetErrorFromOutputFileLC(const TDesC8& aBuffer)
   655 	{
   656 	_LIT8(KOutput, "output");
   657 	TInt readPos = 0;
   658 	TPtrC8 wordContents;
   659 
   660 	HBufC8* wordBuf = NULL;
   661 	while (!ReadWordL(aBuffer, readPos, wordContents))
   662 		{
   663 		wordBuf = wordContents.AllocLC();
   664 		wordBuf->Des().Trim();
   665 		if (wordBuf->Des().CompareF(KOutput) == KErrNone)
   666 			{
   667 			readPos+=1;
   668 			if (!ReadWordL(aBuffer, readPos, wordContents))
   669 				{
   670 				CleanupStack::PopAndDestroy(wordBuf);
   671 				wordBuf = wordContents.AllocLC();
   672 				wordBuf->Des().Trim();
   673 				break;
   674 				}
   675 			}
   676 		CleanupStack::PopAndDestroy(wordBuf);
   677 		}
   678 	return wordBuf;		
   679 	}
   680 	
   681 /**
   682  * Override of base class virtual
   683  * @return TVerdict code
   684  */
   685 TVerdict CTestToolParseFileStep::doTestStepPostambleL()
   686 	{
   687 	CActiveScheduler::Install(NULL);
   688 	return TestStepResult();
   689 	}
   690 
   691 
   692 
   693 //
   694 // global public methods
   695 //
   696 
   697 // Reads the words from the Buffer either ended with : or \n 
   698 // if the word is "label", then read the next word and add to the array 
   699 // if the word is not label read upto the end of the line then go to next loop
   700 // if exception is on , reads the entire line
   701 void ConstuctExpectedArrayL(RPointerArray<HBufC>& aArray, const TDesC8& aBuffer,TBool aCheck, TBool aException)
   702 	{
   703 	TInt readPos = 0;
   704 	TPtrC8 wordContents;
   705 
   706 	TInt bufferLength = aBuffer.Length();
   707 	while (!ReadWordL(aBuffer, readPos, wordContents))
   708 		{
   709 		HBufC8* wordBuf = wordContents.AllocLC();
   710 		wordBuf->Des().Trim();
   711 		if (aException)
   712 			{
   713 			HBufC* currentLabel = HBufC::NewLC(wordBuf->Length());
   714 			currentLabel->Des().Copy(*wordBuf);
   715 			currentLabel->Des().Trim();
   716 			aArray.AppendL(currentLabel);
   717 			CleanupStack::Pop(currentLabel);			
   718 			}
   719 		else if (wordBuf->Des().CompareF(KLabel) == KErrNone)
   720 			{
   721 			if (!ReadWordL(aBuffer, readPos, wordContents))
   722 				{
   723 				TPtrC8 word;
   724 				TInt len = wordContents.Length();
   725 				// aCheck is on for reading the certool output file,because the output will be like this
   726 				// label: abc      format:.... ,  so we need to exclude format
   727 				if (aCheck) // certdetails 
   728 					{
   729 					len = len - 6;	
   730 					}		
   731 				word.Set(wordContents.Ptr(), len);
   732 				HBufC* currentLabel = HBufC::NewLC(word.Length());
   733 				currentLabel->Des().Copy(word);
   734 				currentLabel->Des().Trim();
   735 				aArray.AppendL(currentLabel);
   736 				CleanupStack::Pop(currentLabel);			
   737 				}
   738 			else
   739 				{
   740 				break;
   741 				}
   742 			}
   743 		else
   744 			{
   745 			readPos--;
   746 			while (readPos < bufferLength)
   747 				{
   748 				TChar c = aBuffer[readPos];
   749 	
   750 				if (c == KCarriageReturn || c == KLineReturn) 
   751 					{
   752 					readPos += 1;
   753 					break;
   754 					}	
   755 				readPos++;
   756 				}	
   757 			}
   758 		CleanupStack::PopAndDestroy(wordBuf);
   759 		}
   760 	}
   761 
   762 // Reads the output file and return into the buffer.
   763 HBufC8* ParseOutputFileLC(const TPtrC& aFileName)
   764 	{
   765 	RFs fs;
   766 	RFile file;
   767 	User::LeaveIfError(fs.Connect());
   768 	CleanupClosePushL(fs);
   769 	User::LeaveIfError(file.Open(fs, aFileName, EFileRead));
   770 	CleanupClosePushL(file);
   771 	TInt fSize;
   772 	file.Size(fSize);
   773 	
   774 	HBufC8* fileContents = HBufC8::NewLC(fSize);
   775 	TPtr8 ptr(fileContents->Des());
   776 	ptr.SetLength(fSize);
   777 	
   778 	// create file stream and Read the content from the file
   779 	RFileReadStream inputFileStream(file);
   780     CleanupClosePushL(inputFileStream);
   781 	inputFileStream.ReadL(ptr, fSize);
   782 	CleanupStack::PopAndDestroy(&inputFileStream);
   783 	CleanupStack::Pop(fileContents);
   784 	CleanupStack::PopAndDestroy(2, &fs);
   785 	CleanupStack::PushL(fileContents);
   786 
   787 	return fileContents;
   788 	}
   789 	
   790 // Reads the words from the aBuffer either ended with : or \n or \r
   791 TInt ReadWordL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine)
   792 	{
   793 	TBool endOfBuffer = EFalse;
   794 
   795 	TInt bufferLength = aBuffer.Length();
   796 	if ( aPos > bufferLength || aPos < 0 )
   797 		{	
   798 		return ETrue; // End of buffer
   799 		}
   800 	
   801 	TInt endPos = aPos;
   802 	// find the position of the next delimeter		
   803 	endPos = aPos;	
   804 	while (endPos < bufferLength)
   805 		{
   806 		TChar c = aBuffer[endPos];
   807 
   808 		if (c == KCarriageReturn || c == KLineReturn || c == KDelemeter) 
   809 			{
   810 			// exception when comes like c:\filename
   811 			if ((bufferLength > (endPos + 1)) && aBuffer[endPos+1] != '\\')
   812 				{
   813 				break;	
   814 				}		
   815 			}	
   816 		endPos++;
   817 		}
   818 
   819 	if (endPos != aPos)	
   820 		{
   821 		TInt tokenLen = endPos - aPos;
   822 		aLine.Set(&aBuffer[aPos], tokenLen);
   823 		endPos += 1;
   824 		}
   825 	else if (endPos == bufferLength)
   826 		{
   827 		return ETrue; // End of buffer
   828 		}
   829 	else
   830 		{
   831 		endPos++;	
   832 		}
   833 	aPos = endPos;
   834 	return endOfBuffer;
   835 	}
   836 
   837 
   838 void ResetAndDestroyHBufCList(TAny* aList)
   839 	{
   840 	RPointerArray<HBufC>* list = static_cast<RPointerArray<HBufC>*>(aList);
   841 
   842 	list->ResetAndDestroy();
   843 	list->Close();
   844 	}
   845 
   846 
   847 
   848 
   849 
   850 
   851 
   852 
   853 
   854 //
   855 // CTestToolGetTrustStep
   856 //
   857 
   858 CTestToolGetTrustStep::~CTestToolGetTrustStep()
   859 	{
   860 	
   861 	}
   862 	
   863 
   864 CTestToolGetTrustStep::CTestToolGetTrustStep()
   865 	{
   866 	// Call base class method to set up the human readable name for logging
   867 	SetTestStepName(KTestToolGetTrustStep);
   868 	}
   869 
   870 /**
   871  * Override of base class virtual. Prepares for the test run of Filetokens
   872  * @return TVerdict code
   873  */
   874 TVerdict CTestToolGetTrustStep::doTestStepPreambleL()
   875 	{
   876 	
   877 	if (!GetStringFromConfig(ConfigSection(), KExpectedLabel1, iExpectedLabel))
   878 		{
   879 		INFO_PRINTF1(_L("label name is missing"));
   880 		SetTestStepResult(EFail);
   881 		}
   882 	if (!GetIntFromConfig(ConfigSection(), KExpectedTrust, iExpectedTrust))
   883 		{
   884 		INFO_PRINTF1(_L("Expected trust is missing"));
   885 		SetTestStepResult(EFail);
   886 		}
   887 	return TestStepResult();
   888 	}
   889 
   890 /**
   891  * Override of base class pure virtual
   892  * Demonstrates reading configuration parameters from an ini file section
   893  * @return TVerdict code
   894  */
   895 TVerdict CTestToolGetTrustStep::doTestStepL()
   896 	{
   897 	if (TestStepResult() != EPass)
   898 		{
   899 		return TestStepResult();
   900 		}
   901 
   902 	CActiveScheduler* sched = NULL;
   903 	sched = new (ELeave) CActiveScheduler;
   904 	CleanupStack::PushL(sched);
   905 	CActiveScheduler::Install(sched);	
   906 	CTestToolEngine* activeEngine = CTestToolEngine::NewLC();
   907 	iVerdict = activeEngine->CheckTrust(iExpectedLabel,iExpectedTrust);
   908 	CleanupStack::PopAndDestroy(2, sched);
   909 	if (iVerdict == EFail)
   910 		{
   911 		INFO_PRINTF1(_L("Certificate is not trusted for the applicaion"));
   912 		}
   913 	SetTestStepResult(iVerdict);
   914 
   915 	return TestStepResult();
   916 	}
   917 
   918 /**
   919  * Override of base class virtual
   920  * @return TVerdict code
   921  */
   922 TVerdict CTestToolGetTrustStep::doTestStepPostambleL()
   923 	{
   924 	CActiveScheduler::Install(NULL);
   925 	return TestStepResult();
   926 	}
   927 
   928 CTestToolCheckFileStep::CTestToolCheckFileStep()
   929 	{}
   930 
   931 CTestToolCheckFileStep::~CTestToolCheckFileStep()
   932 	{}
   933 
   934 TVerdict CTestToolCheckFileStep::doTestStepPreambleL()
   935 	{
   936 	if (!GetStringFromConfig(ConfigSection(), KFileName,iFileName))
   937 		{
   938 		INFO_PRINTF1(_L("file name is missing"));
   939 		SetTestStepResult(EFail);
   940 		}
   941 	if (!GetStringFromConfig(ConfigSection(), KCheckType,iCheckType))
   942 		{
   943 		INFO_PRINTF1(_L("chek type for file is missing"));
   944 		SetTestStepResult(EFail);
   945 		}
   946 	return TestStepResult();
   947 	}
   948 
   949 TVerdict CTestToolCheckFileStep::doTestStepPostambleL()
   950 	{
   951 	return TestStepResult();
   952 	}
   953 
   954 TVerdict CTestToolCheckFileStep::doTestStepL()
   955 	{
   956 	if (TestStepResult() != EPass)
   957 		{
   958 		return TestStepResult();
   959 		}
   960 	
   961 	RFs fs;
   962 	User::LeaveIfError(fs.Connect());
   963 	CleanupClosePushL(fs);
   964 	RFile file;
   965 	CleanupClosePushL(file);
   966 	
   967 	TInt error = file.Open(fs,iFileName,EFileRead);
   968 	if( ( iCheckType.Compare(_L("present")) == 0 && error == KErrNone ) || 	
   969 		( iCheckType.Compare(_L("absent")) == 0 && error == KErrNotFound )
   970 		)
   971 		{
   972 		SetTestStepResult(EPass);
   973 		}
   974 	else
   975 		{
   976 		SetTestStepResult(EFail);
   977 		}
   978 	
   979 	CleanupStack::PopAndDestroy(2,&fs); // file
   980 	return TestStepResult();
   981 	}
   982 // End of file