// Copyright Epic Games, Inc. All Rights Reserved.
using System.Collections.Generic;
namespace Gauntlet
{
///
/// Simple node that implements the ITestNode interface and provides some convenience functions for
/// inherited tests to use
///
public abstract class BaseTest : ITestNode
{
///
/// Override this to set the max running time for this test
///
public abstract float MaxDuration { get; protected set; }
///
/// What the test result should be treated as if we reach max duration.
///
public virtual EMaxDurationReachedResult MaxDurationReachedResult { get; set; }
///
/// Override this to set the priority of this test
///
public virtual TestPriority Priority { get { return TestPriority.Normal; } }
///
/// Return the name of this test
///
public abstract string Name { get; }
///
/// Returns true if the test has encountered warnings. Test is expected to list any warnings it considers appropriate in the summary
///
public virtual bool HasWarnings { get; protected set; }
///
/// Returns reason for the test cancellation
///
public virtual string CancellationReason { get; protected set; }
///
/// Returns true if the test was cancelled
///
public virtual bool WasCancelled { get; protected set; }
///
/// Internal status state
///
private TestStatus InnerStatus;
///
/// Return true if the warnings and errors needs to log after summary
///
public virtual bool LogWarningsAndErrorsAfterSummary { get; protected set; } = true;
///
/// Default BaseTest Constructor
///
public BaseTest()
{
SetTestStatus(TestStatus.NotStarted);
}
///
/// OVerride this to return the result of the test
///
///
public abstract TestResult GetTestResult();
///
/// Set the test result value of the test.
///
/// New result that the Test should have.
public abstract void SetTestResult(TestResult InTestResult);
///
/// Add a new test event to be rolled up into the summary at the end of this test.
///
public virtual void AddTestEvent(UnrealTestEvent InEvent)
{
}
///
/// Summarize the result of the test
///
///
public virtual string GetTestSummary()
{
return string.Format("{0}: {1}", Name, GetTestResult());
}
///
/// Return list of warnings. Empty by default
///
///
public virtual IEnumerable GetWarnings()
{
return System.Array.Empty();
}
///
/// Return list of errors. Empty by default
///
///
public virtual IEnumerable GetErrors()
{
return System.Array.Empty();
}
public virtual string GetRunLocalCommand(string LaunchingBuildCommand)
{
string CommandToRunLocally =
string.Format("RunUAT {0} -Test={1} ", LaunchingBuildCommand, GetType());
return CommandToRunLocally;
}
///
/// Updates the test status to the passed in value
///
///
protected void SetTestStatus(TestStatus InStatus)
{
InnerStatus = InStatus;
}
///
/// Mark the test as started
///
///
protected void MarkTestStarted()
{
SetTestStatus(TestStatus.InProgress);
SetTestResult(TestResult.Invalid);
}
///
/// Mark the test as complete
///
///
protected void MarkTestComplete()
{
SetTestStatus(TestStatus.Complete);
}
///
/// Return our internal status
///
///
public TestStatus GetTestStatus()
{
return InnerStatus;
}
public virtual bool IsReadyToStart()
{
return true;
}
///
/// Called to request the test launch. Should call MarkTestComplete
///
///
public abstract bool StartTest(int Pass, int NumPasses);
///
/// Called to request the test is shutdown
///
///
public abstract void CleanupTest();
///
/// Called if TestResult returns WantRetry. Can be overridden for something
/// more elegant than a hard shutdown/launch
///
///
public virtual bool RestartTest()
{
CleanupTest();
return StartTest(0, 1);
}
///
/// Gives the test a chance to perform logic. Should call MarkComplete() when it detects a
/// success or error state
///
///
public virtual void TickTest()
{
}
///
/// Sets Cancellation Reason.
///
///
///
public virtual void SetCancellationReason(string InReason)
{
CancellationReason = InReason;
}
///
/// Called after the test is completed and shutdown
///
///
///
public virtual void StopTest(StopReason InReason)
{
WasCancelled = InReason != StopReason.Completed;
}
///
/// Helper to set context
///
///
///
public virtual void SetContext(ITestContext InContext)
{
}
///
/// Output all defined commandline information for this test to the gauntlet window and exit test early.
///
public virtual void DisplayCommandlineHelp()
{
}
}
}