os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_setclientuid.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_setclientuid.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,161 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include <unifiedkeystore.h>
1.23 +#include <e32base.h>
1.24 +#include "t_keystore_actions.h"
1.25 +#include "t_keystore_defs.h"
1.26 +#include "t_input.h"
1.27 +#include "t_output.h"
1.28 +
1.29 +/////////////////////////////////////////////////////////////////////////////////
1.30 +// CSetClientUid
1.31 +/////////////////////////////////////////////////////////////////////////////////
1.32 +
1.33 +CTestAction* CSetClientUid::NewL(RFs& aFs,
1.34 + CConsoleBase& aConsole,
1.35 + Output& aOut,
1.36 + const TTestActionSpec& aTestActionSpec)
1.37 + {
1.38 + CTestAction* self = CSetClientUid::NewLC(aFs, aConsole, aOut, aTestActionSpec);
1.39 + CleanupStack::Pop(self);
1.40 + return self;
1.41 + }
1.42 +
1.43 +CTestAction* CSetClientUid::NewLC(RFs& aFs,
1.44 + CConsoleBase& aConsole,
1.45 + Output& aOut,
1.46 + const TTestActionSpec& aTestActionSpec)
1.47 + {
1.48 + CSetClientUid* self = new (ELeave) CSetClientUid(aFs, aConsole, aOut);
1.49 + CleanupStack::PushL(self);
1.50 + self->ConstructL(aTestActionSpec);
1.51 + return self;
1.52 + }
1.53 +
1.54 +CSetClientUid::~CSetClientUid()
1.55 + {
1.56 + }
1.57 +
1.58 +CSetClientUid::CSetClientUid(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
1.59 + CKeyStoreTestAction(aFs, aConsole, aOut), iState(EMain)
1.60 + {
1.61 + }
1.62 +
1.63 +void CSetClientUid::ConstructL(const TTestActionSpec& aTestActionSpec)
1.64 + {
1.65 + CKeyStoreTestAction::ConstructL(aTestActionSpec);
1.66 +
1.67 + TPtrC8 data = Input::ParseElement(aTestActionSpec.iActionBody, KUidStart);
1.68 + if (data.Length() == 0)
1.69 + User::Leave(KErrNotFound);
1.70 +
1.71 + TLex8 lex(data);
1.72 + lex.Val(iUid.iUid);
1.73 + }
1.74 +
1.75 +void CSetClientUid::PerformAction(TRequestStatus& aStatus)
1.76 + {
1.77 + switch (iState)
1.78 + {
1.79 + case EMain:
1.80 + {
1.81 + RProcess thisProcess;
1.82 + thisProcess.Open(thisProcess.Id());
1.83 + CleanupClosePushL(thisProcess);
1.84 + TUidType type = thisProcess.Type();
1.85 + TUidType newType(type[0], type[1], iUid);
1.86 + thisProcess.SetType(newType);
1.87 + CleanupStack::PopAndDestroy(); // thisProcess
1.88 +
1.89 + iState = EFinished;
1.90 + TRequestStatus* status = &aStatus;
1.91 + User::RequestComplete(status, KErrNone);
1.92 + break;
1.93 + }
1.94 +
1.95 + case EFinished:
1.96 + {
1.97 + TRequestStatus* status = &aStatus;
1.98 + User::RequestComplete(status, aStatus.Int());
1.99 + if (aStatus == iExpectedResult)
1.100 + {
1.101 + iResult = ETrue;
1.102 + }
1.103 + else
1.104 + {
1.105 + iResult = EFalse;
1.106 + }
1.107 +
1.108 + iActionState = EPostrequisite;
1.109 + }
1.110 + break;
1.111 + }
1.112 + }
1.113 +
1.114 +void CSetClientUid::PerformCancel()
1.115 + {
1.116 + // nothing to cancel
1.117 + }
1.118 +
1.119 +void CSetClientUid::Reset()
1.120 + {
1.121 + iState = EMain;
1.122 + }
1.123 +
1.124 +void CSetClientUid::DoReportAction()
1.125 + {
1.126 + iOut.writeString(_L("Setting users..."));
1.127 + iOut.writeNewLine();
1.128 + }
1.129 +
1.130 +
1.131 +void CSetClientUid::DoCheckResult(TInt aError)
1.132 + {
1.133 + if (iFinished)
1.134 + {
1.135 + if (aError == KErrNone)
1.136 + {
1.137 + _LIT(KSuccessful, "Client UID set successfully\n");
1.138 + iConsole.Write(KSuccessful);
1.139 + iOut.writeString(KSuccessful);
1.140 + iOut.writeNewLine();
1.141 + iOut.writeNewLine();
1.142 + }
1.143 + else
1.144 + {
1.145 + if (aError!=iExpectedResult)
1.146 + {
1.147 + _LIT(KFailed, "!!!Set UID failure!!!\n");
1.148 + iConsole.Write(KFailed);
1.149 + iOut.writeString(KFailed);
1.150 + }
1.151 + else
1.152 + {
1.153 + _LIT(KFailed, "Set UID failed, but expected\n");
1.154 + iConsole.Write(KFailed);
1.155 + iOut.writeString(KFailed);
1.156 + }
1.157 +
1.158 + iOut.writeNewLine();
1.159 + iOut.writeNewLine();
1.160 + }
1.161 + }
1.162 + }
1.163 +
1.164 +