os/security/cryptoservices/certificateandkeymgmt/tcertstore/T_unifiedcertstoreapplications.cpp
Update contrib.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
23 #include "T_unifiedcertstoreapplications.h"
25 #include "t_certstoredefs.h"
26 #include "t_certstoreout.h"
27 #include <ccertattributefilter.h>
29 CTestAction* CUnifiedCertStoreApplications::NewL(RFs& aFs,
30 CConsoleBase& aConsole,
32 const TTestActionSpec& aTestActionSpec)
34 CUnifiedCertStoreApplications* self =
35 new(ELeave) CUnifiedCertStoreApplications(aFs, aConsole, aOut);
36 CleanupStack::PushL(self);
37 self->ConstructL(aTestActionSpec);
38 CleanupStack::Pop(self);
42 CUnifiedCertStoreApplications::~CUnifiedCertStoreApplications()
45 iExpectedApplications.Reset();
47 iApplications.Close();
50 CUnifiedCertStoreApplications::CUnifiedCertStoreApplications(RFs& aFs, CConsoleBase& aConsole,
52 : CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCert)
56 void CUnifiedCertStoreApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
58 CCertStoreTestAction::ConstructL(aTestActionSpec);
59 iFilter = CCertAttributeFilter::NewL();
63 TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err);
68 iCertificateLabel.Copy(pLabel);
70 // Set expected result
74 HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length());
75 TPtr(result->Des()).Copy(aTestActionSpec.iActionResult);
76 Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult);
77 CleanupStack::PopAndDestroy(result);
79 const TDesC8& uidsString = Input::ParseElement(aTestActionSpec.iActionResult, KUIDStart, KUIDEnd,
81 TLex8 lex(uidsString);
84 while (err == KErrNone)
87 err = lex.Val(uid.iUid);
91 User::LeaveIfError(iExpectedApplications.Append(uid));
96 void CUnifiedCertStoreApplications::GetApplications(TRequestStatus& aStatus)
98 TRequestStatus* status = &aStatus;
99 TInt ix = KErrNotFound;
100 TInt count = iCertInfos.Count();
101 for (TInt i = 0; i < count; i++)
103 if (iCertInfos[i]->Label() == iCertificateLabel)
109 if (ix == KErrNotFound)
111 User::RequestComplete(status, ix);
115 iCertInfoForApplications = iCertInfos[ix];
116 CertStore().Applications(*iCertInfoForApplications, iApplications, aStatus);
120 void CUnifiedCertStoreApplications::PerformAction(TRequestStatus& aStatus)
125 iState = EGettingApplications;
127 CertStore().List(iCertInfos, *iFilter, aStatus);
130 case EGettingApplications:
132 //get the certificates associated applications
133 GetApplications(aStatus);
138 TRequestStatus* status = &aStatus;
139 User::RequestComplete(status, aStatus.Int());
140 if (aStatus == iExpectedResult)
142 // Check that we have the expected uids
143 TInt iEnd = iApplications.Count();
144 if (iEnd == iExpectedApplications.Count())
147 for (i = 0; i < iEnd; i++)
149 if ((iApplications)[i] != iExpectedApplications[i])
179 void CUnifiedCertStoreApplications::PerformCancel()
183 case EGettingApplications:
184 CertStore().CancelList();
188 CertStore().CancelApplications();
196 void CUnifiedCertStoreApplications::Reset()
202 void CUnifiedCertStoreApplications::DoReportAction()
204 iOut.writeString(_L("Getting applications..."));
206 iOut.writeString(_L("\tExpected applications :"));
207 TInt iEnd = iExpectedApplications.Count();
208 for (TInt i = 0; i < iEnd; i++)
210 iOut.writeString(_L(" "));
211 iOut.writeNum(iExpectedApplications[i].iUid);
217 void CUnifiedCertStoreApplications::DoCheckResult(TInt /*aError*/)
221 iConsole.Printf(_L("\tApplications : "));
222 iOut.writeString(_L("\tApplications : "));
223 TInt count = iApplications.Count();
224 for (TInt i = 0; i < count; i++)
226 iConsole.Printf(_L("%D "), (iApplications)[i]);
227 iOut.writeNum((iApplications)[i].iUid);
228 iOut.writeString(_L(" "));
233 iConsole.Printf(_L("\n\tApplications retrieved successfully\n"));
234 iOut.writeString(_L("\tApplications retrieved successfully"));
239 iConsole.Printf(_L("\n\tApplications retrieved failed\n"));
240 iOut.writeString(_L("\tApplications retrieved failed"));