Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
18d4a960
Commit
18d4a960
authored
Dec 28, 2015
by
HeinrichAD
Browse files
Add: Unit Test metafile rendering
Create metafile rendering Unit Test based on Issue #210 from master.
parent
dd436504
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Tests/Svg.UnitTests/MetafileRenderingTest.cs
0 → 100644
View file @
18d4a960
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Drawing
;
using
System.Drawing.Imaging
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Xml
;
namespace
Svg.UnitTests
{
/// <summary>
/// Test Class of rendering SVGs as meterfile.
/// Based on Issue 210.
/// </summary>
/// <remarks>
/// Test use the following embedded resources:
/// - Issue210_Metafile\3DSceneSnapshotBIG.svg
/// </remarks>
[
TestClass
]
public
class
MetafileRenderingTest
:
SvgTestHelper
{
protected
override
string
TestResource
{
get
{
return
GetFullResourceString
(
"Issue210_Metafile.3DSceneSnapshotBIG.svg"
);
}
}
protected
override
int
ExpectedSize
{
get
{
return
12896
;
}
}
[
TestMethod
]
[
TestProperty
(
name
:
"speed"
,
value
:
"slow"
)]
public
void
TestMetafileRendering
()
{
LoadSvg
(
GetXMLDocFromResource
());
}
protected
override
Image
DrawSvg
(
SvgDocument
svgDoc
)
{
// GDI+
Metafile
metafile
;
using
(
var
stream
=
new
MemoryStream
())
using
(
var
img
=
new
Bitmap
((
int
)
svgDoc
.
Width
.
Value
,
(
int
)
svgDoc
.
Height
.
Value
))
// Not necessary if you use Control.CreateGraphics().
using
(
Graphics
ctrlGraphics
=
Graphics
.
FromImage
(
img
))
// Control.CreateGraphics()
{
IntPtr
handle
=
ctrlGraphics
.
GetHdc
();
var
rect
=
new
RectangleF
(
0
,
0
,
svgDoc
.
Width
,
svgDoc
.
Height
);
metafile
=
new
Metafile
(
stream
,
handle
,
rect
,
MetafileFrameUnit
.
Pixel
,
EmfType
.
EmfPlusOnly
);
using
(
Graphics
ig
=
Graphics
.
FromImage
(
metafile
))
{
svgDoc
.
Draw
(
ig
);
}
ctrlGraphics
.
ReleaseHdc
(
handle
);
}
return
metafile
;
}
}
}
Tests/Svg.UnitTests/Resources/Issue210_Metafile/3DSceneSnapshotBIG.svg
0 → 100644
View file @
18d4a960
This diff is collapsed.
Click to expand it.
Tests/Svg.UnitTests/Svg.UnitTests.csproj
View file @
18d4a960
...
@@ -55,6 +55,7 @@
...
@@ -55,6 +55,7 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"CssQueryTest.cs"
/>
<Compile
Include=
"CssQueryTest.cs"
/>
<Compile
Include=
"MetafileRenderingTest.cs"
/>
<Compile
Include=
"MultiThreadingTest.cs"
/>
<Compile
Include=
"MultiThreadingTest.cs"
/>
<Compile
Include=
"PrivateFontsTests.cs"
/>
<Compile
Include=
"PrivateFontsTests.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
...
@@ -73,6 +74,9 @@
...
@@ -73,6 +74,9 @@
<ItemGroup>
<ItemGroup>
<EmbeddedResource
Include=
"Resources\Issue204_PrivateFont\Text.svg"
/>
<EmbeddedResource
Include=
"Resources\Issue204_PrivateFont\Text.svg"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<EmbeddedResource
Include=
"Resources\Issue210_Metafile\3DSceneSnapshotBIG.svg"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildBinPath)\Microsoft.CSharp.targets"
/>
<Import
Project=
"$(MSBuildBinPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
Tests/Svg.UnitTests/SvgTestHelper.cs
View file @
18d4a960
...
@@ -184,23 +184,45 @@ namespace Svg.UnitTests
...
@@ -184,23 +184,45 @@ namespace Svg.UnitTests
protected
virtual
void
LoadSvg
(
XmlDocument
xml
)
protected
virtual
void
LoadSvg
(
XmlDocument
xml
)
{
{
Trace
.
WriteLine
(
"SvgDocument open xml."
);
Trace
.
WriteLine
(
"SvgDocument open xml."
);
var
svgDoc
=
SvgDocument
.
Open
(
xml
);
var
svgDoc
=
Open
Svg
(
xml
);
Trace
.
WriteLine
(
"Done SvgDocument open xml."
);
Trace
.
WriteLine
(
"Done SvgDocument open xml."
);
Trace
.
WriteLine
(
"Draw svg."
);
Trace
.
WriteLine
(
"Draw svg."
);
var
img
=
svgDoc
.
Draw
(
);
var
img
=
DrawSvg
(
svgDoc
);
Trace
.
WriteLine
(
"Done drawing."
);
Trace
.
WriteLine
(
"Done drawing."
);
CheckSvg
(
svgDoc
,
img
);
CheckSvg
(
svgDoc
,
img
);
}
}
/// <summary>
/// Open SVG document from XML document.
/// </summary>
/// <param name="xml">XML document.</param>
/// <returns>Open SVG document.</returns>
protected
virtual
SvgDocument
OpenSvg
(
XmlDocument
xml
)
{
return
SvgDocument
.
Open
(
xml
);
}
/// <summary>
/// Draw SVG.
/// </summary>
/// <param name="svgDoc">SVG document to draw.</param>
/// <returns>SVG as image.</returns>
protected
virtual
Image
DrawSvg
(
SvgDocument
svgDoc
)
{
return
svgDoc
.
Draw
();
}
/// <summary>
/// <summary>
/// Check svg file data.
/// Check svg file data.
/// </summary>
/// </summary>
/// <param name="svgDoc">Svg document.</param>
/// <param name="svgDoc">Svg document.</param>
/// <param name="img">Image of svg file from <paramref name="svgDoc"/>.</param>
/// <param name="img">Image of svg file from <paramref name="svgDoc"/>.</param>
protected
virtual
void
CheckSvg
(
SvgDocument
svgDoc
,
Bitmap
img
)
protected
virtual
void
CheckSvg
(
SvgDocument
svgDoc
,
Image
img
)
{
{
using
(
var
ms
=
new
MemoryStream
())
using
(
var
ms
=
new
MemoryStream
())
{
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment