Skip to content

Commit 3b41c8c

Browse files
authored
Updates to SvgW3CTestRunner (#1132)
* Updates to SvgW3CTestRunner - Fixes exception in pixel difference calculations due to image size difference - Added difference percentage calculations from Svg.UnitTests - Added a test-run dialog to quickly calculation tests in a selected tab - Added buttons to access the search and test-run dialogs * Improvements to the tests-run dialog - it is modeless - exports the tests run - added positive and negative groups to indicate changes from PR to PR - added revisit group: a suggestions of test result to evaluate (whether passing or failing) - double-click or click a button to view the result in main TestRunner
1 parent 41ed0b4 commit 3b41c8c

17 files changed

+8308
-100
lines changed

Tests/Issues/RunTest-3.4.6.xml

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<testrun version="1.0.0.0" date="2024-01-23T05:25:19.8410688+09:00">
3+
<tests category="Passing">
4+
<test name="__AJ_Digital_Camera.svg" exception="false" percent="30.88" />
5+
<test name="__issue-015-01.svg" exception="false" percent="11.92" />
6+
<test name="__issue-016-01.svg" exception="false" percent="7.89" />
7+
<test name="__issue-034-02.svg" exception="false" percent="18.49" />
8+
<test name="__issue-036-01.svg" exception="false" percent="6.87" />
9+
<test name="__issue-064-01.svg" exception="false" percent="5.18" />
10+
<test name="__issue-064-02.svg" exception="false" percent="2.37" />
11+
<test name="__issue-074-01.svg" exception="false" percent="0" />
12+
<test name="__issue-082-01.svg" exception="false" percent="25.95" />
13+
<test name="__issue-083-01.svg" exception="false" percent="10.9" />
14+
<test name="__issue-084-01.svg" exception="false" percent="1.49" />
15+
<test name="__issue-109-01.svg" exception="false" percent="0.61" />
16+
<test name="__issue-1101-01.svg" exception="false" percent="0" />
17+
<test name="__issue-114-01.svg" exception="false" percent="0" />
18+
<test name="__issue-116-01.svg" exception="false" percent="0" />
19+
<test name="__issue-123-01.svg" exception="false" percent="1.04" />
20+
<test name="__issue-129-01.svg" exception="false" percent="2.91" />
21+
<test name="__issue-131-01.svg" exception="false" percent="2.1" />
22+
<test name="__issue-134-01.svg" exception="false" percent="15.48" />
23+
<test name="__issue-143-01.svg" exception="false" percent="0.02" />
24+
<test name="__issue-166-01.svg" exception="false" percent="9.68" />
25+
<test name="__issue-191-01.svg" exception="false" percent="0" />
26+
<test name="__issue-202-01.svg" exception="false" percent="0" />
27+
<test name="__issue-214-01.svg" exception="false" percent="0" />
28+
<test name="__issue-215-01.svg" exception="false" percent="0.77" />
29+
<test name="__issue-223-01.svg" exception="false" percent="1.32" />
30+
<test name="__issue-223-02.svg" exception="false" percent="1.64" />
31+
<test name="__issue-224-01.svg" exception="false" percent="10.13" />
32+
<test name="__issue-227-01.svg" exception="false" percent="0" />
33+
<test name="__issue-227-02.svg" exception="false" percent="0.02" />
34+
<test name="__issue-239-01.svg" exception="false" percent="0" />
35+
<test name="__issue-242-01.svg" exception="false" percent="0.02" />
36+
<test name="__issue-252-01.svg" exception="false" percent="0" />
37+
<test name="__issue-279-01.svg" exception="false" percent="0" />
38+
<test name="__issue-280-01.svg" exception="false" percent="1.97" />
39+
<test name="__issue-280-02.svg" exception="false" percent="4.19" />
40+
<test name="__issue-318-01.svg" exception="false" percent="3.64" />
41+
<test name="__issue-323-02.svg" exception="false" percent="0.55" />
42+
<test name="__issue-323-03.svg" exception="false" percent="1.47" />
43+
<test name="__issue-329-01.svg" exception="false" percent="0" />
44+
<test name="__issue-338-01_stroke_width.svg" exception="false" percent="0.01" />
45+
<test name="__issue-342-01.svg" exception="false" percent="3.08" />
46+
<test name="__issue-345-01.svg" exception="false" percent="0" />
47+
<test name="__issue-354-01.svg" exception="false" percent="0" />
48+
<test name="__issue-363-01.svg" exception="false" percent="1.6" />
49+
<test name="__issue-385-01_Test_text-anchor-middle.svg" exception="false" percent="0.05" />
50+
<test name="__issue-391-01.svg" exception="false" percent="0" />
51+
<test name="__issue-398-01.svg" exception="false" percent="0" />
52+
<test name="__issue-419-01.svg" exception="false" percent="3.31" />
53+
<test name="__issue-436-01.svg" exception="false" percent="2.67" />
54+
<test name="__issue-437-01.svg" exception="false" percent="0" />
55+
<test name="__issue-437-02.svg" exception="false" percent="0" />
56+
<test name="__issue-437-03.svg" exception="false" percent="0" />
57+
<test name="__issue-460-01.svg" exception="false" percent="0" />
58+
<test name="__issue-479-01.svg" exception="false" percent="0" />
59+
<test name="__issue-488-01.svg" exception="false" percent="0" />
60+
<test name="__issue-508-01.svg" exception="false" percent="0" />
61+
<test name="__issue-541-01.svg" exception="false" percent="0" />
62+
<test name="__issue-554-01.svg" exception="false" percent="0" />
63+
<test name="__issue-554-02.svg" exception="false" percent="0" />
64+
<test name="__issue-578-01.svg" exception="false" percent="11.92" />
65+
<test name="__issue-592-01.svg" exception="false" percent="0" />
66+
<test name="__issue-592-02.svg" exception="false" percent="0" />
67+
<test name="__issue-622-01.svg" exception="false" percent="0" />
68+
<test name="__issue-626-01.svg" exception="false" percent="0" />
69+
<test name="__issue-634-01.svg" exception="false" percent="0" />
70+
<test name="__issue-664-01.svg" exception="false" percent="0" />
71+
<test name="__issue-675-01.svg" exception="false" percent="0" />
72+
<test name="__issue-732-01.svg" exception="false" percent="0" />
73+
<test name="__issue-744-01.svg" exception="false" percent="3.1" />
74+
<test name="__issue-747-01.svg" exception="false" percent="0" />
75+
<test name="__issue-755-01.svg" exception="false" percent="0" />
76+
<test name="__issue-758-01.svg" exception="false" percent="0" />
77+
<test name="__issue-769-01.svg" exception="false" percent="0" />
78+
<test name="__issue-785-01.svg" exception="false" percent="0.37" />
79+
<test name="__issue-830-01.svg" exception="false" percent="0" />
80+
<test name="__issue-863-01.svg" exception="false" percent="0" />
81+
<test name="__issue-886-01.svg" exception="false" percent="0" />
82+
<test name="__issue-888-01.svg" exception="false" percent="0" />
83+
<test name="__issue-917-01.svg" exception="false" percent="0" />
84+
<test name="__issue-917-02.svg" exception="false" percent="0" />
85+
<test name="__issue-941-01.svg" exception="false" percent="0" />
86+
<test name="__issue-960-01.svg" exception="false" percent="0" />
87+
<test name="__issue-966-01.svg" exception="false" percent="0" />
88+
<test name="__issue-966-02.svg" exception="false" percent="0" />
89+
<test name="__issue-989-01.svg" exception="false" percent="0" />
90+
<test name="__pull_request-1045-01.svg" exception="false" percent="0" />
91+
<test name="__pull_request-373-01.svg" exception="false" percent="0" />
92+
<test name="__pull_request-374-01.svg" exception="false" percent="0" />
93+
<test name="__pull_request-414-01.svg" exception="false" percent="0" />
94+
<test name="__pull_request-433-01.svg" exception="false" percent="0" />
95+
<test name="__pull_request-444-01.svg" exception="false" percent="0" />
96+
<test name="__pull_request-462-01.svg" exception="false" percent="0" />
97+
<test name="__pull_request-471-01.svg" exception="false" percent="0" />
98+
<test name="__pull_request-492-01.svg" exception="false" percent="0" />
99+
<test name="__pull_request-500-01.svg" exception="false" percent="0" />
100+
<test name="__pull_request-500-02.svg" exception="false" percent="0" />
101+
<test name="__pull_request-504-01.svg" exception="false" percent="0" />
102+
<test name="__pull_request-537-01.svg" exception="false" percent="0" />
103+
<test name="__pull_request-537-02.svg" exception="false" percent="0" />
104+
<test name="__pull_request-551-01.svg" exception="false" percent="0" />
105+
<test name="__pull_request-564-01.svg" exception="false" percent="0" />
106+
<test name="__pull_request-564-02.svg" exception="false" percent="0" />
107+
<test name="__pull_request-575-01.svg" exception="false" percent="0" />
108+
<test name="__pull_request-640-01.svg" exception="false" percent="0" />
109+
<test name="__pull_request-640-02.svg" exception="false" percent="0" />
110+
<test name="__pull_request-642-01.svg" exception="false" percent="0" />
111+
<test name="__pull_request-656-01.svg" exception="false" percent="0" />
112+
<test name="__pull_request-656-02.svg" exception="false" percent="0" />
113+
<test name="__pull_request-658-01.svg" exception="false" percent="0" />
114+
<test name="__pull_request-659-01.svg" exception="false" percent="0" />
115+
<test name="__pull_request-686-01.svg" exception="false" percent="0" />
116+
<test name="__pull_request-690-01.svg" exception="false" percent="0" />
117+
<test name="__pull_request-706-01.svg" exception="false" percent="0" />
118+
<test name="__pull_request-727-01.svg" exception="false" percent="0" />
119+
<test name="__pull_request-873-01.svg" exception="false" percent="0" />
120+
<test name="__pull_request-873-02.svg" exception="false" percent="0" />
121+
<test name="__pull_request-925-01.svg" exception="false" percent="0" />
122+
<test name="__pull_request-925-02.svg" exception="false" percent="0" />
123+
<test name="__pull_request-925-03.svg" exception="false" percent="0" />
124+
<test name="__pull_request-925-04.svg" exception="false" percent="0" />
125+
<test name="__pull_request-925-05.svg" exception="false" percent="0" />
126+
<test name="__pull_request-961-01.svg" exception="false" percent="0" />
127+
<test name="__pull_request-963-01.svg" exception="false" percent="0" />
128+
<test name="__Telefunken_FuBK_test_pattern.svg" exception="false" percent="1.16" />
129+
<test name="__tiger.svg" exception="false" percent="13.66" />
130+
<test name="__title.svg" exception="false" percent="0.31" />
131+
</tests>
132+
<tests category="Failing">
133+
<test name="__issue-084-02.svg" exception="false" percent="12.95" />
134+
<test name="__issue-127-01.svg" exception="false" percent="5.68" />
135+
<test name="__issue-244-01.svg" exception="false" percent="72.32" />
136+
<test name="__issue-247-01.svg" exception="false" percent="65.57" />
137+
<test name="__issue-247-02.svg" exception="false" percent="7.31" />
138+
<test name="__issue-263-01.svg" exception="false" percent="3.69" />
139+
<test name="__issue-315-01.svg" exception="false" percent="50.64" />
140+
<test name="__issue-323-01.svg" exception="false" percent="3.95" />
141+
<test name="__issue-345-02.svg" exception="false" percent="26.9" />
142+
<test name="__issue-362-01.svg" exception="false" percent="11.91" />
143+
<test name="__issue-789-01.svg" exception="false" percent="0.02" />
144+
<test name="__issue-789-02.svg" exception="false" percent="4.64" />
145+
<test name="__issue-789-03.svg" exception="false" percent="0" />
146+
<test name="__text-fonts-06-t.svg" exception="false" percent="0" />
147+
</tests>
148+
</testrun>

Tests/SvgW3CTestRunner/App.ico

172 KB
Binary file not shown.

Tests/SvgW3CTestRunner/BitmapExtensions.cs

+117
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Drawing.Imaging;
33
using System.Drawing;
4+
using System.Drawing.Drawing2D;
45

56
namespace SvgW3CTestRunner
67
{
@@ -61,4 +62,120 @@ public int Reserved
6162
}
6263
}
6364
}
65+
66+
/// <summary>
67+
/// Taken from https://web.archive.org/web/20130111215043/http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
68+
/// and slightly modified.
69+
/// Image width and height, default threshold and handling of alpha values have been adapted.
70+
/// </summary>
71+
static class ExtensionMethods
72+
{
73+
private static readonly int ImageWidth = 64;
74+
private static readonly int ImageHeight = 64;
75+
76+
public static float PercentageDifference(this Image img1, Image img2, byte threshold = 10)
77+
{
78+
byte[,] differences = img1.GetDifferences(img2);
79+
80+
int diffPixels = 0;
81+
82+
foreach (byte b in differences)
83+
{
84+
if (b > threshold) { diffPixels++; }
85+
}
86+
87+
return diffPixels / (float)(differences.GetLength(0) * differences.GetLength(1));
88+
}
89+
90+
public static Bitmap Resize(this Image originalImage, int newWidth, int newHeight)
91+
{
92+
if (originalImage.Width > originalImage.Height)
93+
newWidth = originalImage.Width * newHeight / originalImage.Height;
94+
else
95+
newHeight = originalImage.Height * newWidth / originalImage.Width;
96+
97+
var smallVersion = new Bitmap(newWidth, newHeight);
98+
using (var g = Graphics.FromImage(smallVersion))
99+
{
100+
g.SmoothingMode = SmoothingMode.HighQuality;
101+
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
102+
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
103+
g.DrawImage(originalImage, 0, 0, smallVersion.Width, smallVersion.Height);
104+
}
105+
106+
return smallVersion;
107+
}
108+
109+
public static byte[,] GetGrayScaleValues(this Bitmap img)
110+
{
111+
byte[,] grayScale = new byte[img.Width, img.Height];
112+
113+
for (int y = 0; y < grayScale.GetLength(1); y++)
114+
{
115+
for (int x = 0; x < grayScale.GetLength(0); x++)
116+
{
117+
var alpha = img.GetPixel(x, y).A;
118+
var gray = img.GetPixel(x, y).R;
119+
grayScale[x, y] = (byte)Math.Abs(gray * alpha / 255);
120+
}
121+
}
122+
return grayScale;
123+
}
124+
125+
// the colormatrix needed to grayscale an image
126+
static readonly ColorMatrix ColorMatrix = new ColorMatrix(new float[][]
127+
{
128+
new float[] {.3f, .3f, .3f, 0, 0},
129+
new float[] {.59f, .59f, .59f, 0, 0},
130+
new float[] {.11f, .11f, .11f, 0, 0},
131+
new float[] {0, 0, 0, 1, 0},
132+
new float[] {0, 0, 0, 0, 1}
133+
});
134+
135+
public static Bitmap GetGrayScaleVersion(this Bitmap original)
136+
{
137+
// create a blank bitmap the same size as original
138+
// https://web.archive.org/web/20130111215043/http://www.switchonthecode.com/tutorials/csharp-tutorial-convert-a-color-image-to-grayscale
139+
var newBitmap = new Bitmap(original.Width, original.Height);
140+
141+
// get a graphics object from the new image
142+
using (var g = Graphics.FromImage(newBitmap))
143+
// create some image attributes
144+
using (var attributes = new ImageAttributes())
145+
{
146+
// set the color matrix attribute
147+
attributes.SetColorMatrix(ColorMatrix);
148+
149+
// draw the original image on the new image
150+
// using the grayscale color matrix
151+
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
152+
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
153+
}
154+
155+
return newBitmap;
156+
}
157+
158+
public static byte[,] GetDifferences(this Image img1, Image img2)
159+
{
160+
using (var resizedThisOne = img1.Resize(ImageWidth, ImageHeight))
161+
using (var thisOne = resizedThisOne.GetGrayScaleVersion())
162+
using (var resizedTheOtherOne = img2.Resize(ImageWidth, ImageHeight))
163+
using (var theOtherOne = resizedTheOtherOne.GetGrayScaleVersion())
164+
{
165+
byte[,] differences = new byte[thisOne.Width, thisOne.Height];
166+
byte[,] firstGray = thisOne.GetGrayScaleValues();
167+
byte[,] secondGray = theOtherOne.GetGrayScaleValues();
168+
169+
for (int y = 0; y < differences.GetLength(1); y++)
170+
{
171+
for (int x = 0; x < differences.GetLength(0); x++)
172+
{
173+
differences[x, y] = (byte)Math.Abs(firstGray[x, y] - secondGray[x, y]);
174+
}
175+
}
176+
return differences;
177+
}
178+
}
179+
}
180+
64181
}

Tests/SvgW3CTestRunner/BitmapUtils.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Drawing.Imaging;
22
using System.Drawing;
3+
using System;
34

45
namespace SvgW3CTestRunner
56
{
@@ -10,8 +11,10 @@ internal static class BitmapUtils
1011
#endif
1112
public static unsafe Bitmap PixelDiff(Bitmap a, Bitmap b)
1213
{
13-
Bitmap output = new Bitmap(a.Width, a.Height, PixelFormat.Format32bppArgb);
14-
Rectangle rect = new Rectangle(Point.Empty, a.Size);
14+
var width = Math.Min(a.Width, b.Width);
15+
var height = Math.Min(a.Height, b.Height);
16+
Bitmap output = new Bitmap(width, height, PixelFormat.Format32bppArgb);
17+
Rectangle rect = new Rectangle(Point.Empty, new Size(width, height));
1518
using (var aData = a.LockBitsDisposable(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb))
1619
using (var bData = b.LockBitsDisposable(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb))
1720
using (var outputData = output.LockBitsDisposable(rect, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb))

Tests/SvgW3CTestRunner/ListSearchDialog.Designer.cs

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tests/SvgW3CTestRunner/ListSearchDialog.cs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.ComponentModel;
4-
using System.Data;
5-
using System.Drawing;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
92
using System.Windows.Forms;
103

114
namespace SvgW3CTestRunner
@@ -18,14 +11,12 @@ public partial class ListSearchDialog : Form
1811
public ListSearchDialog()
1912
{
2013
InitializeComponent();
21-
22-
this.Load += OnFormDialogLoad;
2314
}
2415

2516
public int SeletedTabIndex { get => _seletedTabIndex; set => _seletedTabIndex = value; }
2617
public ListBox[] ListItems { get => _listItems; set => _listItems = value; }
2718

28-
private void OnFormDialogLoad(object sender, EventArgs e)
19+
private void OnLoadDialog(object sender, EventArgs e)
2920
{
3021
if (_listItems != null && _listItems.Length == 4)
3122
{

0 commit comments

Comments
 (0)