JD2022-TU1/main/tools/apps/TeaBox/Script/Tools/FunctionalTests/LaunchToolsFunctionalTest.cs

82 lines
No EOL
2.6 KiB
C#

using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JD.Asset.Types.Map;
using NUnit.Framework;
using TeaBox.Code;
using TeaBox.Deadline;
using TeaBox.Diagnostics;
using TeaBox.Macros;
using ExecutionContext = TeaBox.Macros.ExecutionContext;
namespace TeaBox.UAF
{
[TestFixture]
public class LaunchToolsFunctionalTest
{
[Test, Category("Functional")]
public void Test_all_tools_can_be_launched()
{
var asyncTools = ToolExtensions.GetTestableTools(async: true).ToArray();
Parallel.ForEach(asyncTools, ExecuteToolLaunchTestStep);
var syncTools = ToolExtensions.GetTestableTools(async: false).ToArray();
syncTools.ForEach(ExecuteToolLaunchTestStep);
}
[Test, Category("Functional"), Ignore("")]
public void Test_video_captures()
{
var logger = new LoggingContext();
var context = new ExecutionContext(logger);
var captureCommand = new CaptureCommand
{
Map = Map.FromName(@"_TestMap"),
VideoCaptureParameters =
{
GameVisualElements = GameVisualElement.All,
FrameCount = 10,
}
};
captureCommand.Execute(context);
Assert.IsEmpty(logger.Errors);
Assert.AreEqual(context.PlaylistResult, MacroResult.Succeeded);
}
private static void ExecuteToolLaunchTestStep(Tool tool)
{
var process = new Process
{
StartInfo = { FileName = tool.Paths().ReleaseExeFile, CreateNoWindow = true }
};
process.Start();
DebugTimer timer = new DebugTimer();
TimeSpan timeout = TimeSpan.FromSeconds(90);
timer.Start();
// Spam window closing events until it is actually handled or until reaching timeout
while (!process.HasExited && timer.TotalElapsed < timeout)
{
Thread.Sleep(500);
process.CloseMainWindow();
}
if (!process.HasExited)
{
process.Kill();
Assert.Fail("{0} timed out after {1} seconds, killing process.", tool, timer.TotalElapsed.TotalSeconds);
}
else
{
Trace.WriteLine(string.Format("{0} exited with code {1} in {2} seconds", tool, process.ExitCode, timer.TotalElapsed.TotalSeconds));
process.Close();
}
}
}
}