os/security/cryptomgmtlibs/securitytestfw/test/testhandler2/t_testaction.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/testhandler2/t_testaction.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,200 @@
     1.4 +/*
     1.5 +* Copyright (c) 1998-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 "t_testaction.h"
    1.23 +
    1.24 +#include "t_output.h"
    1.25 +#include "t_input.h"
    1.26 +#include "t_testactionspec.h"
    1.27 +#include "tScriptSetup.h"
    1.28 +#include "t_testhandler.h"
    1.29 +
    1.30 +EXPORT_C CTestAction::~CTestAction()
    1.31 +	{
    1.32 +	delete iNameInfo;
    1.33 +	}
    1.34 +
    1.35 +EXPORT_C void CTestAction::PerformPrerequisite(TRequestStatus& aStatus)
    1.36 +	{
    1.37 +	DoPerformPrerequisite(aStatus);
    1.38 +	}
    1.39 +
    1.40 +EXPORT_C void CTestAction::PerformPostrequisite(TRequestStatus& aStatus)
    1.41 +	{
    1.42 +	DoPerformPostrequisite(aStatus);
    1.43 +	}
    1.44 +
    1.45 +EXPORT_C void CTestAction::AfterOOMFailure()
    1.46 +	{
    1.47 +	}
    1.48 +
    1.49 +TBool CTestAction::Finished()
    1.50 +	{
    1.51 +	return iFinished;
    1.52 +	}
    1.53 +
    1.54 +EXPORT_C void CTestAction::ReportAction()
    1.55 +	{
    1.56 +	iOut.writeString(*iNameInfo);
    1.57 +	iOut.writeNewLine();
    1.58 +	DoReportAction();
    1.59 +	}
    1.60 +
    1.61 +EXPORT_C void CTestAction::CheckResult(TInt aError)
    1.62 +{
    1.63 +
    1.64 +	// DoCheckResult must update iResult 
    1.65 +	//iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
    1.66 +	DoCheckResult(aError);
    1.67 +	
    1.68 +	if (iKnownFailure)		//	Expecting an error because of known
    1.69 +		iResult = ETrue;	//	defect current deferred etc
    1.70 +	
    1.71 +	iOut.writeString(_L("\tStatus : "));
    1.72 +	iOut.writeError(aError);
    1.73 +	iOut.writeString(_L(" ("));
    1.74 +	iOut.writeNum(aError);
    1.75 +	iOut.writeString(_L(")"));
    1.76 +	iOut.writeNewLine();
    1.77 +	iOut.writeString(_L("\tTest outcome : "));
    1.78 +	if (iResult)
    1.79 +		{
    1.80 +		iOut.writeString(_L("PASSED"));
    1.81 +		}
    1.82 +	else
    1.83 +		{
    1.84 +		iOut.writeString(_L("FAILED"));
    1.85 +		}
    1.86 +	iOut.writeNewLine();
    1.87 +	iOut.writeNewLine();
    1.88 +	}
    1.89 +
    1.90 +EXPORT_C void CTestAction::PerformCancel()
    1.91 +	{
    1.92 +	}
    1.93 +
    1.94 +EXPORT_C void CTestAction::Reset()
    1.95 +	{
    1.96 +	}
    1.97 +
    1.98 +EXPORT_C CTestAction::CTestAction(CConsoleBase& aConsole,
    1.99 +								  Output& aOut)
   1.100 +: iFinished(EFalse), iKnownFailure(EFalse), iConsole(aConsole), iOut(aOut)
   1.101 +	{
   1.102 +	}
   1.103 +
   1.104 +EXPORT_C void CTestAction::ConstructL(const TTestActionSpec& aTestActionSpec)
   1.105 +{
   1.106 +	iNameInfo = aTestActionSpec.iActionName.AllocL();
   1.107 +	
   1.108 +	iTefScript = aTestActionSpec.iTefScript;
   1.109 +	
   1.110 +	TRAPD(err, iExpectedResult = Input::ParseElementBoolL(
   1.111 +		aTestActionSpec.iActionResult, _L8("<result>")) );
   1.112 +	if(err == KErrArgument)
   1.113 +		{
   1.114 +		//if there is no <result> field or it has invalid text then we assume
   1.115 +		//it's a "normal" test.  ie it must be true to pass.
   1.116 +		iExpectedResult = ETrue; 
   1.117 +		}
   1.118 +	else if(err != KErrNone)
   1.119 +		{
   1.120 +		User::Leave(err);
   1.121 +		}
   1.122 +	
   1.123 +//	If there's a known defect because of deferred defects etc, the script
   1.124 +//	will flag it.  We record as much here and, when result is returned, check
   1.125 +//	against known failure and adjust result accordingly.  This should only be
   1.126 +//	used for reported defects that have been deferred etc rather than as a 
   1.127 +//	workaround for test failures.  The failure will be reported in a separate
   1.128 +//	part of the log file so it's not overlooked entirely.
   1.129 +	
   1.130 +	_LIT8(KTrue, "ETrue");
   1.131 +	// _LIT8(KFalse, "EFalse");
   1.132 +
   1.133 +	TInt pos = 0; 
   1.134 +	err = KErrNone;
   1.135 +	
   1.136 +	TPtrC8 knownFailure = Input::ParseElement(aTestActionSpec.iActionBody, KKnownDefectStart, KKnownDefectEnd, pos, err);	
   1.137 +	if (knownFailure.Compare(KTrue)==0)
   1.138 +		iKnownFailure = ETrue;
   1.139 +	else	//	Assume if it's not true it's false or not there which == false
   1.140 +		iKnownFailure = EFalse;
   1.141 +}
   1.142 +
   1.143 +
   1.144 +EXPORT_C void CTestAction::DoPerformPrerequisite(TRequestStatus& aStatus)
   1.145 +	{
   1.146 +	iActionState = EAction;
   1.147 +	TRequestStatus* status = &aStatus;
   1.148 +	User::RequestComplete(status, KErrNone);
   1.149 +	}
   1.150 +
   1.151 +EXPORT_C void CTestAction::DoPerformPostrequisite(TRequestStatus& aStatus)
   1.152 +	{
   1.153 +	TRequestStatus* status = &aStatus;
   1.154 +	// pass on any error from peform action
   1.155 +	User::RequestComplete(status, aStatus.Int()); 
   1.156 +	iFinished = ETrue;
   1.157 +	}
   1.158 +
   1.159 +EXPORT_C void CTestAction::FailTestNow(TRequestStatus& aStatus)
   1.160 +	{
   1.161 +	iActionState=EPostrequisite;
   1.162 +	iResult=EFalse;
   1.163 +	TRequestStatus* status = &aStatus;
   1.164 +	User::RequestComplete(status, KErrNone);
   1.165 +	}
   1.166 +
   1.167 +
   1.168 +EXPORT_C CTestAction::TScriptError CTestAction::ScriptError(void)
   1.169 +	{
   1.170 +	return(iScriptError);
   1.171 +	}
   1.172 +
   1.173 +EXPORT_C void CTestAction::SetScriptError(const TScriptError &aScriptError, const TDesC& aError)
   1.174 +	{
   1.175 +	iScriptError = aScriptError;
   1.176 +	aScriptErrorDescription.Copy(aError); 
   1.177 +	};
   1.178 +
   1.179 +EXPORT_C void CTestAction::ScriptError(TDes& aError)
   1.180 +	{
   1.181 +	aError.Copy(aScriptErrorDescription);
   1.182 +	};
   1.183 +
   1.184 +void CTestAction::SetTestHandler(CTestHandler& aTestHandler)
   1.185 +	{
   1.186 +	iTestHandler = &aTestHandler;
   1.187 +	}
   1.188 +
   1.189 +EXPORT_C CBase* CTestAction::SharedData() const
   1.190 +	{
   1.191 +	ASSERT(iTestHandler);
   1.192 +	return iTestHandler->SharedData();
   1.193 +	}
   1.194 +
   1.195 +EXPORT_C void CTestAction::SetSharedData(CBase* aData)
   1.196 +	{
   1.197 +	ASSERT(iTestHandler);
   1.198 +	iTestHandler->SetSharedData(aData);
   1.199 +	}
   1.200 +
   1.201 +EXPORT_C void CTestAction::ResetState()
   1.202 +	{
   1.203 +	}