public virtual void SetUp()
        {
            game = new TestGameBase();
            gdm  = new GraphicsDeviceManager(game);
#if !XNA
            // We enable the half-pixel offset for XNA compatibility
            gdm.PreferHalfPixelOffset = true;
#endif
            // some visual tests require a HiDef profile
            gdm.GraphicsProfile = GraphicsProfile.HiDef;
            ((IGraphicsDeviceManager)game.Services.GetService(typeof(IGraphicsDeviceManager))).CreateDevice();
            gd      = game.GraphicsDevice;
            content = game.Content;

            _framePrepared  = false;
            _frameSubmitted = false;
            _framesChecked  = false;

            Similarity         = Constants.StandardRequiredSimilarity;
            WriteCapture       = WriteSettings.Always;
            WriteDiffs         = WriteSettings.WhenFailed;
            ExactNumberSubmits = false;
            ClearColor         = Color.CornflowerBlue;

            Paths.SetStandardWorkingDirectory();
        }
Ejemplo n.º 2
0
        public void InitializeEventCount()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var resettingCount = 0;
            var resetCount     = 0;
            var preparingCount = 0;
            var createdCount   = 0;
            var devDispCount   = 0;
            var dispCount      = 0;

            gdm.DeviceResetting         += (s, a) => resettingCount++;
            gdm.DeviceReset             += (s, a) => resetCount++;
            gdm.PreparingDeviceSettings += (s, a) => preparingCount++;
            gdm.DeviceCreated           += (s, a) => createdCount++;
            gdm.DeviceDisposing         += (s, a) => devDispCount++;
            // TODO remove MonoMac
#if !MONOMAC
            gdm.Disposed += (s, a) => dispCount++;
#endif

            game.InitializeOnly();

            Assert.AreEqual(0, resettingCount);
            Assert.AreEqual(0, resetCount);
            Assert.AreEqual(1, preparingCount);
            Assert.AreEqual(1, createdCount);
            Assert.AreEqual(0, devDispCount);
            Assert.AreEqual(0, dispCount);

            game.Dispose();
        }
Ejemplo n.º 3
0
        public void ApplyChangesReturnsWhenNoSetterCalled()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            game.PreInitializeWith += (sender, args) =>
            {
                gdm.PreparingDeviceSettings += (s, a) =>
                {
                    invoked = true;
                };
            };

            game.InitializeOnly();

            gdm.ApplyChanges();
            Assert.IsFalse(invoked);

            // this proves that XNA does not check for equality, but just registers that setters are used
            gdm.PreferredBackBufferWidth = gdm.PreferredBackBufferWidth;

            gdm.ApplyChanges();
            Assert.That(invoked);

            game.Dispose();
        }
Ejemplo n.º 4
0
        public void PreparingDeviceSettingsArgsPresentationParametersAreApplied()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            game.PreInitializeWith += (sender, args) =>
            {
                Assert.AreEqual(RenderTargetUsage.DiscardContents,
                                gdm.GraphicsDevice.PresentationParameters.RenderTargetUsage);

                gdm.PreparingDeviceSettings += (s, a) =>
                {
                    a.GraphicsDeviceInformation.GraphicsProfile = GraphicsProfile.HiDef;
                    a.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;
                    invoked = true;
                };
            };

            game.InitializeOnly();

            // make a change so ApplyChanges actually does something
            gdm.PreferredBackBufferWidth = 100;
            gdm.ApplyChanges();

            Assert.That(invoked);
            Assert.AreEqual(RenderTargetUsage.PreserveContents, gdm.GraphicsDevice.PresentationParameters.RenderTargetUsage);

            game.Dispose();
        }
Ejemplo n.º 5
0
        public void PreparingDeviceSettings()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            gdm.PreparingDeviceSettings += (sender, args) =>
            {
                Assert.NotNull(args.GraphicsDeviceInformation);

                Assert.NotNull(args.GraphicsDeviceInformation.Adapter);
                Assert.AreEqual(GraphicsProfile.Reach, args.GraphicsDeviceInformation.GraphicsProfile);

                var pp = args.GraphicsDeviceInformation.PresentationParameters;
                Assert.NotNull(pp);

                Assert.AreEqual(800, pp.BackBufferWidth);
                Assert.AreEqual(480, pp.BackBufferHeight);
                Assert.AreEqual(SurfaceFormat.Color, pp.BackBufferFormat);
                Assert.AreEqual(DepthFormat.Depth24, pp.DepthStencilFormat);
                Assert.False(pp.IsFullScreen);
                Assert.AreEqual(PresentInterval.One, pp.PresentationInterval);
                Assert.AreEqual(new Rectangle(0, 0, 800, 480), pp.Bounds);
                Assert.AreNotEqual(IntPtr.Zero, pp.DeviceWindowHandle);
                Assert.AreEqual(DisplayOrientation.Default, pp.DisplayOrientation);
                Assert.AreEqual(RenderTargetUsage.DiscardContents, pp.RenderTargetUsage);
                Assert.AreEqual(0, pp.MultiSampleCount);
            };

            game.ExitCondition = x => x.DrawNumber > 1;
            game.Run();
            game.Dispose();
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            _game = new TestGameBase();
            var graphicsDeviceManager = new GraphicsDeviceManager(_game);
#if XNA
            graphicsDeviceManager.ApplyChanges();
#else
            graphicsDeviceManager.CreateDevice();
#endif
        }
        public void Setup()
        {
            _game = new TestGameBase();
            var graphicsDeviceManager = new GraphicsDeviceManager(_game);

#if XNA
            graphicsDeviceManager.ApplyChanges();
#else
            graphicsDeviceManager.CreateDevice();
#endif
        }
        public virtual void TearDown()
        {
            game.Dispose();
            game    = null;
            gdm     = null;
            gd      = null;
            content = null;

            if (_framePrepared && !_framesChecked)
            {
                Assert.Fail("Initialized fixture for rendering but did not check frames.");
            }
        }
Ejemplo n.º 9
0
        public void ApplyChangesResetsDevice()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var count = 0;

            gdm.DeviceReset += (sender, args) => count++;

            game.InitializeOnly();

            gdm.PreferredBackBufferWidth = gdm.PreferredBackBufferWidth;
            gdm.ApplyChanges();
            Assert.AreEqual(1, count);

            game.Dispose();
        }
Ejemplo n.º 10
0
        public void PreparingDeviceSettingsArgsThrowsWhenPPSetToNull()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            gdm.PreparingDeviceSettings += (s, a) =>
            {
                a.GraphicsDeviceInformation.PresentationParameters = null;
                invoked = true;
            };

            Assert.Throws(Is.InstanceOf(typeof(Exception)), () => game.InitializeOnly());
            Assert.That(invoked);

            game.Dispose();
        }
Ejemplo n.º 11
0
        public void DoNotModifyPresentationParametersDirectly()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            game.InitializeWith += (sender, args) =>
            {
                var gd = game.GraphicsDevice;

                var oldpp = gd.PresentationParameters;
                gdm.PreferredBackBufferWidth = 100;
                gdm.ApplyChanges();
                var newpp = gd.PresentationParameters;
                Assert.AreNotSame(oldpp, newpp);
            };

            game.InitializeOnly();
            game.Dispose();
        }
Ejemplo n.º 12
0
        public void PreparingDeviceSettingsEventChangeGraphicsProfile()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            Assert.AreEqual(GraphicsProfile.Reach, gdm.GraphicsProfile);

            game.InitializeOnly();

            var invoked = false;

            gdm.PreparingDeviceSettings += (s, a) =>
            {
                a.GraphicsDeviceInformation.GraphicsProfile = GraphicsProfile.HiDef;
                invoked = true;
            };

            // make sure that changing the graphics profile creates a new device and does not reset
            var creationCount = 0;

            gdm.DeviceCreated += (sender, args) => creationCount++;
            var resetCount = 0;

            gdm.DeviceReset += (sender, args) => resetCount++;

            // make a change so ApplyChanges actually does something
            gdm.PreferredBackBufferWidth = 100;
            gdm.ApplyChanges();

            // assert that PreparingDeviceSettings is invoked, but the GraphicsProfile of the gdm did not change
            Assert.That(invoked);
            Assert.AreEqual(GraphicsProfile.Reach, gdm.GraphicsProfile);
            Assert.AreEqual(GraphicsProfile.HiDef, gdm.GraphicsDevice.GraphicsProfile);

            Assert.AreEqual(creationCount, 1);
            Assert.AreEqual(resetCount, 0);

            game.Dispose();
        }
Ejemplo n.º 13
0
        public void ApplyChangesInvokesPreparingDeviceSettings()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            game.InitializeWith += (sender, args) =>
            {
                gdm.PreparingDeviceSettings += (s, a) =>
                {
                    invoked = true;
                };
            };

            game.InitializeOnly();

            gdm.PreferredBackBufferWidth = gdm.PreferredBackBufferWidth;
            gdm.ApplyChanges();
            Assert.That(invoked);

            game.Dispose();
        }
Ejemplo n.º 14
0
        public void DeviceDisposingInvokedAfterDeviceDisposed()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            var invoked = false;

            gdm.DeviceDisposing += (sender, args) =>
            {
                invoked = true;
                Assert.IsTrue(gdm.GraphicsDevice.IsDisposed);
            };

            game.InitializeOnly();

            Assert.IsFalse(gdm.GraphicsDevice.IsDisposed);
            Assert.IsFalse(invoked);
            // change the graphics profile so the current device needs to be disposed
            gdm.GraphicsProfile = GraphicsProfile.HiDef;
            gdm.ApplyChanges();
            Assert.IsTrue(invoked);

            game.Dispose();
        }
Ejemplo n.º 15
0
        public static void InitializeOrderTest()
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            game.IsFixedTimeStep = false;
            game.ExitCondition   = x => x.UpdateNumber > 1;

            var constructor2        = new InitializeOrderComponent(game);
            var preBaseInitialize2  = new InitializeOrderComponent(game);
            var postBaseInitialize2 = new InitializeOrderComponent(game);
            var loadContent2        = new InitializeOrderComponent(game);
            var update2             = new InitializeOrderComponent(game);
            var constructor         = new InitializeOrderComponent(game)
            {
                ChildComponent = constructor2
            };
            var preBaseInitialize = new InitializeOrderComponent(game)
            {
                ChildComponent = preBaseInitialize2
            };
            var postBaseInitialize = new InitializeOrderComponent(game)
            {
                ChildComponent = postBaseInitialize2
            };
            var loadContent = new InitializeOrderComponent(game)
            {
                ChildComponent = loadContent2
            };
            var update = new InitializeOrderComponent(game)
            {
                ChildComponent = update2
            };

            game.Components.Add(constructor);

            game.PreInitializeWith += (sender, args) =>
            {
                game.Components.Add(preBaseInitialize);
            };
            game.InitializeWith += (sender, args) =>
            {
                game.Components.Add(postBaseInitialize);
            };
            game.PreLoadContentWith += (sender, args) =>
            {
                game.Components.Add(loadContent);
            };
            game.PreUpdateWith += (sender, args) =>
            {
                game.Components.Add(update);
            };
            game.Run();
            game.Dispose();

            Assert.That(constructor.InitOrder == 0);
            Assert.That(preBaseInitialize.InitOrder == 1);
            Assert.That(constructor2.InitOrder == 2);
            Assert.That(preBaseInitialize2.InitOrder == 3);
            Assert.That(update2.InitOrder == 4);
            Assert.That(update.InitOrder == 5);
            Assert.That(postBaseInitialize.InitOrder == -1);
            Assert.That(postBaseInitialize2.InitOrder == -1);
        }
Ejemplo n.º 16
0
        public void MSAAEnabled(bool enabled)
        {
            var game = new TestGameBase();
            var gdm  = new GraphicsDeviceManager(game);

            gdm.PreferMultiSampling = enabled;
            gdm.GraphicsProfile     = GraphicsProfile.HiDef;

            gdm.PreparingDeviceSettings += (sender, args) =>
            {
                var pp = args.GraphicsDeviceInformation.PresentationParameters;
                if (!enabled)
                {
                    Assert.AreEqual(0, pp.MultiSampleCount);
                }
                else
                {
                    Assert.Less(0, pp.MultiSampleCount);
                    pp.MultiSampleCount = 1024;
                }
            };

            Texture2D   tex         = null;
            SpriteBatch spriteBatch = null;

            game.PreInitializeWith += (sender, args) =>
            {
                tex = new Texture2D(game.GraphicsDevice, 1, 1);
                tex.SetData(new[] { Color.White.PackedValue });
                spriteBatch = new SpriteBatch(game.GraphicsDevice);
            };

            game.PreDrawWith += (sender, args) =>
            {
                if (enabled)
                {
                    var pp = game.GraphicsDevice.PresentationParameters;
                    Assert.Less(0, pp.MultiSampleCount);
                    Assert.AreNotEqual(1024, pp.MultiSampleCount);
                }

                game.GraphicsDevice.Clear(Color.Black);

                spriteBatch.Begin();
                spriteBatch.Draw(tex, new Vector2(800 / 2, 480 / 2), null, Color.White, MathHelper.ToRadians(45), new Vector2(0.5f), 200, SpriteEffects.None, 0);
                spriteBatch.End();
            };

#if XNA
            var data = new Color[800 * 480];
            game.DrawWith += (sender, args) =>
            {
                game.GraphicsDevice.GetBackBufferData(data);
            };
#endif

            game.ExitCondition = x => x.DrawNumber > 1;
            game.Run();

#if XNA
            float black = 0;
            float white = 0;
            float grey  = 0;
            foreach (var c in data)
            {
                if (c == Color.Black)
                {
                    ++black;
                }
                else if (c == Color.White)
                {
                    ++white;
                }
                else if (c.R == c.G && c.G == c.B && c.R > 0 && c.R < 255)
                {
                    ++grey;
                }
            }

            // General percentage of black and white pixels we should be getting.
            black /= data.Length;
            white /= data.Length;
            Assert.Less(black, 0.9f);
            Assert.Greater(black, 0.8f);
            Assert.Less(white, 0.2f);
            Assert.Greater(white, 0.1f);

            // If enabled we should have at least a few grey pixels
            // else we should have zero grey pixels.
            grey /= data.Length;
            if (!enabled)
            {
                Assert.AreEqual(0, grey);
            }
            else
            {
                Assert.Less(grey, 0.01f);
                Assert.Greater(grey, 0.001f);
            }
#endif

            tex.Dispose();
            spriteBatch.Dispose();
            game.Dispose();
        }