From: <bo...@us...> - 2010-06-28 15:25:50
|
Revision: 408 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=408&view=rev Author: bodewig Date: 2010-06-28 15:25:39 +0000 (Mon, 28 Jun 2010) Log Message: ----------- XSLT as poor man's code generator to get rid of the repetitive 'if last comparison resulted in a CRITICAL difference, break out of the method' logic Modified Paths: -------------- trunk/xmlunit/build.xml trunk/xmlunit/xmlunit.nant.build Added Paths: ----------- trunk/xmlunit/src/buildtools/ trunk/xmlunit/src/buildtools/codegen.xslt trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml Removed Paths: ------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs Modified: trunk/xmlunit/build.xml =================================================================== --- trunk/xmlunit/build.xml 2010-06-28 11:49:08 UTC (rev 407) +++ trunk/xmlunit/build.xml 2010-06-28 15:25:39 UTC (rev 408) @@ -24,6 +24,7 @@ <property name="src.dir" value="src/main"/> <property name="test.dir" value="src/tests"/> <property name="build.dir" location="build/java"/> + <property name="gen.src.dir" value="${build.dir}/generated"/> <property name="lib.dir" value="${build.dir}/lib"/> <property name="core.out.dir" value="${build.dir}/core-classes"/> <property name="legacy.out.dir" value="${build.dir}/legacy-classes"/> @@ -60,6 +61,7 @@ <mkdir dir="${dist.dir}"/> <mkdir dir="${docs.dir}"/> <mkdir dir="${userguide.docs.dir}"/> + <mkdir dir="${gen.src.dir}"/> </target> <target name="clean" @@ -78,9 +80,30 @@ </delete> </target> - <target name="compile-core" depends="-init" - description="compiles legacy sources and tests"> - <javac srcdir="${src.dir}/java-core" destdir="${core.out.dir}" + <target name="-generate-sources" depends="-init"> + <xslt destdir="${gen.src.dir}" + useImplicitFileset="false" + style="src/buildtools/codegen.xslt"> + <fileset dir="${src.dir}/java-core" includes="**/*.java.xml"/> + <globmapper from="*.java.xml" to="*.java"/> + + <param name="nsQualifier" expression="package"/> + <param name="nsStart" expression=";"/> + <param name="nsEnd" expression=""/> + <param name="import" expression="import"/> + <param name="extends" expression="extends"/> + <param name="implements" expression="implements"/> + <param name="summaryStart" expression="/** "/> + <param name="summaryEnd" expression="*/"/> + + <param name="compareMethod" expression="compare"/> + </xslt> + </target> + + <target name="compile-core" depends="-init,-generate-sources" + description="compiles core sources"> + <javac srcdir="${src.dir}/java-core:${gen.src.dir}" + destdir="${core.out.dir}" includeantruntime="false" debug="${javac.debug}" target="${javac.target}" source="${javac.source}"> @@ -88,7 +111,7 @@ </target> <target name="compile-legacy" depends="compile-core" - description="compiles legacy sources and tests"> + description="compiles legacy sources"> <javac srcdir="${src.dir}/java-legacy" destdir="${legacy.out.dir}" includeantruntime="false" debug="${javac.debug}" target="${javac.target}" source="${javac.source}"> Added: trunk/xmlunit/src/buildtools/codegen.xslt =================================================================== --- trunk/xmlunit/src/buildtools/codegen.xslt (rev 0) +++ trunk/xmlunit/src/buildtools/codegen.xslt 2010-06-28 15:25:39 UTC (rev 408) @@ -0,0 +1,130 @@ +<?xml version="1.0"?> +<!-- + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + version="1.0" + xmlns:html="http://www.w3.org/Profiles/XHTML-transitional"> + + <xsl:output method="text" indent="no"/> + + <xsl:param name="compareMethod"/> + <xsl:param name="nsQualifier"/> + <xsl:param name="nsStart"/> + <xsl:param name="nsEnd"/> + <xsl:param name="import"/> + <xsl:param name="extends"/> + <xsl:param name="implements"/> + <xsl:param name="summaryStart"/> + <xsl:param name="summaryEnd"/> + + <xsl:template match="class"> +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + <xsl:value-of select="$nsQualifier"/> + <xsl:text> </xsl:text> + <xsl:value-of select="@ns"/> + <xsl:value-of select="$nsStart"/> + <xsl:text> + </xsl:text> + + <xsl:apply-templates mode="imports" select="import"/> + + <xsl:value-of select="$summaryStart"/> + <xsl:value-of select="@summary"/> + <xsl:text> + </xsl:text> + <xsl:value-of select="$summaryEnd"/> + <xsl:text> +</xsl:text> + + <xsl:value-of select="@qualifiers"/> + <xsl:text> </xsl:text> + class + <xsl:value-of select="@name"/> + <xsl:if test="@extends"> + <xsl:text> </xsl:text> + <xsl:value-of select="$extends"/> + <xsl:text> </xsl:text> + <xsl:value-of select="@extends"/> + </xsl:if> + <xsl:if test="@implements"> + <xsl:text> </xsl:text> + <xsl:value-of select="$implements"/> + <xsl:text> </xsl:text> + <xsl:value-of select="@implements"/> + </xsl:if> + + { + <xsl:apply-templates/> + } + <xsl:value-of select="$nsEnd"/> + </xsl:template> + + <xsl:template match="import" mode="imports"> + <xsl:value-of select="$import"/> + <xsl:text> </xsl:text> + <xsl:value-of select="@reference"/>; + </xsl:template> + + <xsl:template match="lastResultDef"> + ComparisonResult lastResult = ComparisonResult.CRITICAL; + </xsl:template> + + <xsl:template match="compare"> + lastResult = + <xsl:value-of select="$compareMethod"/>(new Comparison(ComparisonType.<xsl:value-of select="@type"/>, + control, null, + control.<xsl:value-of select="@property"/>, + test, null, + test.<xsl:value-of select="@property"/>)); + <xsl:call-template name="if-return-boilerplate"/> + </xsl:template> + + <xsl:template match="compareExpr"> + lastResult = + <xsl:value-of select="$compareMethod"/>(new Comparison(ComparisonType.<xsl:value-of select="@type"/>, + control, null, + <xsl:value-of select="@controlExpr"/>, + test, null, + <xsl:value-of select="@testExpr"/>)); + <xsl:call-template name="if-return-boilerplate"/> + </xsl:template> + + <xsl:template match="compareMethod"> + lastResult = <xsl:value-of select="@method"/>(control, test); + <xsl:call-template name="if-return-boilerplate"/> + </xsl:template> + + <xsl:template match="compareMethodExpr"> + lastResult = <xsl:value-of select="@method"/>(<xsl:value-of select="@controlExpr"/>, <xsl:value-of select="@testExpr"/>); + <xsl:call-template name="if-return-boilerplate"/> + </xsl:template> + + <xsl:template name="if-return-boilerplate"> + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + </xsl:template> +</xsl:stylesheet> Property changes on: trunk/xmlunit/src/buildtools/codegen.xslt ___________________________________________________________________ Added: svn:eol-style + native Deleted: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java 2010-06-28 11:49:08 UTC (rev 407) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java 2010-06-28 15:25:39 UTC (rev 408) @@ -1,219 +0,0 @@ -/* - This file is licensed to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ -package net.sf.xmlunit.diff; - -import javax.xml.transform.Source; -import net.sf.xmlunit.util.Convert; -import org.w3c.dom.CharacterData; -import org.w3c.dom.Document; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.ProcessingInstruction; - -/** - * Difference engine based on DOM. - */ -public final class DOMDifferenceEngine extends AbstractDifferenceEngine { - - public void compare(Source control, Source test) { - if (control == null) { - throw new IllegalArgumentException("control must not be null"); - } - if (test == null) { - throw new IllegalArgumentException("test must not be null"); - } - compareNodes(Convert.toNode(control), Convert.toNode(test)); - } - - /** - * Recursively compares two XML nodes. - * - * <p>Performs comparisons common to all node types, the performs - * the node type specific comparisons and finally recures into - * the node's child lists.</p> - * - * <p>Stops as soon as any comparison returns - * ComparisonResult.CRITICAL.</p> - * - * <p>package private to support tests.</p> - */ - ComparisonResult compareNodes(Node control, Node test) { - ComparisonResult lastResult = - compare(new Comparison(ComparisonType.NODE_TYPE, control, - null, control.getNodeType(), - test, null, test.getNodeType())); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - lastResult = - compare(new Comparison(ComparisonType.NAMESPACE_URI, control, - null, control.getNamespaceURI(), - test, null, test.getNamespaceURI())); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - lastResult = - compare(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, - null, control.getPrefix(), - test, null, test.getPrefix())); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - NodeList controlChildren = control.getChildNodes(); - NodeList testChildren = test.getChildNodes(); - lastResult = - compare(new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, - control, null, controlChildren.getLength(), - test, null, testChildren.getLength())); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - lastResult = nodeTypeSpecificComparison(control, test); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - return compareNodeLists(controlChildren, testChildren); - } - - /** - * Dispatches to the node type specific comparison if one is - * defined for the given combination of nodes. - * - * <p>package private to support tests.</p> - */ - ComparisonResult nodeTypeSpecificComparison(Node control, Node test) { - switch (control.getNodeType()) { - case Node.CDATA_SECTION_NODE: - case Node.COMMENT_NODE: - case Node.TEXT_NODE: - if (test instanceof CharacterData) { - return compareCharacterData((CharacterData) control, - (CharacterData) test); - } - break; - case Node.DOCUMENT_NODE: - if (test instanceof Document) { - return compareDocuments((Document) control, - (Document) test); - } - break; - case Node.ELEMENT_NODE: - if (test instanceof Element) { - return compareElements((Element) control, - (Element) test); - } - break; - case Node.PROCESSING_INSTRUCTION_NODE: - if (test instanceof ProcessingInstruction) { - return - compareProcessingInstructions((ProcessingInstruction) control, - (ProcessingInstruction) test); - } - break; - } - return ComparisonResult.EQUAL; - } - - /** - * Compares textual content. - */ - private ComparisonResult compareCharacterData(CharacterData control, - CharacterData test) { - return compare(new Comparison(ComparisonType.TEXT_VALUE, control, - null, control.getData(), - test, null, test.getData())); - } - - ComparisonResult compareDocuments(Document control, - Document test) { - DocumentType controlDt = control.getDoctype(); - DocumentType testDt = test.getDoctype(); - ComparisonResult r = - compare(new Comparison(ComparisonType.HAS_DOCTYPE_DECLARATION, - control, null, - Boolean.valueOf(controlDt != null), - test, null, - Boolean.valueOf(testDt != null))); - if (r == ComparisonResult.CRITICAL) { - return r; - } - if (controlDt != null && testDt != null) { - r = compareDocTypes(controlDt, testDt); - } - if (r == ComparisonResult.CRITICAL) { - return r; - } - r = compare(new Comparison(ComparisonType.XML_VERSION, - control, null, control.getXmlVersion(), - test, null, test.getXmlVersion())); - if (r == ComparisonResult.CRITICAL) { - return r; - } - r = compare(new Comparison(ComparisonType.XML_STANDALONE, - control, null, control.getXmlStandalone(), - test, null, test.getXmlStandalone())); - if (r == ComparisonResult.CRITICAL) { - return r; - } - return compare(new Comparison(ComparisonType.XML_ENCODING, - control, null, control.getXmlEncoding(), - test, null, test.getXmlEncoding())); - } - - ComparisonResult compareDocTypes(DocumentType control, - DocumentType test) { - ComparisonResult r = - compare(new Comparison(ComparisonType.DOCTYPE_NAME, - control, null, control.getName(), - test, null, test.getName())); - if (r == ComparisonResult.CRITICAL) { - return r; - } - r = compare(new Comparison(ComparisonType.DOCTYPE_PUBLIC_ID, - control, null, control.getPublicId(), - test, null, test.getPublicId())); - if (r == ComparisonResult.CRITICAL) { - return r; - } - return compare(new Comparison(ComparisonType.DOCTYPE_SYSTEM_ID, - control, null, control.getSystemId(), - test, null, test.getSystemId())); - } - - ComparisonResult compareElements(Element control, - Element test) { - return ComparisonResult.EQUAL; - } - - ComparisonResult - compareProcessingInstructions(ProcessingInstruction control, - ProcessingInstruction test) { - ComparisonResult r = - compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_TARGET, - control, null, control.getTarget(), - test, null, test.getTarget())); - if (r == ComparisonResult.CRITICAL) { - return r; - } - return compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, - control, null, control.getData(), - test, null, test.getData())); - } - - ComparisonResult compareNodeLists(NodeList control, NodeList test) { - return ComparisonResult.EQUAL; - } -} Copied: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml (from rev 407, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java) =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-06-28 15:25:39 UTC (rev 408) @@ -0,0 +1,179 @@ +<?xml version="1.0"?> +<!-- + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<class ns="net.sf.xmlunit.diff" qualifiers="public final" + name="DOMDifferenceEngine" + summary="Difference engine based on DOM." + extends="AbstractDifferenceEngine"> + + <import reference="javax.xml.transform.Source"/> + <import reference="net.sf.xmlunit.util.Convert"/> + <import reference="org.w3c.dom.CharacterData"/> + <import reference="org.w3c.dom.Document"/> + <import reference="org.w3c.dom.DocumentType"/> + <import reference="org.w3c.dom.Element"/> + <import reference="org.w3c.dom.Node"/> + <import reference="org.w3c.dom.NodeList"/> + <import reference="org.w3c.dom.ProcessingInstruction"/> + + <literal><![CDATA[ + public void compare(Source control, Source test) { + if (control == null) { + throw new IllegalArgumentException("control must not be null"); + } + if (test == null) { + throw new IllegalArgumentException("test must not be null"); + } + compareNodes(Convert.toNode(control), Convert.toNode(test)); + } + + /** + * Recursively compares two XML nodes. + * + * <p>Performs comparisons common to all node types, the performs + * the node type specific comparisons and finally recures into + * the node's child lists.</p> + * + * <p>Stops as soon as any comparison returns + * ComparisonResult.CRITICAL.</p> + * + * <p>package private to support tests.</p> + */ + ComparisonResult compareNodes(Node control, Node test) { +]]></literal> + <lastResultDef/> + <compare type="NODE_TYPE" property="getNodeType()"/> + <compare type="NAMESPACE_URI" property="getNamespaceURI()"/> + <compare type="NAMESPACE_PREFIX" property="getPrefix()"/> + <literal><![CDATA[ + NodeList controlChildren = control.getChildNodes(); + NodeList testChildren = test.getChildNodes(); +]]></literal> + <compareExpr type="CHILD_NODELIST_LENGTH" + controlExpr="controlChildren.getLength()" + testExpr="testChildren.getLength()"/> + <compareMethod method="nodeTypeSpecificComparison"/> + <literal><![CDATA[ + return compareNodeLists(controlChildren, testChildren); + } + + /** + * Dispatches to the node type specific comparison if one is + * defined for the given combination of nodes. + * + * <p>package private to support tests.</p> + */ + ComparisonResult nodeTypeSpecificComparison(Node control, Node test) { + switch (control.getNodeType()) { + case Node.CDATA_SECTION_NODE: + case Node.COMMENT_NODE: + case Node.TEXT_NODE: + if (test instanceof CharacterData) { + return compareCharacterData((CharacterData) control, + (CharacterData) test); + } + break; + case Node.DOCUMENT_NODE: + if (test instanceof Document) { + return compareDocuments((Document) control, + (Document) test); + } + break; + case Node.ELEMENT_NODE: + if (test instanceof Element) { + return compareElements((Element) control, + (Element) test); + } + break; + case Node.PROCESSING_INSTRUCTION_NODE: + if (test instanceof ProcessingInstruction) { + return + compareProcessingInstructions((ProcessingInstruction) control, + (ProcessingInstruction) test); + } + break; + } + return ComparisonResult.EQUAL; + } + + /** + * Compares textual content. + */ + private ComparisonResult compareCharacterData(CharacterData control, + CharacterData test) { + return compare(new Comparison(ComparisonType.TEXT_VALUE, control, + null, control.getData(), + test, null, test.getData())); + } + + ComparisonResult compareDocuments(Document control, + Document test) { + DocumentType controlDt = control.getDoctype(); + DocumentType testDt = test.getDoctype(); +]]></literal> + <lastResultDef/> + <compareExpr type="HAS_DOCTYPE_DECLARATION" + controlExpr="Boolean.valueOf(controlDt != null)" + testExpr="Boolean.valueOf(testDt != null)"/> + <literal><![CDATA[ + if (controlDt != null && testDt != null) { +]]></literal> + <compareMethodExpr method="compareDocTypes" + controlExpr="controlDt" + testExpr="testDt"/> + <literal><![CDATA[ + } +]]></literal> + <compare type="XML_VERSION" property="getXmlVersion()"/> + <compare type="XML_STANDALONE" property="getXmlStandalone()"/> + <literal><![CDATA[ + return compare(new Comparison(ComparisonType.XML_ENCODING, + control, null, control.getXmlEncoding(), + test, null, test.getXmlEncoding())); + } + + ComparisonResult compareDocTypes(DocumentType control, + DocumentType test) { +]]></literal> + <lastResultDef/> + <compare type="DOCTYPE_NAME" property="getName()"/> + <compare type="DOCTYPE_PUBLIC_ID" property="getPublicId()"/> + <literal><![CDATA[ + return compare(new Comparison(ComparisonType.DOCTYPE_SYSTEM_ID, + control, null, control.getSystemId(), + test, null, test.getSystemId())); + } + + ComparisonResult compareElements(Element control, + Element test) { + return ComparisonResult.EQUAL; + } + + ComparisonResult + compareProcessingInstructions(ProcessingInstruction control, + ProcessingInstruction test) { +]]></literal> + <lastResultDef/> + <compare type="PROCESSING_INSTRUCTION_TARGET" property="getTarget()"/> + <literal><![CDATA[ + return compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, + control, null, control.getData(), + test, null, test.getData())); + } + + ComparisonResult compareNodeLists(NodeList control, NodeList test) { + return ComparisonResult.EQUAL; + } +]]></literal> +</class> \ No newline at end of file Deleted: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs 2010-06-28 11:49:08 UTC (rev 407) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs 2010-06-28 15:25:39 UTC (rev 408) @@ -1,158 +0,0 @@ -/* - This file is licensed to You under the Apache License, Version 2.0 - (the "License"); you may not use this file except in compliance with - the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -using System; -using System.Xml; - -namespace net.sf.xmlunit.diff { - - /// <summary> - /// Difference engine based on DOM. - /// </summary> - public sealed class DOMDifferenceEngine : AbstractDifferenceEngine { - - public override void Compare(ISource control, ISource test) { - if (control == null) { - throw new ArgumentNullException("control"); - } - if (test == null) { - throw new ArgumentNullException("test"); - } - - CompareNodes(net.sf.xmlunit.util.Convert.ToNode(control), - net.sf.xmlunit.util.Convert.ToNode(test)); - } - - /// <summary> - /// Recursively compares two XML nodes. - /// </summary> - /// <remarks> - /// Performs comparisons common to all node types, the performs - /// the node type specific comparisons and finally recures into - /// the node's child lists. - /// - /// Stops as soon as any comparison returns ComparisonResult.CRITICAL. - /// </remarks> - internal ComparisonResult CompareNodes(XmlNode control, XmlNode test) { - ComparisonResult lastResult = - Compare(new Comparison(ComparisonType.NODE_TYPE, control, - null, control.NodeType, - test, null, test.NodeType)); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - lastResult = - Compare(new Comparison(ComparisonType.NAMESPACE_URI, control, - null, control.NamespaceURI, - test, null, test.NamespaceURI)); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - lastResult = - Compare(new Comparison(ComparisonType.NAMESPACE_PREFIX, control, - null, control.Prefix, - test, null, test.Prefix)); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - XmlNodeList controlChildren = control.ChildNodes; - XmlNodeList testChildren = test.ChildNodes; - lastResult = - Compare(new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, - control, null, controlChildren.Count, - test, null, testChildren.Count)); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - lastResult = NodeTypeSpecificComparison(control, test); - if (lastResult == ComparisonResult.CRITICAL) { - return lastResult; - } - return CompareNodeLists(controlChildren, testChildren); - } - - /// <summary> - /// Dispatches to the node type specific comparison if one is - /// defined for the given combination of nodes. - /// </summary> - internal ComparisonResult NodeTypeSpecificComparison(XmlNode control, - XmlNode test) { - switch (control.NodeType) { - case XmlNodeType.CDATA: - case XmlNodeType.Comment: - case XmlNodeType.Text: - if (test is XmlCharacterData) { - return CompareCharacterData((XmlCharacterData) control, - (XmlCharacterData) test); - } - break; - case XmlNodeType.Document: -#if false - if (test instanceof Document) { - return compareDocuments((Document) control, - (Document) test); - } -#endif - break; - case XmlNodeType.Element: -#if false - if (test instanceof Element) { - return compareElements((Element) control, - (Element) test); - } -#endif - break; - case XmlNodeType.ProcessingInstruction: - if (test is XmlProcessingInstruction) { - return - CompareProcessingInstructions((XmlProcessingInstruction) control, - (XmlProcessingInstruction) test); - } - break; - } - return ComparisonResult.EQUAL; - } - - /// <summary> - /// Compares textual content. - /// </summary> - private ComparisonResult CompareCharacterData(XmlCharacterData control, - XmlCharacterData test) { - return Compare(new Comparison(ComparisonType.TEXT_VALUE, control, - null, control.Data, - test, null, test.Data)); - } - - private ComparisonResult - CompareProcessingInstructions(XmlProcessingInstruction control, - XmlProcessingInstruction test) { - ComparisonResult r = - Compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_TARGET, - control, null, control.Target, - test, null, test.Target)); - if (r == ComparisonResult.CRITICAL) { - return r; - } - return Compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, - control, null, control.Data, - test, null, test.Data)); - } - - ComparisonResult CompareNodeLists(XmlNodeList control, - XmlNodeList test) { - return ComparisonResult.EQUAL; - } - - } -} Copied: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml (from rev 407, trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs) =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml (rev 0) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-06-28 15:25:39 UTC (rev 408) @@ -0,0 +1,135 @@ +<?xml version="1.0"?> +<!-- + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<class ns="net.sf.xmlunit.diff" qualifiers="public sealed" + name="DOMDifferenceEngine" + summary="Difference engine based on DOM." + extends="AbstractDifferenceEngine"> + + <import reference="System"/> + <import reference="System.Xml"/> + + <literal><![CDATA[ + + public override void Compare(ISource control, ISource test) { + if (control == null) { + throw new ArgumentNullException("control"); + } + if (test == null) { + throw new ArgumentNullException("test"); + } + + CompareNodes(net.sf.xmlunit.util.Convert.ToNode(control), + net.sf.xmlunit.util.Convert.ToNode(test)); + } + + /// <summary> + /// Recursively compares two XML nodes. + /// </summary> + /// <remarks> + /// Performs comparisons common to all node types, the performs + /// the node type specific comparisons and finally recures into + /// the node's child lists. + /// + /// Stops as soon as any comparison returns ComparisonResult.CRITICAL. + /// </remarks> + internal ComparisonResult CompareNodes(XmlNode control, XmlNode test) { +]]></literal> + <lastResultDef/> + <compare type="NODE_TYPE" property="NodeType"/> + <compare type="NAMESPACE_URI" property="NamespaceURI"/> + <compare type="NAMESPACE_PREFIX" property="Prefix"/> + <literal><![CDATA[ + XmlNodeList controlChildren = control.ChildNodes; + XmlNodeList testChildren = test.ChildNodes; +]]></literal> + <compareExpr type="CHILD_NODELIST_LENGTH" + controlExpr="controlChildren.Count" + testExpr="testChildren.Count"/> + <compareMethod method="NodeTypeSpecificComparison"/> + <literal><![CDATA[ + return CompareNodeLists(controlChildren, testChildren); + } + + /// <summary> + /// Dispatches to the node type specific comparison if one is + /// defined for the given combination of nodes. + /// </summary> + internal ComparisonResult NodeTypeSpecificComparison(XmlNode control, + XmlNode test) { + switch (control.NodeType) { + case XmlNodeType.CDATA: + case XmlNodeType.Comment: + case XmlNodeType.Text: + if (test is XmlCharacterData) { + return CompareCharacterData((XmlCharacterData) control, + (XmlCharacterData) test); + } + break; + case XmlNodeType.Document: +#if false + if (test instanceof Document) { + return compareDocuments((Document) control, + (Document) test); + } +#endif + break; + case XmlNodeType.Element: +#if false + if (test instanceof Element) { + return compareElements((Element) control, + (Element) test); + } +#endif + break; + case XmlNodeType.ProcessingInstruction: + if (test is XmlProcessingInstruction) { + return + CompareProcessingInstructions((XmlProcessingInstruction) control, + (XmlProcessingInstruction) test); + } + break; + } + return ComparisonResult.EQUAL; + } + + /// <summary> + /// Compares textual content. + /// </summary> + private ComparisonResult CompareCharacterData(XmlCharacterData control, + XmlCharacterData test) { + return Compare(new Comparison(ComparisonType.TEXT_VALUE, control, + null, control.Data, + test, null, test.Data)); + } + + private ComparisonResult + CompareProcessingInstructions(XmlProcessingInstruction control, + XmlProcessingInstruction test) { +]]></literal> + <lastResultDef/> + <compare type="PROCESSING_INSTRUCTION_TARGET" property="Target"/> + <literal><![CDATA[ + return Compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, + control, null, control.Data, + test, null, test.Data)); + } + + ComparisonResult CompareNodeLists(XmlNodeList control, + XmlNodeList test) { + return ComparisonResult.EQUAL; + } + +]]></literal> +</class> \ No newline at end of file Modified: trunk/xmlunit/xmlunit.nant.build =================================================================== --- trunk/xmlunit/xmlunit.nant.build 2010-06-28 11:49:08 UTC (rev 407) +++ trunk/xmlunit/xmlunit.nant.build 2010-06-28 15:25:39 UTC (rev 408) @@ -22,9 +22,9 @@ <property name="core.tests.src.dir" value="${base.dir}/src/tests/net-core" overwrite="false"/> - <property name="gen.src.dir" value="${base.dir}/build/generated/net" + <property name="build.dir" value="${base.dir}/build/net" overwrite="false"/> + <property name="gen.src.dir" value="${build.dir}/generated" overwrite="false"/> - <property name="build.dir" value="${base.dir}/build/net" overwrite="false"/> <property name="test.report.dir" value="${build.dir}/test-report"/> <property name="bin.dir" value="${build.dir}/bin" overwrite="false"/> @@ -74,6 +74,26 @@ <include name="**/*.cs"/> </fileset> </copy> + <style destdir="${gen.src.dir}" + extension="cs" + style="src/buildtools/codegen.xslt"> + <infiles basedir="${core.src.dir}"> + <include name="**/*.xml"/> + </infiles> + <parameters> + + <parameter name="nsQualifier" value="namespace"/> + <parameter name="nsStart" value="{"/> + <parameter name="nsEnd" value="}"/> + <parameter name="import" value="using"/> + <parameter name="extends" value=":"/> + <parameter name="implements" value=":"/> + <parameter name="summaryStart" value="/// <summary>"/> + <parameter name="summaryEnd" value="/// </summary>"/> + + <parameter name="compareMethod" value="Compare"/> + </parameters> + </style> <csc target="library" output="${bin.dir}/${project::get-name()}-core.dll" debug="true" verbose="${csc.verbose}"> <sources basedir="${gen.src.dir}"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |