test(app): editor sample for --capture and a Windows smoke test of every section
SampleData.FillEditorAsync writes a synthetic harbour sunset of real JPEG frames with Exif (flicker, two exposure steps, white-balance drift, a horizon), scans, deep-analyses and advises it, so --capture writes sequence-<tab>-<theme>.png for every editor section. EditorViewModel .WhenIdleAsync lets capture and tests wait for the preview, corrections, plan, estimates and thumbnails in flight. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
7 files changed
+413
-1
No files matched your search
@@ -1,14 +1,23 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using Titano.App.About;
|
using Titano.App.About;
|
||||||
|
using Titano.App.Editor;
|
||||||
using Titano.App.Infrastructure;
|
using Titano.App.Infrastructure;
|
||||||
using Titano.App.Server;
|
using Titano.App.Server;
|
||||||
using Titano.App.Settings;
|
using Titano.App.Settings;
|
||||||
|
using Titano.Core.Advice;
|
||||||
|
using Titano.Core.Analysis;
|
||||||
|
using Titano.Core.Analysis.Deep;
|
||||||
|
using Titano.Core.Archiving;
|
||||||
using Titano.Core.Codecs.Jpeg;
|
using Titano.Core.Codecs.Jpeg;
|
||||||
|
using Titano.Core.Diagnostics.Synthetic;
|
||||||
using Titano.Core.Imaging;
|
using Titano.Core.Imaging;
|
||||||
|
using Titano.Core.Imaging.Decoders;
|
||||||
|
using Titano.Core.Metadata;
|
||||||
using Titano.Core.Model;
|
using Titano.Core.Model;
|
||||||
using Titano.Core.Video;
|
using Titano.Core.Video;
|
||||||
using Titano.Data;
|
using Titano.Data;
|
||||||
|
using Titano.Data.Archiving;
|
||||||
using Titano.Protocol;
|
using Titano.Protocol;
|
||||||
using Titano.Protocol.Client;
|
using Titano.Protocol.Client;
|
||||||
|
|
||||||
@@ -79,6 +88,149 @@ public sealed class SampleData
|
|||||||
settings.FirstRunCompleted = true;
|
settings.FirstRunCompleted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The sequence editor's sample: a second archive holding a synthetic harbour sunset of real JPEG frames with Exif
|
||||||
|
/// (flicker, two received exposure steps, white-balance drift, a horizon), indexed by a scan, analysed (light and
|
||||||
|
/// deep, saved as <c>analysis.json</c>), advised into <c>project.json</c> and given two past renders.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The sequence id to open in the editor.</returns>
|
||||||
|
public async Task<Guid> FillEditorAsync()
|
||||||
|
{
|
||||||
|
var db = _db ?? throw new InvalidOperationException("OpenEmptyAsync first.");
|
||||||
|
var archives = _services.Archives ?? throw new InvalidOperationException("The archive engine is not attached.");
|
||||||
|
var root = Path.Combine(_services.Environment.DataDirectory, "editor-archive");
|
||||||
|
var archive = await archives.CreateAsync(root, "Editor sample");
|
||||||
|
var sunset = SyntheticSequence.Create(EditorSunset);
|
||||||
|
var folder = Path.Combine(root, "2026", "2026-09-28 Canon EOS R5");
|
||||||
|
Directory.CreateDirectory(folder);
|
||||||
|
for (var i = 0; i < sunset.Count; i++)
|
||||||
|
{
|
||||||
|
using var image = SunsetFrame(sunset, i);
|
||||||
|
var exif = ExifWriter.BuildJpegApp1(sunset.Metadata[i]);
|
||||||
|
File.WriteAllBytes(Path.Combine(folder, $"IMG_{4211 + i:0000}.JPG"), JpegEncoder.Encode(image, new JpegEncodeOptions { Quality = 88, App1Segments = [exif[4..]] }));
|
||||||
|
}
|
||||||
|
await archives.Indexer.ScanAsync(archive, ScanMode.Full, null, _ => ValueTask.CompletedTask, CancellationToken.None);
|
||||||
|
var id = (await db.Sequences.ListLocationsAsync(archive.Id)).Single().Id;
|
||||||
|
await archives.SetSequenceInfoAsync(id, "Harbour sunset", ["sunset", "harbour"], 4, null);
|
||||||
|
|
||||||
|
var source = new LocalSequenceSource(db, id, DecoderFactory.CreateClient(null), null);
|
||||||
|
var content = await source.LoadAsync(CancellationToken.None);
|
||||||
|
var deep = await DeepAnalyzer.AnalyzeAsync(new SunsetFrames(sunset));
|
||||||
|
var sequence = content.Sequence;
|
||||||
|
deep.Save(new ArchivePaths(root).Sequence(sequence.Folder).AnalysisPath);
|
||||||
|
var advice = Advisor.Recommend(content.Light, deep, SequenceContext.FromFrames(content.Frames));
|
||||||
|
await source.SaveProjectAsync(Advisor.Apply(content.Project, advice), content.Project, CancellationToken.None);
|
||||||
|
await db.Sequences.RecordAnalysisAsync(id, SequenceStatus.AnalyzedLight | SequenceStatus.AnalyzedDeep | SequenceStatus.HasWarnings, SequenceStatus.None,
|
||||||
|
advice.Findings.Count(f => f.Severity >= FindingSeverity.Warning), AnalysisSummary.From(deep).ToJson());
|
||||||
|
foreach (var (preset, codec, width, height, daysAgo, bytes) in new[] { ("4K archive", "hevc", 3840, 2160, 7, 2_210_000_000L), ("1080p share", "h264", 1920, 1080, 3, 412_000_000L) })
|
||||||
|
{
|
||||||
|
await db.Renders.InsertAsync(new Render
|
||||||
|
{
|
||||||
|
Id = Guid.CreateVersion7(),
|
||||||
|
SequenceId = id,
|
||||||
|
PresetName = preset,
|
||||||
|
OutputPath = Path.Combine(folder, "exports", $"2026-09-28 Harbour sunset - {preset}.mp4"),
|
||||||
|
Codec = codec,
|
||||||
|
Width = width,
|
||||||
|
Height = height,
|
||||||
|
Fps = 24,
|
||||||
|
DurationSeconds = 5,
|
||||||
|
Bytes = bytes,
|
||||||
|
Created = DateTimeOffset.UtcNow.AddDays(-daysAgo),
|
||||||
|
ProducedBy = "studio-pc",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>A two-minute sunset at 2 s intervals: darkening scene, flicker, two shutter steps the pixels received, warming light.</summary>
|
||||||
|
private static readonly SyntheticSequenceOptions EditorSunset = new()
|
||||||
|
{
|
||||||
|
Width = 600,
|
||||||
|
Height = 400,
|
||||||
|
FrameCount = 96,
|
||||||
|
Seed = 28,
|
||||||
|
Start = new DateTime(2026, 9, 28, 18, 2, 11),
|
||||||
|
IntervalSeconds = 2,
|
||||||
|
StartEv = 0.5,
|
||||||
|
EndEv = -2.5,
|
||||||
|
FlickerEv = 0.12,
|
||||||
|
ExposureSteps = [new SyntheticExposureStep(32, -1), new SyntheticExposureStep(64, -1)],
|
||||||
|
HorizonFraction = 0.62,
|
||||||
|
HorizonWave = 0.02,
|
||||||
|
SkyLevel = 0.32,
|
||||||
|
LandLevel = 0.06,
|
||||||
|
StartKelvin = 5600,
|
||||||
|
EndKelvin = 3200,
|
||||||
|
WhiteBalanceJitter = 0.03,
|
||||||
|
NoiseSigma = 0.002,
|
||||||
|
BaseExposureTime = 1.0 / 125,
|
||||||
|
BaseFNumber = 8,
|
||||||
|
BaseIso = 100,
|
||||||
|
CameraMake = "Canon",
|
||||||
|
CameraModel = "Canon EOS R5",
|
||||||
|
Lens = "RF15-35mm F2.8 L IS USM",
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The synthetic frame (its exposure truth: scene, steps, flicker, white balance) coloured as a harbour sunset: a
|
||||||
|
/// blue-to-amber sky gradient normalised to unit luminance, so the measured luminance keeps the truth, and a setting sun.
|
||||||
|
/// </summary>
|
||||||
|
private static ImageBuffer SunsetFrame(SyntheticSequence sequence, int index)
|
||||||
|
{
|
||||||
|
var image = sequence.Render(index);
|
||||||
|
var (w, h) = (image.Width, image.Height);
|
||||||
|
var t = index / (double)(sequence.Count - 1);
|
||||||
|
var horizon = sequence.Options.HorizonFraction * h;
|
||||||
|
var (sunX, sunY) = (w * 0.64, h * (0.28 + 0.3 * t));
|
||||||
|
var gain = Math.Pow(2, sequence.SceneEv[index] + sequence.ExposureOffsetEv[index] + sequence.FlickerEv[index]);
|
||||||
|
double[][] sky = [Linear("#2A2F6B"), Linear("#8E3F57"), Linear("#E07A48"), Linear("#F5B45E")];
|
||||||
|
var land = Linear("#3A3540");
|
||||||
|
for (var y = 0; y < h; y++)
|
||||||
|
{
|
||||||
|
double[] colour;
|
||||||
|
if (y < horizon)
|
||||||
|
{
|
||||||
|
var f = y / horizon * (sky.Length - 1);
|
||||||
|
var k = Math.Min((int)f, sky.Length - 2);
|
||||||
|
colour = [.. Enumerable.Range(0, 3).Select(c => sky[k][c] + (sky[k + 1][c] - sky[k][c]) * (f - k))];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
colour = land;
|
||||||
|
}
|
||||||
|
var luminance = 0.2126 * colour[0] + 0.7152 * colour[1] + 0.0722 * colour[2];
|
||||||
|
for (var x = 0; x < w; x++)
|
||||||
|
{
|
||||||
|
var d = Math.Sqrt((x - sunX) * (x - sunX) + (y - sunY) * (y - sunY));
|
||||||
|
var sun = y < horizon ? gain * 4 * Math.Exp(-d * d / 220) : 0;
|
||||||
|
for (var c = 0; c < 3; c++)
|
||||||
|
{
|
||||||
|
var plane = image.Plane(c);
|
||||||
|
plane[y * w + x] = (float)(plane[y * w + x] * colour[c] / luminance + sun * (c == 0 ? 1.0 : c == 1 ? 0.75 : 0.45));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static double[] Linear(string hex)
|
||||||
|
{
|
||||||
|
var rgb = Convert.FromHexString(hex.TrimStart('#'));
|
||||||
|
return [.. rgb.Select(v => ColorSpace.SrgbToLinear(v / 255.0))];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>The sunset as the deep analysis reads it (the pixels written to the JPEGs, before compression).</summary>
|
||||||
|
private sealed class SunsetFrames(SyntheticSequence sequence) : IFrameSource
|
||||||
|
{
|
||||||
|
public int Count => sequence.Count;
|
||||||
|
|
||||||
|
public LightFrame Metadata(int index) => LightFrame.From(sequence.Metadata[index], index);
|
||||||
|
|
||||||
|
public ValueTask<ImageBuffer?> LoadAsync(int index, int maxLongEdge, CancellationToken cancellationToken) =>
|
||||||
|
ValueTask.FromResult<ImageBuffer?>(SunsetFrame(sequence, index));
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<(Sequence Sequence, string[] Colours, bool Raw)> Sequences(Guid archiveId)
|
private IEnumerable<(Sequence Sequence, string[] Colours, bool Raw)> Sequences(Guid archiveId)
|
||||||
{
|
{
|
||||||
var now = new DateTime(2026, 9, 28, 18, 2, 11);
|
var now = new DateTime(2026, 9, 28, 18, 2, 11);
|
||||||
|
|||||||
@@ -28,10 +28,27 @@ public static class EditorImages
|
|||||||
public sealed class EditorThumbnails(ISequenceSource source, int count) : IThumbnailSource
|
public sealed class EditorThumbnails(ISequenceSource source, int count) : IThumbnailSource
|
||||||
{
|
{
|
||||||
private readonly SemaphoreSlim _decoders = new(int.Clamp(Environment.ProcessorCount / 2, 2, 6));
|
private readonly SemaphoreSlim _decoders = new(int.Clamp(Environment.ProcessorCount / 2, 2, 6));
|
||||||
|
private int _pending;
|
||||||
|
|
||||||
public int Count { get; } = count;
|
public int Count { get; } = count;
|
||||||
|
|
||||||
|
/// <summary>Thumbnails requested and not yet returned (capture and tests wait for them).</summary>
|
||||||
|
public int Pending => Volatile.Read(ref _pending);
|
||||||
|
|
||||||
public async ValueTask<ImageSource?> GetAsync(int index, int pixelWidth, CancellationToken cancellationToken)
|
public async ValueTask<ImageSource?> GetAsync(int index, int pixelWidth, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
Interlocked.Increment(ref _pending);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await DecodeAsync(index, pixelWidth, cancellationToken);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Interlocked.Decrement(ref _pending);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ImageSource?> DecodeAsync(int index, int pixelWidth, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await _decoders.WaitAsync(cancellationToken);
|
await _decoders.WaitAsync(cancellationToken);
|
||||||
try
|
try
|
||||||
|
|||||||
@@ -319,6 +319,38 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
|||||||
Shell.Notify(Loc.L("Editor.Render.Queued"), request.Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
|
Shell.Notify(Loc.L("Editor.Render.Queued"), request.Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Completes once the preview, corrections, plan, estimates and filmstrip thumbnails in flight are done (capture and
|
||||||
|
/// tests); a finished step may start the next (corrections re-render the preview), so it waits until all are quiet.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>False when the work was still going on after <paramref name="timeout"/>.</returns>
|
||||||
|
public async Task<bool> WhenIdleAsync(TimeSpan timeout)
|
||||||
|
{
|
||||||
|
var deadline = DateTime.UtcNow + timeout;
|
||||||
|
while (deadline - DateTime.UtcNow is { Ticks: > 0 } left)
|
||||||
|
{
|
||||||
|
var work = Work();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.WhenAll(work).WaitAsync(left);
|
||||||
|
}
|
||||||
|
catch (TimeoutException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||||
|
{
|
||||||
|
// A failed run was already logged by its owner; it counts as done.
|
||||||
|
}
|
||||||
|
await Task.Delay(50);
|
||||||
|
// Quiet means nothing new was scheduled meanwhile (the same tasks) and no thumbnail is loading.
|
||||||
|
if (work.SequenceEqual(Work()) && (Thumbnails as EditorThumbnails)?.Pending is null or 0) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Task[] Work() => [_preview.Idle, _corrections.Idle, _plans.Idle, .. Tabs.OfType<ExportTab>().Select(t => t.EstimatesIdle)];
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Loads the jobs of this sequence already queued or running (busy state).</summary>
|
/// <summary>Loads the jobs of this sequence already queued or running (busy state).</summary>
|
||||||
public async Task AttachJobsAsync()
|
public async Task AttachJobsAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -293,6 +293,9 @@ public sealed class ExportTab : EditorTab
|
|||||||
|
|
||||||
public IReadOnlyList<string> Batch => Export.Batch;
|
public IReadOnlyList<string> Batch => Export.Batch;
|
||||||
|
|
||||||
|
/// <summary>Completes when the card estimates in flight are done.</summary>
|
||||||
|
public Task EstimatesIdle => _estimates.Idle;
|
||||||
|
|
||||||
private ExportSettings Export => Editor.Session.Project.Export;
|
private ExportSettings Export => Editor.Session.Project.Export;
|
||||||
|
|
||||||
private ResolvedExport Resolved => Editor.Plan?.Export ?? ExportResolver.Resolve(Export);
|
private ResolvedExport Resolved => Editor.Plan?.Export ?? ExportResolver.Resolve(Export);
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ public sealed class ExposureTab : EditorTab
|
|||||||
if (content.Deep is { Regions: not null } withSky && withSky.Frames.SkyLogLuminance.Any(v => v is not null))
|
if (content.Deep is { Regions: not null } withSky && withSky.Frames.SkyLogLuminance.Any(v => v is not null))
|
||||||
{
|
{
|
||||||
series.Add(new ChartSeries(Loc.L("Editor.Chart.Sky"), withSky.Frames.SkyLogLuminance.Select(v => v ?? double.NaN).ToArray(), "Brush.Region")
|
series.Add(new ChartSeries(Loc.L("Editor.Chart.Sky"), withSky.Frames.SkyLogLuminance.Select(v => v ?? double.NaN).ToArray(), "Brush.Region")
|
||||||
{ Dash = LineDash.Dashed });
|
{ Dash = LineDash.Dashed });
|
||||||
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Sky"), "Brush.Region", LegendSwatch.DashedLine));
|
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Sky"), "Brush.Region", LegendSwatch.DashedLine));
|
||||||
}
|
}
|
||||||
var markers = EditorViewModel.StepMarkers(content);
|
var markers = EditorViewModel.StepMarkers(content);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Threading;
|
using System.Windows.Threading;
|
||||||
using Titano.App.DesignTime;
|
using Titano.App.DesignTime;
|
||||||
|
using Titano.App.Editor;
|
||||||
using Titano.App.Settings;
|
using Titano.App.Settings;
|
||||||
using Titano.Core.Diagnostics;
|
using Titano.Core.Diagnostics;
|
||||||
using Titano.Ui.Theming;
|
using Titano.Ui.Theming;
|
||||||
@@ -97,6 +98,8 @@ public static class ScreenCapture
|
|||||||
written += await SaveAsync(window, directory, key.ToString().ToLowerInvariant(), theme);
|
written += await SaveAsync(window, directory, key.ToString().ToLowerInvariant(), theme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
written += await CaptureEditorAsync(window, shell, sample, directory);
|
||||||
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
|
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
|
||||||
if (written == 0) Environment.ExitCode = 1;
|
if (written == 0) Environment.ExitCode = 1;
|
||||||
}
|
}
|
||||||
@@ -111,6 +114,34 @@ public static class ScreenCapture
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>The sequence editor on the synthetic sunset: every section in both themes (<c>sequence-<tab>-<theme>.png</c>).</summary>
|
||||||
|
private static async Task<int> CaptureEditorAsync(Window window, ShellViewModel shell, SampleData sample, string directory)
|
||||||
|
{
|
||||||
|
var written = 0;
|
||||||
|
var id = await sample.FillEditorAsync();
|
||||||
|
shell.OpenSequence(id);
|
||||||
|
await shell.Sequence.OpenAsync(id);
|
||||||
|
if (shell.Sequence.Editor is not { } editor)
|
||||||
|
{
|
||||||
|
Log.Warning("capture", "The editor sample did not open");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
foreach (var theme in Themes)
|
||||||
|
{
|
||||||
|
ThemeManager.Apply(theme);
|
||||||
|
foreach (var tab in editor.Tabs)
|
||||||
|
{
|
||||||
|
editor.SelectedTab = tab;
|
||||||
|
editor.CurrentIndex = tab is ExportTab ? 40 : 45;
|
||||||
|
await Settle(window);
|
||||||
|
if (!await editor.WhenIdleAsync(TimeSpan.FromSeconds(30))) Log.Warning("capture", $"The {tab.Key} section was still busy");
|
||||||
|
written += await SaveAsync(window, directory, "sequence-" + tab.Key.ToLowerInvariant(), theme);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor.SelectedTab = editor.Exposure;
|
||||||
|
return written;
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task<int> SaveAsync(Window window, string directory, string screen, AppTheme theme, ShellViewModel? waitForThumbnails = null)
|
private static async Task<int> SaveAsync(Window window, string directory, string screen, AppTheme theme, ShellViewModel? waitForThumbnails = null)
|
||||||
{
|
{
|
||||||
await Settle(window);
|
await Settle(window);
|
||||||
|
|||||||
@@ -0,0 +1,177 @@
|
|||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
using Titano.App.DesignTime;
|
||||||
|
using Titano.App.Editor;
|
||||||
|
using Titano.App.Infrastructure;
|
||||||
|
using Titano.App.Sections;
|
||||||
|
using Titano.App.Shell;
|
||||||
|
using Titano.App.Tests.Windows;
|
||||||
|
using Titano.Core.Project;
|
||||||
|
using Titano.Testing;
|
||||||
|
using Titano.Ui.Theming;
|
||||||
|
using Titano.Ui.Visuals;
|
||||||
|
|
||||||
|
namespace Titano.App.Tests.Editor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The sequence editor in the real main window, off screen at the minimum capture size, on the synthetic sunset of
|
||||||
|
/// <c>--capture</c> (real JPEG frames, deep analysis, advised project): every section shows its measuring tool, its
|
||||||
|
/// settings and preview pixels in both themes, and an edit goes through undo and redo.
|
||||||
|
/// </summary>
|
||||||
|
[WindowsOnly]
|
||||||
|
[Serial]
|
||||||
|
[Timeout(300_000)]
|
||||||
|
public sealed class EditorSmokeTests
|
||||||
|
{
|
||||||
|
private static readonly AppTheme[] Themes = [AppTheme.Dark, AppTheme.Light];
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public Task EverySectionOfTheEditorRendersInBothThemes() => ScreenHost.RunAsync(async () =>
|
||||||
|
{
|
||||||
|
var environment = AppEnvironment.ForCapture();
|
||||||
|
UiLanguage.Apply("en");
|
||||||
|
ThemeManager.Apply(AppTheme.Dark);
|
||||||
|
var services = new AppServices(environment, new AppSettings { Language = "en", FirstRunCompleted = true }, () => { }, new NoDialogs());
|
||||||
|
var sample = SampleData.Configure(services);
|
||||||
|
var shell = new ShellViewModel(services);
|
||||||
|
var window = new MainWindow(shell)
|
||||||
|
{
|
||||||
|
WindowStartupLocation = WindowStartupLocation.Manual,
|
||||||
|
Left = -20000,
|
||||||
|
Top = -20000,
|
||||||
|
Width = 1200,
|
||||||
|
Height = 788,
|
||||||
|
ShowActivated = false,
|
||||||
|
ShowInTaskbar = false,
|
||||||
|
};
|
||||||
|
window.Show();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await sample.OpenEmptyAsync();
|
||||||
|
await shell.StartAsync();
|
||||||
|
var id = await sample.FillEditorAsync();
|
||||||
|
shell.OpenSequence(id);
|
||||||
|
await shell.Sequence.OpenAsync(id);
|
||||||
|
var editor = Assert.NotNull(shell.Sequence.Editor);
|
||||||
|
Assert.Equal(96, editor.FrameCount);
|
||||||
|
Assert.NotNull(editor.Session.Content.Deep, "the sample is analysed");
|
||||||
|
Assert.True(editor.Session.Project.Exposure.Deflicker.HasAdvice, "the advice is in the project");
|
||||||
|
Assert.Equal("Harbour sunset", editor.Title);
|
||||||
|
|
||||||
|
foreach (var theme in Themes)
|
||||||
|
{
|
||||||
|
ThemeManager.Apply(theme);
|
||||||
|
foreach (var tab in editor.Tabs)
|
||||||
|
{
|
||||||
|
editor.SelectedTab = tab;
|
||||||
|
await SettleAsync(window);
|
||||||
|
Assert.True(await editor.WhenIdleAsync(TimeSpan.FromSeconds(60)), $"{tab.Key}: still busy");
|
||||||
|
await SettleAsync(window);
|
||||||
|
var view = Find<SequenceView>(window).Single(v => v.IsVisible);
|
||||||
|
Assert.NotNull(editor.PreviewImage, $"{tab.Key}: the preview shows pixels");
|
||||||
|
ExpectMeasure(view, tab);
|
||||||
|
Assert.True(Find<ContentPresenter>(view).Any(p => ReferenceEquals(p.Content, tab) && p.ActualHeight > 100), $"{tab.Key}: settings column");
|
||||||
|
Assert.Greater(Distinct(Render(window)), 40, $"{tab.Key} drew almost nothing in {theme}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// An edit through the session is undone and redone (Ctrl+Z / Ctrl+Y run the same commands).
|
||||||
|
ThemeManager.Apply(AppTheme.Dark);
|
||||||
|
var before = editor.Session.Project.Exposure.ExposureOffsetEv;
|
||||||
|
editor.Session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } });
|
||||||
|
editor.UndoCommand.Execute(null);
|
||||||
|
Assert.Equal(before, editor.Session.Project.Exposure.ExposureOffsetEv);
|
||||||
|
editor.RedoCommand.Execute(null);
|
||||||
|
Assert.Equal(0.5, editor.Session.Project.Exposure.ExposureOffsetEv);
|
||||||
|
await editor.Session.FlushAsync();
|
||||||
|
Assert.NotNull(editor.Plan, "the export is planned");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ThemeManager.Apply(AppTheme.Dark);
|
||||||
|
window.Close();
|
||||||
|
await shell.Sequence.CloseAsync();
|
||||||
|
shell.Dispose();
|
||||||
|
await services.DisposeAsync();
|
||||||
|
environment.DeleteCaptureData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/// <summary>The measuring tool of each section has content.</summary>
|
||||||
|
private static void ExpectMeasure(SequenceView view, EditorTab tab)
|
||||||
|
{
|
||||||
|
switch (tab)
|
||||||
|
{
|
||||||
|
case FramesTab frames:
|
||||||
|
Assert.Equal(96, frames.Frames.Count);
|
||||||
|
Assert.NotEmpty(Find<ListBoxItem>(view).Where(i => i.DataContext is FrameRow && i.IsVisible));
|
||||||
|
break;
|
||||||
|
case CameraTab or TimeTab:
|
||||||
|
Assert.NotEmpty(Find<CurveEditor>(view).Where(c => c.IsVisible && c.ActualHeight > 50));
|
||||||
|
break;
|
||||||
|
case ExportTab export:
|
||||||
|
Assert.NotEmpty(export.Cards);
|
||||||
|
Assert.NotEmpty(Find<Button>(view).Where(b => b.DataContext is PresetCard && b.IsVisible));
|
||||||
|
Assert.True(export.Cards.Any(c => c.Estimate is not null), "estimates on the cards");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
var chart = Find<SeriesChart>(view).Single(c => c.IsVisible);
|
||||||
|
Assert.True(chart.ActualHeight > 50, $"{tab.Key}: chart height");
|
||||||
|
Assert.NotEmpty(chart.Series!);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task SettleAsync(Window window)
|
||||||
|
{
|
||||||
|
window.UpdateLayout();
|
||||||
|
await window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
|
||||||
|
await Task.Delay(30);
|
||||||
|
await window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
|
||||||
|
window.UpdateLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RenderTargetBitmap Render(Window window)
|
||||||
|
{
|
||||||
|
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
||||||
|
var dpi = VisualTreeHelper.GetDpi(window);
|
||||||
|
var bitmap = new RenderTargetBitmap((int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX), (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY),
|
||||||
|
dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
||||||
|
bitmap.Render(root);
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int Distinct(BitmapSource bitmap)
|
||||||
|
{
|
||||||
|
var pixels = new byte[bitmap.PixelWidth * bitmap.PixelHeight * 4];
|
||||||
|
bitmap.CopyPixels(pixels, bitmap.PixelWidth * 4, 0);
|
||||||
|
var colours = new HashSet<int>();
|
||||||
|
for (var i = 0; i < pixels.Length && colours.Count < 2000; i += 4 * 5) colours.Add(BitConverter.ToInt32(pixels, i));
|
||||||
|
return colours.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<T> Find<T>(DependencyObject root)
|
||||||
|
where T : DependencyObject
|
||||||
|
{
|
||||||
|
var found = new List<T>();
|
||||||
|
var stack = new Stack<DependencyObject>([root]);
|
||||||
|
while (stack.TryPop(out var node))
|
||||||
|
{
|
||||||
|
if (node is T match) found.Add(match);
|
||||||
|
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(node); i++) stack.Push(VisualTreeHelper.GetChild(node, i));
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>Dialogs that answer like a user who cancels everything.</summary>
|
||||||
|
private sealed class NoDialogs : IAppDialogs
|
||||||
|
{
|
||||||
|
public string? PickFolder(string title, string? initialFolder = null) => null;
|
||||||
|
public string? PickJsonFile(string title) => null;
|
||||||
|
public bool Confirm(ConfirmRequest request) => false;
|
||||||
|
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user