sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "T_unifiedcertstoreapplications.h" sl@0: #include "t_input.h" sl@0: #include "t_certstoredefs.h" sl@0: #include "t_certstoreout.h" sl@0: #include sl@0: sl@0: CTestAction* CUnifiedCertStoreApplications::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CUnifiedCertStoreApplications* self = sl@0: new(ELeave) CUnifiedCertStoreApplications(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CUnifiedCertStoreApplications::~CUnifiedCertStoreApplications() sl@0: { sl@0: iCertInfos.Close(); sl@0: iExpectedApplications.Reset(); sl@0: delete iFilter; sl@0: iApplications.Close(); sl@0: } sl@0: sl@0: CUnifiedCertStoreApplications::CUnifiedCertStoreApplications(RFs& aFs, CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CCertStoreTestAction(aFs, aConsole, aOut), iState(EGetCert) sl@0: { sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: iFilter = CCertAttributeFilter::NewL(); sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: sl@0: TPtrC8 pLabel = Input::ParseElement(aTestActionSpec.iActionBody, KCertLabelStart, KCertLabelEnd, pos, err); sl@0: if (err != KErrNone) sl@0: { sl@0: User::Leave(err); sl@0: } sl@0: iCertificateLabel.Copy(pLabel); sl@0: sl@0: // Set expected result sl@0: sl@0: pos = 0; sl@0: sl@0: HBufC* result = HBufC::NewLC(aTestActionSpec.iActionResult.Length()); sl@0: TPtr(result->Des()).Copy(aTestActionSpec.iActionResult); sl@0: Input::GetExpectedResultL(Input::ParseElement(*result, KReturnStart, KReturnEnd), iExpectedResult); sl@0: CleanupStack::PopAndDestroy(result); sl@0: sl@0: const TDesC8& uidsString = Input::ParseElement(aTestActionSpec.iActionResult, KUIDStart, KUIDEnd, sl@0: pos, err); sl@0: TLex8 lex(uidsString); sl@0: sl@0: err = KErrNone; sl@0: while (err == KErrNone) sl@0: { sl@0: TUid uid; sl@0: err = lex.Val(uid.iUid); sl@0: if (err == KErrNone) sl@0: { sl@0: lex.SkipSpace(); sl@0: User::LeaveIfError(iExpectedApplications.Append(uid)); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::GetApplications(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: TInt ix = KErrNotFound; sl@0: TInt count = iCertInfos.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: if (iCertInfos[i]->Label() == iCertificateLabel) sl@0: { sl@0: ix = i; sl@0: break; sl@0: } sl@0: } sl@0: if (ix == KErrNotFound) sl@0: { sl@0: User::RequestComplete(status, ix); sl@0: } sl@0: else sl@0: { sl@0: iCertInfoForApplications = iCertInfos[ix]; sl@0: CertStore().Applications(*iCertInfoForApplications, iApplications, aStatus); sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EGetCert: sl@0: iState = EGettingApplications; sl@0: //get the certs sl@0: CertStore().List(iCertInfos, *iFilter, aStatus); sl@0: break; sl@0: sl@0: case EGettingApplications: sl@0: iState = EFinished; sl@0: //get the certificates associated applications sl@0: GetApplications(aStatus); sl@0: break; sl@0: sl@0: case EFinished: sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: if (aStatus == iExpectedResult) sl@0: { sl@0: // Check that we have the expected uids sl@0: TInt iEnd = iApplications.Count(); sl@0: if (iEnd == iExpectedApplications.Count()) sl@0: { sl@0: TInt i = 0; sl@0: for (i = 0; i < iEnd; i++) sl@0: { sl@0: if ((iApplications)[i] != iExpectedApplications[i]) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: if (i == iEnd) sl@0: { sl@0: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: sl@0: iFinished = ETrue; sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::PerformCancel() sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EGettingApplications: sl@0: CertStore().CancelList(); sl@0: break; sl@0: sl@0: case EFinished: sl@0: CertStore().CancelApplications(); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::Reset() sl@0: { sl@0: iCertInfos.Close(); sl@0: iState = EGetCert; sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Getting applications...")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\tExpected applications :")); sl@0: TInt iEnd = iExpectedApplications.Count(); sl@0: for (TInt i = 0; i < iEnd; i++) sl@0: { sl@0: iOut.writeString(_L(" ")); sl@0: iOut.writeNum(iExpectedApplications[i].iUid); sl@0: } sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: void CUnifiedCertStoreApplications::DoCheckResult(TInt /*aError*/) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: iConsole.Printf(_L("\tApplications : ")); sl@0: iOut.writeString(_L("\tApplications : ")); sl@0: TInt count = iApplications.Count(); sl@0: for (TInt i = 0; i < count; i++) sl@0: { sl@0: iConsole.Printf(_L("%D "), (iApplications)[i]); sl@0: iOut.writeNum((iApplications)[i].iUid); sl@0: iOut.writeString(_L(" ")); sl@0: } sl@0: iOut.writeNewLine(); sl@0: if (iResult) sl@0: { sl@0: iConsole.Printf(_L("\n\tApplications retrieved successfully\n")); sl@0: iOut.writeString(_L("\tApplications retrieved successfully")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: iConsole.Printf(_L("\n\tApplications retrieved failed\n")); sl@0: iOut.writeString(_L("\tApplications retrieved failed")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: iOut.writeNewLine(); sl@0: } sl@0: }