#region CPL License /* Nuclex Framework Copyright (C) 2002-2009 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #endregion #if UNITTEST using System; using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using NUnit.Framework; using Nuclex.Testing.Xna; namespace Nuclex.Graphics.Batching { /// Unit tests for the Effect drawing context [TestFixture] internal class EffectDrawContextTest { #region class TestDrawContext /// Drawing context used for the unit test private class TestDrawContext : DrawContext { /// Number of passes this draw context requires for rendering public override int Passes { get { return 123; } } /// Prepares the graphics device for drawing /// Index of the pass to begin rendering /// /// Should only be called between the normal Begin() and End() methods. /// public override void Apply(int pass) { } /// Tests whether another draw context is identical to this one /// Other context to check for equality /// True if the other context is identical to this one public override bool Equals(DrawContext otherContext) { return ReferenceEquals(this, otherContext); } } #endregion // class TestDrawContext #region class TestEffectDrawContext /// Drawing context used for the unit test private class TestEffectDrawContext : EffectDrawContext { /// Initializes a new test effect drawing context /// Effect that will be used for testing public TestEffectDrawContext(Effect effect) : base(effect) { } } #endregion // class TestEffectDrawContext /// Verifies that the constructor of the drawing context is working [Test] public void TestConstructor() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using (BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.GreaterOrEqual(test.Passes, 1); } } } /// /// Verifies that the Begin() and End() methods of the drawing context are working /// as expected /// [Test] public void TestBeginEnd() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using (BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); for (int pass = 0; pass < test.Passes; ++pass) { test.Apply(pass); } } } } /// /// Verifies that the used effect can be obtained using the 'Effect' property /// [Test] public void TestEffectRetrieval() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using (BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.AreSame(effect, test.Effect); } } } /// /// Verifies that testing the drawing context against itself results in /// the comparison reporting equality /// [Test] public void TestEqualsWithSameObject() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using (BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test = new TestEffectDrawContext(effect); Assert.IsTrue(test.Equals((object)test)); } } } /// /// Verifies that testing the drawing context against a different instance /// results the comparison reporting inequality /// [Test] public void TestEqualsWithDifferentObject() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using (BasicEffect effect1 = new BasicEffect(service.GraphicsDevice)) { using (BasicEffect effect2 = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test1 = new TestEffectDrawContext(effect1); TestEffectDrawContext test2 = new TestEffectDrawContext(effect2); Assert.IsFalse(test1.Equals((object)test2)); } } } } /// /// Verifies that testing the drawing context against an instance of a different /// drawing context is reported as inequality /// [Test] public void TestEqualsWithIncpmpatibleDrawContext() { MockedGraphicsDeviceService service = new MockedGraphicsDeviceService(); using(IDisposable keeper = service.CreateDevice()) { using (BasicEffect effect = new BasicEffect(service.GraphicsDevice)) { TestEffectDrawContext test1 = new TestEffectDrawContext(effect); TestDrawContext test2 = new TestDrawContext(); Assert.IsFalse(test1.Equals((object)test2)); } } } } } // namespace Nuclex.Graphics #endif // UNITTEST