CI / Build and test (pull_request) Failing after 2m3s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / Docker image (pull_request) Skipped
CI / Windows tests and installer (pull_request) Skipped
CI / YAML check (pull_request) Successful in 4s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow) and pe-check. BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
203 lines
9.2 KiB
C#
203 lines
9.2 KiB
C#
using Chronos.Core.Project;
|
||
using Chronos.Core.Render;
|
||
using Chronos.Core.Video;
|
||
using Chronos.Testing;
|
||
|
||
namespace Chronos.Core.Tests.Render;
|
||
|
||
public sealed class RenderPlanTests
|
||
{
|
||
private static readonly DateTime Start = new(2024, 6, 21, 19, 0, 0);
|
||
|
||
private static DateTime?[] Regular(int count, double interval = 10) =>
|
||
Enumerable.Range(0, count).Select(i => (DateTime?)Start.AddSeconds(i * interval)).ToArray();
|
||
|
||
private static ProjectSettings Timing(TimingMode mode, string? playback = null, double? fit = null, IReadOnlyList<CurvePoint>? curve = null, int[]? excluded = null) => new()
|
||
{
|
||
Timing = new TimingSettings
|
||
{
|
||
Mode = new Auto<TimingMode>().WithManual(mode),
|
||
FrameRate = playback is null ? new Auto<string>() : new Auto<string>().WithManual(playback),
|
||
FitToSeconds = fit,
|
||
RemapCurve = curve ?? [new(0, 0), new(1, 1)],
|
||
},
|
||
ExcludedFrames = excluded ?? [],
|
||
};
|
||
|
||
private static void AssertExactDurations(RenderPlan plan)
|
||
{
|
||
Assert.Equal(plan.Duration90k, plan.Frames.Sum(f => f.Duration90k));
|
||
Assert.Equal(RenderPlan.TicksAt(plan.FrameRate, plan.SlotCount), plan.Duration90k);
|
||
long t = 0;
|
||
var slot = 0;
|
||
foreach (var f in plan.Frames)
|
||
{
|
||
Assert.Equal(t, f.Start90k);
|
||
Assert.Equal(slot, f.StartSlot);
|
||
Assert.Greater(f.Duration90k, 0);
|
||
t += f.Duration90k;
|
||
slot += f.Slots;
|
||
}
|
||
Assert.Equal(plan.SlotCount, slot);
|
||
Assert.Monotonic(plan.Frames.Select(f => f.SourcePosition));
|
||
}
|
||
|
||
[Test]
|
||
public void ConstantShowsEveryFrameOnceAtTheOutputRate()
|
||
{
|
||
var plan = RenderPlan.Build(Regular(100), Timing(TimingMode.Constant), new Rational(24, 1));
|
||
Assert.Equal(100, plan.Frames.Count);
|
||
Assert.SequenceEqual(Enumerable.Range(0, 100).Select(i => (double)i), plan.Frames.Select(f => f.SourcePosition));
|
||
Assert.True(plan.Frames.All(f => f.Duration90k == 3750 && f.Flags == PlannedFrameFlags.None && f.Speed == 1));
|
||
Assert.Equal(375_000L, plan.Duration90k);
|
||
AssertExactDurations(plan);
|
||
}
|
||
|
||
[Test]
|
||
public void ExcludedFramesAreSkipped()
|
||
{
|
||
var plan = RenderPlan.Build(Regular(20), Timing(TimingMode.Constant, excluded: [3, 7, 99]), new Rational(25, 1));
|
||
Assert.Equal(18, plan.Frames.Count);
|
||
Assert.DoesNotContain(3, plan.Frames.Select(f => f.From));
|
||
Assert.DoesNotContain(7, plan.Frames.Select(f => f.To));
|
||
Assert.Equal(2, plan.Statistics.ExcludedFrames);
|
||
Assert.Equal(2.0, plan.Frames.Single(f => f.From == 2).Speed);
|
||
AssertExactDurations(plan);
|
||
}
|
||
|
||
[Test]
|
||
public void NtscDurationsAccumulateWithoutDrift()
|
||
{
|
||
var plan = RenderPlan.Build(Regular(1001), Timing(TimingMode.Constant), Rational.Fps2997);
|
||
Assert.Equal(1001 * 3003L, plan.Duration90k);
|
||
Assert.True(plan.Frames.All(f => f.Duration90k == 3003));
|
||
var fps23 = RenderPlan.Build(Regular(7), Timing(TimingMode.Constant), Rational.Fps23976);
|
||
Assert.SequenceEqual(new long[] { 3754, 3754, 3753, 3754, 3754, 3754, 3753 }, fps23.Frames.Select(f => f.Duration90k));
|
||
Assert.Equal(26_276L, fps23.Duration90k);
|
||
AssertExactDurations(fps23);
|
||
}
|
||
|
||
[Test]
|
||
public void SlowerPlaybackHoldsFramesInConstantAndSynthesisesInInterpolated()
|
||
{
|
||
var held = RenderPlan.Build(Regular(10), Timing(TimingMode.Constant, playback: "12"), new Rational(24, 1));
|
||
Assert.Equal(10, held.Frames.Count);
|
||
Assert.True(held.Frames.All(f => f.Slots == 2 && f.IsHeld && f.Duration90k == 7500));
|
||
AssertExactDurations(held);
|
||
|
||
var smooth = RenderPlan.Build(Regular(10), Timing(TimingMode.Interpolated, playback: "12"), new Rational(24, 1));
|
||
Assert.Equal(19, smooth.Frames.Count);
|
||
Assert.Equal(9, smooth.Statistics.InterpolatedFrames);
|
||
Assert.Equal(0.5, smooth.Frames[1].SourcePosition);
|
||
Assert.Equal(0.5, smooth.Frames[1].Fraction);
|
||
Assert.Equal(9.0, smooth.Frames[^1].SourcePosition);
|
||
Assert.True(smooth.Frames[^1].IsHeld, "the last frame has no successor to blend towards");
|
||
AssertExactDurations(smooth);
|
||
}
|
||
|
||
[Test]
|
||
public void FitToSecondsScalesThePlan()
|
||
{
|
||
var shorter = RenderPlan.Build(Regular(100), Timing(TimingMode.Constant, fit: 2), new Rational(25, 1));
|
||
Assert.Equal(50, shorter.SlotCount);
|
||
Assert.Equal(180_000L, shorter.Duration90k);
|
||
Assert.True(shorter.Frames.All(f => f.Fraction == 0 && f.SourcePosition % 2 == 0));
|
||
Assert.Equal(50, shorter.Statistics.SkippedFrames);
|
||
Assert.Approximately(2.0, shorter.Statistics.MaximumSpeed, 1e-9);
|
||
|
||
var longer = RenderPlan.Build(Regular(100), Timing(TimingMode.Interpolated, fit: 7.96), new Rational(25, 1));
|
||
Assert.Equal(199, longer.SlotCount);
|
||
Assert.Equal(716_400L, longer.Duration90k);
|
||
Assert.Greater(longer.Statistics.InterpolatedFrames, 90);
|
||
AssertExactDurations(longer);
|
||
}
|
||
|
||
[Test]
|
||
public void AdaptiveFollowsCaptureTimeAndShortensPauses()
|
||
{
|
||
var times = Regular(40);
|
||
for (var i = 11; i < 40; i++) times[i] = times[i]!.Value.AddSeconds(10); // 2× interval into frame 11
|
||
for (var i = 21; i < 40; i++) times[i] = times[i]!.Value.AddSeconds(60); // 7× gap into frame 21
|
||
for (var i = 31; i < 40; i++) times[i] = times[i]!.Value.AddHours(1); // deliberate pause into frame 31
|
||
var plan = RenderPlan.Build(times, Timing(TimingMode.Adaptive), new Rational(24, 1));
|
||
Assert.Equal(40, plan.Frames.Count);
|
||
Assert.Equal(2, plan.Frames[10].Slots);
|
||
Assert.Equal(4, plan.Frames[20].Slots); // 3 + log2(7/3) = 4.22 periods, rounded on the grid
|
||
Assert.Equal(5, plan.Frames[30].Slots); // 0.2 s × 24 fps = 4.8 periods
|
||
Assert.True(plan.Frames.Where((_, i) => i is not (10 or 20 or 30)).All(f => f.Slots == 1));
|
||
Assert.False(plan.IsCutBefore(11));
|
||
Assert.True(plan.IsCutBefore(21));
|
||
Assert.True(plan.IsCutBefore(31));
|
||
Assert.Equal(-1, plan.NextContinuous(30));
|
||
Assert.Equal(29, plan.PreviousContinuous(30));
|
||
Assert.Equal(2, plan.Statistics.Cuts);
|
||
Assert.Approximately(10.0, plan.Statistics.MedianIntervalSeconds!.Value, 1e-9);
|
||
AssertExactDurations(plan);
|
||
}
|
||
|
||
[Test]
|
||
public void InterpolatedFillsMissingAndExcludedFrames()
|
||
{
|
||
var times = Regular(40);
|
||
for (var i = 20; i < 40; i++) times[i] = times[i]!.Value.AddSeconds(10); // one capture missing before frame 20
|
||
for (var i = 35; i < 40; i++) times[i] = times[i]!.Value.AddSeconds(600); // too long to synthesise
|
||
var plan = RenderPlan.Build(times, Timing(TimingMode.Interpolated, excluded: [30]), new Rational(30, 1));
|
||
var gap = plan.Frames.Single(f => f.From == 19 && f.IsInterpolated);
|
||
Assert.Equal(19.5, gap.SourcePosition);
|
||
Assert.Equal(20, gap.To);
|
||
var excluded = plan.Frames.Single(f => f.From == 29 && f.IsInterpolated);
|
||
Assert.Equal(30.0, excluded.SourcePosition);
|
||
Assert.Equal(31, excluded.To);
|
||
Assert.Equal(0.5, excluded.Fraction);
|
||
Assert.True(plan.IsCutBefore(35));
|
||
Assert.False(plan.Frames.Any(f => f.From == 34 && f.IsInterpolated));
|
||
Assert.Equal(41, plan.Frames.Count);
|
||
AssertExactDurations(plan);
|
||
}
|
||
|
||
[Test]
|
||
public void RemapIsMonotoneEvenForBadCurves()
|
||
{
|
||
var ease = RenderPlan.Build(Regular(120), Timing(TimingMode.Remapped, curve: [new(0, 0), new(0.5, 0.2), new(1, 1)]), new Rational(24, 1));
|
||
AssertExactDurations(ease);
|
||
Assert.Equal(120, ease.SlotCount);
|
||
Assert.Equal(0.0, ease.Frames[0].SourcePosition);
|
||
Assert.Greater(ease.Frames[^1].SourcePosition, 115);
|
||
Assert.Less(ease.Frames[^1].Speed * ease.Frames[^1].Slots, 3.5);
|
||
Assert.Less(ease.Frames[10].Speed, 0.5);
|
||
Assert.Empty(ease.Warnings);
|
||
|
||
var bad = RenderPlan.Build(Regular(60), Timing(TimingMode.Remapped, curve: [new(1, 1), new(0, 0.1), new(0.4, 0.8), new(0.6, 0.3)]), new Rational(24, 1));
|
||
Assert.Contains("Export.Plan.RemapNotMonotonic", bad.Warnings);
|
||
AssertExactDurations(bad);
|
||
Assert.Approximately(0.1 * 60, bad.Frames[0].SourcePosition, 1e-9);
|
||
}
|
||
|
||
[Test]
|
||
public void AnUnreadablePlaybackRateFallsBackToTheOutputRate()
|
||
{
|
||
var plan = RenderPlan.Build(Regular(10), Timing(TimingMode.Constant, playback: "fast"), new Rational(25, 1));
|
||
Assert.Contains("Export.Plan.FrameRateIgnored", plan.Warnings);
|
||
Assert.Equal(10, plan.SlotCount);
|
||
Assert.Equal(25.0, plan.PlaybackRate);
|
||
}
|
||
|
||
[Test]
|
||
public void EverythingExcludedGivesAnEmptyPlan()
|
||
{
|
||
var plan = RenderPlan.Build(Regular(3), Timing(TimingMode.Constant, excluded: [0, 1, 2]), new Rational(30, 1));
|
||
Assert.Empty(plan.Frames);
|
||
Assert.Equal(0L, plan.Duration90k);
|
||
Assert.Contains("Export.Plan.NoFrames", plan.Warnings);
|
||
}
|
||
|
||
[Test]
|
||
public void AdaptiveWithoutCaptureTimesFallsBackToConstantPacing()
|
||
{
|
||
var plan = RenderPlan.Build(new DateTime?[12], Timing(TimingMode.Adaptive), new Rational(30, 1));
|
||
Assert.Equal(12, plan.Frames.Count);
|
||
Assert.Contains("Export.Plan.NoCaptureTimes", plan.Warnings);
|
||
AssertExactDurations(plan);
|
||
}
|
||
}
|