os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_setclientuid.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include <unifiedkeystore.h>
    20 #include <e32base.h>
    21 #include "t_keystore_actions.h"
    22 #include "t_keystore_defs.h"
    23 #include "t_input.h"
    24 #include "t_output.h"
    25 
    26 /////////////////////////////////////////////////////////////////////////////////
    27 // CSetClientUid
    28 /////////////////////////////////////////////////////////////////////////////////
    29 
    30 CTestAction* CSetClientUid::NewL(RFs& aFs, 
    31 							 CConsoleBase& aConsole, 
    32 							 Output& aOut,
    33 							 const TTestActionSpec& aTestActionSpec)
    34 	{
    35 	CTestAction* self = CSetClientUid::NewLC(aFs, aConsole, aOut, aTestActionSpec);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}
    39 
    40 CTestAction* CSetClientUid::NewLC(RFs& aFs,
    41 							  CConsoleBase& aConsole, 
    42 							  Output& aOut,
    43 							  const TTestActionSpec& aTestActionSpec)
    44 	{
    45 	CSetClientUid* self = new (ELeave) CSetClientUid(aFs, aConsole, aOut);
    46 	CleanupStack::PushL(self);
    47 	self->ConstructL(aTestActionSpec);
    48 	return self;
    49 	}
    50 
    51 CSetClientUid::~CSetClientUid()
    52 	{
    53 	}
    54 
    55 CSetClientUid::CSetClientUid(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
    56 	CKeyStoreTestAction(aFs, aConsole, aOut), iState(EMain)
    57 	{
    58 	}
    59 
    60 void CSetClientUid::ConstructL(const TTestActionSpec& aTestActionSpec)
    61 	{
    62 	CKeyStoreTestAction::ConstructL(aTestActionSpec);
    63 
    64 	TPtrC8 data = Input::ParseElement(aTestActionSpec.iActionBody, KUidStart);
    65 	if (data.Length() == 0)
    66 		User::Leave(KErrNotFound);
    67 	
    68 	TLex8 lex(data);
    69 	lex.Val(iUid.iUid);
    70 	}
    71 
    72 void CSetClientUid::PerformAction(TRequestStatus& aStatus)
    73 	{
    74 	switch (iState)
    75 		{
    76 		case EMain:
    77 			{
    78 			RProcess thisProcess;
    79 			thisProcess.Open(thisProcess.Id());
    80 			CleanupClosePushL(thisProcess);
    81 			TUidType type = thisProcess.Type();
    82 			TUidType newType(type[0], type[1], iUid);
    83 			thisProcess.SetType(newType);
    84 			CleanupStack::PopAndDestroy(); // thisProcess
    85 			
    86 			iState = EFinished;
    87 			TRequestStatus* status = &aStatus;
    88 			User::RequestComplete(status, KErrNone);
    89 			break;
    90 			}
    91 
    92 		case EFinished:
    93 			{
    94 			TRequestStatus* status = &aStatus;
    95 			User::RequestComplete(status, aStatus.Int());
    96 			if (aStatus == iExpectedResult)
    97 				{
    98 				iResult = ETrue;
    99 				}
   100 			else
   101 				{
   102 				iResult = EFalse;
   103 				}
   104 			
   105 			iActionState = EPostrequisite;
   106 			}
   107 			break;
   108 		}
   109 	}
   110 
   111 void CSetClientUid::PerformCancel()
   112 	{
   113     // nothing to cancel
   114 	}
   115 
   116 void CSetClientUid::Reset()
   117 	{
   118 	iState = EMain;
   119 	}
   120 
   121 void CSetClientUid::DoReportAction()
   122 	{
   123 	iOut.writeString(_L("Setting users..."));
   124 	iOut.writeNewLine();
   125 	}
   126 
   127 
   128 void CSetClientUid::DoCheckResult(TInt aError)
   129 	{
   130 	if (iFinished)
   131 		{
   132 		if (aError == KErrNone)
   133 			{
   134 			_LIT(KSuccessful, "Client UID set successfully\n");
   135 			iConsole.Write(KSuccessful);
   136 			iOut.writeString(KSuccessful);
   137 			iOut.writeNewLine();
   138 			iOut.writeNewLine();
   139 			}
   140 		else
   141 			{
   142 			if (aError!=iExpectedResult)
   143 				{
   144 				_LIT(KFailed, "!!!Set UID  failure!!!\n");
   145 				iConsole.Write(KFailed);
   146 				iOut.writeString(KFailed);
   147 				}
   148 			else
   149 				{
   150 				_LIT(KFailed, "Set UID failed, but expected\n");
   151 				iConsole.Write(KFailed);
   152 				iOut.writeString(KFailed);
   153 				}
   154 
   155 			iOut.writeNewLine();
   156 			iOut.writeNewLine();
   157 			}
   158 		}
   159 	}
   160 
   161