Browse Source

* XsltTestUtils.cs, xslt.vmwcsproj, xslt.sln, xslttest.cs, XmlCompare.cs,
Makefile: make XML compare to reduce the noise from attribute order and
namespace names (not URIs)

--This ine, and those below, will be ignored--

M standalone_tests/XsltTestUtils.cs
M standalone_tests/xslt.vmwcsproj
M standalone_tests/xslt.sln
M standalone_tests/ChangeLog
M standalone_tests/xslttest.cs
AM standalone_tests/XmlCompare.cs
M standalone_tests/Makefile

svn path=/trunk/mcs/; revision=52088

Andrew Skiba 20 years ago
parent
commit
b00f990430

+ 6 - 0
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/ChangeLog

@@ -1,3 +1,9 @@
+2005-10-23  Andrew Skiba  <[email protected]>
+
+	* XsltTestUtils.cs, xslt.vmwcsproj, xslt.sln, xslttest.cs, XmlCompare.cs,
+	Makefile: make XML compare to reduce the noise from attribute order and
+	namespace names (not URIs)
+
 2005-10-23  Andrew Skiba  <[email protected]>
 
 	* xslt.sln, xslt.vmwcsproj, README.j2ee, run-test.j2ee.bat: add files

+ 1 - 1
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/Makefile

@@ -84,7 +84,7 @@ endif
 $(GENERATE_EXE) : generate.cs XsltTestUtils.cs
 	$(CSCOMPILE) generate.cs XsltTestUtils.cs -out:$@
 $(TEST_PROG) : xslttest.cs XsltTestUtils.cs
-	$(CSCOMPILE) xslttest.cs XsltTestUtils.cs -r:NUnit.core -r:NUnit.framework -out:$@ -t:library
+	$(CSCOMPILE) xslttest.cs XsltTestUtils.cs XmlCompare.cs -r:NUnit.core -r:NUnit.framework -out:$@ -t:library
 
 catalog-fixed : $(FIXED_CATALOG)
 

+ 110 - 0
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/XmlCompare.cs

@@ -0,0 +1,110 @@
+using System;
+using System.Xml;
+
+namespace XmlCompare
+{
+	/// <summary>
+	/// Summary description for XmlCompare.
+	/// </summary>
+	public class XmlCompare
+	{
+		[Flags]
+		public enum Flags {
+			IgnoreNone=0,
+			IgnoreAttribOrder=1,
+		}
+		Flags flags;
+		public XmlCompare (Flags flags)
+		{
+			this.flags = flags;
+		}
+
+		public XmlCompare ()
+			:this (Flags.IgnoreNone)
+		{
+		}
+
+		public bool AreEqualAttribs (XmlAttributeCollection attrs1, XmlAttributeCollection attrs2)
+		{
+			if (attrs1.Count != attrs2.Count)
+				return false;
+			for (int i=0; i<attrs1.Count; i++) {
+				if ((flags & Flags.IgnoreAttribOrder) != 0) {
+					string ln = attrs1[i].LocalName;
+					string ns = attrs1[i].NamespaceURI;
+					string val = attrs1[i].Value;
+					XmlAttribute atr2 = attrs2[ln, ns];
+					if (atr2 == null || atr2.Value != val)
+						return false;
+				} else {
+					if (attrs1 [i].LocalName != attrs2 [i].LocalName)
+						return false;
+					if (attrs1 [i].NamespaceURI != attrs2 [i].NamespaceURI)
+						return false;
+					if (attrs1 [i].Value != attrs2 [i].Value)
+						return false;
+				}
+			}
+			return true;
+		}
+
+		public bool AreEqualNodeList (XmlNodeList lst1, XmlNodeList lst2)
+		{
+			if (lst1.Count != lst2.Count)
+				return false;
+			for (int i=0; i<lst1.Count; i++) {
+				if (!AreEqual (lst1[i], lst2[i]))
+					return false;
+			}
+			return true;
+		}
+
+		public bool AreEqual (XmlNode node1, XmlNode node2)
+		{
+			if (node1.NodeType != node2.NodeType)
+				return false;
+			if (node1.LocalName != node2.LocalName)
+				return false;
+			if (node1.NamespaceURI != node2.NamespaceURI)
+				return false;
+			if (node1.Attributes != null && node2.Attributes != null) {
+				if (!AreEqualAttribs (node1.Attributes, node2.Attributes))
+					return false;
+			}
+			else //one of nodes has no attrs
+				if (node1.Attributes != null || node2.Attributes != null)
+					return false;//and another has some
+			if (!node1.HasChildNodes && !node2.HasChildNodes)
+				return node1.Value == node2.Value;
+			else {//one of nodes has some children
+				if (!node1.HasChildNodes || !node2.HasChildNodes)
+					return false;//and another has none
+				return AreEqualNodeList (node1.ChildNodes, node2.ChildNodes);
+			}
+		}
+
+		static void Main ()
+		{
+			XmlDocument doc1 = new XmlDocument ();
+			XmlDocument doc2 = new XmlDocument ();
+			XmlDocument doc3 = new XmlDocument ();
+			XmlDocument doc4 = new XmlDocument ();
+			
+			doc1.LoadXml (@"<?xml version=""1.0""?>
+<doc>
+	<element attr1=""1"" attr2=""2"" />
+</doc>");
+			doc2.LoadXml (@"<?xml version=""1.0""?><doc><element attr1=""1"" attr2=""2""/></doc>");
+			doc3.LoadXml (@"<?xml version=""1.0""?><doc><element attr2=""2"" attr1=""1""/></doc>");
+			doc4.LoadXml (@"<?xml version=""1.0""?><doc><element attr3=""3"" attr2=""2""/></doc>");
+
+			XmlCompare cmp1 = new XmlCompare();
+			XmlCompare cmp2 = new XmlCompare(Flags.IgnoreAttribOrder);
+
+			Console.Out.WriteLine (cmp1.AreEqual (doc1, doc2).ToString ());
+			Console.Out.WriteLine (cmp1.AreEqual (doc1, doc3).ToString ());
+			Console.Out.WriteLine (cmp2.AreEqual (doc1, doc3).ToString ());
+			Console.Out.WriteLine (cmp2.AreEqual (doc1, doc4).ToString ());
+		}
+	}
+}

+ 26 - 2
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/XsltTestUtils.cs

@@ -83,6 +83,12 @@ namespace MonoTests.oasis_xslt {
 		string _stylesheet;
 		string _srcxml;
 		string _outfile;
+		public enum CompareType {
+			Text,
+			HTML,
+			XML
+		}
+		CompareType _compare;
 		XmlElement _testCase;
 		string _outputDir;
 
@@ -134,10 +140,28 @@ namespace MonoTests.oasis_xslt {
 
 			_srcxml = Path.Combine (path, scenario.SelectSingleNode ("input-file[@role='principal-data']").InnerText);
 			XmlNode outputNode = scenario.SelectSingleNode ("output-file[@role='principal']");
-			if (outputNode != null) 
+			if (outputNode != null) {
 				_outfile = Path.Combine (outputPath, outputNode.InnerText);
-			else
+				switch (outputNode.Attributes ["compare"].Value) {
+				case "XML":
+					_compare = CompareType.XML;
+					break;
+				case "HTML":
+					_compare = CompareType.HTML;
+					break;
+				default:
+					_compare = CompareType.Text;
+					break;
+				}
+			}
+			else {
 				_outfile = null;
+				_compare = CompareType.Text;
+			}
+		}
+
+		public CompareType Compare {
+			get {return _compare;}
 		}
 
 		public string StyleSheet {

+ 9 - 0
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/xslt.sln

@@ -5,12 +5,21 @@ Project("{83B010C7-76FC-4FAD-A26C-00D7EFE60256}") = "xslt", "xslt.vmwcsproj", "{
 EndProject
 Global
 	GlobalSection(SolutionConfiguration) = preSolution
+		Debug = Debug
 		Debug_Java = Debug_Java
+		Debug-Strong = Debug-Strong
+		Release = Release
 		Release_Java = Release_Java
 	EndGlobalSection
 	GlobalSection(ProjectConfiguration) = postSolution
+		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Debug.ActiveCfg = Debug|.NET
+		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Debug.Build.0 = Debug|.NET
 		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Debug_Java.ActiveCfg = Debug_Java|.NET
 		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Debug_Java.Build.0 = Debug_Java|.NET
+		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Debug-Strong.ActiveCfg = Debug|.NET
+		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Debug-Strong.Build.0 = Debug|.NET
+		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Release.ActiveCfg = Release_Java|.NET
+		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Release.Build.0 = Release_Java|.NET
 		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Release_Java.ActiveCfg = Release_Java|.NET
 		{7D5A1B1C-4B8C-462B-86C8-0961A838A39D}.Release_Java.Build.0 = Release_Java|.NET
 	EndGlobalSection

+ 5 - 3
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/xslt.vmwcsproj

@@ -4,11 +4,12 @@
 			<Settings ApplicationIcon="" AssemblyKeyContainerName="" AssemblyName="xslt" AssemblyOriginatorKeyFile="" DefaultClientScript="JScript" DefaultHTMLPageLayout="Grid" DefaultTargetSchema="IE50" DelaySign="false" OutputType="Library" PreBuildEvent="" PostBuildEvent="" RootNamespace="xslt" RunPostBuildEvent="OnBuildSuccess" StartupObject="">
 				<Config Name="Debug_Java" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="DEBUG;TRACE;TARGET_JVM" DocumentationFile="" DebugSymbols="true" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="1595" Optimize="false" OutputPath=".\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4"/>
 				<Config Name="Release_Java" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="TRACE;TARGET_JVM" DocumentationFile="" DebugSymbols="false" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="1595" Optimize="true" OutputPath="bin\Release_Java\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4"/>
+				<Config Name="Debug" AllowUnsafeBlocks="false" BaseAddress="285212672" CheckForOverflowUnderflow="false" ConfigurationOverrideFile="" DefineConstants="DEBUG;TRACE" DocumentationFile="" DebugSymbols="true" FileAlignment="4096" IncrementalBuild="false" NoStdLib="false" NoWarn="1595" Optimize="false" OutputPath=".\" RegisterForComInterop="false" RemoveIntegerChecks="false" TreatWarningsAsErrors="false" WarningLevel="4"/>
 			</Settings>
 			<References>
 				<Reference Name="System" AssemblyName="System" HintPath="..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"/>
-				<Reference Name="System.Xml" AssemblyName="System.Xml" HintPath="..\..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Xml.dll"/>
 				<Reference Name="rt" AssemblyName="rt" HintPath="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\jgac\j2sdk1.4\rt.dll" Private="False"/>
+				<Reference Name="System.Xml" AssemblyName="System.Xml" HintPath="..\..\..\bin\Debug\System.Xml.dll"/>
 				<Reference Name="nunit.core" AssemblyName="nunit.core" HintPath="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.core.dll" Private="True"/>
 				<Reference Name="nunit.framework" AssemblyName="nunit.framework" HintPath="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.framework.dll" Private="True"/>
 				<Reference Name="nunit.util" AssemblyName="nunit.util" HintPath="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.util.dll" Private="True"/>
@@ -16,10 +17,11 @@
 		</Build>
 		<Files>
 			<Include>
+				<File RelPath="XmlCompare.cs" SubType="Code" BuildAction="Compile"/>
 				<File RelPath="xslttest.cs" SubType="Code" BuildAction="Compile"/>
 				<File RelPath="XsltTestUtils.cs" SubType="Code" BuildAction="Compile"/>
 			</Include>
 		</Files>
-		<UserProperties jarserver="ipa" project.JDKType="1.4.2_05" REFS.JarPath.rt="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\j2sdk1.4\lib\rt.jar" REFS.JarPath.system.xml="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\jgac\vmw4j2ee_110\System.Xml.jar" REFS.JarPath.system="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\jgac\vmw4j2ee_110\System.jar" REFS.JarPath.nunit.core="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.core.jar" REFS.JarPath.nunit.framework="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.framework.jar" REFS.JarPath.nunit.util="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.util.jar"/>
+		<UserProperties REFS.JarPath.nunit.util="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.util.jar" REFS.JarPath.nunit.framework="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.framework.jar" REFS.JarPath.nunit.core="..\..\..\..\..\..\..\..\views\DevQA\studio\GH\DevQA\tests\utils\nunit\nunit-2.2.0\nunit-console\bin\Debug_Java\nunit.core.jar" REFS.JarPath.system="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\jgac\vmw4j2ee_110\System.jar" REFS.JarPath.system.xml="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\jgac\vmw4j2ee_110\System.Xml.jar" REFS.JarPath.rt="..\..\..\..\..\..\..\..\Program Files\Mainsoft\Visual MainWin for J2EE\j2sdk1.4\lib\rt.jar" project.JDKType="1.4.2_05" jarserver="ipa"/>
 	</CSHARP>
-	<VisualMainWin><Project Prop2023="1.4.2_05" Prop2024="" Prop2026="" Prop2015="" Version="1.7.0" ProjectType="1"/><References/><Configs><Config Prop2000="0" Prop2001="0" Prop2002="0" Prop2003="0" Prop2004="0" Prop2005="0" Prop2006="" Prop2007="" Prop2008="" Prop2009="" Prop2010="" Prop2011="0" Prop2012="0" Prop2013="" Prop2014="0" Prop2016="" Prop2027="" Prop2019="0" Prop2020="285212672" Prop2021="4096" Prop2022="0" Prop2017="0" Prop2018="0" Name="Release_Java"/><Config Prop2000="0" Prop2001="0" Prop2002="0" Prop2003="0" Prop2004="0" Prop2005="1" Prop2006=".\nunit-console.jar" Prop2007="" Prop2008="" Prop2009="/fixture:MonoTests.oasis_xslt.SuiteBuilder  /include:Clean" Prop2010="" Prop2011="0" Prop2012="0" Prop2013="" Prop2014="0" Prop2016="" Prop2027="" Prop2019="0" Prop2020="285212672" Prop2021="4096" Prop2022="0" Prop2017="0" Prop2018="0" Name="Debug_Java"/></Configs></VisualMainWin></VisualStudioProject>
+	<VisualMainWin><Project Prop2023="1.4.2_05" Prop2024="" Prop2026="" Prop2015="" Version="1.7.0" ProjectType="1"/><References/><Configs><Config Prop2000="0" Prop2001="0" Prop2002="0" Prop2003="0" Prop2004="0" Prop2005="1" Prop2006=".\nunit-console.jar" Prop2007="" Prop2008="" Prop2009="/fixture:MonoTests.oasis_xslt.SuiteBuilder  /include:Clean" Prop2010="" Prop2011="0" Prop2012="0" Prop2013="" Prop2014="0" Prop2016="" Prop2027="" Prop2019="0" Prop2020="285212672" Prop2021="4096" Prop2022="0" Prop2017="0" Prop2018="0" Name="Debug_Java"/><Config Prop2000="0" Prop2001="0" Prop2002="0" Prop2003="0" Prop2004="0" Prop2005="0" Prop2006="" Prop2007="" Prop2008="" Prop2009="" Prop2010="" Prop2011="0" Prop2012="0" Prop2013="" Prop2014="0" Prop2016="" Prop2027="" Prop2019="0" Prop2020="285212672" Prop2021="4096" Prop2022="0" Prop2017="0" Prop2018="0" Name="Release_Java"/><Config Prop2000="1" Prop2001="0" Prop2002="0" Prop2003="0" Prop2004="0" Prop2005="1" Prop2006=".\nunit-console.exe" Prop2007="" Prop2008="" Prop2009="xslt.dll /fixture:MonoTests.oasis_xslt.SuiteBuilder  /include:Clean" Prop2010="" Prop2011="0" Prop2012="0" Prop2013="" Prop2014="0" Prop2016="" Prop2027="" Prop2019="0" Prop2020="285212672" Prop2021="4096" Prop2022="0" Prop2017="0" Prop2018="0" Name="Debug"/></Configs></VisualMainWin></VisualStudioProject>

+ 25 - 5
mcs/class/System.XML/Test/System.Xml.Xsl/standalone_tests/xslttest.cs

@@ -117,11 +117,30 @@ namespace MonoTests.oasis_xslt {
 			return sb.ToString ();
 		}
 
-		string CompareResult (string actual, string expected)
+		string CompareResult (string actual, string expected, CatalogTestCase.CompareType compare)
 		{
-			//TODO: add xml comparison
-			if (actual == expected)
-				return null;
+			//TODO: add html comparison
+			if (compare== CatalogTestCase.CompareType.XML) {
+				try {
+					XmlDocument actDoc = new XmlDocument();
+					XmlDocument expDoc = new XmlDocument();
+					actDoc.LoadXml (actual);
+					expDoc.LoadXml (expected);
+					XmlCompare.XmlCompare cmp = new XmlCompare.XmlCompare(XmlCompare.XmlCompare.Flags.IgnoreAttribOrder);
+					if (cmp.AreEqual (actDoc, expDoc)) {
+						return null;
+					}
+				}
+				catch (Exception ex) {
+					//could not compare as xml, fallback to text
+					if (actual == expected)
+						return null;
+				}
+			}
+			else
+				if (actual == expected)
+					return null;
+
 			string res = "Different.\nActual*****\n"+actual+"\nReference*****\n"+expected;
 			return EscapeString (res);
 		}
@@ -164,7 +183,7 @@ namespace MonoTests.oasis_xslt {
 			if (_transform.Succeeded) {
 				try {
 					using (StreamReader sr = new StreamReader (_transform.TestCase.OutFile))
-						failureMessage = CompareResult (_transform.Result, sr.ReadToEnd ());
+						failureMessage = CompareResult (_transform.Result, sr.ReadToEnd (), _transform.TestCase.Compare);
 				}
 				catch {
 					//if there is no reference result because of expectedException, we
@@ -172,6 +191,7 @@ namespace MonoTests.oasis_xslt {
 					if (_expectedException!=null)
 						failureMessage = null;
 					else {
+						Console.WriteLine (_transform.TestCase.OutFile);
 						Console.WriteLine ("ERROR: No reference result, and no expected exception.");
 						throw;
 					}