From 07baf1350a2855f11510e756834d5e6dbd65ea67 Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 10:59:17 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=8A=9B=E4=B8=AD=E3=81=AE=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E3=81=AE=E8=A9=A6=E9=A8=93=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge.Tests/ExportDetectorTests.cs | 175 ++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 ProxyForge.Tests/ExportDetectorTests.cs diff --git a/ProxyForge.Tests/ExportDetectorTests.cs b/ProxyForge.Tests/ExportDetectorTests.cs new file mode 100644 index 0000000..98a38e7 --- /dev/null +++ b/ProxyForge.Tests/ExportDetectorTests.cs @@ -0,0 +1,175 @@ +using ProxyForge.Export; + +namespace ProxyForge.Tests; + +public sealed class ExportDetectorTests +{ + const string Configuration = "動画出力"; + const string Progress = "出力"; + + static ExportDetector Create(bool commandLineEncode, Func, bool?>? resolve = null, List? resolveCalls = null) + => new( + commandLineEncode, + () => Configuration, + () => Progress, + probe => + { + resolveCalls?.Add(1); + return resolve is null ? probe() : resolve(probe); + }); + + [Theory] + [InlineData(new[] { "--encode", @"C:\project.ymmp" }, true)] + [InlineData(new[] { "YukkuriMovieMaker.exe", "--ENCODE", @"C:\project.ymmp", "--output", @"C:\out.mp4" }, true)] + [InlineData(new[] { "--encode" }, false)] + [InlineData(new[] { "--encode", "--output" }, false)] + [InlineData(new[] { "--encode", " " }, false)] + [InlineData(new[] { @"C:\project.ymmp" }, false)] + [InlineData(new string[0], false)] + public void TheEncodeOptionIsRecognisedLikeTheHost(string[] arguments, bool expected) + => Assert.Equal(expected, ExportDetector.HasEncodeOption(arguments)); + + [Theory] + [InlineData(Configuration, ExportWindowRole.Configuration)] + [InlineData(Progress, ExportWindowRole.Progress)] + [InlineData("", ExportWindowRole.None)] + [InlineData(null, ExportWindowRole.None)] + [InlineData("出力 ", ExportWindowRole.None)] + [InlineData("YukkuriMovieMaker4", ExportWindowRole.None)] + public void WindowsAreClassifiedByTheirExactTitle(string? title, ExportWindowRole expected) + => Assert.Equal(expected, Create(false).Classify(title)); + + [Fact] + public void TheCommandLineEncodeAlwaysExports() + { + var calls = new List(); + var detector = Create(true, resolveCalls: calls); + + Assert.True(detector.IsCommandLineEncode); + Assert.True(detector.IsExporting()); + Assert.Empty(calls); + Assert.Equal(ExportPhase.Idle, detector.Phase); + } + + [Fact] + public void NothingIsExportingAtFirst() + { + var calls = new List(); + var detector = Create(false, resolveCalls: calls); + + Assert.False(detector.IsExporting()); + Assert.Empty(calls); + } + + [Fact] + public void TheProgressWindowMeansExportingUntilItCloses() + { + var calls = new List(); + var detector = Create(false, resolveCalls: calls); + + detector.OnWindowOpened(ExportWindowRole.Progress); + + Assert.Equal(ExportPhase.Exporting, detector.Phase); + Assert.True(detector.IsExporting()); + Assert.Empty(calls); + + detector.OnWindowClosed(ExportWindowRole.Progress); + + Assert.Equal(ExportPhase.Idle, detector.Phase); + Assert.False(detector.IsExporting()); + } + + [Fact] + public void TheConfigurationWindowStartsThePreparation() + { + var detector = Create(false); + + detector.OnWindowOpened(ExportWindowRole.Configuration); + + Assert.Equal(ExportPhase.Preparing, detector.Phase); + } + + [Fact] + public void ClosingTheConfigurationWindowKeepsThePreparation() + { + var detector = Create(false); + detector.OnWindowOpened(ExportWindowRole.Configuration); + + detector.OnWindowClosed(ExportWindowRole.Configuration); + + Assert.Equal(ExportPhase.Preparing, detector.Phase); + } + + [Fact] + public void AnUnrelatedWindowChangesNothing() + { + var detector = Create(false); + + detector.OnWindowOpened(ExportWindowRole.None); + detector.OnWindowClosed(ExportWindowRole.None); + + Assert.Equal(ExportPhase.Idle, detector.Phase); + } + + [Fact] + public void DuringThePreparationTheUiThreadDecidesThatExportingHasStarted() + { + ExportDetector? detector = null; + detector = Create(false, probe => + { + detector!.OnWindowOpened(ExportWindowRole.Progress); + return probe(); + }); + detector.OnWindowOpened(ExportWindowRole.Configuration); + + Assert.True(detector.IsExporting()); + Assert.Equal(ExportPhase.Exporting, detector.Phase); + } + + [Fact] + public void DuringThePreparationTheUiThreadDecidesThatItWasCancelled() + { + var calls = new List(); + var detector = Create(false, resolveCalls: calls); + detector.OnWindowOpened(ExportWindowRole.Configuration); + + Assert.False(detector.IsExporting()); + Assert.Equal(ExportPhase.Idle, detector.Phase); + Assert.Single(calls); + Assert.False(detector.IsExporting()); + Assert.Single(calls); + } + + [Fact] + public void AnUnresolvedPreparationIsTreatedAsExporting() + { + var detector = Create(false, _ => null); + detector.OnWindowOpened(ExportWindowRole.Configuration); + + Assert.True(detector.IsExporting()); + Assert.Equal(ExportPhase.Preparing, detector.Phase); + } + + [Fact] + public void AConfigurationWindowDuringAnExportDoesNotDemoteThePhase() + { + var detector = Create(false); + detector.OnWindowOpened(ExportWindowRole.Progress); + + detector.OnWindowOpened(ExportWindowRole.Configuration); + + Assert.Equal(ExportPhase.Exporting, detector.Phase); + } + + [Fact] + public void TheProgressWindowEndsAPreparationThatWasResolvedTooEarly() + { + var detector = Create(false); + detector.OnWindowOpened(ExportWindowRole.Configuration); + Assert.False(detector.IsExporting()); + + detector.OnWindowOpened(ExportWindowRole.Progress); + + Assert.True(detector.IsExporting()); + } +}