更新标准 SOP 主界面播放冒烟测试
This commit is contained in:
parent
8e15a900d6
commit
d42e3a0312
@ -177,7 +177,7 @@ internal static class Smoke
|
||||
if(Environment.GetCommandLineArgs().Contains("--check-progress-only"))
|
||||
{ await CheckRemainingWindowProgress(app,window);_exit=0;return; }
|
||||
if(Environment.GetCommandLineArgs().Contains("--standard-sop-only"))
|
||||
{ await CheckStandardSopPlayback(app,window,lifetime);_exit=0;return; }
|
||||
{ await CheckStandardSopPlayback(app,window);_exit=0;return; }
|
||||
if(Environment.GetCommandLineArgs().Contains("--step-counts-only"))
|
||||
{ await CheckStepCounts(app,window);_exit=0;return; }
|
||||
if(Environment.GetCommandLineArgs().Contains("--startup-recipe-only"))
|
||||
@ -785,20 +785,30 @@ internal static class Smoke
|
||||
engine.Stop();
|
||||
}
|
||||
|
||||
private static async Task CheckStandardSopPlayback(App app,Window window,IClassicDesktopStyleApplicationLifetime lifetime)
|
||||
/// <summary>通过主界面验证标准视频切换检测来源,以及停止与播放失败时释放文件。</summary>
|
||||
private static async Task CheckStandardSopPlayback(App app,Window window)
|
||||
{
|
||||
var model=app.Container.Resolve<SopPageViewModel>();
|
||||
var engine=app.Container.Resolve<SopHelper.Engine.Sop.SopEngine>();
|
||||
var view=window.GetVisualDescendants().OfType<SopPage>().Single();
|
||||
var texts=view.GetVisualDescendants().OfType<TextBlock>().Select(t=>t.Text).ToArray();
|
||||
Check(!texts.Contains("步骤计时")&&texts.Contains("流程计时")&&texts.Contains("标准用时"),"Header retains flow and standard times without step timing");
|
||||
var buttons=view.GetVisualDescendants().OfType<Button>().ToArray();
|
||||
Check(!buttons.Any(b=>b.Content?.ToString() is "暂停" or "重置步骤")
|
||||
&&buttons.Any(b=>b.Content?.ToString()=="重置计数"),"Main run controls remove pause and step reset while keeping count reset");
|
||||
// 使用独立配方,避免随程序分发的示例视频影响无视频状态。
|
||||
var store = new RecipeWorkspace(Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT")!);
|
||||
const string recipe = "standard-video-smoke";
|
||||
var config = new SopConfig();
|
||||
config.Sop.Name = recipe;
|
||||
Directory.CreateDirectory(store.DirectoryFor(recipe));
|
||||
SopConfigLoader.Save(config, store.ConfigPath(recipe));
|
||||
model.Recipes.Add(recipe + ".yaml");
|
||||
model.SelectedRecipe = recipe + ".yaml";
|
||||
model.ApplyRecipeCommand.Execute();
|
||||
await Task.Delay(30);
|
||||
var play=view.FindControl<Button>("PlayStandardSopButton")!;
|
||||
Check(!play.IsEffectivelyEnabled,"Standard SOP playback is unavailable when no standard video exists");
|
||||
var store=new RecipeWorkspace(Environment.GetEnvironmentVariable("SOPHELPER_WORKSPACE_ROOT")!);
|
||||
var path=Path.Combine(store.DirectoryFor(Path.GetFileNameWithoutExtension(model.ActiveRecipe)),"sop_stand","sop.avi");
|
||||
var path=Path.Combine(store.DirectoryFor(recipe),"sop_stand","sop.avi");
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
using(var writer=new VideoWriter(path,FourCC.MJPG,10,new OpenCvSharp.Size(160,120)))
|
||||
{
|
||||
@ -813,43 +823,31 @@ internal static class Smoke
|
||||
model.ApplyRecipeCommand.Execute();await Task.Delay(30);
|
||||
Check(play.IsEffectivelyEnabled,"Applying a recipe with a saved standard video enables playback");
|
||||
model.StartStopCommand.Execute();for(var i=0;i<100&&!model.IsRunning;i++)await Task.Delay(20);
|
||||
Check(model.IsRunning&&Camera.IsGrabbing,"Acquisition can run alongside standard video playback");
|
||||
var cameraConnections=Camera.ConnectCount;var state=engine.State;
|
||||
play.Command!.Execute(play.CommandParameter);await Task.Delay(30);
|
||||
var player=lifetime.Windows.OfType<StandardSopWindow>().Single();
|
||||
for(var i=0;i<100&&player.Playback.Frame is null;i++)await Task.Delay(20);
|
||||
Check(player.VideoPath==path&&player.Playback.IsLoaded&&player.Playback.Frame is not null,"Playback opens and decodes the applied recipe's standard video");
|
||||
play.Command.Execute(play.CommandParameter);
|
||||
Check(lifetime.Windows.OfType<StandardSopWindow>().Count()==1,"Repeated playback clicks reuse the existing player");
|
||||
Check(model.IsRunning&&Camera.IsGrabbing&&Camera.ConnectCount==cameraConnections&&engine.State==state,"Opening standard SOP playback preserves acquisition and engine state");
|
||||
var toggle=player.FindControl<Button>("PlaybackToggleButton")!;
|
||||
toggle.RaiseEvent(new Avalonia.Interactivity.RoutedEventArgs(Button.ClickEvent));
|
||||
Check(!player.Playback.IsPlaying,"Standard video supports pausing independently of acquisition");
|
||||
player.FindControl<Slider>("PlaybackSeekSlider")!.Value=60;
|
||||
for(var i=0;i<100&&(player.Playback.IsSeeking||player.Playback.DisplayedSeconds<2);i++)await Task.Delay(20);
|
||||
Check(player.Playback.DisplayedSeconds>=2&&!player.Playback.IsPlaying,"Standard video supports seeking while paused");
|
||||
var screenshots=Path.GetFullPath(Path.Combine("..","scratch","screenshots"));Directory.CreateDirectory(screenshots);
|
||||
using(var rendered=new RenderTargetBitmap(new PixelSize((int)player.Bounds.Width,(int)player.Bounds.Height)))
|
||||
{rendered.Render(player);rendered.Save(Path.Combine(screenshots,"standard-sop-playback.png"));}
|
||||
toggle.RaiseEvent(new Avalonia.Interactivity.RoutedEventArgs(Button.ClickEvent));await Task.Delay(40);
|
||||
Check(player.Playback.IsPlaying,"Standard video resumes from the selected position");
|
||||
player.Close();for(var i=0;i<100&&player.IsVisible;i++)await Task.Delay(20);
|
||||
Check(!player.IsVisible&&!player.Playback.IsLoaded&&Camera.IsGrabbing,"Closing playback releases the video and preserves acquisition");
|
||||
using(var exclusive=new FileStream(path,FileMode.Open,FileAccess.ReadWrite,FileShare.None))Check(exclusive.Length>0,"Video file is unlocked after the player closes");
|
||||
play.Command.Execute(play.CommandParameter);
|
||||
var quick=lifetime.Windows.OfType<StandardSopWindow>().Single();quick.Close();
|
||||
for(var i=0;i<100&&quick.IsVisible;i++)await Task.Delay(20);
|
||||
Check(!quick.IsVisible&&!quick.Playback.IsLoaded,"Closing during video opening also releases playback resources");
|
||||
Check(model.IsRunning && Camera.IsGrabbing, "播放前相机正在采集");
|
||||
var cameraConnections = Camera.ConnectCount;
|
||||
play.Command!.Execute(play.CommandParameter);
|
||||
bool VideoFrameShown() => model.PreviewFrame is SopHelper.Presentation.Imaging.BitmapSource { PixelWidth: 160, PixelHeight: 120 };
|
||||
for (var i = 0; i < 100 && !VideoFrameShown(); i++) await Task.Delay(20);
|
||||
Check(model.IsRunning && !Camera.IsGrabbing && Camera.ConnectCount == cameraConnections
|
||||
&& model.StandardSopButtonText == "停止标准 SOP" && VideoFrameShown(),
|
||||
"主界面切换到标准视频画面并运行检测");
|
||||
var screenshots = Path.GetFullPath(Path.Combine("..", "scratch", "screenshots"));
|
||||
Directory.CreateDirectory(screenshots);
|
||||
window.WindowState=WindowState.Normal;window.Width=1180;window.Height=820;await Task.Delay(50);window.UpdateLayout();
|
||||
using(var rendered=new RenderTargetBitmap(new PixelSize((int)window.Bounds.Width,(int)window.Bounds.Height)))
|
||||
{rendered.Render(window);rendered.Save(Path.Combine(screenshots,"standard-sop-main.png"));}
|
||||
File.WriteAllText(path,"damaged-video");play.Command.Execute(play.CommandParameter);
|
||||
var damaged=lifetime.Windows.OfType<StandardSopWindow>().Single();
|
||||
for(var i=0;i<100&&string.IsNullOrWhiteSpace(damaged.FindControl<TextBlock>("PlaybackErrorText")!.Text);i++)await Task.Delay(20);
|
||||
Check(damaged.FindControl<TextBlock>("PlaybackErrorText")!.Text?.Contains("无法播放")==true&&!damaged.Playback.IsLoaded,"Damaged standard video reports a playback error without loading a capture");
|
||||
damaged.Close();for(var i=0;i<100&&damaged.IsVisible;i++)await Task.Delay(20);
|
||||
Check(model.IsRunning&&Camera.IsGrabbing&&Camera.ConnectCount==cameraConnections,"Playback errors do not change the running camera");
|
||||
model.StartStopCommand.Execute();for(var i=0;i<100&&model.IsRunning;i++)await Task.Delay(20);
|
||||
{rendered.Render(window);rendered.Save(Path.Combine(screenshots,"standard-sop-main.png"), PngBitmapEncoderOptions.Default);}
|
||||
play.Command.Execute(play.CommandParameter);
|
||||
for (var i = 0; i < 100 && model.IsRunning; i++) await Task.Delay(20);
|
||||
Check(!model.IsRunning && model.StatusText == "已停止标准 SOP 播放", "停止标准视频时同步结束检测");
|
||||
using (var exclusive = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
|
||||
Check(exclusive.Length > 0, "停止播放后释放视频文件");
|
||||
|
||||
File.WriteAllText(path, "damaged-video");
|
||||
play.Command.Execute(play.CommandParameter);
|
||||
for (var i = 0; i < 100 && (model.IsRunning || !model.Logs.Any(item => item.Message.StartsWith("标准 SOP 播放或检测失败"))); i++) await Task.Delay(20);
|
||||
Check(!model.IsRunning && !Camera.IsGrabbing && model.StandardSopButtonText == "播放标准 SOP"
|
||||
&& model.Logs.Any(item => item.Message.StartsWith("标准 SOP 播放或检测失败")),
|
||||
"无法打开标准视频时结束检测并恢复播放入口");
|
||||
}
|
||||
|
||||
private static async Task CheckStepCounts(App app,Window window)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user