cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreapplications.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of 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 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "T_unifiedcertstoreapplications.h"
       
    26 #include "t_input.h"
       
    27 #include "t_certstoredefs.h"
       
    28 #include "t_certstoreout.h"
       
    29 #include <ccertattributefilter.h>
       
    30 
       
    31 CTestAction* CUnifiedCertStoreApplications::NewL(RFs& aFs,
       
    32 												 CConsoleBase& aConsole,	
       
    33 												 Output& aOut, 
       
    34 												 const TTestActionSpec& aTestActionSpec)
       
    35 	{
       
    36 	CUnifiedCertStoreApplications* self = 
       
    37 		new(ELeave) CUnifiedCertStoreApplications(aFs, aConsole, aOut);
       
    38 	CleanupStack::PushL(self);
       
    39 	self->ConstructL(aTestActionSpec);
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 CUnifiedCertStoreApplications::~CUnifiedCertStoreApplications()
       
    45 	{
       
    46 	iCertInfos.Close();
       
    47 	iExpectedApplications.Reset();
       
    48 	delete iFilter;
       
    49 	iApplications.Close();
       
    50 	}
       
    51 
       
    52 CUnifiedCertStoreApplications::CUnifiedCertStoreApplications(RFs& aFs, CConsoleBase& aConsole,	
       
    53 															 Output& aOut)
       
    54 : CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCert)
       
    55 	{
       
    56 	}
       
    57 
       
    58 void CUnifiedCertStoreApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
       
    59 	{
       
    60 	CCertStoreTestAction::ConstructL(aTestActionSpec);
       
    61 	iFilter = CCertAttributeFilter::NewL();
       
    62 	TInt err = KErrNone;
       
    63 	TInt pos = 0;
       
    64 	
       
    65 	TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
       
    66 	if (err != KErrNone)
       
    67 		{
       
    68 		User::Leave(err);
       
    69 		}
       
    70 	iCertificateLabel.Copy(pLabel);
       
    71 
       
    72 	// Set expected result
       
    73 
       
    74 	pos = 0;
       
    75 	
       
    76 	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
       
    77 	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
       
    78 	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
       
    79 	CleanupStack::PopAndDestroy(result);
       
    80 	
       
    81 	const TDesC8& uidsString = Input::ParseElement(aTestActionSpec.iActionResult, KUIDStart, KUIDEnd,
       
    82 		pos, err);
       
    83 	TLex8 lex(uidsString);
       
    84 
       
    85 	err = KErrNone;
       
    86 	while (err == KErrNone)
       
    87 		{
       
    88 		TUid uid;
       
    89 		err = lex.Val(uid.iUid);
       
    90 		if (err == KErrNone)
       
    91 			{	
       
    92 			lex.SkipSpace();
       
    93 			User::LeaveIfError(iExpectedApplications.Append(uid));
       
    94 			}
       
    95 		}
       
    96 	}
       
    97 
       
    98 void CUnifiedCertStoreApplications::GetApplications(TRequestStatus& aStatus)
       
    99 	{
       
   100 	TRequestStatus* status = &aStatus;
       
   101 	TInt ix = KErrNotFound;
       
   102 	TInt count = iCertInfos.Count();
       
   103 	for (TInt i = 0; i < count; i++)
       
   104 		{
       
   105 		if (iCertInfos[i]->Label() == iCertificateLabel)
       
   106 			{
       
   107 			ix = i;
       
   108 			break;
       
   109 			}
       
   110 		}
       
   111 	if (ix == KErrNotFound)
       
   112 		{
       
   113 		User::RequestComplete(status, ix);
       
   114 		}	
       
   115 	else
       
   116 		{
       
   117 		iCertInfoForApplications = iCertInfos[ix];
       
   118 		CertStore().Applications(*iCertInfoForApplications, iApplications, aStatus);
       
   119 		}
       
   120 	}
       
   121 
       
   122 void CUnifiedCertStoreApplications::PerformAction(TRequestStatus& aStatus)
       
   123 	{
       
   124 	switch (iState)
       
   125 		{
       
   126 		case EGetCert:
       
   127 			iState = EGettingApplications;
       
   128 			//get the certs
       
   129 			CertStore().List(iCertInfos, *iFilter, aStatus);
       
   130 			break;
       
   131 			
       
   132 		case EGettingApplications:
       
   133 			iState = EFinished;
       
   134 			//get the certificates associated applications
       
   135 			GetApplications(aStatus);
       
   136 			break;
       
   137 			
       
   138 		case EFinished:
       
   139 			{
       
   140 			TRequestStatus* status = &aStatus;
       
   141 			User::RequestComplete(status, aStatus.Int());
       
   142 			if (aStatus == iExpectedResult)
       
   143 				{
       
   144 				// Check that we have the expected uids
       
   145 				TInt iEnd = iApplications.Count();
       
   146 				if (iEnd == iExpectedApplications.Count())
       
   147 					{
       
   148 					TInt i = 0;
       
   149 					for (i = 0; i < iEnd; i++)
       
   150 						{
       
   151 						if ((iApplications)[i] != iExpectedApplications[i])
       
   152 							{
       
   153 							break;
       
   154 							}
       
   155 						}
       
   156 					if (i == iEnd)
       
   157 						{
       
   158 						iResult = ETrue;
       
   159 						}
       
   160 					else
       
   161 						{
       
   162 						iResult = EFalse;
       
   163 						}
       
   164 					}
       
   165 				else
       
   166 					{
       
   167 					iResult = EFalse;
       
   168 					}
       
   169 				}
       
   170 			else
       
   171 				{
       
   172 				iResult = EFalse;
       
   173 				}
       
   174             
       
   175             iFinished = ETrue;
       
   176 			}
       
   177 			break;
       
   178 		}
       
   179 	}
       
   180 
       
   181 void CUnifiedCertStoreApplications::PerformCancel()
       
   182 	{
       
   183 	switch (iState)
       
   184 		{
       
   185 		case EGettingApplications:
       
   186 			CertStore().CancelList();
       
   187 			break;
       
   188 
       
   189 		case EFinished:
       
   190 			CertStore().CancelApplications();
       
   191 			break;
       
   192 
       
   193 		default:
       
   194 			break;
       
   195 		}
       
   196 	}
       
   197 
       
   198 void CUnifiedCertStoreApplications::Reset()
       
   199 	{
       
   200     iCertInfos.Close();
       
   201     iState = EGetCert;
       
   202 	}
       
   203 
       
   204 void CUnifiedCertStoreApplications::DoReportAction()
       
   205 	{
       
   206 	iOut.writeString(_L("Getting applications..."));
       
   207 	iOut.writeNewLine();
       
   208 	iOut.writeString(_L("\tExpected applications :"));
       
   209 	TInt iEnd = iExpectedApplications.Count();
       
   210 	for (TInt i = 0; i < iEnd; i++)
       
   211 		{
       
   212 		iOut.writeString(_L(" "));
       
   213 		iOut.writeNum(iExpectedApplications[i].iUid);
       
   214 		}
       
   215 	iOut.writeNewLine();
       
   216 	iOut.writeNewLine();
       
   217 	}	
       
   218 
       
   219 void CUnifiedCertStoreApplications::DoCheckResult(TInt /*aError*/)
       
   220 	{
       
   221 	if (iFinished)
       
   222 		{
       
   223 		iConsole.Printf(_L("\tApplications : "));
       
   224 		iOut.writeString(_L("\tApplications : "));
       
   225 		TInt count = iApplications.Count();
       
   226 		for (TInt i = 0; i < count; i++)
       
   227 			{
       
   228 			iConsole.Printf(_L("%D "), (iApplications)[i]);
       
   229 			iOut.writeNum((iApplications)[i].iUid);
       
   230 			iOut.writeString(_L(" "));
       
   231 			}
       
   232 		iOut.writeNewLine();
       
   233 		if (iResult)
       
   234 			{
       
   235 			iConsole.Printf(_L("\n\tApplications retrieved successfully\n"));
       
   236 			iOut.writeString(_L("\tApplications retrieved successfully"));
       
   237 			iOut.writeNewLine();
       
   238 			}
       
   239 		else
       
   240 			{
       
   241 			iConsole.Printf(_L("\n\tApplications retrieved failed\n"));
       
   242 			iOut.writeString(_L("\tApplications retrieved failed"));
       
   243 			iOut.writeNewLine();
       
   244 			}
       
   245 		iOut.writeNewLine();
       
   246 		}
       
   247 	}