os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_settimeout.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 // CSetTimeout
    28 /////////////////////////////////////////////////////////////////////////////////
    29 
    30 CTestAction* CSetTimeout::NewL(RFs& aFs, 
    31 							 CConsoleBase& aConsole, 
    32 							 Output& aOut,
    33 							 const TTestActionSpec& aTestActionSpec)
    34 	{
    35 	CTestAction* self = CSetTimeout::NewLC(aFs, aConsole, aOut, aTestActionSpec);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}
    39 
    40 CTestAction* CSetTimeout::NewLC(RFs& aFs,
    41 							  CConsoleBase& aConsole, 
    42 							  Output& aOut,
    43 							  const TTestActionSpec& aTestActionSpec)
    44 	{
    45 	CSetTimeout* self = new (ELeave) CSetTimeout(aFs, aConsole, aOut);
    46 	CleanupStack::PushL(self);
    47 	self->ConstructL(aTestActionSpec);
    48 	return self;
    49 	}
    50 
    51 CSetTimeout::~CSetTimeout()
    52 	{
    53 	}
    54 
    55 CSetTimeout::CSetTimeout(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
    56 	CKeyStoreTestAction(aFs, aConsole, aOut), iState(EMain)
    57 	{
    58 	}
    59 
    60 void CSetTimeout::ConstructL(const TTestActionSpec& aTestActionSpec)
    61 	{
    62 	CKeyStoreTestAction::ConstructL(aTestActionSpec);
    63 
    64 	TPtrC8 data = Input::ParseElement(aTestActionSpec.iActionBody, KTimeoutStart);
    65 	if (data.Length() == 0)
    66 		User::Leave(KErrNotFound);
    67 	TLex8 lex(data);
    68 	lex.Val(iNewTimeout);
    69 	}
    70 
    71 void CSetTimeout::PerformAction(TRequestStatus& aStatus)
    72 	{
    73 	switch (iState)
    74 		{
    75 		case EMain:
    76 			{						
    77 			CUnifiedKeyStore& keystore = *CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
    78 
    79 			iState = EFinished;
    80 			keystore.SetPassphraseTimeout(iNewTimeout, aStatus);
    81 			break;
    82 			}
    83 
    84 		case EFinished:
    85 			{
    86 			TRequestStatus* status = &aStatus;
    87 			User::RequestComplete(status, aStatus.Int());
    88 			if (aStatus == iExpectedResult)
    89 				{
    90 				iResult = ETrue;
    91 				}
    92 			else
    93 				{
    94 				iResult = EFalse;
    95 				}
    96 			
    97 			iActionState = EPostrequisite;
    98 			}
    99 			break;
   100 		}
   101 	}
   102 
   103 void CSetTimeout::PerformCancel()
   104 	{
   105     CUnifiedKeyStore* keystore = CSharedKeyStores::TheUnifiedKeyStores().operator[](iKeystore);
   106     ASSERT(keystore);
   107     if (iState == EFinished)
   108         {
   109         keystore->CancelSetPassphraseTimeout();
   110         }
   111 	}
   112 
   113 void CSetTimeout::Reset()
   114 	{
   115 	iState = EMain;
   116 	}
   117 
   118 void CSetTimeout::DoReportAction()
   119 	{
   120 	iOut.writeString(_L("Setting timeout..."));
   121 	iOut.writeNewLine();
   122 	}
   123 
   124 
   125 void CSetTimeout::DoCheckResult(TInt aError)
   126 	{
   127 	if (iFinished)
   128 		{
   129 		if (aError == KErrNone)
   130 			{
   131 			_LIT(KSuccessful, "Timeout set successfully\n");
   132 			iConsole.Write(KSuccessful);
   133 			iOut.writeString(KSuccessful);
   134 			iOut.writeNewLine();
   135 			iOut.writeNewLine();
   136 			}
   137 		else
   138 			{
   139 			if (aError!=iExpectedResult)
   140 				{
   141 				_LIT(KFailed, "!!!Set timeout failure!!!\n");
   142 				iConsole.Write(KFailed);
   143 				iOut.writeString(KFailed);
   144 				}
   145 			else
   146 				{
   147 				_LIT(KFailed, "Set timeout failed, but expected\n");
   148 				iConsole.Write(KFailed);
   149 				iOut.writeString(KFailed);
   150 				}
   151 
   152 			iOut.writeNewLine();
   153 			iOut.writeNewLine();
   154 			}
   155 		}
   156 	}