You can subscribe to this list here.
2007 |
Jan
|
Feb
(3) |
Mar
(18) |
Apr
(39) |
May
(15) |
Jun
(12) |
Jul
(3) |
Aug
(23) |
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(21) |
Feb
(23) |
Mar
(33) |
Apr
(8) |
May
(1) |
Jun
(22) |
Jul
|
Aug
(1) |
Sep
(1) |
Oct
(6) |
Nov
|
Dec
(11) |
2009 |
Jan
(5) |
Feb
|
Mar
(2) |
Apr
(24) |
May
(36) |
Jun
(18) |
Jul
(2) |
Aug
(3) |
Sep
(9) |
Oct
(3) |
Nov
(1) |
Dec
|
2010 |
Jan
(5) |
Feb
(3) |
Mar
|
Apr
(15) |
May
(24) |
Jun
(11) |
Jul
(8) |
Aug
(34) |
Sep
(42) |
Oct
|
Nov
|
Dec
|
2011 |
Jan
(13) |
Feb
(32) |
Mar
(35) |
Apr
(31) |
May
(33) |
Jun
(30) |
Jul
(32) |
Aug
(31) |
Sep
(30) |
Oct
(31) |
Nov
(32) |
Dec
(31) |
2012 |
Jan
(35) |
Feb
(31) |
Mar
(31) |
Apr
(30) |
May
(31) |
Jun
(34) |
Jul
(23) |
Aug
(30) |
Sep
(30) |
Oct
(29) |
Nov
(30) |
Dec
(32) |
2013 |
Jan
(25) |
Feb
(39) |
Mar
(1) |
Apr
(18) |
May
(1) |
Jun
|
Jul
(1) |
Aug
(20) |
Sep
(41) |
Oct
(32) |
Nov
(9) |
Dec
(31) |
2014 |
Jan
(31) |
Feb
(30) |
Mar
(34) |
Apr
(60) |
May
(31) |
Jun
(28) |
Jul
(32) |
Aug
(28) |
Sep
(26) |
Oct
(32) |
Nov
(43) |
Dec
(115) |
2015 |
Jan
(106) |
Feb
(101) |
Mar
(51) |
Apr
(32) |
May
(63) |
Jun
(18) |
Jul
|
Aug
(18) |
Sep
|
Oct
(1) |
Nov
(84) |
Dec
(63) |
2016 |
Jan
(26) |
Feb
(17) |
Mar
(104) |
Apr
(30) |
May
(6) |
Jun
(30) |
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(48) |
Dec
(22) |
2017 |
Jan
(15) |
Feb
(29) |
Mar
(43) |
Apr
(29) |
May
(25) |
Jun
(28) |
Jul
(62) |
Aug
(35) |
Sep
(35) |
Oct
(72) |
Nov
(10) |
Dec
(4) |
2018 |
Jan
(7) |
Feb
(4) |
Mar
|
Apr
(46) |
May
(20) |
Jun
(12) |
Jul
(9) |
Aug
(42) |
Sep
(4) |
Oct
(17) |
Nov
(32) |
Dec
(31) |
2019 |
Jan
(21) |
Feb
(14) |
Mar
|
Apr
(74) |
May
(25) |
Jun
(43) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(10) |
2020 |
Jan
(1) |
Feb
|
Mar
(26) |
Apr
(8) |
May
(62) |
Jun
(4) |
Jul
(25) |
Aug
|
Sep
(21) |
Oct
(24) |
Nov
(26) |
Dec
(9) |
2021 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
(11) |
Nov
(1) |
Dec
(12) |
2022 |
Jan
(47) |
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(14) |
2023 |
Jan
(3) |
Feb
|
Mar
(60) |
Apr
(9) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2024 |
Jan
(5) |
Feb
|
Mar
|
Apr
(10) |
May
(1) |
Jun
|
Jul
|
Aug
(17) |
Sep
(2) |
Oct
|
Nov
|
Dec
(1) |
2025 |
Jan
|
Feb
|
Mar
(88) |
Apr
(64) |
May
(47) |
Jun
(20) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Stefan B. <bo...@ap...> - 2011-01-23 06:29:07
|
To whom it may engage... This is an automated request, but not an unsolicited one. For more information please visit http://gump.apache.org/nagged.html, and/or contact the folk at ge...@gu.... Project net.sf.xmlunit has an issue affecting its community integration. This issue affects 16 projects, and has been outstanding for 3 runs. The current state of this project is 'Failed', with reason 'Build Failed'. For reference only, the following projects are affected by this: - commons-jelly-tags-jmx : Commons Jelly - commons-jelly-tags-xmlunit : Commons Jelly - fulcrum-cache : Services Framework - fulcrum-cache-test : Services Framework - jakarta-turbine-jcs : Cache - jcs : Cache - jgroups : A Reliable Multicast Communication Toolkit for Java - mx4j : OpenSource implementation of a JMX agent - mx4j-remote : OpenSource implementation of a JMX agent - mx4j-tools : OpenSource implementation of a JMX agent - net.sf.xmlunit : JUnit extension for XML unit tests. - turbine-core : A servlet based framework. - turbine-core-test : A servlet based framework. - ws-axis-test : Apache eXtensible Interaction System - xml-xindice : native XML database - xmlunit : JUnit extension for XML unit tests. Full details are available at: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/index.html That said, some information snippets are provided here. The following annotations (debug/informational/warning/error messages) were provided: -INFO- Failed with reason build failed -DEBUG- Extracted fallback artifacts from Gump Repository The following work was performed: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/gump_work/build_xmlunit_net.sf.xmlunit.html Work Name: build_xmlunit_net.sf.xmlunit (Type: Build) Work ended in a state of : Failed Elapsed: 30 secs Command Line: /usr/lib/jvm/java-6-openjdk/bin/java -Djava.awt.headless=true -Dbuild.sysclasspath=only -Xbootclasspath/p:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis.jar:/srv/gump/public/workspace/xml-xerces2/build/xercesImpl.jar:/srv/gump/public/workspace/xml-xalan/build/xalan-unbundled.jar:/srv/gump/public/workspace/xml-xalan/build/serializer.jar org.apache.tools.ant.Main -Dgump.merge=/srv/gump/public/gump/work/merge.xml -Dxmlunit.version=23012011 Gump [Working Directory: /srv/gump/public/workspace/xmlunit] CLASSPATH: /usr/lib/jvm/java-6-openjdk/lib/tools.jar:/srv/gump/public/workspace/xmlunit/build/java/core-classes:/srv/gump/public/workspace/xmlunit/build/java/core-test-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes:/srv/gump/public/workspace/ant/dist/lib/ant.jar:/srv/gump/public/workspace/ant/dist/lib/ant-launcher.jar:/srv/gump/public/workspace/ant/dist/lib/ant-jmf.jar:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar:/srv/gump/public/workspace/ant/dist/lib/ant-swing.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-resolver.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-xalan2.jar:/srv/gump/packages/junit3.8.1/junit.jar:/srv/gump/public/workspace/xml-commons/java/build/resolver.jar:/srv/gump/public/workspace/junit/dist/junit-23012011.jar:/srv/gump/public/workspace/junit/dist/junit-dep-23012011.jar:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis-ext.jar --------------------------------------------- [junit] TEST org.custommonkey.xmlunit.test_Transform FAILED [junit] Running org.custommonkey.xmlunit.test_Validator [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.174 sec [junit] Running org.custommonkey.xmlunit.test_XMLTestCase [junit] Tests run: 22, Failures: 0, Errors: 0, Time elapsed: 1.514 sec [junit] Running org.custommonkey.xmlunit.test_XMLUnit [junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.066 sec [junit] Running org.custommonkey.xmlunit.test_XpathNodeTracker [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.015 sec [junit] Running org.custommonkey.xmlunit.util.test_IntegerBuffer [junit] Tests run: 13, Failures: 0, Errors: 0, Time elapsed: 0.08 sec [junit] Running net.sf.xmlunit.builder.InputTest [junit] Tests run: 12, Failures: 2, Errors: 0, Time elapsed: 0.438 sec [junit] TEST net.sf.xmlunit.builder.InputTest FAILED [junit] Running net.sf.xmlunit.builder.TransformTest [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.033 sec [junit] Running net.sf.xmlunit.diff.ComparisonListenerSupportTest [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.005 sec [junit] Running net.sf.xmlunit.diff.DOMDifferenceEngineTest [junit] Tests run: 24, Failures: 0, Errors: 0, Time elapsed: 0.135 sec [junit] Running net.sf.xmlunit.diff.DifferenceEvaluatorsTest [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.007 sec [junit] Running net.sf.xmlunit.diff.ElementSelectorsTest [junit] Tests run: 13, Failures: 0, Errors: 0, Time elapsed: 0.037 sec [junit] Running net.sf.xmlunit.diff.XPathContextTest [junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.017 sec [junit] Running net.sf.xmlunit.input.CommentLessSourceTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.008 sec [junit] Running net.sf.xmlunit.transform.TransformationTest [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.042 sec [junit] Running net.sf.xmlunit.util.ConvertTest [junit] Tests run: 11, Failures: 0, Errors: 0, Time elapsed: 0.093 sec [junit] Running net.sf.xmlunit.util.NodesTest [junit] Tests run: 17, Failures: 0, Errors: 0, Time elapsed: 0.102 sec [junit] Running net.sf.xmlunit.validation.JAXPValidatorTest [junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.05 sec [junit] Running net.sf.xmlunit.validation.ParsingValidatorTest [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.054 sec [junit] Running net.sf.xmlunit.xpath.JAXPXPathEngineTest [junit] Tests run: 12, Failures: 0, Errors: 0, Time elapsed: 0.096 sec [junit] Tests FAILED [junitreport] Processing /srv/gump/public/workspace/xmlunit/build/java/test-report/TESTS-TestSuites.xml to /tmp/null1178156990 [junitreport] Loading stylesheet jar:file:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] Transform time: 4628ms [junitreport] Deleting: /tmp/null1178156990 BUILD FAILED /srv/gump/public/workspace/xmlunit/build.xml:172: Some tests failed Total time: 30 seconds --------------------------------------------- To subscribe to this information via syndicated feeds: - RSS: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/rss.xml - Atom: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/atom.xml ============================== Gump Tracking Only === Produced by Apache Gump(TM) version 2.3. Gump Run 07000623012011, vmgump.apache.org:vmgump:07000623012011 Gump E-mail Identifier (unique within run) #3. -- Apache Gump http://gump.apache.org/ [Instance: vmgump] |
From: Stefan B. <bo...@ap...> - 2011-01-22 06:29:16
|
To whom it may engage... This is an automated request, but not an unsolicited one. For more information please visit http://gump.apache.org/nagged.html, and/or contact the folk at ge...@gu.... Project net.sf.xmlunit has an issue affecting its community integration. This issue affects 16 projects. The current state of this project is 'Failed', with reason 'Build Failed'. For reference only, the following projects are affected by this: - commons-jelly-tags-jmx : Commons Jelly - commons-jelly-tags-xmlunit : Commons Jelly - fulcrum-cache : Services Framework - fulcrum-cache-test : Services Framework - jakarta-turbine-jcs : Cache - jcs : Cache - jgroups : A Reliable Multicast Communication Toolkit for Java - mx4j : OpenSource implementation of a JMX agent - mx4j-remote : OpenSource implementation of a JMX agent - mx4j-tools : OpenSource implementation of a JMX agent - net.sf.xmlunit : JUnit extension for XML unit tests. - turbine-core : A servlet based framework. - turbine-core-test : A servlet based framework. - ws-axis-test : Apache eXtensible Interaction System - xml-xindice : native XML database - xmlunit : JUnit extension for XML unit tests. Full details are available at: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/index.html That said, some information snippets are provided here. The following annotations (debug/informational/warning/error messages) were provided: -INFO- Failed with reason build failed -DEBUG- Extracted fallback artifacts from Gump Repository The following work was performed: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/gump_work/build_xmlunit_net.sf.xmlunit.html Work Name: build_xmlunit_net.sf.xmlunit (Type: Build) Work ended in a state of : Failed Elapsed: 30 secs Command Line: /usr/lib/jvm/java-6-openjdk/bin/java -Djava.awt.headless=true -Dbuild.sysclasspath=only -Xbootclasspath/p:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis.jar:/srv/gump/public/workspace/xml-xerces2/build/xercesImpl.jar:/srv/gump/public/workspace/xml-xalan/build/xalan-unbundled.jar:/srv/gump/public/workspace/xml-xalan/build/serializer.jar org.apache.tools.ant.Main -Dgump.merge=/srv/gump/public/gump/work/merge.xml -Dxmlunit.version=22012011 Gump [Working Directory: /srv/gump/public/workspace/xmlunit] CLASSPATH: /usr/lib/jvm/java-6-openjdk/lib/tools.jar:/srv/gump/public/workspace/xmlunit/build/java/core-classes:/srv/gump/public/workspace/xmlunit/build/java/core-test-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-classes:/srv/gump/public/workspace/xmlunit/build/java/legacy-test-classes:/srv/gump/public/workspace/ant/dist/lib/ant.jar:/srv/gump/public/workspace/ant/dist/lib/ant-launcher.jar:/srv/gump/public/workspace/ant/dist/lib/ant-jmf.jar:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar:/srv/gump/public/workspace/ant/dist/lib/ant-swing.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-resolver.jar:/srv/gump/public/workspace/ant/dist/lib/ant-apache-xalan2.jar:/srv/gump/packages/junit3.8.1/junit.jar:/srv/gump/public/workspace/xml-commons/java/build/resolver.jar:/srv/gump/public/workspace/junit/dist/junit-22012011.jar:/srv/gump/public/workspace/junit/dist/junit-dep-22012011.jar:/srv/gump/public/workspace/xml-commons/java/external/build/xml-apis-ext.jar --------------------------------------------- [junit] TEST org.custommonkey.xmlunit.test_Transform FAILED [junit] Running org.custommonkey.xmlunit.test_Validator [junit] Tests run: 5, Failures: 0, Errors: 0, Time elapsed: 0.093 sec [junit] Running org.custommonkey.xmlunit.test_XMLTestCase [junit] Tests run: 22, Failures: 0, Errors: 0, Time elapsed: 1.266 sec [junit] Running org.custommonkey.xmlunit.test_XMLUnit [junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.061 sec [junit] Running org.custommonkey.xmlunit.test_XpathNodeTracker [junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.026 sec [junit] Running org.custommonkey.xmlunit.util.test_IntegerBuffer [junit] Tests run: 13, Failures: 0, Errors: 0, Time elapsed: 0.067 sec [junit] Running net.sf.xmlunit.builder.InputTest [junit] Tests run: 12, Failures: 2, Errors: 0, Time elapsed: 0.207 sec [junit] TEST net.sf.xmlunit.builder.InputTest FAILED [junit] Running net.sf.xmlunit.builder.TransformTest [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.028 sec [junit] Running net.sf.xmlunit.diff.ComparisonListenerSupportTest [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.003 sec [junit] Running net.sf.xmlunit.diff.DOMDifferenceEngineTest [junit] Tests run: 24, Failures: 0, Errors: 0, Time elapsed: 0.086 sec [junit] Running net.sf.xmlunit.diff.DifferenceEvaluatorsTest [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.003 sec [junit] Running net.sf.xmlunit.diff.ElementSelectorsTest [junit] Tests run: 13, Failures: 0, Errors: 0, Time elapsed: 0.021 sec [junit] Running net.sf.xmlunit.diff.XPathContextTest [junit] Tests run: 8, Failures: 0, Errors: 0, Time elapsed: 0.016 sec [junit] Running net.sf.xmlunit.input.CommentLessSourceTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.006 sec [junit] Running net.sf.xmlunit.transform.TransformationTest [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0.034 sec [junit] Running net.sf.xmlunit.util.ConvertTest [junit] Tests run: 11, Failures: 0, Errors: 0, Time elapsed: 0.064 sec [junit] Running net.sf.xmlunit.util.NodesTest [junit] Tests run: 17, Failures: 0, Errors: 0, Time elapsed: 0.078 sec [junit] Running net.sf.xmlunit.validation.JAXPValidatorTest [junit] Tests run: 6, Failures: 0, Errors: 0, Time elapsed: 0.064 sec [junit] Running net.sf.xmlunit.validation.ParsingValidatorTest [junit] Tests run: 4, Failures: 0, Errors: 0, Time elapsed: 0.057 sec [junit] Running net.sf.xmlunit.xpath.JAXPXPathEngineTest [junit] Tests run: 12, Failures: 0, Errors: 0, Time elapsed: 0.082 sec [junit] Tests FAILED [junitreport] Processing /srv/gump/public/workspace/xmlunit/build/java/test-report/TESTS-TestSuites.xml to /tmp/null1396034333 [junitreport] Loading stylesheet jar:file:/srv/gump/public/workspace/ant/dist/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl [junitreport] Transform time: 4612ms [junitreport] Deleting: /tmp/null1396034333 BUILD FAILED /srv/gump/public/workspace/xmlunit/build.xml:172: Some tests failed Total time: 30 seconds --------------------------------------------- To subscribe to this information via syndicated feeds: - RSS: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/rss.xml - Atom: http://vmgump.apache.org/gump/public/xmlunit/net.sf.xmlunit/atom.xml ============================== Gump Tracking Only === Produced by Apache Gump(TM) version 2.3. Gump Run 06000622012011, vmgump.apache.org:vmgump:06000622012011 Gump E-mail Identifier (unique within run) #3. -- Apache Gump http://gump.apache.org/ [Instance: vmgump] |
From: <bo...@us...> - 2010-09-24 10:52:29
|
Revision: 485 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=485&view=rev Author: bodewig Date: 2010-09-24 10:52:22 +0000 (Fri, 24 Sep 2010) Log Message: ----------- exception handling Modified 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/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java 2010-09-24 10:42:48 UTC (rev 484) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java 2010-09-24 10:52:22 UTC (rev 485) @@ -23,6 +23,7 @@ import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.transform.Source; +import net.sf.xmlunit.exceptions.XMLUnitException; import net.sf.xmlunit.util.Convert; import net.sf.xmlunit.util.IterableNodeList; import net.sf.xmlunit.util.Linqy; @@ -37,6 +38,7 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; + /** * Difference engine based on DOM. */ @@ -49,8 +51,13 @@ if (test == null) { throw new IllegalArgumentException("test must not be null"); } - compareNodes(Convert.toNode(control), new XPathContext(), - Convert.toNode(test), new XPathContext()); + try { + compareNodes(Convert.toNode(control), new XPathContext(), + Convert.toNode(test), new XPathContext()); + } catch (Exception ex) { + throw new XMLUnitException("Caught exception during comparison", + ex); + } } /** Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs 2010-09-24 10:42:48 UTC (rev 484) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs 2010-09-24 10:52:22 UTC (rev 485) @@ -16,6 +16,7 @@ using System.Collections.Generic; using System.Xml; using System.Xml.Schema; +using net.sf.xmlunit.exceptions; using net.sf.xmlunit.util; namespace net.sf.xmlunit.diff{ @@ -34,11 +35,15 @@ if (test == null) { throw new ArgumentNullException("test"); } - - CompareNodes(net.sf.xmlunit.util.Convert.ToNode(control), - new XPathContext(), - net.sf.xmlunit.util.Convert.ToNode(test), - new XPathContext()); + try { + CompareNodes(net.sf.xmlunit.util.Convert.ToNode(control), + new XPathContext(), + net.sf.xmlunit.util.Convert.ToNode(test), + new XPathContext()); + } catch (Exception ex) { + throw new XMLUnitException("Caught exception during comparison", + ex); + } } /// <summary> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-24 10:42:56
|
Revision: 484 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=484&view=rev Author: bodewig Date: 2010-09-24 10:42:48 +0000 (Fri, 24 Sep 2010) Log Message: ----------- revert code-generation experiment, it didn't help reducing duplicate code as much as I had hoped Modified Paths: -------------- trunk/xmlunit/build.xml trunk/xmlunit/xmlunit.nant.build Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs Removed Paths: ------------- 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 Modified: trunk/xmlunit/build.xml =================================================================== --- trunk/xmlunit/build.xml 2010-09-24 09:54:53 UTC (rev 483) +++ trunk/xmlunit/build.xml 2010-09-24 10:42:48 UTC (rev 484) @@ -80,28 +80,7 @@ </delete> </target> - <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="getXPath" expression="getXPath"/> - - <param name="compareMethod" expression="compare"/> - </xslt> - </target> - - <target name="compile-core" depends="-init,-generate-sources" + <target name="compile-core" depends="-init" description="compiles core sources"> <javac srcdir="${src.dir}/java-core:${gen.src.dir}" destdir="${core.out.dir}" Deleted: trunk/xmlunit/src/buildtools/codegen.xslt =================================================================== --- trunk/xmlunit/src/buildtools/codegen.xslt 2010-09-24 09:54:53 UTC (rev 483) +++ trunk/xmlunit/src/buildtools/codegen.xslt 2010-09-24 10:42:48 UTC (rev 484) @@ -1,137 +0,0 @@ -<?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:param name="getXPath"/> - - <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, <xsl:value-of select="$getXPath"/>(controlContext), - control.<xsl:value-of select="@property"/>, - test, <xsl:value-of select="$getXPath"/>(testContext), - 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, <xsl:value-of select="$getXPath"/>(controlContext), - <xsl:value-of select="@controlExpr"/>, - test, <xsl:value-of select="$getXPath"/>(testContext), - <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, controlContext, - test, testContext); - <xsl:call-template name="if-return-boilerplate"/> - </xsl:template> - - <xsl:template match="compareMethodExpr"> - lastResult = <xsl:value-of select="@method"/>(<xsl:value-of select="@controlExpr"/>, controlContext, - <xsl:value-of select="@testExpr"/>, testContext); - <xsl:call-template name="if-return-boilerplate"/> - </xsl:template> - - <xsl:template match="if-return-boilerplate"> - <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> Copied: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java (from rev 483, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml) =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java 2010-09-24 10:42:48 UTC (rev 484) @@ -0,0 +1,645 @@ +/* + 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 java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import javax.xml.transform.Source; +import net.sf.xmlunit.util.Convert; +import net.sf.xmlunit.util.IterableNodeList; +import net.sf.xmlunit.util.Linqy; +import net.sf.xmlunit.util.Nodes; +import net.sf.xmlunit.util.Predicate; +import org.w3c.dom.Attr; +import org.w3c.dom.CharacterData; +import org.w3c.dom.Document; +import org.w3c.dom.DocumentType; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +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), new XPathContext(), + Convert.toNode(test), new XPathContext()); + } + + /** + * Recursively compares two XML nodes. + * + * <p>Performs comparisons common to all node types, then performs + * the node type specific comparisons and finally recurses 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, XPathContext controlContext, + Node test, XPathContext testContext) { + ComparisonResult lastResult = + compare(new Comparison(ComparisonType.NODE_TYPE, + control, getXPath(controlContext), + control.getNodeType(), + test, getXPath(testContext), + test.getNodeType())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + lastResult = + compare(new Comparison(ComparisonType.NAMESPACE_URI, + control, getXPath(controlContext), + control.getNamespaceURI(), + test, getXPath(testContext), + test.getNamespaceURI())); + + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + lastResult = + compare(new Comparison(ComparisonType.NAMESPACE_PREFIX, + control, getXPath(controlContext), + control.getPrefix(), + test, getXPath(testContext), + test.getPrefix())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + + Iterable<Node> controlChildren = + Linqy.filter(new IterableNodeList(control.getChildNodes()), + INTERESTING_NODES); + Iterable<Node> testChildren = + Linqy.filter(new IterableNodeList(test.getChildNodes()), + INTERESTING_NODES); + if (control.getNodeType() != Node.ATTRIBUTE_NODE) { + lastResult = + compare(new Comparison(ComparisonType.CHILD_NODELIST_LENGTH, + control, getXPath(controlContext), + Linqy.count(controlChildren), + test, getXPath(testContext), + Linqy.count(testChildren))); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } + + lastResult = nodeTypeSpecificComparison(control, controlContext, + test, testContext); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + if (control.getNodeType() != Node.ATTRIBUTE_NODE) { + controlContext + .setChildren(Linqy.map(controlChildren, TO_NODE_INFO)); + testContext + .setChildren(Linqy.map(testChildren, TO_NODE_INFO)); + + lastResult = compareNodeLists(controlChildren, controlContext, + testChildren, testContext); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } + return lastResult; + } + + /** + * Dispatches to the node type specific comparison if one is + * defined for the given combination of nodes. + */ + private ComparisonResult + nodeTypeSpecificComparison(Node control, + XPathContext controlContext, + Node test, XPathContext testContext) { + switch (control.getNodeType()) { + case Node.CDATA_SECTION_NODE: + case Node.COMMENT_NODE: + case Node.TEXT_NODE: + if (test instanceof CharacterData) { + return compareCharacterData((CharacterData) control, + controlContext, + (CharacterData) test, testContext); + } + break; + case Node.DOCUMENT_NODE: + if (test instanceof Document) { + return compareDocuments((Document) control, controlContext, + (Document) test, testContext); + } + break; + case Node.ELEMENT_NODE: + if (test instanceof Element) { + return compareElements((Element) control, controlContext, + (Element) test, testContext); + } + break; + case Node.PROCESSING_INSTRUCTION_NODE: + if (test instanceof ProcessingInstruction) { + return + compareProcessingInstructions((ProcessingInstruction) control, + controlContext, + (ProcessingInstruction) test, + testContext); + } + break; + case Node.DOCUMENT_TYPE_NODE: + if (test instanceof DocumentType) { + return compareDocTypes((DocumentType) control, controlContext, + (DocumentType) test, testContext); + } + break; + case Node.ATTRIBUTE_NODE: + if (test instanceof Attr) { + return compareAttributes((Attr) control, controlContext, + (Attr) test, testContext); + } + break; + } + return ComparisonResult.EQUAL; + } + + /** + * Compares textual content. + */ + private ComparisonResult compareCharacterData(CharacterData control, + XPathContext controlContext, + CharacterData test, + XPathContext testContext) { + return compare(new Comparison(ComparisonType.TEXT_VALUE, control, + getXPath(controlContext), + control.getData(), + test, getXPath(testContext), + test.getData())); + } + + /** + * Compares document node, doctype and XML declaration properties + */ + private ComparisonResult compareDocuments(Document control, + XPathContext controlContext, + Document test, + XPathContext testContext) { + DocumentType controlDt = control.getDoctype(); + DocumentType testDt = test.getDoctype(); + + ComparisonResult lastResult = + compare(new Comparison(ComparisonType.HAS_DOCTYPE_DECLARATION, + control, getXPath(controlContext), + Boolean.valueOf(controlDt != null), + test, getXPath(testContext), + Boolean.valueOf(testDt != null))); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + if (controlDt != null && testDt != null) { + lastResult = compareNodes(controlDt, controlContext, + testDt, testContext); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } + + lastResult = + compare(new Comparison(ComparisonType.XML_VERSION, + control, getXPath(controlContext), + control.getXmlVersion(), + test, getXPath(testContext), + test.getXmlVersion())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + + lastResult = + compare(new Comparison(ComparisonType.XML_STANDALONE, + control, getXPath(controlContext), + control.getXmlStandalone(), + test, getXPath(testContext), + test.getXmlStandalone())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + return compare(new Comparison(ComparisonType.XML_ENCODING, + control, getXPath(controlContext), + control.getXmlEncoding(), + test, getXPath(testContext), + test.getXmlEncoding())); + } + + /** + * Compares properties of the doctype declaration. + */ + private ComparisonResult compareDocTypes(DocumentType control, + XPathContext controlContext, + DocumentType test, + XPathContext testContext) { + ComparisonResult lastResult = + compare(new Comparison(ComparisonType.DOCTYPE_NAME, + control, getXPath(controlContext), + control.getName(), + test, getXPath(testContext), + test.getName())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + lastResult = + compare(new Comparison(ComparisonType.DOCTYPE_PUBLIC_ID, + control, getXPath(controlContext), + control.getPublicId(), + test, getXPath(testContext), + test.getPublicId())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + return compare(new Comparison(ComparisonType.DOCTYPE_SYSTEM_ID, + control, null, control.getSystemId(), + test, null, test.getSystemId())); + } + + /** + * Compares elements node properties, in particular the element's + * name and its attributes. + */ + private ComparisonResult compareElements(Element control, + XPathContext controlContext, + Element test, + XPathContext testContext) { + ComparisonResult lastResult = + compare(new Comparison(ComparisonType.ELEMENT_TAG_NAME, + control, getXPath(controlContext), + Nodes.getQName(control).getLocalPart(), + test, getXPath(testContext), + Nodes.getQName(test).getLocalPart())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + Attributes controlAttributes = splitAttributes(control.getAttributes()); + controlContext + .addAttributes(Linqy.map(controlAttributes.remainingAttributes, + QNAME_MAPPER)); + Attributes testAttributes = splitAttributes(test.getAttributes()); + testContext + .addAttributes(Linqy.map(testAttributes.remainingAttributes, + QNAME_MAPPER)); + Set<Attr> foundTestAttributes = new HashSet<Attr>(); + + lastResult = + compare(new Comparison(ComparisonType.ELEMENT_NUM_ATTRIBUTES, + control, getXPath(controlContext), + controlAttributes.remainingAttributes.size(), + test, getXPath(testContext), + testAttributes.remainingAttributes.size())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + for (Attr controlAttr : controlAttributes.remainingAttributes) { + final Attr testAttr = + findMatchingAttr(testAttributes.remainingAttributes, + controlAttr); + + controlContext.navigateToAttribute(Nodes.getQName(controlAttr)); + try { + lastResult = + compare(new Comparison(ComparisonType.ATTR_NAME_LOOKUP, + control, getXPath(controlContext), + Boolean.TRUE, + test, getXPath(testContext), + Boolean.valueOf(testAttr != null))); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + if (testAttr != null) { + testContext.navigateToAttribute(Nodes.getQName(testAttr)); + try { + lastResult = compareNodes(controlAttr, controlContext, + testAttr, testContext); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + foundTestAttributes.add(testAttr); + } finally { + testContext.navigateToParent(); + } + } + } finally { + controlContext.navigateToParent(); + } + } + + for (Attr testAttr : testAttributes.remainingAttributes) { + testContext.navigateToAttribute(Nodes.getQName(testAttr)); + try { + lastResult = + compare(new Comparison(ComparisonType.ATTR_NAME_LOOKUP, + control, getXPath(controlContext), + Boolean.valueOf(foundTestAttributes.contains(testAttr)), + test, getXPath(testContext), + Boolean.TRUE)); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } finally { + testContext.navigateToParent(); + } + } + + lastResult = + compare(new Comparison(ComparisonType.SCHEMA_LOCATION, + control, getXPath(controlContext), + controlAttributes.schemaLocation != null + ? controlAttributes.schemaLocation.getValue() + : null, + test, getXPath(testContext), + testAttributes.schemaLocation != null + ? testAttributes.schemaLocation.getValue() + : null)); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + return + compare(new Comparison(ComparisonType.NO_NAMESPACE_SCHEMA_LOCATION, + control, getXPath(controlContext), + controlAttributes.noNamespaceSchemaLocation != null ? + controlAttributes.noNamespaceSchemaLocation.getValue() + : null, + test, getXPath(testContext), + testAttributes.noNamespaceSchemaLocation != null + ? testAttributes.noNamespaceSchemaLocation.getValue() + : null)); + } + + /** + * Compares properties of a processing instruction. + */ + private ComparisonResult + compareProcessingInstructions(ProcessingInstruction control, + XPathContext controlContext, + ProcessingInstruction test, + XPathContext testContext) { + ComparisonResult lastResult = + compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_TARGET, + control, getXPath(controlContext), + control.getTarget(), + test, getXPath(testContext), + test.getTarget())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + return compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, + control, getXPath(controlContext), + control.getData(), + test, getXPath(testContext), + test.getData())); + } + + /** + * Matches nodes of two node lists and invokes compareNode on each pair. + * + * <p>Also performs CHILD_LOOKUP comparisons for each node that + * couldn't be matched to one of the "other" list.</p> + */ + private ComparisonResult compareNodeLists(Iterable<Node> controlSeq, + XPathContext controlContext, + Iterable<Node> testSeq, + XPathContext testContext) { + // if there are no children on either Node, the result is equal + ComparisonResult lastResult = ComparisonResult.EQUAL; + + Iterable<Map.Entry<Node, Node>> matches = + getNodeMatcher().match(controlSeq, testSeq); + List<Node> controlList = Linqy.asList(controlSeq); + List<Node> testList = Linqy.asList(testSeq); + Set<Node> seen = new HashSet<Node>(); + for (Map.Entry<Node, Node> pair : matches) { + Node control = pair.getKey(); + seen.add(control); + Node test = pair.getValue(); + seen.add(test); + int controlIndex = controlList.indexOf(control); + int testIndex = testList.indexOf(test); + + controlContext.navigateToChild(controlIndex); + testContext.navigateToChild(testIndex); + try { + lastResult = + compare(new Comparison(ComparisonType.CHILD_NODELIST_SEQUENCE, + control, getXPath(controlContext), + Integer.valueOf(controlIndex), + test, getXPath(testContext), + Integer.valueOf(testIndex))); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + lastResult = compareNodes(control, controlContext, + test, testContext); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } finally { + testContext.navigateToParent(); + controlContext.navigateToParent(); + } + } + + final int controlSize = controlList.size(); + for (int i = 0; i < controlSize; i++) { + if (!seen.contains(controlList.get(i))) { + controlContext.navigateToChild(i); + try { + lastResult = + compare(new Comparison(ComparisonType.CHILD_LOOKUP, + controlList.get(i), + getXPath(controlContext), + controlList.get(i), + null, null, null)); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } finally { + controlContext.navigateToParent(); + } + } + } + + final int testSize = testList.size(); + for (int i = 0; i < testSize; i++) { + if (!seen.contains(testList.get(i))) { + testContext.navigateToChild(i); + try { + lastResult = + compare(new Comparison(ComparisonType.CHILD_LOOKUP, + null, null, null, + testList.get(i), + getXPath(testContext), + testList.get(i))); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + } finally { + testContext.navigateToParent(); + } + } + } + return lastResult; + } + + /** + * Compares properties of an attribute. + */ + private ComparisonResult compareAttributes(Attr control, + XPathContext controlContext, + Attr test, + XPathContext testContext) { + ComparisonResult lastResult = + compare(new Comparison(ComparisonType.ATTR_VALUE_EXPLICITLY_SPECIFIED, + control, getXPath(controlContext), + control.getSpecified(), + test, getXPath(testContext), + test.getSpecified())); + if (lastResult == ComparisonResult.CRITICAL) { + return lastResult; + } + + return compare(new Comparison(ComparisonType.ATTR_VALUE, + control, getXPath(controlContext), + control.getValue(), + test, getXPath(testContext), + test.getValue())); + } + + /** + * Separates XML namespace related attributes from "normal" attributes.xb + */ + private static Attributes splitAttributes(final NamedNodeMap map) { + Attr sLoc = (Attr) map.getNamedItemNS(XMLConstants + .W3C_XML_SCHEMA_INSTANCE_NS_URI, + "schemaLocation"); + Attr nNsLoc = (Attr) map.getNamedItemNS(XMLConstants + .W3C_XML_SCHEMA_INSTANCE_NS_URI, + "noNamespaceSchemaLocation"); + List<Attr> rest = new LinkedList<Attr>(); + final int len = map.getLength(); + for (int i = 0; i < len; i++) { + Attr a = (Attr) map.item(i); + if (!XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(a.getNamespaceURI()) + && + !XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI + .equals(a.getNamespaceURI())) { + rest.add(a); + } + } + return new Attributes(sLoc, nNsLoc, rest); + } + + private static class Attributes { + private final Attr schemaLocation; + private final Attr noNamespaceSchemaLocation; + private final List<Attr> remainingAttributes; + private Attributes(Attr schemaLocation, Attr noNamespaceSchemaLocation, + List<Attr> remainingAttributes) { + this.schemaLocation = schemaLocation; + this.noNamespaceSchemaLocation = noNamespaceSchemaLocation; + this.remainingAttributes = remainingAttributes; + } + } + + /** + * Find the attribute with the same namespace and local name as a + * given attribute in a list of attributes. + */ + private static Attr findMatchingAttr(final List<Attr> attrs, + final Attr attrToMatch) { + final boolean hasNs = attrToMatch.getNamespaceURI() != null; + final String nsToMatch = attrToMatch.getNamespaceURI(); + final String nameToMatch = hasNs ? attrToMatch.getLocalName() + : attrToMatch.getName(); + for (Attr a : attrs) { + if (((!hasNs && a.getNamespaceURI() == null) + || + (hasNs && nsToMatch.equals(a.getNamespaceURI()))) + && + ((hasNs && nameToMatch.equals(a.getLocalName())) + || + (!hasNs && nameToMatch.equals(a.getName()))) + ) { + return a; + } + } + return null; + } + + /** + * Maps Nodes to their QNames. + */ + private static final Linqy.Mapper<Node, QName> QNAME_MAPPER = + new Linqy.Mapper<Node, QName>() { + public QName map(Node n) { return Nodes.getQName(n); } + }; + + /** + * Maps Nodes to their NodeInfo equivalent. + */ + private static final Linqy.Mapper<Node, XPathContext.NodeInfo> TO_NODE_INFO = + new Linqy.Mapper<Node, XPathContext.NodeInfo>() { + public XPathContext.NodeInfo map(Node n) { + return new XPathContext.DOMNodeInfo(n); + } + }; + + /** + * Suppresses document-type nodes. + */ + private static final Predicate<Node> INTERESTING_NODES = + new Predicate<Node>() { + public boolean matches(Node n) { + return n.getNodeType() != Node.DOCUMENT_TYPE_NODE; + } + }; + +} Deleted: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-24 09:54:53 UTC (rev 483) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-24 10:42:48 UTC (rev 484) @@ -1,484 +0,0 @@ -<?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="java.util.HashSet"/> - <import reference="java.util.LinkedList"/> - <import reference="java.util.List"/> - <import reference="java.util.Map"/> - <import reference="java.util.Set"/> - <import reference="java.util.TreeSet"/> - <import reference="javax.xml.XMLConstants"/> - <import reference="javax.xml.namespace.QName"/> - <import reference="javax.xml.transform.Source"/> - <import reference="net.sf.xmlunit.util.Convert"/> - <import reference="net.sf.xmlunit.util.IterableNodeList"/> - <import reference="net.sf.xmlunit.util.Linqy"/> - <import reference="net.sf.xmlunit.util.Nodes"/> - <import reference="net.sf.xmlunit.util.Predicate"/> - <import reference="org.w3c.dom.Attr"/> - <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.NamedNodeMap"/> - <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), new XPathContext(), - Convert.toNode(test), new XPathContext()); - } - - /** - * 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, XPathContext controlContext, - Node test, XPathContext testContext) { -]]></literal> - <lastResultDef/> - <compare type="NODE_TYPE" property="getNodeType()"/> - <compare type="NAMESPACE_URI" property="getNamespaceURI()"/> - <compare type="NAMESPACE_PREFIX" property="getPrefix()"/> - <literal><![CDATA[ - Iterable<Node> controlChildren = - Linqy.filter(new IterableNodeList(control.getChildNodes()), - INTERESTING_NODES); - Iterable<Node> testChildren = - Linqy.filter(new IterableNodeList(test.getChildNodes()), - INTERESTING_NODES); - if (control.getNodeType() != Node.ATTRIBUTE_NODE) { -]]></literal> - <compareExpr type="CHILD_NODELIST_LENGTH" - controlExpr="Linqy.count(controlChildren)" - testExpr="Linqy.count(testChildren)"/> - <literal><![CDATA[ - } -]]></literal> - <compareMethod method="nodeTypeSpecificComparison"/> - <literal><![CDATA[ - if (control.getNodeType() != Node.ATTRIBUTE_NODE) { - controlContext - .setChildren(Linqy.map(controlChildren, TO_NODE_INFO)); - testContext - .setChildren(Linqy.map(testChildren, TO_NODE_INFO)); -]]></literal> - <compareMethodExpr method="compareNodeLists" - controlExpr="controlChildren" - testExpr="testChildren"/> - <literal><![CDATA[ - } - return lastResult; - } - - /** - * Dispatches to the node type specific comparison if one is - * defined for the given combination of nodes. - * - * <p>package private to support tests.</p> - */ - private ComparisonResult nodeTypeSpecificComparison(Node control, - XPathContext controlContext, - Node test, - XPathContext testContext) { - switch (control.getNodeType()) { - case Node.CDATA_SECTION_NODE: - case Node.COMMENT_NODE: - case Node.TEXT_NODE: - if (test instanceof CharacterData) { - return compareCharacterData((CharacterData) control, - controlContext, - (CharacterData) test, testContext); - } - break; - case Node.DOCUMENT_NODE: - if (test instanceof Document) { - return compareDocuments((Document) control, controlContext, - (Document) test, testContext); - } - break; - case Node.ELEMENT_NODE: - if (test instanceof Element) { - return compareElements((Element) control, controlContext, - (Element) test, testContext); - } - break; - case Node.PROCESSING_INSTRUCTION_NODE: - if (test instanceof ProcessingInstruction) { - return - compareProcessingInstructions((ProcessingInstruction) control, - controlContext, - (ProcessingInstruction) test, - testContext); - } - break; - case Node.DOCUMENT_TYPE_NODE: - if (test instanceof DocumentType) { - return compareDocTypes((DocumentType) control, controlContext, - (DocumentType) test, testContext); - } - break; - case Node.ATTRIBUTE_NODE: - if (test instanceof Attr) { - return compareAttributes((Attr) control, controlContext, - (Attr) test, testContext); - } - break; - } - return ComparisonResult.EQUAL; - } - - /** - * Compares textual content. - */ - private ComparisonResult compareCharacterData(CharacterData control, - XPathContext controlContext, - CharacterData test, - XPathContext testContext) { - return compare(new Comparison(ComparisonType.TEXT_VALUE, control, - getXPath(controlContext), - control.getData(), - test, getXPath(testContext), - test.getData())); - } - - private ComparisonResult compareDocuments(Document control, - XPathContext controlContext, - Document test, - XPathContext testContext) { - 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="compareNodes" - 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, getXPath(controlContext), - control.getXmlEncoding(), - test, getXPath(testContext), - test.getXmlEncoding())); - } - - private ComparisonResult compareDocTypes(DocumentType control, - XPathContext controlContext, - DocumentType test, - XPathContext testContext) { -]]></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())); - } - - private ComparisonResult compareElements(Element control, - XPathContext controlContext, - Element test, - XPathContext testContext) { -]]></literal> - <lastResultDef/> - <compareExpr type="ELEMENT_TAG_NAME" - controlExpr="Nodes.getQName(control).getLocalPart()" - testExpr="Nodes.getQName(test).getLocalPart()"/> - <literal><![CDATA[ - Attributes controlAttributes = splitAttributes(control.getAttributes()); - controlContext - .addAttributes(Linqy.map(controlAttributes.remainingAttributes, - QNAME_MAPPER)); - Attributes testAttributes = splitAttributes(test.getAttributes()); - testContext - .addAttributes(Linqy.map(testAttributes.remainingAttributes, - QNAME_MAPPER)); - Set<Attr> foundTestAttributes = new HashSet<Attr>(); -]]></literal> - <compareExpr type="ELEMENT_NUM_ATTRIBUTES" - controlExpr="controlAttributes.remainingAttributes.size()" - testExpr="testAttributes.remainingAttributes.size()"/> - <literal><![CDATA[ - for (Attr controlAttr : controlAttributes.remainingAttributes) { - final Attr testAttr = - findMatchingAttr(testAttributes.remainingAttributes, - controlAttr); -]]></literal> - controlContext.navigateToAttribute(Nodes.getQName(controlAttr)); - try { - <compareExpr type="ATTR_NAME_LOOKUP" - controlExpr="Boolean.TRUE" - testExpr="Boolean.valueOf(testAttr != null)"/> - <literal><![CDATA[ - if (testAttr != null) { - testContext.navigateToAttribute(Nodes.getQName(testAttr)); - try { -]]></literal> - <compareMethodExpr method="compareNodes" - controlExpr="controlAttr" - testExpr="testAttr"/> - <literal><![CDATA[ - foundTestAttributes.add(testAttr); - } finally { - testContext.navigateToParent(); - } - } - } finally { - controlContext.navigateToParent(); - } - } -]]></literal> - <literal><![CDATA[ - for (Attr testAttr : testAttributes.remainingAttributes) { - testContext.navigateToAttribute(Nodes.getQName(testAttr)); - try { -]]></literal> - <compareExpr type="ATTR_NAME_LOOKUP" - controlExpr="Boolean.valueOf(foundTestAttributes.contains(testAttr))" - testExpr="Boolean.TRUE"/> - <literal><![CDATA[ - } finally { - testContext.navigateToParent(); - } - } -]]></literal> - <compareExpr type="SCHEMA_LOCATION" - controlExpr="controlAttributes.schemaLocation != null ? controlAttributes.schemaLocation.getValue() : null" - testExpr="testAttributes.schemaLocation != null ? testAttributes.schemaLocation.getValue() : null" - /> - <compareExpr type="NO_NAMESPACE_SCHEMA_LOCATION" - controlExpr="controlAttributes.noNamespaceSchemaLocation != null ? controlAttributes.noNamespaceSchemaLocation.getValue() : null" - testExpr="testAttributes.noNamespaceSchemaLocation != null ? testAttributes.noNamespaceSchemaLocation.getValue() : null" - /> - <literal><![CDATA[ - return lastResult; - } - - private ComparisonResult - compareProcessingInstructions(ProcessingInstruction control, - XPathContext controlContext, - ProcessingInstruction test, - XPathContext testContext) { -]]></literal> - <lastResultDef/> - <compare type="PROCESSING_INSTRUCTION_TARGET" property="getTarget()"/> - <literal><![CDATA[ - return compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, - control, getXPath(controlContext), - control.getData(), - test, getXPath(testContext), - test.getData())); - } - - private ComparisonResult compareNodeLists(Iterable<Node> controlSeq, - XPathContext controlContext, - Iterable<Node> testSeq, - XPathContext testContext) { -]]></literal> - <lastResultDef/> - <literal><![CDATA[ - // if there are no children on either Node, the result is equal - lastResult = ComparisonResult.EQUAL; - - Iterable<Map.Entry<Node, Node>> matches = - getNodeMatcher().match(controlSeq, testSeq); - List<Node> controlList = Linqy.asList(controlSeq); - List<Node> testList = Linqy.asList(testSeq); - Set<Node> seen = new HashSet<Node>(); - for (Map.Entry<Node, Node> pair : matches) { - Node control = pair.getKey(); - seen.add(control); - Node test = pair.getValue(); - seen.add(test); - int controlIndex = controlList.indexOf(control); - int testIndex = testList.indexOf(test); - controlContext.navigateToChild(controlIndex); - testContext.navigateToChild(testIndex); - try { -]]></literal> - <compareExpr type="CHILD_NODELIST_SEQUENCE" - controlExpr="Integer.valueOf(controlIndex)" - testExpr="Integer.valueOf(testIndex)" - /> - <compareMethodExpr method="compareNodes" - controlExpr="control" - testExpr="test"/> - <literal><![CDATA[ - } finally { - testContext.navigateToParent(); - controlContext.navigateToParent(); - } - } - final int controlSize = controlList.size(); - for (int i = 0; i < controlSize; i++) { - if (!seen.contains(controlList.get(i))) { - controlContext.navigateToChild(i); - try { - lastResult = - compare(new Comparison(ComparisonType.CHILD_LOOKUP, - controlList.get(i), - getXPath(controlContext), - controlList.get(i), - null, null, null)); -]]></literal> - <if-return-boilerplate/> - <literal><![CDATA[ - } finally { - controlContext.navigateToParent(); - } - } - } - final int testSize = testList.size(); - for (int i = 0; i < testSize; i++) { - if (!seen.contains(testList.get(i))) { - testContext.navigateToChild(i); - try { - lastResult = - compare(new Comparison(ComparisonType.CHILD_LOOKUP, - null, null, null, - testList.get(i), - getXPath(testContext), - testList.get(i))); -]]></literal> - <if-return-boilerplate/> - <literal><![CDATA[ - } finally { - testContext.navigateToParent(); - } - } - } - return lastResult; - } - - private ComparisonResult compareAttributes(Attr control, - XPathContext controlContext, - Attr test, - XPathContext testContext) { -]]></literal> - <lastResultDef/> - <compare type="ATTR_VALUE_EXPLICITLY_SPECIFIED" property="getSpecified()"/> - <literal><![CDATA[ - return compare(new Comparison(ComparisonType.ATTR_VALUE, - control, getXPath(controlContext), - control.getValue(), - test, getXPath(testContext), - test.getValue())); - } - - private static Attributes splitAttributes(final NamedNodeMap map) { - Attr sLoc = (Attr) map.getNamedItemNS(XMLConstants - .W3C_XML_SCHEMA_INSTANCE_NS_URI, - "schemaLocation"); - Attr nNsLoc = (Attr) map.getNamedItemNS(XMLConstants - .W3C_XML_SCHEMA_INSTANCE_NS_URI, - "noNamespaceSchemaLocation"); - List<Attr> rest = new LinkedList<Attr>(); - final int len = map.getLength(); - for (int i = 0; i < len; i++) { - Attr a = (Attr) map.item(i); - if (!XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(a.getNamespaceURI()) - && - !XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI - .equals(a.getNamespaceURI())) { - rest.add(a); - } - } - return new Attributes(sLoc, nNsLoc, rest); - } - - private static class Attributes { - private final Attr schemaLocation; - private final Attr noNamespaceSchemaLocation; - private final List<Attr> remainingAttributes; - private Attributes(Attr schemaLocation, Attr noNamespaceSchemaLocation, - List<Attr> remainingAttributes) { - this.schemaLocation = schemaLocation; - this.noNamespaceSchemaLocation = noNamespaceSchemaLocation; - this.remainingAttributes = remainingAttributes; - } - } - - private static Attr findMatchingAttr(final List<Attr> attrs, - final Attr attrToMatch) { - final boolean hasNs = attrToMatch.getNamespaceURI() != null; - final String nsToMatch = attrToMatch.getNamespaceURI(); - final String nameToMatch = hasNs ? attrToMatch.getLocalName() - : attrToMatch.getName(); - for (Attr a : attrs) { - if (((!hasNs && a.getNamespaceURI() == null) - || - (hasNs && nsToMatch.equals(a.getNamespaceURI()))) - && - ((hasNs && nameToMatch.equals(a.getLocalName())) - || - (!hasNs && nameToMatch.equals(a.getName()))) - ) { - return a; - } - } - return null; - } - - private static final Linqy.Mapper<Node, QName> QNAME_MAPPER = - new Linqy.Mapper<Node, QName>() { - public QName map(Node n) { return Nodes.getQName(n); } - }; - - private static final Linqy.Mapper<Node, XPathContext.NodeInfo> TO_NODE_INFO = - new Linqy.Mapper<Node, XPathContext.NodeInfo>() { - public XPathContext.NodeInfo map(Node n) { - return new XPathContext.DOMNodeInfo(n); - } - }; - - private static final Predicate<Node> INTERESTING_NODES = - new Predicate<Node>() { - public boolean matches(Node n) { - return n.getNodeType() != Node.DOCUMENT_TYPE_NODE; - } - }; -]]></literal> -</class> Copied: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs (from rev 479, trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml) =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.cs 2010-09-24 10:42:48 UTC (rev 484) @@ -0,0 +1,671 @@ +/* + 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.Collections.Generic; +using System.Xml; +using System.Xml.Schema; +using net.sf.xmlunit.util; + +namespace net.sf.xmlunit.diff{ + + /// <summary> + /// Difference engine based on DOM. + /// </summary> + public sealed class DOMDifferenceEngine : AbstractDifferenceEngine { + + private static readonly object DUMMY = new object(); + + 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), + new XPathContext(), + net.sf.xmlunit.util.Convert.ToNode(test), + new XPathContext()); + } + + /// <summary> + /// Recursively compares two XML nodes. + /// </summary> + /// <remarks> + /// Performs comparisons common to all node types, then performs + /// the node type specific comparisons and finally recurses into + /// the node's child lists. + /// + /// Stops as soon as any comparison returns ComparisonResult.CRITICAL. + /// </remarks> + internal ComparisonResult CompareNodes(XmlNode control, + XPathContext controlContext, + XmlNode test, + XPathContext testContext) { + ComparisonResult lastResult = + Compa... [truncated message content] |
From: <bo...@us...> - 2010-09-24 09:54:59
|
Revision: 483 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=483&view=rev Author: bodewig Date: 2010-09-24 09:54:53 +0000 (Fri, 24 Sep 2010) Log Message: ----------- extract predicate from linqy Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/main/net-core/util/Linqy.cs Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Predicate.java trunk/xmlunit/src/main/net-core/util/Predicate.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-24 09:47:28 UTC (rev 482) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-24 09:54:53 UTC (rev 483) @@ -30,6 +30,7 @@ <import reference="net.sf.xmlunit.util.IterableNodeList"/> <import reference="net.sf.xmlunit.util.Linqy"/> <import reference="net.sf.xmlunit.util.Nodes"/> + <import reference="net.sf.xmlunit.util.Predicate"/> <import reference="org.w3c.dom.Attr"/> <import reference="org.w3c.dom.CharacterData"/> <import reference="org.w3c.dom.Document"/> @@ -473,8 +474,8 @@ } }; - private static final Linqy.Predicate<Node> INTERESTING_NODES = - new Linqy.Predicate<Node>() { + private static final Predicate<Node> INTERESTING_NODES = + new Predicate<Node>() { public boolean matches(Node n) { return n.getNodeType() != Node.DOCUMENT_TYPE_NODE; } Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-09-24 09:47:28 UTC (rev 482) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-09-24 09:54:53 UTC (rev 483) @@ -89,13 +89,6 @@ } /** - * A function that tests an object for a property. - */ - public interface Predicate<T> { - boolean matches(T toTest); - } - - /** * Count the number of elements in a sequence. */ public static int count(Iterable seq) { Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Predicate.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Predicate.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Predicate.java 2010-09-24 09:54:53 UTC (rev 483) @@ -0,0 +1,21 @@ +/* + 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.util; + +/** + * A function that tests an object for a property. + */ +public interface Predicate<T> { + boolean matches(T toTest); +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Predicate.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-24 09:47:28 UTC (rev 482) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-24 09:54:53 UTC (rev 483) @@ -60,6 +60,7 @@ import net.sf.xmlunit.input.WhitespaceNormalizedSource; import net.sf.xmlunit.input.WhitespaceStrippedSource; import net.sf.xmlunit.util.Linqy; +import net.sf.xmlunit.util.Predicate; import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier; import org.w3c.dom.CDATASection; @@ -531,7 +532,7 @@ result.add(new Entry(n, map.get(n))); } else { Iterable<Node> unmatchedTestElements = - Linqy.filter(testNodes, new Linqy.Predicate<Node>() { + Linqy.filter(testNodes, new Predicate<Node>() { public boolean matches(Node t) { return !map.containsValue(t); } Modified: trunk/xmlunit/src/main/net-core/util/Linqy.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-09-24 09:47:28 UTC (rev 482) +++ trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-09-24 09:54:53 UTC (rev 483) @@ -67,11 +67,6 @@ } /// <summary> - /// A function that tests an object for a property. - /// </summary> - public delegate bool Predicate<T>(T toTest); - - /// <summary> /// Count the number of elements in a sequence. /// </summary> public static int Count(IEnumerable e) { Added: trunk/xmlunit/src/main/net-core/util/Predicate.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Predicate.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/util/Predicate.cs 2010-09-24 09:54:53 UTC (rev 483) @@ -0,0 +1,20 @@ +/* + 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. +*/ + +namespace net.sf.xmlunit.util { + /// <summary> + /// A function that tests an object for a property. + /// </summary> + public delegate bool Predicate<T>(T toTest); +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/util/Predicate.cs ___________________________________________________________________ Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-24 09:47:34
|
Revision: 482 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=482&view=rev Author: bodewig Date: 2010-09-24 09:47:28 +0000 (Fri, 24 Sep 2010) Log Message: ----------- docs Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java trunk/xmlunit/src/main/net-core/util/Linqy.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-09-17 11:50:31 UTC (rev 481) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-09-24 09:47:28 UTC (rev 482) @@ -18,6 +18,9 @@ import java.util.List; import java.util.NoSuchElementException; +/** + * A couple of (functional) sequence processing constructs. + */ public final class Linqy { /** * Turns the iterable into a list. @@ -30,6 +33,9 @@ return a; } + /** + * Turns an iterable into its type-safe cousin. + */ public static <E> Iterable<E> cast(final Iterable i) { return map(i, new Mapper<Object, E>() { public E map(Object o) { @@ -38,6 +44,9 @@ }); } + /** + * An iterable containing a single element. + */ public static <E> Iterable<E> singleton(final E single) { return new Iterable<E>() { public Iterator<E> iterator() { @@ -46,6 +55,10 @@ }; } + /** + * Create a new iterable by applying a mapper function to each + * element of a given sequence. + */ public static <F, T> Iterable<T> map(final Iterable<F> from, final Mapper<? super F, T> mapper) { return new Iterable<T>() { @@ -55,10 +68,17 @@ }; } + /** + * A function mapping from one type to another. + */ public interface Mapper<F, T> { T map(F from); } + /** + * Exclude all elements from an iterable that don't match a given + * predicate. + */ public static <T> Iterable<T> filter(final Iterable<T> sequence, final Predicate<? super T> filter) { return new Iterable<T>() { @@ -68,10 +88,16 @@ }; } + /** + * A function that tests an object for a property. + */ public interface Predicate<T> { boolean matches(T toTest); } + /** + * Count the number of elements in a sequence. + */ public static int count(Iterable seq) { int c = 0; Iterator it = seq.iterator(); Modified: trunk/xmlunit/src/main/net-core/util/Linqy.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-09-17 11:50:31 UTC (rev 481) +++ trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-09-24 09:47:28 UTC (rev 482) @@ -17,21 +17,30 @@ namespace net.sf.xmlunit.util { /// <summary> - /// Conversion methods. + /// A couple of (functional) sequence processing constructs. /// </summary> public sealed class Linqy { + + /// <summary> + /// Turns an enumerable into its type-safe cousin. + /// </summary> public static IEnumerable<T> Cast<T>(IEnumerable i) { foreach (T t in i) { yield return t; } } + /// <summary> + /// An enumerable containing a single element. + /// </summary> public static IEnumerable<T> Singleton<T>(T t) { yield return t; } - public delegate T Mapper<F, T>(F from); - + /// <summary> + /// Create a new enumerable by applying a mapper function to + /// each element of a given sequence. + /// </summary> public static IEnumerable<T> Map<F, T>(IEnumerable<F> from, Mapper<F, T> mapper) { foreach (F f in from) { @@ -39,8 +48,15 @@ } } - public delegate bool Predicate<T>(T toTest); + /// <summary> + /// A function mapping from one type to another. + /// </summary> + public delegate T Mapper<F, T>(F from); + /// <summary> + /// Exclude all elements from an enumerable that don't match a + /// given predicate. + /// </summary> public static IEnumerable<T> Filter<T>(IEnumerable<T> sequence, Predicate<T> filter) { foreach (T t in sequence) { @@ -50,6 +66,14 @@ } } + /// <summary> + /// A function that tests an object for a property. + /// </summary> + public delegate bool Predicate<T>(T toTest); + + /// <summary> + /// Count the number of elements in a sequence. + /// </summary> public static int Count(IEnumerable e) { int c = 0; foreach (object o in e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-17 11:50:37
|
Revision: 481 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=481&view=rev Author: bodewig Date: 2010-09-17 11:50:31 +0000 (Fri, 17 Sep 2010) Log Message: ----------- implement whitespace nomalization Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Nodes.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/main/net-core/util/Nodes.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/util/NodesTest.java trunk/xmlunit/src/tests/net-core/util/NodesTest.cs Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/WhitespaceNormalizedSource.java trunk/xmlunit/src/main/net-core/input/WhitespaceNormalizedSource.cs Copied: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/WhitespaceNormalizedSource.java (from rev 479, trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/WhitespaceStrippedSource.java) =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/WhitespaceNormalizedSource.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/WhitespaceNormalizedSource.java 2010-09-17 11:50:31 UTC (rev 481) @@ -0,0 +1,35 @@ +/* + 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.input; + +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; +import net.sf.xmlunit.util.Convert; +import net.sf.xmlunit.util.Nodes; + +/** + * A source that is obtained from a different source by removing all + * empty text nodes and normalizing the non-empty ones. + * + * <p>"normalized" in this context means all whitespace characters + * are replaced by space characters and consecutive whitespace + * characaters are collapsed.</p> + */ +public class WhitespaceNormalizedSource extends DOMSource { + + public WhitespaceNormalizedSource(Source originalSource) { + super(Nodes.normalizeWhitespace(Convert.toDocument(originalSource))); + setSystemId(originalSource.getSystemId()); + } +} Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Nodes.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Nodes.java 2010-09-16 15:13:39 UTC (rev 480) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Nodes.java 2010-09-17 11:50:31 UTC (rev 481) @@ -91,21 +91,43 @@ public static Node stripWhitespace(Node original) { Node cloned = original.cloneNode(true); cloned.normalize(); - stripWsRec(cloned); + handleWsRec(cloned, false); return cloned; } /** + * Creates a new Node (of the same type as the original node) that + * is similar to the orginal but doesn't contain any empty text or + * CDATA nodes and where all textual content including attribute + * values or comments are trimmed and normalized. + * + * <p>"normalized" in this context means all whitespace characters + * are replaced by space characters and consecutive whitespace + * characaters are collapsed.</p> + */ + public static Node normalizeWhitespace(Node original) { + Node cloned = original.cloneNode(true); + cloned.normalize(); + handleWsRec(cloned, true); + return cloned; + } + + /** * Trims textual content of this node, removes empty text and * CDATA children, recurses into its child nodes. + * @param normalize whether to normalize whitespace as well */ - private static void stripWsRec(Node n) { + private static void handleWsRec(Node n, boolean normalize) { if (n instanceof CharacterData || n instanceof ProcessingInstruction) { - n.setNodeValue(n.getNodeValue().trim()); + String s = n.getNodeValue().trim(); + if (normalize) { + s = normalize(s); + } + n.setNodeValue(s); } List<Node> toRemove = new LinkedList<Node>(); for (Node child : new IterableNodeList(n.getChildNodes())) { - stripWsRec(child); + handleWsRec(child, normalize); if (!(n instanceof Attr) && (child instanceof Text || child instanceof CDATASection) && child.getNodeValue().length() == 0) { @@ -119,8 +141,40 @@ if (attrs != null) { final int len = attrs.getLength(); for (int i = 0; i < len; i++) { - stripWsRec(attrs.item(i)); + handleWsRec(attrs.item(i), normalize); } } } + + private static final char SPACE = ' '; + + /** + * Normalize a string. + * + * <p>"normalized" in this context means all whitespace characters + * are replaced by space characters and consecutive whitespace + * characaters are collapsed.</p> + */ + static String normalize(String s) { + StringBuilder sb = new StringBuilder(); + boolean changed = false; + boolean lastCharWasWS = false; + final int len = s.length(); + for (int i = 0; i < len; i++) { + char c = s.charAt(i); + if (Character.isWhitespace(c)) { + if (!lastCharWasWS) { + sb.append(SPACE); + changed |= (c != SPACE); + } else { + changed = true; + } + lastCharWasWS = true; + } else { + sb.append(c); + lastCharWasWS = false; + } + } + return changed ? sb.toString() : s; + } } Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-16 15:13:39 UTC (rev 480) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-17 11:50:31 UTC (rev 481) @@ -423,8 +423,6 @@ if ( XMLUnit.getIgnoreAttributeOrder() && - !XMLUnit.getNormalizeWhitespace() - && (!usesUnknownElementQualifier() || XMLUnit.getCompareUnmatched()) ) { Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-16 15:13:39 UTC (rev 480) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-17 11:50:31 UTC (rev 481) @@ -57,6 +57,7 @@ import net.sf.xmlunit.diff.ElementSelectors; import net.sf.xmlunit.diff.NodeMatcher; import net.sf.xmlunit.input.CommentLessSource; +import net.sf.xmlunit.input.WhitespaceNormalizedSource; import net.sf.xmlunit.input.WhitespaceStrippedSource; import net.sf.xmlunit.util.Linqy; import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier; @@ -200,7 +201,10 @@ ctrlSource = new CommentLessSource(ctrlSource); tstSource = new CommentLessSource(tstSource); } - if (XMLUnit.getIgnoreWhitespace()) { + if (XMLUnit.getNormalizeWhitespace()) { + ctrlSource = new WhitespaceNormalizedSource(ctrlSource); + tstSource = new WhitespaceNormalizedSource(tstSource); + } else if (XMLUnit.getIgnoreWhitespace()) { ctrlSource = new WhitespaceStrippedSource(ctrlSource); tstSource = new WhitespaceStrippedSource(tstSource); } Copied: trunk/xmlunit/src/main/net-core/input/WhitespaceNormalizedSource.cs (from rev 479, trunk/xmlunit/src/main/net-core/input/WhitespaceStrippedSource.cs) =================================================================== --- trunk/xmlunit/src/main/net-core/input/WhitespaceNormalizedSource.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/input/WhitespaceNormalizedSource.cs 2010-09-17 11:50:31 UTC (rev 481) @@ -0,0 +1,35 @@ +/* + 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 net.sf.xmlunit.util; + +namespace net.sf.xmlunit.input { + + /// <summary> + /// A source that is obtained from a different source by removing + /// all empty text nodes and normalizing the non-empty ones. + /// </summary> + /// <remarks> + /// "normalized" in this context means all whitespace characters + /// are replaced by space characters and consecutive whitespace + /// characaters are collapsed. + /// </remarks> + public class WhitespaceNormalizedSource : DOMSource { + public WhitespaceNormalizedSource(ISource originalSource) : + base(Nodes.NormalizeWhitespace(Convert.ToDocument(originalSource))) + { + SystemId = originalSource.SystemId; + } + } +} Modified: trunk/xmlunit/src/main/net-core/util/Nodes.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Nodes.cs 2010-09-16 15:13:39 UTC (rev 480) +++ trunk/xmlunit/src/main/net-core/util/Nodes.cs 2010-09-17 11:50:31 UTC (rev 481) @@ -74,21 +74,45 @@ public static XmlNode StripWhitespace(XmlNode original) { XmlNode cloned = original.CloneNode(true); cloned.Normalize(); - StripWsRec(cloned); + HandleWsRec(cloned, false); return cloned; } /// <summary> + /// Creates a new Node (of the same type as the original node) + /// that is similar to the orginal but doesn't contain any + /// empty text or CDATA nodes and where all textual content + /// including attribute values or comments are normalized. + /// </summary> + /// <remarks> + /// "normalized" in this context means all whitespace + /// characters are replaced by space characters and + /// consecutive whitespace characaters are collapsed. + /// </remarks> + public static XmlNode NormalizeWhitespace(XmlNode original) { + XmlNode cloned = original.CloneNode(true); + cloned.Normalize(); + HandleWsRec(cloned, true); + return cloned; + } + + /// <summary> /// Trims textual content of this node, removes empty text and /// CDATA children, recurses into its child nodes. /// </summary> - private static void StripWsRec(XmlNode n) { + /// <parameter name="normalize">whether to normalize + /// whitespace as well</parameter> + private static void HandleWsRec(XmlNode n, bool normalize) { if (n is XmlCharacterData || n is XmlProcessingInstruction) { - n.Value = n.Value.Trim(); + string s = n.Value.Trim(); + if (normalize) { + s = Normalize(s); + } + n.Value = s; } LinkedList<XmlNode> toRemove = new LinkedList<XmlNode>(); foreach (XmlNode child in n.ChildNodes) { - StripWsRec(child); + HandleWsRec(child, normalize); if (!(n is XmlAttribute) && (child is XmlText || child is XmlCDataSection) && child.Value.Length == 0) { @@ -101,10 +125,40 @@ XmlNamedNodeMap attrs = n.Attributes; if (attrs != null) { foreach (XmlAttribute a in attrs) { - StripWsRec(a); + HandleWsRec(a, normalize); } } } + private const char SPACE = ' '; + + /// <summary> + /// Normalize a string. + /// <summary> + /// <remarks> + /// "normalized" in this context means all whitespace + /// characters are replaced by space characters and + /// consecutive whitespace characaters are collapsed. + /// </remarks> + internal static string Normalize(string s) { + StringBuilder sb = new StringBuilder(); + bool changed = false; + bool lastCharWasWS = false; + foreach (char c in s) { + if (char.IsWhiteSpace(c)) { + if (!lastCharWasWS) { + sb.Append(SPACE); + changed |= (c != SPACE); + } else { + changed = true; + } + lastCharWasWS = true; + } else { + sb.Append(c); + lastCharWasWS = false; + } + } + return changed ? sb.ToString() : s; + } } } Modified: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/util/NodesTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/util/NodesTest.java 2010-09-16 15:13:39 UTC (rev 480) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/util/NodesTest.java 2010-09-17 11:50:31 UTC (rev 481) @@ -144,16 +144,20 @@ assertEquals(BAR, m.get(new QName(SOME_URI, FOO, BAR))); } - private Map.Entry<Document, Node> stripWsSetup() { - final Document toTest = Convert.toDocument(Input.fromMemory( + private Document handleWsSetup() { + return Convert.toDocument(Input.fromMemory( "<root>\n" - + "<!-- trim me -->\n" + + "<!-- trim\tme -->\n" + "<child attr=' trim me ' attr2='not me'>\n" + " trim me \n" + "</child><![CDATA[ trim me ]]>\n" + "<?target trim me ?>\n" + "<![CDATA[ ]]>\n" + "</root>").build()); + } + + private Map.Entry<Document, Node> stripWsSetup() { + final Document toTest = handleWsSetup(); final Node stripped = Nodes.stripWhitespace(toTest); return new Map.Entry<Document, Node>() { public Document getKey() { @@ -168,8 +172,32 @@ }; } + private Map.Entry<Document, Node> normalizeWsSetup() { + final Document toTest = handleWsSetup(); + final Node stripped = Nodes.normalizeWhitespace(toTest); + return new Map.Entry<Document, Node>() { + public Document getKey() { + return toTest; + } + public Node getValue() { + return stripped; + } + public Node setValue(Node n) { + throw new UnsupportedOperationException(); + } + }; + } + @Test public void stripWhitespaceWorks() { - Map.Entry<Document, Node> s = stripWsSetup(); + handleWsWorks(stripWsSetup(), "trim\tme"); + } + + @Test public void normalizeWhitespaceWorks() { + handleWsWorks(normalizeWsSetup(), "trim me"); + } + + private void handleWsWorks(Map.Entry<Document, Node> s, + String commentContent) { assertTrue(s.getValue() instanceof Document); NodeList top = s.getValue().getChildNodes(); assertEquals(1, top.getLength()); @@ -179,7 +207,8 @@ assertEquals(4, rootsChildren.getLength()); assertTrue("should be comment, is " + rootsChildren.item(0).getClass(), rootsChildren.item(0) instanceof Comment); - assertEquals("trim me", ((Comment) rootsChildren.item(0)).getData()); + assertEquals(commentContent, + ((Comment) rootsChildren.item(0)).getData()); assertTrue("should be element, is " + rootsChildren.item(1).getClass(), rootsChildren.item(1) instanceof Element); assertEquals("child", rootsChildren.item(1).getNodeName()); @@ -206,7 +235,14 @@ } @Test public void stripWhitespaceDoesntAlterOriginal() { - Map.Entry<Document, Node> s = stripWsSetup(); + handleWsDoesntAlterOriginal(stripWsSetup()); + } + + @Test public void normalizeWhitespaceDoesntAlterOriginal() { + handleWsDoesntAlterOriginal(normalizeWsSetup()); + } + + private void handleWsDoesntAlterOriginal(Map.Entry<Document, Node> s) { NodeList top = s.getKey().getChildNodes(); assertEquals(1, top.getLength()); assertTrue(top.item(0) instanceof Element); @@ -216,7 +252,7 @@ assertNewlineTextNode(rootsChildren.item(0)); assertTrue("should be comment, is " + rootsChildren.item(1).getClass(), rootsChildren.item(1) instanceof Comment); - assertEquals(" trim me ", ((Comment) rootsChildren.item(1)).getData()); + assertEquals(" trim\tme ", ((Comment) rootsChildren.item(1)).getData()); assertNewlineTextNode(rootsChildren.item(2)); assertTrue("should be element, is " + rootsChildren.item(3).getClass(), rootsChildren.item(3) instanceof Element); @@ -255,4 +291,11 @@ n instanceof Text); assertEquals("\n", ((Text) n).getData()); } + + @Test public void normalize() { + assertSame("foo", Nodes.normalize("foo")); + assertSame("foo bar", Nodes.normalize("foo bar")); + assertEquals("foo bar", Nodes.normalize("foo\nbar")); + assertEquals("foo bar", Nodes.normalize("foo \r\n\t bar")); + } } Modified: trunk/xmlunit/src/tests/net-core/util/NodesTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/util/NodesTest.cs 2010-09-16 15:13:39 UTC (rev 480) +++ trunk/xmlunit/src/tests/net-core/util/NodesTest.cs 2010-09-17 11:50:31 UTC (rev 481) @@ -123,23 +123,42 @@ Assert.AreEqual(BAR, m[new XmlQualifiedName(FOO, SOME_URI)]); } - private KeyValuePair<XmlDocument, XmlNode> StripWsSetup() { - XmlDocument toTest = Convert.ToDocument(Input.FromMemory( + private XmlDocument HandleWsSetup() { + return Convert.ToDocument(Input.FromMemory( "<root>\n" - + "<!-- trim me -->\n" + + "<!-- trim\tme -->\n" + "<child attr=' trim me ' attr2='not me'>\n" + " trim me \n" + "</child><![CDATA[ trim me ]]>\n" + "<?target trim me ?>\n" + "<![CDATA[ ]]>\n" + "</root>").Build()); + } + + private KeyValuePair<XmlDocument, XmlNode> StripWsSetup() { + XmlDocument toTest = HandleWsSetup(); return new KeyValuePair<XmlDocument, XmlNode>(toTest, Nodes.StripWhitespace(toTest)); } + private KeyValuePair<XmlDocument, XmlNode> NormalizeWsSetup() { + XmlDocument toTest = HandleWsSetup(); + return new KeyValuePair<XmlDocument, + XmlNode>(toTest, Nodes.NormalizeWhitespace(toTest)); + } + [Test] public void StripWhitespaceWorks() { - KeyValuePair<XmlDocument, XmlNode> s = StripWsSetup(); + HandleWsWorks(StripWsSetup(), "trim\tme"); + } + + [Test] + public void NormalizeWhitespaceWorks() { + HandleWsWorks(NormalizeWsSetup(), "trim me"); + } + + private void HandleWsWorks(KeyValuePair<XmlDocument, XmlNode> s, + string commentContent) { Assert.IsTrue(s.Value is XmlDocument); XmlNodeList top = s.Value.ChildNodes; Assert.AreEqual(1, top.Count); @@ -149,7 +168,7 @@ Assert.AreEqual(4, rootsChildren.Count); Assert.IsTrue(rootsChildren[0] is XmlComment, "should be comment, is " + rootsChildren[0].GetType()); - Assert.AreEqual("trim me", + Assert.AreEqual(commentContent, ((XmlComment) rootsChildren[0]).Data); Assert.IsTrue(rootsChildren[1] is XmlElement, "should be element, is " + rootsChildren[1].GetType()); @@ -178,7 +197,16 @@ [Test] public void StripWhitespaceDoesntAlterOriginal() { - KeyValuePair<XmlDocument, XmlNode> s = StripWsSetup(); + HandleWsDoesntAlterOriginal(StripWsSetup()); + } + + [Test] + public void NormalizeWhitespaceDoesntAlterOriginal() { + HandleWsDoesntAlterOriginal(NormalizeWsSetup()); + } + + private void HandleWsDoesntAlterOriginal(KeyValuePair<XmlDocument, + XmlNode> s) { XmlNodeList top = s.Key.ChildNodes; Assert.AreEqual(1, top.Count); Assert.IsTrue(top[0] is XmlElement); @@ -187,7 +215,7 @@ Assert.AreEqual(5, rootsChildren.Count); Assert.IsTrue(rootsChildren[0] is XmlComment, "should be comment, is " + rootsChildren[0].GetType()); - Assert.AreEqual(" trim me ", + Assert.AreEqual(" trim\tme ", ((XmlComment) rootsChildren[0]).Data); Assert.IsTrue(rootsChildren[1] is XmlElement, "should be element, is " + rootsChildren[1].GetType()); @@ -217,5 +245,13 @@ XmlAttribute a2 = (XmlAttribute) attrs.GetNamedItem("attr2"); Assert.AreEqual("not me", a2.Value); } + + [Test] + public void Normalize() { + Assert.AreSame("foo", Nodes.Normalize("foo")); + Assert.AreSame("foo bar", Nodes.Normalize("foo bar")); + Assert.AreEqual("foo bar", Nodes.Normalize("foo\nbar")); + Assert.AreEqual("foo bar", Nodes.Normalize("foo \r\n\t bar")); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-16 15:13:50
|
Revision: 480 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=480&view=rev Author: bodewig Date: 2010-09-16 15:13:39 +0000 (Thu, 16 Sep 2010) Log Message: ----------- avoid double-wrapping of ElementSelectors Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 11:30:44 UTC (rev 479) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-16 15:13:39 UTC (rev 480) @@ -36,6 +36,7 @@ package org.custommonkey.xmlunit; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; @@ -53,10 +54,12 @@ import net.sf.xmlunit.diff.DifferenceEvaluator; import net.sf.xmlunit.diff.DifferenceEvaluators; import net.sf.xmlunit.diff.ElementSelector; +import net.sf.xmlunit.diff.ElementSelectors; import net.sf.xmlunit.diff.NodeMatcher; import net.sf.xmlunit.input.CommentLessSource; import net.sf.xmlunit.input.WhitespaceStrippedSource; import net.sf.xmlunit.util.Linqy; +import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; @@ -79,6 +82,17 @@ implements DifferenceConstants, DifferenceEngineContract { private static final Integer ZERO = Integer.valueOf(0); + private static final Map<Class<?>, ElementSelector> KNOWN_SELECTORS; + static { + Map<Class<?>, ElementSelector> m = + new HashMap<Class<?>, ElementSelector>(); + m.put(ElementNameAndTextQualifier.class, + ElementSelectors.byNameAndText); + m.put(ElementQualifier.class, ElementSelectors.byName); + m.put(RecursiveElementNameAndTextQualifier.class, + ElementSelectors.byNameAndTextRec); + KNOWN_SELECTORS = Collections.unmodifiableMap(m); + } private final ComparisonController controller; private MatchTracker matchTracker; @@ -164,7 +178,12 @@ NodeMatcher m = new DefaultNodeMatcher(); if (elementQualifier != null) { - m = new DefaultNodeMatcher(new ElementQualifier2ElementSelector(elementQualifier)); + Class<?> c = elementQualifier.getClass(); + if (KNOWN_SELECTORS.containsKey(c)) { + m = new DefaultNodeMatcher(KNOWN_SELECTORS.get(c)); + } else { + m = new DefaultNodeMatcher(new ElementQualifier2ElementSelector(elementQualifier)); + } } if (!XMLUnit.getCompareUnmatched()) { engine.setNodeMatcher(m); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 11:30:51
|
Revision: 479 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=479&view=rev Author: bodewig Date: 2010-09-14 11:30:44 +0000 (Tue, 14 Sep 2010) Log Message: ----------- can also deal with custom DifferenceListener Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java Removed Paths: ------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-14 10:25:52 UTC (rev 478) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-14 11:30:44 UTC (rev 479) @@ -72,7 +72,7 @@ * <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a> */ public class Diff - implements DifferenceEvaluator, DifferenceListener, ComparisonController { + implements DifferenceListener, ComparisonController { private final Document controlDoc; private final Document testDoc; private boolean similar = true; @@ -425,8 +425,6 @@ && !XMLUnit.getNormalizeWhitespace() && - differenceListenerDelegate == null - && (!usesUnknownElementQualifier() || XMLUnit.getCompareUnmatched()) ) { Deleted: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java 2010-09-14 10:25:52 UTC (rev 478) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java 2010-09-14 11:30:44 UTC (rev 479) @@ -1,55 +0,0 @@ -/* -****************************************************************** -Copyright (c) 2010, Jeff Martin, Tim Bacon -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of the xmlunit.sourceforge.net nor the names - of its contributors may be used to endorse or promote products - derived from this software without specific prior written - permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. - -****************************************************************** -*/ - -package org.custommonkey.xmlunit; - -/** - * Contains the pure evaluation logic of DifferenceListener - */ -public interface DifferenceEvaluator { - /** - * Receive notification of a difference and decides whether 2 - * nodes are different. - * @param difference a Difference instance as defined in {@link - * DifferenceConstants DifferenceConstants} describing the cause - * of the difference and containing the detail of the nodes that - * differ - * @return int one of the RETURN_... constants of - * DifferenceListener describing how this difference was - * interpreted - */ - int evaluate(Difference difference); -} Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 10:25:52 UTC (rev 478) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 11:30:44 UTC (rev 479) @@ -50,6 +50,7 @@ import net.sf.xmlunit.diff.ComparisonType; import net.sf.xmlunit.diff.DOMDifferenceEngine; import net.sf.xmlunit.diff.DefaultNodeMatcher; +import net.sf.xmlunit.diff.DifferenceEvaluator; import net.sf.xmlunit.diff.DifferenceEvaluators; import net.sf.xmlunit.diff.ElementSelector; import net.sf.xmlunit.diff.NodeMatcher; @@ -138,34 +139,19 @@ .addMatchListener(new MatchTracker2ComparisonListener(matchTracker)); } - net.sf.xmlunit.diff.DifferenceEvaluator controllerAsEvaluator = + DifferenceEvaluator controllerAsEvaluator = new ComparisonController2DifferenceEvaluator(controller); - net.sf.xmlunit.diff.DifferenceEvaluator ev = null; + DifferenceEvaluator ev = null; if (listener != null) { - net.sf.xmlunit.diff.DifferenceEvaluator e = null; - if (listener instanceof org.custommonkey.xmlunit.DifferenceEvaluator) { - e = new DifferenceEvaluatorAdapter((DifferenceEvaluator) listener); - final ComparisonListener l = new DifferenceListener2ComparisonListener(listener); - engine - .addDifferenceListener(new ComparisonListener() { - public void comparisonPerformed(Comparison comparison, - ComparisonResult outcome) { - if (!swallowComparison(comparison, outcome, - checkPrelude)) { - l.comparisonPerformed(comparison, outcome); - } - } - }); - } else { - e = new DifferenceListener2DifferenceEvaluator(listener); - } - ev = DifferenceEvaluators.first(e, controllerAsEvaluator); + ev = DifferenceEvaluators + .first(new DifferenceListener2DifferenceEvaluator(listener), + controllerAsEvaluator); } else { ev = controllerAsEvaluator; } final net.sf.xmlunit.diff.DifferenceEvaluator evaluator = ev; engine - .setDifferenceEvaluator(new net.sf.xmlunit.diff.DifferenceEvaluator() { + .setDifferenceEvaluator(new DifferenceEvaluator() { public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { if (!swallowComparison(comparison, outcome, @@ -394,7 +380,7 @@ } public static class ComparisonController2DifferenceEvaluator - implements net.sf.xmlunit.diff.DifferenceEvaluator { + implements DifferenceEvaluator { private final ComparisonController cc; public ComparisonController2DifferenceEvaluator(ComparisonController c) { cc = c; @@ -410,33 +396,6 @@ } } - public static class DifferenceEvaluatorAdapter - implements net.sf.xmlunit.diff.DifferenceEvaluator { - private final DifferenceEvaluator de; - public DifferenceEvaluatorAdapter(DifferenceEvaluator d) { - de = d; - } - - public ComparisonResult evaluate(Comparison comparison, - ComparisonResult outcome) { - Difference diff = toDifference(comparison); - if (diff != null) { - switch (de.evaluate(diff)) { - case DifferenceListener - .RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: - return ComparisonResult.EQUAL; - case DifferenceListener - .RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: - return ComparisonResult.SIMILAR; - case DifferenceListener - .RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: - return ComparisonResult.DIFFERENT; - } - } - return outcome; - } - } - public static class ElementQualifier2ElementSelector implements ElementSelector { private final ElementQualifier eq; @@ -453,7 +412,7 @@ } public static class DifferenceListener2DifferenceEvaluator - implements net.sf.xmlunit.diff.DifferenceEvaluator { + implements DifferenceEvaluator { private final DifferenceListener dl; public DifferenceListener2DifferenceEvaluator(DifferenceListener dl) { Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2010-09-14 10:25:52 UTC (rev 478) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2010-09-14 11:30:44 UTC (rev 479) @@ -146,9 +146,9 @@ new Diff(control, dissimilarTest)); dissimilarDetailedDiff.overrideDifferenceListener(listener); List differences = dissimilarDetailedDiff.getAllDifferences(); - assertEquals("wrong number of attributes, missing attribute, different attribute value, and missing text node. " + assertEquals("has children, wrong number of attributes, missing attribute, different attribute value, and missing text node. " + dissimilarDetailedDiff.toString(), - 4, differences.size()); + 5, differences.size()); int recoverable = 0; for (Iterator iter = differences.iterator(); iter.hasNext(); ) { Difference aDifference = (Difference) iter.next(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 10:25:59
|
Revision: 478 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=478&view=rev Author: bodewig Date: 2010-09-14 10:25:52 +0000 (Tue, 14 Sep 2010) Log Message: ----------- don't need compareDontFire anymore Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-09-14 10:23:36 UTC (rev 477) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-09-14 10:25:52 UTC (rev 478) @@ -82,23 +82,16 @@ * listeners and returns the outcome. */ protected final ComparisonResult compare(Comparison comp) { - ComparisonResult altered = compareDontFire(comp); - listeners.fireComparisonPerformed(comp, altered); - return altered; - } - - /** - * Compares the detail values for object equality, lets the - * difference evaluator evaluate the result - */ - protected final ComparisonResult compareDontFire(Comparison comp) { Object controlValue = comp.getControlDetails().getValue(); Object testValue = comp.getTestDetails().getValue(); boolean equal = controlValue == null ? testValue == null : controlValue.equals(testValue); ComparisonResult initial = equal ? ComparisonResult.EQUAL : ComparisonResult.DIFFERENT; - return getDifferenceEvaluator().evaluate(comp, initial); + ComparisonResult altered = + getDifferenceEvaluator().evaluate(comp, initial); + listeners.fireComparisonPerformed(comp, altered); + return altered; } protected static String getXPath(XPathContext ctx) { Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-14 10:23:36 UTC (rev 477) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-14 10:25:52 UTC (rev 478) @@ -68,23 +68,15 @@ /// listeners and returns the outcome. /// </summary> protected internal ComparisonResult Compare(Comparison comp) { - ComparisonResult altered = CompareDontFire(comp); - FireComparisonPerformed(comp, altered); - return altered; - } - - /// <summary> - /// Compares the detail values for object equality, lets the - /// difference evaluator evaluate the result. - /// </summary> - protected internal ComparisonResult CompareDontFire(Comparison comp) { object controlValue = comp.ControlDetails.Value; object testValue = comp.TestDetails.Value; bool equal = controlValue == null ? testValue == null : controlValue.Equals(testValue); ComparisonResult initial = equal ? ComparisonResult.EQUAL : ComparisonResult.DIFFERENT; - return DifferenceEvaluator(comp, initial); + ComparisonResult altered = DifferenceEvaluator(comp, initial); + FireComparisonPerformed(comp, altered); + return altered; } private void FireComparisonPerformed(Comparison comp, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 10:23:42
|
Revision: 477 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=477&view=rev Author: bodewig Date: 2010-09-14 10:23:36 +0000 (Tue, 14 Sep 2010) Log Message: ----------- the legacy DifferenceEngine doesn't only match Elements Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 10:10:30 UTC (rev 476) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 10:23:36 UTC (rev 477) @@ -547,12 +547,11 @@ for (Node n : controlNodes) { if (map.containsKey(n)) { result.add(new Entry(n, map.get(n))); - } else if (n instanceof Element) { + } else { Iterable<Node> unmatchedTestElements = Linqy.filter(testNodes, new Linqy.Predicate<Node>() { public boolean matches(Node t) { - return t instanceof Element - && !map.containsValue(t); + return !map.containsValue(t); } }); Iterator<Node> it = unmatchedTestElements.iterator(); Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-14 10:10:30 UTC (rev 476) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-14 10:23:36 UTC (rev 477) @@ -205,9 +205,8 @@ listenToDifferences(control, test); assertEquals("11th control xpath", "/stuff[1]/list[1]/item[1]", listener.controlXpath); - // this is different from DifferenceEngine - the test node is null - // if there is no match - assertNull("11th test xpath", listener.testXpath); + assertEquals("11th test xpath", "/stuff[1]/list[1]/text()[1]", + listener.testXpath); } public void testXpathLocation12() throws Exception { @@ -227,13 +226,13 @@ String control = "<stuff><item id=\"1\"/><item id=\"2\"/></stuff>"; String test = "<stuff><?item data?></stuff>"; listenToDifferences(control, test); - // mutiple Differences, we only see the last one, missing PI in test + // mutiple Differences, we only see the last one, missing second element assertEquals("13 difference type", DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, listener.comparingWhat); - assertNull("13th control xpath", listener.controlXpath); - assertEquals("13th test xpath", "/stuff[1]/processing-instruction()[1]", - listener.testXpath); + assertEquals("13th control xpath", "/stuff[1]/item[2]", + listener.controlXpath); + assertNull("13th test xpath", listener.testXpath); } public void testXpathLocation14() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 10:10:37
|
Revision: 476 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=476&view=rev Author: bodewig Date: 2010-09-14 10:10:30 +0000 (Tue, 14 Sep 2010) Log Message: ----------- enable NewDifferenceEngine even for compareUnmatched = true Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-14 07:28:50 UTC (rev 475) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-14 10:10:30 UTC (rev 476) @@ -421,15 +421,14 @@ private DifferenceEngineContract getDifferenceEngine() { if (differenceEngine == null) { if ( - !XMLUnit.getExplicitCompareUnmatched() - && XMLUnit.getIgnoreAttributeOrder() && !XMLUnit.getNormalizeWhitespace() && differenceListenerDelegate == null && - !usesUnknownElementQualifier() + (!usesUnknownElementQualifier() + || XMLUnit.getCompareUnmatched()) ) { return new NewDifferenceEngine(this, matchTrackerDelegate); } Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 07:28:50 UTC (rev 475) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 10:10:30 UTC (rev 476) @@ -36,6 +36,10 @@ package org.custommonkey.xmlunit; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.Map; import javax.xml.namespace.QName; import javax.xml.transform.Source; @@ -48,8 +52,10 @@ import net.sf.xmlunit.diff.DefaultNodeMatcher; import net.sf.xmlunit.diff.DifferenceEvaluators; import net.sf.xmlunit.diff.ElementSelector; +import net.sf.xmlunit.diff.NodeMatcher; import net.sf.xmlunit.input.CommentLessSource; import net.sf.xmlunit.input.WhitespaceStrippedSource; +import net.sf.xmlunit.util.Linqy; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; @@ -170,9 +176,15 @@ } }); + NodeMatcher m = new DefaultNodeMatcher(); if (elementQualifier != null) { - engine.setNodeMatcher(new DefaultNodeMatcher(new ElementQualifier2ElementSelector(elementQualifier))); + m = new DefaultNodeMatcher(new ElementQualifier2ElementSelector(elementQualifier)); } + if (!XMLUnit.getCompareUnmatched()) { + engine.setNodeMatcher(m); + } else { + engine.setNodeMatcher(new CompareUnmatchedNodeMatcher(m)); + } Input.Builder ctrlBuilder = Input.fromNode(control); Input.Builder tstBuilder = Input.fromNode(test); @@ -513,4 +525,60 @@ } } + private static class CompareUnmatchedNodeMatcher + implements NodeMatcher { + private final NodeMatcher nestedMatcher; + private CompareUnmatchedNodeMatcher(NodeMatcher nested) { + nestedMatcher = nested; + } + + public Iterable<Map.Entry<Node, Node>> + match(Iterable<Node> controlNodes, + Iterable<Node> testNodes) { + final Map<Node, Node> map = new HashMap<Node, Node>(); + for (Map.Entry<Node, Node> e + : nestedMatcher.match(controlNodes, testNodes)) { + map.put(e.getKey(), e.getValue()); + } + + final LinkedList<Map.Entry<Node, Node>> result = + new LinkedList<Map.Entry<Node, Node>>(); + + for (Node n : controlNodes) { + if (map.containsKey(n)) { + result.add(new Entry(n, map.get(n))); + } else if (n instanceof Element) { + Iterable<Node> unmatchedTestElements = + Linqy.filter(testNodes, new Linqy.Predicate<Node>() { + public boolean matches(Node t) { + return t instanceof Element + && !map.containsValue(t); + } + }); + Iterator<Node> it = unmatchedTestElements.iterator(); + if (it.hasNext()) { + Node t = it.next(); + map.put(n, t); + result.add(new Entry(n, t)); + } + } + } + return result; + } + + private static class Entry implements Map.Entry<Node, Node> { + private final Node key; + private final Node value; + private Entry(Node k, Node v) { + key = k; + value = v; + } + public Node getKey() { return key; } + public Node getValue() { return value; } + public Node setValue(Node v) { + throw new UnsupportedOperationException(); + } + } + } + } Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java 2010-09-14 07:28:50 UTC (rev 475) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java 2010-09-14 10:10:30 UTC (rev 476) @@ -83,7 +83,7 @@ private static String xsltVersion = "1.0"; private static String xpathFactoryName = null; private static boolean expandEntities = false; - private static Boolean compareUnmatched = null; + private static boolean compareUnmatched = true; private static final String XSLT_VERSION_START = " version=\""; private static final String XSLT_VERSION_END = "\">"; @@ -887,37 +887,18 @@ * <p>Defaults to true.</p> */ public static void setCompareUnmatched(boolean b) { - compareUnmatched = Boolean.valueOf(b); + compareUnmatched = b; } /** - * Reset whether to compare unmatched control nodes to unmatched - * test nodes to its default setting. - */ - static void clearCompareUnmatched() { - compareUnmatched = null; - } - - /** * Whether unmatched control nodes should be compared to unmatched * test nodes. * * @return true by default */ public static boolean getCompareUnmatched() { - return compareUnmatched != null - ? compareUnmatched.booleanValue() : true; + return compareUnmatched; } - /** - * Whether unmatched control nodes should be compared to unmatched - * test nodes. - * - * @return false by default - */ - public static boolean getExplicitCompareUnmatched() { - return compareUnmatched != null - ? compareUnmatched.booleanValue() : false; - } } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 07:28:50 UTC (rev 475) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 10:10:30 UTC (rev 476) @@ -111,38 +111,13 @@ File test, control; control = new File(test_Constants.BASEDIR + "/src/tests/resources/controlDetail.xml"); test = new File(test_Constants.BASEDIR + "/src/tests/resources/testDetail.xml"); - try { - XMLUnit.setCompareUnmatched(true); - DetailedDiff differencesWithWhitespace = new DetailedDiff( - new Diff(new InputSource(new FileReader(control)), - new InputSource(new FileReader(test))) ); - List l = differencesWithWhitespace.getAllDifferences(); - int unmatchedNodes = 0; - for (Iterator iter = l.iterator(); iter.hasNext();) { - Difference d = (Difference) iter.next(); - if (d.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID) { - unmatchedNodes++; - } - } - - assertEquals(1402 + unmatchedNodes, - differencesWithWhitespace.getAllDifferences().size()); - try { XMLUnit.setIgnoreWhitespace(true); Diff prototype = new Diff(new FileReader(control), new FileReader(test)); DetailedDiff detailedDiff = new DetailedDiff(prototype); List differences = detailedDiff.getAllDifferences(); - unmatchedNodes = 0; - for (Iterator iter = differences.iterator(); iter.hasNext();) { - Difference d = (Difference) iter.next(); - if (d.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID) { - unmatchedNodes++; - } - } - assertEquals(40 + unmatchedNodes, differences.size()); SimpleXpathEngine xpathEngine = new SimpleXpathEngine(); Document controlDoc = @@ -187,10 +162,6 @@ } finally { XMLUnit.setIgnoreWhitespace(false); } - } finally { - XMLUnit.clearCompareUnmatched(); - } - } public void testSeeAllDifferencesEvenIfDiffWouldSayHaltComparison() throws Exception { @@ -276,8 +247,8 @@ DetailedDiff dd = new DetailedDiff(diff); List l = dd.getAllDifferences(); assertEquals(3, l.size()); - // (0) number of children, (1) node not found, (2) order different - Difference d = (Difference) l.get(1); + // (0) number of children, (1) order different, (2) node not found + Difference d = (Difference) l.get(2); assertEquals(DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, d.getId()); assertEquals("/books[1]/book[1]", @@ -332,26 +303,21 @@ * https://sourceforge.net/tracker/?func=detail&aid=2758280&group_id=23187&atid=377768 */ public void testCompareUnmatched() throws Exception { - try { - XMLUnit.setCompareUnmatched(true); - String control = "<root><a>1</a>" - + "<b>1</b>" - + "<c>1</c>" - + "<d>1</d>" - + "<e>1</e></root>"; - String test = "<root><a>1</a>" - + "<b>1</b>" - + "<z>1</z>" - + "<d>1</d>" - + "<e>1</e></root>"; - DetailedDiff d = (DetailedDiff) buildDiff(control, test); - List l = d.getAllDifferences(); - assertEquals(1, l.size()); - Difference diff = (Difference) l.get(0); - assertEquals(DifferenceConstants.ELEMENT_TAG_NAME_ID, diff.getId()); - } finally { - XMLUnit.clearCompareUnmatched(); - } + String control = "<root><a>1</a>" + + "<b>1</b>" + + "<c>1</c>" + + "<d>1</d>" + + "<e>1</e></root>"; + String test = "<root><a>1</a>" + + "<b>1</b>" + + "<z>1</z>" + + "<d>1</d>" + + "<e>1</e></root>"; + DetailedDiff d = (DetailedDiff) buildDiff(control, test); + List l = d.getAllDifferences(); + assertEquals(1, l.size()); + Difference diff = (Difference) l.get(0); + assertEquals(DifferenceConstants.ELEMENT_TAG_NAME_ID, diff.getId()); } /** @@ -384,7 +350,7 @@ assertNull(diff.getControlNodeDetail().getNode()); assertNotNull(diff.getTestNodeDetail().getNode()); } finally { - XMLUnit.clearCompareUnmatched(); + XMLUnit.setCompareUnmatched(true); } } @@ -449,7 +415,7 @@ diff.getTestNodeDetail().getXpathLocation()); } finally { - XMLUnit.clearCompareUnmatched(); + XMLUnit.setCompareUnmatched(true); } } } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-14 07:28:50 UTC (rev 475) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-14 10:10:30 UTC (rev 476) @@ -241,14 +241,13 @@ String control = "<stuff><thing id=\"1\"/><item id=\"2\"/></stuff>"; String test = "<stuff><item id=\"2\"/><item id=\"1\"/></stuff>"; listenToDifferences(control, test); - // DifferenceEngine matches test node //item[2] with control - // node //item[1] and then generates a difference of attribute - // vales by default. - // NewDifferenceEngine has a "no match" for test node - // //item[2] as last comparison - assertNull("14th control xpath", listener.controlXpath); - assertEquals("14th test xpath", "/stuff[1]/item[2]", - listener.testXpath); + assertEquals("14th difference type", + NewDifferenceEngine.CHILD_NODELIST_SEQUENCE_ID, + listener.comparingWhat); + assertEquals("14th control xpath", "/stuff[1]/item[1]", + listener.controlXpath); + assertEquals("14th test xpath", "/stuff[1]/item[1]", + listener.testXpath); } public void testIssue1027863() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 07:28:56
|
Revision: 475 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=475&view=rev Author: bodewig Date: 2010-09-14 07:28:50 +0000 (Tue, 14 Sep 2010) Log Message: ----------- whitespace Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceConstants.java trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceConstants.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceConstants.java 2010-09-14 07:26:52 UTC (rev 474) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceConstants.java 2010-09-14 07:28:50 UTC (rev 475) @@ -97,7 +97,7 @@ * attribute at all. */ int NO_NAMESPACE_SCHEMA_LOCATION_ID = 24; - + /** Comparing an implied attribute value against an explicit value */ public static final Difference ATTR_VALUE_EXPLICITLY_SPECIFIED = new Difference(ATTR_VALUE_EXPLICITLY_SPECIFIED_ID, @@ -181,7 +181,7 @@ public static final Difference CHILD_NODELIST_SEQUENCE = new Difference(CHILD_NODELIST_SEQUENCE_ID, "sequence of child nodes", true); - + /** Comparing 2 Documents only one of which has a doctype */ public static final Difference HAS_DOCTYPE_DECLARATION = new Difference(HAS_DOCTYPE_DECLARATION_ID, Modified: trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs 2010-09-14 07:26:52 UTC (rev 474) +++ trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs 2010-09-14 07:28:50 UTC (rev 475) @@ -16,7 +16,7 @@ using System.Xml; namespace net.sf.xmlunit.diff { - + /// <summary> /// Strategy that matches control and tests nodes for comparison. /// </summary> Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 07:26:52 UTC (rev 474) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 07:28:50 UTC (rev 475) @@ -125,7 +125,7 @@ unmatchedNodes++; } } - + assertEquals(1402 + unmatchedNodes, differencesWithWhitespace.getAllDifferences().size()); @@ -169,7 +169,7 @@ assertEquals(i + " control " + aDifference.toString(), value, aDifference.getControlNodeDetail().getValue()); } - + expr = aDifference.getTestNodeDetail().getXpathLocation(); if (expr == null || expr.length()==0) { System.out.println(aDifference); @@ -219,7 +219,7 @@ // sequence of nodes assertEquals(3, l.size()); } - + /** * @see http://sourceforge.net/forum/forum.php?thread_id=1691528&forum_id=73274 */ @@ -241,7 +241,7 @@ + "<td>Newsitem 1</td>" + "</tr>" + "</table>"; - + DetailedDiff diff = new DetailedDiff(new Diff(control, test)); List changes = diff.getAllDifferences(); // number of children, text of first child, unexpected second Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-09-14 07:26:52 UTC (rev 474) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-09-14 07:28:50 UTC (rev 475) @@ -42,7 +42,7 @@ internal DiffExpecter(ComparisonType type, string controlXPath, string testXPath) : this(type, 1, true, controlXPath, testXPath) { } - + private DiffExpecter(ComparisonType type, int expected, bool withXPath, string controlXPath, string testXPath) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 07:26:58
|
Revision: 474 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=474&view=rev Author: bodewig Date: 2010-09-14 07:26:52 +0000 (Tue, 14 Sep 2010) Log Message: ----------- minor cleanup Modified Paths: -------------- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-14 06:55:50 UTC (rev 473) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-14 07:26:52 UTC (rev 474) @@ -26,8 +26,7 @@ public event ComparisonListener MatchListener; public event ComparisonListener DifferenceListener; - private INodeMatcher nodeMatcher = - new DefaultNodeMatcher(ElementSelectors.Default); + private INodeMatcher nodeMatcher = new DefaultNodeMatcher(); public virtual INodeMatcher NodeMatcher { set { if (value == null) { Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 06:55:50 UTC (rev 473) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 07:26:52 UTC (rev 474) @@ -417,15 +417,13 @@ assertEquals("/Fruits[1]", diff.getTestNodeDetail().getXpathLocation()); - // didn't find the second Apple element - diff = (Difference) l.get(3); - assertEquals(DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, - diff.getId()); - assertEquals("Apple", diff.getControlNodeDetail().getValue()); - assertEquals("null", diff.getTestNodeDetail().getValue()); - assertEquals("/Fruits[1]/Apple[2]", + // Banana is the third child in control but the second one in test + diff = (Difference) l.get(1); + assertEquals("2", diff.getControlNodeDetail().getValue()); + assertEquals("1", diff.getTestNodeDetail().getValue()); + assertEquals("/Fruits[1]/Banana[1]", diff.getControlNodeDetail().getXpathLocation()); - assertEquals(null, + assertEquals("/Fruits[1]/Banana[1]", diff.getTestNodeDetail().getXpathLocation()); // Banana's size attribute doesn't match @@ -439,14 +437,17 @@ assertEquals("/Fruits[1]/Banana[1]/@size", diff.getTestNodeDetail().getXpathLocation()); - // Banana is the third child in control but the second one in test - diff = (Difference) l.get(1); - assertEquals("2", diff.getControlNodeDetail().getValue()); - assertEquals("1", diff.getTestNodeDetail().getValue()); - assertEquals("/Fruits[1]/Banana[1]", + // didn't find the second Apple element + diff = (Difference) l.get(3); + assertEquals(DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, + diff.getId()); + assertEquals("Apple", diff.getControlNodeDetail().getValue()); + assertEquals("null", diff.getTestNodeDetail().getValue()); + assertEquals("/Fruits[1]/Apple[2]", diff.getControlNodeDetail().getXpathLocation()); - assertEquals("/Fruits[1]/Banana[1]", + assertEquals(null, diff.getTestNodeDetail().getXpathLocation()); + } finally { XMLUnit.clearCompareUnmatched(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-14 06:55:57
|
Revision: 473 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=473&view=rev Author: bodewig Date: 2010-09-14 06:55:50 +0000 (Tue, 14 Sep 2010) Log Message: ----------- make the whole process of selecting nodes to match pluggable via a strategy Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEngine.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DefaultNodeMatcher.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/NodeMatcher.java trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs trunk/xmlunit/src/main/net-core/diff/INodeMatcher.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-09-14 06:55:50 UTC (rev 473) @@ -23,7 +23,7 @@ public abstract class AbstractDifferenceEngine implements DifferenceEngine { private final ComparisonListenerSupport listeners = new ComparisonListenerSupport(); - private ElementSelector elementSelector = ElementSelectors.Default; + private NodeMatcher nodeMatcher = new DefaultNodeMatcher(); private DifferenceEvaluator diffEvaluator = DifferenceEvaluators.Default; private Map<String, String> uri2Prefix = Collections.emptyMap(); @@ -48,16 +48,16 @@ listeners.addDifferenceListener(l); } - public void setElementSelector(ElementSelector s) { - if (s == null) { - throw new IllegalArgumentException("element selector must" + public void setNodeMatcher(NodeMatcher n) { + if (n == null) { + throw new IllegalArgumentException("node matcher must" + " not be null"); } - elementSelector = s; + nodeMatcher = n; } - public ElementSelector getElementSelector() { - return elementSelector; + public NodeMatcher getNodeMatcher() { + return nodeMatcher; } public void setDifferenceEvaluator(DifferenceEvaluator e) { Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-14 06:55:50 UTC (rev 473) @@ -20,6 +20,7 @@ <import reference="java.util.HashSet"/> <import reference="java.util.LinkedList"/> <import reference="java.util.List"/> + <import reference="java.util.Map"/> <import reference="java.util.Set"/> <import reference="java.util.TreeSet"/> <import reference="javax.xml.XMLConstants"/> @@ -315,47 +316,46 @@ XPathContext controlContext, Iterable<Node> testSeq, XPathContext testContext) { - List<Node> controlList = Linqy.asList(controlSeq); - List<Node> testList = Linqy.asList(testSeq); - final int testSize = testList.size(); - Set<Integer> unmatchedTestIndexes = new TreeSet<Integer>(); - for (int i = 0; i < testSize; i++) { - unmatchedTestIndexes.add(Integer.valueOf(i)); - } ]]></literal> <lastResultDef/> <literal><![CDATA[ // if there are no children on either Node, the result is equal lastResult = ComparisonResult.EQUAL; - final int controlSize = controlList.size(); - Match lastMatch = new Match(null, -1); - for (int i = 0; i < controlSize; i++) { - controlContext.navigateToChild(i); + + Iterable<Map.Entry<Node, Node>> matches = + getNodeMatcher().match(controlSeq, testSeq); + List<Node> controlList = Linqy.asList(controlSeq); + List<Node> testList = Linqy.asList(testSeq); + Set<Node> seen = new HashSet<Node>(); + for (Map.Entry<Node, Node> pair : matches) { + Node control = pair.getKey(); + seen.add(control); + Node test = pair.getValue(); + seen.add(test); + int controlIndex = controlList.indexOf(control); + int testIndex = testList.indexOf(test); + controlContext.navigateToChild(controlIndex); + testContext.navigateToChild(testIndex); try { - Match testMatch = findMatchingNode(controlList.get(i), testList, - lastMatch.index, - unmatchedTestIndexes); - if (testMatch != null) { ]]></literal> - testContext.navigateToChild(testMatch.index); - try { - Node control = controlList.get(i); - Node test = testMatch.node; - Integer testIndex = Integer.valueOf(testMatch.index); <compareExpr type="CHILD_NODELIST_SEQUENCE" - controlExpr="Integer.valueOf(i)" - testExpr="testIndex" + controlExpr="Integer.valueOf(controlIndex)" + testExpr="Integer.valueOf(testIndex)" /> <compareMethodExpr method="compareNodes" controlExpr="control" testExpr="test"/> <literal><![CDATA[ - unmatchedTestIndexes.remove(testIndex); - lastMatch = testMatch; - } finally { - testContext.navigateToParent(); - } - } else { + } finally { + testContext.navigateToParent(); + controlContext.navigateToParent(); + } + } + final int controlSize = controlList.size(); + for (int i = 0; i < controlSize; i++) { + if (!seen.contains(controlList.get(i))) { + controlContext.navigateToChild(i); + try { lastResult = compare(new Comparison(ComparisonType.CHILD_LOOKUP, controlList.get(i), @@ -365,26 +365,28 @@ ]]></literal> <if-return-boilerplate/> <literal><![CDATA[ + } finally { + controlContext.navigateToParent(); } - } finally { - controlContext.navigateToParent(); } } - for (Integer I : unmatchedTestIndexes) { - int i = I.intValue(); - testContext.navigateToChild(i); - try { - lastResult = - compare(new Comparison(ComparisonType.CHILD_LOOKUP, - null, null, null, - testList.get(i), - getXPath(testContext), - testList.get(i))); + final int testSize = testList.size(); + for (int i = 0; i < testSize; i++) { + if (!seen.contains(testList.get(i))) { + testContext.navigateToChild(i); + try { + lastResult = + compare(new Comparison(ComparisonType.CHILD_LOOKUP, + null, null, null, + testList.get(i), + getXPath(testContext), + testList.get(i))); ]]></literal> <if-return-boilerplate/> <literal><![CDATA[ - } finally { - testContext.navigateToParent(); + } finally { + testContext.navigateToParent(); + } } } return lastResult; @@ -459,51 +461,6 @@ return null; } - private Match findMatchingNode(final Node searchFor, - final List<Node> searchIn, - final int indexOfLastMatch, - final Set<Integer> availableIndexes) { - final int searchSize = searchIn.size(); - for (int i = indexOfLastMatch + 1; i < searchSize; i++) { - if (!availableIndexes.contains(Integer.valueOf(i))) { - continue; - } - if (nodesMatch(searchFor, searchIn.get(i))) { - return new Match(searchIn.get(i), i); - } - } - for (int i = 0; i < indexOfLastMatch; i++) { - if (!availableIndexes.contains(Integer.valueOf(i))) { - continue; - } - if (nodesMatch(searchFor, searchIn.get(i))) { - return new Match(searchIn.get(i), i); - } - } - return null; - } - - private boolean nodesMatch(final Node n1, final Node n2) { - if (n1 instanceof Element && n2 instanceof Element) { - return getElementSelector() - .canBeCompared((Element) n1, (Element) n2); - } - ComparisonResult r = - compareDontFire(new Comparison(ComparisonType.NODE_TYPE, - n1, null, n1.getNodeType(), - n2, null, n2.getNodeType())); - return r != ComparisonResult.CRITICAL && r != ComparisonResult.DIFFERENT; - } - - private class Match { - private final Node node; - private final int index; - private Match(Node match, int index) { - this.node = match; - this.index = index; - } - } - private static final Linqy.Mapper<Node, QName> QNAME_MAPPER = new Linqy.Mapper<Node, QName>() { public QName map(Node n) { return Nodes.getQName(n); } Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DefaultNodeMatcher.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DefaultNodeMatcher.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DefaultNodeMatcher.java 2010-09-14 06:55:50 UTC (rev 473) @@ -0,0 +1,125 @@ +/* + 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 java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import net.sf.xmlunit.util.Linqy; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Strategy that matches control and tests nodes for comparison. + */ +public class DefaultNodeMatcher implements NodeMatcher { + private final ElementSelector elementSelector; + private final NodeTypeMatcher nodeTypeMatcher; + + public DefaultNodeMatcher() { + this(ElementSelectors.Default); + } + + public DefaultNodeMatcher(ElementSelector es) { + this(es, new DefaultNodeTypeMatcher()); + } + + public DefaultNodeMatcher(ElementSelector es, NodeTypeMatcher ntm) { + elementSelector = es; + nodeTypeMatcher = ntm; + } + + public Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, + Iterable<Node> testNodes) { + Map<Node, Node> matches = new LinkedHashMap<Node, Node>(); + List<Node> controlList = Linqy.asList(controlNodes); + List<Node> testList = Linqy.asList(testNodes); + final int testSize = testList.size(); + Set<Integer> unmatchedTestIndexes = new TreeSet<Integer>(); + for (int i = 0; i < testSize; i++) { + unmatchedTestIndexes.add(Integer.valueOf(i)); + } + final int controlSize = controlList.size(); + Match lastMatch = new Match(null, -1); + for (int i = 0; i < controlSize; i++) { + Node control = controlList.get(i); + Match testMatch = findMatchingNode(control, testList, + lastMatch.index, + unmatchedTestIndexes); + if (testMatch != null) { + unmatchedTestIndexes.remove(testMatch.index); + matches.put(control, testMatch.node); + } + } + return matches.entrySet(); + } + + private Match findMatchingNode(final Node searchFor, + final List<Node> searchIn, + final int indexOfLastMatch, + final Set<Integer> availableIndexes) { + final int searchSize = searchIn.size(); + for (int i = indexOfLastMatch + 1; i < searchSize; i++) { + if (!availableIndexes.contains(Integer.valueOf(i))) { + continue; + } + if (nodesMatch(searchFor, searchIn.get(i))) { + return new Match(searchIn.get(i), i); + } + } + for (int i = 0; i < indexOfLastMatch; i++) { + if (!availableIndexes.contains(Integer.valueOf(i))) { + continue; + } + if (nodesMatch(searchFor, searchIn.get(i))) { + return new Match(searchIn.get(i), i); + } + } + return null; + } + + private boolean nodesMatch(final Node n1, final Node n2) { + if (n1 instanceof Element && n2 instanceof Element) { + return elementSelector.canBeCompared((Element) n1, (Element) n2); + } + return nodeTypeMatcher.canBeCompared(n1.getNodeType(), + n2.getNodeType()); + } + + private class Match { + private final Node node; + private final int index; + private Match(Node match, int index) { + this.node = match; + this.index = index; + } + } + + public interface NodeTypeMatcher { + boolean canBeCompared(short controlType, short testType); + } + + private static final short CDATA = Node.TEXT_NODE; + private static final short TEXT = Node.CDATA_SECTION_NODE; + + public static class DefaultNodeTypeMatcher implements NodeTypeMatcher { + public boolean canBeCompared(short controlType, short testType) { + return controlType == testType + || (controlType == CDATA && testType == TEXT) + || (controlType == TEXT && testType == CDATA); + } + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DefaultNodeMatcher.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEngine.java 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEngine.java 2010-09-14 06:55:50 UTC (rev 473) @@ -38,9 +38,9 @@ void addDifferenceListener(ComparisonListener l); /** - * Sets the strategy for selecting elements to compare. + * Sets the strategy for selecting nodes to compare. */ - void setElementSelector(ElementSelector s); + void setNodeMatcher(NodeMatcher n); /** * Determines whether the comparison should stop after given Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/NodeMatcher.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/NodeMatcher.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/NodeMatcher.java 2010-09-14 06:55:50 UTC (rev 473) @@ -0,0 +1,30 @@ +/* + 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 java.util.Map; +import org.w3c.dom.Node; + +/** + * Strategy that matches control and tests nodes for comparison. + */ +public interface NodeMatcher { + + /** + * Matches control and test nodes against each other, returns the + * matching pairs. + */ + Iterable<Map.Entry<Node, Node>> match(Iterable<Node> controlNodes, + Iterable<Node> testNodes); +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/NodeMatcher.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-14 06:55:50 UTC (rev 473) @@ -45,6 +45,7 @@ import net.sf.xmlunit.diff.ComparisonResult; import net.sf.xmlunit.diff.ComparisonType; import net.sf.xmlunit.diff.DOMDifferenceEngine; +import net.sf.xmlunit.diff.DefaultNodeMatcher; import net.sf.xmlunit.diff.DifferenceEvaluators; import net.sf.xmlunit.diff.ElementSelector; import net.sf.xmlunit.input.CommentLessSource; @@ -170,8 +171,7 @@ }); if (elementQualifier != null) { - engine - .setElementSelector(new ElementQualifier2ElementSelector(elementQualifier)); + engine.setNodeMatcher(new DefaultNodeMatcher(new ElementQualifier2ElementSelector(elementQualifier))); } Input.Builder ctrlBuilder = Input.fromNode(control); @@ -349,11 +349,12 @@ if ((comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH && comparison.getControlDetails().getTarget() instanceof Document) || - (comparison.getType() == ComparisonType.CHILD_LOOKUP - && comparison.getTestDetails() != null - && comparison.getTestDetails().getTarget() instanceof Node - && ((Node) comparison.getTestDetails().getTarget()).getParentNode() - instanceof Document) + ( + comparison.getType() == ComparisonType.CHILD_LOOKUP + && + (isNonElementDocumentChild(comparison.getControlDetails()) + || isNonElementDocumentChild(comparison.getTestDetails())) + ) || checkPrelude.shouldSkip() ) { return true; @@ -374,6 +375,12 @@ return false; } + private static boolean isNonElementDocumentChild(Comparison.Detail detail) { + return detail != null && detail.getTarget() instanceof Node + && !(detail.getTarget() instanceof Element) + && ((Node) detail.getTarget()).getParentNode() instanceof Document; + } + public static class ComparisonController2DifferenceEvaluator implements net.sf.xmlunit.diff.DifferenceEvaluator { private final ComparisonController cc; Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-14 06:55:50 UTC (rev 473) @@ -26,16 +26,17 @@ public event ComparisonListener MatchListener; public event ComparisonListener DifferenceListener; - private ElementSelector elementSelector = ElementSelectors.Default; - public virtual ElementSelector ElementSelector { + private INodeMatcher nodeMatcher = + new DefaultNodeMatcher(ElementSelectors.Default); + public virtual INodeMatcher NodeMatcher { set { if (value == null) { - throw new ArgumentNullException("element selector"); + throw new ArgumentNullException("node matcher"); } - elementSelector = value; + nodeMatcher = value; } get { - return elementSelector; + return nodeMatcher; } } Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-14 06:55:50 UTC (rev 473) @@ -353,45 +353,48 @@ XPathContext controlContext, IEnumerable<XmlNode> testSeq, XPathContext testContext) { - IList<XmlNode> controlList = new List<XmlNode>(controlSeq); - IList<XmlNode> testList = new List<XmlNode>(testSeq); - IDictionary<int, object> unmatchedTestIndexes = - new SortedDictionary<int, object>(); - for (int i = 0; i < testList.Count; i++) { - unmatchedTestIndexes.Add(i, DUMMY); - } ]]></literal> <lastResultDef/> <literal><![CDATA[ // if there are no children on either Node, the result is equal lastResult = ComparisonResult.EQUAL; - Match lastMatch = new Match(null, -1); - for (int i = 0; i < controlList.Count; i++) { - Match testMatch = FindMatchingNode(controlList[i], testList, - lastMatch.Index, - unmatchedTestIndexes); - controlContext.NavigateToChild(i); + + IEnumerable<KeyValuePair<XmlNode, XmlNode>> matches = + NodeMatcher.Match(controlSeq, testSeq); + IList<XmlNode> controlList = new List<XmlNode>(controlSeq); + IList<XmlNode> testList = new List<XmlNode>(testSeq); + IDictionary<XmlNode, object> seen = + new Dictionary<XmlNode, object>(); + foreach (KeyValuePair<XmlNode, XmlNode> pair in matches) { + XmlNode control = pair.Key; + seen[control] = DUMMY; + XmlNode test = pair.Value; + seen[test] = DUMMY; + int controlIndex = controlList.IndexOf(control); + int testIndex = testList.IndexOf(test); + controlContext.NavigateToChild(controlIndex); + testContext.NavigateToChild(testIndex); try { - if (testMatch != null) { - XmlNode control = controlList[i]; - XmlNode test = testMatch.Node; - testContext.NavigateToChild(testMatch.Index); - try { ]]></literal> <compareExpr type="CHILD_NODELIST_SEQUENCE" - controlExpr="i" - testExpr="testMatch.Index" + controlExpr="controlIndex" + testExpr="testIndex" /> <compareMethodExpr method="CompareNodes" controlExpr="control" testExpr="test"/> <literal><![CDATA[ - unmatchedTestIndexes.Remove(testMatch.Index); - lastMatch = testMatch; - } finally { - testContext.NavigateToParent(); - } - } else { + } finally { + testContext.NavigateToParent(); + controlContext.NavigateToParent(); + } + } + + int controlSize = controlList.Count; + for (int i = 0; i < controlSize; i++) { + if (!seen.ContainsKey(controlList[i])) { + controlContext.NavigateToChild(i); + try { lastResult = Compare(new Comparison(ComparisonType.CHILD_LOOKUP, controlList[i], @@ -399,26 +402,30 @@ controlList[i], null, null, null)); ]]></literal> - <if-return-boilerplate/> - <literal><![CDATA[ + <if-return-boilerplate/> + <literal><![CDATA[ + } finally { + controlContext.NavigateToParent(); } - } finally { - controlContext.NavigateToParent(); } } - foreach (int i in unmatchedTestIndexes.Keys) { - testContext.NavigateToChild(i); - try { - lastResult = - Compare(new Comparison(ComparisonType.CHILD_LOOKUP, - null, null, null, - testList[i], GetXPath(testContext), - testList[i])); + int testSize = testList.Count; + for (int i = 0; i < testSize; i++) { + if (!seen.ContainsKey(testList[i])) { + testContext.NavigateToChild(i); + try { + lastResult = + Compare(new Comparison(ComparisonType.CHILD_LOOKUP, + null, null, null, + testList[i], + GetXPath(testContext), + testList[i])); ]]></literal> <if-return-boilerplate/> <literal><![CDATA[ - } finally { - testContext.NavigateToParent(); + } finally { + testContext.NavigateToParent(); + } } } return lastResult; @@ -491,52 +498,6 @@ return null; } - private Match FindMatchingNode(XmlNode searchFor, - IList<XmlNode> searchIn, - int indexOfLastMatch, - IDictionary<int, object> - availableIndexes) { - int searchSize = searchIn.Count; - for (int i = indexOfLastMatch + 1; i < searchSize; i++) { - if (!availableIndexes.ContainsKey(i)) { - continue; - } - if (NodesMatch(searchFor, searchIn[i])) { - return new Match(searchIn[i], i); - } - } - for (int i = 0; i < indexOfLastMatch; i++) { - if (!availableIndexes.ContainsKey(i)) { - continue; - } - if (NodesMatch(searchFor, searchIn[i])) { - return new Match(searchIn[i], i); - } - } - return null; - } - - private bool NodesMatch(XmlNode n1, XmlNode n2) { - if (n1 is XmlElement && n2 is XmlElement) { - return ElementSelector(n1 as XmlElement, n2 as XmlElement); - } - ComparisonResult r = - CompareDontFire(new Comparison(ComparisonType.NODE_TYPE, - n1, null, n1.NodeType, - n2, null, n2.NodeType)); - return r != ComparisonResult.CRITICAL - && r != ComparisonResult.DIFFERENT; - } - - internal class Match { - internal readonly XmlNode Node; - internal readonly int Index; - internal Match(XmlNode match, int index) { - Node = match; - Index = index; - } - } - private static XPathContext.INodeInfo TO_NODE_INFO(XmlNode n) { return new XPathContext.DOMNodeInfo(n); } Added: trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs 2010-09-14 06:55:50 UTC (rev 473) @@ -0,0 +1,122 @@ +/* + 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.Collections.Generic; +using System.Xml; + +namespace net.sf.xmlunit.diff { + + /// <summary> + /// Strategy that matches control and tests nodes for comparison. + /// </summary> + public class DefaultNodeMatcher : INodeMatcher { + private static readonly object DUMMY = new object(); + + private readonly ElementSelector elementSelector; + private readonly NodeTypeMatcher nodeTypeMatcher; + + public DefaultNodeMatcher() : this(ElementSelectors.Default) { + } + + public DefaultNodeMatcher(ElementSelector es) : + this(es, DefaultNodeTypeMatcher) { + } + + public DefaultNodeMatcher(ElementSelector es, NodeTypeMatcher ntm) { + elementSelector = es; + nodeTypeMatcher = ntm; + } + + public IEnumerable<KeyValuePair<XmlNode, XmlNode>> + Match(IEnumerable<XmlNode> controlNodes, + IEnumerable<XmlNode> testNodes) { + LinkedList<KeyValuePair<XmlNode, XmlNode>> matches = + new LinkedList<KeyValuePair<XmlNode, XmlNode>>(); + IList<XmlNode> controlList = new List<XmlNode>(controlNodes); + IList<XmlNode> testList = new List<XmlNode>(testNodes); + IDictionary<int, object> unmatchedTestIndexes = + new Dictionary<int, object>(); + for (int i = 0; i < testList.Count; i++) { + unmatchedTestIndexes.Add(i, DUMMY); + } + int controlSize = controlList.Count; + MatchInfo lastMatch = new MatchInfo(null, -1); + for (int i = 0; i < controlSize; i++) { + XmlNode control = controlList[i]; + MatchInfo testMatch = FindMatchingNode(control, testList, + lastMatch.Index, + unmatchedTestIndexes); + if (testMatch != null) { + unmatchedTestIndexes.Remove(testMatch.Index); + matches.AddLast(new KeyValuePair<XmlNode, + XmlNode>(control, testMatch.Node)); + } + } + return matches; + } + + private MatchInfo FindMatchingNode(XmlNode searchFor, + IList<XmlNode> searchIn, + int indexOfLastMatch, + IDictionary<int, object> + availableIndexes) { + int searchSize = searchIn.Count; + for (int i = indexOfLastMatch + 1; i < searchSize; i++) { + if (!availableIndexes.ContainsKey(i)) { + continue; + } + if (NodesMatch(searchFor, searchIn[i])) { + return new MatchInfo(searchIn[i], i); + } + } + for (int i = 0; i < indexOfLastMatch; i++) { + if (!availableIndexes.ContainsKey(i)) { + continue; + } + if (NodesMatch(searchFor, searchIn[i])) { + return new MatchInfo(searchIn[i], i); + } + } + return null; + } + + private bool NodesMatch(XmlNode n1, XmlNode n2) { + if (n1 is XmlElement && n2 is XmlElement) { + return elementSelector(n1 as XmlElement, n2 as XmlElement); + } + return nodeTypeMatcher(n1.NodeType, n2.NodeType); + } + + internal class MatchInfo { + internal readonly XmlNode Node; + internal readonly int Index; + internal MatchInfo(XmlNode match, int index) { + Node = match; + Index = index; + } + } + + public delegate bool NodeTypeMatcher(XmlNodeType controlType, + XmlNodeType testType); + + public static bool DefaultNodeTypeMatcher(XmlNodeType controlType, + XmlNodeType testType) { + return controlType == testType + || (controlType == XmlNodeType.CDATA + && testType == XmlNodeType.Text) + || (controlType == XmlNodeType.Text + && testType == XmlNodeType.CDATA); + } + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/diff/DefaultNodeMatcher.cs ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs 2010-09-14 06:55:50 UTC (rev 473) @@ -38,9 +38,9 @@ event ComparisonListener DifferenceListener; /// <summary> - /// Sets the strategy for selecting elements to compare. + /// Sets the strategy for selecting nodes to compare. /// </summary> - ElementSelector ElementSelector { set; } + INodeMatcher NodeMatcher { set; } /// <summary> /// Determines whether the comparison should stop after given Added: trunk/xmlunit/src/main/net-core/diff/INodeMatcher.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/INodeMatcher.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/diff/INodeMatcher.cs 2010-09-14 06:55:50 UTC (rev 473) @@ -0,0 +1,32 @@ +/* + 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.Collections.Generic; +using System.Xml; + +namespace net.sf.xmlunit.diff { + + /// <summary> + /// Strategy that matches control and tests nodes for comparison. + /// </summary> + public interface INodeMatcher { + /// <summary> + /// Matches control and test nodes against each other, returns + /// the matching pairs. + /// </summary> + IEnumerable<KeyValuePair<XmlNode, XmlNode>> + Match(IEnumerable<XmlNode> controlNodes, + IEnumerable<XmlNode> testNodes); + } +} Property changes on: trunk/xmlunit/src/main/net-core/diff/INodeMatcher.cs ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-09-14 06:55:50 UTC (rev 473) @@ -634,7 +634,7 @@ assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); - d.setElementSelector(ElementSelectors.byName); + d.setNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)); ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP, "/bar[1]", null); d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); @@ -751,7 +751,7 @@ } }; d.setDifferenceEvaluator(ev); - d.setElementSelector(ElementSelectors.byName); + d.setNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)); assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, new XPathContext(), Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-14 06:55:50 UTC (rev 473) @@ -418,7 +418,7 @@ diff.getTestNodeDetail().getXpathLocation()); // didn't find the second Apple element - diff = (Difference) l.get(1); + diff = (Difference) l.get(3); assertEquals(DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, diff.getId()); assertEquals("Apple", diff.getControlNodeDetail().getValue()); @@ -429,7 +429,7 @@ diff.getTestNodeDetail().getXpathLocation()); // Banana's size attribute doesn't match - diff = (Difference) l.get(3); + diff = (Difference) l.get(2); assertEquals(DifferenceConstants.ATTR_VALUE_ID, diff.getId()); assertEquals("10", diff.getControlNodeDetail().getValue()); @@ -440,7 +440,7 @@ diff.getTestNodeDetail().getXpathLocation()); // Banana is the third child in control but the second one in test - diff = (Difference) l.get(2); + diff = (Difference) l.get(1); assertEquals("2", diff.getControlNodeDetail().getValue()); assertEquals("1", diff.getTestNodeDetail().getValue()); assertEquals("/Fruits[1]/Banana[1]", Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-14 06:55:50 UTC (rev 473) @@ -487,6 +487,10 @@ assertFalse("unexpected difference: " + listener.comparingWhat, listener.different); resetListener(); + listenToDifferences(test, control); + assertFalse("unexpected difference: " + listener.comparingWhat, + listener.different); + resetListener(); control = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + "<!-- some comment -->" @@ -500,6 +504,10 @@ listenToDifferences(control, test); assertFalse("unexpected difference: " + listener.comparingWhat, listener.different); + resetListener(); + listenToDifferences(test, control); + assertFalse("unexpected difference: " + listener.comparingWhat, + listener.different); } private void listenToDifferences(String control, String test) Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-09-13 11:49:10 UTC (rev 472) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-09-14 06:55:50 UTC (rev 473) @@ -627,7 +627,7 @@ Assert.AreEqual(1, ex.invoked); d = new DOMDifferenceEngine(); - d.ElementSelector = ElementSelectors.ByName; + d.NodeMatcher = new DefaultNodeMatcher(ElementSelectors.ByName); ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); d.DifferenceListener += ex.ComparisonPerformed; d.DifferenceEvaluator = @@ -743,7 +743,7 @@ outcome); }; d.DifferenceEvaluator = ev; - d.ElementSelector = ElementSelectors.ByName; + d.NodeMatcher = new DefaultNodeMatcher(ElementSelectors.ByName); Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, new XPathContext(), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 11:49:17
|
Revision: 472 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=472&view=rev Author: bodewig Date: 2010-09-13 11:49:10 +0000 (Mon, 13 Sep 2010) Log Message: ----------- tests pass by now Modified Paths: -------------- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_ElementNameAndAttributeQualifier.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 11:47:03 UTC (rev 471) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 11:49:10 UTC (rev 472) @@ -438,7 +438,7 @@ assertFalse("should not be similar: " + diff.toString(), diff.similar()); } - public void NOtestRepeatedElementNamesWithNamespacedAttributeQualification() throws Exception { + public void testRepeatedElementNamesWithNamespacedAttributeQualification() throws Exception { Diff diff = buildDiff("<root xmlns:a=\"http://a.com\" xmlns:b=\"http://b.com\">" + "<node id=\"1\" a:val=\"a\" b:val=\"b\"/><node id=\"2\" a:val=\"a2\" b:val=\"b2\"/></root>", "<root xmlns:c=\"http://a.com\" xmlns:d=\"http://b.com\">" Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_ElementNameAndAttributeQualifier.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_ElementNameAndAttributeQualifier.java 2010-09-13 11:47:03 UTC (rev 471) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_ElementNameAndAttributeQualifier.java 2010-09-13 11:49:10 UTC (rev 472) @@ -219,7 +219,7 @@ /** * @see https://sourceforge.net/forum/forum.php?thread_id=1135716&forum_id=73274l */ - public void NOtestHelpForumThread1135716() throws Exception { + public void testHelpForumThread1135716() throws Exception { String control = "<class id=\"c0\"> " + "<method id=\"c0_m0\"> " + "<dependency_info stmtId=\"c0_m0_s4\"> " Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2010-09-13 11:47:03 UTC (rev 471) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_IgnoreTextAndAttributeValuesDifferenceListener.java 2010-09-13 11:49:10 UTC (rev 472) @@ -120,7 +120,7 @@ listener.differenceFound(difference)); } - public void NOtestClassInUse() throws Exception { + public void testClassInUse() throws Exception { String control = "<clouds><cloud name=\"cumulus\" rain=\"maybe\">fluffy</cloud></clouds>"; String similarTest = "<clouds><cloud name=\"cirrus\" rain=\"no\">wispy</cloud></clouds>"; @@ -160,7 +160,7 @@ 1, recoverable); } - public void NOtestIssue771839() throws Exception { + public void testIssue771839() throws Exception { String xmlString1 = "<location>" + "<street-address>22 any street</street-address>" + "<postcode id='3'>XY0099Z</postcode>" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 11:47:10
|
Revision: 471 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=471&view=rev Author: bodewig Date: 2010-09-13 11:47:03 +0000 (Mon, 13 Sep 2010) Log Message: ----------- adapt test to new engine Modified Paths: -------------- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 11:37:08 UTC (rev 470) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 11:47:03 UTC (rev 471) @@ -770,8 +770,8 @@ assertFalse(diff.toString(), diff.identical()); assertFalse(diff.toString(), diff.similar()); } - - public void NOtestMatchTrackerSetViaOverride() throws Exception { + + public void testMatchTrackerSetViaOverride() throws Exception { Diff diff = buildDiff("<foo/>", "<foo/>"); final int[] count = new int[1]; diff.overrideMatchTracker(new MatchTracker() { @@ -780,14 +780,18 @@ } }); assertTrue(diff.identical()); - // NODE_TYPE (not null), NODE_TYPE(Document), NAMESPACE_URI(none), - // NAMESPACE_PREFIX(none), HAS_DOCTYPE_DECLARATION(no), - // HAS_CHILD_NODES(true) + + // uses new engine + + // NODE_TYPE(Document), NAMESPACE_URI(none), + // NAMESPACE_PREFIX(none), NUMBER_OF_CHILDREN(1) + // HAS_DOCTYPE_DECLARATION(no), CHILD_NODE_SEQUENCE(0) // // NODE_TYPE(Element), NAMESPACE_URI(none), - // NAMESPACE_PREFIX(none), ELEMENT_TAG_NAME(foo), - // ELEMENT_NUM_ATTRIBUTE(none), HAS_CHILD_NODES(false) - assertEquals(12, count[0]); + // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), + // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) + assertEquals(14, count[0]); } public void testMatchTrackerSetViaEngine() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 11:37:15
|
Revision: 470 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=470&view=rev Author: bodewig Date: 2010-09-13 11:37:08 +0000 (Mon, 13 Sep 2010) Log Message: ----------- don't match test nodes more than once Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-13 11:25:11 UTC (rev 469) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-13 11:37:08 UTC (rev 470) @@ -333,7 +333,8 @@ controlContext.navigateToChild(i); try { Match testMatch = findMatchingNode(controlList.get(i), testList, - lastMatch.index); + lastMatch.index, + unmatchedTestIndexes); if (testMatch != null) { ]]></literal> testContext.navigateToChild(testMatch.index); @@ -460,14 +461,21 @@ private Match findMatchingNode(final Node searchFor, final List<Node> searchIn, - final int indexOfLastMatch) { + final int indexOfLastMatch, + final Set<Integer> availableIndexes) { final int searchSize = searchIn.size(); for (int i = indexOfLastMatch + 1; i < searchSize; i++) { + if (!availableIndexes.contains(Integer.valueOf(i))) { + continue; + } if (nodesMatch(searchFor, searchIn.get(i))) { return new Match(searchIn.get(i), i); } } for (int i = 0; i < indexOfLastMatch; i++) { + if (!availableIndexes.contains(Integer.valueOf(i))) { + continue; + } if (nodesMatch(searchFor, searchIn.get(i))) { return new Match(searchIn.get(i), i); } Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-13 11:25:11 UTC (rev 469) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-13 11:37:08 UTC (rev 470) @@ -368,7 +368,8 @@ Match lastMatch = new Match(null, -1); for (int i = 0; i < controlList.Count; i++) { Match testMatch = FindMatchingNode(controlList[i], testList, - lastMatch.Index); + lastMatch.Index, + unmatchedTestIndexes); controlContext.NavigateToChild(i); try { if (testMatch != null) { @@ -492,14 +493,22 @@ private Match FindMatchingNode(XmlNode searchFor, IList<XmlNode> searchIn, - int indexOfLastMatch) { + int indexOfLastMatch, + IDictionary<int, object> + availableIndexes) { int searchSize = searchIn.Count; for (int i = indexOfLastMatch + 1; i < searchSize; i++) { + if (!availableIndexes.ContainsKey(i)) { + continue; + } if (NodesMatch(searchFor, searchIn[i])) { return new Match(searchIn[i], i); } } for (int i = 0; i < indexOfLastMatch; i++) { + if (!availableIndexes.ContainsKey(i)) { + continue; + } if (NodesMatch(searchFor, searchIn[i])) { return new Match(searchIn[i], i); } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 11:25:11 UTC (rev 469) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 11:37:08 UTC (rev 470) @@ -941,7 +941,7 @@ /** * @see https://sourceforge.net/tracker/?func=detail&aid=2807167&group_id=23187&atid=377768 */ - public void NOtestIssue2807167() throws Exception { + public void testIssue2807167() throws Exception { String test = "<tag>" + "<child amount=\"100\" />" + "<child amount=\"100\" />" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 11:25:17
|
Revision: 469 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=469&view=rev Author: bodewig Date: 2010-09-13 11:25:11 +0000 (Mon, 13 Sep 2010) Log Message: ----------- port doctype test to .NET Modified Paths: -------------- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-09-13 10:46:07 UTC (rev 468) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-09-13 11:25:11 UTC (rev 469) @@ -313,21 +313,18 @@ XmlDocument d1, d2; -#if false // ProhibitDtd needs to be handled at a lower level d1 = net.sf.xmlunit.util.Convert .ToDocument(Input.FromMemory("<Book/>").Build()); - d2 = net.sf.xmlunit.util.Convert - .ToDocument(Input.FromMemory("<!DOCTYPE Book PUBLIC " - + "\"XMLUNIT/TEST/PUB\" " - + "\"" + TestResources.BOOK_DTD - + "\">" - + "<Book/>") - .Build()); + d2 = new XmlDocument(); + d2.LoadXml("<!DOCTYPE Book PUBLIC " + + "\"XMLUNIT/TEST/PUB\" " + + "\"" + TestResources.BOOK_DTD + + "\">" + + "<Book/>"); Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(d1, new XPathContext(), d2, new XPathContext())); Assert.AreEqual(1, ex.invoked); -#endif #if false // .NET doesn't like XML 1.1 anyway d = new DOMDifferenceEngine(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 10:46:14
|
Revision: 468 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=468&view=rev Author: bodewig Date: 2010-09-13 10:46:07 +0000 (Mon, 13 Sep 2010) Log Message: ----------- a missing test child node could be signaled after the root element of the control document has been visited Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-13 10:41:11 UTC (rev 467) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-13 10:46:07 UTC (rev 468) @@ -348,6 +348,12 @@ } if ((comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH && comparison.getControlDetails().getTarget() instanceof Document) + || + (comparison.getType() == ComparisonType.CHILD_LOOKUP + && comparison.getTestDetails() != null + && comparison.getTestDetails().getTarget() instanceof Node + && ((Node) comparison.getTestDetails().getTarget()).getParentNode() + instanceof Document) || checkPrelude.shouldSkip() ) { return true; Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 10:41:11 UTC (rev 467) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-13 10:46:07 UTC (rev 468) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008, Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -963,5 +963,19 @@ ElementNameAndAttributeQualifier()); assertTrue(diff.toString(), diff.similar()); } + + public void testCocoonXmlTestCase() throws Exception { + Document control = + XMLUnit.buildTestDocument("<!DOCTYPE skinconfig []>" + + "<!--abcd--><root></root>"); + Document test = + XMLUnit.buildControlDocument("<!DOCTYPE skinconfig [<!--abcd-->]>" + + "<root></root>"); + Diff diff = new Diff(control, test); + assertTrue(diff.toString(), diff.identical()); + + diff = new Diff(test, control); + assertTrue(diff.toString(), diff.identical()); + } } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java 2010-09-13 10:41:11 UTC (rev 467) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java 2010-09-13 10:46:07 UTC (rev 468) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2009, Jeff Martin, Tim Bacon +Copyright (c) 2001-2010, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 10:41:18
|
Revision: 467 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=467&view=rev Author: bodewig Date: 2010-09-13 10:41:11 +0000 (Mon, 13 Sep 2010) Log Message: ----------- tear evaluation of difference and differencelistener apart in legacy difference engine Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java Added Paths: ----------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-13 09:49:28 UTC (rev 466) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-09-13 10:41:11 UTC (rev 467) @@ -72,7 +72,7 @@ * <br />Examples and more at <a href="http://xmlunit.sourceforge.net"/>xmlunit.sourceforge.net</a> */ public class Diff - implements DifferenceListener, ComparisonController { + implements DifferenceEvaluator, DifferenceListener, ComparisonController { private final Document controlDoc; private final Document testDoc; private boolean similar = true; @@ -287,10 +287,7 @@ * Always RETURN_ACCEPT_DIFFERENCE if the call is not delegated. */ public int differenceFound(Difference difference) { - int returnValue = RETURN_ACCEPT_DIFFERENCE; - if (differenceListenerDelegate != null) { - returnValue = differenceListenerDelegate.differenceFound(difference); - } + int returnValue = evaluate(difference); switch (returnValue) { case RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: @@ -325,6 +322,14 @@ return returnValue; } + public int evaluate(Difference difference) { + int returnValue = RETURN_ACCEPT_DIFFERENCE; + if (differenceListenerDelegate != null) { + returnValue = differenceListenerDelegate.differenceFound(difference); + } + return returnValue; + } + /** * DifferenceListener implementation. * If the {@link Diff#overrideDifferenceListener overrideDifferenceListener} @@ -422,6 +427,8 @@ && !XMLUnit.getNormalizeWhitespace() && + differenceListenerDelegate == null + && !usesUnknownElementQualifier() ) { return new NewDifferenceEngine(this, matchTrackerDelegate); Added: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java (rev 0) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java 2010-09-13 10:41:11 UTC (rev 467) @@ -0,0 +1,55 @@ +/* +****************************************************************** +Copyright (c) 2010, Jeff Martin, Tim Bacon +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of the xmlunit.sourceforge.net nor the names + of its contributors may be used to endorse or promote products + derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +****************************************************************** +*/ + +package org.custommonkey.xmlunit; + +/** + * Contains the pure evaluation logic of DifferenceListener + */ +public interface DifferenceEvaluator { + /** + * Receive notification of a difference and decides whether 2 + * nodes are different. + * @param difference a Difference instance as defined in {@link + * DifferenceConstants DifferenceConstants} describing the cause + * of the difference and containing the detail of the nodes that + * differ + * @return int one of the RETURN_... constants of + * DifferenceListener describing how this difference was + * interpreted + */ + int evaluate(Difference difference); +} Property changes on: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEvaluator.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-13 09:49:28 UTC (rev 466) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-13 10:41:11 UTC (rev 467) @@ -45,7 +45,6 @@ import net.sf.xmlunit.diff.ComparisonResult; import net.sf.xmlunit.diff.ComparisonType; import net.sf.xmlunit.diff.DOMDifferenceEngine; -import net.sf.xmlunit.diff.DifferenceEvaluator; import net.sf.xmlunit.diff.DifferenceEvaluators; import net.sf.xmlunit.diff.ElementSelector; import net.sf.xmlunit.input.CommentLessSource; @@ -123,7 +122,7 @@ ElementQualifier elementQualifier) { DOMDifferenceEngine engine = new DOMDifferenceEngine(); - IsBetweenDocumentNodeAndRootElement checkPrelude = + final IsBetweenDocumentNodeAndRootElement checkPrelude = new IsBetweenDocumentNodeAndRootElement(); engine.addComparisonListener(checkPrelude); @@ -132,19 +131,44 @@ .addMatchListener(new MatchTracker2ComparisonListener(matchTracker)); } - DifferenceEvaluator controllerAsEvaluator = - new ComparisonController2DifferenceEvaluator(controller, - checkPrelude); + net.sf.xmlunit.diff.DifferenceEvaluator controllerAsEvaluator = + new ComparisonController2DifferenceEvaluator(controller); + net.sf.xmlunit.diff.DifferenceEvaluator ev = null; if (listener != null) { - DifferenceEvaluator l = - new DifferenceListener2DifferenceEvaluator(listener, checkPrelude); - engine - .setDifferenceEvaluator(DifferenceEvaluators.first(l, - controllerAsEvaluator)); + net.sf.xmlunit.diff.DifferenceEvaluator e = null; + if (listener instanceof org.custommonkey.xmlunit.DifferenceEvaluator) { + e = new DifferenceEvaluatorAdapter((DifferenceEvaluator) listener); + final ComparisonListener l = new DifferenceListener2ComparisonListener(listener); + engine + .addDifferenceListener(new ComparisonListener() { + public void comparisonPerformed(Comparison comparison, + ComparisonResult outcome) { + if (!swallowComparison(comparison, outcome, + checkPrelude)) { + l.comparisonPerformed(comparison, outcome); + } + } + }); + } else { + e = new DifferenceListener2DifferenceEvaluator(listener); + } + ev = DifferenceEvaluators.first(e, controllerAsEvaluator); } else { - engine - .setDifferenceEvaluator(controllerAsEvaluator); + ev = controllerAsEvaluator; } + final net.sf.xmlunit.diff.DifferenceEvaluator evaluator = ev; + engine + .setDifferenceEvaluator(new net.sf.xmlunit.diff.DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (!swallowComparison(comparison, outcome, + checkPrelude)) { + return evaluator.evaluate(comparison, outcome); + } + return outcome; + } + }); + if (elementQualifier != null) { engine .setElementSelector(new ElementQualifier2ElementSelector(elementQualifier)); @@ -345,25 +369,46 @@ } public static class ComparisonController2DifferenceEvaluator - implements DifferenceEvaluator { + implements net.sf.xmlunit.diff.DifferenceEvaluator { private final ComparisonController cc; - private final IsBetweenDocumentNodeAndRootElement checkPrelude; - public ComparisonController2DifferenceEvaluator(ComparisonController c, - IsBetweenDocumentNodeAndRootElement checkPrelude) { + public ComparisonController2DifferenceEvaluator(ComparisonController c) { cc = c; - this.checkPrelude = checkPrelude; } public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - if (!swallowComparison(comparison, outcome, checkPrelude)) { - Difference diff = toDifference(comparison); - if (diff != null && cc.haltComparison(diff)) { - return ComparisonResult.CRITICAL; + Difference diff = toDifference(comparison); + if (diff != null && cc.haltComparison(diff)) { + return ComparisonResult.CRITICAL; + } + return outcome; + } + } + + public static class DifferenceEvaluatorAdapter + implements net.sf.xmlunit.diff.DifferenceEvaluator { + private final DifferenceEvaluator de; + public DifferenceEvaluatorAdapter(DifferenceEvaluator d) { + de = d; + } + + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + Difference diff = toDifference(comparison); + if (diff != null) { + switch (de.evaluate(diff)) { + case DifferenceListener + .RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: + return ComparisonResult.EQUAL; + case DifferenceListener + .RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: + return ComparisonResult.SIMILAR; + case DifferenceListener + .RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: + return ComparisonResult.DIFFERENT; } - return outcome; } - return ComparisonResult.EQUAL; + return outcome; } } @@ -383,36 +428,30 @@ } public static class DifferenceListener2DifferenceEvaluator - implements DifferenceEvaluator { + implements net.sf.xmlunit.diff.DifferenceEvaluator { private final DifferenceListener dl; - private final IsBetweenDocumentNodeAndRootElement checkPrelude; - public DifferenceListener2DifferenceEvaluator(DifferenceListener dl, - IsBetweenDocumentNodeAndRootElement checkPrelude) { + public DifferenceListener2DifferenceEvaluator(DifferenceListener dl) { this.dl = dl; - this.checkPrelude = checkPrelude; } public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - if (!swallowComparison(comparison, outcome, checkPrelude)) { - Difference diff = toDifference(comparison); - if (diff != null) { - switch (dl.differenceFound(diff)) { - case DifferenceListener - .RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: - return ComparisonResult.EQUAL; - case DifferenceListener - .RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: - return ComparisonResult.SIMILAR; - case DifferenceListener - .RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: - return ComparisonResult.DIFFERENT; - } + Difference diff = toDifference(comparison); + if (diff != null) { + switch (dl.differenceFound(diff)) { + case DifferenceListener + .RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: + return ComparisonResult.EQUAL; + case DifferenceListener + .RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: + return ComparisonResult.SIMILAR; + case DifferenceListener + .RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT: + return ComparisonResult.DIFFERENT; } - return outcome; } - return ComparisonResult.EQUAL; + return outcome; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 09:49:34
|
Revision: 466 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=466&view=rev Author: bodewig Date: 2010-09-13 09:49:28 +0000 (Mon, 13 Sep 2010) Log Message: ----------- DIFFERENT is different enough to make nodes not match Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-13 08:29:05 UTC (rev 465) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-13 09:49:28 UTC (rev 466) @@ -484,7 +484,7 @@ compareDontFire(new Comparison(ComparisonType.NODE_TYPE, n1, null, n1.getNodeType(), n2, null, n2.getNodeType())); - return r != ComparisonResult.CRITICAL; + return r != ComparisonResult.CRITICAL && r != ComparisonResult.DIFFERENT; } private class Match { Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-13 08:29:05 UTC (rev 465) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-13 09:49:28 UTC (rev 466) @@ -515,7 +515,8 @@ CompareDontFire(new Comparison(ComparisonType.NODE_TYPE, n1, null, n1.NodeType, n2, null, n2.NodeType)); - return r != ComparisonResult.CRITICAL; + return r != ComparisonResult.CRITICAL + && r != ComparisonResult.DIFFERENT; } internal class Match { Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-13 08:29:05 UTC (rev 465) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-13 09:49:28 UTC (rev 466) @@ -227,13 +227,13 @@ String control = "<stuff><item id=\"1\"/><item id=\"2\"/></stuff>"; String test = "<stuff><?item data?></stuff>"; listenToDifferences(control, test); - // mutiple Differences, we only see the last one, missing second element + // mutiple Differences, we only see the last one, missing PI in test assertEquals("13 difference type", DifferenceConstants.CHILD_NODE_NOT_FOUND_ID, listener.comparingWhat); - assertEquals("13th control xpath", "/stuff[1]/item[2]", - listener.controlXpath); - assertNull("13th test xpath", listener.testXpath); + assertNull("13th control xpath", listener.controlXpath); + assertEquals("13th test xpath", "/stuff[1]/processing-instruction()[1]", + listener.testXpath); } public void testXpathLocation14() throws Exception { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-13 08:29:12
|
Revision: 465 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=465&view=rev Author: bodewig Date: 2010-09-13 08:29:05 +0000 (Mon, 13 Sep 2010) Log Message: ----------- don't fire comparison events when just searching for matching nodes Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-09-12 06:12:20 UTC (rev 464) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-09-13 08:29:05 UTC (rev 465) @@ -82,16 +82,23 @@ * listeners and returns the outcome. */ protected final ComparisonResult compare(Comparison comp) { + ComparisonResult altered = compareDontFire(comp); + listeners.fireComparisonPerformed(comp, altered); + return altered; + } + + /** + * Compares the detail values for object equality, lets the + * difference evaluator evaluate the result + */ + protected final ComparisonResult compareDontFire(Comparison comp) { Object controlValue = comp.getControlDetails().getValue(); Object testValue = comp.getTestDetails().getValue(); boolean equal = controlValue == null ? testValue == null : controlValue.equals(testValue); ComparisonResult initial = equal ? ComparisonResult.EQUAL : ComparisonResult.DIFFERENT; - ComparisonResult altered = - getDifferenceEvaluator().evaluate(comp, initial); - listeners.fireComparisonPerformed(comp, altered); - return altered; + return getDifferenceEvaluator().evaluate(comp, initial); } protected static String getXPath(XPathContext ctx) { Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-12 06:12:20 UTC (rev 464) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-09-13 08:29:05 UTC (rev 465) @@ -481,9 +481,9 @@ .canBeCompared((Element) n1, (Element) n2); } ComparisonResult r = - compare(new Comparison(ComparisonType.NODE_TYPE, - n1, null, n1.getNodeType(), - n2, null, n2.getNodeType())); + compareDontFire(new Comparison(ComparisonType.NODE_TYPE, + n1, null, n1.getNodeType(), + n2, null, n2.getNodeType())); return r != ComparisonResult.CRITICAL; } @@ -515,4 +515,4 @@ } }; ]]></literal> -</class> \ No newline at end of file +</class> Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-12 06:12:20 UTC (rev 464) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-09-13 08:29:05 UTC (rev 465) @@ -68,15 +68,23 @@ /// listeners and returns the outcome. /// </summary> protected internal ComparisonResult Compare(Comparison comp) { + ComparisonResult altered = CompareDontFire(comp); + FireComparisonPerformed(comp, altered); + return altered; + } + + /// <summary> + /// Compares the detail values for object equality, lets the + /// difference evaluator evaluate the result. + /// </summary> + protected internal ComparisonResult CompareDontFire(Comparison comp) { object controlValue = comp.ControlDetails.Value; object testValue = comp.TestDetails.Value; bool equal = controlValue == null ? testValue == null : controlValue.Equals(testValue); ComparisonResult initial = equal ? ComparisonResult.EQUAL : ComparisonResult.DIFFERENT; - ComparisonResult altered = DifferenceEvaluator(comp, initial); - FireComparisonPerformed(comp, altered); - return altered; + return DifferenceEvaluator(comp, initial); } private void FireComparisonPerformed(Comparison comp, Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-12 06:12:20 UTC (rev 464) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-09-13 08:29:05 UTC (rev 465) @@ -512,9 +512,9 @@ return ElementSelector(n1 as XmlElement, n2 as XmlElement); } ComparisonResult r = - Compare(new Comparison(ComparisonType.NODE_TYPE, - n1, null, n1.NodeType, - n2, null, n2.NodeType)); + CompareDontFire(new Comparison(ComparisonType.NODE_TYPE, + n1, null, n1.NodeType, + n2, null, n2.NodeType)); return r != ComparisonResult.CRITICAL; } @@ -536,4 +536,4 @@ && n.NodeType != XmlNodeType.XmlDeclaration; } ]]></literal> -</class> \ No newline at end of file +</class> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-12 06:12:26
|
Revision: 464 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=464&view=rev Author: bodewig Date: 2010-09-12 06:12:20 +0000 (Sun, 12 Sep 2010) Log Message: ----------- yes, the XPath is different, but it is more correct now. XPath for missing element uses the element's XPath and not the one of its parent as well Modified Paths: -------------- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java 2010-09-12 06:07:29 UTC (rev 463) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Difference.java 2010-09-12 06:12:20 UTC (rev 464) @@ -99,7 +99,7 @@ } // bug 2386807 - public void NOtestXpathOfMissingAttribute() throws Exception { + public void testXpathOfMissingAttribute() throws Exception { Diff d = new Diff("<foo><bar a=\"x\" y=\"z\"/></foo>", "<foo><bar a=\"x\"/></foo>"); DetailedDiff dd = new DetailedDiff(d); @@ -115,7 +115,7 @@ Difference d2 = (Difference) diffs.get(1); assertEquals(DifferenceConstants.ATTR_NAME_NOT_FOUND_ID, d2.getId()); - assertEquals("/foo[1]/bar[1]", + assertEquals("/foo[1]/bar[1]/@y", d2.getControlNodeDetail().getXpathLocation()); assertEquals("/foo[1]/bar[1]", d2.getTestNodeDetail().getXpathLocation()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-09-12 06:07:35
|
Revision: 463 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=463&view=rev Author: bodewig Date: 2010-09-12 06:07:29 +0000 (Sun, 12 Sep 2010) Log Message: ----------- ignore anything between the document node and the root element in legacy layer Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-10 15:11:00 UTC (rev 462) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-12 06:07:29 UTC (rev 463) @@ -53,6 +53,7 @@ import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; +import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -121,16 +122,22 @@ public void compare(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) { DOMDifferenceEngine engine = new DOMDifferenceEngine(); + + IsBetweenDocumentNodeAndRootElement checkPrelude = + new IsBetweenDocumentNodeAndRootElement(); + engine.addComparisonListener(checkPrelude); + if (matchTracker != null) { engine .addMatchListener(new MatchTracker2ComparisonListener(matchTracker)); } DifferenceEvaluator controllerAsEvaluator = - new ComparisonController2DifferenceEvaluator(controller); + new ComparisonController2DifferenceEvaluator(controller, + checkPrelude); if (listener != null) { DifferenceEvaluator l = - new DifferenceListener2DifferenceEvaluator(listener); + new DifferenceListener2DifferenceEvaluator(listener, checkPrelude); engine .setDifferenceEvaluator(DifferenceEvaluators.first(l, controllerAsEvaluator)); @@ -309,10 +316,18 @@ Short.valueOf(Node.CDATA_SECTION_NODE); private static boolean swallowComparison(Comparison comparison, - ComparisonResult outcome) { + ComparisonResult outcome, + IsBetweenDocumentNodeAndRootElement + checkPrelude) { if (outcome == ComparisonResult.EQUAL) { return true; } + if ((comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH + && comparison.getControlDetails().getTarget() instanceof Document) + || checkPrelude.shouldSkip() + ) { + return true; + } if (XMLUnit.getIgnoreDiffBetweenTextAndCDATA() && comparison.getType() == ComparisonType.NODE_TYPE) { return ( @@ -332,13 +347,16 @@ public static class ComparisonController2DifferenceEvaluator implements DifferenceEvaluator { private final ComparisonController cc; - public ComparisonController2DifferenceEvaluator(ComparisonController c) { + private final IsBetweenDocumentNodeAndRootElement checkPrelude; + public ComparisonController2DifferenceEvaluator(ComparisonController c, + IsBetweenDocumentNodeAndRootElement checkPrelude) { cc = c; + this.checkPrelude = checkPrelude; } public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - if (!swallowComparison(comparison, outcome)) { + if (!swallowComparison(comparison, outcome, checkPrelude)) { Difference diff = toDifference(comparison); if (diff != null && cc.haltComparison(diff)) { return ComparisonResult.CRITICAL; @@ -367,14 +385,17 @@ public static class DifferenceListener2DifferenceEvaluator implements DifferenceEvaluator { private final DifferenceListener dl; + private final IsBetweenDocumentNodeAndRootElement checkPrelude; - public DifferenceListener2DifferenceEvaluator(DifferenceListener dl) { + public DifferenceListener2DifferenceEvaluator(DifferenceListener dl, + IsBetweenDocumentNodeAndRootElement checkPrelude) { this.dl = dl; + this.checkPrelude = checkPrelude; } public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - if (!swallowComparison(comparison, outcome)) { + if (!swallowComparison(comparison, outcome, checkPrelude)) { Difference diff = toDifference(comparison); if (diff != null) { switch (dl.differenceFound(diff)) { @@ -394,4 +415,50 @@ return ComparisonResult.EQUAL; } } + + /** + * Tests whether the DifferenceEngine is currently processing + * comparisons of "things" between the document node and the + * document's root element (comments or PIs, mostly) since these + * must be ignored for backwards compatibility reasons. + * + * <p>Relies on the following assumptions: + * <ul> + + * <li>the last comparison DOMDifferenceEngine performs on the + * document node is an XML_ENCODING comparison.</li> + * <li>the first comparison DOMDifferenceEngine performs on matching + * root elements is a NODE_TYPE comparison. The control Node + * is an Element Node.</li> + * <li>the first comparison DOMDifferenceEngine performs if the + * root elements don't match is a CHILD_LOOKUP comparison. + * The control Node is an Element Node.</li> + * </ul> + * </p> + */ + private static class IsBetweenDocumentNodeAndRootElement + implements ComparisonListener { + + private boolean haveSeenXmlEncoding = false; + private boolean haveSeenElementNodeComparison = false; + + public void comparisonPerformed(Comparison comparison, + ComparisonResult outcome) { + if (comparison.getType() == ComparisonType.XML_ENCODING) { + haveSeenXmlEncoding = true; + } else if (comparison.getControlDetails().getTarget() + instanceof Element + && + (comparison.getType() == ComparisonType.NODE_TYPE + || comparison.getType() == ComparisonType.CHILD_LOOKUP) + ) { + haveSeenElementNodeComparison = true; + } + } + + private boolean shouldSkip() { + return haveSeenXmlEncoding && !haveSeenElementNodeComparison; + } + } + } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java 2010-09-10 15:11:00 UTC (rev 462) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DifferenceEngine.java 2010-09-12 06:07:29 UTC (rev 463) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008, Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -925,11 +925,46 @@ + "</abc:XMLContent>" + "</abc:EventBody>" + "</abc:Message>"; - listener.tracing = true; listenToDifferences(control, test); assertFalse(listener.different); } + /** + * XMLUnit 1.3 jumps from the document node straight to the root + * element, ignoring any other children the document might have. + * Some people consider this a bug (Issue 2770386) others rely on + * it. + * + * <p>XMLUnit 2.x doesn't ignore differences in the prelude but we + * want to keep the behavior for the legacy code base.</p> + */ + public void testIgnoresDifferencesBetweenDocAndRootElement() + throws Throwable { + String control = + "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<!-- some comment -->" + + "<?foo some PI ?>" + + "<bar/>"; + String test = "<bar/>"; + listenToDifferences(control, test); + assertFalse("unexpected difference: " + listener.comparingWhat, + listener.different); + resetListener(); + control = + "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<!-- some comment -->" + + "<?foo some PI ?>" + + "<bar/>"; + test = + "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<?foo some other PI ?>" + + "<!-- some other comment -->" + + "<bar/>"; + listenToDifferences(control, test); + assertFalse("unexpected difference: " + listener.comparingWhat, + listener.different); + } + private void listenToDifferences(String control, String test) throws SAXException, IOException { Document controlDoc = XMLUnit.buildControlDocument(control); Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-10 15:11:00 UTC (rev 462) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_NewDifferenceEngine.java 2010-09-12 06:07:29 UTC (rev 463) @@ -466,6 +466,42 @@ assertFalse(listener.different); } + /** + * XMLUnit 1.3 jumps from the document node straight to the root + * element, ignoring any other children the document might have. + * Some people consider this a bug (Issue 2770386) others rely on + * it. + * + * <p>XMLUnit 2.x doesn't ignore differences in the prelude but we + * want to keep the behavior for the legacy code base.</p> + */ + public void testIgnoresDifferencesBetweenDocAndRootElement() + throws Throwable { + String control = + "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<!-- some comment -->" + + "<?foo some PI ?>" + + "<bar/>"; + String test = "<bar/>"; + listenToDifferences(control, test); + assertFalse("unexpected difference: " + listener.comparingWhat, + listener.different); + resetListener(); + control = + "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<!-- some comment -->" + + "<?foo some PI ?>" + + "<bar/>"; + test = + "<?xml version = \"1.0\" encoding = \"UTF-8\"?>" + + "<?foo some other PI ?>" + + "<!-- some other comment -->" + + "<bar/>"; + listenToDifferences(control, test); + assertFalse("unexpected difference: " + listener.comparingWhat, + listener.different); + } + private void listenToDifferences(String control, String test) throws SAXException, IOException { listenToDifferences(control, test, DEFAULT_ELEMENT_QUALIFIER); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |