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 TestVisualTests() { using (var host = new HeadlessGameHost()) { host.Run(new AutomatedVisualTestGame()); } }
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 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 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); } }
/// <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 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 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)); }
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 TestPortableInstall() { Assert.IsFalse(startupStorage.Exists(FrameworkConfigManager.FILENAME)); using (var portable = new HeadlessGameHost(@"portable", portableInstallation: true)) { portable.Run(new TestGame()); Assert.AreEqual(startupStorage.GetFullPath(FrameworkConfigManager.FILENAME), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); } // portable mode should write the configuration Assert.IsTrue(startupStorage.Exists(FrameworkConfigManager.FILENAME)); // subsequent startups should detect the portable config and continue running in portable mode, even though it is not explicitly specified using (var portable = new HeadlessGameHost(@"portable")) { portable.Run(new TestGame()); Assert.AreEqual(startupStorage.GetFullPath(FrameworkConfigManager.FILENAME), portable.Storage.GetFullPath(FrameworkConfigManager.FILENAME)); } Assert.IsTrue(startupStorage.Exists(FrameworkConfigManager.FILENAME)); }
public void TestChildDisposedBeforeGame() { var gameCreated = new ManualResetEventSlim(); var task = Task.Factory.StartNew(() => { using (host = new TestRunHeadlessGameHost("host", new HostOptions(), bypassCleanup: false)) { game = new TestTestGame(); gameCreated.Set(); host.Run(game); } }, TaskCreationOptions.LongRunning); Assert.IsTrue(gameCreated.Wait(timeout)); Assert.IsTrue(game.BecameAlive.Wait(timeout)); var container = new DisposableContainer(); game.Schedule(() => game.Add(container)); Assert.IsTrue(container.BecameAlive.Wait(timeout)); game.Schedule(() => { game.ClearInternal(false); game.DisposeChildAsync(container); }); game.Exit(); Assert.IsTrue(task.Wait(timeout)); game.Dispose(); Assert.IsTrue(container.DisposedSuccessfully.Wait(timeout)); }
public void TestChildDisposedBeforeGame() { 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)); var container = new DisposableContainer(); game.Schedule(() => game.Add(container)); Assert.IsTrue(container.BecameAlive.Wait(timeout)); game.Schedule(() => { game.ClearInternal(false); game.DisposeChildAsync(container); }); game.Exit(); Assert.IsTrue(task.Wait(timeout)); game.Dispose(); Assert.IsTrue(container.DisposedSuccessfully.Wait(timeout)); }
public override void RunTest() { using (var host = new HeadlessGameHost(AppDomain.CurrentDomain.FriendlyName.Replace(' ', '-'), realtime: false)) host.Run(new OsuTestCaseTestRunner(this)); }
public void TestPauseResume(ExecutionMode threadMode) { var gameCreated = new ManualResetEventSlim(); IBindable <GameThreadState> updateThreadState = null; var task = Task.Run(() => { using (host = new ExecutionModeGameHost(@"host", threadMode)) { 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(() => { updateThreadState = host.UpdateThread.State.GetBoundCopy(); updateThreadState.BindValueChanged(state => { if (state.NewValue != GameThreadState.Starting) { Assert.IsTrue(ThreadSafety.IsUpdateThread); } }); completed.Set(); }); Assert.IsTrue(completed.Wait(timeout / 10)); Assert.AreEqual(GameThreadState.Running, updateThreadState.Value); 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)); Assert.AreEqual(GameThreadState.Paused, updateThreadState.Value); // 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)); Assert.AreEqual(GameThreadState.Running, updateThreadState.Value); game.Exit(); Assert.IsTrue(task.Wait(timeout)); Assert.AreEqual(GameThreadState.Exited, updateThreadState.Value); }
public override void RunTest() { using (var host = new HeadlessGameHost()) host.Run(new FrameworkTestCaseTestRunner(this)); }
public override void RunTest() { using (var host = new HeadlessGameHost(realtime: false)) host.Run(new OsuTestCaseTestRunner(this)); }
public virtual void RunTest() { using (var host = new HeadlessGameHost()) host.Run(new TestCaseTestRunner(this)); }