os/security/cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreapplications.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreapplications.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,245 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-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 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +/**
    1.23 + @file
    1.24 +*/
    1.25 +
    1.26 +#include "T_unifiedcertstoreapplications.h"
    1.27 +#include "t_input.h"
    1.28 +#include "t_certstoredefs.h"
    1.29 +#include "t_certstoreout.h"
    1.30 +#include <ccertattributefilter.h>
    1.31 +
    1.32 +CTestAction* CUnifiedCertStoreApplications::NewL(RFs& aFs,
    1.33 +												 CConsoleBase& aConsole,	
    1.34 +												 Output& aOut, 
    1.35 +												 const TTestActionSpec& aTestActionSpec)
    1.36 +	{
    1.37 +	CUnifiedCertStoreApplications* self = 
    1.38 +		new(ELeave) CUnifiedCertStoreApplications(aFs, aConsole, aOut);
    1.39 +	CleanupStack::PushL(self);
    1.40 +	self->ConstructL(aTestActionSpec);
    1.41 +	CleanupStack::Pop(self);
    1.42 +	return self;
    1.43 +	}
    1.44 +
    1.45 +CUnifiedCertStoreApplications::~CUnifiedCertStoreApplications()
    1.46 +	{
    1.47 +	iCertInfos.Close();
    1.48 +	iExpectedApplications.Reset();
    1.49 +	delete iFilter;
    1.50 +	iApplications.Close();
    1.51 +	}
    1.52 +
    1.53 +CUnifiedCertStoreApplications::CUnifiedCertStoreApplications(RFs& aFs, CConsoleBase& aConsole,	
    1.54 +															 Output& aOut)
    1.55 +: CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCert)
    1.56 +	{
    1.57 +	}
    1.58 +
    1.59 +void CUnifiedCertStoreApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
    1.60 +	{
    1.61 +	CCertStoreTestAction::ConstructL(aTestActionSpec);
    1.62 +	iFilter = CCertAttributeFilter::NewL();
    1.63 +	TInt err = KErrNone;
    1.64 +	TInt pos = 0;
    1.65 +	
    1.66 +	TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
    1.67 +	if (err != KErrNone)
    1.68 +		{
    1.69 +		User::Leave(err);
    1.70 +		}
    1.71 +	iCertificateLabel.Copy(pLabel);
    1.72 +
    1.73 +	// Set expected result
    1.74 +
    1.75 +	pos = 0;
    1.76 +	
    1.77 +	HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
    1.78 +	TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
    1.79 +	Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
    1.80 +	CleanupStack::PopAndDestroy(result);
    1.81 +	
    1.82 +	const TDesC8& uidsString = Input::ParseElement(aTestActionSpec.iActionResult, KUIDStart, KUIDEnd,
    1.83 +		pos, err);
    1.84 +	TLex8 lex(uidsString);
    1.85 +
    1.86 +	err = KErrNone;
    1.87 +	while (err == KErrNone)
    1.88 +		{
    1.89 +		TUid uid;
    1.90 +		err = lex.Val(uid.iUid);
    1.91 +		if (err == KErrNone)
    1.92 +			{	
    1.93 +			lex.SkipSpace();
    1.94 +			User::LeaveIfError(iExpectedApplications.Append(uid));
    1.95 +			}
    1.96 +		}
    1.97 +	}
    1.98 +
    1.99 +void CUnifiedCertStoreApplications::GetApplications(TRequestStatus& aStatus)
   1.100 +	{
   1.101 +	TRequestStatus* status = &aStatus;
   1.102 +	TInt ix = KErrNotFound;
   1.103 +	TInt count = iCertInfos.Count();
   1.104 +	for (TInt i = 0; i < count; i++)
   1.105 +		{
   1.106 +		if (iCertInfos[i]->Label() == iCertificateLabel)
   1.107 +			{
   1.108 +			ix = i;
   1.109 +			break;
   1.110 +			}
   1.111 +		}
   1.112 +	if (ix == KErrNotFound)
   1.113 +		{
   1.114 +		User::RequestComplete(status, ix);
   1.115 +		}	
   1.116 +	else
   1.117 +		{
   1.118 +		iCertInfoForApplications = iCertInfos[ix];
   1.119 +		CertStore().Applications(*iCertInfoForApplications, iApplications, aStatus);
   1.120 +		}
   1.121 +	}
   1.122 +
   1.123 +void CUnifiedCertStoreApplications::PerformAction(TRequestStatus& aStatus)
   1.124 +	{
   1.125 +	switch (iState)
   1.126 +		{
   1.127 +		case EGetCert:
   1.128 +			iState = EGettingApplications;
   1.129 +			//get the certs
   1.130 +			CertStore().List(iCertInfos, *iFilter, aStatus);
   1.131 +			break;
   1.132 +			
   1.133 +		case EGettingApplications:
   1.134 +			iState = EFinished;
   1.135 +			//get the certificates associated applications
   1.136 +			GetApplications(aStatus);
   1.137 +			break;
   1.138 +			
   1.139 +		case EFinished:
   1.140 +			{
   1.141 +			TRequestStatus* status = &aStatus;
   1.142 +			User::RequestComplete(status, aStatus.Int());
   1.143 +			if (aStatus == iExpectedResult)
   1.144 +				{
   1.145 +				// Check that we have the expected uids
   1.146 +				TInt iEnd = iApplications.Count();
   1.147 +				if (iEnd == iExpectedApplications.Count())
   1.148 +					{
   1.149 +					TInt i = 0;
   1.150 +					for (i = 0; i < iEnd; i++)
   1.151 +						{
   1.152 +						if ((iApplications)[i] != iExpectedApplications[i])
   1.153 +							{
   1.154 +							break;
   1.155 +							}
   1.156 +						}
   1.157 +					if (i == iEnd)
   1.158 +						{
   1.159 +						iResult = ETrue;
   1.160 +						}
   1.161 +					else
   1.162 +						{
   1.163 +						iResult = EFalse;
   1.164 +						}
   1.165 +					}
   1.166 +				else
   1.167 +					{
   1.168 +					iResult = EFalse;
   1.169 +					}
   1.170 +				}
   1.171 +			else
   1.172 +				{
   1.173 +				iResult = EFalse;
   1.174 +				}
   1.175 +            
   1.176 +            iFinished = ETrue;
   1.177 +			}
   1.178 +			break;
   1.179 +		}
   1.180 +	}
   1.181 +
   1.182 +void CUnifiedCertStoreApplications::PerformCancel()
   1.183 +	{
   1.184 +	switch (iState)
   1.185 +		{
   1.186 +		case EGettingApplications:
   1.187 +			CertStore().CancelList();
   1.188 +			break;
   1.189 +
   1.190 +		case EFinished:
   1.191 +			CertStore().CancelApplications();
   1.192 +			break;
   1.193 +
   1.194 +		default:
   1.195 +			break;
   1.196 +		}
   1.197 +	}
   1.198 +
   1.199 +void CUnifiedCertStoreApplications::Reset()
   1.200 +	{
   1.201 +    iCertInfos.Close();
   1.202 +    iState = EGetCert;
   1.203 +	}
   1.204 +
   1.205 +void CUnifiedCertStoreApplications::DoReportAction()
   1.206 +	{
   1.207 +	iOut.writeString(_L("Getting applications..."));
   1.208 +	iOut.writeNewLine();
   1.209 +	iOut.writeString(_L("\tExpected applications :"));
   1.210 +	TInt iEnd = iExpectedApplications.Count();
   1.211 +	for (TInt i = 0; i < iEnd; i++)
   1.212 +		{
   1.213 +		iOut.writeString(_L(" "));
   1.214 +		iOut.writeNum(iExpectedApplications[i].iUid);
   1.215 +		}
   1.216 +	iOut.writeNewLine();
   1.217 +	iOut.writeNewLine();
   1.218 +	}	
   1.219 +
   1.220 +void CUnifiedCertStoreApplications::DoCheckResult(TInt /*aError*/)
   1.221 +	{
   1.222 +	if (iFinished)
   1.223 +		{
   1.224 +		iConsole.Printf(_L("\tApplications : "));
   1.225 +		iOut.writeString(_L("\tApplications : "));
   1.226 +		TInt count = iApplications.Count();
   1.227 +		for (TInt i = 0; i < count; i++)
   1.228 +			{
   1.229 +			iConsole.Printf(_L("%D "), (iApplications)[i]);
   1.230 +			iOut.writeNum((iApplications)[i].iUid);
   1.231 +			iOut.writeString(_L(" "));
   1.232 +			}
   1.233 +		iOut.writeNewLine();
   1.234 +		if (iResult)
   1.235 +			{
   1.236 +			iConsole.Printf(_L("\n\tApplications retrieved successfully\n"));
   1.237 +			iOut.writeString(_L("\tApplications retrieved successfully"));
   1.238 +			iOut.writeNewLine();
   1.239 +			}
   1.240 +		else
   1.241 +			{
   1.242 +			iConsole.Printf(_L("\n\tApplications retrieved failed\n"));
   1.243 +			iOut.writeString(_L("\tApplications retrieved failed"));
   1.244 +			iOut.writeNewLine();
   1.245 +			}
   1.246 +		iOut.writeNewLine();
   1.247 +		}
   1.248 +	}