os/security/cryptoservices/filebasedcertificateandkeystores/test/tkeystore/t_settime.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 // CSetTime
    28 /////////////////////////////////////////////////////////////////////////////////
    29 
    30 CTestAction* CSetTime::NewL(RFs& aFs, 
    31 							 CConsoleBase& aConsole, 
    32 							 Output& aOut,
    33 							 const TTestActionSpec& aTestActionSpec)
    34 	{
    35 	CTestAction* self = CSetTime::NewLC(aFs, aConsole, aOut, aTestActionSpec);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}
    39 
    40 CTestAction* CSetTime::NewLC(RFs& aFs,
    41 							  CConsoleBase& aConsole, 
    42 							  Output& aOut,
    43 							  const TTestActionSpec& aTestActionSpec)
    44 	{
    45 	CSetTime* self = new (ELeave) CSetTime(aFs, aConsole, aOut);
    46 	CleanupStack::PushL(self);
    47 	self->ConstructL(aTestActionSpec);
    48 	return self;
    49 	}
    50 
    51 CSetTime::~CSetTime()
    52 	{
    53 	}
    54 
    55 CSetTime::CSetTime(RFs& aFs, CConsoleBase& aConsole, Output& aOut) :
    56 	CKeyStoreTestAction(aFs, aConsole, aOut), iState(EMain)
    57 	{
    58 	}
    59 
    60 void CSetTime::ConstructL(const TTestActionSpec& aTestActionSpec)
    61 	{
    62 	CKeyStoreTestAction::ConstructL(aTestActionSpec);
    63 
    64 	TPtrC8 data = Input::ParseElement(aTestActionSpec.iActionBody, KHomeTimeStart);
    65 	SetNewTimeL(data);
    66 	}
    67 
    68 void CSetTime::PerformAction(TRequestStatus& aStatus)
    69 	{
    70 	switch (iState)
    71 		{
    72 		case EMain:
    73 			{
    74 			User::LeaveIfError(User::SetHomeTime(iNewTime));
    75 			
    76 			iState = EFinished;
    77 			TRequestStatus* status = &aStatus;
    78 			User::RequestComplete(status, KErrNone);
    79 			break;
    80 			}
    81 
    82 		case EFinished:
    83 			{
    84 			TRequestStatus* status = &aStatus;
    85 			User::RequestComplete(status, aStatus.Int());
    86 			if (aStatus == iExpectedResult)
    87 				{
    88 				iResult = ETrue;
    89 				}
    90 			else
    91 				{
    92 				iResult = EFalse;
    93 				}
    94 			
    95 			iActionState = EPostrequisite;
    96 			}
    97 			break;
    98 		}
    99 	}
   100 
   101 void CSetTime::PerformCancel()
   102 	{
   103     // nothing to cancel
   104 	}
   105 
   106 void CSetTime::Reset()
   107 	{
   108 	iState = EMain;
   109 	}
   110 
   111 void CSetTime::DoReportAction()
   112 	{
   113 	iOut.writeString(_L("Setting time..."));
   114 	iOut.writeNewLine();
   115 	}
   116 
   117 void CSetTime::DoCheckResult(TInt aError)
   118 	{
   119 	if (iFinished)
   120 		{
   121 		if (aError == KErrNone)
   122 			{
   123 			_LIT(KSuccessful, "Time set successfully\n");
   124 			iConsole.Write(KSuccessful);
   125 			iOut.writeString(KSuccessful);
   126 			iOut.writeNewLine();
   127 			iOut.writeNewLine();
   128 			}
   129 		else
   130 			{
   131 			if (aError!=iExpectedResult)
   132 				{
   133 				_LIT(KFailed, "!!!Set time failure!!!\n");
   134 				iConsole.Write(KFailed);
   135 				iOut.writeString(KFailed);
   136 				}
   137 			else
   138 				{
   139 				_LIT(KFailed, "Set time failed, but expected\n");
   140 				iConsole.Write(KFailed);
   141 				iOut.writeString(KFailed);
   142 				}
   143 
   144 			iOut.writeNewLine();
   145 			iOut.writeNewLine();
   146 			}
   147 		}
   148 	}
   149 
   150 void CSetTime::SetNewTimeL(const TDesC8& aData)
   151 	{
   152 	HBufC* buf = HBufC::NewLC(aData.Length());
   153 	TPtr ptr = buf->Des();
   154 	ptr.Copy(aData);	
   155 	User::LeaveIfError(iNewTime.Parse(*buf));
   156 	CleanupStack::PopAndDestroy(buf);
   157 	}