sl@0: /* sl@0: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "t_testaction.h" sl@0: sl@0: #include "t_output.h" sl@0: #include "t_input.h" sl@0: #include "t_testactionspec.h" sl@0: #include "tScriptSetup.h" sl@0: #include "t_testhandler.h" sl@0: sl@0: EXPORT_C CTestAction::~CTestAction() sl@0: { sl@0: delete iNameInfo; sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::PerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: DoPerformPrerequisite(aStatus); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::PerformPostrequisite(TRequestStatus& aStatus) sl@0: { sl@0: DoPerformPostrequisite(aStatus); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::AfterOOMFailure() sl@0: { sl@0: } sl@0: sl@0: TBool CTestAction::Finished() sl@0: { sl@0: return iFinished; sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::ReportAction() sl@0: { sl@0: iOut.writeString(*iNameInfo); sl@0: iOut.writeNewLine(); sl@0: DoReportAction(); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::CheckResult(TInt aError) sl@0: { sl@0: sl@0: // DoCheckResult must update iResult sl@0: //iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult); sl@0: DoCheckResult(aError); sl@0: sl@0: if (iKnownFailure) // Expecting an error because of known sl@0: iResult = ETrue; // defect current deferred etc sl@0: sl@0: iOut.writeString(_L("\tStatus : ")); sl@0: iOut.writeError(aError); sl@0: iOut.writeString(_L(" (")); sl@0: iOut.writeNum(aError); sl@0: iOut.writeString(_L(")")); sl@0: iOut.writeNewLine(); sl@0: iOut.writeString(_L("\tTest outcome : ")); sl@0: if (iResult) sl@0: { sl@0: iOut.writeString(_L("PASSED")); sl@0: } sl@0: else sl@0: { sl@0: iOut.writeString(_L("FAILED")); sl@0: } sl@0: iOut.writeNewLine(); sl@0: iOut.writeNewLine(); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::PerformCancel() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::Reset() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CTestAction::CTestAction(CConsoleBase& aConsole, sl@0: Output& aOut) sl@0: : iFinished(EFalse), iKnownFailure(EFalse), iConsole(aConsole), iOut(aOut) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::ConstructL(const TTestActionSpec& aTestActionSpec) sl@0: { sl@0: iNameInfo = aTestActionSpec.iActionName.AllocL(); sl@0: sl@0: iTefScript = aTestActionSpec.iTefScript; sl@0: sl@0: TRAPD(err, iExpectedResult = Input::ParseElementBoolL( sl@0: aTestActionSpec.iActionResult, _L8("")) ); sl@0: if(err == KErrArgument) sl@0: { sl@0: //if there is no field or it has invalid text then we assume sl@0: //it's a "normal" test. ie it must be true to pass. sl@0: iExpectedResult = ETrue; sl@0: } sl@0: else if(err != KErrNone) sl@0: { sl@0: User::Leave(err); sl@0: } sl@0: sl@0: // If there's a known defect because of deferred defects etc, the script sl@0: // will flag it. We record as much here and, when result is returned, check sl@0: // against known failure and adjust result accordingly. This should only be sl@0: // used for reported defects that have been deferred etc rather than as a sl@0: // workaround for test failures. The failure will be reported in a separate sl@0: // part of the log file so it's not overlooked entirely. sl@0: sl@0: _LIT8(KTrue, "ETrue"); sl@0: // _LIT8(KFalse, "EFalse"); sl@0: sl@0: TInt pos = 0; sl@0: err = KErrNone; sl@0: sl@0: TPtrC8 knownFailure = Input::ParseElement(aTestActionSpec.iActionBody, KKnownDefectStart, KKnownDefectEnd, pos, err); sl@0: if (knownFailure.Compare(KTrue)==0) sl@0: iKnownFailure = ETrue; sl@0: else // Assume if it's not true it's false or not there which == false sl@0: iKnownFailure = EFalse; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void CTestAction::DoPerformPrerequisite(TRequestStatus& aStatus) sl@0: { sl@0: iActionState = EAction; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::DoPerformPostrequisite(TRequestStatus& aStatus) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: // pass on any error from peform action sl@0: User::RequestComplete(status, aStatus.Int()); sl@0: iFinished = ETrue; sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::FailTestNow(TRequestStatus& aStatus) sl@0: { sl@0: iActionState=EPostrequisite; sl@0: iResult=EFalse; sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CTestAction::TScriptError CTestAction::ScriptError(void) sl@0: { sl@0: return(iScriptError); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::SetScriptError(const TScriptError &aScriptError, const TDesC& aError) sl@0: { sl@0: iScriptError = aScriptError; sl@0: aScriptErrorDescription.Copy(aError); sl@0: }; sl@0: sl@0: EXPORT_C void CTestAction::ScriptError(TDes& aError) sl@0: { sl@0: aError.Copy(aScriptErrorDescription); sl@0: }; sl@0: sl@0: void CTestAction::SetTestHandler(CTestHandler& aTestHandler) sl@0: { sl@0: iTestHandler = &aTestHandler; sl@0: } sl@0: sl@0: EXPORT_C CBase* CTestAction::SharedData() const sl@0: { sl@0: ASSERT(iTestHandler); sl@0: return iTestHandler->SharedData(); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::SetSharedData(CBase* aData) sl@0: { sl@0: ASSERT(iTestHandler); sl@0: iTestHandler->SetSharedData(aData); sl@0: } sl@0: sl@0: EXPORT_C void CTestAction::ResetState() sl@0: { sl@0: }