Files
riojoy/tests/RioJoy.Core.Tests/Overlay/OverlayRenderIntegrationTests.cs
T
CydandClaude Fable 5 1ff0b16015 Phase 8A (2/2): RioJoy.Core multi-targets net48 + net40 (Windows XP flavor)
- TargetFrameworks net48;net40. net48 keeps x64 + ViGEm + System.IO.Ports
  package; net40 adds Microsoft.Bcl.Async + System.ValueTuple and uses the
  in-box SerialPort.
- Compat/TaskCompat bridges Task.Run/Delay/WhenAny/WhenAll (TaskEx on
  net40) and SemaphoreSlim.WaitAsync (net40 blocks briefly - trivial at
  9600 baud).
- IReadOnlyList/IReadOnlyDictionary -> IList/IDictionary throughout
  (net40 predates the IReadOnly* interfaces and the Bcl backport cannot
  make arrays implement them).
- HashCode.Combine replaced with a manual combine (Bcl.HashCode has no
  net40 build); Marshal.SizeOf<T> -> typeof form; ViGEmJoystickSink
  gated #if !NET40. HidFeederJoystickSink stays on both flavors - it
  will drive RioGamepadXP.sys on XP via the same contract.

Both TFMs build; 275 tests green on net48.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 20:41:58 -05:00

51 lines
1.9 KiB
C#

using RioJoy.Core.Overlay;
using RioJoy.Overlay;
using SkiaSharp;
using Xunit;
namespace RioJoy.Core.Tests.Overlay;
/// <summary>
/// Full Phase-7 pipeline on the real cockpit assets: extracted regions.json + the
/// exported riojoy.png + the legacy TEST.data labels → a rendered wallpaper. Proves
/// the extract → import → lay out → rasterize chain end to end (headless).
/// </summary>
public class OverlayRenderIntegrationTests
{
private static bool RegionDiffers(SKBitmap a, SKBitmap b, OverlayRegion r)
{
int x0 = (int)r.X, y0 = (int)r.Y;
int x1 = Math.Min(a.Width, (int)(r.X + r.Width));
int y1 = Math.Min(a.Height, (int)(r.Y + r.Height));
for (int y = y0; y < y1; y++)
for (int x = x0; x < x1; x++)
if (a.GetPixel(x, y) != b.GetPixel(x, y))
return true;
return false;
}
[Fact]
public void RendersCockpitWallpaper_FromRealAssets()
{
OverlayTemplate template = OverlayTemplateStore.Load(TestRepo.CustomBackground("regions.json"));
Assert.False(string.IsNullOrWhiteSpace(template.BaseImagePath));
using SKBitmap baseImg = SKBitmap.Decode(TestRepo.CustomBackground(template.BaseImagePath!));
Assert.NotNull(baseImg);
Assert.Equal(template.Width, baseImg.Width);
Assert.Equal(template.Height, baseImg.Height);
IDictionary<string, string> labels =
GoobieDataImporter.LabelsForRow(GoobieDataImporter.Load(TestRepo.CustomBackground("TEST.data")));
using SKBitmap rendered = new SkiaOverlayRenderer().Render(template, labels, baseImg);
Assert.Equal(2720, rendered.Width);
Assert.Equal(600, rendered.Height);
// A labeled cell ("b-00" -> "LSDI") must have changed from the base.
OverlayRegion b00 = template.FindRegion("b-00")!;
Assert.True(RegionDiffers(baseImg, rendered, b00), "labelled region b-00 should differ from the base image");
}
}