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_certstoreactionsfilecertstore.h" sl@0: #include "t_certstoredefs.h" sl@0: #include "t_input.h" sl@0: sl@0: CTestAction* CCreateFileCertStore::NewL(RFs &aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = NewLC(aFs, aConsole, aOut, aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CCreateFileCertStore::NewLC(RFs &aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCreateFileCertStore* self = sl@0: new(ELeave) CCreateFileCertStore(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CCreateFileCertStore::~CCreateFileCertStore() sl@0: { sl@0: delete iFileName; sl@0: } sl@0: sl@0: void CCreateFileCertStore::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EInit: sl@0: { sl@0: TRAPD(err, HandleEInit()); sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, err); sl@0: } 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: iResult = ETrue; sl@0: } sl@0: else sl@0: { sl@0: iResult = EFalse; sl@0: } sl@0: iFinished = ETrue; sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CCreateFileCertStore::PerformCancel() sl@0: { sl@0: } sl@0: sl@0: void CCreateFileCertStore::Reset() sl@0: { sl@0: __ASSERT_DEBUG(EFalse, User::Panic(_L("CCreateFileCertStore::Reset()"), 1)); sl@0: } sl@0: sl@0: CCreateFileCertStore::CCreateFileCertStore(RFs &aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : CCertStoreTestAction(aFs, aConsole, aOut), sl@0: iState(EInit), iFs(aFs) sl@0: { sl@0: } sl@0: sl@0: void CCreateFileCertStore::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CCertStoreTestAction::ConstructL(aTestActionSpec); sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: TPtrC8 fileName = Input::ParseElement(aTestActionSpec.iActionBody, KFileNameStart, sl@0: KFileNameEnd, pos, err); sl@0: iFileName = HBufC::NewL(fileName.Length()); sl@0: iFileName->Des().Copy(fileName); sl@0: sl@0: // Set expected result 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: sl@0: void CCreateFileCertStore::HandleEInit() sl@0: { sl@0: iState = EFinished; sl@0: CreateStoreL(*iFileName, iFs); sl@0: } sl@0: sl@0: void CCreateFileCertStore::DoReportAction() sl@0: { sl@0: } sl@0: sl@0: void CCreateFileCertStore::DoCheckResult(TInt /*aError*/) sl@0: { sl@0: } sl@0: sl@0: void CCreateFileCertStore::CreateStoreL(const TDesC& aFileName, RFs& aFs) sl@0: { sl@0: aFs.MkDirAll(aFileName); sl@0: RFile file; sl@0: User::LeaveIfError(file.Replace(aFs, aFileName, EFileWrite)); sl@0: sl@0: //TCleanupItem deleteFile(CFileCertStore::DeleteFile, this);//store will revert() if a leave occurs sl@0: //CleanupStack::PushL(deleteFile); sl@0: sl@0: CPermanentFileStore* store = CPermanentFileStore::NewLC(file); sl@0: store->SetTypeL(KPermanentFileStoreLayoutUid); sl@0: sl@0: RStoreWriteStream caCertEntryStream; sl@0: TStreamId caCertEntryStreamId = caCertEntryStream.CreateLC(*store); sl@0: caCertEntryStream.WriteInt32L(0);//we have zero ca certs sl@0: caCertEntryStream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: RStoreWriteStream rootStream; sl@0: TStreamId rootId = rootStream.CreateLC(*store); sl@0: sl@0: rootStream << caCertEntryStreamId; sl@0: rootStream.CommitL(); sl@0: CleanupStack::PopAndDestroy(); sl@0: sl@0: store->SetRootL(rootId); sl@0: store->CommitL(); sl@0: CleanupStack::PopAndDestroy();//store sl@0: } sl@0: sl@0: