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_certapps_actions.h"
sl@0: #include "t_certapps_defs.h"
sl@0: #include "t_input.h"
sl@0: #include "t_output.h"
sl@0:
sl@0: #include "certificateapps.h"
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CCertAppTestAction base class
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0:
sl@0: // singleton instance of the manager
sl@0: CCertificateAppInfoManager* CCertAppTestAction::iAppManager = NULL;
sl@0:
sl@0: CCertAppTestAction::~CCertAppTestAction()
sl@0: {
sl@0: }
sl@0:
sl@0:
sl@0: CCertAppTestAction::CCertAppTestAction(RFs& aFs, CConsoleBase& aConsole,
sl@0: Output& aOut)
sl@0: : CTestAction(aConsole, aOut), iFs(aFs)
sl@0: {
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0: {
sl@0: CTestAction::ConstructL(aTestActionSpec);
sl@0: TInt pos = 0, error = 0;
sl@0: SetExpectedResult(ParseTagString(aTestActionSpec.iActionResult, KReturn, pos, error));
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::InitialiseL(TBool& /*aMemFailureFlag*/,
sl@0: TBool& /*aCancel*/, TInt& /*aHeapMark*/, TInt& /*aHeapMarkEnd*/)
sl@0: {
sl@0: }
sl@0:
sl@0: TPtrC8 CCertAppTestAction::ParseTagString(const TDesC8& aBuf, const TDesC8& aTagName, TInt& aPos, TInt& aError)
sl@0: {
sl@0: // wrapper around the Input::ParseElement function. Processes aTagName
sl@0: // and produces and used by ParseElement
sl@0: TBuf8<64> start(0);
sl@0: TBuf8<64> end(0);
sl@0:
sl@0: start.Append('<');
sl@0: start.Append(aTagName);
sl@0: start.Append('>');
sl@0:
sl@0: end.Append('<');
sl@0: end.Append('/');
sl@0: end.Append(aTagName);
sl@0: end.Append('>');
sl@0:
sl@0: return Input::ParseElement(aBuf, start, end, aPos, aError);
sl@0: }
sl@0:
sl@0: TInt32 CCertAppTestAction::ParseTagInt(const TDesC8& aBuf, const TDesC8& aTagName, TInt& aPos, TInt& aError)
sl@0: {
sl@0: TPtrC8 ptr(ParseTagString(aBuf, aTagName, aPos, aError));
sl@0:
sl@0: // Get an integer value out of it
sl@0: TInt32 retVal = 0;
sl@0: TLex8 lex(ptr);
sl@0: lex.Val(retVal);
sl@0: return retVal;
sl@0: }
sl@0:
sl@0:
sl@0: void CCertAppTestAction::SetExpectedResult(const TDesC8& aResult)
sl@0: {
sl@0: if (aResult == _L8("KErrNone") || aResult == KNullDesC8)
sl@0: {
sl@0: iExpectedResult = KErrNone;
sl@0: }
sl@0: else if (aResult == _L8("KErrAccessDenied"))
sl@0: {
sl@0: iExpectedResult = KErrAccessDenied;
sl@0: }
sl@0: else if (aResult == _L8("KErrNotReady"))
sl@0: {
sl@0: iExpectedResult = KErrNotReady;
sl@0: }
sl@0: else if (aResult == _L8("KErrAlreadyExists"))
sl@0: {
sl@0: iExpectedResult = KErrAlreadyExists;
sl@0: }
sl@0: else if (aResult == _L8("KErrInUse"))
sl@0: {
sl@0: iExpectedResult = KErrInUse;
sl@0: }
sl@0: else if (aResult == _L8("KErrNotFound"))
sl@0: {
sl@0: iExpectedResult = KErrNotFound;
sl@0: }
sl@0: else if (aResult == _L8("KErrBadName"))
sl@0: {
sl@0: iExpectedResult = KErrBadName;
sl@0: }
sl@0: else if (aResult == _L8("KErrArgument"))
sl@0: {
sl@0: iExpectedResult = KErrArgument;
sl@0: }
sl@0: else if (aResult == _L8("KErrNotReady"))
sl@0: {
sl@0: iExpectedResult = KErrNotReady;
sl@0: }
sl@0: else if (aResult == _L8("KErrCorrupt"))
sl@0: {
sl@0: iExpectedResult = KErrCorrupt;
sl@0: }
sl@0: else if (aResult == _L8("KErrPermissionDenied"))
sl@0: {
sl@0: iExpectedResult = KErrPermissionDenied;
sl@0: }
sl@0: else
sl@0: {
sl@0: iOut.write(_L("Unrecognised error code: "));
sl@0: iOut.writeString(aResult);
sl@0: iOut.writeNewLine();
sl@0: User::Leave(KErrArgument);
sl@0: }
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::PerformAction(TRequestStatus& aStatus)
sl@0: {
sl@0: TInt err = KErrNone;
sl@0: TRAP(err, DoPerformActionL());
sl@0:
sl@0: if (err != KErrNoMemory)
sl@0: {
sl@0: iFinished = ETrue;
sl@0: }
sl@0:
sl@0: TRequestStatus* status = &aStatus;
sl@0: User::RequestComplete(status, err);
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0: {
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // For all tests (with the exception of InitManager which overrides this
sl@0: // method), we check to make sure that the AppManager is set
sl@0: if (iAppManager)
sl@0: {
sl@0: iActionState = EAction;
sl@0: }
sl@0: else
sl@0: {
sl@0: iFinished = ETrue;
sl@0: err = KErrNotFound;
sl@0: }
sl@0:
sl@0: TRequestStatus* status = &aStatus;
sl@0: User::RequestComplete(status, err);
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::DoPerformPostrequisite(TRequestStatus& aStatus)
sl@0: {
sl@0: TRequestStatus* status = &aStatus;
sl@0: User::RequestComplete(status, KErrNone);
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::PerformCancel()
sl@0: {
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::Reset()
sl@0: {
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::DoReportAction()
sl@0: {
sl@0: }
sl@0:
sl@0: void CCertAppTestAction::DoCheckResult(TInt aError)
sl@0: {
sl@0: iResult = (aError == iExpectedResult);
sl@0: }
sl@0:
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CInitManager - initialises the singleton manager
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CInitManager::CInitManager(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: void CInitManager::DoPerformPrerequisite(TRequestStatus& aStatus)
sl@0: {
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // If it does not exist, then we are OK
sl@0: if (!iAppManager)
sl@0: {
sl@0: iActionState = EAction;
sl@0: }
sl@0: else
sl@0: {
sl@0: iFinished = ETrue;
sl@0: err = KErrAlreadyExists;
sl@0: }
sl@0:
sl@0: TRequestStatus* status = &aStatus;
sl@0: User::RequestComplete(status, err);
sl@0: }
sl@0:
sl@0: void CInitManager::DoPerformActionL()
sl@0: {
sl@0: iAppManager = CCertificateAppInfoManager::NewL();
sl@0: }
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CDestroyManager - destroys the singleton manager
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CDestroyManager::CDestroyManager(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: void CDestroyManager::DoPerformActionL()
sl@0: {
sl@0: delete iAppManager;
sl@0: iAppManager = NULL;
sl@0: }
sl@0:
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CClearAllApps - removes all the applications from the app list
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CClearAllApps::CClearAllApps(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: void CClearAllApps::DoPerformActionL()
sl@0: {
sl@0: for (;;)
sl@0: {
sl@0: // apps is owned by the app manager, don't try accessing it after we've
sl@0: // removed any of the applications though
sl@0:
sl@0: RArray apps;
sl@0: apps = iAppManager->Applications();
sl@0: if (apps.Count() == 0)
sl@0: {
sl@0: break;
sl@0: }
sl@0: iAppManager->RemoveL(apps[0].Id());
sl@0: }
sl@0: }
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CAddApp - adds applications
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CAddApp::CAddApp(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: CAddApp::~CAddApp()
sl@0: {
sl@0: iAppArray.Close();
sl@0: }
sl@0:
sl@0: void CAddApp::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0: {
sl@0: CCertAppTestAction::ConstructL(aTestActionSpec);
sl@0: TInt pos = 0;
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // Parse the UID and name for the new app
sl@0: do
sl@0: {
sl@0: TUid uid(TUid::Uid(ParseTagInt(aTestActionSpec.iActionBody, KUid, pos, err)));
sl@0: if (!err)
sl@0: {
sl@0: TName name;
sl@0: name.Copy(ParseTagString(aTestActionSpec.iActionBody, KAppName, pos, err));
sl@0: iAppArray.Append(TCertificateAppInfo(uid, name));
sl@0: }
sl@0: }
sl@0: while (!err);
sl@0: }
sl@0:
sl@0: void CAddApp::DoPerformActionL()
sl@0: {
sl@0: for (TInt i = 0; i < iAppArray.Count(); ++i)
sl@0: {
sl@0: iAppManager->AddL(iAppArray[i]);
sl@0: }
sl@0: }
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CRemoveApp - removes an application
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CRemoveApp::CRemoveApp(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: void CRemoveApp::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0: {
sl@0: CCertAppTestAction::ConstructL(aTestActionSpec);
sl@0: TInt pos = 0;
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // Parse the UID
sl@0: iUid = TUid::Uid(ParseTagInt(aTestActionSpec.iActionBody, KUid, pos, err));
sl@0: }
sl@0:
sl@0: void CRemoveApp::DoPerformActionL()
sl@0: {
sl@0: iAppManager->RemoveL(iUid);
sl@0: }
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CAppCount - Gets the number of applications
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CAppCount::CAppCount(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: void CAppCount::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0: {
sl@0: CCertAppTestAction::ConstructL(aTestActionSpec);
sl@0: TInt pos = 0;
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // Parse the expected number of applications
sl@0: iCount = ParseTagInt(aTestActionSpec.iActionBody, KCount, pos, err);
sl@0: }
sl@0:
sl@0: void CAppCount::DoPerformActionL()
sl@0: {
sl@0: if (iCount != iAppManager->Applications().Count())
sl@0: User::Leave(KErrArgument);
sl@0: }
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CGetApp - Gets an application with a given ID
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CGetApp::CGetApp(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: void CGetApp::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0: {
sl@0: CCertAppTestAction::ConstructL(aTestActionSpec);
sl@0: TInt pos = 0;
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // Parse the UID to retrieve and the name to expect
sl@0: iUid = TUid::Uid(ParseTagInt(aTestActionSpec.iActionBody, KUid, pos, err));
sl@0: iName.Copy(ParseTagString(aTestActionSpec.iActionBody, KAppName, pos, err));
sl@0: }
sl@0:
sl@0: void CGetApp::DoPerformActionL()
sl@0: {
sl@0: TCertificateAppInfo app;
sl@0: TInt index;
sl@0: app = iAppManager->ApplicationL(iUid, index);
sl@0:
sl@0: if (app.Name() != iName)
sl@0: User::Leave(KErrCorrupt);
sl@0: }
sl@0:
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: //CGetApplications - Gets the applications and compares with what is expected
sl@0: /////////////////////////////////////////////////////////////////////////////////
sl@0: CGetApplications::CGetApplications(RFs& aFs, CConsoleBase& aConsole, Output& aOut)
sl@0: : CCertAppTestAction(aFs, aConsole, aOut)
sl@0: {
sl@0: }
sl@0:
sl@0: CGetApplications::~CGetApplications()
sl@0: {
sl@0: iAppArray.Close();
sl@0: }
sl@0:
sl@0: void CGetApplications::ConstructL(const TTestActionSpec& aTestActionSpec)
sl@0: {
sl@0: CCertAppTestAction::ConstructL(aTestActionSpec);
sl@0: TInt pos = 0;
sl@0: TInt err = KErrNone;
sl@0:
sl@0: // Parse the UID and name for the new app
sl@0: do
sl@0: {
sl@0: TUid uid(TUid::Uid(ParseTagInt(aTestActionSpec.iActionBody, KUid, pos, err)));
sl@0: if (!err)
sl@0: {
sl@0: TName name;
sl@0: name.Copy(ParseTagString(aTestActionSpec.iActionBody, KAppName, pos, err));
sl@0: iAppArray.Append(TCertificateAppInfo(uid, name));
sl@0: }
sl@0: }
sl@0: while (!err);
sl@0: }
sl@0:
sl@0: void CGetApplications::DoPerformActionL()
sl@0: {
sl@0: const RArray& recArray = iAppManager->Applications();
sl@0: TInt count = iAppArray.Count();
sl@0:
sl@0: if (count != recArray.Count())
sl@0: {
sl@0: User::Leave(KErrArgument);
sl@0: }
sl@0:
sl@0: for (TInt i = 0 ; i < count ; ++i)
sl@0: {
sl@0: TInt j;
sl@0: for (j = 0 ; j < count ; ++j)
sl@0: {
sl@0: if ((iAppArray[i].Id() == recArray[j].Id()) &&
sl@0: (iAppArray[i].Name() == recArray[j].Name()))
sl@0: {
sl@0: break;
sl@0: }
sl@0: }
sl@0:
sl@0: if (j == count)
sl@0: {
sl@0: // If we get to the end of recArray and there is no match then
sl@0: // the arrays definitely do not match
sl@0: User::Leave(KErrArgument);
sl@0: }
sl@0: }
sl@0: }