Skip to content

Commit

Permalink
Updates to support multiple dotnet targets
Browse files Browse the repository at this point in the history
- support v3.5, v4.0, v4.5.2, v4.7.2 and dotnetcore2.2
- added support for Appveyor build
- added explict FrameworkPathOverride to projects
- added <IsTextProject> to csproj file
- remove net35 from unittests. Updated licence method.
  • Loading branch information
garyranson authored and mrbean-bremen committed May 7, 2019
1 parent 43f5acc commit feb3961
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 568 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ Tests/**/*.suo
Source/TestResults/
Source/.vs
/Source/Svg.sln.DotSettings.user
/Source/Svg.XML
5 changes: 0 additions & 5 deletions Source/DataTypes/SvgUnitConverter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;

namespace Svg
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Document Structure/SvgGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected override void Render(ISvgRenderer renderer)
}

/// <summary>
/// Gets the <see cref="GraphicsPath"/> for this element.
/// Gets the <see cref="System.Drawing.Drawing2D.GraphicsPath"/> for this element.
/// </summary>
/// <value></value>
public override GraphicsPath Path(ISvgRenderer renderer)
Expand Down
2 changes: 1 addition & 1 deletion Source/Painting/EnumConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public EnumBaseConverter() { }

/// <summary>Creates a new instance.</summary>
/// <param name="defaultValue">Specified the default value of the enum.</param>
/// <param name="caseHandling">Specified the case.</param>
/// <param name="caseHandling">Defines if the value shall be converted to lower camel case or lower case</param>
public EnumBaseConverter(T defaultValue, CaseHandling caseHandling = CaseHandling.CamelCase)
{
this.DefaultValue = defaultValue;
Expand Down
3 changes: 2 additions & 1 deletion Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#if NETFULL
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -34,7 +35,7 @@
// by using the '*' as shown below:
[assembly: AssemblyVersion("2.4.3.*")]
//[assembly: AssemblyFileVersion("1.0.1.*")]

#endif
[assembly: CLSCompliant(true)]

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Svg.UnitTests,PublicKey=" +
Expand Down
500 changes: 126 additions & 374 deletions Source/Svg.csproj

Large diffs are not rendered by default.

53 changes: 7 additions & 46 deletions Source/Svg.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Svg", "Svg.csproj", "{886A98C5-37C0-4E8B-885E-30C1D2F98B47}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Svg", "Svg.csproj", "{886A98C5-37C0-4E8B-885E-30C1D2F98B47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SVGViewer", "..\Samples\SVGViewer\SVGViewer.csproj", "{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Svg.UnitTests", "..\Tests\Svg.UnitTests\Svg.UnitTests.csproj", "{E702EB7D-D01D-438A-BADD-E72D4E49109F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Svg.UnitTests", "..\Tests\Svg.UnitTests\Svg.UnitTests.csproj", "{E702EB7D-D01D-438A-BADD-E72D4E49109F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A417AF1E-BEDB-4715-B4FD-D795579217F9}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -16,10 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SvgW3CTestRunner", "..\Tests\SvgW3CTestRunner\SvgW3CTestRunner.csproj", "{8ED74C39-6CFF-421E-952A-30F9E6957108}"
EndProject
Project("{FF286327-C783-4F7A-AB73-9BCBAD0D4460}") = "Svg.Package", "SvgNuget\Svg.Package.nuproj", "{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -40,18 +34,6 @@ Global
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{886A98C5-37C0-4E8B-885E-30C1D2F98B47}.Release|x86.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|Mixed Platforms.Build.0 = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.ActiveCfg = Debug|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Debug|x86.Build.0 = Debug|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Any CPU.Build.0 = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.ActiveCfg = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|Mixed Platforms.Build.0 = Release|x86
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.ActiveCfg = Release|Any CPU
{1B8F3C8A-CCAC-474E-B09D-522FBA93DCFD}.Release|x86.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Any CPU.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand All @@ -62,34 +44,13 @@ Global
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{E702EB7D-D01D-438A-BADD-E72D4E49109F}.Release|x86.ActiveCfg = Release|Any CPU
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Any CPU.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|Mixed Platforms.Build.0 = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|x86.ActiveCfg = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Debug|x86.Build.0 = Debug|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Any CPU.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Any CPU.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Mixed Platforms.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|Mixed Platforms.Build.0 = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|x86.ActiveCfg = Release|x86
{8ED74C39-6CFF-421E-952A-30F9E6957108}.Release|x86.Build.0 = Release|x86
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|x86.ActiveCfg = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Debug|x86.Build.0 = Debug|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Any CPU.Build.0 = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|x86.ActiveCfg = Release|Any CPU
{AEEFC0CC-6D17-439D-B8E0-53B713485E3B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5096EEB3-8F41-44B5-BCF9-58743A59AB21}
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = Svg.vsmdi
EndGlobalSection
Expand Down
20 changes: 12 additions & 8 deletions Source/SvgDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,10 @@ public static SvgDocument Open(string path)

using (var strReader = new System.IO.StringReader(svg))
{
var reader = new SvgTextReader(strReader, null);
reader.XmlResolver = new SvgDtdResolver();
reader.WhitespaceHandling = WhitespaceHandling.None;
var reader = new SvgTextReader(strReader, null)
{
XmlResolver = new SvgDtdResolver(), WhitespaceHandling = WhitespaceHandling.None
};
return Open<T>(reader);
}
}
Expand All @@ -251,9 +252,10 @@ public static SvgDocument Open(string path)
}

// Don't close the stream via a dispose: that is the client's job.
var reader = new SvgTextReader(stream, entities);
reader.XmlResolver = new SvgDtdResolver();
reader.WhitespaceHandling = WhitespaceHandling.None;
var reader = new SvgTextReader(stream, entities)
{
XmlResolver = new SvgDtdResolver(), WhitespaceHandling = WhitespaceHandling.None
};
return Open<T>(reader);
}

Expand Down Expand Up @@ -621,8 +623,10 @@ public override void Write(XmlTextWriter writer)
public void Write(Stream stream, bool useBom = true)
{

var xmlWriter = new XmlTextWriter(stream, useBom ? Encoding.UTF8 : new System.Text.UTF8Encoding(false));
xmlWriter.Formatting = Formatting.Indented;
var xmlWriter = new XmlTextWriter(stream, useBom ? Encoding.UTF8 : new System.Text.UTF8Encoding(false))
{
Formatting = Formatting.Indented
};
xmlWriter.WriteStartDocument();
xmlWriter.WriteDocType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd", null);

Expand Down
6 changes: 6 additions & 0 deletions Source/SvgElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,13 @@ private Dictionary<string, string> WritePropertyAttributes(XmlTextWriter writer)
}
}

#if NETFULL
var value = (string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
#else
// dotnetcore throws exception if input is null
string value = propertyValue==null?null:(string)attr.Property.Converter.ConvertTo(propertyValue, typeof(string));
#endif

if (propertyValue != null)
{
var type = propertyValue.GetType();
Expand Down
4 changes: 3 additions & 1 deletion Source/Web/SvgHandler.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if NETFULL
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -230,4 +231,5 @@ public WaitHandle AsyncWaitHandle
}
}
}
}
}
#endif
71 changes: 60 additions & 11 deletions Tests/Svg.UnitTests/ImageComparisonTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace Svg.UnitTests
{
Expand All @@ -13,6 +15,32 @@ namespace Svg.UnitTests
public class ImageComparisonTest
{
public TestContext TestContext { get; set; }
#if NETCORE
private static string _basePath = null;
private static string GetSuiteTestsFolder
{
get
{
if (_basePath != null) return _basePath;
var basePath = Environment.CurrentDirectory;
while (!basePath.ToLower().EndsWith("svg"))
{
basePath = Path.GetDirectoryName(basePath);
}

_basePath = Path.Combine(basePath, "Tests");
return _basePath;
}
}

private static IEnumerable<object[]> GetData()
{
var basePath = GetSuiteTestsFolder;
var testSuite = Path.Combine(basePath, "W3CTestSuite");
var rows = File.ReadAllLines(Path.Combine(basePath, "Svg.UnitTests", "PassingTests.csv")).Skip(1);
foreach (var row in rows)
yield return new[] { (object)testSuite, (object) row,};
}

/// <summary>
/// Compares SVG images against reference PNG images from the W3C SVG 1.1 test suite.
Expand All @@ -21,9 +49,26 @@ public class ImageComparisonTest
/// Note that with the current test there are still a lot of false positives,
/// so this is not a definitive test for image equality yet.
/// </summary>
[TestMethod]
[DynamicData(nameof(GetData), DynamicDataSourceType.Method)]
// [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",@"|DataDirectory|\..\..\PassingTests.csv","PassingTests#csv", DataAccessMethod.Sequential)]
//public void CompareSvgImageWithReference()
public void CompareSvgImageWithReference(string basePath, string baseName)
{
var svgPath = Path.Combine(basePath, "svg", baseName + ".svg");
var pngPath = Path.Combine(basePath, "png", baseName + ".png");
var pngImage = Image.FromFile(pngPath);
var svgImage = LoadSvgImage(baseName, svgPath);
Assert.AreNotEqual(null, pngImage, "Failed to load " + pngPath);
Assert.AreNotEqual(null, svgImage, "Failed to load " + svgPath);
var difference = svgImage.PercentageDifference(pngImage);
Assert.IsTrue(difference < 0.05,
baseName + ": Difference is " + (difference * 100.0).ToString() + "%");
}
#else
[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV",
@"|DataDirectory|\..\..\PassingTests.csv",
@"|DataDirectory|\..\..\..\PassingTests.csv",
"PassingTests#csv", DataAccessMethod.Sequential)]
public void CompareSvgImageWithReference()
{
Expand All @@ -32,16 +77,16 @@ public void CompareSvgImageWithReference()
{
basePath = Path.GetDirectoryName(basePath);
}
basePath = Path.Combine(basePath, "Tests", "W3CTestSuite");
basePath = Path.Combine(Path.Combine(basePath, "Tests"), "W3CTestSuite");
var svgBasePath = Path.Combine(basePath, "svg");
var baseName = TestContext.DataRow[0] as string;
bool testSaveLoad = !baseName.StartsWith("#");
if (!testSaveLoad)
{
baseName = baseName.Substring(1);
}
var svgPath = Path.Combine(basePath, "svg", baseName + ".svg");
var pngPath = Path.Combine(basePath, "png", baseName + ".png");
var svgPath = Path.Combine(Path.Combine(basePath, "svg"), baseName + ".svg");
var pngPath = Path.Combine(Path.Combine(basePath, "png"), baseName + ".png");
var pngImage = Image.FromFile(pngPath);
var svgDoc = LoadSvgDocument(svgPath);
Assert.IsNotNull(svgDoc);
Expand All @@ -50,7 +95,7 @@ public void CompareSvgImageWithReference()
Assert.AreNotEqual(null, pngImage, "Failed to load " + pngPath);
Assert.AreNotEqual(null, svgImage, "Failed to load " + svgPath);
var difference = svgImage.PercentageDifference(pngImage);
Assert.IsTrue(difference < 0.05,
Assert.IsTrue(difference < 0.05,
baseName + ": Difference is " + (difference * 100.0).ToString() + "%");
if (!testSaveLoad)
{
Expand All @@ -76,6 +121,7 @@ public void CompareSvgImageWithReference()
baseName + ": Difference is " + (difference * 100.0).ToString() + "%");
}
}
#endif

/// <summary>
/// Enable this test to output the calculate percentage difference
Expand All @@ -85,15 +131,18 @@ public void CompareSvgImageWithReference()
// [TestClass]
public void RecordDiffForAllSvgImagesWithReference()
{
var basePath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(
TestContext.TestRunDirectory)));
basePath = Path.Combine(basePath, "Tests", "W3CTestSuite");
var svgBasePath = Path.Combine(basePath, "svg");
#if NETCORE
var basePath = Path.Combine(GetSuiteTestsFolder, "W3CTestSuite");
#else
var basePath = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(TestContext.TestRunDirectory)));
basePath = Path.Combine(Path.Combine(basePath, "Tests"), "W3CTestSuite");
#endif
// var svgBasePath = Path.Combine(basePath, "svg");
string[] lines = File.ReadAllLines(@"..\..\..\..\Tests\Svg.UnitTests\all.csv");
foreach (var baseName in lines)
{
var svgPath = Path.Combine(basePath, "svg", baseName + ".svg");
var pngPath = Path.Combine(basePath, "png", baseName + ".png");
var svgPath = Path.Combine(Path.Combine(basePath, "svg"), baseName + ".svg");
var pngPath = Path.Combine(Path.Combine(basePath, "png"), baseName + ".png");
if (File.Exists(pngPath) && File.Exists(svgPath))
{
var pngImage = Image.FromFile(pngPath);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Svg.UnitTests/MultiThreadingTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if NET35
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Svg.Exceptions;
using System;
Expand Down Expand Up @@ -37,3 +39,4 @@ public void LoadSVGThreading_MultiThread_YieldsNoErrorWhileInBounds()
}
}
}
#endif
33 changes: 1 addition & 32 deletions Tests/Svg.UnitTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Svg.UnitTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Svg.UnitTests")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6ab1d266-f201-46c0-9d14-523768eb18db")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit feb3961

Please sign in to comment.