diff --git a/StarterNG.Tests/ExternalIniTests.cs b/StarterNG.Tests/ExternalIniTests.cs
index ba721d0..7086035 100644
--- a/StarterNG.Tests/ExternalIniTests.cs
+++ b/StarterNG.Tests/ExternalIniTests.cs
@@ -68,6 +68,71 @@ public class ExternalIniTests
Assert.Contains("fieldofview 60", installation.Files.ReadAllText(UserIni));
}
+ [Fact]
+ public void A_renderer_written_in_by_hand_while_the_starter_runs_survives_its_save()
+ {
+ // Notepad: "gfxrenderer vulkan", a word the starter does not offer.
+ var installation = WithIni("gfxrenderer default\nfieldofview 45\n");
+ Edited(installation, "gfxrenderer vulkan\nfieldofview 45\n");
+
+ installation.SettingsStore.Settings.FieldOfView = 60;
+ installation.SettingsStore.Save();
+
+ string saved = installation.Files.ReadAllText(UserIni);
+ Assert.Contains("gfxrenderer vulkan", saved);
+ Assert.Contains("fieldofview 60", saved);
+ Assert.Equal("vulkan", installation.SettingsStore.Settings.RendererWord);
+ }
+
+ [Fact]
+ public void A_renderer_written_in_by_hand_and_read_again_survives_the_next_save()
+ {
+ var installation = WithIni("gfxrenderer default\n");
+ Edited(installation, "gfxrenderer vulkan\n");
+
+ // "Wczytać ponownie?" - yes.
+ installation.SettingsStore.Load();
+ installation.SettingsStore.Save();
+
+ Assert.Contains("gfxrenderer vulkan", installation.Files.ReadAllText(UserIni));
+ }
+
+ [Fact]
+ public void A_change_on_disk_not_read_again_is_not_lost_on_the_next_save()
+ {
+ var installation = WithIni("gfxrenderer default\nfieldofview 45\nvsync no\n");
+ var store = installation.SettingsStore;
+ Edited(installation, "gfxrenderer vulkan\nfieldofview 45\nvsync yes\n");
+ Assert.True(store.HasChangeOnDiskToAskAbout());
+
+ // "Wczytać ponownie?" - no: not asked again about the same change.
+ store.LeaveChangeOnDisk();
+ Assert.False(store.HasChangeOnDiskToAskAbout());
+
+ store.Settings.FieldOfView = 60;
+ store.Save();
+
+ string saved = installation.Files.ReadAllText(UserIni);
+ Assert.Contains("gfxrenderer vulkan", saved);
+ Assert.Contains("vsync yes", saved);
+ Assert.Contains("fieldofview 60", saved);
+ Assert.True(store.LastSaveMerged);
+ }
+
+ [Fact]
+ public void A_later_change_on_disk_is_asked_about_again()
+ {
+ var installation = WithIni("fieldofview 45\n");
+ var store = installation.SettingsStore;
+ Edited(installation, "fieldofview 50\n");
+ store.LeaveChangeOnDisk();
+
+ installation.Files.WithFile(UserIni, "fieldofview 55\n")
+ .WrittenAt(UserIni, installation.Files.GetLastWriteTimeUtc(UserIni).AddMinutes(1));
+
+ Assert.True(store.HasChangeOnDiskToAskAbout());
+ }
+
[Fact]
public void A_file_nobody_else_touched_saves_as_before()
{
@@ -97,6 +162,8 @@ public class ExternalIniTests
Assert.False(unreadable.ContainsKey("gfxrenderer"));
Assert.False(unreadable.ContainsKey("gfx.framebuffer.width"));
Assert.False(unreadable.ContainsKey("calibratein"));
+ // The default features in another order: the same line.
+ Assert.False(WithIni("uartfeature local|main|scnd|train\n").SettingsStore.UnreadableValues().ContainsKey("uartfeature"));
// The file keeps what it says until the setting is changed.
installation.SettingsStore.Save();
Assert.Contains("fieldofview abc", installation.Files.ReadAllText(UserIni));
diff --git a/StarterNG.Tests/GraphicsSettingsTests.cs b/StarterNG.Tests/GraphicsSettingsTests.cs
index f63e300..1ac97dd 100644
--- a/StarterNG.Tests/GraphicsSettingsTests.cs
+++ b/StarterNG.Tests/GraphicsSettingsTests.cs
@@ -37,18 +37,18 @@ public class GraphicsSettingsTests
private static string? Line(string text, string key) =>
Lines(text).FirstOrDefault(l => l == key || l.StartsWith(key + " ", StringComparison.Ordinal));
- // As application.cpp on master has them: a word it does not know gets the full renderer.
+ // As application.cpp on master has them; a word the starter does not know is the file's own, written back as it is.
[Theory]
[InlineData("default", "default")]
- [InlineData("full", "default")]
- [InlineData("gl46", "default")]
- [InlineData("vulkan", "default")]
- [InlineData("vulkan14", "default")]
+ [InlineData("full", "full")]
+ [InlineData("gl46", "gl46")]
+ [InlineData("vulkan", "vulkan")]
+ [InlineData("vulkan14", "vulkan14")]
[InlineData("legacy", "legacy")]
[InlineData("simpleshader", "legacy")]
[InlineData("off", "legacy")]
[InlineData("simple", "simple")]
- [InlineData("experimental", "default")]
+ [InlineData("experimental", "experimental")]
public void A_renderer_is_written_by_the_name_master_knows(string read, string written)
{
Assert.Equal($"gfxrenderer {written}", Line(Write(Read($"gfxrenderer {read}\n")), "gfxrenderer"));
@@ -93,7 +93,7 @@ public class GraphicsSettingsTests
}
[Fact]
- public void Keys_of_the_vulkan_renderer_master_does_not_have_go_on_a_save()
+ public void Keys_of_the_vulkan_renderer_master_does_not_have_stay_on_a_save()
{
string[] vulkan =
{
@@ -107,7 +107,8 @@ public class GraphicsSettingsTests
string saved = installation.Files.ReadAllText(UserIni);
Assert.Contains("calibratein 0 0 0 0", saved);
- Assert.All(vulkan, line => Assert.Null(Line(saved, line.Split(' ')[0])));
+ // Written in by hand for a build that has that renderer: the starter does not know them, and leaves them.
+ Assert.All(vulkan, line => Assert.Equal(line, Line(saved, line.Split(' ')[0])));
}
[Fact]
diff --git a/StarterNG.Tests/SettingsStoreTests.cs b/StarterNG.Tests/SettingsStoreTests.cs
index aa063be..206fa5d 100644
--- a/StarterNG.Tests/SettingsStoreTests.cs
+++ b/StarterNG.Tests/SettingsStoreTests.cs
@@ -961,23 +961,34 @@ public class SettingsStoreTests
Assert.Contains($"gfxrenderer {word}\n", SavedLines(installation));
}
- // Words master does not know start the full renderer with a line in its log, and the
- // experimental renderer is not in a player's build: a save puts "default" in their place.
+ // A word the starter does not know is written in by hand for a build that has it, such as one with Vulkan:
+ // shown, and left as it is until another renderer is chosen.
[Theory]
[InlineData("full")]
[InlineData("opengl")]
[InlineData("gl46")]
+ [InlineData("vulkan")]
[InlineData("vulkan14")]
[InlineData("experimental")]
[InlineData("null")]
- public void A_renderer_word_master_does_not_run_is_saved_as_default(string word)
+ public void A_renderer_word_the_starter_does_not_know_stays_until_another_is_chosen(string word)
{
- var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, $"gfxrenderer {word}\n"));
- installation.SettingsStore.Load();
+ var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, $"gfxrenderer {word}\nfieldofview 45\n"));
+ var store = installation.SettingsStore;
+ store.Load();
- installation.SettingsStore.Save();
+ Assert.Equal(word, store.Settings.RendererWord);
+ Assert.Equal(word, store.UnreadableValues()["gfxrenderer"]);
+ store.Settings.FieldOfView = 60;
+ store.Save();
+ Assert.Contains($"gfxrenderer {word}\n", SavedLines(installation));
+ // Picking one from the list, even the full renderer it runs as, is a choice.
+ store.Settings.RendererWord = null;
+ store.Settings.RenderEngine = 0;
+ store.Save();
Assert.Contains("gfxrenderer default\n", SavedLines(installation));
+ Assert.False(store.UnreadableValues().ContainsKey("gfxrenderer"));
}
[Theory]
diff --git a/StarterNG.Tests/SettingsUnknownValueTests.cs b/StarterNG.Tests/SettingsUnknownValueTests.cs
new file mode 100644
index 0000000..760829e
--- /dev/null
+++ b/StarterNG.Tests/SettingsUnknownValueTests.cs
@@ -0,0 +1,182 @@
+using Avalonia.Controls;
+using StarterNG.Application;
+using StarterNG.Controls;
+using StarterNG.Tests.Fakes;
+
+namespace StarterNG.Tests;
+
+///
+/// Values of eu07.ini the starter does not know, or a control cannot show, as the settings page
+/// shows them: as the file writes them, with a note, until the player sets them by hand - or the
+/// move to the standard mode puts them right.
+///
+[Collection(AvaloniaControls.Name)]
+public class SettingsUnknownValueTests
+{
+ // The standard mode already, unless a test moves to it.
+ private const string Standard = "starter.settings.standard yes\n";
+
+ private static void WithPage(string ini, Action> act)
+ {
+ var installation = new TestInstallation(new InMemoryFileSystem());
+ installation.Environment.AsWindows();
+ var services = AppServices.Initialize(installation.Paths, installation.Files, installation.Clock,
+ installation.Environment);
+ string path = services.SettingsPaths.UserConfigPath();
+ installation.Files.WriteAllText(path, ini);
+ services.SettingsStore.Load();
+
+ HeadlessDrawing.Ensure();
+ var context = SynchronizationContext.Current;
+ SynchronizationContext.SetSynchronizationContext(new Avalonia.Threading.AvaloniaSynchronizationContext());
+ Window? window = null;
+ try
+ {
+ var page = new StarterNG.Views.Settings();
+ window = Controls.Show(page, 1600, 1000, themed: true);
+ act(page, services, () => installation.Files.ReadAllText(path).Replace("\r\n", "\n"));
+ }
+ finally
+ {
+ window?.Close();
+ SynchronizationContext.SetSynchronizationContext(context);
+ }
+ }
+
+ private static ComboBox List(StarterNG.Views.Settings page, string name) => page.FindControl(name)!;
+
+ private static string? Shown(ComboBox list) => (list.SelectedItem as ComboBoxItem)?.Content as string;
+
+ private static string? Note(StarterNG.Views.Settings page, string key) =>
+ Avalonia.LogicalTree.LogicalExtensions.GetLogicalDescendants(page).OfType()
+ .First(row => row.ConfigKey == key).UnknownValue;
+
+ [Fact]
+ public void A_renderer_word_is_on_the_list_chosen_and_saved_as_it_is()
+ {
+ WithPage(Standard + "gfxrenderer vulkan\nfieldofview 45\n", (page, _, saved) =>
+ {
+ Assert.Equal("vulkan", Shown(List(page, "RenderEngineCb")));
+ Assert.Contains("vulkan", Note(page, "gfxrenderer"));
+ Assert.False(page.HasUnsavedChanges);
+
+ page.Save();
+
+ Assert.Contains("gfxrenderer vulkan\n", saved());
+ });
+ }
+
+ [Fact]
+ public void Another_renderer_picked_from_the_list_replaces_it()
+ {
+ WithPage(Standard + "gfxrenderer vulkan\n", (page, services, saved) =>
+ {
+ List(page, "RenderEngineCb").SelectedIndex = 0;
+
+ page.Save();
+
+ Assert.Contains("gfxrenderer default\n", saved());
+ Assert.Null(services.Settings.RendererWord);
+ Assert.Null(Note(page, "gfxrenderer"));
+ });
+ }
+
+ [Fact]
+ public void A_value_a_list_does_not_offer_is_listed_as_written_and_kept()
+ {
+ WithPage(Standard + "starter.batterydefault 7\ngfx.shadow.rank.cutoff 9\n", (page, _, saved) =>
+ {
+ Assert.Equal("7", Shown(List(page, "ReadyOverrideCb")));
+ Assert.Equal("9", Shown(List(page, "ShadowDisplayCb")));
+ Assert.Contains("7", Note(page, "starter.batterydefault"));
+ Assert.Contains("9", Note(page, "gfx.shadow.rank.cutoff"));
+ Assert.False(page.HasUnsavedChanges);
+
+ page.Save();
+
+ Assert.Contains("starter.batterydefault 7\n", saved());
+ Assert.Contains("gfx.shadow.rank.cutoff 9\n", saved());
+ });
+ }
+
+ [Fact]
+ public void Picking_the_value_the_starter_shows_by_default_replaces_the_files_own()
+ {
+ // "7" is read as the scenery's choice, the first on the list: picked by hand, it is written.
+ WithPage(Standard + "starter.batterydefault 7\n", (page, _, saved) =>
+ {
+ List(page, "ReadyOverrideCb").SelectedIndex = 0;
+ Assert.Null(Note(page, "starter.batterydefault"));
+
+ page.Save();
+
+ Assert.Contains("starter.batterydefault 0\n", saved());
+ });
+ }
+
+ [Fact]
+ public void A_list_put_back_at_the_files_value_keeps_it()
+ {
+ WithPage(Standard + "starter.batterydefault 7\n", (page, _, saved) =>
+ {
+ var list = List(page, "ReadyOverrideCb");
+ var fileValue = list.SelectedItem;
+ list.SelectedIndex = 1;
+ list.SelectedItem = fileValue;
+
+ page.Save();
+
+ Assert.Contains("starter.batterydefault 7\n", saved());
+ });
+ }
+
+ [Fact]
+ public void A_control_set_by_hand_to_the_default_replaces_a_value_it_could_not_read()
+ {
+ WithPage(Standard + "vsync moze\n", (page, _, saved) =>
+ {
+ Assert.Contains("moze", Note(page, "vsync"));
+ var box = page.FindControl("VSyncCb")!;
+ box.IsChecked = true;
+ box.IsChecked = false;
+
+ page.Save();
+
+ Assert.Contains("vsync no\n", saved());
+ });
+ }
+
+ [Fact]
+ public void A_level_for_other_settings_leaves_a_value_of_the_file_alone()
+ {
+ WithPage(Standard + "starter.batterydefault 7\ngfxrenderer vulkan\n", (page, _, saved) =>
+ {
+ page.FindControl("PresetButtons")!.Children.OfType