Пример #1
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="image">The image to send.</param>
        /// <param name="testName">The name of the test.</param>
        public void SendImage(Image image, string testName)
        {
            var frame = testName;

            if (frame == null && FrameIndex++ > 0)
            {
                frame = "f" + (FrameIndex - 1);
            }

            // Register 3D card name
            // TODO: This doesn't work well because ImageTester.ImageTestResultConnection is static, this will need improvements
            //if (!ImageTester.ImageTestResultConnection.DeviceName.Contains("_"))
            //    ImageTester.ImageTestResultConnection.DeviceName += "_" + GraphicsDevice.Adapter.Description.Split('\0')[0].TrimEnd(' '); // Workaround for sharpDX bug: Description ends with an series trailing of '\0' characters

#if STRIDE_PLATFORM_WINDOWS_DESKTOP
            var platformSpecific = $"Windows_{GraphicsDevice.Platform}_{GraphicsDevice.Adapter.Description.Split('\0')[0].TrimEnd(' ')}";
#else
            var platformSpecific = string.Empty;
            throw new NotImplementedException();
#endif

            var rootFolder = FindStrideRootFolder();

            var testFilename        = GenerateName(Path.Combine(rootFolder, "tests"), frame, platformSpecific);
            var testFilenamePattern = GenerateName(Path.Combine(rootFolder, "tests"), frame, null);
            testFilenamePattern = Path.Combine(Path.GetDirectoryName(testFilenamePattern), Path.GetFileNameWithoutExtension(testFilenamePattern) + ".*" + Path.GetExtension(testFilenamePattern));
            var testFilenameUser = GenerateName(Path.Combine(rootFolder, @"tests\local"), frame, platformSpecific);

            var testFilenames = new[] { testFilename };

            // First, if exact match doesn't exist, test any other pattern
            // TODO: We might want to sort/filter partially (platform, etc...)?
            if (!File.Exists(testFilename))
            {
                testFilenames = Directory.Exists(Path.GetDirectoryName(testFilenamePattern))
                    ? Directory.GetFiles(Path.GetDirectoryName(testFilenamePattern), Path.GetFileName(testFilenamePattern))
                    : new string[0];
            }

            if (testFilenames.Length == 0)
            {
                // No source image, save this one so that user can later copy it to validated folder
                ImageTester.SaveImage(image, testFilenameUser);
                comparisonMissingMessages.Add($"* {testFilenameUser} (current)");
            }
            else if (!testFilenames.Any(file => ImageTester.CompareImage(image, file)))
            {
                // Comparison failed, save current version so that user can compare/promote it manually
                ImageTester.SaveImage(image, testFilenameUser);
                comparisonFailedMessages.Add($"* {testFilenameUser} (current)");
                foreach (var file in testFilenames)
                {
                    comparisonFailedMessages.Add($"  {file} (reference)");
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Send the data of the test to the server.
        /// </summary>
        /// <param name="image">The image to send.</param>
        /// <param name="testName">The name of the test.</param>
        public void SendImage(Image image, string testName)
        {
            var frame = testName;

            if (frame == null && FrameIndex++ > 0)
            {
                frame = "f" + (FrameIndex - 1);
            }

            // Register 3D card name
            // TODO: This doesn't work well because ImageTester.ImageTestResultConnection is static, this will need improvements
            //if (!ImageTester.ImageTestResultConnection.DeviceName.Contains("_"))
            //    ImageTester.ImageTestResultConnection.DeviceName += "_" + GraphicsDevice.Adapter.Description.Split('\0')[0].TrimEnd(' '); // Workaround for sharpDX bug: Description ends with an series trailing of '\0' characters

            var platformSpecific = GetPlatformSpecificFolder();
            var rootFolder       = FindStrideRootFolder();

            var testFilename     = GenerateTestArtifactFileName(Path.Combine(rootFolder, "tests"), frame, platformSpecific, ".png");
            var testFilenameUser = GenerateTestArtifactFileName(Path.Combine(rootFolder, @"tests\local"), frame, platformSpecific, ".png");

            var testFilenames = new List <string> {
                testFilename
            };

            // First, if exact match doesn't exist, test any other pattern
            // TODO: We might want to sort/filter partially (platform, etc...)?
            var matchingImage = File.Exists(testFilename);

            if (!matchingImage)
            {
                testFilenames.Clear();

                var testFilenamePattern = GenerateTestArtifactFileName(Path.Combine(rootFolder, "tests"), frame, @"*\*", ".png");
                var testFilenameRoot    = testFilenamePattern.Substring(0, testFilenamePattern.IndexOf('*'));
                var testFilenameRegex   = new Regex("^" + Regex.Escape(testFilenamePattern).Replace(@"\*", @"[^\\]*") + "$", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                foreach (var file in Directory.EnumerateFiles(testFilenameRoot, "*.*", SearchOption.AllDirectories))
                {
                    if (testFilenameRegex.IsMatch(file))
                    {
                        testFilenames.Add(file);
                    }
                }
            }

            if (testFilenames.Count == 0)
            {
                // No source image, save this one so that user can later copy it to validated folder
                ImageTester.SaveImage(image, testFilenameUser);
                comparisonMissingMessages.Add($"* {testFilenameUser} (current)");
            }
            else if (!testFilenames.Any(file => ImageTester.CompareImage(image, file)))
            {
                // Comparison failed, save current version so that user can compare/promote it manually
                ImageTester.SaveImage(image, testFilenameUser);
                comparisonFailedMessages.Add($"* {testFilenameUser} (current)");
                foreach (var file in testFilenames)
                {
                    comparisonFailedMessages.Add($"  {file} ({ (matchingImage ? "reference" : "different platform/device") })");
                }
            }
            else
            {
                // If test is a success, let's delete the local file if it was previously generated
                if (File.Exists(testFilenameUser))
                {
                    File.Delete(testFilenameUser);
                }
            }
        }