mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-11-21 07:44:58 +01:00
Add graphics levels, screen choices and the rest of the simulator's keys
Six levels of detail climbing in even steps, High being where a player with no settings of their own starts. Five parts of the picture can also take a level of their own. Resolutions start from the monitors in the computer. uartfeature with nothing selected writes "no no no no"; uart and uarttune are written whole or not at all. On Linux the file's contents tell a Windows build, a native one and a script from a note that merely has the execute bit.
This commit is contained in:
100
StarterNG.Tests/DisplaysTests.cs
Normal file
100
StarterNG.Tests/DisplaysTests.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using StarterNG.Infrastructure;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class DisplaysTests
|
||||
{
|
||||
/// <summary>A 128-byte block with an 18-byte timing at 54, as a panel's base EDID has it.</summary>
|
||||
private static byte[] BaseBlock(int pixelClock10KHz, int hActive, int hBlank, int vActive, int vBlank,
|
||||
int extensions = 0)
|
||||
{
|
||||
var edid = new byte[128];
|
||||
new byte[] { 0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0 }.CopyTo(edid, 0);
|
||||
edid[126] = (byte)extensions;
|
||||
int at = 54;
|
||||
edid[at] = (byte)pixelClock10KHz;
|
||||
edid[at + 1] = (byte)(pixelClock10KHz >> 8);
|
||||
edid[at + 2] = (byte)hActive;
|
||||
edid[at + 3] = (byte)hBlank;
|
||||
edid[at + 4] = (byte)((hActive >> 8) << 4 | hBlank >> 8);
|
||||
edid[at + 5] = (byte)vActive;
|
||||
edid[at + 6] = (byte)vBlank;
|
||||
edid[at + 7] = (byte)((vActive >> 8) << 4 | vBlank >> 8);
|
||||
return edid;
|
||||
}
|
||||
|
||||
/// <summary>A DisplayID 2.0 block with one type VII timing (kHz, sizes less one).</summary>
|
||||
private static byte[] DisplayIdBlock(int pixelClockKHz, int hActive, int hBlank, int vActive, int vBlank)
|
||||
{
|
||||
var block = new byte[128];
|
||||
block[0] = 0x70;
|
||||
block[1] = 0x20;
|
||||
block[2] = 23; // one data block: 3 bytes of header, 20 of timing
|
||||
block[3] = 2;
|
||||
int at = 5;
|
||||
block[at] = 0x22;
|
||||
block[at + 2] = 20;
|
||||
int t = at + 3, clock = pixelClockKHz - 1;
|
||||
block[t] = (byte)clock;
|
||||
block[t + 1] = (byte)(clock >> 8);
|
||||
block[t + 2] = (byte)(clock >> 16);
|
||||
void Put(int offset, int value)
|
||||
{
|
||||
block[t + offset] = (byte)(value - 1);
|
||||
block[t + offset + 1] = (byte)((value - 1) >> 8);
|
||||
}
|
||||
Put(4, hActive);
|
||||
Put(6, hBlank);
|
||||
Put(12, vActive);
|
||||
Put(14, vBlank);
|
||||
return block;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_plain_monitor_gives_its_preferred_timing()
|
||||
{
|
||||
// 1920x1080 at 148.5 MHz: the usual 60 Hz.
|
||||
Assert.Equal(60, Edid.HighestRefreshRate(BaseBlock(14850, 1920, 280, 1080, 45)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_fast_panel_found_only_in_displayid_is_read_there()
|
||||
{
|
||||
// As the eDP panel of a gaming laptop: 60 Hz in the base block, 165 Hz in DisplayID.
|
||||
var edid = BaseBlock(15394, 1920, 160, 1200, 35, extensions: 1)
|
||||
.Concat(DisplayIdBlock(423250, 1920, 160, 1200, 33)).ToArray();
|
||||
|
||||
Assert.Equal(165, Edid.HighestRefreshRate(edid));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Something_too_short_for_an_edid_has_no_rate()
|
||||
{
|
||||
Assert.Equal(0, Edid.HighestRefreshRate(new byte[] { 0, 0xFF }));
|
||||
Assert.Equal(0, Edid.HighestRefreshRate(new byte[128]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Only_connected_screens_are_listed_by_their_connector()
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithFile("/sys/class/drm/card1-eDP-1/status", "connected\n")
|
||||
.WithFile("/sys/class/drm/card1-HDMI-A-1/status", "disconnected\n")
|
||||
.WithFile("/sys/class/drm/card1/device/uevent", "DRIVER=amdgpu\n");
|
||||
files.WriteAllBytes("/sys/class/drm/card1-eDP-1/edid", BaseBlock(14850, 1920, 280, 1080, 45));
|
||||
files.WriteAllBytes("/sys/class/drm/card1-HDMI-A-1/edid", BaseBlock(14850, 1920, 280, 1080, 45));
|
||||
|
||||
var displays = new Displays(files, new FakeEnvironment()).List();
|
||||
|
||||
Assert.Equal(new[] { new Display("eDP-1", 60) }, displays);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Off_linux_without_windows_nothing_is_read()
|
||||
{
|
||||
var environment = new FakeEnvironment { IsLinux = false, IsMacOS = true };
|
||||
|
||||
Assert.Empty(new Displays(new InMemoryFileSystem(), environment).List());
|
||||
}
|
||||
}
|
||||
@@ -171,6 +171,65 @@ public class ExecutableLocatorTests
|
||||
Assert.Equal(arguments, programArguments);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void What_is_inside_says_what_the_file_is_not_its_name()
|
||||
{
|
||||
string windowsBuild = TestInstallation.At("eu07-win");
|
||||
string nativeBuild = TestInstallation.At("eu07.exe");
|
||||
var installation = WithWine(new InMemoryFileSystem()
|
||||
.WithFile(windowsBuild, PortableExecutable)
|
||||
.WithExecutable(nativeBuild, Elf));
|
||||
var executables = installation.Executables;
|
||||
|
||||
Assert.True(executables.IsWindowsBuild("eu07-win"));
|
||||
Assert.Equal(Wine, executables.LaunchCommand(windowsBuild, Array.Empty<string>()).FileName);
|
||||
Assert.False(executables.IsWindowsBuild("eu07.exe"));
|
||||
Assert.Equal(nativeBuild, executables.LaunchCommand(nativeBuild, Array.Empty<string>()).FileName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_script_on_linux_starts_itself()
|
||||
{
|
||||
string script = TestInstallation.At("eu07-start");
|
||||
var installation = WithWine(new InMemoryFileSystem().WithExecutable(script, "#!/bin/sh\nwine eu07.exe\n"));
|
||||
|
||||
string resolved = installation.Executables.Resolve(new SimulatorSettings(), out var problem);
|
||||
|
||||
Assert.EndsWith("eu07-start", resolved);
|
||||
Assert.Equal(ExeProblem.None, problem);
|
||||
Assert.Equal(script, installation.Executables.LaunchCommand(script, Array.Empty<string>()).FileName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("notatki do eu07\n")]
|
||||
[InlineData("")]
|
||||
public void On_linux_the_execute_bit_alone_does_not_make_a_program(string inside)
|
||||
{
|
||||
// On a Windows partition every file has the bit.
|
||||
string note = TestInstallation.At("eu07_opis");
|
||||
var installation = WithWine(new InMemoryFileSystem()
|
||||
.WithExecutable(note, inside)
|
||||
.WithFile(TestInstallation.At("eu07.exe"), PortableExecutable));
|
||||
|
||||
string resolved = installation.Executables.Resolve(new SimulatorSettings(), out var problem);
|
||||
|
||||
Assert.EndsWith("eu07.exe", resolved);
|
||||
Assert.Equal(ExeProblem.WrongPlatform, problem);
|
||||
Assert.Equal(new[] { "eu07.exe" }, installation.Executables.ListCandidates());
|
||||
Assert.Equal(ExeProblem.NotAProgram, installation.Executables.Validate(note));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_mac_binary_is_not_taken_for_a_note()
|
||||
{
|
||||
string build = TestInstallation.At("eu07");
|
||||
var installation = new TestInstallation(new InMemoryFileSystem().WithExecutable(build, "Ïúíþ"));
|
||||
installation.Environment.IsLinux = false;
|
||||
installation.Environment.IsMacOS = true;
|
||||
|
||||
Assert.Equal(ExeProblem.None, installation.Executables.Validate(build));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Wine_is_never_looked_for_on_windows()
|
||||
{
|
||||
|
||||
190
StarterNG.Tests/GpuOffloadTests.cs
Normal file
190
StarterNG.Tests/GpuOffloadTests.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using StarterNG.Domain.Settings;
|
||||
using StarterNG.Infrastructure;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class GpuOffloadTests
|
||||
{
|
||||
// The laptop this was written on: an RTX 5060 beside a Radeon 780M that drives the screen.
|
||||
private static readonly GpuDevice Nvidia = new("0000:01:00.0", "10DE:2D19", "nvidia", BootVga: false,
|
||||
InternalPanel: true);
|
||||
private static readonly GpuDevice Radeon780M = new("0000:65:00.0", "1002:1900", "amdgpu", BootVga: true,
|
||||
InternalPanel: true);
|
||||
private static readonly GpuDevice RadeonDiscrete = new("0000:03:00.0", "1002:73DF", "amdgpu", BootVga: false);
|
||||
private static readonly GpuDevice IntelIntegrated = new("0000:00:02.0", "8086:A7A0", "i915", BootVga: true,
|
||||
InternalPanel: true);
|
||||
|
||||
private static string? Unset(string name) => null;
|
||||
|
||||
private static IReadOnlyDictionary<string, string> For(GpuPreference preference, params GpuDevice[] gpus) =>
|
||||
Inheriting(Unset, preference, gpus);
|
||||
|
||||
private static IReadOnlyDictionary<string, string> Inheriting(Func<string, string?> inherited,
|
||||
GpuPreference preference,
|
||||
params GpuDevice[] gpus) =>
|
||||
GpuOffload.Target(gpus, preference, inherited) is { } target
|
||||
? GpuOffload.EnvironmentFor(target)
|
||||
: new Dictionary<string, string>();
|
||||
|
||||
[Fact]
|
||||
public void A_proprietary_nvidia_card_gets_prime_render_offload()
|
||||
{
|
||||
var environment = For(GpuPreference.Discrete, Nvidia, Radeon780M);
|
||||
|
||||
Assert.Equal("1", environment["__NV_PRIME_RENDER_OFFLOAD"]);
|
||||
Assert.Equal("nvidia", environment["__GLX_VENDOR_LIBRARY_NAME"]);
|
||||
Assert.Equal("NVIDIA_only", environment["__VK_LAYER_NV_optimus"]);
|
||||
// DRI_PRIME on a card Mesa does not drive leaves Mesa on llvmpipe.
|
||||
Assert.False(environment.ContainsKey("DRI_PRIME"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_card_mesa_drives_is_picked_by_its_pci_address()
|
||||
{
|
||||
var environment = For(GpuPreference.Discrete, IntelIntegrated, RadeonDiscrete);
|
||||
|
||||
Assert.Equal("pci-0000_03_00_0", Assert.Single(environment).Value);
|
||||
Assert.Equal("DRI_PRIME", environment.Keys.Single());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_card_on_a_driver_of_unknown_ways_is_left_alone()
|
||||
{
|
||||
var odd = Nvidia with { Driver = "vfio-pci" };
|
||||
|
||||
Assert.Empty(For(GpuPreference.Discrete, odd, Radeon780M));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void One_card_leaves_nothing_to_choose()
|
||||
{
|
||||
Assert.Empty(For(GpuPreference.Discrete, Radeon780M));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_system_choice_changes_nothing()
|
||||
{
|
||||
Assert.Empty(For(GpuPreference.System, Nvidia, Radeon780M));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("DRI_PRIME")]
|
||||
[InlineData("__NV_PRIME_RENDER_OFFLOAD")]
|
||||
[InlineData("__GLX_VENDOR_LIBRARY_NAME")]
|
||||
public void A_choice_the_player_made_stands(string variable)
|
||||
{
|
||||
// prime-run %command% in Steam's launch options, say.
|
||||
var environment = Inheriting(name => name == variable ? "1" : null, GpuPreference.Discrete, Nvidia, Radeon780M);
|
||||
|
||||
Assert.Empty(environment);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_discrete_card_already_driving_the_screen_needs_no_offload()
|
||||
{
|
||||
// A laptop with its MUX switched to the NVIDIA card.
|
||||
Assert.Empty(For(GpuPreference.Discrete, Nvidia with { BootVga = true },
|
||||
Radeon780M with { BootVga = false }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_desktop_stays_on_the_card_its_monitor_is_plugged_into()
|
||||
{
|
||||
// The monitor on a Radeon, the processor's own graphics left on: moving
|
||||
// off the boot card would land on the weaker one.
|
||||
var radeon = RadeonDiscrete with { BootVga = true };
|
||||
var intel = IntelIntegrated with { BootVga = false, InternalPanel = false };
|
||||
|
||||
Assert.Empty(For(GpuPreference.Discrete, radeon, intel));
|
||||
}
|
||||
|
||||
// ── What the settings say about it ───────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void No_card_read_is_said_whatever_was_chosen()
|
||||
{
|
||||
Assert.Equal(GpuNote.Unread, GpuOffload.NoteFor(Array.Empty<GpuDevice>(), GpuPreference.Discrete, Unset));
|
||||
Assert.Equal(GpuNote.Unread, GpuOffload.NoteFor(Array.Empty<GpuDevice>(), GpuPreference.System, name => "1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void One_card_is_said_whatever_was_chosen()
|
||||
{
|
||||
Assert.Equal(GpuNote.OneCard, GpuOffload.NoteFor(new[] { Radeon780M }, GpuPreference.Discrete, Unset));
|
||||
Assert.Equal(GpuNote.OneCard, GpuOffload.NoteFor(new[] { Radeon780M }, GpuPreference.System, name => "1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_system_choice_comes_before_what_the_player_set()
|
||||
{
|
||||
Assert.Equal(GpuNote.LeftToSystem,
|
||||
GpuOffload.NoteFor(new[] { Nvidia, Radeon780M }, GpuPreference.System, name => "1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void What_the_player_set_comes_before_the_card_it_would_be_moved_to()
|
||||
{
|
||||
static string? Inherited(string name) => name is "DRI_PRIME" or "__NV_PRIME_RENDER_OFFLOAD" ? "1" : null;
|
||||
|
||||
Assert.Equal(GpuNote.PlayerChose,
|
||||
GpuOffload.NoteFor(new[] { Nvidia, Radeon780M }, GpuPreference.Discrete, Inherited));
|
||||
Assert.Equal(new[] { "__NV_PRIME_RENDER_OFFLOAD", "DRI_PRIME" }, GpuOffload.PlayerChoices(Inherited));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_variable_set_empty_is_no_choice_of_the_player()
|
||||
{
|
||||
Assert.Empty(GpuOffload.PlayerChoices(name => string.Empty));
|
||||
Assert.Equal(GpuNote.Moved,
|
||||
GpuOffload.NoteFor(new[] { Nvidia, Radeon780M }, GpuPreference.Discrete, name => string.Empty));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_note_says_a_move_only_with_a_card_to_move_to()
|
||||
{
|
||||
Assert.Equal(GpuNote.Moved, GpuOffload.NoteFor(new[] { Nvidia, Radeon780M }, GpuPreference.Discrete, Unset));
|
||||
Assert.Equal(GpuNote.NoTarget,
|
||||
GpuOffload.NoteFor(new[] { Nvidia with { Driver = "vfio-pci" }, Radeon780M },
|
||||
GpuPreference.Discrete, Unset));
|
||||
}
|
||||
|
||||
// ── Reading the cards ────────────────────────────────────────────────────
|
||||
|
||||
private static InMemoryFileSystem Card(InMemoryFileSystem files, string card, string driver, string id,
|
||||
string slot, bool bootVga) =>
|
||||
files.WithFile($"/sys/class/drm/{card}/device/uevent",
|
||||
$"DRIVER={driver}\nPCI_CLASS=30000\nPCI_ID={id}\nPCI_SLOT_NAME={slot}\n")
|
||||
.WithFile($"/sys/class/drm/{card}/device/boot_vga", bootVga ? "1\n" : "0\n");
|
||||
|
||||
[Fact]
|
||||
public void The_cards_are_read_from_sysfs()
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true);
|
||||
Card(files, "card0", "nvidia", "10DE:2D19", "0000:01:00.0", bootVga: false);
|
||||
Card(files, "card1", "amdgpu", "1002:1900", "0000:65:00.0", bootVga: true);
|
||||
// A connector, not a card.
|
||||
files.WithFile("/sys/class/drm/card0-eDP-2/device/uevent", "DRIVER=nvidia\nPCI_ID=10DE:2D19\nPCI_SLOT_NAME=x\n");
|
||||
|
||||
files.WithFile("/sys/class/drm/card1-eDP-1/status", "connected\n");
|
||||
|
||||
var gpus = new LinuxGpus(files, new FakeEnvironment()).List();
|
||||
|
||||
Assert.Equal(new[] { Nvidia, Radeon780M }, gpus);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Off_linux_there_are_no_cards_to_move_between()
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true);
|
||||
Card(files, "card0", "nvidia", "10DE:2D19", "0000:01:00.0", bootVga: false);
|
||||
|
||||
Assert.Empty(new LinuxGpus(files, new FakeEnvironment().AsWindows()).List());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_sysfs_there_are_no_cards()
|
||||
{
|
||||
Assert.Empty(new LinuxGpus(new InMemoryFileSystem(), new FakeEnvironment()).List());
|
||||
}
|
||||
}
|
||||
628
StarterNG.Tests/GraphicsPresetTests.cs
Normal file
628
StarterNG.Tests/GraphicsPresetTests.cs
Normal file
@@ -0,0 +1,628 @@
|
||||
using StarterNG.Application;
|
||||
using StarterNG.Domain.Settings;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class GraphicsPresetTests
|
||||
{
|
||||
private static SimulatorSettings Defaults()
|
||||
{
|
||||
var installation = new TestInstallation();
|
||||
installation.SettingsStore.Load();
|
||||
return installation.SettingsStore.Settings;
|
||||
}
|
||||
|
||||
private static SimulatorSettings AtHigh()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
GraphicsPreset.High.ApplyTo(settings);
|
||||
return settings;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_keys_named_are_the_keys_a_level_sets()
|
||||
{
|
||||
var store = new TestInstallation().SettingsStore;
|
||||
var low = Defaults().Copy();
|
||||
var top = Defaults().Copy();
|
||||
(GraphicsPreset.Minimal with { Extras = null }).ApplyTo(low);
|
||||
(GraphicsPreset.Ultra with { Extras = null, Top = null }).ApplyTo(top);
|
||||
|
||||
var lowKeys = store.Render(low);
|
||||
var topKeys = store.Render(top);
|
||||
var differing = lowKeys.Keys.Union(topKeys.Keys)
|
||||
.Where(key => lowKeys.GetValueOrDefault(key) != topKeys.GetValueOrDefault(key))
|
||||
.Where(key => !key.StartsWith("gfx.framebuffer", StringComparison.Ordinal));
|
||||
|
||||
Assert.Equal(GraphicsPreset.Keys.OrderBy(k => k), differing.OrderBy(k => k));
|
||||
}
|
||||
|
||||
// ── The scale ────────────────────────────────────────────────────────────
|
||||
|
||||
private static void Climbs(Func<GraphicsPreset, double> value, int repeatsAllowed)
|
||||
{
|
||||
var values = GraphicsPreset.All.Select(value).ToList();
|
||||
|
||||
Assert.Equal(values.OrderBy(v => v), values);
|
||||
Assert.True(values.Count - values.Distinct().Count() <= repeatsAllowed, string.Join(", ", values));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_slider_moves_from_level_to_level_as_far_as_it_has_steps_for_six()
|
||||
{
|
||||
// Sizes and filtering run out of steps above High.
|
||||
Climbs(p => p.TextureSize, 1);
|
||||
Climbs(p => p.CabTextureSize, 1);
|
||||
Climbs(p => p.Anisotropy, 1);
|
||||
|
||||
// Four steps or three for six levels.
|
||||
Climbs(p => p.Multisampling, 2);
|
||||
Climbs(p => p.SmokeFidelity, 2);
|
||||
Climbs(p => p.SplineFidelity, 2);
|
||||
Climbs(p => p.ReflectionsFidelity, 3);
|
||||
Climbs(p => p.ShadowRank, 3);
|
||||
|
||||
// The simulator takes no more than its own 7 lights, and draws no less than 2 km.
|
||||
Climbs(p => p.DynamicLights, 2);
|
||||
Climbs(p => p.DrawRange, 1);
|
||||
Climbs(p => p.DrawRangeFactor, 2);
|
||||
Climbs(p => p.CabShadowsRange, 1);
|
||||
|
||||
Climbs(p => p.ShadowMap, 1);
|
||||
Climbs(p => p.ShadowRange, 0);
|
||||
Climbs(p => p.ReflectionsRate, 0);
|
||||
Climbs(p => p.DistanceFactor, 0);
|
||||
Climbs(p => p.BufferScale, 0);
|
||||
Climbs(p => p.SleeperDistance, 0);
|
||||
Climbs(p => p.ReflectedInstances, 0);
|
||||
Climbs(p => p.ReflectedVehicles, 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_step_up_a_scale_is_more_than_a_few_steps_of_its_slider()
|
||||
{
|
||||
// In steps of what the screen offers, so Ultra does not jump to the top from far below.
|
||||
var rates = GraphicsPreset.All.Select(p => Steps.IndexOf(Steps.ReflectionUpdates, p.ReflectionsRate)).ToList();
|
||||
Assert.All(rates.Zip(rates.Skip(1)), step => Assert.InRange(step.Second - step.First, 1, 4));
|
||||
|
||||
foreach (Func<GraphicsPreset, int> fidelity in new Func<GraphicsPreset, int>[] { p => p.SmokeFidelity, p => p.SplineFidelity })
|
||||
{
|
||||
var levels = GraphicsPreset.All.Select(fidelity).ToList();
|
||||
Assert.All(levels.Zip(levels.Skip(1)), step => Assert.InRange(step.Second - step.First, 0, 1));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void High_is_the_simulators_own_but_where_that_is_the_bottom_of_a_scale()
|
||||
{
|
||||
var store = new TestInstallation().SettingsStore;
|
||||
var own = store.Render(Defaults());
|
||||
var high = store.Render(AtHigh());
|
||||
|
||||
var differing = own.Keys.Union(high.Keys)
|
||||
.Where(key => own.GetValueOrDefault(key) != high.GetValueOrDefault(key))
|
||||
.Where(key => !GraphicsPreset.RowKeys.Contains(key))
|
||||
.Where(key => !key.StartsWith("gfx.framebuffer", StringComparison.Ordinal));
|
||||
|
||||
Assert.Equal(new[] { "gfx.reflections.fidelity", "gfx.reflections.framerate", "gfx.shadows.cab.range",
|
||||
"gfx.smoke.fidelity", "splinefidelity" }, differing.OrderBy(k => k));
|
||||
Assert.Equal(1, Defaults().SmokeFidelity);
|
||||
Assert.Equal(1, Defaults().SplineFidelity);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_player_with_no_settings_of_their_own_starts_at_high()
|
||||
{
|
||||
var installation = new TestInstallation();
|
||||
var store = installation.SettingsStore;
|
||||
store.Load();
|
||||
|
||||
store.StartAtHighWithoutOwnSettings();
|
||||
|
||||
Assert.Same(GraphicsPreset.High, GraphicsPreset.Matching(store.Settings));
|
||||
Assert.False(store.LastSaveFailed);
|
||||
|
||||
var again = new TestInstallation(installation.Files).SettingsStore;
|
||||
again.Load();
|
||||
Assert.Same(GraphicsPreset.High, GraphicsPreset.Matching(again.Settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_player_with_settings_of_their_own_stays_as_they_are()
|
||||
{
|
||||
var installation = new TestInstallation();
|
||||
var store = installation.SettingsStore;
|
||||
store.Load();
|
||||
GraphicsPreset.Low.ApplyTo(store.Settings);
|
||||
store.Save();
|
||||
|
||||
var again = new TestInstallation(installation.Files).SettingsStore;
|
||||
again.Load();
|
||||
again.StartAtHighWithoutOwnSettings();
|
||||
|
||||
Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(again.Settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ultra_is_the_top_of_everything_the_screen_offers()
|
||||
{
|
||||
var ultra = GraphicsPreset.Ultra;
|
||||
double Top(string key) => SimulatorKeys.Named(key).Maximum;
|
||||
|
||||
Assert.Equal(8192, ultra.TextureSize);
|
||||
Assert.Equal(8192, ultra.CabTextureSize);
|
||||
Assert.Equal(8192, ultra.ShadowMap);
|
||||
Assert.Equal(600, ultra.ShadowRange);
|
||||
Assert.Equal(Steps.Anisotropy.Max(), ultra.Anisotropy);
|
||||
Assert.Equal(Steps.MultisamplingLevels.Max(), ultra.Multisampling);
|
||||
Assert.Equal(Steps.ReflectionUpdates.Max(), ultra.ReflectionsRate);
|
||||
Assert.Equal(4, ultra.SmokeFidelity);
|
||||
Assert.Equal(4, ultra.SplineFidelity);
|
||||
Assert.Equal(200, ultra.BufferScale);
|
||||
Assert.Equal(Top(GraphicsPreset.DrawRangeKey), ultra.DrawRange);
|
||||
Assert.Equal(Top(GraphicsPreset.DistanceFactorKey), ultra.DistanceFactor);
|
||||
Assert.Equal(Top(GraphicsPreset.SleeperKey), ultra.SleeperDistance);
|
||||
Assert.Equal(Steps.DrawRangeFactors.Max(), ultra.DrawRangeFactor);
|
||||
Assert.Equal(Top(GraphicsPreset.ReflectedInstancesKey), ultra.ReflectedInstances);
|
||||
Assert.Equal(Top(GraphicsPreset.ReflectedVehiclesKey), ultra.ReflectedVehicles);
|
||||
Assert.Equal(100, ultra.CabShadowsRange);
|
||||
|
||||
var extras = ultra.Extras!;
|
||||
Assert.Equal(200, extras.PythonUpdateMs);
|
||||
Assert.True(extras.MotionBlur && extras.ChromaticAberration && extras.Smoke);
|
||||
|
||||
var top = ultra.Top!;
|
||||
Assert.Equal(Top(GraphicsTop.ScreenWindowFpsKey), top.ScreenWindowFps);
|
||||
Assert.True(top.Screens && top.ScreenMipmaps && top.Sky && top.Cab && top.AirCouplers && top.SmoothTraction);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void At_ultra_what_would_only_take_away_is_off()
|
||||
{
|
||||
var top = GraphicsPreset.Ultra.Top!;
|
||||
|
||||
// The longest shadows, the bottom of that scale.
|
||||
Assert.Equal(0.2, top.ShadowAngleLimit);
|
||||
Assert.Equal(0, top.TargetFps);
|
||||
Assert.Equal(0, top.TextureRelease);
|
||||
Assert.False(top.CompressTextures);
|
||||
Assert.False(top.SkipDecor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ultra_undoes_what_was_moved_earlier()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
settings.ShadowAngleLimit = 0.8;
|
||||
settings.IgnoreIrrelevantTrains = true;
|
||||
settings.Extra[GraphicsTop.TargetFpsKey] = "60";
|
||||
settings.Extra[GraphicsTop.TextureReleaseKey] = "2";
|
||||
|
||||
GraphicsPreset.Ultra.ApplyTo(settings);
|
||||
|
||||
Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings));
|
||||
Assert.Equal(0.2, settings.ShadowAngleLimit);
|
||||
Assert.False(settings.IgnoreIrrelevantTrains);
|
||||
Assert.Equal("0", settings.Extra[GraphicsTop.TargetFpsKey]);
|
||||
Assert.Equal("0", settings.Extra[GraphicsTop.TextureReleaseKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ultra_leaves_the_screens_in_their_own_windows_to_the_player()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
settings.Extra["python.displaywindows"] = "yes";
|
||||
|
||||
GraphicsPreset.Ultra.ApplyTo(settings);
|
||||
|
||||
Assert.Equal("yes", settings.Extra["python.displaywindows"]);
|
||||
Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_other_levels_leave_what_only_ultra_sets()
|
||||
{
|
||||
foreach (var preset in GraphicsPreset.All.Where(preset => preset != GraphicsPreset.Ultra))
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
settings.IgnoreIrrelevantTrains = true;
|
||||
settings.Extra[GraphicsTop.TargetFpsKey] = "60";
|
||||
|
||||
preset.ApplyTo(settings);
|
||||
|
||||
Assert.True(settings.IgnoreIrrelevantTrains, preset.NameKey);
|
||||
Assert.Equal("60", settings.Extra[GraphicsTop.TargetFpsKey]);
|
||||
Assert.Same(preset, GraphicsPreset.Matching(settings));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ultra_is_not_recognised_with_one_of_its_values_moved()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
GraphicsPreset.Ultra.ApplyTo(settings);
|
||||
Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings));
|
||||
|
||||
settings.Extra[GraphicsPreset.ReflectedVehiclesKey] = "250";
|
||||
|
||||
Assert.Null(GraphicsPreset.Matching(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void No_level_asks_for_a_range_the_renderer_would_raise_anyway()
|
||||
{
|
||||
Assert.All(GraphicsPreset.All, preset => Assert.True(preset.DrawRange >= 2000, preset.NameKey));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_view_only_shortens_going_down_the_levels()
|
||||
{
|
||||
var factors = GraphicsPreset.All.Select(preset => preset.DistanceFactor).ToList();
|
||||
|
||||
Assert.Equal(factors.OrderBy(factor => factor), factors);
|
||||
Assert.Equal(1, GraphicsPreset.High.DistanceFactor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Shadows_reach_further_with_every_level_that_has_them()
|
||||
{
|
||||
static double Reach(GraphicsPreset preset) =>
|
||||
SimulatorSettings.ShadowReach(preset.ShadowRange, preset.ShadowMap, legacyRenderer: false);
|
||||
|
||||
var reaches = GraphicsPreset.All.Where(preset => preset.Shadows).Select(Reach).ToList();
|
||||
|
||||
Assert.Equal(reaches.Distinct().OrderBy(reach => reach), reaches);
|
||||
Assert.Equal(250, Reach(GraphicsPreset.High));
|
||||
Assert.Equal(800, Reach(GraphicsPreset.VeryHigh));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_extras_the_settings_are_what_the_simulator_goes_by()
|
||||
{
|
||||
Assert.Equal(GraphicsExtras.None, GraphicsExtras.Of(Defaults()));
|
||||
Assert.Equal(GraphicsTop.None, GraphicsTop.Of(Defaults()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_level_leaves_what_only_the_lowest_one_sets()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
|
||||
GraphicsPreset.Low.ApplyTo(settings);
|
||||
|
||||
Assert.False(settings.MotionBlur);
|
||||
Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_level_sets_the_buffer_and_is_not_recognised_with_another()
|
||||
{
|
||||
foreach (var preset in GraphicsPreset.All)
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
settings.BufferScalePercent = 120;
|
||||
|
||||
preset.ApplyTo(settings);
|
||||
Assert.Equal(preset.BufferScale, settings.BufferScalePercent);
|
||||
|
||||
settings.BufferScalePercent = 120;
|
||||
Assert.Null(GraphicsPreset.Matching(settings));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_buffer_is_the_screen_at_high_and_climbs_through_it()
|
||||
{
|
||||
Assert.Equal(100, GraphicsPreset.High.BufferScale);
|
||||
Assert.Equal(200, GraphicsPreset.Ultra.BufferScale);
|
||||
Assert.InRange(GraphicsPreset.Minimal.BufferScale, 50, 100);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_lowest_level_is_not_recognised_with_one_of_its_extras_undone()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
GraphicsPreset.Minimal.ApplyTo(settings);
|
||||
|
||||
settings.Smoke = true;
|
||||
|
||||
Assert.Null(GraphicsPreset.Matching(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_extras_sit_on_the_steps_the_screen_offers()
|
||||
{
|
||||
foreach (var extras in new[] { GraphicsPreset.Minimal.Extras!, GraphicsPreset.Ultra.Extras! })
|
||||
Assert.Contains(extras.PythonUpdateMs, new[] { 200, 400, 800, 1600 });
|
||||
}
|
||||
|
||||
// ── Leaving an end of the scale ──────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void A_level_between_the_ends_chooses_only_its_own_keys()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
settings.Extra[GraphicsTop.TargetFpsKey] = "60";
|
||||
|
||||
var applied = new GraphicsPresetMemory().Apply(GraphicsPreset.Medium, settings);
|
||||
|
||||
Assert.Same(GraphicsPreset.Medium, GraphicsPreset.Matching(settings));
|
||||
Assert.False(settings.MotionBlur);
|
||||
Assert.Equal("60", settings.Extra[GraphicsTop.TargetFpsKey]);
|
||||
Assert.Equal(GraphicsPreset.RowKeys, applied.RowKeys);
|
||||
Assert.Equal(GraphicsPreset.Keys, applied.ChosenKeys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Leaving_the_lowest_level_brings_back_what_was_there_before_it()
|
||||
{
|
||||
var memory = new GraphicsPresetMemory();
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
var before = GraphicsExtras.Of(settings);
|
||||
|
||||
var entering = memory.Apply(GraphicsPreset.Minimal, settings);
|
||||
Assert.Equal(GraphicsPreset.Minimal.Extras, GraphicsExtras.Of(settings));
|
||||
Assert.Equal(GraphicsPreset.RowKeys, entering.RowKeys);
|
||||
Assert.Equal(GraphicsPreset.Keys.Concat(GraphicsExtras.Keys), entering.ChosenKeys);
|
||||
|
||||
var leaving = memory.Apply(GraphicsPreset.Medium, settings);
|
||||
|
||||
Assert.Equal(before, GraphicsExtras.Of(settings));
|
||||
Assert.Same(GraphicsPreset.Medium, GraphicsPreset.Matching(settings));
|
||||
Assert.Equal(GraphicsPreset.RowKeys, leaving.RowKeys);
|
||||
Assert.Equal(GraphicsPreset.Keys.Concat(GraphicsExtras.Keys), leaving.ChosenKeys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Leaving_ultra_brings_back_what_was_there_before_it()
|
||||
{
|
||||
var memory = new GraphicsPresetMemory();
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
settings.ShadowAngleLimit = 0.8;
|
||||
settings.Extra[GraphicsTop.TargetFpsKey] = "60";
|
||||
var extras = GraphicsExtras.Of(settings);
|
||||
var top = GraphicsTop.Of(settings);
|
||||
|
||||
memory.Apply(GraphicsPreset.Ultra, settings);
|
||||
var applied = memory.Apply(GraphicsPreset.VeryHigh, settings);
|
||||
|
||||
Assert.Equal(extras, GraphicsExtras.Of(settings));
|
||||
Assert.Equal(top, GraphicsTop.Of(settings));
|
||||
Assert.Same(GraphicsPreset.VeryHigh, GraphicsPreset.Matching(settings));
|
||||
Assert.Equal(GraphicsPreset.RowKeys.Concat(GraphicsTop.RowKeys), applied.RowKeys);
|
||||
Assert.Equal(GraphicsPreset.Keys.Concat(GraphicsExtras.Keys).Concat(GraphicsTop.Keys), applied.ChosenKeys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Leaving_an_end_chosen_before_this_run_gives_the_simulators_own_values()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
GraphicsPreset.Ultra.ApplyTo(settings);
|
||||
|
||||
var applied = new GraphicsPresetMemory().Apply(GraphicsPreset.Low, settings);
|
||||
|
||||
Assert.Equal(GraphicsExtras.None, GraphicsExtras.Of(settings));
|
||||
Assert.Equal(GraphicsTop.None, GraphicsTop.Of(settings));
|
||||
Assert.Same(GraphicsPreset.Low, GraphicsPreset.Matching(settings));
|
||||
Assert.Equal(GraphicsPreset.RowKeys.Concat(GraphicsTop.RowKeys), applied.RowKeys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void One_end_to_the_other_keeps_what_was_there_before_either()
|
||||
{
|
||||
var memory = new GraphicsPresetMemory();
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
var extras = GraphicsExtras.Of(settings);
|
||||
var top = GraphicsTop.Of(settings);
|
||||
|
||||
memory.Apply(GraphicsPreset.Minimal, settings);
|
||||
var toUltra = memory.Apply(GraphicsPreset.Ultra, settings);
|
||||
Assert.Same(GraphicsPreset.Ultra, GraphicsPreset.Matching(settings));
|
||||
Assert.Equal(GraphicsPreset.RowKeys.Concat(GraphicsTop.RowKeys), toUltra.RowKeys);
|
||||
|
||||
var toMinimal = memory.Apply(GraphicsPreset.Minimal, settings);
|
||||
Assert.Same(GraphicsPreset.Minimal, GraphicsPreset.Matching(settings));
|
||||
// Ultra's own values go, Minimal has no say over them.
|
||||
Assert.Equal(top, GraphicsTop.Of(settings));
|
||||
Assert.Equal(GraphicsPreset.RowKeys.Concat(GraphicsTop.RowKeys), toMinimal.RowKeys);
|
||||
|
||||
memory.Apply(GraphicsPreset.Medium, settings);
|
||||
Assert.Equal(extras, GraphicsExtras.Of(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void What_was_remembered_comes_back_only_once()
|
||||
{
|
||||
var memory = new GraphicsPresetMemory();
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
|
||||
memory.Apply(GraphicsPreset.Minimal, settings);
|
||||
memory.Apply(GraphicsPreset.Medium, settings);
|
||||
Assert.False(settings.MotionBlur);
|
||||
|
||||
// Moved since, and no end left behind this time: it stays as moved.
|
||||
settings.MotionBlur = true;
|
||||
var applied = memory.Apply(GraphicsPreset.High, settings);
|
||||
|
||||
Assert.True(settings.MotionBlur);
|
||||
Assert.Equal(GraphicsPreset.RowKeys, applied.RowKeys);
|
||||
Assert.Equal(GraphicsPreset.Keys, applied.ChosenKeys);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_level_applied_twice_at_an_end_remembers_what_came_before_the_first()
|
||||
{
|
||||
var memory = new GraphicsPresetMemory();
|
||||
var settings = Defaults().Copy();
|
||||
settings.MotionBlur = false;
|
||||
var before = GraphicsExtras.Of(settings);
|
||||
|
||||
memory.Apply(GraphicsPreset.Minimal, settings);
|
||||
memory.Apply(GraphicsPreset.Minimal, settings);
|
||||
memory.Apply(GraphicsPreset.Low, settings);
|
||||
|
||||
Assert.Equal(before, GraphicsExtras.Of(settings));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_level_applied_is_recognised_until_one_value_moves()
|
||||
{
|
||||
foreach (var preset in GraphicsPreset.All)
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
preset.ApplyTo(settings);
|
||||
Assert.Same(preset, GraphicsPreset.Matching(settings));
|
||||
|
||||
settings.DynamicLights = 6;
|
||||
Assert.Null(GraphicsPreset.Matching(settings));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_level_sits_on_the_steps_the_screen_offers()
|
||||
{
|
||||
void OnSteps(double value, string name)
|
||||
{
|
||||
var key = SimulatorKeys.Named(name);
|
||||
Assert.InRange(value, key.Minimum, key.Maximum);
|
||||
double steps = value / key.Step;
|
||||
Assert.Equal(Math.Round(steps), steps, 6);
|
||||
}
|
||||
|
||||
foreach (var preset in GraphicsPreset.All)
|
||||
{
|
||||
OnSteps(preset.DistanceFactor, GraphicsPreset.DistanceFactorKey);
|
||||
OnSteps(preset.DrawRange, GraphicsPreset.DrawRangeKey);
|
||||
OnSteps(preset.SleeperDistance, GraphicsPreset.SleeperKey);
|
||||
OnSteps(preset.ReflectedInstances, GraphicsPreset.ReflectedInstancesKey);
|
||||
OnSteps(preset.ReflectedVehicles, GraphicsPreset.ReflectedVehiclesKey);
|
||||
Assert.True(Steps.IndexOf(Steps.Anisotropy, preset.Anisotropy) >= 0, preset.NameKey);
|
||||
Assert.True(Steps.IndexOf(Steps.MultisamplingLevels, preset.Multisampling) >= 0, preset.NameKey);
|
||||
Assert.True(Steps.IndexOf(Steps.ReflectionUpdates, preset.ReflectionsRate) >= 0, preset.NameKey);
|
||||
Assert.True(Steps.IndexOf(Steps.DrawRangeFactors, preset.DrawRangeFactor) >= 0, preset.NameKey);
|
||||
foreach (int size in new[] { preset.TextureSize, preset.CabTextureSize, preset.ShadowMap })
|
||||
Assert.True(size is >= 512 and <= 8192 && (size & (size - 1)) == 0, preset.NameKey);
|
||||
Assert.True(preset.ShadowRange >= SimulatorSettings.ShadowRangeFloor(preset.ShadowMap), preset.NameKey);
|
||||
Assert.Equal(0, preset.CabShadowsRange % 10);
|
||||
}
|
||||
}
|
||||
|
||||
// ── A level for one part ─────────────────────────────────────────────────
|
||||
|
||||
private static GraphicsGroupLevels Groups() => new(new TestInstallation().SettingsStore);
|
||||
|
||||
[Fact]
|
||||
public void Every_key_a_level_sets_but_the_buffer_belongs_to_one_part()
|
||||
{
|
||||
var inGroups = GraphicsGroup.All.SelectMany(group => group.Keys).ToList();
|
||||
|
||||
Assert.Equal(inGroups.Distinct(), inGroups);
|
||||
Assert.Empty(inGroups.Except(GraphicsPreset.Keys).Except(GraphicsExtras.Keys).Except(GraphicsTop.Keys));
|
||||
Assert.Equal(new[] { "starter.bufferscale" }, GraphicsPreset.Keys.Except(inGroups));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void One_part_moves_alone()
|
||||
{
|
||||
var groups = Groups();
|
||||
var settings = AtHigh();
|
||||
|
||||
var moved = groups.Apply(GraphicsGroup.Shadows, GraphicsPreset.Low, settings);
|
||||
|
||||
Assert.Equal(GraphicsPreset.Low.ShadowMap, moved.ShadowMapResolution);
|
||||
Assert.Equal(GraphicsPreset.Low.ShadowRange, moved.ShadowProjectionRange);
|
||||
Assert.Equal(GraphicsPreset.Low.ShadowRank, moved.ShadowRankCutoff);
|
||||
Assert.Equal(settings.MaxTextureSize, moved.MaxTextureSize);
|
||||
Assert.Equal(settings.DynamicLights, moved.DynamicLights);
|
||||
Assert.Equal(settings.BufferScalePercent, moved.BufferScalePercent);
|
||||
|
||||
var levels = groups.LevelsOf(moved);
|
||||
Assert.Same(GraphicsPreset.Low, levels[GraphicsGroup.Shadows]);
|
||||
Assert.Same(GraphicsPreset.High, levels[GraphicsGroup.Textures]);
|
||||
Assert.Null(GraphicsPreset.Matching(moved));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_part_shows_ultra_when_the_whole_is_at_ultra()
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
GraphicsPreset.Ultra.ApplyTo(settings);
|
||||
|
||||
Assert.All(Groups().LevelsOf(settings).Values, level => Assert.Same(GraphicsPreset.Ultra, level));
|
||||
|
||||
// The row of a key at the simulator's own value leaves it out of the file.
|
||||
settings.Extra.Remove(GraphicsTop.TextureReleaseKey);
|
||||
|
||||
Assert.Same(GraphicsPreset.Ultra, Groups().LevelsOf(settings)[GraphicsGroup.Textures]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_part_moved_by_hand_is_at_no_level_and_the_others_keep_theirs()
|
||||
{
|
||||
var settings = AtHigh();
|
||||
settings.DynamicLights = 6;
|
||||
|
||||
var levels = Groups().LevelsOf(settings);
|
||||
|
||||
Assert.Null(levels[GraphicsGroup.Effects]);
|
||||
Assert.Same(GraphicsPreset.High, levels[GraphicsGroup.Shadows]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_part_at_a_level_and_the_buffer_with_it_is_that_level()
|
||||
{
|
||||
var groups = Groups();
|
||||
foreach (var level in GraphicsPreset.All.Where(level => level.Extras is null))
|
||||
{
|
||||
var settings = Defaults().Copy();
|
||||
foreach (var group in GraphicsGroup.All)
|
||||
settings = groups.Apply(group, level, settings);
|
||||
settings.BufferScalePercent = level.BufferScale;
|
||||
|
||||
Assert.Same(level, GraphicsPreset.Matching(settings));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_part_tells_every_level_from_the_others()
|
||||
{
|
||||
var groups = Groups();
|
||||
foreach (var group in GraphicsGroup.All)
|
||||
foreach (var level in GraphicsPreset.All)
|
||||
Assert.Same(level, groups.LevelsOf(groups.Apply(group, level, Defaults()))[group]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Leaving_an_end_in_a_part_gives_the_simulators_own_for_what_only_the_end_sets()
|
||||
{
|
||||
var groups = Groups();
|
||||
var settings = AtHigh();
|
||||
|
||||
var ultra = groups.Apply(GraphicsGroup.Textures, GraphicsPreset.Ultra, settings);
|
||||
Assert.False(ultra.CompressTextures);
|
||||
Assert.Same(GraphicsPreset.Ultra, groups.LevelsOf(ultra)[GraphicsGroup.Textures]);
|
||||
|
||||
var back = groups.Apply(GraphicsGroup.Textures, GraphicsPreset.High, ultra);
|
||||
Assert.Equal(GraphicsTop.None.CompressTextures, back.CompressTextures);
|
||||
Assert.Same(GraphicsPreset.High, groups.LevelsOf(back)[GraphicsGroup.Textures]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_level_in_a_part_between_the_ends_leaves_what_only_an_end_sets()
|
||||
{
|
||||
var settings = AtHigh();
|
||||
settings.MotionBlur = false;
|
||||
|
||||
var moved = Groups().Apply(GraphicsGroup.Effects, GraphicsPreset.VeryHigh, settings);
|
||||
|
||||
Assert.False(moved.MotionBlur);
|
||||
Assert.Equal(GraphicsPreset.VeryHigh.SmokeFidelity, moved.SmokeFidelity);
|
||||
}
|
||||
}
|
||||
119
StarterNG.Tests/KeyMapTests.cs
Normal file
119
StarterNG.Tests/KeyMapTests.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using StarterNG.Classes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class KeyMapTests
|
||||
{
|
||||
/// <summary>The names of the simulator's key table, keytonamemap in input/keyboardinput.cpp.</summary>
|
||||
private static readonly HashSet<string> SimulatorKeyNames = new(StringComparer.Ordinal)
|
||||
{
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "-", "=",
|
||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
|
||||
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
|
||||
"backspace", "[", "]", "\\", ";", "'", "enter", ",", ".", "/", "space", "pause",
|
||||
"insert", "delete", "home", "end",
|
||||
"num_/", "num_*", "num_-", "num_+", "num_enter", "num_.",
|
||||
"num_0", "num_1", "num_2", "num_3", "num_4", "num_5", "num_6", "num_7", "num_8", "num_9",
|
||||
"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "f10", "f11", "f12",
|
||||
"tab", "esc", "left", "right", "up", "down", "page_up", "page_down"
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData("tab", "KbUseMap")]
|
||||
[InlineData("f1", "KbUseConsist")]
|
||||
[InlineData("f2", "KbUseTimetable")]
|
||||
[InlineData("f3", "KbUseScenario")]
|
||||
[InlineData("f9", "KbUseLog")]
|
||||
[InlineData("f10", "KbUseQuit")]
|
||||
public void What_the_simulator_takes_first_blocks_only_without_a_modifier(string token, string text)
|
||||
{
|
||||
Assert.Equal(new SimulatorKeyUse(text, true), KeyMap.SimulatorUse(token, false, false));
|
||||
Assert.Null(KeyMap.SimulatorUse(token, true, false));
|
||||
Assert.Null(KeyMap.SimulatorUse(token, false, true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Shift_F12_blocks_and_F12_alone_is_free()
|
||||
{
|
||||
Assert.Equal(new SimulatorKeyUse("KbUseDebugPanel", true), KeyMap.SimulatorUse("f12", true, false));
|
||||
Assert.Null(KeyMap.SimulatorUse("f12", false, false));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("f4", false, false, "KbUseCab")]
|
||||
[InlineData("f4", true, false, "KbUseCab")]
|
||||
[InlineData("f5", false, true, "KbUseVehicle")]
|
||||
[InlineData("f6", false, false, "KbUseDebug")]
|
||||
[InlineData("f7", false, true, "KbUseDebug")]
|
||||
[InlineData("f11", false, false, "KbUseEditor")]
|
||||
[InlineData("3", true, false, "KbUseSceneryEvent")]
|
||||
[InlineData("3", false, true, "KbUseCamera")]
|
||||
public void What_is_left_to_a_key_a_binding_may_replace(string token, bool shift, bool ctrl, string text)
|
||||
{
|
||||
Assert.Equal(new SimulatorKeyUse(text, false), KeyMap.SimulatorUse(token, shift, ctrl));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("3", false, false)]
|
||||
[InlineData("a", false, false)]
|
||||
[InlineData("a", true, true)]
|
||||
[InlineData("f7", true, false)]
|
||||
[InlineData("f8", false, false)]
|
||||
[InlineData("f11", true, false)]
|
||||
[InlineData("num_5", true, false)]
|
||||
[InlineData("enter", false, false)]
|
||||
public void The_rest_the_simulator_leaves_alone(string token, bool shift, bool ctrl)
|
||||
{
|
||||
Assert.Null(KeyMap.SimulatorUse(token, shift, ctrl));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_bundled_keys_use_nothing_the_simulator_takes_first()
|
||||
{
|
||||
var config = new KeyboardConfig();
|
||||
string path = Path.Combine(AppContext.BaseDirectory, "startercfg", "eu07_input-keyboard.ini");
|
||||
config.Parse(File.ReadAllText(path));
|
||||
|
||||
var taken = config.Bindings
|
||||
.Where(b => b.IsAssigned && KeyMap.SimulatorUse(b.Key, b.Shift, b.Ctrl) is { Blocks: true })
|
||||
.Select(b => b.Command)
|
||||
.ToList();
|
||||
|
||||
Assert.Empty(taken);
|
||||
Assert.Contains(config.Bindings, b => b.IsAssigned);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_key_drawn_is_one_the_simulator_knows()
|
||||
{
|
||||
var drawn = KeyMap.MainBlock.Concat(KeyMap.NumpadBlock).Concat(KeyMap.NavBlock)
|
||||
.SelectMany(row => row)
|
||||
.Select(cap => cap.Token)
|
||||
.OfType<string>();
|
||||
|
||||
Assert.Empty(drawn.Where(token => !SimulatorKeyNames.Contains(token)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("page_up", "Page Up")]
|
||||
[InlineData("page_down", "Page Down")]
|
||||
[InlineData("esc", "Esc")]
|
||||
[InlineData("num_enter", "Num Enter")]
|
||||
public void Key_names_read_as_on_a_keyboard(string token, string expected)
|
||||
{
|
||||
Assert.Equal(expected, KeyMap.DisplayName(token));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("a", false, false, "A")]
|
||||
[InlineData("a", true, false, "Shift + A")]
|
||||
[InlineData("a", false, true, "Ctrl + A")]
|
||||
[InlineData("num_enter", true, true, "Ctrl + Shift + Num Enter")]
|
||||
[InlineData("none", true, true, "—")]
|
||||
[InlineData("NONE", false, true, "—")]
|
||||
[InlineData("", true, false, "—")]
|
||||
public void A_combination_reads_with_its_modifiers_unless_there_is_no_key(string token, bool shift, bool ctrl, string expected)
|
||||
{
|
||||
Assert.Equal(expected, KeyMap.ComboText(token, shift, ctrl));
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,151 @@ public class KeyboardConfigTests
|
||||
[Fact]
|
||||
public void A_description_without_polish_letters_matches_the_bundled_one() =>
|
||||
Assert.Equal("zwiekszenie nastawnika glownego", KeyboardConfig.StripPolish("zwiększenie nastawnika głównego"));
|
||||
|
||||
private static KeyBinding Parse(string line)
|
||||
{
|
||||
var config = new KeyboardConfig();
|
||||
config.Parse(line);
|
||||
return Assert.Single(config.Bindings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_binding_without_a_description_shows_the_translated_one()
|
||||
{
|
||||
var binding = Parse("hornhighactivate a");
|
||||
|
||||
string text = new KeyboardConfig().DescriptionOf(binding, _ => "high tone horn");
|
||||
|
||||
Assert.Equal("high tone horn", text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_description_someone_wrote_wins_over_the_translation()
|
||||
{
|
||||
var binding = Parse("hornhighactivate a // my own horn");
|
||||
|
||||
string text = new KeyboardConfig().DescriptionOf(binding, _ => "high tone horn");
|
||||
|
||||
Assert.Equal("my own horn", text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_a_translation_the_file_description_stays()
|
||||
{
|
||||
var binding = Parse("hornhighactivate a // syrena wysoka");
|
||||
|
||||
Assert.Equal("syrena wysoka", new KeyboardConfig().DescriptionOf(binding, _ => string.Empty));
|
||||
}
|
||||
|
||||
// ── Which binding sits where ─────────────────────────────────────────────
|
||||
|
||||
private static KeyboardConfig Config(params string[] lines)
|
||||
{
|
||||
var config = new KeyboardConfig();
|
||||
config.Parse(string.Join("\n", lines));
|
||||
return config;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_cleared_binding_is_on_no_key_and_no_modifier()
|
||||
{
|
||||
var binding = Parse("hornhighactivate shift ctrl a");
|
||||
|
||||
binding.Clear();
|
||||
|
||||
Assert.False(binding.IsAssigned);
|
||||
Assert.False(binding.Shift);
|
||||
Assert.False(binding.Ctrl);
|
||||
Assert.Equal("none", binding.Key);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("a", true, false, true)]
|
||||
[InlineData("A", true, false, true)]
|
||||
[InlineData("a", false, false, false)]
|
||||
[InlineData("a", true, true, false)]
|
||||
[InlineData("b", true, false, false)]
|
||||
public void A_binding_is_on_its_key_with_exactly_its_modifiers(string token, bool shift, bool ctrl, bool on) =>
|
||||
Assert.Equal(on, Parse("hornhighactivate shift a").IsOn(token, shift, ctrl));
|
||||
|
||||
[Fact]
|
||||
public void An_unassigned_binding_is_on_nothing_not_even_the_word_none() =>
|
||||
Assert.False(Parse("hornhighactivate none").IsOn("none", false, false));
|
||||
|
||||
[Fact]
|
||||
public void The_binding_at_a_combination_is_found_by_key_and_modifiers()
|
||||
{
|
||||
var config = Config("plain a", "shifted shift a");
|
||||
|
||||
Assert.Equal("plain", config.BindingAt("A", false, false)?.Command);
|
||||
Assert.Equal("shifted", config.BindingAt("a", true, false)?.Command);
|
||||
Assert.Null(config.BindingAt("a", false, true));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_combination_put_on_a_binding_moves_there_from_the_one_that_had_it()
|
||||
{
|
||||
var config = Config("first ctrl a", "second b", "third a");
|
||||
|
||||
config.Put(config.Bindings[1], "a", shift: false, ctrl: true);
|
||||
|
||||
Assert.False(config.Bindings[0].IsAssigned);
|
||||
Assert.False(config.Bindings[0].Ctrl);
|
||||
Assert.True(config.Bindings[1].IsOn("a", false, true));
|
||||
// The same key with other modifiers is another combination.
|
||||
Assert.True(config.Bindings[2].IsOn("a", false, false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Every_binding_doubled_up_on_a_combination_leaves_it_but_the_one_put_there()
|
||||
{
|
||||
var config = Config("first a", "second a", "third a");
|
||||
|
||||
config.Put(config.Bindings[1], "a", shift: false, ctrl: false);
|
||||
|
||||
Assert.False(config.Bindings[0].IsAssigned);
|
||||
Assert.True(config.Bindings[1].IsOn("a", false, false));
|
||||
Assert.False(config.Bindings[2].IsAssigned);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Nothing_put_on_a_combination_frees_it()
|
||||
{
|
||||
var config = Config("first shift a", "second b");
|
||||
|
||||
config.Put(null, "a", shift: true, ctrl: false);
|
||||
|
||||
Assert.False(config.Bindings[0].IsAssigned);
|
||||
Assert.True(config.Bindings[1].IsOn("b", false, false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_combination_put_back_on_the_binding_that_has_it_stays()
|
||||
{
|
||||
var config = Config("first a");
|
||||
|
||||
config.Put(config.Bindings[0], "a", shift: false, ctrl: false);
|
||||
|
||||
Assert.True(config.Bindings[0].IsOn("a", false, false));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Two_bindings_on_a_combination_conflict_however_the_key_is_spelled()
|
||||
{
|
||||
var config = Config("first shift a", "second shift A", "third a", "fourth ctrl a", "fifth none", "sixth none");
|
||||
|
||||
var conflicts = config.ConflictingCombos();
|
||||
|
||||
Assert.Equal(config.Bindings[0].ComboKey, Assert.Single(conflicts));
|
||||
Assert.Contains(config.Bindings[1].ComboKey, conflicts);
|
||||
Assert.DoesNotContain(config.Bindings[2].ComboKey, conflicts);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Only_bindings_on_a_key_of_the_numpad_count_as_on_it()
|
||||
{
|
||||
var config = Config("first num_1", "second shift NUM_enter", "third a", "fourth none");
|
||||
|
||||
Assert.Equal(2, config.BindingsOnNumpad());
|
||||
}
|
||||
}
|
||||
|
||||
103
StarterNG.Tests/ResolutionChoicesTests.cs
Normal file
103
StarterNG.Tests/ResolutionChoicesTests.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class ResolutionChoicesTests
|
||||
{
|
||||
private static List<string> Listed(ScreenSize[] monitors, ScreenSize current) =>
|
||||
ResolutionChoices.For(monitors, current).Select(c => c.Size.ToString()).ToList();
|
||||
|
||||
[Fact]
|
||||
public void The_monitors_come_first_and_are_marked()
|
||||
{
|
||||
var choices = ResolutionChoices.For(new[] { new ScreenSize(1920, 1200), new ScreenSize(2560, 1440) },
|
||||
new ScreenSize(1280, 720));
|
||||
|
||||
Assert.Equal(new ScreenSize(1920, 1200), choices[0].Size);
|
||||
Assert.Equal(new ScreenSize(2560, 1440), choices[1].Size);
|
||||
Assert.True(choices[0].IsMonitor);
|
||||
Assert.True(choices[1].IsMonitor);
|
||||
Assert.All(choices.Skip(2), c => Assert.False(c.IsMonitor));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_size_no_monitor_can_show_is_not_offered()
|
||||
{
|
||||
var listed = Listed(new[] { new ScreenSize(1920, 1080) }, new ScreenSize(1280, 720));
|
||||
|
||||
Assert.Contains("1920x1080", listed);
|
||||
Assert.Contains("1600x900", listed);
|
||||
Assert.DoesNotContain("3840x2160", listed);
|
||||
Assert.DoesNotContain("2560x1440", listed);
|
||||
// Taller than the screen, though no wider.
|
||||
Assert.DoesNotContain("1920x1200", listed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_size_fitting_any_of_the_monitors_is_offered()
|
||||
{
|
||||
var listed = Listed(new[] { new ScreenSize(1920, 1080), new ScreenSize(3440, 1440) }, new ScreenSize(1280, 720));
|
||||
|
||||
Assert.Contains("2560x1080", listed);
|
||||
Assert.DoesNotContain("3840x2160", listed);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(1920, 1200)]
|
||||
[InlineData(1280, 800)]
|
||||
[InlineData(2560, 1080)]
|
||||
[InlineData(3440, 1440)]
|
||||
public void The_monitors_size_is_there_even_where_it_is_not_a_usual_one(int width, int height)
|
||||
{
|
||||
var listed = Listed(new[] { new ScreenSize(width, height) }, new ScreenSize(1024, 768));
|
||||
|
||||
Assert.Equal($"{width}x{height}", listed[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_size_asked_for_stays_on_the_list_whatever_it_is()
|
||||
{
|
||||
var listed = Listed(new[] { new ScreenSize(1920, 1080) }, new ScreenSize(5120, 1440));
|
||||
|
||||
Assert.Contains("5120x1440", listed);
|
||||
Assert.Single(listed, "5120x1440");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_rest_goes_from_the_largest_down_without_repeats()
|
||||
{
|
||||
var listed = Listed(new[] { new ScreenSize(2560, 1440) }, new ScreenSize(1920, 1080));
|
||||
|
||||
Assert.Equal(listed.Count, listed.Distinct().Count());
|
||||
var sizes = ResolutionChoices.For(new[] { new ScreenSize(2560, 1440) }, new ScreenSize(1920, 1080))
|
||||
.Skip(1).Select(c => c.Size).ToList();
|
||||
Assert.Equal(sizes.OrderByDescending(s => s.Width).ThenByDescending(s => s.Height), sizes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Two_monitors_of_a_size_are_one_entry()
|
||||
{
|
||||
var choices = ResolutionChoices.For(new[] { new ScreenSize(1920, 1080), new ScreenSize(1920, 1080) },
|
||||
new ScreenSize(1920, 1080));
|
||||
|
||||
Assert.Single(choices, c => c.Size == new ScreenSize(1920, 1080));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_no_monitors_known_everything_usual_is_offered()
|
||||
{
|
||||
var listed = Listed(Array.Empty<ScreenSize>(), new ScreenSize(1280, 720));
|
||||
|
||||
Assert.Contains("3840x2160", listed);
|
||||
Assert.Contains("1280x800", listed);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_size_of_nothing_is_not_listed()
|
||||
{
|
||||
var listed = Listed(new[] { new ScreenSize(0, 0) }, new ScreenSize(0, 0));
|
||||
|
||||
Assert.DoesNotContain("0x0", listed);
|
||||
Assert.NotEmpty(listed);
|
||||
}
|
||||
}
|
||||
128
StarterNG.Tests/SettingReachTests.cs
Normal file
128
StarterNG.Tests/SettingReachTests.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using StarterNG.Domain.Settings;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class SettingReachTests
|
||||
{
|
||||
private static SimulatorTarget Linux(string renderer = "full", bool server = false) =>
|
||||
new(WindowsBuild: false, renderer, server);
|
||||
|
||||
[Theory]
|
||||
[InlineData("feedbackmode")]
|
||||
[InlineData("feedbackport")]
|
||||
[InlineData("showsystemconsole")]
|
||||
[InlineData("gfx.angleplatform")]
|
||||
public void Windows_only_keys_idle_on_a_linux_build(string key)
|
||||
{
|
||||
Assert.Equal(IdleReason.WindowsBuildOnly, SettingReach.Why(key, Linux()));
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why(key, Linux() with { WindowsBuild = true }));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("full", IdleReason.LegacyRendererOnly)]
|
||||
[InlineData("experimental", IdleReason.LegacyRendererOnly)]
|
||||
[InlineData("legacy", IdleReason.None)]
|
||||
[InlineData("simpleshader", IdleReason.None)]
|
||||
[InlineData("simple", IdleReason.None)]
|
||||
public void Legacy_renderer_keys_follow_the_renderer(string renderer, IdleReason expected)
|
||||
{
|
||||
Assert.Equal(expected, SettingReach.Why("smoothtraction", Linux(renderer)));
|
||||
Assert.Equal(expected, SettingReach.Why("usevbo", Linux(renderer)));
|
||||
Assert.Equal(expected, SettingReach.Why("gfx.shadows.cab.range", Linux(renderer)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pausing_in_the_background_needs_a_network_server()
|
||||
{
|
||||
Assert.Equal(IdleReason.NeedsNetworkServer, SettingReach.Why("inactivepause", Linux()));
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why("inactivepause", Linux(server: true)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_starters_own_keys_never_idle()
|
||||
{
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why("starter.autoclose", Linux()));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("width, height")]
|
||||
[InlineData("fullscreen")]
|
||||
public void The_monitors_own_mode_overrides_size_and_full_screen(string key)
|
||||
{
|
||||
Assert.Equal(IdleReason.MonitorModeInstead,
|
||||
SettingReach.Why(key, Linux() with { FullscreenWindowed = true }));
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why(key, Linux()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_ordinary_key_works_everywhere()
|
||||
{
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why("fieldofview", Linux()));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("full", IdleReason.None)]
|
||||
[InlineData("legacy", IdleReason.ModernRendererOnly)]
|
||||
[InlineData("experimental", IdleReason.ModernRendererOnly)]
|
||||
public void Effects_of_the_full_renderer_follow_the_renderer(string renderer, IdleReason expected)
|
||||
{
|
||||
Assert.Equal(expected, SettingReach.Why("gfx.postfx.motionblur.enabled", Linux(renderer)));
|
||||
Assert.Equal(expected, SettingReach.Why("gfx.envmap.enabled", Linux(renderer)));
|
||||
Assert.Equal(expected, SettingReach.Why("sleeperdistance", Linux(renderer)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("full", IdleReason.None)]
|
||||
[InlineData("legacy", IdleReason.None)]
|
||||
[InlineData("experimental", IdleReason.OpenGlRenderersOnly)]
|
||||
public void The_experimental_renderer_passes_over_what_only_opengl_reads(string renderer, IdleReason expected)
|
||||
{
|
||||
Assert.Equal(expected, SettingReach.Why("multisampling", Linux(renderer)));
|
||||
Assert.Equal(expected, SettingReach.Why("anisotropicfiltering", Linux(renderer)));
|
||||
Assert.Equal(expected, SettingReach.Why("gfx.smoke", Linux(renderer)));
|
||||
// ...but reads the rest of the reflections and shadows.
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why("gfx.reflections.fidelity", Linux(renderer)));
|
||||
Assert.Equal(IdleReason.None, SettingReach.Why("shadowtune", Linux(renderer)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, 0, false)]
|
||||
[InlineData(0.0, 0, false)]
|
||||
[InlineData(60.0, 0, true)]
|
||||
[InlineData(null, 50, true)] // fpsaverage, the older regulator
|
||||
public void The_draw_range_factor_needs_a_regulator(double? targetFps, double fpsAverage, bool regulated)
|
||||
{
|
||||
var target = Linux() with { TargetFps = targetFps, FpsAverage = fpsAverage };
|
||||
|
||||
Assert.Equal(regulated ? IdleReason.None : IdleReason.NeedsFrameRateTarget,
|
||||
SettingReach.Why("gfx.drawrange.factor.max", target));
|
||||
}
|
||||
|
||||
// ── The rest of the target ───────────────────────────────────────────────
|
||||
|
||||
[Fact]
|
||||
public void A_windows_build_is_told_from_its_header()
|
||||
{
|
||||
var files = new InMemoryFileSystem()
|
||||
.WithExecutable(TestInstallation.At("eu07"), "\u007fELF binary")
|
||||
.WithFile(TestInstallation.At("eu07.exe"), "MZ binary");
|
||||
var installation = new TestInstallation(files);
|
||||
|
||||
Assert.False(installation.Executables.IsWindowsBuild("eu07"));
|
||||
Assert.True(installation.Executables.IsWindowsBuild("eu07.exe"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_network_server_in_the_ini_is_noticed()
|
||||
{
|
||||
string ini = Path.Combine("/home/kolejarz", ".config", "MaSzyna", "eu07.ini");
|
||||
var installation = new TestInstallation(new InMemoryFileSystem()
|
||||
.WithFile(ini, "network.server tcp 0.0.0.0:7424\n"));
|
||||
installation.Environment.With("HOME", "/home/kolejarz");
|
||||
|
||||
installation.SettingsStore.Load();
|
||||
|
||||
Assert.True(installation.SettingsStore.Settings.NetworkServer);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
42
StarterNG.Tests/StepsTests.cs
Normal file
42
StarterNG.Tests/StepsTests.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using StarterNG.Domain.Settings;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class StepsTests
|
||||
{
|
||||
[Fact]
|
||||
public void A_value_among_the_steps_leaves_them_as_they_are()
|
||||
{
|
||||
Assert.Same(Steps.FrameRateLimits, Steps.With(Steps.FrameRateLimits, 144));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_value_between_the_steps_joins_them_in_order()
|
||||
{
|
||||
var steps = Steps.With(Steps.FrameRateLimits, 58);
|
||||
|
||||
Assert.Equal(Steps.FrameRateLimits.Length + 1, steps.Count);
|
||||
Assert.Equal(new double[] { 50, 58, 60 }, steps.Skip(Steps.IndexOf(steps, 50)).Take(3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Values_past_either_end_join_at_that_end()
|
||||
{
|
||||
Assert.Equal(0.5, Steps.With(Steps.Anisotropy, 0.5)[0]);
|
||||
Assert.Equal(500, Steps.With(Steps.FrameRateLimits, 500)[^1]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_frame_rate_limits_start_with_none()
|
||||
{
|
||||
Assert.Equal(new double[] { 0, 10, 20 }, Steps.With(Steps.FrameRateLimits, 10).Take(3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_step_is_found_from_its_rounding_in_the_file()
|
||||
{
|
||||
// 1/300 is written as 0.003333.
|
||||
Assert.Equal(0, Steps.IndexOf(Steps.ReflectionUpdates, 0.003333));
|
||||
Assert.Equal(-1, Steps.IndexOf(Steps.ReflectionUpdates, 0.0033));
|
||||
}
|
||||
}
|
||||
209
StarterNG.Tests/WineConfigLinkTests.cs
Normal file
209
StarterNG.Tests/WineConfigLinkTests.cs
Normal file
@@ -0,0 +1,209 @@
|
||||
using StarterNG.Infrastructure;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class WineConfigLinkTests
|
||||
{
|
||||
// Rooted the way the host roots a path: the link is made to the folder's full
|
||||
// path, and on a Windows host "/home" alone is not one. Wine itself only runs off
|
||||
// Windows, but what is decided here is the same wherever these tests run.
|
||||
private static readonly string Home = Path.GetFullPath("/home/kolejarz");
|
||||
private static readonly string Config = Path.GetFullPath(Home + "/.config/MaSzyna");
|
||||
private static readonly string Roaming = Home + "/.wine/drive_c/users/kolejarz/AppData/Roaming";
|
||||
private static readonly string PrefixFolder = Roaming + "/MaSzyna";
|
||||
|
||||
private static (WineConfigLink Link, TestInstallation Installation) Rig(Action<InMemoryFileSystem>? arrange = null)
|
||||
{
|
||||
var files = new InMemoryFileSystem(caseSensitive: true)
|
||||
.WithFile(Config + "/eu07.ini", "fpslimit 30\n");
|
||||
arrange?.Invoke(files);
|
||||
var installation = new TestInstallation(files);
|
||||
installation.Environment.With("HOME", Home).With("USER", "kolejarz");
|
||||
return (new WineConfigLink(files, installation.Environment, installation.SettingsPaths, installation.Log),
|
||||
installation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_prefixs_own_folder_is_kept_aside_and_linked_to_the_starters()
|
||||
{
|
||||
var (link, installation) = Rig(files => files
|
||||
.WithFile(PrefixFolder + "/eu07.ini", "fpslimit 0\n")
|
||||
.WithFile(PrefixFolder + "/eu07_input-uart.ini", "port COM3\n"));
|
||||
|
||||
link.Ensure();
|
||||
|
||||
var files = installation.Files;
|
||||
Assert.Equal(Config, files.LinkTarget(PrefixFolder));
|
||||
Assert.Equal("fpslimit 0\n", files.ReadAllText(PrefixFolder + ".before-starter/eu07.ini"));
|
||||
// What only the prefix had comes along; the starter's own eu07.ini stays.
|
||||
Assert.Equal("port COM3\n", files.ReadAllText(Config + "/eu07_input-uart.ini"));
|
||||
Assert.Equal("fpslimit 30\n", files.ReadAllText(Config + "/eu07.ini"));
|
||||
Assert.Contains("now links to", installation.Log.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_prefix_already_linked_is_left_alone()
|
||||
{
|
||||
var (link, installation) = Rig(files => files.WithDirectory(PrefixFolder));
|
||||
link.Ensure();
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal(Config, installation.Files.LinkTarget(PrefixFolder));
|
||||
Assert.False(installation.Files.DirectoryExists(PrefixFolder + ".before-starter-2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_link_of_the_players_own_is_not_touched()
|
||||
{
|
||||
var (link, installation) = Rig(files =>
|
||||
{
|
||||
files.WithDirectory(Roaming);
|
||||
files.CreateDirectoryLink(PrefixFolder, "/mnt/shared/MaSzyna");
|
||||
});
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal("/mnt/shared/MaSzyna", installation.Files.LinkTarget(PrefixFolder));
|
||||
Assert.Contains("left as it is", installation.Log.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_a_prefix_nothing_is_made()
|
||||
{
|
||||
var (link, installation) = Rig();
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.False(installation.Files.DirectoryExists(Home + "/.wine"));
|
||||
Assert.Contains("no prefix", installation.Log.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_prefix_named_in_wineprefix_is_the_one_linked()
|
||||
{
|
||||
string prefix = Path.GetFullPath("/games/wine-maszyna");
|
||||
var (link, installation) = Rig(files => files
|
||||
.WithDirectory(prefix + "/drive_c/users/kolejarz/AppData/Roaming")
|
||||
.WithDirectory(Roaming));
|
||||
installation.Environment.With("WINEPREFIX", prefix);
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal(Config, installation.Files.LinkTarget(prefix + "/drive_c/users/kolejarz/AppData/Roaming/MaSzyna"));
|
||||
Assert.Null(installation.Files.LinkTarget(PrefixFolder));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_older_backup_is_not_overwritten()
|
||||
{
|
||||
var (link, installation) = Rig(files => files
|
||||
.WithFile(PrefixFolder + ".before-starter/eu07.ini", "first\n")
|
||||
.WithFile(PrefixFolder + "/eu07.ini", "second\n"));
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal("first\n", installation.Files.ReadAllText(PrefixFolder + ".before-starter/eu07.ini"));
|
||||
Assert.Equal("second\n", installation.Files.ReadAllText(PrefixFolder + ".before-starter-2/eu07.ini"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_older_wine_keeps_application_data_where_xp_did()
|
||||
{
|
||||
string applicationData = Home + "/.wine/drive_c/users/kolejarz/Application Data";
|
||||
var (link, installation) = Rig(files => files.WithDirectory(applicationData));
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal(Config, installation.Files.LinkTarget(applicationData + "/MaSzyna"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_only_profile_is_used_when_the_user_name_differs()
|
||||
{
|
||||
string profile = Home + "/.wine/drive_c/users/steamuser/AppData/Roaming";
|
||||
var (link, installation) = Rig(files => files
|
||||
.WithDirectory(Home + "/.wine/drive_c/users/Public")
|
||||
.WithDirectory(profile));
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal(Config, installation.Files.LinkTarget(profile + "/MaSzyna"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_link_that_cannot_be_made_leaves_the_prefix_as_it_was()
|
||||
{
|
||||
var (link, installation) = Rig(files => files
|
||||
.WithFile(PrefixFolder + "/eu07.ini", "fpslimit 0\n")
|
||||
.WithFile(PrefixFolder + "/eu07_input-uart.ini", "port COM3\n"));
|
||||
var files = installation.Files;
|
||||
files.LinksFail = true;
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Null(files.LinkTarget(PrefixFolder));
|
||||
Assert.Equal("fpslimit 0\n", files.ReadAllText(PrefixFolder + "/eu07.ini"));
|
||||
Assert.False(files.DirectoryExists(PrefixFolder + ".before-starter"));
|
||||
// Nothing carried over stays behind for a move that did not happen.
|
||||
Assert.False(files.FileExists(Config + "/eu07_input-uart.ini"));
|
||||
Assert.Equal("fpslimit 30\n", files.ReadAllText(Config + "/eu07.ini"));
|
||||
Assert.Contains("linking the settings", installation.Log.Text);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Attempts_that_fail_do_not_pile_up_backups()
|
||||
{
|
||||
var (link, installation) = Rig(files => files.WithFile(PrefixFolder + "/eu07.ini", "fpslimit 0\n"));
|
||||
var files = installation.Files;
|
||||
files.LinksFail = true;
|
||||
|
||||
link.Ensure();
|
||||
link.Ensure();
|
||||
link.Ensure();
|
||||
|
||||
Assert.False(files.DirectoryExists(PrefixFolder + ".before-starter"));
|
||||
Assert.False(files.DirectoryExists(PrefixFolder + ".before-starter-2"));
|
||||
|
||||
files.LinksFail = false;
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal(Config, files.LinkTarget(PrefixFolder));
|
||||
Assert.Equal("fpslimit 0\n", files.ReadAllText(PrefixFolder + ".before-starter/eu07.ini"));
|
||||
Assert.False(files.DirectoryExists(PrefixFolder + ".before-starter-2"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_copy_that_fails_half_way_takes_back_what_it_had_copied()
|
||||
{
|
||||
var (link, installation) = Rig(files => files
|
||||
.WithFile(PrefixFolder + "/a.ini", "first\n")
|
||||
.WithFile(PrefixFolder + "/b.ini", "second\n")
|
||||
// It is read from where the folder has been moved to by then.
|
||||
.FailReading(PrefixFolder + ".before-starter/b.ini"));
|
||||
var files = installation.Files;
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Null(files.LinkTarget(PrefixFolder));
|
||||
Assert.Equal("first\n", files.ReadAllText(PrefixFolder + "/a.ini"));
|
||||
Assert.False(files.FileExists(Config + "/a.ini"));
|
||||
Assert.False(files.DirectoryExists(PrefixFolder + ".before-starter"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_folder_that_cannot_be_put_back_is_said_to_be_where_it_is()
|
||||
{
|
||||
var (link, installation) = Rig(files => files.WithFile(PrefixFolder + "/eu07.ini", "fpslimit 0\n"));
|
||||
var files = installation.Files;
|
||||
files.LinksFail = true;
|
||||
// In the way of the move back: made by whatever broke the link, say.
|
||||
files.MoveFails = path => path.EndsWith("/Roaming/MaSzyna");
|
||||
|
||||
link.Ensure();
|
||||
|
||||
Assert.Equal("fpslimit 0\n", files.ReadAllText(PrefixFolder + ".before-starter/eu07.ini"));
|
||||
Assert.Contains("stays at", installation.Log.Text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user