public void TestUnbindOnDrawableDisposeCached() { // Build cache var drawable = new TestDrawable(); drawable.Dispose(); TestUnbindOnDrawableDispose(); }
public void TestCreateGraphicsDeviceBeforeConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using (IDisposable keeper = service.CreateDevice()) { using (Drawable drawable = new TestDrawable(service)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }
public void TestThrowOnMissingGraphicsDeviceService() { GameServiceContainer container = new GameServiceContainer(); Assert.Throws <InvalidOperationException>( delegate() { using (Drawable drawable = new TestDrawable(container)) { } } ); }
public void TestParentInvalidationFromChildDoesNotReturnPooledParent() { resetWithNewPool(() => new TestPool(TimePerAction, 1)); TestDrawable drawable = null; AddStep("consume item", () => drawable = consumeDrawable(false)); AddStep("add child", () => drawable.AddChild(Empty())); AddAssert("not freed", () => drawable.FreedCount == 0); }
public void TestUsePoolableDrawableWithoutPool() { TestDrawable drawable = null; AddStep("consume item", () => Add(drawable = new TestDrawable())); AddAssert("prepare was run", () => drawable.PreparedCount == 1); AddUntilStep("free was run", () => drawable.FreedCount == 1); AddUntilStep("drawable was disposed", () => drawable.IsDisposed); }
public void TestUnbindOnDrawableDispose() { var drawable = new TestDrawable(); drawable.SetValue(1); Assert.IsTrue(drawable.ValueChanged, "bound correctly"); drawable.Dispose(); drawable.ValueChanged = false; drawable.SetValue(2); Assert.IsFalse(drawable.ValueChanged, "unbound correctly"); }
public void TestCreateFromServiceProvider() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); GameServiceContainer container = new GameServiceContainer(); container.AddService(typeof(IGraphicsDeviceService), service); using (IDisposable keeper = service.CreateDevice()) { using (Drawable drawable = new TestDrawable(container)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }
protected override void UpdateOncePerDraw(GameTime gameTime) { base.UpdateOncePerDraw(gameTime); if (_batchNumber < NumberOfBatches) { for (int i = 0; i < ItemsPerBatch; ++i) { var drawable = new TestDrawable(Game, this, _drawables.Count + 1); _drawables.Add(drawable); Game.Components.Add(drawable); } _batchNumber++; } }
public void TestGraphicsDeviceReset() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using (IDisposable keeper = service.CreateDevice()) { using (TestDrawable drawable = new TestDrawable(service)) { Assert.AreEqual(0, drawable.LoadContentFalseCount); Assert.AreEqual(0, drawable.UnloadContentFalseCount); service.ResetDevice(); Assert.AreEqual(1, drawable.LoadContentFalseCount); Assert.AreEqual(1, drawable.UnloadContentFalseCount); } } }
public void TestPrepareAndFreeMethods() { resetWithNewPool(() => new TestPool(TimePerAction, 1)); TestDrawable drawable = null; TestDrawable drawable2 = null; AddStep("consume item", () => drawable = consumeDrawable()); AddAssert("prepare was run", () => drawable.PreparedCount == 1); AddUntilStep("free was run", () => drawable.FreedCount == 1); AddStep("consume item", () => drawable2 = consumeDrawable()); AddAssert("is same item", () => ReferenceEquals(drawable, drawable2)); AddAssert("prepare was run", () => drawable2.PreparedCount == 2); AddUntilStep("free was run", () => drawable2.FreedCount == 2); }
public void TestPrepareOnlyOnceOnMultipleUsages() { resetWithNewPool(() => new TestPool(TimePerAction, 1)); TestDrawable drawable = null; TestDrawable drawable2 = null; AddStep("consume item", () => drawable = consumeDrawable(false)); AddAssert("prepare was not run", () => drawable.PreparedCount == 0); AddUntilStep("free was not run", () => drawable.FreedCount == 0); AddStep("manually return drawable", () => pool.Return(drawable)); AddUntilStep("free was run", () => drawable.FreedCount == 1); AddStep("consume item", () => drawable2 = consumeDrawable()); AddAssert("is same item", () => ReferenceEquals(drawable, drawable2)); AddAssert("prepare was only run once", () => drawable2.PreparedCount == 1); AddUntilStep("free was run", () => drawable2.FreedCount == 2); }
protected override void Update(GameTime gameTime) { if (_batchNumber < NumberOfBatches && gameTime.TotalGameTime >= TimeSpan.FromSeconds(_batchNumber)) { for (int i = 0; i < ItemsPerBatch; ++i) { var updateable = new TestUpdateable(this); _updateables.Add(updateable); Components.Add(updateable); var drawable = new TestDrawable(this); _drawables.Add(drawable); Components.Add(drawable); } _batchNumber++; } base.Update(gameTime); _updateablesOrderedCorrectly = ListsEqual(_updateables, _updateablesInUpdateOrder); _updateablesInUpdateOrder.Clear(); }
public void TestDrawablePreparedWhenClockRewound() { resetWithNewPool(() => new TestPool(TimePerAction, 1)); TestDrawable drawable = null; AddStep("consume item and rewind clock", () => { var clock = new ManualClock { CurrentTime = Time.Current }; Add(new Container { RelativeSizeAxes = Axes.Both, Clock = new FramedClock(clock), Child = drawable = consumeDrawable(false) }); clock.CurrentTime = 0; }); AddAssert("child prepared", () => drawable.PreparedCount == 1); }
public void TestCreateGraphicsDeviceBeforeConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using(Drawable drawable = new TestDrawable(service)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }
public void TestCreateFromServiceProvider() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); GameServiceContainer container = new GameServiceContainer(); container.AddService(typeof(IGraphicsDeviceService), service); using(IDisposable keeper = service.CreateDevice()) { using(Drawable drawable = new TestDrawable(container)) { Assert.AreSame(drawable.GraphicsDevice, service.GraphicsDevice); } } }
public void TestThrowOnMissingGraphicsDeviceService() { GameServiceContainer container = new GameServiceContainer(); Assert.Throws<InvalidOperationException>( delegate() { using(Drawable drawable = new TestDrawable(container)) { } } ); }
public void TestDraw() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(Drawable drawable = new TestDrawable(service)) { drawable.Draw(new GameTime()); } }
public void TestGraphicsDeviceReset() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using(TestDrawable drawable = new TestDrawable(service)) { Assert.AreEqual(0, drawable.LoadContentFalseCount); Assert.AreEqual(0, drawable.UnloadContentFalseCount); service.ResetDevice(); Assert.AreEqual(1, drawable.LoadContentFalseCount); Assert.AreEqual(1, drawable.UnloadContentFalseCount); } } }
public void TestConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(Drawable drawable = new TestDrawable(service)) { Assert.IsNotNull(drawable); } }