From 39873811da1f9fdc6adcb0ea48225045ef12788e Mon Sep 17 00:00:00 2001 From: Timothy Date: Sat, 25 Jul 2026 14:20:33 +0200 Subject: [PATCH] test(503): guard WatermarkLocation exhaustiveness and cover source-content margins Review follow-up. The 9-element ExpectedPositions table meant a future enum member would pass every case and silently render bottom-right again -- the exact bug #503 fixes. Assert the table covers Enum.GetValues instead, and exercise the previously untested SourceContentMargins() branch. --- .../Filter/OverlayWatermarkFilterTests.cs | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/ErsatzTV.FFmpeg.Tests/Filter/OverlayWatermarkFilterTests.cs b/ErsatzTV.FFmpeg.Tests/Filter/OverlayWatermarkFilterTests.cs index 0d37c62ed..f878162aa 100644 --- a/ErsatzTV.FFmpeg.Tests/Filter/OverlayWatermarkFilterTests.cs +++ b/ErsatzTV.FFmpeg.Tests/Filter/OverlayWatermarkFilterTests.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using ErsatzTV.FFmpeg; @@ -19,7 +20,11 @@ public class OverlayWatermarkFilterTests private static readonly FrameSize Resolution = new(1920, 1080); private static readonly FrameSize SquarePixelFrameSize = new(1920, 1080); - private static WatermarkState StateFor(WatermarkLocation location) => + // a pillarboxed source: 1440x1080 of real content inside a 1920x1080 frame, so + // SourceContentMargins() adds half the 480px horizontal padding to the margin + private static readonly FrameSize PillarboxedSquarePixelFrameSize = new(1440, 1080); + + private static WatermarkState StateFor(WatermarkLocation location, bool placeWithinSourceContent = false) => new( Option>.None, location, @@ -28,7 +33,7 @@ public class OverlayWatermarkFilterTests 10, 10, 100, - false); + placeWithinSourceContent); private static readonly (WatermarkLocation Location, string Expected)[] ExpectedPositions = [ @@ -84,6 +89,33 @@ public class OverlayWatermarkFilterTests filter.Filter.ShouldBe($"overlay_qsv={expectedPosition}"); } + // #503: the position switch has a catch-all default that silently renders bottom-right, so a + // newly added WatermarkLocation would compile, pass every case above, and reintroduce the exact + // bug this fixture exists to prevent. Fail here instead, at the point the enum grows. + [Test] + public void Every_WatermarkLocation_Has_An_Expected_Position() + { + IEnumerable covered = ExpectedPositions.Select(x => x.Location); + + Enum.GetValues().Except(covered).ShouldBeEmpty( + "every WatermarkLocation needs an explicit arm in OverlayWatermarkFilter.Position and a " + + "matching entry in ExpectedPositions; otherwise it silently renders bottom-right"); + } + + [Test] + public void Source_Content_Margins_Offset_By_Half_The_Pillarbox_Padding() + { + var filter = new OverlayWatermarkFilter( + StateFor(WatermarkLocation.BottomRight, placeWithinSourceContent: true), + Resolution, + PillarboxedSquarePixelFrameSize, + new PixelFormatUnknown(), + NullLogger.Instance); + + // horizontal: round(0.10 * 1440 + 480 / 2) = 384; vertical: round(0.10 * 1080 + 0) = 108 + filter.Filter.ShouldBe("overlay=x=W-w-384:y=H-h-108:format=0"); + } + [Test] public void Unmapped_Location_Falls_Back_To_BottomRight_Position() {