public void TestCustomDirectory() { using (var host = new HeadlessGameHost(nameof(TestCustomDirectory))) { string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestCustomDirectory)); // need access before the game has constructed its own storage yet. Storage storage = new DesktopStorage(defaultStorageLocation, host); // manual cleaning so we can prepare a config file. storage.DeleteDirectory(string.Empty); using (var storageConfig = new StorageConfigManager(storage)) storageConfig.Set(StorageConfig.FullPath, customPath); try { var osu = loadOsu(host); // switch to DI'd storage storage = osu.Dependencies.Get <Storage>(); Assert.That(storage.GetFullPath("."), Is.EqualTo(customPath)); } finally { host.Exit(); } } }
public void TestCustomDirectory() { using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestCustomDirectory))) // don't use clean run as we are writing a config file. { string osuDesktopStorage = basePath(nameof(TestCustomDirectory)); const string custom_tournament = "custom"; // need access before the game has constructed its own storage yet. Storage storage = new DesktopStorage(osuDesktopStorage, host); // manual cleaning so we can prepare a config file. storage.DeleteDirectory(string.Empty); using (var storageConfig = new TournamentStorageManager(storage)) storageConfig.SetValue(StorageConfig.CurrentTournament, custom_tournament); try { var osu = loadOsu(host); storage = osu.Dependencies.Get <Storage>(); Assert.That(storage.GetFullPath("."), Is.EqualTo(Path.Combine(host.Storage.GetFullPath("."), "tournaments", custom_tournament))); } finally { host.Exit(); } } }
private void runGameWithLogic(Action <Game> logic, Func <Game, bool> exitCondition = null) { Storage storage = null; try { using (var host = new HeadlessGameHost($"{GetType().Name}-{Guid.NewGuid()}", realtime: false)) { storage = host.Storage; using (var game = new TestGame()) { game.Schedule(() => logic(game)); host.UpdateThread.Scheduler.AddDelayed(() => { if (exitCondition?.Invoke(game) == true) { host.Exit(); } }, 0, true); host.Run(game); } } } finally { storage?.DeleteDirectory(string.Empty); } }
public void CheckIPCLocation() { // don't use clean run because files are being written before osu! launches. using (HeadlessGameHost host = new HeadlessGameHost(nameof(CheckIPCLocation))) { string basePath = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(CheckIPCLocation)); // Set up a fake IPC client for the IPC Storage to switch to. string testStableInstallDirectory = Path.Combine(basePath, "stable-ce"); Directory.CreateDirectory(testStableInstallDirectory); string ipcFile = Path.Combine(testStableInstallDirectory, "ipc.txt"); File.WriteAllText(ipcFile, string.Empty); try { var osu = loadOsu(host); TournamentStorage storage = (TournamentStorage)osu.Dependencies.Get <Storage>(); FileBasedIPC ipc = null; waitForOrAssert(() => (ipc = osu.Dependencies.Get <MatchIPCInfo>() as FileBasedIPC) != null, @"ipc could not be populated in a reasonable amount of time"); Assert.True(ipc.SetIPCLocation(testStableInstallDirectory)); Assert.True(storage.AllTournaments.Exists("stable.json")); } finally { host.Storage.DeleteDirectory(testStableInstallDirectory); host.Storage.DeleteDirectory("tournaments"); host.Exit(); } } }
private void runGameWithLogic(Action <Game> logic, Func <Game, bool> exitCondition = null) { using (var host = new HeadlessGameHost($"test-{Guid.NewGuid()}", realtime: false)) using (var game = new TestGame()) { game.Schedule(() => logic(game)); host.UpdateThread.Scheduler.AddDelayed(() => { if (exitCondition?.Invoke(game) == true) { host.Exit(); } }, 0, true); host.Run(game); } }
public async Task TestSaveAndReload() { using (HeadlessGameHost host = new CleanRunHeadlessGameHost()) { try { var osu = LoadOsuIntoHost(host, true); await importCollectionsFromStream(osu, TestResources.OpenResource("Collections/collections.db")); // Move first beatmap from second collection into the first. osu.CollectionManager.Collections[0].Beatmaps.Add(osu.CollectionManager.Collections[1].Beatmaps[0]); osu.CollectionManager.Collections[1].Beatmaps.RemoveAt(0); // Rename the second collecction. osu.CollectionManager.Collections[1].Name.Value = "Another"; } finally { host.Exit(); } } using (HeadlessGameHost host = new HeadlessGameHost("TestSaveAndReload")) { try { var osu = LoadOsuIntoHost(host, true); Assert.That(osu.CollectionManager.Collections.Count, Is.EqualTo(2)); Assert.That(osu.CollectionManager.Collections[0].Name.Value, Is.EqualTo("First")); Assert.That(osu.CollectionManager.Collections[0].Beatmaps.Count, Is.EqualTo(2)); Assert.That(osu.CollectionManager.Collections[1].Name.Value, Is.EqualTo("Another")); Assert.That(osu.CollectionManager.Collections[1].Beatmaps.Count, Is.EqualTo(11)); } finally { host.Exit(); } } }
private void runGameWithLogic(Action <Game> logic, Func <Game, bool> exitCondition = null) { Storage storage = null; try { using (var host = new HeadlessGameHost($"{GetType().Name}-{Guid.NewGuid()}", realtime: false)) { using (var game = new TestGame()) { game.Schedule(() => { storage = host.Storage; host.UpdateThread.Scheduler.AddDelayed(() => { if (exitCondition?.Invoke(game) == true) { host.Exit(); } }, 0, true); logic(game); }); host.Run(game); } } } finally { try { storage?.DeleteDirectory(string.Empty); } catch { // May fail due to the file handles still being open on Windows, but this isn't a big problem for us } } }
public void TestSubDirectoryLookup() { using (var host = new HeadlessGameHost(nameof(TestSubDirectoryLookup))) { string defaultStorageLocation = Path.Combine(RuntimeInfo.StartupDirectory, "headless", nameof(TestSubDirectoryLookup)); // need access before the game has constructed its own storage yet. Storage storage = new DesktopStorage(defaultStorageLocation, host); // manual cleaning so we can prepare a config file. storage.DeleteDirectory(string.Empty); using (var storageConfig = new StorageConfigManager(storage)) storageConfig.Set(StorageConfig.FullPath, customPath); try { var osu = loadOsu(host); // switch to DI'd storage storage = osu.Dependencies.Get <Storage>(); string actualTestFile = Path.Combine(customPath, "rulesets", "test"); File.WriteAllText(actualTestFile, "test"); var rulesetStorage = storage.GetStorageForDirectory("rulesets"); var lookupPath = rulesetStorage.GetFiles(".").Single(); Assert.That(lookupPath, Is.EqualTo("test")); } finally { host.Exit(); } } }
public void TestMigration() { using (HeadlessGameHost host = new HeadlessGameHost(nameof(TestMigration))) // don't use clean run as we are writing test files for migration. { string osuRoot = basePath(nameof(TestMigration)); string configFile = Path.Combine(osuRoot, "tournament.ini"); if (File.Exists(configFile)) { File.Delete(configFile); } // Recreate the old setup that uses "tournament" as the base path. string oldPath = Path.Combine(osuRoot, "tournament"); string videosPath = Path.Combine(oldPath, "videos"); string modsPath = Path.Combine(oldPath, "mods"); string flagsPath = Path.Combine(oldPath, "flags"); Directory.CreateDirectory(videosPath); Directory.CreateDirectory(modsPath); Directory.CreateDirectory(flagsPath); // Define testing files corresponding to the specific file migrations that are needed string bracketFile = Path.Combine(osuRoot, "bracket.json"); string drawingsConfig = Path.Combine(osuRoot, "drawings.ini"); string drawingsFile = Path.Combine(osuRoot, "drawings.txt"); string drawingsResult = Path.Combine(osuRoot, "drawings_results.txt"); // Define sample files to test recursive copying string videoFile = Path.Combine(videosPath, "video.mp4"); string modFile = Path.Combine(modsPath, "mod.png"); string flagFile = Path.Combine(flagsPath, "flag.png"); File.WriteAllText(bracketFile, "{}"); File.WriteAllText(drawingsConfig, "test"); File.WriteAllText(drawingsFile, "test"); File.WriteAllText(drawingsResult, "test"); File.WriteAllText(videoFile, "test"); File.WriteAllText(modFile, "test"); File.WriteAllText(flagFile, "test"); try { var osu = loadOsu(host); var storage = osu.Dependencies.Get <Storage>(); string migratedPath = Path.Combine(host.Storage.GetFullPath("."), "tournaments", "default"); videosPath = Path.Combine(migratedPath, "videos"); modsPath = Path.Combine(migratedPath, "mods"); flagsPath = Path.Combine(migratedPath, "flags"); videoFile = Path.Combine(videosPath, "video.mp4"); modFile = Path.Combine(modsPath, "mod.png"); flagFile = Path.Combine(flagsPath, "flag.png"); Assert.That(storage.GetFullPath("."), Is.EqualTo(migratedPath)); Assert.True(storage.Exists("bracket.json")); Assert.True(storage.Exists("drawings.txt")); Assert.True(storage.Exists("drawings_results.txt")); Assert.True(storage.Exists("drawings.ini")); Assert.True(storage.Exists(videoFile)); Assert.True(storage.Exists(modFile)); Assert.True(storage.Exists(flagFile)); } finally { host.Storage.Delete("tournament.ini"); host.Storage.DeleteDirectory("tournaments"); host.Exit(); } } }