Skip to content

Commit 135e086

Browse files
author
Dirk Lemstra
committed
Added extra unit tests.
1 parent 34a8fb1 commit 135e086

12 files changed

+285
-5
lines changed

Source/Magick.NET/Core/Drawables/Paths/PathQuadraticCurveToRel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public PathQuadraticCurveToRel(PointD controlPoint, PointD end)
5454
void IPath.Draw(IDrawingWand wand)
5555
{
5656
if (wand != null)
57-
wand.PathQuadraticCurveToAbs(_ControlPoint, _End);
57+
wand.PathQuadraticCurveToRel(_ControlPoint, _End);
5858
}
5959
}
6060
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
//=================================================================================================
2+
// Copyright 2013-2016 Dirk Lemstra <https://magick.codeplex.com/>
3+
//
4+
// Licensed under the ImageMagick License (the "License"); you may not use this file except in
5+
// compliance with the License. You may obtain a copy of the License at
6+
//
7+
// http://www.imagemagick.org/script/license.php
8+
//
9+
// Unless required by applicable law or agreed to in writing, software distributed under the
10+
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
//=================================================================================================
14+
15+
using ImageMagick;
16+
using Microsoft.VisualStudio.TestTools.UnitTesting;
17+
18+
namespace Magick.NET.Tests
19+
{
20+
[TestClass]
21+
public partial class DrawableAffineTests
22+
{
23+
[TestMethod]
24+
public void Test_Reset()
25+
{
26+
DrawableAffine affine = new DrawableAffine();
27+
28+
Assert.AreEqual(1.0, affine.ScaleX);
29+
Assert.AreEqual(1.0, affine.ScaleY);
30+
Assert.AreEqual(0.0, affine.ShearX);
31+
Assert.AreEqual(0.0, affine.ShearY);
32+
Assert.AreEqual(0.0, affine.TranslateX);
33+
Assert.AreEqual(0.0, affine.TranslateY);
34+
35+
affine.ScaleX = 2.0;
36+
Assert.AreEqual(2.0, affine.ScaleX);
37+
Assert.AreEqual(1.0, affine.ScaleY);
38+
Assert.AreEqual(0.0, affine.ShearX);
39+
Assert.AreEqual(0.0, affine.ShearY);
40+
Assert.AreEqual(0.0, affine.TranslateX);
41+
Assert.AreEqual(0.0, affine.TranslateY);
42+
43+
affine.ScaleY = 3.0;
44+
Assert.AreEqual(2.0, affine.ScaleX);
45+
Assert.AreEqual(3.0, affine.ScaleY);
46+
Assert.AreEqual(0.0, affine.ShearX);
47+
Assert.AreEqual(0.0, affine.ShearY);
48+
Assert.AreEqual(0.0, affine.TranslateX);
49+
Assert.AreEqual(0.0, affine.TranslateY);
50+
51+
affine.ShearX = 4.0;
52+
Assert.AreEqual(2.0, affine.ScaleX);
53+
Assert.AreEqual(3.0, affine.ScaleY);
54+
Assert.AreEqual(4.0, affine.ShearX);
55+
Assert.AreEqual(0.0, affine.ShearY);
56+
Assert.AreEqual(0.0, affine.TranslateX);
57+
Assert.AreEqual(0.0, affine.TranslateY);
58+
59+
affine.ShearY = 5.0;
60+
Assert.AreEqual(2.0, affine.ScaleX);
61+
Assert.AreEqual(3.0, affine.ScaleY);
62+
Assert.AreEqual(4.0, affine.ShearX);
63+
Assert.AreEqual(5.0, affine.ShearY);
64+
Assert.AreEqual(0.0, affine.TranslateX);
65+
Assert.AreEqual(0.0, affine.TranslateY);
66+
67+
affine.TranslateX = 6.0;
68+
Assert.AreEqual(2.0, affine.ScaleX);
69+
Assert.AreEqual(3.0, affine.ScaleY);
70+
Assert.AreEqual(4.0, affine.ShearX);
71+
Assert.AreEqual(5.0, affine.ShearY);
72+
Assert.AreEqual(6.0, affine.TranslateX);
73+
Assert.AreEqual(0.0, affine.TranslateY);
74+
75+
affine.TranslateY = 7.0;
76+
Assert.AreEqual(2.0, affine.ScaleX);
77+
Assert.AreEqual(3.0, affine.ScaleY);
78+
Assert.AreEqual(4.0, affine.ShearX);
79+
Assert.AreEqual(5.0, affine.ShearY);
80+
Assert.AreEqual(6.0, affine.TranslateX);
81+
Assert.AreEqual(7.0, affine.TranslateY);
82+
83+
affine.Reset();
84+
Assert.AreEqual(1.0, affine.ScaleX);
85+
Assert.AreEqual(1.0, affine.ScaleY);
86+
Assert.AreEqual(0.0, affine.ShearX);
87+
Assert.AreEqual(0.0, affine.ShearY);
88+
Assert.AreEqual(0.0, affine.TranslateX);
89+
Assert.AreEqual(0.0, affine.TranslateY);
90+
}
91+
92+
[TestMethod]
93+
public void Test_TransformOrigin()
94+
{
95+
DrawableAffine affine = new DrawableAffine();
96+
affine.TransformOrigin(4.0, 2.0);
97+
98+
Assert.AreEqual(1.0, affine.ScaleX);
99+
Assert.AreEqual(1.0, affine.ScaleY);
100+
Assert.AreEqual(0.0, affine.ShearX);
101+
Assert.AreEqual(0.0, affine.ShearY);
102+
Assert.AreEqual(4.0, affine.TranslateX);
103+
Assert.AreEqual(2.0, affine.TranslateY);
104+
}
105+
106+
[TestMethod]
107+
public void Test_TransformRatation()
108+
{
109+
DrawableAffine affine = new DrawableAffine();
110+
affine.TransformRotation(45.0);
111+
112+
Assert.AreEqual(0.7071, affine.ScaleX, 0.0001);
113+
Assert.AreEqual(0.7071, affine.ScaleY, 0.0001);
114+
Assert.AreEqual(-0.7071, affine.ShearX, 0.0001);
115+
Assert.AreEqual(0.7071, affine.ShearY, 0.0001);
116+
Assert.AreEqual(0.0, affine.TranslateX);
117+
Assert.AreEqual(0.0, affine.TranslateY);
118+
}
119+
120+
[TestMethod]
121+
public void Test_TransformScale()
122+
{
123+
DrawableAffine affine = new DrawableAffine();
124+
affine.TransformScale(4.0, 2.0);
125+
126+
Assert.AreEqual(4.0, affine.ScaleX);
127+
Assert.AreEqual(2.0, affine.ScaleY);
128+
Assert.AreEqual(0.0, affine.ShearX);
129+
Assert.AreEqual(0.0, affine.ShearY);
130+
Assert.AreEqual(0.0, affine.TranslateX);
131+
Assert.AreEqual(0.0, affine.TranslateY);
132+
}
133+
134+
[TestMethod]
135+
public void Test_TransformSkew()
136+
{
137+
DrawableAffine affine = new DrawableAffine();
138+
affine.TransformSkewX(4.0);
139+
140+
Assert.AreEqual(1.0, affine.ScaleX);
141+
Assert.AreEqual(1.0, affine.ScaleY);
142+
Assert.AreEqual(0.0699, affine.ShearX, 0.0001);
143+
Assert.AreEqual(0.0, affine.ShearY);
144+
Assert.AreEqual(0.0, affine.TranslateX);
145+
Assert.AreEqual(0.0, affine.TranslateY);
146+
147+
affine.TransformSkewY(2.0);
148+
149+
Assert.AreEqual(1.0, affine.ScaleX);
150+
Assert.AreEqual(1.0024, affine.ScaleY, 0.0001);
151+
Assert.AreEqual(0.0699, affine.ShearX, 0.0001);
152+
Assert.AreEqual(0.0349, affine.ShearY, 0.0001);
153+
Assert.AreEqual(0.0, affine.TranslateX);
154+
Assert.AreEqual(0.0, affine.TranslateY);
155+
}
156+
}
157+
}

Tests/Magick.NET.Tests/Core/Drawables/DrawableDensityTests.cs

+8
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,13 @@ public void Test_ImageSize()
5151
Assert.AreEqual(24, image.Height);
5252
}
5353
}
54+
55+
[TestMethod]
56+
public void Test_Constructor()
57+
{
58+
DrawableDensity density = new DrawableDensity(new PointD(4, 2));
59+
Assert.AreEqual(4, density.Density.X);
60+
Assert.AreEqual(2, density.Density.Y);
61+
}
5462
}
5563
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//=================================================================================================
2+
// Copyright 2013-2016 Dirk Lemstra <https://magick.codeplex.com/>
3+
//
4+
// Licensed under the ImageMagick License (the "License"); you may not use this file except in
5+
// compliance with the License. You may obtain a copy of the License at
6+
//
7+
// http://www.imagemagick.org/script/license.php
8+
//
9+
// Unless required by applicable law or agreed to in writing, software distributed under the
10+
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
//=================================================================================================
14+
15+
using ImageMagick;
16+
using Microsoft.VisualStudio.TestTools.UnitTesting;
17+
using System.Linq;
18+
19+
namespace Magick.NET.Tests
20+
{
21+
[TestClass]
22+
public class DrawablePathTests
23+
{
24+
[TestMethod]
25+
public void Test_DrawablePath()
26+
{
27+
DrawablePath path = new DrawablePath();
28+
Assert.AreEqual(0, path.Paths.Count());
29+
30+
((IDrawable)path).Draw(null);
31+
}
32+
}
33+
}

Tests/Magick.NET.Tests/Core/Drawables/DrawableTests.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Text;
1717
using ImageMagick;
1818
using Microsoft.VisualStudio.TestTools.UnitTesting;
19+
using System.Linq;
1920

2021
namespace Magick.NET.Tests
2122
{
@@ -40,7 +41,11 @@ public void Test_Drawables()
4041
image.Draw(new DrawableAffine(0, 0, 1, 1, 2, 2));
4142
image.Draw(new DrawableAlpha(0, 0, PaintMethod.Floodfill));
4243
image.Draw(new DrawableArc(0, 0, 10, 10, 45, 90));
43-
image.Draw(new DrawableBezier(coordinates));
44+
45+
var bezier = new DrawableBezier(coordinates.ToList());
46+
Assert.AreEqual(3, bezier.Coordinates.Count());
47+
image.Draw(bezier);
48+
4449
image.Draw(new DrawableBorderColor(MagickColors.Fuchsia));
4550
image.Draw(new DrawableCircle(0, 0, 50, 50));
4651
image.Draw(new DrawableClipPath("foo"));
@@ -61,13 +66,16 @@ public void Test_Drawables()
6166
image.Draw(new DrawableFillColor(MagickColors.Red));
6267
image.Draw(new DrawableFillOpacity(new Percentage(50)));
6368
image.Draw(new DrawableFillRule(FillRule.EvenOdd));
69+
image.Draw(new DrawableFont("Arial.ttf"));
6470
image.Draw(new DrawableFont("Arial"));
6571
image.Draw(new DrawableGravity(Gravity.Center));
6672
image.Draw(new DrawableLine(20, 20, 40, 40));
6773
image.Draw(new DrawablePoint(60, 60));
6874
image.Draw(new DrawableFontPointSize(5));
6975
image.Draw(new DrawablePolygon(coordinates));
76+
image.Draw(new DrawablePolygon(coordinates.ToList()));
7077
image.Draw(new DrawablePolyline(coordinates));
78+
image.Draw(new DrawablePolyline(coordinates.ToList()));
7179
image.Draw(new DrawableRectangle(30, 30, 70, 70));
7280
image.Draw(new DrawableRotation(180));
7381
image.Draw(new DrawableRoundRectangle(50, 50, 30, 30, 70, 70));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//=================================================================================================
2+
// Copyright 2013-2016 Dirk Lemstra <https://magick.codeplex.com/>
3+
//
4+
// Licensed under the ImageMagick License (the "License"); you may not use this file except in
5+
// compliance with the License. You may obtain a copy of the License at
6+
//
7+
// http://www.imagemagick.org/script/license.php
8+
//
9+
// Unless required by applicable law or agreed to in writing, software distributed under the
10+
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
//=================================================================================================
14+
15+
using ImageMagick;
16+
using Microsoft.VisualStudio.TestTools.UnitTesting;
17+
using System.Text;
18+
19+
namespace Magick.NET.Tests
20+
{
21+
[TestClass]
22+
public partial class DrawableTextEncodingTests
23+
{
24+
[TestMethod]
25+
public void Test_Encoding()
26+
{
27+
DrawableTextEncoding encoding = new DrawableTextEncoding(Encoding.UTF8);
28+
encoding.Encoding = null;
29+
30+
using (MagickImage image = new MagickImage(MagickColors.Firebrick, 10, 10))
31+
{
32+
image.Draw(encoding);
33+
}
34+
}
35+
}
36+
}

Tests/Magick.NET.Tests/Core/Drawables/DrawablesTests.cs

+29-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
using ImageMagick;
1616
using Microsoft.VisualStudio.TestTools.UnitTesting;
17+
using System;
18+
using System.Collections;
1719

1820
namespace Magick.NET.Tests
1921
{
@@ -25,15 +27,40 @@ public void Test_Draw()
2527
{
2628
using (MagickImage image = new MagickImage(MagickColors.Fuchsia, 100, 100))
2729
{
28-
image.Draw(new Drawables()
30+
Drawables drawables = new Drawables()
2931
.FillColor(MagickColors.Red)
30-
.Rectangle(10, 10, 90, 90));
32+
.Rectangle(10, 10, 90, 90);
33+
34+
IEnumerator enumerator = ((IEnumerable)drawables).GetEnumerator();
35+
Assert.IsTrue(enumerator.MoveNext());
36+
37+
drawables.Draw(image);
3138

3239
ColorAssert.AreEqual(MagickColors.Fuchsia, image, 9, 9);
3340
ColorAssert.AreEqual(MagickColors.Red, image, 10, 10);
3441
ColorAssert.AreEqual(MagickColors.Red, image, 90, 90);
3542
ColorAssert.AreEqual(MagickColors.Fuchsia, image, 91, 91);
43+
44+
image.Draw(new Drawables()
45+
.FillColor(MagickColors.Green)
46+
.Rectangle(15, 15, 85, 85));
47+
48+
ColorAssert.AreEqual(MagickColors.Fuchsia, image, 9, 9);
49+
ColorAssert.AreEqual(MagickColors.Red, image, 10, 10);
50+
ColorAssert.AreEqual(MagickColors.Green, image, 15, 15);
51+
ColorAssert.AreEqual(MagickColors.Green, image, 85, 85);
52+
ColorAssert.AreEqual(MagickColors.Red, image, 90, 90);
53+
ColorAssert.AreEqual(MagickColors.Fuchsia, image, 91, 91);
3654
}
3755
}
56+
57+
[TestMethod]
58+
public void Test_Exceptions()
59+
{
60+
ExceptionAssert.Throws<ArgumentNullException>(delegate ()
61+
{
62+
new Drawables().Draw(null);
63+
});
64+
}
3865
}
3966
}

Tests/Magick.NET.Tests/Framework/Drawables/DrawableAffineTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
namespace Magick.NET.Tests
2121
{
22-
[TestClass]
2322
public partial class DrawableAffineTests
2423
{
2524
[TestMethod]

Tests/Magick.NET.Tests/Magick.NET.Tests.AnyCPU.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<Compile Include="Core\Defines\DefinesCreatorTests.cs" />
157157
<Compile Include="Core\Defines\Jp2\Jp2WriteDefines.cs" />
158158
<Compile Include="Core\Defines\Jp2\Jp2ReadDefinesTests.cs" />
159+
<Compile Include="Core\Drawables\DrawableAffineTests.cs" />
160+
<Compile Include="Core\Drawables\DrawablePathTests.cs" />
161+
<Compile Include="Core\Drawables\DrawableTextEncodingTests.cs" />
159162
<Compile Include="Core\TestStream.cs" />
160163
<Compile Include="Core\Replacements\ExcludeFromCodeCoverage.cs" />
161164
<Compile Include="Framework\Coders\PdfTests.cs" />

Tests/Magick.NET.Tests/Magick.NET.Tests.AnyCPU.net20.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
<Compile Include="Core\Defines\DefinesCreatorTests.cs" />
155155
<Compile Include="Core\Defines\Jp2\Jp2WriteDefines.cs" />
156156
<Compile Include="Core\Defines\Jp2\Jp2ReadDefinesTests.cs" />
157+
<Compile Include="Core\Drawables\DrawableAffineTests.cs" />
158+
<Compile Include="Core\Drawables\DrawablePathTests.cs" />
159+
<Compile Include="Core\Drawables\DrawableTextEncodingTests.cs" />
157160
<Compile Include="Core\TestStream.cs" />
158161
<Compile Include="Core\Replacements\ExcludeFromCodeCoverage.cs" />
159162
<Compile Include="Framework\Coders\PdfTests.cs" />

Tests/Magick.NET.Tests/Magick.NET.Tests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
<Compile Include="Core\Defines\DefinesCreatorTests.cs" />
157157
<Compile Include="Core\Defines\Jp2\Jp2WriteDefines.cs" />
158158
<Compile Include="Core\Defines\Jp2\Jp2ReadDefinesTests.cs" />
159+
<Compile Include="Core\Drawables\DrawableAffineTests.cs" />
160+
<Compile Include="Core\Drawables\DrawablePathTests.cs" />
161+
<Compile Include="Core\Drawables\DrawableTextEncodingTests.cs" />
159162
<Compile Include="Core\TestStream.cs" />
160163
<Compile Include="Core\Replacements\ExcludeFromCodeCoverage.cs" />
161164
<Compile Include="Framework\Coders\PdfTests.cs" />

Tests/Magick.NET.Tests/Magick.NET.Tests.net20.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@
154154
<Compile Include="Core\Defines\DefinesCreatorTests.cs" />
155155
<Compile Include="Core\Defines\Jp2\Jp2WriteDefines.cs" />
156156
<Compile Include="Core\Defines\Jp2\Jp2ReadDefinesTests.cs" />
157+
<Compile Include="Core\Drawables\DrawableAffineTests.cs" />
158+
<Compile Include="Core\Drawables\DrawablePathTests.cs" />
159+
<Compile Include="Core\Drawables\DrawableTextEncodingTests.cs" />
157160
<Compile Include="Core\TestStream.cs" />
158161
<Compile Include="Core\Replacements\ExcludeFromCodeCoverage.cs" />
159162
<Compile Include="Framework\Coders\PdfTests.cs" />

0 commit comments

Comments
 (0)