public void TestBenchmark() { BasicGameHost host = new HeadlessGameHost(); host.Add(new Benchmark()); host.Run(); }
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 TestImportOverIPC() { using (HeadlessGameHost host = new HeadlessGameHost("host", true)) using (HeadlessGameHost client = new HeadlessGameHost("client", true)) { Assert.IsTrue(host.IsPrimaryInstance); Assert.IsTrue(!client.IsPrimaryInstance); var osu = loadOsu(host); var temp = prepareTempCopy(osz_path); Assert.IsTrue(File.Exists(temp)); var importer = new BeatmapIPCChannel(client); if (!importer.ImportAsync(temp).Wait(5000)) { Assert.Fail(@"IPC took too long to send"); } ensureLoaded(osu); Assert.IsFalse(File.Exists(temp)); } }
public void TestIpc() { using (var server = new BackgroundGameHeadlessGameHost(@"server", true)) using (var client = new HeadlessGameHost(@"client", true)) { Assert.IsTrue(server.IsPrimaryInstance, @"Server wasn't able to bind"); Assert.IsFalse(client.IsPrimaryInstance, @"Client was able to bind when it shouldn't have been able to"); var serverChannel = new IpcChannel <Foobar>(server); var clientChannel = new IpcChannel <Foobar>(client); void waitAction() { using (var received = new ManualResetEventSlim(false)) { serverChannel.MessageReceived += message => { Assert.AreEqual("example", message.Bar); // ReSharper disable once AccessToDisposedClosure received.Set(); }; clientChannel.SendMessageAsync(new Foobar { Bar = "example" }).Wait(); received.Wait(); } } Assert.IsTrue(Task.Run(waitAction).Wait(10000), @"Message was not received in a timely fashion"); } }
public void TestUnhandledExceptionLogging() { TestException resolvedException = null; void logTest(LogEntry entry) { if (entry.Exception is TestException ex) { Assert.IsNull(resolvedException, "exception was forwarded more than once"); resolvedException = ex; } } Logger.NewEntry += logTest; try { using (var host = new HeadlessGameHost()) { var game = new TestGame(); game.Schedule(() => throw new TestException()); host.Run(game); } } catch { // catch crashing exception } Assert.IsNotNull(resolvedException, "exception wasn't forwarded by logger"); Logger.NewEntry -= logTest; }
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(); } } }
public void TestIpc() { using (var server = new HeadlessGameHost(@"server", true)) using (var client = new HeadlessGameHost(@"client", true)) { Assert.IsTrue(server.IsPrimaryInstance, @"Server wasn't able to bind"); Assert.IsFalse(client.IsPrimaryInstance, @"Client was able to bind when it shouldn't have been able to"); var serverChannel = new IpcChannel <Foobar>(server); var clientChannel = new IpcChannel <Foobar>(client); Action waitAction = () => { bool received = false; serverChannel.MessageReceived += message => { Assert.AreEqual("example", message.Bar); received = true; }; clientChannel.SendMessageAsync(new Foobar { Bar = "example" }).Wait(); while (!received) { Thread.Sleep(1); } }; Assert.IsTrue(waitAction.BeginInvoke(null, null).AsyncWaitHandle.WaitOne(1000), @"Message was not received in a timely fashion"); } }
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(); } } }
public void TestVisualTests() { using (var host = new HeadlessGameHost()) { host.Run(new AutomatedVisualTestGame()); } }
public void TestGameUpdateExceptionNoLogging() { Assert.Throws <TestException>(() => { using (var host = new HeadlessGameHost()) host.Run(new CrashTestGame()); }); }
public override void RunTest() { using (var host = new HeadlessGameHost($"test-{Guid.NewGuid()}", realtime: false)) { host.Storage.DeleteDirectory(string.Empty); host.Run(new OsuTestCaseTestRunner(this)); } }
public void TestBenchmark() { using (var host = new HeadlessGameHost()) { host.Add(new VisualTests.Benchmark()); host.Run(); } }
public void TestGameUnobservedExceptionDoesntCrashGame() { using (var host = new HeadlessGameHost()) { TaskCrashTestGame game = new TaskCrashTestGame(); host.Run(game); } }
public void TestImportWhenClosed() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. using (HeadlessGameHost host = new HeadlessGameHost()) { var osu = loadOsu(host); osu.Dependencies.Get <BeatmapDatabase>().Import(osz_path); ensureLoaded(osu); } }
public void TestImportWhenClosed() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. using (HeadlessGameHost host = new HeadlessGameHost()) { var osu = loadOsu(host); osu.Dependencies.Get<BeatmapDatabase>().Import(osz_path); ensureLoaded(osu); } }
public void TestImportWhenClosed() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. HeadlessGameHost host = new HeadlessGameHost(); var osu = loadOsu(host); osu.Beatmaps.Import(osz_path); ensureLoaded(osu); }
public void TestNonPortableInstall() { Assert.IsFalse(File.Exists(FrameworkConfigManager.FILENAME)); using (var portable = new HeadlessGameHost(@"non-portable")) { portable.Run(new TestGame()); Assert.AreEqual(Path.GetFullPath(Path.Combine(@"headless-non-portable", FrameworkConfigManager.FILENAME)), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); } Assert.IsFalse(File.Exists(FrameworkConfigManager.FILENAME)); }
public void TestVisualTests() { using (var host = new HeadlessGameHost()) { Ruleset.Register(new OsuRuleset()); Ruleset.Register(new TaikoRuleset()); Ruleset.Register(new ManiaRuleset()); Ruleset.Register(new CatchRuleset()); host.Run(new AutomatedVisualTestGame()); } }
public void TestBenchmark() { using (var host = new HeadlessGameHost()) { Ruleset.Register(new OsuRuleset()); Ruleset.Register(new TaikoRuleset()); Ruleset.Register(new ManiaRuleset()); Ruleset.Register(new CatchRuleset()); host.Run(new Benchmark()); } }
public virtual void RunTest() { Storage storage; using (var host = new HeadlessGameHost($"test-{Guid.NewGuid()}", realtime: false)) { storage = host.Storage; host.Run(new TestCaseTestRunner(this)); } // clean up after each run storage.DeleteDirectory(string.Empty); }
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 void TestImportOverIPC() { using (HeadlessGameHost host = new HeadlessGameHost("host", true)) using (HeadlessGameHost client = new HeadlessGameHost("client", true)) { Assert.IsTrue(host.IsPrimaryInstance); Assert.IsTrue(!client.IsPrimaryInstance); var osu = loadOsu(host); var importer = new BeatmapImporter(client); if (!importer.Import(osz_path).Wait(1000)) Assert.Fail(@"IPC took too long to send"); ensureLoaded(osu, 10000); } }
/// <summary> /// Ignore unhandled exceptions for the provided count. /// </summary> /// <param name="ignoreCount">Number of exceptions to ignore.</param> /// <param name="fireCount">How many exceptions to fire.</param> private void runWithIgnoreCount(int ignoreCount, int fireCount) { using (var host = new HeadlessGameHost()) { host.ExceptionThrown += ex => ignoreCount-- > 0; var game = new TestGame(); for (int i = 0; i < fireCount; i++) { game.Schedule(() => throw new TestException()); } game.Schedule(() => game.Exit()); host.Run(game); } }
public void TestImportWhenClosed() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. using (HeadlessGameHost host = new HeadlessGameHost("TestImportWhenClosed")) { var osu = loadOsu(host); var temp = prepareTempCopy(osz_path); Assert.IsTrue(File.Exists(temp)); osu.Dependencies.Get <BeatmapManager>().Import(temp); ensureLoaded(osu); waitForOrAssert(() => !File.Exists(temp), "Temporary file still exists after standard import", 5000); } }
public void TestImportWhenClosed() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. using (HeadlessGameHost host = new HeadlessGameHost()) { var osu = loadOsu(host); var temp = prepareTempCopy(osz_path); Assert.IsTrue(File.Exists(temp)); osu.Dependencies.Get <BeatmapDatabase>().Import(temp); ensureLoaded(osu); Assert.IsFalse(File.Exists(temp)); } }
public void TestPauseResume() { var gameCreated = new ManualResetEventSlim(); var task = Task.Run(() => { using (host = new HeadlessGameHost(@"host", false)) { game = new TestTestGame(); gameCreated.Set(); host.Run(game); } }); Assert.IsTrue(gameCreated.Wait(timeout)); Assert.IsTrue(game.BecameAlive.Wait(timeout)); // check scheduling is working before suspend var completed = new ManualResetEventSlim(); game.Schedule(() => completed.Set()); Assert.IsTrue(completed.Wait(timeout / 10)); host.Suspend(); // in single-threaded execution, the main thread may already be in the process of updating one last time. int gameUpdates = 0; game.Scheduler.AddDelayed(() => ++ gameUpdates, 0, true); Assert.That(() => gameUpdates, Is.LessThan(2).After(timeout / 10)); // check that scheduler doesn't process while suspended.. completed.Reset(); game.Schedule(() => completed.Set()); Assert.IsFalse(completed.Wait(timeout / 10)); // ..and does after resume. host.Resume(); Assert.IsTrue(completed.Wait(timeout / 10)); game.Exit(); Assert.IsTrue(task.Wait(timeout)); }
public void TestImportOverIPC() { HeadlessGameHost host = new HeadlessGameHost("host", true); HeadlessGameHost client = new HeadlessGameHost("client", true); Assert.IsTrue(host.IsPrimaryInstance); Assert.IsTrue(!client.IsPrimaryInstance); var osu = loadOsu(host); var importer = new BeatmapImporter(client); if (!importer.Import(osz_path).Wait(1000)) { Assert.Fail(@"IPC took too long to send"); } ensureLoaded(osu, 10000); }
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(); } } }
public void TestImportWhenFileOpen() { using (HeadlessGameHost host = new HeadlessGameHost("TestImportWhenFileOpen")) { var osu = loadOsu(host); var temp = prepareTempCopy(osz_path); Assert.IsTrue(File.Exists(temp), "Temporary file copy never substantiated"); using (File.OpenRead(temp)) osu.Dependencies.Get <BeatmapManager>().Import(temp); ensureLoaded(osu); File.Delete(temp); Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't"); } }
public void TestImportWhenFileOpen() { //unfortunately for the time being we need to reference osu.Framework.Desktop for a game host here. using (HeadlessGameHost host = new HeadlessGameHost()) { var osu = loadOsu(host); var temp = prepareTempCopy(osz_path); Assert.IsTrue(File.Exists(temp), "Temporary file copy never substantiated"); using (File.OpenRead(temp)) osu.Dependencies.Get <BeatmapManager>().Import(temp); ensureLoaded(osu); File.Delete(temp); Assert.IsFalse(File.Exists(temp), "We likely held a read lock on the file when we shouldn't"); } }
public void TestPauseResume() { var gameCreated = new ManualResetEventSlim(); var task = Task.Run(() => { using (host = new HeadlessGameHost(@"host", false)) { game = new TestTestGame(); gameCreated.Set(); host.Run(game); } }); Assert.IsTrue(gameCreated.Wait(timeout)); Assert.IsTrue(game.BecameAlive.Wait(timeout)); // check scheduling is working before suspend var completed = new ManualResetEventSlim(); game.Schedule(() => completed.Set()); Assert.IsTrue(completed.Wait(timeout / 10)); host.Suspend(); completed.Reset(); // check that scheduler doesn't process while suspended.. game.Schedule(() => completed.Set()); Assert.IsFalse(completed.Wait(timeout / 10)); host.Resume(); // ..and does after resume. Assert.IsTrue(completed.Wait(timeout / 10)); game.Exit(); Assert.IsTrue(task.Wait(timeout)); }