cryptomgmtlibs/securitytestfw/test/testhandler2/t_testaction.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 1998-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 "t_testaction.h"
       
    20 
       
    21 #include "t_output.h"
       
    22 #include "t_input.h"
       
    23 #include "t_testactionspec.h"
       
    24 #include "tScriptSetup.h"
       
    25 #include "t_testhandler.h"
       
    26 
       
    27 EXPORT_C CTestAction::~CTestAction()
       
    28 	{
       
    29 	delete iNameInfo;
       
    30 	}
       
    31 
       
    32 EXPORT_C void CTestAction::PerformPrerequisite(TRequestStatus& aStatus)
       
    33 	{
       
    34 	DoPerformPrerequisite(aStatus);
       
    35 	}
       
    36 
       
    37 EXPORT_C void CTestAction::PerformPostrequisite(TRequestStatus& aStatus)
       
    38 	{
       
    39 	DoPerformPostrequisite(aStatus);
       
    40 	}
       
    41 
       
    42 EXPORT_C void CTestAction::AfterOOMFailure()
       
    43 	{
       
    44 	}
       
    45 
       
    46 TBool CTestAction::Finished()
       
    47 	{
       
    48 	return iFinished;
       
    49 	}
       
    50 
       
    51 EXPORT_C void CTestAction::ReportAction()
       
    52 	{
       
    53 	iOut.writeString(*iNameInfo);
       
    54 	iOut.writeNewLine();
       
    55 	DoReportAction();
       
    56 	}
       
    57 
       
    58 EXPORT_C void CTestAction::CheckResult(TInt aError)
       
    59 {
       
    60 
       
    61 	// DoCheckResult must update iResult 
       
    62 	//iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
       
    63 	DoCheckResult(aError);
       
    64 	
       
    65 	if (iKnownFailure)		//	Expecting an error because of known
       
    66 		iResult = ETrue;	//	defect current deferred etc
       
    67 	
       
    68 	iOut.writeString(_L("\tStatus : "));
       
    69 	iOut.writeError(aError);
       
    70 	iOut.writeString(_L(" ("));
       
    71 	iOut.writeNum(aError);
       
    72 	iOut.writeString(_L(")"));
       
    73 	iOut.writeNewLine();
       
    74 	iOut.writeString(_L("\tTest outcome : "));
       
    75 	if (iResult)
       
    76 		{
       
    77 		iOut.writeString(_L("PASSED"));
       
    78 		}
       
    79 	else
       
    80 		{
       
    81 		iOut.writeString(_L("FAILED"));
       
    82 		}
       
    83 	iOut.writeNewLine();
       
    84 	iOut.writeNewLine();
       
    85 	}
       
    86 
       
    87 EXPORT_C void CTestAction::PerformCancel()
       
    88 	{
       
    89 	}
       
    90 
       
    91 EXPORT_C void CTestAction::Reset()
       
    92 	{
       
    93 	}
       
    94 
       
    95 EXPORT_C CTestAction::CTestAction(CConsoleBase& aConsole,
       
    96 								  Output& aOut)
       
    97 : iFinished(EFalse), iKnownFailure(EFalse), iConsole(aConsole), iOut(aOut)
       
    98 	{
       
    99 	}
       
   100 
       
   101 EXPORT_C void CTestAction::ConstructL(const TTestActionSpec& aTestActionSpec)
       
   102 {
       
   103 	iNameInfo = aTestActionSpec.iActionName.AllocL();
       
   104 	
       
   105 	TRAPD(err, iExpectedResult = Input::ParseElementBoolL(
       
   106 		aTestActionSpec.iActionResult, _L8("<result>")) );
       
   107 	if(err == KErrArgument)
       
   108 		{
       
   109 		//if there is no <result> field or it has invalid text then we assume
       
   110 		//it's a "normal" test.  ie it must be true to pass.
       
   111 		iExpectedResult = ETrue; 
       
   112 		}
       
   113 	else if(err != KErrNone)
       
   114 		{
       
   115 		User::Leave(err);
       
   116 		}
       
   117 	
       
   118 //	If there's a known defect because of deferred defects etc, the script
       
   119 //	will flag it.  We record as much here and, when result is returned, check
       
   120 //	against known failure and adjust result accordingly.  This should only be
       
   121 //	used for reported defects that have been deferred etc rather than as a 
       
   122 //	workaround for test failures.  The failure will be reported in a separate
       
   123 //	part of the log file so it's not overlooked entirely.
       
   124 	
       
   125 	_LIT8(KTrue, "ETrue");
       
   126 	// _LIT8(KFalse, "EFalse");
       
   127 
       
   128 	TInt pos = 0; 
       
   129 	err = KErrNone;
       
   130 	
       
   131 	TPtrC8 knownFailure = Input::ParseElement(aTestActionSpec.iActionBody, KKnownDefectStart, KKnownDefectEnd, pos, err);	
       
   132 	if (knownFailure.Compare(KTrue)==0)
       
   133 		iKnownFailure = ETrue;
       
   134 	else	//	Assume if it's not true it's false or not there which == false
       
   135 		iKnownFailure = EFalse;
       
   136 }
       
   137 
       
   138 
       
   139 EXPORT_C void CTestAction::DoPerformPrerequisite(TRequestStatus& aStatus)
       
   140 	{
       
   141 	iActionState = EAction;
       
   142 	TRequestStatus* status = &aStatus;
       
   143 	User::RequestComplete(status, KErrNone);
       
   144 	}
       
   145 
       
   146 EXPORT_C void CTestAction::DoPerformPostrequisite(TRequestStatus& aStatus)
       
   147 	{
       
   148 	TRequestStatus* status = &aStatus;
       
   149 	// pass on any error from peform action
       
   150 	User::RequestComplete(status, aStatus.Int()); 
       
   151 	iFinished = ETrue;
       
   152 	}
       
   153 
       
   154 EXPORT_C void CTestAction::FailTestNow(TRequestStatus& aStatus)
       
   155 	{
       
   156 	iActionState=EPostrequisite;
       
   157 	iResult=EFalse;
       
   158 	TRequestStatus* status = &aStatus;
       
   159 	User::RequestComplete(status, KErrNone);
       
   160 	}
       
   161 
       
   162 
       
   163 EXPORT_C CTestAction::TScriptError CTestAction::ScriptError(void)
       
   164 	{
       
   165 	return(iScriptError);
       
   166 	}
       
   167 
       
   168 EXPORT_C void CTestAction::SetScriptError(const TScriptError &aScriptError, const TDesC& aError)
       
   169 	{
       
   170 	iScriptError = aScriptError;
       
   171 	aScriptErrorDescription.Copy(aError); 
       
   172 	};
       
   173 
       
   174 EXPORT_C void CTestAction::ScriptError(TDes& aError)
       
   175 	{
       
   176 	aError.Copy(aScriptErrorDescription);
       
   177 	};
       
   178 
       
   179 void CTestAction::SetTestHandler(CTestHandler& aTestHandler)
       
   180 	{
       
   181 	iTestHandler = &aTestHandler;
       
   182 	}
       
   183 
       
   184 EXPORT_C CBase* CTestAction::SharedData() const
       
   185 	{
       
   186 	ASSERT(iTestHandler);
       
   187 	return iTestHandler->SharedData();
       
   188 	}
       
   189 
       
   190 EXPORT_C void CTestAction::SetSharedData(CBase* aData)
       
   191 	{
       
   192 	ASSERT(iTestHandler);
       
   193 	iTestHandler->SetSharedData(aData);
       
   194 	}
       
   195 
       
   196 EXPORT_C void CTestAction::ResetState()
       
   197 	{
       
   198 	}