Exemple #1
0
        public static Image <TPixel> GetReferenceOutputImageMultiFrame <TPixel>(
            this ITestImageProvider provider,
            int frameCount,
            object testOutputDetails       = null,
            string extension               = "png",
            bool appendPixelTypeToFileName = true)
            where TPixel : struct, IPixel <TPixel>
        {
            string[] frameFiles = provider.Utility.GetReferenceOutputFileNamesMultiFrame(
                frameCount,
                extension,
                testOutputDetails,
                appendPixelTypeToFileName);

            var temporaryFrameImages = new List <Image <TPixel> >();

            IImageDecoder decoder = TestEnvironment.GetReferenceDecoder(frameFiles[0]);

            foreach (string path in frameFiles)
            {
                if (!File.Exists(path))
                {
                    throw new Exception("Reference output file missing: " + path);
                }

                var tempImage = Image.Load <TPixel>(path, decoder);
                temporaryFrameImages.Add(tempImage);
            }

            Image <TPixel> firstTemp = temporaryFrameImages[0];

            var result = new Image <TPixel>(firstTemp.Width, firstTemp.Height);

            foreach (Image <TPixel> fi in temporaryFrameImages)
            {
                result.Frames.AddFrame(fi.Frames.RootFrame);
                fi.Dispose();
            }

            // Remove the initial empty frame:
            result.Frames.RemoveFrame(0);
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Saves the image only when not running in the CI server.
        /// </summary>
        /// <param name="image">The image</param>
        /// <param name="provider">The image provider</param>
        /// <param name="encoder">The image encoder</param>
        /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
        /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
        public static void DebugSave(
            this Image image,
            ITestImageProvider provider,
            IImageEncoder encoder,
            object testOutputDetails       = null,
            bool appendPixelTypeToFileName = true)
        {
            if (TestEnvironment.RunsOnCI)
            {
                return;
            }

            // We are running locally then we want to save it out
            provider.Utility.SaveTestOutputFile(
                image,
                encoder: encoder,
                testOutputDetails: testOutputDetails,
                appendPixelTypeToFileName: appendPixelTypeToFileName);
        }
 public static Image <TPixel> CompareFirstFrameToReferenceOutput <TPixel>(
     this Image <TPixel> image,
     ImageComparer comparer,
     ITestImageProvider provider,
     FormattableString testOutputDetails,
     string extension = "png",
     bool grayscale   = false,
     bool appendPixelTypeToFileName     = true,
     bool appendSourceFileOrDescription = true)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     return(image.CompareFirstFrameToReferenceOutput(
                comparer,
                provider,
                (object)testOutputDetails,
                extension,
                grayscale,
                appendPixelTypeToFileName,
                appendSourceFileOrDescription));
 }
 /// <summary>
 /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough.
 /// The output file should be named identically to the output produced by <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.
 /// </summary>
 /// <typeparam name="TPixel">The pixel format.</typeparam>
 /// <param name="image">The image which should be compared to the reference image.</param>
 /// <param name="provider">The image provider.</param>
 /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
 /// <param name="extension">The extension</param>
 /// <param name="grayscale">A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size.</param>
 /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
 /// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
 /// <returns>The image.</returns>
 public static Image <TPixel> CompareToReferenceOutput <TPixel>(
     this Image <TPixel> image,
     ITestImageProvider provider,
     object testOutputDetails           = null,
     string extension                   = "png",
     bool grayscale                     = false,
     bool appendPixelTypeToFileName     = true,
     bool appendSourceFileOrDescription = true)
     where TPixel : unmanaged, IPixel <TPixel>
 {
     return(CompareToReferenceOutput(
                image,
                ImageComparer.Tolerant(),
                provider,
                testOutputDetails,
                extension,
                grayscale,
                appendPixelTypeToFileName,
                appendSourceFileOrDescription));
 }
        public static Image <TPixel> DebugSaveMultiFrame <TPixel>(
            this Image <TPixel> image,
            ITestImageProvider provider,
            object testOutputDetails       = null,
            string extension               = "png",
            bool appendPixelTypeToFileName = true)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            if (TestEnvironment.RunsOnCI)
            {
                return(image);
            }

            // We are running locally then we want to save it out
            provider.Utility.SaveTestOutputFileMultiFrame(
                image,
                extension,
                testOutputDetails: testOutputDetails,
                appendPixelTypeToFileName: appendPixelTypeToFileName);
            return(image);
        }
        /// <summary>
        /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough.
        /// The output file should be named identically to the output produced by <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format</typeparam>
        /// <param name="image">The image</param>
        /// <param name="provider">The image provider</param>
        /// <param name="comparer">The <see cref="ImageComparer"/> to use</param>
        /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
        /// <param name="extension">The extension</param>
        /// <param name="grayscale">A boolean indicating whether we should debug save + compare against a grayscale image, smaller in size.</param>
        /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
        /// <returns></returns>
        public static Image <TPixel> CompareToReferenceOutput <TPixel>(
            this Image <TPixel> image,
            ITestImageProvider provider,
            ImageComparer comparer,
            object testOutputDetails       = null,
            string extension               = "png",
            bool grayscale                 = false,
            bool appendPixelTypeToFileName = true)
            where TPixel : struct, IPixel <TPixel>
        {
            using (Image <TPixel> referenceImage = GetReferenceOutputImage <TPixel>(
                       provider,
                       testOutputDetails,
                       extension,
                       appendPixelTypeToFileName))
            {
                comparer.VerifySimilarity(referenceImage, image);
            }

            return(image);
        }
        public static Image <TPixel> DebugSaveMultiFrame <TPixel>(
            this Image <TPixel> image,
            ITestImageProvider provider,
            object testOutputDetails       = null,
            string extension               = "png",
            bool appendPixelTypeToFileName = true)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            if (TestEnvironment.RunsWithCodeCoverage)
            {
                return(image);
            }

            provider.Utility.SaveTestOutputFileMultiFrame(
                image,
                extension,
                testOutputDetails: testOutputDetails,
                appendPixelTypeToFileName: appendPixelTypeToFileName);

            return(image);
        }
        public static Image <TPixel> CompareToReferenceOutputMultiFrame <TPixel>(
            this Image <TPixel> image,
            ITestImageProvider provider,
            ImageComparer comparer,
            object testOutputDetails       = null,
            string extension               = "png",
            bool appendPixelTypeToFileName = true)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> referenceImage = GetReferenceOutputImageMultiFrame <TPixel>(
                       provider,
                       image.Frames.Count,
                       testOutputDetails,
                       extension,
                       appendPixelTypeToFileName))
            {
                comparer.VerifySimilarity(referenceImage, image);
            }

            return(image);
        }
Exemple #9
0
        public static void DebugSave <TPixel>(this Image <TPixel> img, ITestImageProvider provider, object settings = null, string extension = "png")
            where TPixel : struct, IPixel <TPixel>
        {
            string tag = null;

            if (settings is string)
            {
                tag = (string)settings;
            }
            else if (settings != null)
            {
                var properties = settings.GetType().GetRuntimeProperties();

                tag = string.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(settings)).Select(x => $"{x.Key}-{x.Value}"));
            }
            if (!bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCI) || !isCI)
            {
                // we are running locally then we want to save it out
                provider.Utility.SaveTestOutputFile(img, extension, tag: tag);
            }
        }
        public static Image <TPixel> GetReferenceOutputImage <TPixel>(this ITestImageProvider provider,
                                                                      object testOutputDetails           = null,
                                                                      string extension                   = "png",
                                                                      bool appendPixelTypeToFileName     = true,
                                                                      bool appendSourceFileOrDescription = true,
                                                                      IImageDecoder decoder              = null)
            where TPixel : struct, IPixel <TPixel>
        {
            string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(
                extension,
                testOutputDetails,
                appendPixelTypeToFileName,
                appendSourceFileOrDescription);

            if (!File.Exists(referenceOutputFile))
            {
                throw new System.IO.FileNotFoundException("Reference output file missing: " + referenceOutputFile, referenceOutputFile);
            }

            decoder = decoder ?? TestEnvironment.GetReferenceDecoder(referenceOutputFile);

            return(Image.Load <TPixel>(referenceOutputFile, decoder));
        }
        /// <summary>
        /// Saves the image for debugging purpose.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="provider">The image provider.</param>
        /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
        /// <param name="extension">The extension.</param>
        /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
        /// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
        /// <param name="encoder">Custom encoder to use.</param>
        /// <returns>The input image.</returns>
        public static Image DebugSave(
            this Image image,
            ITestImageProvider provider,
            object testOutputDetails           = null,
            string extension                   = "png",
            bool appendPixelTypeToFileName     = true,
            bool appendSourceFileOrDescription = true,
            IImageEncoder encoder              = null)
        {
            if (TestEnvironment.RunsWithCodeCoverage)
            {
                return(image);
            }

            provider.Utility.SaveTestOutputFile(
                image,
                extension,
                testOutputDetails: testOutputDetails,
                appendPixelTypeToFileName: appendPixelTypeToFileName,
                appendSourceFileOrDescription: appendSourceFileOrDescription,
                encoder: encoder);
            return(image);
        }
        /// <summary>
        /// Saves the image only when not running in the CI server.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="provider">The image provider.</param>
        /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
        /// <param name="extension">The extension.</param>
        /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
        /// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
        /// <param name="encoder">Custom encoder to use.</param>
        /// <returns>The input image.</returns>
        public static Image DebugSave(
            this Image image,
            ITestImageProvider provider,
            object testOutputDetails           = null,
            string extension                   = "png",
            bool appendPixelTypeToFileName     = true,
            bool appendSourceFileOrDescription = true,
            IImageEncoder encoder              = null)
        {
            if (TestEnvironment.RunsOnCI)
            {
                return(image);
            }

            // We are running locally then we want to save it out
            provider.Utility.SaveTestOutputFile(
                image,
                extension,
                testOutputDetails: testOutputDetails,
                appendPixelTypeToFileName: appendPixelTypeToFileName,
                appendSourceFileOrDescription: appendSourceFileOrDescription,
                encoder: encoder);
            return(image);
        }
        /// <summary>
        /// Compares the image against the expected Reference output, throws an exception if the images are not similar enough.
        /// The output file should be named identically to the output produced by <see cref="DebugSave{TPixel}(Image{TPixel}, ITestImageProvider, object, string, bool)"/>.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format</typeparam>
        /// <param name="image">The image</param>
        /// <param name="comparer">The <see cref="ImageComparer"/> to use</param>
        /// <param name="provider">The image provider</param>
        /// <param name="testOutputDetails">Details to be concatenated to the test output file, describing the parameters of the test.</param>
        /// <param name="extension">The extension</param>
        /// <param name="appendPixelTypeToFileName">A boolean indicating whether to append the pixel type to the  output file name.</param>
        /// <param name="appendSourceFileOrDescription">A boolean indicating whether to append <see cref="ITestImageProvider.SourceFileOrDescription"/> to the test output file name.</param>
        /// <param name="decoder">A custom decoder.</param>
        /// <returns>The <see cref="Image{TPixel}"/>.</returns>
        public static Image <TPixel> CompareToReferenceOutput <TPixel>(
            this Image <TPixel> image,
            ImageComparer comparer,
            ITestImageProvider provider,
            object testOutputDetails           = null,
            string extension                   = "png",
            bool appendPixelTypeToFileName     = true,
            bool appendSourceFileOrDescription = true,
            IImageDecoder decoder              = null)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            using (Image <TPixel> referenceImage = GetReferenceOutputImage <TPixel>(
                       provider,
                       testOutputDetails,
                       extension,
                       appendPixelTypeToFileName,
                       appendSourceFileOrDescription,
                       decoder))
            {
                comparer.VerifySimilarity(referenceImage, image);
            }

            return(image);
        }
 public static Image <TPixel> CompareToOriginal <TPixel>(
     this Image <TPixel> image,
     ITestImageProvider provider,
     IImageDecoder referenceDecoder = null)
     where TPixel : unmanaged, IPixel <TPixel>
 => CompareToOriginal(image, provider, ImageComparer.Tolerant(), referenceDecoder);
Exemple #15
0
        public static string GetFilePathOrNull(ITestImageProvider provider)
        {
            var fileProvider = provider as FileProvider;

            return(fileProvider?.FilePath);
        }