mirror of
https://github.com/MaSzyna-EU07/StarterNG.git
synced 2026-10-30 19:50:28 +01:00
Draw a stand-in for a missing thumbnail, pass the language code to eu07.ini
The file was getting "pl" or "en" whatever the user picked, so a simulator with its own language file started in English.
This commit is contained in:
76
StarterNG.Tests/MiniTextureIndexTests.cs
Normal file
76
StarterNG.Tests/MiniTextureIndexTests.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using StarterNG.Infrastructure.Adapters;
|
||||
using StarterNG.Infrastructure.Vehicles;
|
||||
using StarterNG.Tests.Fakes;
|
||||
|
||||
namespace StarterNG.Tests;
|
||||
|
||||
public class MiniTextureIndexTests
|
||||
{
|
||||
private static readonly string[] Names =
|
||||
{
|
||||
"ep07", "et22", "111a", "112a", "203v", "401k", "en57", "sm42", "st44", "412w",
|
||||
"406r", "424z", "621z", "z1kd", "gags", "eaos", "falns", "uacs", "sgs", "kbs"
|
||||
};
|
||||
|
||||
private static MiniTextureIndex Build(int missRate)
|
||||
{
|
||||
var files = new InMemoryFileSystem();
|
||||
foreach (string name in Names)
|
||||
files.WithFile(TestInstallation.At("textures", "mini", name + ".bmp"), "bitmap");
|
||||
files.WithFile(TestInstallation.At("textures", "mini", "other.bmp"), "bitmap");
|
||||
|
||||
var environment = new FakeEnvironment();
|
||||
if (missRate > 0)
|
||||
environment.With(MiniTextureIndex.MissRateVariable, missRate.ToString());
|
||||
|
||||
return new MiniTextureIndex(files, new GamePaths(TestInstallation.Root), environment);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Without_the_debug_variable_every_thumbnail_loads()
|
||||
{
|
||||
var index = Build(missRate: 0);
|
||||
|
||||
Assert.Equal(0, index.SimulatedMissRate);
|
||||
Assert.All(Names, name => Assert.True(index.Has(name)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_debug_variable_hides_roughly_the_share_it_names()
|
||||
{
|
||||
var index = Build(missRate: 50);
|
||||
|
||||
int hidden = Names.Count(name => !index.Has(name));
|
||||
|
||||
// Twenty names is a small sample, so this only asserts that the switch
|
||||
// bites and does not take everything with it.
|
||||
Assert.InRange(hidden, 3, Names.Length - 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_hidden_thumbnail_stays_hidden_rather_than_flickering()
|
||||
{
|
||||
var index = Build(missRate: 50);
|
||||
string hidden = Names.First(name => !index.Has(name));
|
||||
|
||||
for (int i = 0; i < 20; i++)
|
||||
Assert.False(index.Has(hidden));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_hidden_thumbnail_falls_back_to_other_bmp_like_an_unknown_one()
|
||||
{
|
||||
var index = Build(missRate: 50);
|
||||
string hidden = Names.First(name => !index.Has(name));
|
||||
|
||||
Assert.EndsWith("other.bmp", index.PathFor(hidden));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_unknown_name_still_falls_back_to_other_bmp_in_a_normal_run()
|
||||
{
|
||||
var index = Build(missRate: 0);
|
||||
|
||||
Assert.EndsWith("other.bmp", index.PathFor("nie-ma-takiej"));
|
||||
}
|
||||
}
|
||||
@@ -26,11 +26,50 @@ public class SettingsStoreTests
|
||||
Assert.Equal(1920, settings.Width);
|
||||
Assert.Equal(1080, settings.Height);
|
||||
Assert.True(settings.Fullscreen);
|
||||
Assert.Equal("Polski", settings.Language);
|
||||
Assert.Equal("pl", settings.LanguageCode);
|
||||
Assert.True(settings.LanguageWasSet);
|
||||
Assert.Equal(UserIni, installation.SettingsStore.LoadedFrom);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_language_the_starter_does_not_ship_survives_a_round_trip()
|
||||
{
|
||||
// A user-supplied translation must reach the simulator as written; folding
|
||||
// every unknown code into "en" is what forced eu07.exe into English.
|
||||
var installation = WithHome(new InMemoryFileSystem().WithFile(UserIni, "lang zh\n"));
|
||||
installation.SettingsStore.Load();
|
||||
|
||||
Assert.Equal("zh", installation.SettingsStore.Settings.LanguageCode);
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Contains("lang zh", installation.Files.ReadAllText(UserIni));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_language_chosen_in_the_picker_is_written_as_its_own_code()
|
||||
{
|
||||
var installation = WithHome();
|
||||
installation.SettingsStore.Load();
|
||||
installation.SettingsStore.Settings.Language = "中文";
|
||||
installation.SettingsStore.Settings.LanguageCode = "zh";
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Contains("lang zh", installation.Files.ReadAllText(UserIni));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void With_no_language_recorded_the_file_still_names_one()
|
||||
{
|
||||
var installation = WithHome();
|
||||
installation.SettingsStore.Load();
|
||||
|
||||
installation.SettingsStore.Save();
|
||||
|
||||
Assert.Contains("lang en", installation.Files.ReadAllText(UserIni));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_first_run_falls_back_to_the_ini_shipped_with_the_installation()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user