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