sl@0: /* sl@0: * Copyright (c) 2003-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: #include sl@0: #include sl@0: #include "t_keystore_actions.h" sl@0: #include "t_keystore_defs.h" sl@0: #include "t_input.h" sl@0: #include "t_output.h" sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: // CSetUsers sl@0: ///////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: CTestAction* CSetUsers::NewL(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CTestAction* self = CSetUsers::NewLC(aFs, aConsole, aOut, aTestActionSpec); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CTestAction* CSetUsers::NewLC(RFs& aFs, sl@0: CConsoleBase& aConsole, sl@0: Output& aOut, sl@0: const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CSetUsers* self = new (ELeave) CSetUsers(aFs, aConsole, aOut); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aTestActionSpec); sl@0: return self; sl@0: } sl@0: sl@0: CSetUsers::~CSetUsers() sl@0: { sl@0: iUsers.Close(); sl@0: iKeys.Close(); sl@0: } sl@0: sl@0: CSetUsers::CSetUsers(RFs& aFs, CConsoleBase& aConsole, Output& aOut) : sl@0: CKeyStoreTestAction(aFs, aConsole, aOut), iState(EListKeys) sl@0: { sl@0: } sl@0: sl@0: void CSetUsers::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: CKeyStoreTestAction::ConstructL(aTestActionSpec); sl@0: sl@0: // Set users sl@0: TInt err = KErrNone; sl@0: TInt pos = 0; sl@0: while (AddUserL(Input::ParseElement(aTestActionSpec.iActionBody, KUserStart, KUserEnd, pos, err))) sl@0: /* do nothing */; sl@0: } sl@0: sl@0: TBool CSetUsers::AddUserL(const TDesC8& aData) sl@0: { sl@0: if (aData.Length() == 0) sl@0: { sl@0: return EFalse; sl@0: } sl@0: sl@0: TLex8 lex(aData); sl@0: TUid uid; sl@0: lex.Val(uid.iUid); sl@0: User::LeaveIfError(iUsers.Append(uid)); sl@0: sl@0: return ETrue; sl@0: } sl@0: sl@0: void CSetUsers::PerformAction(TRequestStatus& aStatus) sl@0: { sl@0: switch (iState) sl@0: { sl@0: case EListKeys: sl@0: { sl@0: // Currently uses first store sl@0: CUnifiedKeyStore& keystore = *CSharedKeyStores::TheUnifiedKeyStores().operator[](0); sl@0: sl@0: TCTKeyAttributeFilter filter; sl@0: keystore.List(iKeys, filter, aStatus); sl@0: iState = EMain; sl@0: break; sl@0: } sl@0: sl@0: case EMain: sl@0: { sl@0: iState = EFinished; sl@0: TRequestStatus* status = &aStatus; sl@0: sl@0: if (iKeys.Count() == 0) sl@0: { sl@0: User::RequestComplete(status, KErrNotFound); sl@0: return; sl@0: } sl@0: sl@0: const CCTKeyInfo* key = NULL; sl@0: for (TInt index = 0 ; index < iKeys.Count() ; ++index) sl@0: { sl@0: const CCTKeyInfo* k = iKeys[index]; sl@0: if (k->Label() == *iLabel) sl@0: { sl@0: key = k; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: if (!key) sl@0: { sl@0: iOut.writeString(_L("Key not found: ")); sl@0: iOut.writeString(*iLabel); sl@0: iOut.writeNewLine(); sl@0: User::RequestComplete(status, KErrNotFound); sl@0: return; sl@0: } sl@0: sl@0: sl@0: // Currently uses first store sl@0: CUnifiedKeyStore& keystore = *CSharedKeyStores::TheUnifiedKeyStores().operator[](0); sl@0: sl@0: keystore.SetUsers(*key, iUsers, aStatus); sl@0: break; sl@0: } 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: sl@0: iActionState = EPostrequisite; sl@0: } sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CSetUsers::PerformCancel() sl@0: { sl@0: CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](0); sl@0: ASSERT(keystore); sl@0: sl@0: switch (iState) sl@0: { sl@0: case EMain: sl@0: keystore->CancelList(); sl@0: break; sl@0: sl@0: case EFinished: sl@0: keystore->CancelSetUsers(); sl@0: break; sl@0: sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: void CSetUsers::Reset() sl@0: { sl@0: iState = EListKeys; sl@0: iKeys.Close(); sl@0: } sl@0: sl@0: void CSetUsers::DoReportAction() sl@0: { sl@0: iOut.writeString(_L("Setting users...")); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: sl@0: void CSetUsers::DoCheckResult(TInt aError) sl@0: { sl@0: if (iFinished) sl@0: { sl@0: if (aError == KErrNone) sl@0: { sl@0: _LIT(KSuccessful, "Users set successfully\n"); sl@0: iConsole.Write(KSuccessful); sl@0: iOut.writeString(KSuccessful); sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: else sl@0: { sl@0: if (aError!=iExpectedResult) sl@0: { sl@0: _LIT(KFailed, "!!!Set users failure!!!\n"); sl@0: iConsole.Write(KFailed); sl@0: iOut.writeString(KFailed); sl@0: } sl@0: else sl@0: { sl@0: _LIT(KFailed, "Set users failed, but expected\n"); sl@0: iConsole.Write(KFailed); sl@0: iOut.writeString(KFailed); sl@0: } sl@0: sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: } sl@0: } sl@0: sl@0: