/// <summary>
        /// Provides a quick and easy way to run a multi-frame visual
        /// test using the default comparison and diff-writing options.
        /// Tests that need more control over the run-diff-assert
        /// process should manually call:
        ///
        /// <code>
        /// Game.Components.Add ($FrameCompareComponent$);
        /// Game.Run ();
        /// WriteFrameDiffs ();
        /// AssertFrameComparisonPassed ();
        /// </code>
        /// </summary>
        /// <param name="captureCount">The total number of frames to
        /// capture.</param>
        /// <param name="captureStride">How often to capture.  A value
        /// of 1 captures every frame, 2 captures every other, etc.
        /// </param>
        /// <param name="similarity">The similarity to the reference
        /// image required for a frame to be considered passing.</param>
        /// <param name="writeDiffs">A value indicating whether visual
        /// diffs should be written for this test.</param>
        protected void RunMultiFrameTest(
            int captureCount,
            int captureStride = 1,
            float similarity  = Constants.StandardRequiredSimilarity,
            bool writeDiffs   = true)
        {
            if (captureCount < 1)
            {
                throw new ArgumentOutOfRangeException(
                          "captureCount", "captureCount must be positive");
            }
            if (captureStride < 1)
            {
                throw new ArgumentOutOfRangeException(
                          "captureStride", "captureStride must be positive");
            }

            if (!Game.Components.Any(x => x is FrameCompareComponent))
            {
                Game.Components.Add(FrameCompareComponent.CreateDefault(
                                        Game,
                                        captureWhen: x => x.DrawNumber % captureStride == 0,
                                        maxFrameNumber: captureCount * captureStride));
            }

            Game.Run(until: x => x.DrawNumber > captureCount * captureStride);
            if (writeDiffs)
            {
                WriteFrameDiffs();
            }
            AssertFrameComparisonPassed(similarity: similarity, expectedCount: captureCount);
        }
Ejemplo n.º 2
0
        public void Draw2D()
        {
            Game.Components.Add (new ClearComponent (Game) { ColorFunction = x => Color.CornflowerBlue });
            Game.Components.Add (new Draw2DComponent (Game));

            var frameComparer = new FrameCompareComponent (
                Game, x => x.DrawNumber % 5 == 0,
                "frame-{0:00}.png",
                Paths.ReferenceImage (Draw2DFolder),
                Paths.CapturedFrame (Draw2DFolder)) {
                { new PixelDeltaFrameComparer(), 1.0f }
                };
            Game.Components.Add(frameComparer);

            Game.ExitCondition = x => x.DrawNumber > 50;
            Game.Run ();

            WriteFrameComparisonDiffs(
                frameComparer.Results,
                Paths.CapturedFrameDiff(Draw2DFolder));
            AssertFrameComparisonResultsPassed (
                frameComparer.Results, Constants.StandardRequiredSimilarity, 10);
        }
Ejemplo n.º 3
0
        //routines to do simple testing of drawing components
        protected void TestComponents(string testImageName,
		                              IGameComponent[] components,
		                              string frameFolder,
		                              int framesToDraw = 1)
        {
            foreach (var component in components)
            {
                Game.Components.Add (component);
            }

            var frameComparer = new FrameCompareComponent (
                Game, x => true,
                testImageName + "-{0:00}.png",
                Paths.ReferenceImage (frameFolder),
                Paths.CapturedFrame (frameFolder)) {
                    { new PixelDeltaFrameComparer (), 1 },
                };
            Game.Components.Add (frameComparer);

            Game.ExitCondition = x => x.DrawNumber > framesToDraw;
            Game.Run ();

            WriteFrameComparisonDiffs (
                frameComparer.Results,
                Paths.CapturedFrameDiff (frameFolder));
            AssertFrameComparisonResultsPassed (
                frameComparer.Results, Constants.StandardRequiredSimilarity, framesToDraw);
        }