Пример #1
0
		private static TestResult ComparePngs (Test test, string result_path, string master_path)
		{
			TestResult res;
			
			if (!File.Exists (result_path)) {
				test.SetFailedReason (String.Format ("Can not find results file {0}", result_path));
				return TestResult.Fail;
			}

			if (!File.Exists (master_path)) {
				test.SetToIgnore (String.Format ("Can not find master file {0}", Path.GetFullPath (master_path)));
				return TestResult.Ignore;
			}

			using (Bitmap result = (Bitmap) Image.FromFile (result_path)) {
				using (Bitmap master = (Bitmap) Image.FromFile (master_path)) {
		
					res = CompareBitmaps (test, result, master);
		
					if (res == TestResult.Pass)
						res = EdgeCompare.CompareBitmaps (test, result, master);
		
				}
			}
			
			return res;
		}
Пример #2
0
        private static TestResult ComparePngs(Test test, string result_path, string master_path)
        {
            TestResult res;

            if (!File.Exists(result_path))
            {
                test.SetFailedReason(String.Format("Can not find results file {0}", result_path));
                return(TestResult.Fail);
            }

            if (!File.Exists(master_path))
            {
                test.SetToIgnore(String.Format("Can not find master file {0}", Path.GetFullPath(master_path)));
                return(TestResult.Ignore);
            }

            using (Bitmap result = (Bitmap)Image.FromFile(result_path)) {
                using (Bitmap master = (Bitmap)Image.FromFile(master_path)) {
                    res = CompareBitmaps(test, result, master);

                    if (res == TestResult.Pass)
                    {
                        res = EdgeCompare.CompareBitmaps(test, result, master);
                    }
                }
            }

            return(res);
        }
Пример #3
0
		public static TestResult CompareBitmaps (Test test, Bitmap result, Bitmap master)
		{
			using (Bitmap result_edges = BuildEdges (result)) {
				using (Bitmap master_edges = BuildEdges (master)) {
					using (Bitmap diff = new Bitmap (result.Width, result.Height + KeyHeight)) {
						double point_count = 0;
						double diff_score = 0;
						int missing_points = 0;
						
						using (Graphics g = Graphics.FromImage (diff)) {
							g.DrawImage (master_edges, 0, 0);
						}
						
						for (int x = 0; x < result.Width; x++) {
							
							// Cut off the top/bottom because the blur doesn't work correctly on these rows
							for (int y = 5; y < result.Height - 5; y++) {
								Color rc = result_edges.GetPixel (x, y);
								Color mc = master_edges.GetPixel (x, y);
								
								if (mc.ToArgb () == Color.Black.ToArgb ())
									point_count++;							
								
								if (rc.ToArgb () != mc.ToArgb ()) {
									int severity = PixelDiffSeverity (x, y, result_edges, master_edges);
									
									diff_score += severity;
									if (severity == 20)
										missing_points++;
									
									int red = Math.Min (255, (int) (severity / 10.0 * 255) + 100);
									diff.SetPixel (x, y, Color.FromArgb (red, 255, 0, 0));
								}
							}
						}
						
						AddDiffKey (diff);

						diff.Save (String.Concat (test.LocalFilePath, "-edge-diff.png"), ImageFormat.Png);
						
						if (diff_score / (point_count * 10) > Tolerance) {
							test.SetFailedReason (String.Format ("Edge difference was too great ({0})",
									diff_score / (point_count * 10)));
							return TestResult.Fail;
						}
	
						if (missing_points > MaxMissingPoints) {
							test.SetFailedReason (String.Format ("Too many missing points in edge compare ({0}).", missing_points));
							return TestResult.Fail;
						}
						
					}
				}
			}

			return TestResult.Pass;
		}
Пример #4
0
        private void ProcessTest(Test test)
        {
            TestResult result = TestResult.Pass;

            if (test.CompleteReason == TestCompleteReason.Finished)
            {
                if (logging_server.IsTestResultSet(test.InputFileName))
                {
                    result = logging_server.GetTestResult(test.InputFileName);
                    if (result == TestResult.Fail)
                    {
                        test.SetFailedReason("Test LogResult set to FAIL");
                    }
                }

                if (result == TestResult.Pass)
                {
                    result = test.ComputeImageCompareResult();
                }
            }
            else
            {
                test.SetFailedReason(String.Format("Test did not complete properly ({0})", test.CompleteReason));
                result = TestResult.Fail;
            }

            if (result == TestResult.Pass && test.UnitTest)
            {
                result = test.ProcessUnitTestResult();
            }

            if (test.IsKnownFailure)
            {
                result = (result == TestResult.Pass) ? TestResult.UnexpectedPass : TestResult.KnownFailure;
            }

            RecordResult(test, result);
            reports.ForEach(delegate(IReport report) { report.AddResult(test, result); });

            test.Teardown();
        }
Пример #5
0
        private static TestResult CompareBitmaps(Test test, Bitmap result, Bitmap master)
        {
            double result_norm = CalculateNorm(result);
            double master_norm = CalculateNorm(master);
            double difference  = Math.Max(0, (Math.Abs(result_norm - master_norm) / (result_norm + master_norm + Double.Epsilon)));
            double tolerance   = (test.ImageCompareTolerance != null ? (double)test.ImageCompareTolerance : Tolerance) / 100.0F;

            test.ImageDifference = difference;

            if (difference > tolerance)
            {
                test.SetFailedReason(String.Format("Image difference was too great ({0:P})", difference));
                return(TestResult.Fail);
            }

            return(TestResult.Pass);
        }
Пример #6
0
		public static TestResult Compare (Test test, string result, string master)
		{
			string result_ext = Path.GetExtension (result).ToLower ();
			string master_ext = Path.GetExtension (master).ToLower ();

			if (result_ext != master_ext) {
				test.SetFailedReason (String.Format ("Files {0} and {1} do not have the same extension.", result, master));
				return TestResult.Ignore;
			}

			switch (result_ext) {
			case ".png":
				return ComparePngs (test, result, master);
			case ".tif":
			case ".tiff":
				return CompareTiffs (test, result, master);
			}

			test.SetToIgnore (String.Format ("Unknown file type: {0}", result_ext));
			return TestResult.Ignore;
		}
Пример #7
0
        public static TestResult Compare(Test test, string result, string master)
        {
            string result_ext = Path.GetExtension(result).ToLower();
            string master_ext = Path.GetExtension(master).ToLower();

            if (result_ext != master_ext)
            {
                test.SetFailedReason(String.Format("Files {0} and {1} do not have the same extension.", result, master));
                return(TestResult.Ignore);
            }

            switch (result_ext)
            {
            case ".png":
                return(ComparePngs(test, result, master));

            case ".tif":
            case ".tiff":
                return(CompareTiffs(test, result, master));
            }

            test.SetToIgnore(String.Format("Unknown file type: {0}", result_ext));
            return(TestResult.Ignore);
        }
Пример #8
0
        private static TestResult CompareTiffs(Test test, string result_path, string master_path)
        {
            if (!File.Exists(result_path))
            {
                test.SetFailedReason(String.Format("Can not find results file {0}", result_path));
                return(TestResult.Fail);
            }

            if (!File.Exists(master_path))
            {
                test.SetToIgnore(String.Format("Can not find master file {0}", master_path));
                return(TestResult.Ignore);
            }

            using (Bitmap result = (Bitmap)Image.FromFile(result_path)) {
                using (Bitmap master = (Bitmap)Image.FromFile(master_path)) {
                    Guid [] result_frames = result.FrameDimensionsList;
                    Guid [] master_frames = master.FrameDimensionsList;

                    if (result_frames.Length != master_frames.Length)
                    {
                        test.SetFailedReason(String.Format("Result and Master do not have the same number of layers: result: {0}, master: {1}",
                                                           result_frames.Length, master_frames.Length));
                        return(TestResult.Fail);
                    }

                    for (int i = 0; i < result_frames.Length; i++)
                    {
                        FrameDimension result_dimension    = new FrameDimension(result_frames [0]);
                        FrameDimension master_dimension    = new FrameDimension(master_frames [0]);
                        int            result_frames_count = result.GetFrameCount(result_dimension);
                        int            master_frames_count = master.GetFrameCount(master_dimension);

                        if (result_frames_count != master_frames_count)
                        {
                            test.SetFailedReason(String.Format("Result and Master do not have the same number of frames for frame dimension {0} ({1} vs {2})",
                                                               i, result_frames_count, master_frames_count));
                            return(TestResult.Fail);
                        }

                        for (int f = 0; f < result_frames_count; f++)
                        {
                            result.SelectActiveFrame(result_dimension, f);
                            master.SelectActiveFrame(master_dimension, f);

                            TestResult res = CompareBitmaps(test, result, master);
                            if (res != TestResult.Pass)
                            {
                                test.SetFailedReason(String.Format("Layer {0} -- {1}", f, test.FailedReason));
                                return(res);
                            }

                            res = EdgeCompare.CompareBitmaps(test, result, master);

                            if (res != TestResult.Pass)
                            {
                                test.SetFailedReason(String.Format("Layer {0} -- {1}", f, test.FailedReason));
                                return(res);
                            }
                        }
                    }
                }
            }

            return(TestResult.Pass);
        }
Пример #9
0
		private void ProcessTest (Test test)
		{
			TestResult result = TestResult.Pass;

			if (test.CompleteReason == TestCompleteReason.Finished) {

				if (logging_server.IsTestResultSet (test.InputFileName)) {
					result = logging_server.GetTestResult (test.InputFileName);
					if (result == TestResult.Fail)
						test.SetFailedReason ("Test LogResult set to FAIL");
				}
				
				if (result == TestResult.Pass)
					result = test.ComputeImageCompareResult ();
			} else {
				test.SetFailedReason (String.Format ("Test did not complete properly ({0})", test.CompleteReason));
				result = TestResult.Fail;
			}
			
			if (result == TestResult.Pass && test.UnitTest)
				result = test.ProcessUnitTestResult ();
			
			if (test.IsKnownFailure)
				result = (result == TestResult.Pass) ? TestResult.UnexpectedPass : TestResult.KnownFailure;

			RecordResult (test, result);
			reports.ForEach (delegate (IReport report) { report.AddResult (test, result); });

			test.Teardown ();
		}
Пример #10
0
		private static TestResult CompareTiffs (Test test, string result_path, string master_path)
		{
			if (!File.Exists (result_path)) {
				test.SetFailedReason (String.Format ("Can not find results file {0}", result_path));
				return TestResult.Fail;
			}

			if (!File.Exists (master_path)) {
				test.SetToIgnore (String.Format ("Can not find master file {0}", master_path));
				return TestResult.Ignore;
			}

			using (Bitmap result = (Bitmap) Image.FromFile (result_path)) {
				using (Bitmap master = (Bitmap) Image.FromFile (master_path)) {
					Guid [] result_frames = result.FrameDimensionsList;
					Guid [] master_frames = master.FrameDimensionsList;

					if (result_frames.Length != master_frames.Length) {
						test.SetFailedReason (String.Format ("Result and Master do not have the same number of layers: result: {0}, master: {1}",
									result_frames.Length, master_frames.Length));
						return TestResult.Fail;
					}

					for (int i = 0; i < result_frames.Length; i++) {
						FrameDimension result_dimension = new FrameDimension (result_frames [0]);
						FrameDimension master_dimension = new FrameDimension (master_frames [0]);
						int result_frames_count = result.GetFrameCount (result_dimension);
						int master_frames_count = master.GetFrameCount (master_dimension);
						
						if (result_frames_count != master_frames_count) {
							test.SetFailedReason (String.Format ("Result and Master do not have the same number of frames for frame dimension {0} ({1} vs {2})",
										i, result_frames_count, master_frames_count));
							return TestResult.Fail;
						}

						for (int f = 0; f < result_frames_count; f++) {
							result.SelectActiveFrame (result_dimension, f);
							master.SelectActiveFrame (master_dimension, f);
							
							TestResult res = CompareBitmaps (test, result, master);
							if (res != TestResult.Pass) {
								test.SetFailedReason (String.Format ("Layer {0} -- {1}", f, test.FailedReason));
								return res;
							}
							
							res = EdgeCompare.CompareBitmaps (test, result, master);
							
							if (res != TestResult.Pass) {
								test.SetFailedReason (String.Format ("Layer {0} -- {1}", f, test.FailedReason));
								return res;
							}
						}
					}
				}
			}
			
			return TestResult.Pass;
		}
Пример #11
0
		private static TestResult CompareBitmaps (Test test, Bitmap result, Bitmap master)
		{
			double result_norm = CalculateNorm (result);
			double master_norm = CalculateNorm (master);
			double difference = Math.Max (0, (Math.Abs (result_norm - master_norm) / (result_norm + master_norm + Double.Epsilon)));
			double tolerance = (test.ImageCompareTolerance != null ? (double) test.ImageCompareTolerance : Tolerance) / 100.0F;

			test.ImageDifference = difference;

			if (difference > tolerance) {
				test.SetFailedReason (String.Format ("Image difference was too great ({0:P})", difference));
				return TestResult.Fail;
			}
				
			return TestResult.Pass;
		}
Пример #12
0
        public static TestResult CompareBitmaps(Test test, Bitmap result, Bitmap master)
        {
            using (Bitmap result_edges = BuildEdges(result)) {
                using (Bitmap master_edges = BuildEdges(master)) {
                    using (Bitmap diff = new Bitmap(result.Width, result.Height + KeyHeight)) {
                        double point_count    = 0;
                        double diff_score     = 0;
                        int    missing_points = 0;

                        using (Graphics g = Graphics.FromImage(diff)) {
                            g.DrawImage(master_edges, 0, 0);
                        }

                        for (int x = 0; x < result.Width; x++)
                        {
                            // Cut off the top/bottom because the blur doesn't work correctly on these rows
                            for (int y = 5; y < result.Height - 5; y++)
                            {
                                Color rc = result_edges.GetPixel(x, y);
                                Color mc = master_edges.GetPixel(x, y);

                                if (mc.ToArgb() == Color.Black.ToArgb())
                                {
                                    point_count++;
                                }

                                if (rc.ToArgb() != mc.ToArgb())
                                {
                                    int severity = PixelDiffSeverity(x, y, result_edges, master_edges);

                                    diff_score += severity;
                                    if (severity == 20)
                                    {
                                        missing_points++;
                                    }

                                    int red = Math.Min(255, (int)(severity / 10.0 * 255) + 100);
                                    diff.SetPixel(x, y, Color.FromArgb(red, 255, 0, 0));
                                }
                            }
                        }

                        AddDiffKey(diff);

                        diff.Save(String.Concat(test.LocalFilePath, "-edge-diff.png"), ImageFormat.Png);

                        if (diff_score / (point_count * 10) > Tolerance)
                        {
                            test.SetFailedReason(String.Format("Edge difference was too great ({0})",
                                                               diff_score / (point_count * 10)));
                            return(TestResult.Fail);
                        }

                        if (missing_points > MaxMissingPoints)
                        {
                            test.SetFailedReason(String.Format("Too many missing points in edge compare ({0}).", missing_points));
                            return(TestResult.Fail);
                        }
                    }
                }
            }

            return(TestResult.Pass);
        }