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: <bo...@us...> - 2010-08-31 15:19:36
|
Revision: 446 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=446&view=rev Author: bodewig Date: 2010-08-31 15:19:27 +0000 (Tue, 31 Aug 2010) Log Message: ----------- extract common interface of DifferenceEngine and NewDifferenceEngine Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java Added Paths: ----------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngineContract.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-08-31 15:08:26 UTC (rev 445) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/Diff.java 2010-08-31 15:19:27 UTC (rev 446) @@ -80,7 +80,7 @@ private boolean compared = false; private boolean haltComparison = false; private StringBuffer messages; - private DifferenceEngine differenceEngine; + private DifferenceEngineContract differenceEngine; private DifferenceListener differenceListenerDelegate; private ElementQualifier elementQualifierDelegate; private MatchTracker matchTrackerDelegate; @@ -106,7 +106,7 @@ * Construct a Diff that compares the XML in two Documents */ public Diff(Document controlDoc, Document testDoc) { - this(controlDoc, testDoc, (DifferenceEngine) null); + this(controlDoc, testDoc, (DifferenceEngineContract) null); } /** @@ -141,7 +141,7 @@ * DifferenceEngine */ public Diff(Document controlDoc, Document testDoc, - DifferenceEngine comparator) { + DifferenceEngineContract comparator) { this(controlDoc, testDoc, comparator, new ElementNameQualifier()); } @@ -150,7 +150,7 @@ * DifferenceEngine and ElementQualifier */ public Diff(Document controlDoc, Document testDoc, - DifferenceEngine comparator, + DifferenceEngineContract comparator, ElementQualifier elementQualifier) { this.controlDoc = getManipulatedDocument(controlDoc); this.testDoc = getManipulatedDocument(testDoc); @@ -413,7 +413,7 @@ * Lazily initializes the difference engine if it hasn't been set * via a constructor. */ - private DifferenceEngine getDifferenceEngine() { + private DifferenceEngineContract getDifferenceEngine() { return differenceEngine == null ? new DifferenceEngine(this, matchTrackerDelegate) : differenceEngine; Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java 2010-08-31 15:08:26 UTC (rev 445) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java 2010-08-31 15:19:27 UTC (rev 446) @@ -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 @@ -65,7 +65,9 @@ * sourceforge.net</a> * @see DifferenceListener#differenceFound(Difference) */ -public class DifferenceEngine implements DifferenceConstants { +public class DifferenceEngine + implements DifferenceConstants, DifferenceEngineContract { + private static final String NULL_NODE = "null"; private static final String NOT_NULL_NODE = "not null"; private static final String ATTRIBUTE_ABSENT = "[attribute absent]"; Added: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngineContract.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngineContract.java (rev 0) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngineContract.java 2010-08-31 15:19:27 UTC (rev 446) @@ -0,0 +1,65 @@ +/* +****************************************************************** +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; + +import org.w3c.dom.Node; + +/** + * The pieces of DifferenceEngine's API used by Diff. + * + * <p>This interface allows Diff to switch between {@link + * DifferenceEngine} and {@link NewDifferenceEngine} at will.</p> + */ +public interface DifferenceEngineContract { + /** + * @param matchTracker the instance that is notified on each + * successful match. May be null. + */ + void setMatchTracker(MatchTracker matchTracker); + /** + * Entry point for Node comparison testing. + * @param control Control XML to compare + * @param test Test XML to compare + * @param listener Notified of any {@link Difference differences} detected + * during node comparison testing + * @param elementQualifier Used to determine which elements qualify for + * comparison e.g. when a node has repeated child elements that may occur + * in any sequence and that sequence is not considered important. + */ + void compare(Node control, Node test, DifferenceListener listener, + ElementQualifier elementQualifier); +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngineContract.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-08-31 15:08:26 UTC (rev 445) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-08-31 15:19:27 UTC (rev 446) @@ -64,7 +64,9 @@ * sourceforge.net</a> * @see DifferenceListener#differenceFound(Difference) */ -public class NewDifferenceEngine implements DifferenceConstants { +public class NewDifferenceEngine + implements DifferenceConstants, DifferenceEngineContract { + private static final Integer ZERO = Integer.valueOf(0); private final ComparisonController controller; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-31 14:18:02
|
Revision: 444 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=444&view=rev Author: bodewig Date: 2010-08-31 14:17:56 +0000 (Tue, 31 Aug 2010) Log Message: ----------- add forgotten child_nodelist_sequence comparison 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-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-31 10:15:01 UTC (rev 443) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-31 14:17:56 UTC (rev 444) @@ -326,12 +326,16 @@ ]]></literal> testContext.navigateToChild(testMatch.index); try { + Integer testIndex = Integer.valueOf(testMatch.index); + <compareExpr type="CHILD_NODELIST_SEQUENCE" + controlExpr="Integer.valueOf(i)" + testExpr="testIndex" + /> <compareMethodExpr method="compareNodes" controlExpr="controlList.get(i)" testExpr="testMatch.node"/> <literal><![CDATA[ - unmatchedTestIndexes - .remove(Integer.valueOf(testMatch.index)); + unmatchedTestIndexes.remove(testIndex); lastMatch = testMatch; } finally { testContext.navigateToParent(); Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-31 10:15:01 UTC (rev 443) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-31 14:17:56 UTC (rev 444) @@ -365,6 +365,10 @@ testContext.NavigateToChild(testMatch.Index); try { ]]></literal> + <compareExpr type="CHILD_NODELIST_SEQUENCE" + controlExpr="i" + testExpr="testMatch.Index" + /> <compareMethodExpr method="CompareNodes" controlExpr="controlList[i]" testExpr="testMatch.Node"/> 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-08-31 10:15:01 UTC (rev 443) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-31 14:17:56 UTC (rev 444) @@ -727,4 +727,41 @@ assertEquals(0, ex.invoked); } + @Test public void childNodeListSequence() { + Element e1 = doc.createElement("foo"); + Element e3 = doc.createElement("bar"); + Element e4 = doc.createElement("baz"); + e1.appendChild(e3); + e1.appendChild(e4); + + Element e2 = doc.createElement("foo"); + Element e5 = doc.createElement("bar"); + Element e6 = doc.createElement("baz"); + e2.appendChild(e6); + e2.appendChild(e5); + + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.CHILD_NODELIST_SEQUENCE, + "/bar[1]", "/bar[1]"); + d.addDifferenceListener(ex); + DifferenceEvaluator ev = new DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (outcome != ComparisonResult.EQUAL + && comparison.getType() == ComparisonType.CHILD_NODELIST_SEQUENCE) { + return ComparisonResult.CRITICAL; + } + return DifferenceEvaluators.DefaultStopWhenDifferent + .evaluate(comparison, outcome); + } + }; + d.setDifferenceEvaluator(ev); + d.setElementSelector(ElementSelectors.byName); + + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); + assertEquals(1, ex.invoked); + } + } Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-31 10:15:01 UTC (rev 443) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-31 14:17:56 UTC (rev 444) @@ -717,5 +717,41 @@ e2, new XPathContext())); Assert.AreEqual(0, ex.invoked); } + + [Test] + public void ChildNodeListSequence() { + XmlElement e1 = doc.CreateElement("foo"); + XmlElement e3 = doc.CreateElement("bar"); + XmlElement e4 = doc.CreateElement("baz"); + e1.AppendChild(e3); + e1.AppendChild(e4); + + XmlElement e2 = doc.CreateElement("foo"); + XmlElement e5 = doc.CreateElement("bar"); + XmlElement e6 = doc.CreateElement("baz"); + e2.AppendChild(e6); + e2.AppendChild(e5); + + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.CHILD_NODELIST_SEQUENCE, + "/bar[1]", "/bar[1]"); + d.DifferenceListener += ex.ComparisonPerformed; + DifferenceEvaluator ev = delegate(Comparison comparison, + ComparisonResult outcome) { + if (outcome != ComparisonResult.EQUAL + && comparison.Type == ComparisonType.CHILD_NODELIST_SEQUENCE) { + return ComparisonResult.CRITICAL; + } + return DifferenceEvaluators.DefaultStopWhenDifferent(comparison, + outcome); + }; + d.DifferenceEvaluator = ev; + d.ElementSelector = ElementSelectors.ByName; + + Assert.AreEqual(ComparisonResult.CRITICAL, + d.CompareNodes(e1, new XPathContext(), + e2, new XPathContext())); + Assert.AreEqual(1, ex.invoked); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-31 10:15:07
|
Revision: 443 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=443&view=rev Author: bodewig Date: 2010-08-31 10:15:01 +0000 (Tue, 31 Aug 2010) Log Message: ----------- a source that is obtained by stripping comments from a different source Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/CommentLessSource.java trunk/xmlunit/src/main/net-core/input/CommentLessSource.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/input/ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/input/CommentLessSourceTest.java trunk/xmlunit/src/tests/net-core/input/ trunk/xmlunit/src/tests/net-core/input/CommentLessSourceTest.cs Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/CommentLessSource.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/CommentLessSource.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/CommentLessSource.java 2010-08-31 10:15:01 UTC (rev 443) @@ -0,0 +1,48 @@ +/* + 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 javax.xml.transform.stream.StreamSource; + +import net.sf.xmlunit.transform.Transformation; + +/** + * A source that is obtained from a different source by stripping all + * comments. + */ +public final class CommentLessSource extends DOMSource { + + public CommentLessSource(Source originalSource) { + super(); + if (originalSource == null) { + throw new IllegalArgumentException("source must not be null"); + } + Transformation t = new Transformation(originalSource); + t.setStylesheet(getStylesheet()); + setNode(t.transformToDocument()); + } + + private static final String STYLE = + "<stylesheet xmlns=\"http://www.w3.org/1999/XSL/Transform\">" + + "<template match=\"node()[not(self::comment())]|@*\"><copy>" + + "<apply-templates select=\"node()[not(self::comment())]|@*\"/>" + + "</copy></template>" + + "</stylesheet>"; + + private static Source getStylesheet() { + return new StreamSource(new java.io.StringReader(STYLE)); + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/input/CommentLessSource.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/main/net-core/input/CommentLessSource.cs =================================================================== --- trunk/xmlunit/src/main/net-core/input/CommentLessSource.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/input/CommentLessSource.cs 2010-08-31 10:15:01 UTC (rev 443) @@ -0,0 +1,67 @@ +/* + This file is licensed to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +using System; +using System.Xml; +using net.sf.xmlunit.transform; + +namespace net.sf.xmlunit.input { + + /// <summary> + /// ISource implementation that is obtained from a different + /// source by stripping all comments. + /// </summary> + public sealed class CommentLessSource : ISource { + private readonly XmlReader reader; + private string systemId; + + public CommentLessSource(ISource originalSource) { + if (originalSource == null) { + throw new ArgumentNullException(); + } + systemId = originalSource.SystemId; + + Transformation t = new Transformation(originalSource); + t.Stylesheet = Stylesheet; + reader = new XmlNodeReader(t.TransformToDocument()); + } + + public XmlReader Reader { + get { + return reader; + } + } + public string SystemId { + get { + return systemId; + } + set { + systemId = value; + } + } + + private const string STYLE = + "<stylesheet xmlns=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">" + + "<template match=\"node()[not(self::comment())]|@*\"><copy>" + + "<apply-templates select=\"node()[not(self::comment())]|@*\"/>" + + "</copy></template>" + + "</stylesheet>"; + + private static ISource Stylesheet { + get { + return new StreamSource(new System.IO.StringReader(STYLE)); + } + } + } +} Property changes on: trunk/xmlunit/src/main/net-core/input/CommentLessSource.cs ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/input/CommentLessSourceTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/input/CommentLessSourceTest.java (rev 0) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/input/CommentLessSourceTest.java 2010-08-31 10:15:01 UTC (rev 443) @@ -0,0 +1,41 @@ +/* + 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 java.io.StringReader; +import javax.xml.transform.stream.StreamSource; +import net.sf.xmlunit.util.Convert; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.junit.Assert.*; + +public class CommentLessSourceTest { + + @Test public void stripCommentsAtDifferentLevels() { + StreamSource s = + new StreamSource(new StringReader("<?xml version='1.0'?>" + + "<!-- comment 1 -->" + + "<foo>" + + "<!-- comment 2 -->" + + "</foo>")); + CommentLessSource cls = new CommentLessSource(s); + Document d = Convert.toDocument(cls); + assertEquals(1, d.getChildNodes().getLength()); + assertTrue(d.getChildNodes().item(0) instanceof Element); + assertEquals(0, d.getChildNodes().item(0).getChildNodes().getLength()); + } + +} Property changes on: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/input/CommentLessSourceTest.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/tests/net-core/input/CommentLessSourceTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/input/CommentLessSourceTest.cs (rev 0) +++ trunk/xmlunit/src/tests/net-core/input/CommentLessSourceTest.cs 2010-08-31 10:15:01 UTC (rev 443) @@ -0,0 +1,40 @@ +/* + 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 NUnit.Framework; +using System.IO; +using System.Xml; + +namespace net.sf.xmlunit.input { + [TestFixture] + public class CommentLessSourceTest { + + [Test] + public void StripCommentsAtDifferentLevels() { + StreamSource s = + new StreamSource(new StringReader("<?xml version='1.0'?>" + + "<!-- comment 1 -->" + + "<foo>" + + "<!-- comment 2 -->" + + "</foo>")); + CommentLessSource cls = new CommentLessSource(s); + XmlDocument d = net.sf.xmlunit.util.Convert.ToDocument(cls); + Assert.AreEqual(2, d.ChildNodes.Count); + Assert.IsTrue(d.ChildNodes[0] is XmlDeclaration); + Assert.IsTrue(d.ChildNodes[1] is XmlElement); + Assert.AreEqual(0, d.ChildNodes[1].ChildNodes.Count); + } + } +} + Property changes on: trunk/xmlunit/src/tests/net-core/input/CommentLessSourceTest.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-08-31 09:18:36
|
Revision: 442 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=442&view=rev Author: bodewig Date: 2010-08-31 09:18:25 +0000 (Tue, 31 Aug 2010) Log Message: ----------- ELEMENT_TAG_NAME differences must not use prefix Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-31 08:36:50 UTC (rev 441) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-31 09:18:25 UTC (rev 442) @@ -210,7 +210,9 @@ XPathContext testContext) { ]]></literal> <lastResultDef/> - <compare type="ELEMENT_TAG_NAME" property="getTagName()"/> + <compareExpr type="ELEMENT_TAG_NAME" + controlExpr="Nodes.getQName(control).getLocalPart()" + testExpr="Nodes.getQName(test).getLocalPart()"/> <literal><![CDATA[ Attributes controlAttributes = splitAttributes(control.getAttributes()); controlContext 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-08-31 08:36:50 UTC (rev 441) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-31 09:18:25 UTC (rev 442) @@ -701,4 +701,30 @@ e2, new XPathContext())); assertEquals(1, ex.invoked); } + + @Test public void compareElementsNS() { + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.ELEMENT_TAG_NAME); + d.addDifferenceListener(ex); + DifferenceEvaluator ev = new DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.getType() == ComparisonType.NAMESPACE_PREFIX) { + return ComparisonResult.EQUAL; + } + return DifferenceEvaluators.DefaultStopWhenDifferent + .evaluate(comparison, outcome); + } + }; + d.setDifferenceEvaluator(ev); + Element e1 = doc.createElementNS("urn:xmlunit:test", "foo"); + e1.setPrefix("p1"); + Element e2 = doc.createElementNS("urn:xmlunit:test", "foo"); + e2.setPrefix("p2"); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); + assertEquals(0, ex.invoked); + } + } Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-31 08:36:50 UTC (rev 441) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-31 09:18:25 UTC (rev 442) @@ -694,5 +694,28 @@ e2, new XPathContext())); Assert.AreEqual(1, ex.invoked); } + + [Test] + public void CompareElementsNS() { + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.ELEMENT_TAG_NAME); + d.DifferenceListener += ex.ComparisonPerformed; + DifferenceEvaluator ev = delegate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.Type == ComparisonType.NAMESPACE_PREFIX) { + return ComparisonResult.EQUAL; + } + return DifferenceEvaluators.DefaultStopWhenDifferent(comparison, + outcome); + }; + d.DifferenceEvaluator = ev; + + XmlElement e1 = doc.CreateElement("p1", "foo", "urn:xmlunit:test"); + XmlElement e2 = doc.CreateElement("p1", "foo", "urn:xmlunit:test"); + Assert.AreEqual(ComparisonResult.EQUAL, + d.CompareNodes(e1, new XPathContext(), + e2, new XPathContext())); + Assert.AreEqual(0, ex.invoked); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-31 08:36:58
|
Revision: 441 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=441&view=rev Author: bodewig Date: 2010-08-31 08:36:50 +0000 (Tue, 31 Aug 2010) Log Message: ----------- a first-wins combiner for DifferenceEvaluators Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs Added Paths: ----------- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DifferenceEvaluatorsTest.java trunk/xmlunit/src/tests/net-core/diff/DifferenceEvaluatorsTest.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java 2010-08-30 07:57:04 UTC (rev 440) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java 2010-08-31 08:36:50 UTC (rev 441) @@ -101,4 +101,24 @@ } }; } + + /** + * Combines multiple DifferenceEvaluators so that the first one + * that changes the outcome wins. + */ + public static DifferenceEvaluator + first(final DifferenceEvaluator... evaluators) { + return new DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult orig) { + for (DifferenceEvaluator ev : evaluators) { + ComparisonResult evaluated = ev.evaluate(comparison, orig); + if (evaluated != orig) { + return evaluated; + } + } + return orig; + } + }; + } } Modified: trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs 2010-08-30 07:57:04 UTC (rev 440) +++ trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs 2010-08-31 08:36:50 UTC (rev 441) @@ -96,5 +96,22 @@ ? ComparisonResult.CRITICAL : r; }; } + + /// <summary> + /// Combines multiple DifferenceEvaluators so that the first + /// one that changes the outcome wins. + /// </summary> + public static DifferenceEvaluator + First(params DifferenceEvaluator[] evaluators) { + return delegate(Comparison comparison, ComparisonResult orig) { + foreach (DifferenceEvaluator ev in evaluators) { + ComparisonResult evaluated = ev(comparison, orig); + if (evaluated != orig) { + return evaluated; + } + } + return orig; + }; + } } } \ No newline at end of file Added: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DifferenceEvaluatorsTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DifferenceEvaluatorsTest.java (rev 0) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DifferenceEvaluatorsTest.java 2010-08-31 08:36:50 UTC (rev 441) @@ -0,0 +1,56 @@ +/* + 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 org.junit.Test; + +import static org.junit.Assert.*; + +public class DifferenceEvaluatorsTest { + + private static class Evaluator implements DifferenceEvaluator { + private boolean called = false; + private final ComparisonResult ret; + private Evaluator(ComparisonResult ret) { + this.ret = ret; + } + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult orig) { + called = true; + return ret; + } + } + + @Test public void emptyFirstJustWorks() { + DifferenceEvaluator d = DifferenceEvaluators.first(); + assertEquals(ComparisonResult.CRITICAL, + d.evaluate(null, ComparisonResult.CRITICAL)); + } + + @Test public void firstChangeWinsInFirst() { + Evaluator e1 = new Evaluator(ComparisonResult.CRITICAL); + Evaluator e2 = new Evaluator(ComparisonResult.EQUAL); + DifferenceEvaluator d = DifferenceEvaluators.first(e1, e2); + assertEquals(ComparisonResult.CRITICAL, + d.evaluate(null, ComparisonResult.DIFFERENT)); + assertTrue(e1.called); + assertFalse(e2.called); + e1.called = false; + assertEquals(ComparisonResult.EQUAL, + d.evaluate(null, ComparisonResult.CRITICAL)); + assertTrue(e1.called); + assertTrue(e2.called); + } + +} Property changes on: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DifferenceEvaluatorsTest.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/tests/net-core/diff/DifferenceEvaluatorsTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DifferenceEvaluatorsTest.cs (rev 0) +++ trunk/xmlunit/src/tests/net-core/diff/DifferenceEvaluatorsTest.cs 2010-08-31 08:36:50 UTC (rev 441) @@ -0,0 +1,59 @@ +/* + 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 NUnit.Framework; + +namespace net.sf.xmlunit.diff { + + [TestFixture] + public class DifferenceEvaluatorsTest { + + internal class Evaluator { + internal bool Called = false; + private readonly ComparisonResult ret; + internal Evaluator(ComparisonResult ret) { + this.ret = ret; + } + public ComparisonResult Evaluate(Comparison comparison, + ComparisonResult orig) { + Called = true; + return ret; + } + } + + [Test] + public void EmptyFirstJustWorks() { + DifferenceEvaluator d = DifferenceEvaluators.First(); + Assert.AreEqual(ComparisonResult.CRITICAL, + d(null, ComparisonResult.CRITICAL)); + } + + [Test] + public void FirstChangeWinsInFirst() { + Evaluator e1 = new Evaluator(ComparisonResult.CRITICAL); + Evaluator e2 = new Evaluator(ComparisonResult.EQUAL); + DifferenceEvaluator d = DifferenceEvaluators.First(e1.Evaluate, + e2.Evaluate); + Assert.AreEqual(ComparisonResult.CRITICAL, + d(null, ComparisonResult.DIFFERENT)); + Assert.IsTrue(e1.Called); + Assert.IsFalse(e2.Called); + e1.Called = false; + Assert.AreEqual(ComparisonResult.EQUAL, + d(null, ComparisonResult.CRITICAL)); + Assert.IsTrue(e1.Called); + Assert.IsTrue(e2.Called); + } + } +} Property changes on: trunk/xmlunit/src/tests/net-core/diff/DifferenceEvaluatorsTest.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-08-30 07:57:11
|
Revision: 440 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=440&view=rev Author: bodewig Date: 2010-08-30 07:57:04 +0000 (Mon, 30 Aug 2010) Log Message: ----------- implement cast() in terms of map() Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 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-08-30 07:53:46 UTC (rev 439) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-08-30 07:57:04 UTC (rev 440) @@ -31,11 +31,11 @@ } public static <E> Iterable<E> cast(final Iterable i) { - return new Iterable<E>() { - public Iterator<E> iterator() { - return new CastingIterator<E>(i.iterator()); - } - }; + return map(i, new Mapper<Object, E>() { + public E map(Object o) { + return (E) o; + } + }); } public static <E> Iterable<E> singleton(final E single) { @@ -59,22 +59,6 @@ T map(F from); } - private static class CastingIterator<E> implements Iterator<E> { - private final Iterator i; - private CastingIterator(Iterator i) { - this.i = i; - } - public void remove() { - i.remove(); - } - public E next() { - return (E) i.next(); - } - public boolean hasNext() { - return i.hasNext(); - } - } - private static class OnceOnlyIterator<E> implements Iterator<E> { private final E element; private boolean iterated = false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-30 07:53:52
|
Revision: 439 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=439&view=rev Author: bodewig Date: 2010-08-30 07:53:46 +0000 (Mon, 30 Aug 2010) Log Message: ----------- remove redundant check Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-27 15:42:01 UTC (rev 438) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-30 07:53:46 UTC (rev 439) @@ -137,9 +137,7 @@ if (levels.size() < 2) { reset(); } else { - if (levels.size() > 0) { - levels.getLast().reset(); - } + levels.getLast().reset(); levels.removeLast(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-27 15:42:09
|
Revision: 438 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=438&view=rev Author: bodewig Date: 2010-08-27 15:42:01 +0000 (Fri, 27 Aug 2010) Log Message: ----------- track XPath information in DifferenceEngine Modified Paths: -------------- trunk/xmlunit/build.xml trunk/xmlunit/src/buildtools/codegen.xslt 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/util/Linqy.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/util/Linqy.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs trunk/xmlunit/xmlunit.nant.build Modified: trunk/xmlunit/build.xml =================================================================== --- trunk/xmlunit/build.xml 2010-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/build.xml 2010-08-27 15:42:01 UTC (rev 438) @@ -95,6 +95,7 @@ <param name="implements" expression="implements"/> <param name="summaryStart" expression="/** "/> <param name="summaryEnd" expression="*/"/> + <param name="getXPath" expression="getXPath"/> <param name="compareMethod" expression="compare"/> </xslt> Modified: trunk/xmlunit/src/buildtools/codegen.xslt =================================================================== --- trunk/xmlunit/src/buildtools/codegen.xslt 2010-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/buildtools/codegen.xslt 2010-08-27 15:42:01 UTC (rev 438) @@ -27,6 +27,7 @@ <xsl:param name="implements"/> <xsl:param name="summaryStart"/> <xsl:param name="summaryEnd"/> + <xsl:param name="getXPath"/> <xsl:template match="class"> /* @@ -95,9 +96,9 @@ <xsl:template match="compare"> lastResult = <xsl:value-of select="$compareMethod"/>(new Comparison(ComparisonType.<xsl:value-of select="@type"/>, - control, null, + control, <xsl:value-of select="$getXPath"/>(controlContext), control.<xsl:value-of select="@property"/>, - test, null, + test, <xsl:value-of select="$getXPath"/>(testContext), test.<xsl:value-of select="@property"/>)); <xsl:call-template name="if-return-boilerplate"/> </xsl:template> @@ -105,20 +106,22 @@ <xsl:template match="compareExpr"> lastResult = <xsl:value-of select="$compareMethod"/>(new Comparison(ComparisonType.<xsl:value-of select="@type"/>, - control, null, + control, <xsl:value-of select="$getXPath"/>(controlContext), <xsl:value-of select="@controlExpr"/>, - test, null, + 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, test); + 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"/>, <xsl:value-of select="@testExpr"/>); + 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> 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-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-08-27 15:42:01 UTC (rev 438) @@ -93,4 +93,8 @@ listeners.fireComparisonPerformed(comp, altered); return altered; } + + protected static String getXPath(XPathContext ctx) { + return ctx == null ? null : ctx.getXPath(); + } } 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-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-27 15:42:01 UTC (rev 438) @@ -23,9 +23,12 @@ <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="org.w3c.dom.Attr"/> <import reference="org.w3c.dom.CharacterData"/> <import reference="org.w3c.dom.Document"/> @@ -44,7 +47,8 @@ if (test == null) { throw new IllegalArgumentException("test must not be null"); } - compareNodes(Convert.toNode(control), Convert.toNode(test)); + compareNodes(Convert.toNode(control), new XPathContext(), + Convert.toNode(test), new XPathContext()); } /** @@ -59,7 +63,8 @@ * * <p>package private to support tests.</p> */ - ComparisonResult compareNodes(Node control, Node test) { + ComparisonResult compareNodes(Node control, XPathContext controlContext, + Node test, XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="NODE_TYPE" property="getNodeType()"/> @@ -74,7 +79,14 @@ testExpr="testChildren.getLength()"/> <compareMethod method="nodeTypeSpecificComparison"/> <literal><![CDATA[ - return compareNodeLists(controlChildren, testChildren); + controlContext + .setChildren(Linqy.map(new IterableNodeList(controlChildren), + TO_NODE_INFO)); + testContext + .setChildren(Linqy.map(new IterableNodeList(testChildren), + TO_NODE_INFO)); + return compareNodeLists(controlChildren, controlContext, + testChildren, testContext); } /** @@ -84,45 +96,50 @@ * <p>package private to support tests.</p> */ private ComparisonResult nodeTypeSpecificComparison(Node control, - Node test) { + 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, - (CharacterData) test); + controlContext, + (CharacterData) test, testContext); } break; case Node.DOCUMENT_NODE: if (test instanceof Document) { - return compareDocuments((Document) control, - (Document) test); + return compareDocuments((Document) control, controlContext, + (Document) test, testContext); } break; case Node.ELEMENT_NODE: if (test instanceof Element) { - return compareElements((Element) control, - (Element) test); + return compareElements((Element) control, controlContext, + (Element) test, testContext); } break; case Node.PROCESSING_INSTRUCTION_NODE: if (test instanceof ProcessingInstruction) { return compareProcessingInstructions((ProcessingInstruction) control, - (ProcessingInstruction) test); + controlContext, + (ProcessingInstruction) test, + testContext); } break; case Node.DOCUMENT_TYPE_NODE: if (test instanceof DocumentType) { - return compareDocTypes((DocumentType) control, - (DocumentType) test); + return compareDocTypes((DocumentType) control, controlContext, + (DocumentType) test, testContext); } break; case Node.ATTRIBUTE_NODE: if (test instanceof Attr) { - return compareAttributes((Attr) control, - (Attr) test); + return compareAttributes((Attr) control, controlContext, + (Attr) test, testContext); } break; } @@ -133,14 +150,20 @@ * Compares textual content. */ private ComparisonResult compareCharacterData(CharacterData control, - CharacterData test) { + XPathContext controlContext, + CharacterData test, + XPathContext testContext) { return compare(new Comparison(ComparisonType.TEXT_VALUE, control, - null, control.getData(), - test, null, test.getData())); + getXPath(controlContext), + control.getData(), + test, getXPath(testContext), + test.getData())); } private ComparisonResult compareDocuments(Document control, - Document test) { + XPathContext controlContext, + Document test, + XPathContext testContext) { DocumentType controlDt = control.getDoctype(); DocumentType testDt = test.getDoctype(); ]]></literal> @@ -161,12 +184,16 @@ <compare type="XML_STANDALONE" property="getXmlStandalone()"/> <literal><![CDATA[ return compare(new Comparison(ComparisonType.XML_ENCODING, - control, null, control.getXmlEncoding(), - test, null, test.getXmlEncoding())); + control, getXPath(controlContext), + control.getXmlEncoding(), + test, getXPath(testContext), + test.getXmlEncoding())); } private ComparisonResult compareDocTypes(DocumentType control, - DocumentType test) { + XPathContext controlContext, + DocumentType test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="DOCTYPE_NAME" property="getName()"/> @@ -178,13 +205,21 @@ } private ComparisonResult compareElements(Element control, - Element test) { + XPathContext controlContext, + Element test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="ELEMENT_TAG_NAME" property="getTagName()"/> <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" @@ -196,27 +231,42 @@ 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) { + if (testAttr != null) { + testContext.navigateToAttribute(Nodes.getQName(testAttr)); + try { ]]></literal> <compareMethodExpr method="compareNodes" controlExpr="controlAttr" testExpr="testAttr"/> <literal><![CDATA[ - foundTestAttributes.add(testAttr); + 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" @@ -233,17 +283,24 @@ private ComparisonResult compareProcessingInstructions(ProcessingInstruction control, - ProcessingInstruction test) { + 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, null, control.getData(), - test, null, test.getData())); + control, getXPath(controlContext), + control.getData(), + test, getXPath(testContext), + test.getData())); } - private ComparisonResult compareNodeLists(NodeList control, NodeList test) { + private ComparisonResult compareNodeLists(NodeList control, + XPathContext controlContext, + NodeList test, + XPathContext testContext) { List<Node> controlList = IterableNodeList.asList(control); List<Node> testList = IterableNodeList.asList(test); final int testSize = testList.size(); @@ -259,48 +316,72 @@ final int controlSize = controlList.size(); Match lastMatch = new Match(null, -1); for (int i = 0; i < controlSize; i++) { - Match testMatch = findMatchingNode(controlList.get(i), testList, - lastMatch.index); - if (testMatch != null) { + controlContext.navigateToChild(i); + try { + Match testMatch = findMatchingNode(controlList.get(i), testList, + lastMatch.index); + if (testMatch != null) { ]]></literal> + testContext.navigateToChild(testMatch.index); + try { <compareMethodExpr method="compareNodes" controlExpr="controlList.get(i)" testExpr="testMatch.node"/> <literal><![CDATA[ - unmatchedTestIndexes.remove(Integer.valueOf(testMatch.index)); - lastMatch = testMatch; - } else { - lastResult = - compare(new Comparison(ComparisonType.CHILD_LOOKUP, - controlList.get(i), null, - controlList.get(i), - null, null, null)); + unmatchedTestIndexes + .remove(Integer.valueOf(testMatch.index)); + lastMatch = testMatch; + } finally { + testContext.navigateToParent(); + } + } else { + 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(); } } for (Integer I : unmatchedTestIndexes) { int i = I.intValue(); - lastResult = - compare(new Comparison(ComparisonType.CHILD_LOOKUP, - null, null, null, - testList.get(i), null, 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, Attr test) { + 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, null, control.getValue(), - test, null, test.getValue())); + control, getXPath(controlContext), + control.getValue(), + test, getXPath(testContext), + test.getValue())); } private static Attributes splitAttributes(final NamedNodeMap map) { @@ -395,5 +476,16 @@ } } + 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); + } + }; ]]></literal> </class> \ No newline at end of file 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-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-08-27 15:42:01 UTC (rev 438) @@ -46,6 +46,19 @@ }; } + public static <F, T> Iterable<T> map(final Iterable<F> from, + final Mapper<? super F, T> mapper) { + return new Iterable<T>() { + public Iterator<T> iterator() { + return new MappingIterator<F, T>(from.iterator(), mapper); + } + }; + } + + public interface Mapper<F, T> { + T map(F from); + } + private static class CastingIterator<E> implements Iterator<E> { private final Iterator i; private CastingIterator(Iterator i) { @@ -82,4 +95,23 @@ return !iterated; } } + + private static class MappingIterator<F, T> implements Iterator<T> { + private final Iterator<F> i; + private final Mapper<? super F, T> mapper; + private MappingIterator(Iterator<F> i, Mapper<? super F, T> mapper) { + this.i = i; + this.mapper = mapper; + } + public void remove() { + i.remove(); + } + public T next() { + return mapper.map(i.next()); + } + public boolean hasNext() { + return i.hasNext(); + } + } + } \ No newline at end of file Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-08-27 15:42:01 UTC (rev 438) @@ -91,5 +91,9 @@ DifferenceListener(comp, outcome); } } + + protected static string GetXPath(XPathContext ctx) { + return ctx == null ? null : ctx.XPath; + } } } Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-27 15:42:01 UTC (rev 438) @@ -36,7 +36,9 @@ } CompareNodes(net.sf.xmlunit.util.Convert.ToNode(control), - net.sf.xmlunit.util.Convert.ToNode(test)); + new XPathContext(), + net.sf.xmlunit.util.Convert.ToNode(test), + new XPathContext()); } /// <summary> @@ -49,7 +51,10 @@ /// /// Stops as soon as any comparison returns ComparisonResult.CRITICAL. /// </remarks> - internal ComparisonResult CompareNodes(XmlNode control, XmlNode test) { + internal ComparisonResult CompareNodes(XmlNode control, + XPathContext controlContext, + XmlNode test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="NODE_TYPE" property="NodeType"/> @@ -64,7 +69,18 @@ testExpr="testChildren.Count"/> <compareMethod method="NodeTypeSpecificComparison"/> <literal><![CDATA[ - return CompareNodeLists(controlChildren, testChildren); + IEnumerable<XmlNode> cc = Linqy.Cast<XmlNode>(controlChildren); + controlContext + .SetChildren(Linqy.Map<XmlNode, + XPathContext.INodeInfo>(cc, + TO_NODE_INFO)); + IEnumerable<XmlNode> tc = Linqy.Cast<XmlNode>(testChildren); + testContext + .SetChildren(Linqy.Map<XmlNode, + XPathContext.INodeInfo>(tc, + TO_NODE_INFO)); + return CompareNodeLists(controlChildren, controlContext, + testChildren, testContext); } /// <summary> @@ -72,45 +88,56 @@ /// defined for the given combination of nodes. /// </summary> private ComparisonResult NodeTypeSpecificComparison(XmlNode control, - XmlNode test) { + XPathContext controlContext, + XmlNode test, + XPathContext testContext) { switch (control.NodeType) { case XmlNodeType.CDATA: case XmlNodeType.Comment: case XmlNodeType.Text: if (test is XmlCharacterData) { return CompareCharacterData((XmlCharacterData) control, - (XmlCharacterData) test); + controlContext, + (XmlCharacterData) test, + testContext); } break; case XmlNodeType.Document: if (test is XmlDocument) { return CompareDocuments((XmlDocument) control, - (XmlDocument) test); + controlContext, + (XmlDocument) test, testContext); } break; case XmlNodeType.Element: if (test is XmlElement) { return CompareElements((XmlElement) control, - (XmlElement) test); + controlContext, + (XmlElement) test, + testContext); } break; case XmlNodeType.ProcessingInstruction: if (test is XmlProcessingInstruction) { return CompareProcessingInstructions((XmlProcessingInstruction) control, - (XmlProcessingInstruction) test); + controlContext, + (XmlProcessingInstruction) test, + testContext); } break; case XmlNodeType.DocumentType: if (test is XmlDocumentType) { return CompareDocTypes((XmlDocumentType) control, - (XmlDocumentType) test); + controlContext, + (XmlDocumentType) test, testContext); } break; case XmlNodeType.Attribute: if (test is XmlAttribute) { return CompareAttributes((XmlAttribute) control, - (XmlAttribute) test); + controlContext, + (XmlAttribute) test, testContext); } break; } @@ -121,14 +148,20 @@ /// Compares textual content. /// </summary> private ComparisonResult CompareCharacterData(XmlCharacterData control, - XmlCharacterData test) { + XPathContext controlContext, + XmlCharacterData test, + XPathContext testContext) { return Compare(new Comparison(ComparisonType.TEXT_VALUE, control, - null, control.Data, - test, null, test.Data)); + GetXPath(controlContext), + control.Data, + test, GetXPath(testContext), + test.Data)); } private ComparisonResult CompareDocuments(XmlDocument control, - XmlDocument test) { + XPathContext controlContext, + XmlDocument test, + XPathContext testContext) { XmlDocumentType controlDt = control.DocumentType; XmlDocumentType testDt = test.DocumentType; ]]></literal> @@ -155,19 +188,25 @@ } private ComparisonResult CompareDocTypes(XmlDocumentType control, - XmlDocumentType test) { + XPathContext controlContext, + XmlDocumentType test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="DOCTYPE_NAME" property="Name"/> <compare type="DOCTYPE_PUBLIC_ID" property="PublicId"/> <literal><![CDATA[ return Compare(new Comparison(ComparisonType.DOCTYPE_SYSTEM_ID, - control, null, control.SystemId, - test, null, test.SystemId)); + control, GetXPath(controlContext), + control.SystemId, + test, GetXPath(testContext), + test.SystemId)); } private ComparisonResult CompareDeclarations(XmlDeclaration control, - XmlDeclaration test) { + XPathContext controlContext, + XmlDeclaration test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <literal><![CDATA[ @@ -193,18 +232,32 @@ control != null ? control.Encoding : string.Empty; string testEncoding = test != null ? test.Encoding : string.Empty; return Compare(new Comparison(ComparisonType.XML_ENCODING, - control, null, controlEncoding, - test, null, testEncoding)); + control, GetXPath(controlContext), + controlEncoding, + test, GetXPath(testContext), + testEncoding)); } private ComparisonResult CompareElements(XmlElement control, - XmlElement test) { + XPathContext controlContext, + XmlElement test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="ELEMENT_TAG_NAME" property="Name"/> <literal><![CDATA[ Attributes controlAttributes = SplitAttributes(control.Attributes); + controlContext + .AddAttributes(Linqy.Map<XmlAttribute, + XmlQualifiedName>(controlAttributes + .RemainingAttributes, + Nodes.GetQName)); Attributes testAttributes = SplitAttributes(test.Attributes); + testContext + .AddAttributes(Linqy.Map<XmlAttribute, + XmlQualifiedName>(testAttributes + .RemainingAttributes, + Nodes.GetQName)); IDictionary<XmlAttribute, object> foundTestAttributes = new Dictionary<XmlAttribute, object>(); ]]></literal> @@ -216,28 +269,44 @@ XmlAttribute testAttr = FindMatchingAttr(testAttributes.RemainingAttributes, controlAttr); + controlContext.NavigateToAttribute(Nodes.GetQName(controlAttr)); + try { ]]></literal> <compareExpr type="ATTR_NAME_LOOKUP" controlExpr="true" testExpr="testAttr != null"/> <literal><![CDATA[ - if (testAttr != null) { + if (testAttr != null) { + testContext.NavigateToAttribute(Nodes + .GetQName(testAttr)); + try { ]]></literal> <compareMethodExpr method="CompareNodes" controlExpr="controlAttr" testExpr="testAttr"/> <literal><![CDATA[ - foundTestAttributes[testAttr] = DUMMY; + foundTestAttributes[testAttr] = DUMMY; + } finally { + testContext.NavigateToParent(); + } + } + } finally { + controlContext.NavigateToParent(); } } ]]></literal> <literal><![CDATA[ foreach (XmlAttribute testAttr in testAttributes.RemainingAttributes) { + testContext.NavigateToAttribute(Nodes.GetQName(testAttr)); + try { ]]></literal> <compareExpr type="ATTR_NAME_LOOKUP" controlExpr="foundTestAttributes.ContainsKey(testAttr)" testExpr="true"/> <literal><![CDATA[ + } finally { + testContext.NavigateToParent(); + } } ]]></literal> <compareExpr type="SCHEMA_LOCATION" @@ -254,18 +323,24 @@ private ComparisonResult CompareProcessingInstructions(XmlProcessingInstruction control, - XmlProcessingInstruction test) { + XPathContext controlContext, + XmlProcessingInstruction test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="PROCESSING_INSTRUCTION_TARGET" property="Target"/> <literal><![CDATA[ return Compare(new Comparison(ComparisonType.PROCESSING_INSTRUCTION_DATA, - control, null, control.Data, - test, null, test.Data)); + control, GetXPath(controlContext), + control.Data, + test, GetXPath(testContext), + test.Data)); } private ComparisonResult CompareNodeLists(XmlNodeList control, - XmlNodeList test) { + XPathContext controlContext, + XmlNodeList test, + XPathContext testContext) { IList<XmlNode> controlList = new List<XmlNode>(Linqy.Cast<XmlNode>(control)); IList<XmlNode> testList = @@ -284,46 +359,67 @@ for (int i = 0; i < controlList.Count; i++) { Match testMatch = FindMatchingNode(controlList[i], testList, lastMatch.Index); - if (testMatch != null) { + controlContext.NavigateToChild(i); + try { + if (testMatch != null) { + testContext.NavigateToChild(testMatch.Index); + try { ]]></literal> <compareMethodExpr method="CompareNodes" controlExpr="controlList[i]" testExpr="testMatch.Node"/> <literal><![CDATA[ - unmatchedTestIndexes.Remove(testMatch.Index); - lastMatch = testMatch; - } else { - lastResult = - Compare(new Comparison(ComparisonType.CHILD_LOOKUP, - controlList[i], null, - controlList[i], - null, null, null)); + unmatchedTestIndexes.Remove(testMatch.Index); + lastMatch = testMatch; + } finally { + testContext.NavigateToParent(); + } + } else { + lastResult = + Compare(new Comparison(ComparisonType.CHILD_LOOKUP, + controlList[i], + GetXPath(controlContext), + controlList[i], + null, null, null)); ]]></literal> <if-return-boilerplate/> <literal><![CDATA[ + } + } finally { + controlContext.NavigateToParent(); } } foreach (int i in unmatchedTestIndexes.Keys) { - lastResult = - Compare(new Comparison(ComparisonType.CHILD_LOOKUP, - null, null, null, - testList[i], null, 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(); + } } return lastResult; } private ComparisonResult CompareAttributes(XmlAttribute control, - XmlAttribute test) { + XPathContext controlContext, + XmlAttribute test, + XPathContext testContext) { ]]></literal> <lastResultDef/> <compare type="ATTR_VALUE_EXPLICITLY_SPECIFIED" property="Specified"/> <literal><![CDATA[ return Compare(new Comparison(ComparisonType.ATTR_VALUE, - control, null, control.Value, - test, null, test.Value)); + control, GetXPath(controlContext), + control.Value, + test, GetXPath(testContext), + test.Value)); } private static Attributes SplitAttributes(XmlAttributeCollection map) { @@ -414,5 +510,9 @@ Index = index; } } + + private static XPathContext.INodeInfo TO_NODE_INFO(XmlNode n) { + return new XPathContext.DOMNodeInfo(n); + } ]]></literal> </class> \ No newline at end of file Modified: trunk/xmlunit/src/main/net-core/util/Linqy.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-08-27 15:42:01 UTC (rev 438) @@ -30,5 +30,13 @@ yield return t; } + public delegate T Mapper<F, T>(F from); + + public static IEnumerable<T> Map<F, T>(IEnumerable<F> from, + Mapper<F, T> mapper) { + foreach (F f in from) { + yield return mapper(f); + } + } } } \ No newline at end of file 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-08-27 10:54:58 UTC (rev 437) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-27 15:42:01 UTC (rev 438) @@ -44,12 +44,27 @@ private int invoked = 0; private final int expectedInvocations; private final ComparisonType type; + private final boolean withXPath; + private final String controlXPath; + private final String testXPath; private DiffExpecter(ComparisonType type) { this(type, 1); } private DiffExpecter(ComparisonType type, int expected) { + this(type, expected, false, null, null); + } + private DiffExpecter(ComparisonType type, String controlXPath, + String testXPath) { + this(type, 1, true, controlXPath, testXPath); + } + private DiffExpecter(ComparisonType type, int expected, + boolean withXPath, String controlXPath, + String testXPath) { this.type = type; this.expectedInvocations = expected; + this.withXPath = withXPath; + this.controlXPath = controlXPath; + this.testXPath = testXPath; } public void comparisonPerformed(Comparison comparison, ComparisonResult outcome) { @@ -58,6 +73,12 @@ invoked++; assertEquals(type, comparison.getType()); assertEquals(ComparisonResult.CRITICAL, outcome); + if (withXPath) { + assertEquals("Control XPath", controlXPath, + comparison.getControlDetails().getXPath()); + assertEquals("Test XPath", testXPath, + comparison.getTestDetails().getXPath()); + } } } @@ -74,8 +95,8 @@ d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(doc.createElement("x"), - doc.createComment("x"))); + d.compareNodes(doc.createElement("x"), new XPathContext(), + doc.createComment("x"), new XPathContext())); assertEquals(1, ex.invoked); } @@ -85,8 +106,8 @@ d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(doc.createElement("x"), - doc.createElement("x"))); + d.compareNodes(doc.createElement("x"), new XPathContext(), + doc.createElement("x"), new XPathContext())); assertEquals(0, ex.invoked); } @@ -97,7 +118,9 @@ d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); assertEquals(ComparisonResult.CRITICAL, d.compareNodes(doc.createElementNS("x", "y"), - doc.createElementNS("z", "y"))); + new XPathContext(), + doc.createElementNS("z", "y"), + new XPathContext())); assertEquals(1, ex.invoked); } @@ -119,7 +142,9 @@ }); assertEquals(ComparisonResult.CRITICAL, d.compareNodes(doc.createElementNS("x", "x:y"), - doc.createElementNS("x", "z:y"))); + new XPathContext(), + doc.createElementNS("x", "z:y"), + new XPathContext())); assertEquals(1, ex.invoked); } @@ -131,14 +156,22 @@ d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); Element e1 = doc.createElement("x"); Element e2 = doc.createElement("x"); - assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); e1.appendChild(doc.createElement("x")); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); assertEquals(1, ex.invoked); e2.appendChild(doc.createElement("x")); - assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); e2.appendChild(doc.createElement("x")); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); assertEquals(2, ex.invoked); } @@ -174,42 +207,60 @@ CDATASection barCDATASection = doc.createCDATASection("bar"); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooComment, fooComment)); + d.compareNodes(fooComment, new XPathContext(), + fooComment, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooComment, barComment)); + d.compareNodes(fooComment, new XPathContext(), + barComment, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooText, fooText)); + d.compareNodes(fooText, new XPathContext(), + fooText, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooText, barText)); + d.compareNodes(fooText, new XPathContext(), + barText, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooCDATASection, fooCDATASection)); + d.compareNodes(fooCDATASection, new XPathContext(), + fooCDATASection, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooCDATASection, barCDATASection)); + d.compareNodes(fooCDATASection, new XPathContext(), + barCDATASection, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooComment, fooText)); + d.compareNodes(fooComment, new XPathContext(), + fooText, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooComment, barText)); + d.compareNodes(fooComment, new XPathContext(), + barText, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooComment, fooCDATASection)); + d.compareNodes(fooComment, new XPathContext(), + fooCDATASection, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooComment, barCDATASection)); + d.compareNodes(fooComment, new XPathContext(), + barCDATASection, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooText, fooComment)); + d.compareNodes(fooText, new XPathContext(), + fooComment, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooText, barComment)); + d.compareNodes(fooText, new XPathContext(), + barComment, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooText, fooCDATASection)); + d.compareNodes(fooText, new XPathContext(), + fooCDATASection, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooText, barCDATASection)); + d.compareNodes(fooText, new XPathContext(), + barCDATASection, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooCDATASection, fooText)); + d.compareNodes(fooCDATASection, new XPathContext(), + fooText, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooCDATASection, barText)); + d.compareNodes(fooCDATASection, new XPathContext(), + barText, new XPathContext())); assertEquals(ComparisonResult.EQUAL, - d.compareNodes(fooCDATASection, fooComment)); + d.compareNodes(fooCDATASection, new XPathContext(), + fooComment, new XPathContext())); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(fooCDATASection, barComment)); + d.compareNodes(fooCDATASection, new XPathContext(), + barComment, new XPathContext())); assertEquals(9, ex.invoked); } @@ -221,8 +272,12 @@ ProcessingInstruction foo1 = doc.createProcessingInstruction("foo", "1"); ProcessingInstruction bar1 = doc.createProcessingInstruction("bar", "1"); - assertEquals(ComparisonResult.EQUAL, d.compareNodes(foo1, foo1)); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(foo1, bar1)); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(foo1, new XPathContext(), + foo1, new XPathContext())); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(foo1, new XPathContext(), + bar1, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -230,8 +285,12 @@ d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); ProcessingInstruction foo2 = doc.createProcessingInstruction("foo", "2"); - assertEquals(ComparisonResult.EQUAL, d.compareNodes(foo1, foo1)); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(foo1, foo2)); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(foo1, new XPathContext(), + foo1, new XPathContext())); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(foo1, new XPathContext(), + foo2, new XPathContext())); assertEquals(1, ex.invoked); } @@ -266,7 +325,9 @@ + "\">" + "<Book/>") .build()); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(d1, d2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(d1, new XPathContext(), + d2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -281,7 +342,8 @@ + " encoding=\"UTF-8\"?>" + "<Book/>").build()); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(d1, d2)); + d.compareNodes(d1, new XPathContext(), + d2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -296,7 +358,8 @@ + " standalone=\"no\"?>" + "<Book/>").build()); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(d1, d2)); + d.compareNodes(d1, new XPathContext(), + d2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -322,7 +385,8 @@ + " encoding=\"UTF-16\"?>" + "<Book/>").build()); assertEquals(ComparisonResult.CRITICAL, - d.compareNodes(d1, d2)); + d.compareNodes(d1, new XPathContext(), + d2, new XPathContext())); assertEquals(1, ex.invoked); } @@ -363,7 +427,9 @@ d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); DocumentType dt1 = new DocType("name", "pub", "system"); DocumentType dt2 = new DocType("name2", "pub", "system"); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(dt1, dt2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(dt1, new XPathContext(), + dt2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -371,7 +437,9 @@ d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); dt2 = new DocType("name", "pub2", "system"); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(dt1, dt2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(dt1, new XPathContext(), + dt2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -390,7 +458,9 @@ } }); dt2 = new DocType("name", "pub", "system2"); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(dt1, dt2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(dt1, new XPathContext(), + dt2, new XPathContext())); assertEquals(1, ex.invoked); } @@ -402,8 +472,12 @@ Element e1 = doc.createElement("foo"); Element e2 = doc.createElement("foo"); Element e3 = doc.createElement("bar"); - assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e3)); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(e1, new XPathContext(), + e3, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); @@ -411,15 +485,20 @@ e1.setAttribute("attr1", "value1"); d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); assertEquals(1, ex.invoked); d = new DOMDifferenceEngine(); - ex = new DiffExpecter(ComparisonType.ATTR_NAME_LOOKUP); + ex = new DiffExpecter(ComparisonType.ATTR_NAME_LOOKUP, + "/@attr1", "/"); e2.setAttributeNS("urn:xmlunit:test", "attr1", "value1"); d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); - assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.CRITICAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); assertEquals(1, ex.invoked); @@ -438,7 +517,9 @@ e2.setAttributeNS(null, "attr1", "value1"); d.addDifferenceListener(ex); d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); - assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.EQUAL, + d.compareNodes(e1, new XPathContext(), + e2, new XPathContext())); } @Test public void compareAttributes() { @@ -451,7 +532,9 @@ ... [truncated message content] |
From: <bo...@us...> - 2010-08-27 10:55:04
|
Revision: 437 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=437&view=rev Author: bodewig Date: 2010-08-27 10:54:58 +0000 (Fri, 27 Aug 2010) Log Message: ----------- re-implement XpathNodeTracker in terms of XPathContext Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-26 14:46:54 UTC (rev 436) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-27 10:54:58 UTC (rev 437) @@ -35,12 +35,14 @@ */ package org.custommonkey.xmlunit; -import java.util.ArrayList; +import java.util.Deque; import java.util.HashMap; -import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.Map; +import javax.xml.namespace.QName; +import net.sf.xmlunit.diff.XPathContext; import net.sf.xmlunit.util.IterableNodeList; import net.sf.xmlunit.util.Linqy; @@ -72,13 +74,14 @@ * @see Difference#getTestNodeDetail */ public class XpathNodeTracker implements XMLConstants { - private final List indentationList = new ArrayList(); - private TrackingEntry currentEntry; + private XPathContext ctx; + private final Deque<TrackingEntry> levels = new LinkedList<TrackingEntry>(); /** * Simple constructor */ public XpathNodeTracker() { + ctx = new XPathContext(); newLevel(); } @@ -87,7 +90,8 @@ * Call if required to reuse an existing instance. */ public void reset() { - indentationList.clear(); + ctx = new XPathContext(); + levels.clear(); indent(); } @@ -102,15 +106,12 @@ * reset.</p> */ public void indent() { - if (currentEntry != null) { - currentEntry.clearTrackedAttribute(); - } newLevel(); } private void newLevel() { - currentEntry = new TrackingEntry(); - indentationList.add(currentEntry); + clearTrackedAttribute(); + levels.add(new TrackingEntry()); } /** @@ -118,8 +119,8 @@ * compare the child nodes. */ public void clearTrackedAttribute() { - if (currentEntry != null) { - currentEntry.clearTrackedAttribute(); + if (levels.size() > 0) { + levels.getLast().clearTrackedAttribute(); } } @@ -133,11 +134,13 @@ * outdent}.</p> */ public void outdent() { - int last = indentationList.size() - 1; - indentationList.remove(last); - --last; - if (last >= 0) { - currentEntry = (TrackingEntry) indentationList.get(last); + if (levels.size() < 2) { + reset(); + } else { + if (levels.size() > 0) { + levels.getLast().reset(); + } + levels.removeLast(); } } @@ -187,7 +190,7 @@ * identifier matching the type of node. */ protected void visitedNode(Node visited, String value) { - currentEntry.trackNode(visited, value); + levels.getLast().trackNode(visited, value); } /** @@ -196,7 +199,7 @@ * @param visited the local name of the attribute. */ protected void visitedAttribute(String visited) { - currentEntry.trackAttribute(visited); + levels.getLast().trackAttribute(new QName(visited)); } /** @@ -234,13 +237,7 @@ * @return the last visited node as an xpath-location String */ public String toXpathString() { - StringBuilder buf = new StringBuilder(); - TrackingEntry nextEntry; - for (Iterator iter = indentationList.iterator(); iter.hasNext(); ) { - nextEntry = (TrackingEntry) iter.next(); - nextEntry.appendEntryTo(buf); - } - return buf.toString(); + return ctx.getXPath(); } /** @@ -266,120 +263,108 @@ * @param nodeList the items to preload */ private void preloadChildren(Iterable<Node> nodeList) { - currentEntry.trackNodesAsWellAsValues(true); + levels.getLast().trackNodesAsWellAsValues(true); for (Node n : nodeList) { visited(n); } - currentEntry.trackNodesAsWellAsValues(false); + levels.getLast().trackNodesAsWellAsValues(false); } /** - * Wrapper class around a mutable <code>int</code> value - * Avoids creation of many immutable <code>Integer</code> objects - */ - private static final class Int { - private int value; - - Int(int startAt) { - value = startAt; - } - - void increment() { - ++value; - } - - int getValue() { - return value; - } - - Integer toInteger() { - return Integer.valueOf(value); - } - } - - /** * Holds node tracking details - one instance is used for each * level of indentation in a DOM * * Provides reference between a String-ified Node value and the * xpath index of that value */ - private static final class TrackingEntry { - // how often has the key been seen at this level of tracking - // (including this occurence)? - private final Map<String, Int> valueMap = new HashMap<String, Int>(); - // the current XPath expression for this level and the current - // attribute - if any - private String currentValue, currentAttribute; + private final class TrackingEntry { + // Is the XPathContext looking at an attribute? + private boolean atAttribute = false; + // Has the XPathContext walked down a child node? + private boolean atChild = false; + + // the next index usable for a child node + private int nextIndex = 0; + // may be used if children of this level have been preloaded, - // maps the Node instance to number of same-names XPath - // expression that have been seen at this level already. - private Map<Node, Integer> nodeReferenceMap; + // maps the Node instance to index of the Node in the parent's + // child list + private Map<Node, Integer> nodeReferenceMap = null; // node references are tracked while preloading child nodes private boolean trackNodeReferences = false; - // index of current node obtained from nodeReferenceMap - if any. - private Integer nodeReferenceLookup = null; - /** * Keep a reference to the current visited (non-attribute) node * @param visited the non-attribute node visited * @param value the String-ified value of the non-attribute node visited */ - void trackNode(Node visited, String value) { - if (nodeReferenceMap == null || trackNodeReferences) { - Int occurrence = valueMap.get(value); - if (occurrence == null) { - occurrence = new Int(1); - valueMap.put(value, occurrence); + private void trackNode(final Node visited, final String value) { + if (trackNodeReferences && visited != null) { + nodeReferenceMap.put(visited, nextIndex++); + } + + int currentIndex = 0; + if (nodeReferenceMap == null || visited == null || + !nodeReferenceMap.containsKey(visited)) { + currentIndex = nextIndex++; + } else { + currentIndex = nodeReferenceMap.get(visited).intValue(); + } + reset(); + + if (trackNodeReferences || nodeReferenceMap == null) { + XPathContext.NodeInfo i = null; + if (visited != null) { + i = new XPathContext.DOMNodeInfo(visited); } else { - occurrence.increment(); + // visited is only ever null when invoked from the + // unit tests and in this case it is always + // expected to be an element node + i = new XPathContext.NodeInfo() { + public short getType() { return Node.ELEMENT_NODE; } + public QName getName() { return new QName(value); } + }; } - if (trackNodeReferences) { - nodeReferenceMap.put(visited, occurrence.toInteger()); - } - } else { - nodeReferenceLookup = nodeReferenceMap.get(visited); + ctx.appendChildren(Linqy.singleton(i)); } - currentValue = value; - clearTrackedAttribute(); + + if (!trackNodeReferences) { + ctx.navigateToChild(currentIndex); + atChild = true; + } } /** * Keep a reference to the visited attribute at the current visited node * @param value the attribute visited */ - void trackAttribute(String visited) { - currentAttribute = visited; + private void trackAttribute(QName visited) { + if (atAttribute) { + ctx.navigateToParent(); + } + ctx.addAttributes(Linqy.singleton(visited)); + ctx.navigateToAttribute(visited); + atAttribute = true; } /** * Clear any reference to the current visited attribute */ void clearTrackedAttribute() { - currentAttribute = null; + if (atAttribute) { + ctx.navigateToParent(); + atAttribute = false; + } } - /** - * Append the details of the current visited node to a StringBuilder - * @param buf the StringBuilder to append to - */ - void appendEntryTo(StringBuilder buf) { - if (currentValue == null) { - return; + private void reset() { + clearTrackedAttribute(); + if (atChild) { + ctx.navigateToParent(); + atChild = false; } - buf.append(XPATH_SEPARATOR).append(currentValue); - - int value = nodeReferenceLookup == null - ? valueMap.get(currentValue).getValue() : nodeReferenceLookup.intValue(); - buf.append(XPATH_NODE_INDEX_START).append(value).append(XPATH_NODE_INDEX_END); - - if (currentAttribute != null) { - buf.append(XPATH_SEPARATOR).append(XPATH_ATTRIBUTE_IDENTIFIER) - .append(currentAttribute); - } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-26 14:47:00
|
Revision: 436 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=436&view=rev Author: bodewig Date: 2010-08-26 14:46:54 +0000 (Thu, 26 Aug 2010) Log Message: ----------- allow child elements to be added incrementally in XPathContext Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java trunk/xmlunit/src/main/net-core/diff/XPathContext.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-23 08:42:44 UTC (rev 435) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-26 14:46:54 UTC (rev 436) @@ -28,6 +28,15 @@ private final Deque<Level> path = new LinkedList<Level>(); private final Map<String, String> uri2Prefix; + private static final String COMMENT = "comment()"; + private static final String PI = "processing-instruction()"; + private static final String TEXT = "text()"; + private static final String OPEN = "["; + private static final String CLOSE = "]"; + private static final String SEP = "/"; + private static final String ATTR = "@"; + private static final String EMPTY = ""; + public XPathContext() { this(null); } @@ -38,7 +47,7 @@ } else { this.uri2Prefix = Collections.unmodifiableMap(uri2Prefix); } - path.addLast(new Level("")); + path.addLast(new Level(EMPTY)); } public void navigateToChild(int index) { @@ -53,42 +62,63 @@ path.removeLast(); } - public void registerAttributes(Iterable<? extends QName> attributes) { + public void addAttributes(Iterable<? extends QName> attributes) { Level current = path.getLast(); for (QName attribute : attributes) { current.attributes.put(attribute, - new Level("@" + getName(attribute))); + new Level(ATTR + getName(attribute))); } } - public void registerChildren(Iterable<? extends NodeInfo> children) { + public void setChildren(Iterable<? extends NodeInfo> children) { Level current = path.getLast(); + current.children.clear(); + appendChildren(children); + } + + public void appendChildren(Iterable<? extends NodeInfo> children) { + Level current = path.getLast(); int comments, pis, texts; comments = pis = texts = 0; Map<String, Integer> elements = new HashMap<String, Integer>(); + + for (Level l : current.children) { + String childName = l.expression; + if (childName.startsWith(COMMENT)) { + comments++; + } else if (childName.startsWith(PI)) { + pis++; + } else if (childName.startsWith(TEXT)) { + texts++; + } else { + childName = childName.substring(0, childName.indexOf(OPEN)); + add1OrIncrement(childName, elements); + } + } + for (NodeInfo child : children) { Level l = null; switch (child.getType()) { case Node.COMMENT_NODE: - l = new Level("comment()[" + (++comments) + "]"); + l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case Node.PROCESSING_INSTRUCTION_NODE: - l = new Level("processing-instruction()[" + (++pis) + "]"); + l = new Level(PI + OPEN + (++pis) + CLOSE); break; case Node.CDATA_SECTION_NODE: case Node.TEXT_NODE: - l = new Level("text()[" + (++texts) + "]"); + l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case Node.ELEMENT_NODE: String name = getName(child.getName()); - Integer old = elements.get(name); - int index = old == null ? 0 : old.intValue(); - l = new Level(name + "[" + (++index) + "]"); - elements.put(name, Integer.valueOf(index)); + l = new Level(name + OPEN + add1OrIncrement(name, elements) + + CLOSE); break; default: - throw new IllegalArgumentException("unknown node type " + - child.getType()); + // more or less ignore + // FIXME: is this a good thing? + l = new Level(EMPTY); + break; } current.children.add(l); } @@ -97,9 +127,9 @@ public String getXPath() { StringBuilder sb = new StringBuilder(); for (Level l : path) { - sb.append("/").append(l.expression); + sb.append(SEP).append(l.expression); } - return sb.toString().replace("//", "/"); + return sb.toString().replace(SEP + SEP, SEP); } private String getName(QName name) { @@ -108,9 +138,22 @@ if (ns != null) { p = uri2Prefix.get(ns); } - return (p == null ? "" : p + ":") + name.getLocalPart(); + return (p == null ? EMPTY : p + ":") + name.getLocalPart(); } + /** + * Increments the value name maps to or adds 1 as value if name + * isn't present inside the map. + * + * @return the new mapping for name + */ + private static int add1OrIncrement(String name, Map<String, Integer> map) { + Integer old = map.get(name); + int index = old == null ? 1 : (old.intValue() + 1); + map.put(name, Integer.valueOf(index)); + return index; + } + private static class Level { private final String expression; private List<Level> children = new ArrayList<Level>(); 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-08-23 08:42:44 UTC (rev 435) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-08-26 14:46:54 UTC (rev 436) @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.NoSuchElementException; public final class Linqy { /** @@ -37,6 +38,14 @@ }; } + public static <E> Iterable<E> singleton(final E single) { + return new Iterable<E>() { + public Iterator<E> iterator() { + return new OnceOnlyIterator<E>(single); + } + }; + } + private static class CastingIterator<E> implements Iterator<E> { private final Iterator i; private CastingIterator(Iterator i) { @@ -52,4 +61,25 @@ return i.hasNext(); } } + + private static class OnceOnlyIterator<E> implements Iterator<E> { + private final E element; + private boolean iterated = false; + private OnceOnlyIterator(E element) { + this.element = element; + } + public void remove() { + throw new UnsupportedOperationException(); + } + public E next() { + if (iterated) { + throw new NoSuchElementException(); + } + iterated = true; + return element; + } + public boolean hasNext() { + return !iterated; + } + } } \ No newline at end of file Modified: trunk/xmlunit/src/main/net-core/diff/XPathContext.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-23 08:42:44 UTC (rev 435) +++ trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-26 14:46:54 UTC (rev 436) @@ -23,6 +23,14 @@ private readonly LinkedList<Level> path = new LinkedList<Level>(); private readonly IDictionary<string, string> uri2Prefix; + private const string COMMENT = "comment()"; + private const string PI = "processing-instruction()"; + private const string TEXT = "text()"; + private const string OPEN = "["; + private const string CLOSE = "]"; + private const string SEP = "/"; + private const string ATTR = "@"; + public XPathContext() : this(null) { } @@ -47,46 +55,66 @@ path.RemoveLast(); } - public void RegisterAttributes<Q>(IEnumerable<Q> attributes) + public void AddAttributes<Q>(IEnumerable<Q> attributes) where Q : XmlQualifiedName { Level current = path.Last.Value; foreach (XmlQualifiedName attribute in attributes) { current.Attributes[attribute] = - new Level("@" + GetName(attribute)); + new Level(ATTR + GetName(attribute)); } } - public void RegisterChildren<N>(IEnumerable<N> children) + public void SetChildren<N>(IEnumerable<N> children) where N : INodeInfo { Level current = path.Last.Value; + current.Children.Clear(); + AppendChildren(children); + } + + public void AppendChildren<N>(IEnumerable<N> children) + where N : INodeInfo { + Level current = path.Last.Value; int comments, pis, texts; comments = pis = texts = 0; IDictionary<string, int> elements = new Dictionary<string, int>(); + + foreach (Level l in current.Children) { + string childName = l.Expression; + if (childName.StartsWith(COMMENT)) { + comments++; + } else if (childName.StartsWith(PI)) { + pis++; + } else if (childName.StartsWith(TEXT)) { + texts++; + } else { + childName = childName.Substring(0, childName.IndexOf(OPEN)); + Add1OrIncrement(childName, elements); + } + } + foreach (INodeInfo child in children) { Level l = null; switch (child.Type) { case XmlNodeType.Comment: - l = new Level("comment()[" + (++comments) + "]"); + l = new Level(COMMENT + OPEN + (++comments) + CLOSE); break; case XmlNodeType.ProcessingInstruction: - l = new Level("processing-instruction()[" + (++pis) + "]"); + l = new Level(PI + OPEN + (++pis) + CLOSE); break; case XmlNodeType.CDATA: case XmlNodeType.Text: - l = new Level("text()[" + (++texts) + "]"); + l = new Level(TEXT + OPEN + (++texts) + CLOSE); break; case XmlNodeType.Element: string name = GetName(child.Name); - int old; - if (!elements.TryGetValue(name, out old)) { - old = 0; - } - l = new Level(name + "[" + (++old) + "]"); - elements[name] = old; + l = new Level(name + OPEN + Add1OrIncrement(name, elements) + + CLOSE); break; default: - throw new ArgumentException("unknown node type " + - child.Type); + // more or less ignore + // FIXME: is this a good thing? + l = new Level(string.Empty); + break; } current.Children.Add(l); } @@ -96,9 +124,9 @@ get { StringBuilder sb = new StringBuilder(); foreach (Level l in path) { - sb.AppendFormat("/{0}", l.Expression); + sb.AppendFormat(SEP + "{0}", l.Expression); } - return sb.Replace("//", "/").ToString(); + return sb.Replace(SEP + SEP, SEP).ToString(); } } @@ -111,6 +139,19 @@ return (p == null ? "" : p + ":") + name.Name; } + /// <summary> + /// Increments the value name maps to or adds 1 as value if name + /// isn't present inside the map. + /// </summary> + /// <returns>the new mapping for name</returns> + private static int Add1OrIncrement(string name, + IDictionary<string, int> map) { + int index = 0; + map.TryGetValue(name, out index); + map[name] = ++index; + return index; + } + internal class Level { internal readonly string Expression; internal readonly IList<Level> Children = new List<Level>(); Modified: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java 2010-08-23 08:42:44 UTC (rev 435) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java 2010-08-26 14:46:54 UTC (rev 436) @@ -14,9 +14,9 @@ package net.sf.xmlunit.diff; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import javax.xml.namespace.QName; +import net.sf.xmlunit.util.Linqy; import org.junit.Test; import org.w3c.dom.Node; @@ -34,7 +34,7 @@ l.add(new Element("bar")); l.add(new Element("foo")); XPathContext ctx = new XPathContext(); - ctx.registerChildren(l); + ctx.setChildren(l); ctx.navigateToChild(0); assertEquals("/foo[1]", ctx.getXPath()); ctx.navigateToParent(); @@ -48,6 +48,29 @@ assertEquals("/foo[3]", ctx.getXPath()); } + @Test public void appendChildren() { + ArrayList<Element> l = new ArrayList<Element>(); + l.add(new Element("foo")); + l.add(new Element("foo")); + XPathContext ctx = new XPathContext(); + ctx.setChildren(l); + l = new ArrayList<Element>(); + l.add(new Element("bar")); + l.add(new Element("foo")); + ctx.appendChildren(l); + ctx.navigateToChild(0); + assertEquals("/foo[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(1); + assertEquals("/foo[2]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(2); + assertEquals("/bar[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(3); + assertEquals("/foo[3]", ctx.getXPath()); + } + @Test public void twoLevelsOfElements() { ArrayList<Element> l = new ArrayList<Element>(); l.add(new Element("foo")); @@ -55,10 +78,10 @@ l.add(new Element("bar")); l.add(new Element("foo")); XPathContext ctx = new XPathContext(); - ctx.registerChildren(l); + ctx.setChildren(l); ctx.navigateToChild(0); assertEquals("/foo[1]", ctx.getXPath()); - ctx.registerChildren(l); + ctx.setChildren(l); ctx.navigateToChild(3); assertEquals("/foo[1]/foo[3]", ctx.getXPath()); ctx.navigateToParent(); @@ -70,11 +93,11 @@ @Test public void attributes() { XPathContext ctx = new XPathContext(); - ctx.registerChildren(Collections.singletonList(new Element("foo"))); + ctx.setChildren(Linqy.singleton(new Element("foo"))); ctx.navigateToChild(0); ArrayList<QName> l = new ArrayList<QName>(); l.add(new QName("bar")); - ctx.registerAttributes(l); + ctx.addAttributes(l); ctx.navigateToAttribute(new QName("bar")); assertEquals("/foo[1]/@bar", ctx.getXPath()); } @@ -90,7 +113,7 @@ l.add(new PI()); l.add(new Text()); XPathContext ctx = new XPathContext(); - ctx.registerChildren(l); + ctx.setChildren(l); ctx.navigateToChild(0); assertEquals("/text()[1]", ctx.getXPath()); ctx.navigateToParent(); @@ -124,7 +147,7 @@ HashMap<String, String> m = new HashMap<String, String>(); m.put("urn:foo:bar", "bar"); XPathContext ctx = new XPathContext(m); - ctx.registerChildren(l); + ctx.setChildren(l); ctx.navigateToChild(0); assertEquals("/foo[1]", ctx.getXPath()); ctx.navigateToParent(); @@ -139,14 +162,12 @@ HashMap<String, String> m = new HashMap<String, String>(); m.put("urn:foo:bar", "bar"); XPathContext ctx = new XPathContext(m); - ctx.registerChildren(Collections.singletonList(new Element("foo", - "urn:foo:bar")) - ); + ctx.setChildren(Linqy.singleton(new Element("foo", "urn:foo:bar"))); ctx.navigateToChild(0); ArrayList<QName> l = new ArrayList<QName>(); l.add(new QName("baz")); l.add(new QName("urn:foo:bar", "baz")); - ctx.registerAttributes(l); + ctx.addAttributes(l); ctx.navigateToAttribute(new QName("baz")); assertEquals("/bar:foo[1]/@baz", ctx.getXPath()); ctx.navigateToParent(); Modified: trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-23 08:42:44 UTC (rev 435) +++ trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-26 14:46:54 UTC (rev 436) @@ -27,6 +27,30 @@ } [Test] + public void AppendChildren() { + List<Element> l = new List<Element>(); + l.Add(new Element("foo")); + l.Add(new Element("foo")); + XPathContext ctx = new XPathContext(); + ctx.SetChildren(l); + l = new List<Element>(); + l.Add(new Element("bar")); + l.Add(new Element("foo")); + ctx.AppendChildren(l); + ctx.NavigateToChild(0); + Assert.AreEqual("/foo[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(1); + Assert.AreEqual("/foo[2]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(2); + Assert.AreEqual("/bar[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(3); + Assert.AreEqual("/foo[3]", ctx.XPath); + } + + [Test] public void OneLevelOfElements() { List<Element> l = new List<Element>(); l.Add(new Element("foo")); @@ -34,7 +58,7 @@ l.Add(new Element("bar")); l.Add(new Element("foo")); XPathContext ctx = new XPathContext(); - ctx.RegisterChildren(l); + ctx.SetChildren(l); ctx.NavigateToChild(0); Assert.AreEqual("/foo[1]", ctx.XPath); ctx.NavigateToParent(); @@ -56,10 +80,10 @@ l.Add(new Element("bar")); l.Add(new Element("foo")); XPathContext ctx = new XPathContext(); - ctx.RegisterChildren(l); + ctx.SetChildren(l); ctx.NavigateToChild(0); Assert.AreEqual("/foo[1]", ctx.XPath); - ctx.RegisterChildren(l); + ctx.SetChildren(l); ctx.NavigateToChild(3); Assert.AreEqual("/foo[1]/foo[3]", ctx.XPath); ctx.NavigateToParent(); @@ -72,11 +96,11 @@ [Test] public void Attributes() { XPathContext ctx = new XPathContext(); - ctx.RegisterChildren(Linqy.Singleton(new Element("foo"))); + ctx.SetChildren(Linqy.Singleton(new Element("foo"))); ctx.NavigateToChild(0); List<XmlQualifiedName> l = new List<XmlQualifiedName>(); l.Add(new XmlQualifiedName("bar")); - ctx.RegisterAttributes(l); + ctx.AddAttributes(l); ctx.NavigateToAttribute(new XmlQualifiedName("bar")); Assert.AreEqual("/foo[1]/@bar", ctx.XPath); } @@ -93,7 +117,7 @@ l.Add(new PI()); l.Add(new Text()); XPathContext ctx = new XPathContext(); - ctx.RegisterChildren(l); + ctx.SetChildren(l); ctx.NavigateToChild(0); Assert.AreEqual("/text()[1]", ctx.XPath); ctx.NavigateToParent(); @@ -128,7 +152,7 @@ Dictionary<string, string> m = new Dictionary<string, string>(); m["urn:foo:bar"] = "bar"; XPathContext ctx = new XPathContext(m); - ctx.RegisterChildren(l); + ctx.SetChildren(l); ctx.NavigateToChild(0); Assert.AreEqual("/foo[1]", ctx.XPath); ctx.NavigateToParent(); @@ -144,13 +168,13 @@ Dictionary<string, string> m = new Dictionary<string, string>(); m["urn:foo:bar"] = "bar"; XPathContext ctx = new XPathContext(m); - ctx.RegisterChildren(Linqy.Singleton(new Element("foo", + ctx.SetChildren(Linqy.Singleton(new Element("foo", "urn:foo:bar"))); ctx.NavigateToChild(0); List<XmlQualifiedName> l = new List<XmlQualifiedName>(); l.Add(new XmlQualifiedName("baz")); l.Add(new XmlQualifiedName("baz", "urn:foo:bar")); - ctx.RegisterAttributes(l); + ctx.AddAttributes(l); ctx.NavigateToAttribute(new XmlQualifiedName("baz")); Assert.AreEqual("/bar:foo[1]/@baz", ctx.XPath); ctx.NavigateToParent(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-23 08:42:50
|
Revision: 435 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=435&view=rev Author: bodewig Date: 2010-08-23 08:42:44 +0000 (Mon, 23 Aug 2010) Log Message: ----------- whitespace Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-23 08:41:47 UTC (rev 434) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-23 08:42:44 UTC (rev 435) @@ -81,7 +81,7 @@ public XpathNodeTracker() { newLevel(); } - + /** * Clear state data. * Call if required to reuse an existing instance. @@ -90,7 +90,7 @@ indentationList.clear(); indent(); } - + /** * Call before examining child nodes one level of indentation into DOM * @@ -140,7 +140,7 @@ currentEntry = (TrackingEntry) indentationList.get(last); } } - + /** * Call when visiting a node whose xpath location needs tracking * @@ -174,7 +174,7 @@ break; } } - + /** * Invoked by {@link #visited visited} when visited is an element, * text, CDATA section, comment or processing instruction. @@ -213,7 +213,7 @@ public void preloadNodeList(NodeList nodeList) { preloadChildren(new IterableNodeList(nodeList)); } - + /** * Preload the items in a List by visiting each in turn * Required for pieces of test XML whose node children can be visited @@ -229,7 +229,7 @@ Iterable<Node> nodes = Linqy.cast(nodeList); preloadChildren(nodes); } - + /** * @return the last visited node as an xpath-location String */ @@ -242,7 +242,7 @@ } return buf.toString(); } - + /** * extracts the local name of a node. */ @@ -279,24 +279,24 @@ */ private static final class Int { private int value; - + Int(int startAt) { value = startAt; } - + void increment() { ++value; } - + int getValue() { return value; } - + Integer toInteger() { return Integer.valueOf(value); } } - + /** * Holds node tracking details - one instance is used for each * level of indentation in a DOM @@ -322,7 +322,7 @@ // index of current node obtained from nodeReferenceMap - if any. private Integer nodeReferenceLookup = null; - + /** * Keep a reference to the current visited (non-attribute) node * @param visited the non-attribute node visited @@ -346,7 +346,7 @@ currentValue = value; clearTrackedAttribute(); } - + /** * Keep a reference to the visited attribute at the current visited node * @param value the attribute visited @@ -354,14 +354,14 @@ void trackAttribute(String visited) { currentAttribute = visited; } - + /** - * Clear any reference to the current visited attribute + * Clear any reference to the current visited attribute */ void clearTrackedAttribute() { currentAttribute = null; } - + /** * Append the details of the current visited node to a StringBuilder * @param buf the StringBuilder to append to @@ -371,17 +371,17 @@ return; } buf.append(XPATH_SEPARATOR).append(currentValue); - + int value = nodeReferenceLookup == null ? valueMap.get(currentValue).getValue() : nodeReferenceLookup.intValue(); buf.append(XPATH_NODE_INDEX_START).append(value).append(XPATH_NODE_INDEX_END); - + if (currentAttribute != null) { buf.append(XPATH_SEPARATOR).append(XPATH_ATTRIBUTE_IDENTIFIER) .append(currentAttribute); } } - + /** * whether the indices of subsequently tracked nodes should be tracked. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-23 08:41:53
|
Revision: 434 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=434&view=rev Author: bodewig Date: 2010-08-23 08:41:47 +0000 (Mon, 23 Aug 2010) Log Message: ----------- Simplify XpathNodeTracker and document its more obscure corners. This is a preparation to re-implement it in terms of XPathContext later. Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 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-08-20 12:56:17 UTC (rev 433) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-08-23 08:41:47 UTC (rev 434) @@ -14,6 +14,7 @@ package net.sf.xmlunit.util; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; public final class Linqy { @@ -27,4 +28,28 @@ } return a; } + + public static <E> Iterable<E> cast(final Iterable i) { + return new Iterable<E>() { + public Iterator<E> iterator() { + return new CastingIterator<E>(i.iterator()); + } + }; + } + + private static class CastingIterator<E> implements Iterator<E> { + private final Iterator i; + private CastingIterator(Iterator i) { + this.i = i; + } + public void remove() { + i.remove(); + } + public E next() { + return (E) i.next(); + } + public boolean hasNext() { + return i.hasNext(); + } + } } \ No newline at end of file Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-20 12:56:17 UTC (rev 433) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XpathNodeTracker.java 2010-08-23 08:41:47 UTC (rev 434) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2007, 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 @@ -41,15 +41,32 @@ import java.util.List; import java.util.Map; +import net.sf.xmlunit.util.IterableNodeList; +import net.sf.xmlunit.util.Linqy; + import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** - * Tracks Nodes visited by the DifferenceEngine and - * converts that information into an Xpath-String to supply - * to the NodeDetail of a Difference instance + * Tracks Nodes visited by the DifferenceEngine and converts that + * information into an Xpath-String to supply to the NodeDetail of a + * Difference instance. + * + * <p>The tracker has the concept of a level which corresponds to the + * depth of the tree it has visited. The {@link #indent indent} + * method creates a new level, making the tracker walk prepare to walk + * down the tree, the {@link #outdent outdent} method moves one level + * up and any information about the previous level is discarded.</p> + * + * <p>At each level there may be a current Node - the last one for + * which {@link #visitedNode visitedNode} or {@link #visited visited} + * has been called - and maybe a current attribute at this node - the + * last one for which {@link #visitedAttribute visitedAttribute} or + * {@link #visited visited} has been called. Attributes are assumed + * to be at the same level as the nodes they belong to.</p> + * @see NodeDetail#getXpathLocation() * @see Difference#getControlNodeDetail * @see Difference#getTestNodeDetail @@ -76,6 +93,13 @@ /** * Call before examining child nodes one level of indentation into DOM + * + * <p>Any subsequent call to {@link #visited visited} is assumed + * to belong to nodes one level deeper into the tree than the + * nodes visited before calling {@link #indent indent}.</p> + * + * <p>As a side effect, the current attribute - if any - is + * reset.</p> */ public void indent() { if (currentEntry != null) { @@ -90,7 +114,7 @@ } /** - * Call after processing attributes of an element and turining to + * Call after processing attributes of an element and turning to * compare the child nodes. */ public void clearTrackedAttribute() { @@ -100,7 +124,13 @@ } /** - * Call after examining child nodes, ie before returning back one level of indentation from DOM + * Call after examining child nodes, ie before returning back one + * level of indentation from DOM. + * + * <p>Any subsequent call to {@link #visited visited} is assumed + * to belong to nodes one level closer to the root of the tree + * than the nodes visited before calling {@link #outdent + * outdent}.</p> */ public void outdent() { int last = indentationList.size() - 1; @@ -113,24 +143,21 @@ /** * Call when visiting a node whose xpath location needs tracking - * @param node the Node being visited + * + * <p>Delegates to {@link #visitedAttribute visitedAttribute} for + * attribute nodes, {@link #visitedNode visitedNode} for elements, + * texts, CDATA sections, comments or processing instructions and + * ignores any other type of node.</p> + * + * @param node the Node being visited - must not be null. */ public void visited(Node node) { - String nodeName; switch(node.getNodeType()) { case Node.ATTRIBUTE_NODE: - nodeName = ((Attr)node).getLocalName(); - if (nodeName == null || nodeName.length() == 0) { - nodeName = node.getNodeName(); - } - visitedAttribute(nodeName); + visitedAttribute(getNodeName(node)); break; case Node.ELEMENT_NODE: - nodeName = ((Element)node).getLocalName(); - if (nodeName == null || nodeName.length() == 0) { - nodeName = node.getNodeName(); - } - visitedNode(node, nodeName); + visitedNode(node, getNodeName(node)); break; case Node.COMMENT_NODE: visitedNode(node, XPATH_COMMENT_IDENTIFIER); @@ -148,10 +175,26 @@ } } + /** + * Invoked by {@link #visited visited} when visited is an element, + * text, CDATA section, comment or processing instruction. + * + * @param visited the visited node - Unit tests call this with + * null values, so it is not safe to assume it will never be null. + * It will never be null when the {@link #visited visited} method + * delegates here. + * @param value the local name of the element or an XPath + * identifier matching the type of node. + */ protected void visitedNode(Node visited, String value) { currentEntry.trackNode(visited, value); } + /** + * Invoked by {@link #visited visited} when visiting an attribute node. + * + * @param visited the local name of the attribute. + */ protected void visitedAttribute(String visited) { currentEntry.trackAttribute(visited); } @@ -160,37 +203,38 @@ * Preload the items in a NodeList by visiting each in turn * Required for pieces of test XML whose node children can be visited * out of sequence by a DifferenceEngine comparison + * + * <p>Makes the nodes of this list known as nodes that are + * visitable at the current level and makes the last child node + * the current node as a side effect.</p> + * * @param nodeList the items to preload */ public void preloadNodeList(NodeList nodeList) { - currentEntry.trackNodesAsWellAsValues(true); - int length = nodeList.getLength(); - for (int i=0; i < length; ++i) { - visited(nodeList.item(i)); - } - currentEntry.trackNodesAsWellAsValues(false); + preloadChildren(new IterableNodeList(nodeList)); } /** * Preload the items in a List by visiting each in turn * Required for pieces of test XML whose node children can be visited * out of sequence by a DifferenceEngine comparison + * + * <p>Makes the nodes of this list known as nodes that are + * visitable at the current level and makes the last child node + * the current node as a side effect.</p> + * * @param nodeList the items to preload */ public void preloadChildList(List nodeList) { - currentEntry.trackNodesAsWellAsValues(true); - int length = nodeList.size(); - for (int i=0; i < length; ++i) { - visited((Node) nodeList.get(i)); - } - currentEntry.trackNodesAsWellAsValues(false); + Iterable<Node> nodes = Linqy.cast(nodeList); + preloadChildren(nodes); } /** * @return the last visited node as an xpath-location String */ public String toXpathString() { - StringBuffer buf = new StringBuffer(); + StringBuilder buf = new StringBuilder(); TrackingEntry nextEntry; for (Iterator iter = indentationList.iterator(); iter.hasNext(); ) { nextEntry = (TrackingEntry) iter.next(); @@ -200,53 +244,93 @@ } /** + * extracts the local name of a node. + */ + private static String getNodeName(Node n) { + String nodeName = n.getLocalName(); + if (nodeName == null || nodeName.length() == 0) { + nodeName = n.getNodeName(); + } + return nodeName; + } + + /** + * Preload the nodes by visiting each in turn. + * Required for pieces of test XML whose node children can be visited + * out of sequence by a DifferenceEngine comparison + * + * <p>Makes the nodes of this list known as nodes that are + * visitable at the current level and makes the last child node + * the current node as a side effect.</p> + * + * @param nodeList the items to preload + */ + private void preloadChildren(Iterable<Node> nodeList) { + currentEntry.trackNodesAsWellAsValues(true); + for (Node n : nodeList) { + visited(n); + } + currentEntry.trackNodesAsWellAsValues(false); + } + + /** * Wrapper class around a mutable <code>int</code> value * Avoids creation of many immutable <code>Integer</code> objects */ private static final class Int { private int value; - public Int(int startAt) { + Int(int startAt) { value = startAt; } - public void increment() { + void increment() { ++value; } - public int getValue() { + int getValue() { return value; } - public Integer toInteger() { - return new Integer(value); + Integer toInteger() { + return Integer.valueOf(value); } } /** - * Holds node tracking details - one instance is used for each level of indentation in a DOM - * Provides reference between a String-ified Node value and the xpath index of that value + * Holds node tracking details - one instance is used for each + * level of indentation in a DOM + * + * Provides reference between a String-ified Node value and the + * xpath index of that value */ private static final class TrackingEntry { - private final Map valueMap = new HashMap(); + // how often has the key been seen at this level of tracking + // (including this occurence)? + private final Map<String, Int> valueMap = new HashMap<String, Int>(); + // the current XPath expression for this level and the current + // attribute - if any private String currentValue, currentAttribute; - private Map nodeReferenceMap; + // may be used if children of this level have been preloaded, + // maps the Node instance to number of same-names XPath + // expression that have been seen at this level already. + private Map<Node, Integer> nodeReferenceMap; + + // node references are tracked while preloading child nodes private boolean trackNodeReferences = false; + + // index of current node obtained from nodeReferenceMap - if any. private Integer nodeReferenceLookup = null; - private Int lookup(String value) { - return (Int) valueMap.get(value); - } - /** * Keep a reference to the current visited (non-attribute) node * @param visited the non-attribute node visited * @param value the String-ified value of the non-attribute node visited */ - public void trackNode(Node visited, String value) { + void trackNode(Node visited, String value) { if (nodeReferenceMap == null || trackNodeReferences) { - Int occurrence = lookup(value); + Int occurrence = valueMap.get(value); if (occurrence == null) { occurrence = new Int(1); valueMap.put(value, occurrence); @@ -257,7 +341,7 @@ nodeReferenceMap.put(visited, occurrence.toInteger()); } } else { - nodeReferenceLookup = (Integer) nodeReferenceMap.get(visited); + nodeReferenceLookup = nodeReferenceMap.get(visited); } currentValue = value; clearTrackedAttribute(); @@ -267,29 +351,29 @@ * Keep a reference to the visited attribute at the current visited node * @param value the attribute visited */ - public void trackAttribute(String visited) { + void trackAttribute(String visited) { currentAttribute = visited; } /** * Clear any reference to the current visited attribute */ - public void clearTrackedAttribute() { + void clearTrackedAttribute() { currentAttribute = null; } /** - * Append the details of the current visited node to a StringBuffer - * @param buf the StringBuffer to append to + * Append the details of the current visited node to a StringBuilder + * @param buf the StringBuilder to append to */ - public void appendEntryTo(StringBuffer buf) { + void appendEntryTo(StringBuilder buf) { if (currentValue == null) { return; } buf.append(XPATH_SEPARATOR).append(currentValue); int value = nodeReferenceLookup == null - ? lookup(currentValue).getValue() : nodeReferenceLookup.intValue(); + ? valueMap.get(currentValue).getValue() : nodeReferenceLookup.intValue(); buf.append(XPATH_NODE_INDEX_START).append(value).append(XPATH_NODE_INDEX_END); if (currentAttribute != null) { @@ -298,10 +382,13 @@ } } - public void trackNodesAsWellAsValues(boolean yesNo) { + /** + * whether the indices of subsequently tracked nodes should be tracked. + */ + void trackNodesAsWellAsValues(boolean yesNo) { this.trackNodeReferences = yesNo; if (yesNo) { - nodeReferenceMap = new HashMap(); + nodeReferenceMap = new HashMap<Node, Integer>(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-20 12:56:23
|
Revision: 433 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=433&view=rev Author: bodewig Date: 2010-08-20 12:56:17 +0000 (Fri, 20 Aug 2010) Log Message: ----------- cleanup Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/main/net-core/diff/XPathContext.cs trunk/xmlunit/src/main/net-core/util/Convert.cs trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs Added 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/diff/XPathContext.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-20 12:56:17 UTC (rev 433) @@ -96,20 +96,10 @@ public String getXPath() { StringBuilder sb = new StringBuilder(); - boolean first = true, second = false; for (Level l : path) { - if (!second) { - sb.append("/"); - } - sb.append(l.expression); - if (first) { - second = true; - } else { - second = false; - } - first = false; + sb.append("/").append(l.expression); } - return sb.toString(); + return sb.toString().replace("//", "/"); } private String getName(QName name) { Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java 2010-08-20 12:56:17 UTC (rev 433) @@ -13,7 +13,6 @@ */ package net.sf.xmlunit.util; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.w3c.dom.Node; @@ -50,20 +49,9 @@ } /** - * Turns the iterable into a list. - */ - public static List<Node> asList(IterableNodeList l) { - ArrayList<Node> a = new ArrayList<Node>(l.length); - for (Node n : l) { - a.add(n); - } - return a; - } - - /** * Turns the NodeList into a list. */ public static List<Node> asList(NodeList l) { - return asList(new IterableNodeList(l)); + return Linqy.asList(new IterableNodeList(l)); } } Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java 2010-08-20 12:56:17 UTC (rev 433) @@ -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.util; + +import java.util.ArrayList; +import java.util.List; + +public final class Linqy { + /** + * Turns the iterable into a list. + */ + public static <E> List<E> asList(Iterable<E> i) { + ArrayList<E> a = new ArrayList<E>(); + for (E e : i) { + a.add(e); + } + return a; + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Linqy.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-20 12:56:17 UTC (rev 433) @@ -21,6 +21,7 @@ <import reference="System.Collections.Generic"/> <import reference="System.Xml"/> <import reference="System.Xml.Schema"/> + <import reference="net.sf.xmlunit.util"/> <literal><![CDATA[ @@ -266,11 +267,9 @@ private ComparisonResult CompareNodeLists(XmlNodeList control, XmlNodeList test) { IList<XmlNode> controlList = - new List<XmlNode>(net.sf.xmlunit.util.Convert - .Cast<XmlNode>(control)); + new List<XmlNode>(Linqy.Cast<XmlNode>(control)); IList<XmlNode> testList = - new List<XmlNode>(net.sf.xmlunit.util.Convert - .Cast<XmlNode>(test)); + new List<XmlNode>(Linqy.Cast<XmlNode>(test)); IDictionary<int, object> unmatchedTestIndexes = new SortedDictionary<int, object>(); for (int i = 0; i < testList.Count; i++) { Modified: trunk/xmlunit/src/main/net-core/diff/XPathContext.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -95,20 +95,10 @@ public string XPath { get { StringBuilder sb = new StringBuilder(); - bool first = true, second = false; foreach (Level l in path) { - if (!second) { - sb.Append("/"); - } - sb.Append(l.Expression); - if (first) { - second = true; - } else { - second = false; - } - first = false; + sb.AppendFormat("/{0}", l.Expression); } - return sb.ToString(); + return sb.Replace("//", "/").ToString(); } } Modified: trunk/xmlunit/src/main/net-core/util/Convert.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Convert.cs 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/main/net-core/util/Convert.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -12,7 +12,6 @@ limitations under the License. */ -using System.Collections; using System.Collections.Generic; using System.Xml; using net.sf.xmlunit.input; @@ -73,11 +72,5 @@ } return man; } - - public static IEnumerable<T> Cast<T>(IEnumerable i) { - foreach (T t in i) { - yield return t; - } - } } } Added: trunk/xmlunit/src/main/net-core/util/Linqy.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Linqy.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/util/Linqy.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -0,0 +1,34 @@ +/* + 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; +using System.Collections.Generic; + +namespace net.sf.xmlunit.util { + /// <summary> + /// Conversion methods. + /// </summary> + public sealed class Linqy { + public static IEnumerable<T> Cast<T>(IEnumerable i) { + foreach (T t in i) { + yield return t; + } + } + + public static IEnumerable<T> Singleton<T>(T t) { + yield return t; + } + + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/util/Linqy.cs ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-20 10:07:48 UTC (rev 432) +++ trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-20 12:56:17 UTC (rev 433) @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using System.Xml; +using net.sf.xmlunit.util; using NUnit.Framework; namespace net.sf.xmlunit.diff { @@ -71,7 +72,7 @@ [Test] public void Attributes() { XPathContext ctx = new XPathContext(); - ctx.RegisterChildren(Singleton(new Element("foo"))); + ctx.RegisterChildren(Linqy.Singleton(new Element("foo"))); ctx.NavigateToChild(0); List<XmlQualifiedName> l = new List<XmlQualifiedName>(); l.Add(new XmlQualifiedName("bar")); @@ -80,10 +81,6 @@ Assert.AreEqual("/foo[1]/@bar", ctx.XPath); } - private static IEnumerable<T> Singleton<T>(T t) { - yield return t; - } - [Test] public void Mixed() { List<XPathContext.INodeInfo> l = new List<XPathContext.INodeInfo>(); @@ -147,7 +144,8 @@ Dictionary<string, string> m = new Dictionary<string, string>(); m["urn:foo:bar"] = "bar"; XPathContext ctx = new XPathContext(m); - ctx.RegisterChildren(Singleton(new Element("foo", "urn:foo:bar"))); + ctx.RegisterChildren(Linqy.Singleton(new Element("foo", + "urn:foo:bar"))); ctx.NavigateToChild(0); List<XmlQualifiedName> l = new List<XmlQualifiedName>(); l.Add(new XmlQualifiedName("baz")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-20 10:07:55
|
Revision: 432 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=432&view=rev Author: bodewig Date: 2010-08-20 10:07:48 +0000 (Fri, 20 Aug 2010) Log Message: ----------- prepare for XPath tracking in difference engine Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEngine.java trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs Added Paths: ----------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java trunk/xmlunit/src/main/net-core/diff/XPathContext.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.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-08-19 14:52:28 UTC (rev 431) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-08-20 10:07:48 UTC (rev 432) @@ -13,6 +13,9 @@ */ package net.sf.xmlunit.diff; +import java.util.Collections; +import java.util.Map; + /** * Useful base-implementation of some parts of the DifferenceEngine * interface. @@ -22,6 +25,7 @@ new ComparisonListenerSupport(); private ElementSelector elementSelector = ElementSelectors.Default; private DifferenceEvaluator diffEvaluator = DifferenceEvaluators.Default; + private Map<String, String> uri2Prefix = Collections.emptyMap(); public void addComparisonListener(ComparisonListener l) { if (l == null) { @@ -68,6 +72,10 @@ return diffEvaluator; } + public void setNamespaceContext(Map<String, String> uri2Prefix) { + this.uri2Prefix = Collections.unmodifiableMap(uri2Prefix); + } + /** * Compares the detail values for object equality, lets the * difference evaluator evaluate the result, notifies all 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-08-19 14:52:28 UTC (rev 431) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEngine.java 2010-08-20 10:07:48 UTC (rev 432) @@ -13,6 +13,7 @@ */ package net.sf.xmlunit.diff; +import java.util.Map; import javax.xml.transform.Source; /** @@ -48,6 +49,18 @@ void setDifferenceEvaluator(DifferenceEvaluator e); /** + * Establish a namespace context that will be used in {@link + * Comparison.Detail#getXPath Comparison.Detail#getXPath}. + * + * <p>Without a namespace context (or with an empty context) the + * XPath expressions will only use local names for elements and + * attributes.</p> + * + * @param uri2Prefix maps from namespace URI to prefix. + */ + void setNamespaceContext(Map<String, String> uri2Prefix); + + /** * Compares two pieces of XML and invokes the registered listeners. */ void compare(Source control, Source test); Added: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java (rev 0) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java 2010-08-20 10:07:48 UTC (rev 432) @@ -0,0 +1,148 @@ +/* + 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.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import javax.xml.namespace.QName; +import net.sf.xmlunit.util.Nodes; +import org.w3c.dom.Node; + +public class XPathContext { + private final Deque<Level> path = new LinkedList<Level>(); + private final Map<String, String> uri2Prefix; + + public XPathContext() { + this(null); + } + + public XPathContext(Map<String, String> uri2Prefix) { + if (uri2Prefix == null) { + this.uri2Prefix = Collections.emptyMap(); + } else { + this.uri2Prefix = Collections.unmodifiableMap(uri2Prefix); + } + path.addLast(new Level("")); + } + + public void navigateToChild(int index) { + path.addLast(path.getLast().children.get(index)); + } + + public void navigateToAttribute(QName attribute) { + path.addLast(path.getLast().attributes.get(attribute)); + } + + public void navigateToParent() { + path.removeLast(); + } + + public void registerAttributes(Iterable<? extends QName> attributes) { + Level current = path.getLast(); + for (QName attribute : attributes) { + current.attributes.put(attribute, + new Level("@" + getName(attribute))); + } + } + + public void registerChildren(Iterable<? extends NodeInfo> children) { + Level current = path.getLast(); + int comments, pis, texts; + comments = pis = texts = 0; + Map<String, Integer> elements = new HashMap<String, Integer>(); + for (NodeInfo child : children) { + Level l = null; + switch (child.getType()) { + case Node.COMMENT_NODE: + l = new Level("comment()[" + (++comments) + "]"); + break; + case Node.PROCESSING_INSTRUCTION_NODE: + l = new Level("processing-instruction()[" + (++pis) + "]"); + break; + case Node.CDATA_SECTION_NODE: + case Node.TEXT_NODE: + l = new Level("text()[" + (++texts) + "]"); + break; + case Node.ELEMENT_NODE: + String name = getName(child.getName()); + Integer old = elements.get(name); + int index = old == null ? 0 : old.intValue(); + l = new Level(name + "[" + (++index) + "]"); + elements.put(name, Integer.valueOf(index)); + break; + default: + throw new IllegalArgumentException("unknown node type " + + child.getType()); + } + current.children.add(l); + } + } + + public String getXPath() { + StringBuilder sb = new StringBuilder(); + boolean first = true, second = false; + for (Level l : path) { + if (!second) { + sb.append("/"); + } + sb.append(l.expression); + if (first) { + second = true; + } else { + second = false; + } + first = false; + } + return sb.toString(); + } + + private String getName(QName name) { + String ns = name.getNamespaceURI(); + String p = null; + if (ns != null) { + p = uri2Prefix.get(ns); + } + return (p == null ? "" : p + ":") + name.getLocalPart(); + } + + private static class Level { + private final String expression; + private List<Level> children = new ArrayList<Level>(); + private Map<QName, Level> attributes = new HashMap<QName, Level>(); + private Level(String expression) { + this.expression = expression; + } + } + + public static interface NodeInfo { + QName getName(); + short getType(); + } + + public static final class DOMNodeInfo implements NodeInfo { + private QName name; + private short type; + public DOMNodeInfo(Node n) { + name = Nodes.getQName(n); + type = n.getNodeType(); + } + public QName getName() { return name; } + public short getType() { return type; } + } +} Property changes on: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/XPathContext.java ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-08-19 14:52:28 UTC (rev 431) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-08-20 10:07:48 UTC (rev 432) @@ -13,6 +13,7 @@ */ using System; +using System.Collections.Generic; namespace net.sf.xmlunit.diff { @@ -53,6 +54,14 @@ public abstract void Compare(ISource control, ISource test); + private IDictionary<string, string> namespaceContext; + + public IDictionary<string, string> NamespaceContext { + set { + namespaceContext = value; + } + } + /// <summary> /// Compares the detail values for object equality, lets the /// difference evaluator evaluate the result, notifies all Modified: trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs 2010-08-19 14:52:28 UTC (rev 431) +++ trunk/xmlunit/src/main/net-core/diff/IDifferenceEngine.cs 2010-08-20 10:07:48 UTC (rev 432) @@ -12,6 +12,8 @@ limitations under the License. */ +using System.Collections.Generic; + namespace net.sf.xmlunit.diff { /// <summary> @@ -47,6 +49,17 @@ DifferenceEvaluator DifferenceEvaluator { set; } /// <summary> + /// Establish a namespace context mapping from URI to prefix + /// that will be used in Comparison.Detail.XPath. + /// </summary> + /// <remarks> + /// Without a namespace context (or with an empty context) the + /// XPath expressions will only use local names for elements and + /// attributes. + /// </remarks> + IDictionary<string, string> NamespaceContext { set; } + + /// <summary> /// Compares two pieces of XML and invokes the registered listeners. /// </summary> void Compare(ISource control, ISource test); Added: trunk/xmlunit/src/main/net-core/diff/XPathContext.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/XPathContext.cs (rev 0) +++ trunk/xmlunit/src/main/net-core/diff/XPathContext.cs 2010-08-20 10:07:48 UTC (rev 432) @@ -0,0 +1,150 @@ +/* + 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.Text; +using System.Xml; +using net.sf.xmlunit.util; + +namespace net.sf.xmlunit.diff { + public class XPathContext { + private readonly LinkedList<Level> path = new LinkedList<Level>(); + private readonly IDictionary<string, string> uri2Prefix; + + public XPathContext() : this(null) { + } + + public XPathContext(IDictionary<string, string> uri2Prefix) { + if (uri2Prefix == null) { + this.uri2Prefix = new Dictionary<string, string>(); + } else { + this.uri2Prefix = new Dictionary<string, string>(uri2Prefix); + } + path.AddLast(new Level("")); + } + + public void NavigateToChild(int index) { + path.AddLast(path.Last.Value.Children[index]); + } + + public void NavigateToAttribute(XmlQualifiedName attribute) { + path.AddLast(path.Last.Value.Attributes[attribute]); + } + + public void NavigateToParent() { + path.RemoveLast(); + } + + public void RegisterAttributes<Q>(IEnumerable<Q> attributes) + where Q : XmlQualifiedName { + Level current = path.Last.Value; + foreach (XmlQualifiedName attribute in attributes) { + current.Attributes[attribute] = + new Level("@" + GetName(attribute)); + } + } + + public void RegisterChildren<N>(IEnumerable<N> children) + where N : INodeInfo { + Level current = path.Last.Value; + int comments, pis, texts; + comments = pis = texts = 0; + IDictionary<string, int> elements = new Dictionary<string, int>(); + foreach (INodeInfo child in children) { + Level l = null; + switch (child.Type) { + case XmlNodeType.Comment: + l = new Level("comment()[" + (++comments) + "]"); + break; + case XmlNodeType.ProcessingInstruction: + l = new Level("processing-instruction()[" + (++pis) + "]"); + break; + case XmlNodeType.CDATA: + case XmlNodeType.Text: + l = new Level("text()[" + (++texts) + "]"); + break; + case XmlNodeType.Element: + string name = GetName(child.Name); + int old; + if (!elements.TryGetValue(name, out old)) { + old = 0; + } + l = new Level(name + "[" + (++old) + "]"); + elements[name] = old; + break; + default: + throw new ArgumentException("unknown node type " + + child.Type); + } + current.Children.Add(l); + } + } + + public string XPath { + get { + StringBuilder sb = new StringBuilder(); + bool first = true, second = false; + foreach (Level l in path) { + if (!second) { + sb.Append("/"); + } + sb.Append(l.Expression); + if (first) { + second = true; + } else { + second = false; + } + first = false; + } + return sb.ToString(); + } + } + + private string GetName(XmlQualifiedName name) { + string ns = name.Namespace; + string p = null; + if (ns != null) { + uri2Prefix.TryGetValue(ns, out p); + } + return (p == null ? "" : p + ":") + name.Name; + } + + internal class Level { + internal readonly string Expression; + internal readonly IList<Level> Children = new List<Level>(); + internal readonly IDictionary<XmlQualifiedName, Level> Attributes = + new Dictionary<XmlQualifiedName, Level>(); + internal Level(string expression) { + this.Expression = expression; + } + } + + public interface INodeInfo { + XmlQualifiedName Name { get; } + XmlNodeType Type { get; } + } + + public class DOMNodeInfo : INodeInfo { + private XmlQualifiedName name; + private XmlNodeType type; + public DOMNodeInfo(XmlNode n) { + name = Nodes.GetQName(n); + type = n.NodeType; + } + public XmlQualifiedName Name { get { return name; } } + public XmlNodeType Type { get { return type; } } + } + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/main/net-core/diff/XPathContext.cs ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java =================================================================== --- trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java (rev 0) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java 2010-08-20 10:07:48 UTC (rev 432) @@ -0,0 +1,185 @@ +/* + 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.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import javax.xml.namespace.QName; +import org.junit.Test; +import org.w3c.dom.Node; + +import static org.junit.Assert.*; + +public class XPathContextTest { + @Test public void empty() { + assertEquals("/", new XPathContext().getXPath()); + } + + @Test public void oneLevelOfElements() { + ArrayList<Element> l = new ArrayList<Element>(); + l.add(new Element("foo")); + l.add(new Element("foo")); + l.add(new Element("bar")); + l.add(new Element("foo")); + XPathContext ctx = new XPathContext(); + ctx.registerChildren(l); + ctx.navigateToChild(0); + assertEquals("/foo[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(1); + assertEquals("/foo[2]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(2); + assertEquals("/bar[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(3); + assertEquals("/foo[3]", ctx.getXPath()); + } + + @Test public void twoLevelsOfElements() { + ArrayList<Element> l = new ArrayList<Element>(); + l.add(new Element("foo")); + l.add(new Element("foo")); + l.add(new Element("bar")); + l.add(new Element("foo")); + XPathContext ctx = new XPathContext(); + ctx.registerChildren(l); + ctx.navigateToChild(0); + assertEquals("/foo[1]", ctx.getXPath()); + ctx.registerChildren(l); + ctx.navigateToChild(3); + assertEquals("/foo[1]/foo[3]", ctx.getXPath()); + ctx.navigateToParent(); + assertEquals("/foo[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(2); + assertEquals("/bar[1]", ctx.getXPath()); + } + + @Test public void attributes() { + XPathContext ctx = new XPathContext(); + ctx.registerChildren(Collections.singletonList(new Element("foo"))); + ctx.navigateToChild(0); + ArrayList<QName> l = new ArrayList<QName>(); + l.add(new QName("bar")); + ctx.registerAttributes(l); + ctx.navigateToAttribute(new QName("bar")); + assertEquals("/foo[1]/@bar", ctx.getXPath()); + } + + @Test public void mixed() { + ArrayList<XPathContext.NodeInfo> l = new ArrayList<XPathContext.NodeInfo>(); + l.add(new Text()); + l.add(new Comment()); + l.add(new CDATA()); + l.add(new PI()); + l.add(new CDATA()); + l.add(new Comment()); + l.add(new PI()); + l.add(new Text()); + XPathContext ctx = new XPathContext(); + ctx.registerChildren(l); + ctx.navigateToChild(0); + assertEquals("/text()[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(1); + assertEquals("/comment()[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(2); + assertEquals("/text()[2]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(3); + assertEquals("/processing-instruction()[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(4); + assertEquals("/text()[3]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(5); + assertEquals("/comment()[2]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(6); + assertEquals("/processing-instruction()[2]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(7); + assertEquals("/text()[4]", ctx.getXPath()); + } + + @Test public void elementsAndNs() { + ArrayList<Element> l = new ArrayList<Element>(); + l.add(new Element("foo", "urn:foo:foo")); + l.add(new Element("foo")); + l.add(new Element("foo", "urn:foo:bar")); + HashMap<String, String> m = new HashMap<String, String>(); + m.put("urn:foo:bar", "bar"); + XPathContext ctx = new XPathContext(m); + ctx.registerChildren(l); + ctx.navigateToChild(0); + assertEquals("/foo[1]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(1); + assertEquals("/foo[2]", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToChild(2); + assertEquals("/bar:foo[1]", ctx.getXPath()); + } + + @Test public void attributesAndNs() { + HashMap<String, String> m = new HashMap<String, String>(); + m.put("urn:foo:bar", "bar"); + XPathContext ctx = new XPathContext(m); + ctx.registerChildren(Collections.singletonList(new Element("foo", + "urn:foo:bar")) + ); + ctx.navigateToChild(0); + ArrayList<QName> l = new ArrayList<QName>(); + l.add(new QName("baz")); + l.add(new QName("urn:foo:bar", "baz")); + ctx.registerAttributes(l); + ctx.navigateToAttribute(new QName("baz")); + assertEquals("/bar:foo[1]/@baz", ctx.getXPath()); + ctx.navigateToParent(); + ctx.navigateToAttribute(new QName("urn:foo:bar", "baz")); + assertEquals("/bar:foo[1]/@bar:baz", ctx.getXPath()); + ctx.navigateToParent(); + } + + private static class Element implements XPathContext.NodeInfo { + private final QName name; + private Element(String name) { + this.name = new QName(name); + } + private Element(String name, String ns) { + this.name = new QName(ns, name); + } + public QName getName() { return name; } + public short getType() { return Node.ELEMENT_NODE; } + } + + private static abstract class NonElement implements XPathContext.NodeInfo { + public QName getName() { return null; } + } + private static class Text extends NonElement { + public short getType() { return Node.TEXT_NODE; } + } + private static class Comment extends NonElement { + public short getType() { return Node.COMMENT_NODE; } + } + private static class PI extends NonElement { + public short getType() { return Node.PROCESSING_INSTRUCTION_NODE; } + } + private static class CDATA extends NonElement { + public short getType() { return Node.CDATA_SECTION_NODE; } + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/XPathContextTest.java ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs (rev 0) +++ trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.cs 2010-08-20 10:07:48 UTC (rev 432) @@ -0,0 +1,201 @@ +/* + 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 NUnit.Framework; + +namespace net.sf.xmlunit.diff { + + [TestFixture] + public class XPathContextTest { + [Test] + public void Empty() { + Assert.AreEqual("/", new XPathContext().XPath); + } + + [Test] + public void OneLevelOfElements() { + List<Element> l = new List<Element>(); + l.Add(new Element("foo")); + l.Add(new Element("foo")); + l.Add(new Element("bar")); + l.Add(new Element("foo")); + XPathContext ctx = new XPathContext(); + ctx.RegisterChildren(l); + ctx.NavigateToChild(0); + Assert.AreEqual("/foo[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(1); + Assert.AreEqual("/foo[2]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(2); + Assert.AreEqual("/bar[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(3); + Assert.AreEqual("/foo[3]", ctx.XPath); + } + + [Test] + public void TwoLevelsOfElements() { + List<Element> l = new List<Element>(); + l.Add(new Element("foo")); + l.Add(new Element("foo")); + l.Add(new Element("bar")); + l.Add(new Element("foo")); + XPathContext ctx = new XPathContext(); + ctx.RegisterChildren(l); + ctx.NavigateToChild(0); + Assert.AreEqual("/foo[1]", ctx.XPath); + ctx.RegisterChildren(l); + ctx.NavigateToChild(3); + Assert.AreEqual("/foo[1]/foo[3]", ctx.XPath); + ctx.NavigateToParent(); + Assert.AreEqual("/foo[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(2); + Assert.AreEqual("/bar[1]", ctx.XPath); + } + + [Test] + public void Attributes() { + XPathContext ctx = new XPathContext(); + ctx.RegisterChildren(Singleton(new Element("foo"))); + ctx.NavigateToChild(0); + List<XmlQualifiedName> l = new List<XmlQualifiedName>(); + l.Add(new XmlQualifiedName("bar")); + ctx.RegisterAttributes(l); + ctx.NavigateToAttribute(new XmlQualifiedName("bar")); + Assert.AreEqual("/foo[1]/@bar", ctx.XPath); + } + + private static IEnumerable<T> Singleton<T>(T t) { + yield return t; + } + + [Test] + public void Mixed() { + List<XPathContext.INodeInfo> l = new List<XPathContext.INodeInfo>(); + l.Add(new Text()); + l.Add(new Comment()); + l.Add(new CDATA()); + l.Add(new PI()); + l.Add(new CDATA()); + l.Add(new Comment()); + l.Add(new PI()); + l.Add(new Text()); + XPathContext ctx = new XPathContext(); + ctx.RegisterChildren(l); + ctx.NavigateToChild(0); + Assert.AreEqual("/text()[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(1); + Assert.AreEqual("/comment()[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(2); + Assert.AreEqual("/text()[2]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(3); + Assert.AreEqual("/processing-instruction()[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(4); + Assert.AreEqual("/text()[3]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(5); + Assert.AreEqual("/comment()[2]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(6); + Assert.AreEqual("/processing-instruction()[2]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(7); + Assert.AreEqual("/text()[4]", ctx.XPath); + } + + [Test] + public void ElementsAndNs() { + List<Element> l = new List<Element>(); + l.Add(new Element("foo", "urn:foo:foo")); + l.Add(new Element("foo")); + l.Add(new Element("foo", "urn:foo:bar")); + Dictionary<string, string> m = new Dictionary<string, string>(); + m["urn:foo:bar"] = "bar"; + XPathContext ctx = new XPathContext(m); + ctx.RegisterChildren(l); + ctx.NavigateToChild(0); + Assert.AreEqual("/foo[1]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(1); + Assert.AreEqual("/foo[2]", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToChild(2); + Assert.AreEqual("/bar:foo[1]", ctx.XPath); + } + + [Test] + public void AttributesAndNs() { + Dictionary<string, string> m = new Dictionary<string, string>(); + m["urn:foo:bar"] = "bar"; + XPathContext ctx = new XPathContext(m); + ctx.RegisterChildren(Singleton(new Element("foo", "urn:foo:bar"))); + ctx.NavigateToChild(0); + List<XmlQualifiedName> l = new List<XmlQualifiedName>(); + l.Add(new XmlQualifiedName("baz")); + l.Add(new XmlQualifiedName("baz", "urn:foo:bar")); + ctx.RegisterAttributes(l); + ctx.NavigateToAttribute(new XmlQualifiedName("baz")); + Assert.AreEqual("/bar:foo[1]/@baz", ctx.XPath); + ctx.NavigateToParent(); + ctx.NavigateToAttribute(new XmlQualifiedName("baz", "urn:foo:bar")); + Assert.AreEqual("/bar:foo[1]/@bar:baz", ctx.XPath); + ctx.NavigateToParent(); + } + + internal class Element : XPathContext.INodeInfo { + private readonly XmlQualifiedName name; + internal Element(string name) { + this.name = new XmlQualifiedName(name); + } + internal Element(string name, string ns) { + this.name = new XmlQualifiedName(name, ns); + } + public XmlQualifiedName Name { get { return name; } } + public XmlNodeType Type { get { return XmlNodeType.Element; } } + } + + internal abstract class NonElement : XPathContext.INodeInfo { + public XmlQualifiedName Name { get { return null; } } + public abstract XmlNodeType Type { get; } + } + internal class Text : NonElement { + public override XmlNodeType Type { + get { return XmlNodeType.Text; } + } + } + internal class Comment : NonElement { + public override XmlNodeType Type { + get { return XmlNodeType.Comment; } + } + } + internal class PI : NonElement { + public override XmlNodeType Type { + get { return XmlNodeType.ProcessingInstruction;} + } + } + internal class CDATA : NonElement { + public override XmlNodeType Type { + get { return XmlNodeType.CDATA; } + } + } + } +} \ No newline at end of file Property changes on: trunk/xmlunit/src/tests/net-core/diff/XPathContextTest.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-08-19 14:52:34
|
Revision: 431 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=431&view=rev Author: bodewig Date: 2010-08-19 14:52:28 +0000 (Thu, 19 Aug 2010) Log Message: ----------- XML Declaration differences for .NET as well Modified Paths: -------------- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-19 14:28:50 UTC (rev 430) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-19 14:52:28 UTC (rev 431) @@ -143,16 +143,13 @@ testExpr="testDt"/> <literal><![CDATA[ } + XmlDeclaration controlDecl = control.FirstChild as XmlDeclaration; + XmlDeclaration testDecl = test.FirstChild as XmlDeclaration; ]]></literal> -<!-- - <compare type="XML_VERSION" property="getXmlVersion()"/> - <compare type="XML_STANDALONE" property="getXmlStandalone()"/> + <compareMethodExpr method="CompareDeclarations" + controlExpr="controlDecl" + testExpr="testDecl"/> <literal><![CDATA[ - return Compare(new Comparison(ComparisonType.XML_ENCODING, - control, null, control.getXmlEncoding(), - test, null, test.getXmlEncoding())); ---> - <literal><![CDATA[ return lastResult; } @@ -168,6 +165,37 @@ test, null, test.SystemId)); } + private ComparisonResult CompareDeclarations(XmlDeclaration control, + XmlDeclaration test) { +]]></literal> + <lastResultDef/> + <literal><![CDATA[ + string controlVersion = + control == null ? "1.0" : control.Version; + string testVersion = + test == null ? "1.0" : test.Version; +]]></literal> + <compareExpr type="XML_VERSION" + controlExpr="controlVersion" + testExpr="testVersion"/> + <literal><![CDATA[ + string controlStandalone = + control == null ? string.Empty : control.Standalone; + string testStandalone = + test == null ? string.Empty : test.Standalone; +]]></literal> + <compareExpr type="XML_STANDALONE" + controlExpr="controlStandalone" + testExpr="testStandalone"/> + <literal><![CDATA[ + string controlEncoding = + control != null ? control.Encoding : string.Empty; + string testEncoding = test != null ? test.Encoding : string.Empty; + return Compare(new Comparison(ComparisonType.XML_ENCODING, + control, null, controlEncoding, + test, null, testEncoding)); + } + private ComparisonResult CompareElements(XmlElement control, XmlElement test) { ]]></literal> Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-19 14:28:50 UTC (rev 430) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-19 14:52:28 UTC (rev 431) @@ -265,9 +265,7 @@ Assert.AreEqual(1, ex.invoked); #endif -#if false // need a way to figure out the XML_* differences - - // .NET doesn't like XML 1.1 anyway +#if false // .NET doesn't like XML 1.1 anyway d = new DOMDifferenceEngine(); ex = new DiffExpecter(ComparisonType.XML_VERSION); d.DifferenceListener += ex.ComparisonPerformed; @@ -287,7 +285,6 @@ Assert.AreEqual(1, ex.invoked); #endif -#if false // need a way to figure out the XML_* differences d = new DOMDifferenceEngine(); ex = new DiffExpecter(ComparisonType.XML_STANDALONE); d.DifferenceListener += ex.ComparisonPerformed; @@ -305,9 +302,7 @@ Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(d1, d2)); Assert.AreEqual(1, ex.invoked); -#endif -#if false // need a way to figure out the XML_* differences d = new DOMDifferenceEngine(); ex = new DiffExpecter(ComparisonType.XML_ENCODING); d.DifferenceListener += ex.ComparisonPerformed; @@ -332,7 +327,6 @@ Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(d1, d2)); Assert.AreEqual(1, ex.invoked); -#endif } [Test] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-19 14:28:57
|
Revision: 430 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=430&view=rev Author: bodewig Date: 2010-08-19 14:28:50 +0000 (Thu, 19 Aug 2010) Log Message: ----------- schema location comparisons 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-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-19 14:04:16 UTC (rev 429) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-19 14:28:50 UTC (rev 430) @@ -218,6 +218,16 @@ testExpr="Boolean.TRUE"/> <literal><![CDATA[ } +]]></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; } @@ -320,9 +330,9 @@ private final List<Attr> remainingAttributes; private Attributes(Attr schemaLocation, Attr noNamespaceSchemaLocation, List<Attr> remainingAttributes) { - this.schemaLocation = schemaLocation; + this.schemaLocation = schemaLocation; this.noNamespaceSchemaLocation = noNamespaceSchemaLocation; - this.remainingAttributes = remainingAttributes; + this.remainingAttributes = remainingAttributes; } } Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-19 14:04:16 UTC (rev 429) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-19 14:28:50 UTC (rev 430) @@ -211,6 +211,14 @@ <literal><![CDATA[ } ]]></literal> + <compareExpr type="SCHEMA_LOCATION" + controlExpr="controlAttributes.SchemaLocation != null ? controlAttributes.SchemaLocation.Value : null" + testExpr="testAttributes.SchemaLocation != null ? testAttributes.SchemaLocation.Value : null" + /> + <compareExpr type="NO_NAMESPACE_SCHEMA_LOCATION" + controlExpr="controlAttributes.NoNamespaceSchemaLocation != null ? controlAttributes.NoNamespaceSchemaLocation.Value : null" + testExpr="testAttributes.NoNamespaceSchemaLocation != null ? testAttributes.NoNamespaceSchemaLocation.Value : null" + /> <literal><![CDATA[ return lastResult; } @@ -316,9 +324,9 @@ internal Attributes(XmlAttribute schemaLocation, XmlAttribute noNamespaceSchemaLocation, IList<XmlAttribute> remainingAttributes) { - this.SchemaLocation = schemaLocation; + this.SchemaLocation = schemaLocation; this.NoNamespaceSchemaLocation = noNamespaceSchemaLocation; - this.RemainingAttributes = remainingAttributes; + this.RemainingAttributes = remainingAttributes; } } 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-08-19 14:04:16 UTC (rev 429) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-19 14:28:50 UTC (rev 430) @@ -543,4 +543,53 @@ assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); assertEquals(1, ex.invoked); } + + @Test public void schemaLocationDifferences() { + Element e1 = doc.createElement("foo"); + Element e2 = doc.createElement("foo"); + e1.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", + "schemaLocation", "somewhere"); + e2.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", + "schemaLocation", "somewhere else"); + + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.SCHEMA_LOCATION); + d.addDifferenceListener(ex); + d.setDifferenceEvaluator(new DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.getType() == ComparisonType.SCHEMA_LOCATION) { + assertEquals(ComparisonResult.DIFFERENT, outcome); + return ComparisonResult.CRITICAL; + } + assertEquals(ComparisonResult.EQUAL, outcome); + return ComparisonResult.EQUAL; + } + }); + assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(1, ex.invoked); + + e1 = doc.createElement("foo"); + e2 = doc.createElement("foo"); + e1.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", + "noNamespaceSchemaLocation", "somewhere"); + e2.setAttributeNS("http://www.w3.org/2001/XMLSchema-instance", + "noNamespaceSchemaLocation", "somewhere else"); + d = new DOMDifferenceEngine(); + ex = new DiffExpecter(ComparisonType.NO_NAMESPACE_SCHEMA_LOCATION); + d.addDifferenceListener(ex); + d.setDifferenceEvaluator(new DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.getType() == ComparisonType.NO_NAMESPACE_SCHEMA_LOCATION) { + assertEquals(ComparisonResult.DIFFERENT, outcome); + return ComparisonResult.CRITICAL; + } + assertEquals(ComparisonResult.EQUAL, outcome); + return ComparisonResult.EQUAL; + } + }); + assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(1, ex.invoked); + } } Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-19 14:04:16 UTC (rev 429) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-19 14:28:50 UTC (rev 430) @@ -540,5 +540,55 @@ Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); Assert.AreEqual(1, ex.invoked); } + + [Test] + public void SchemaLocationDifferences() { + XmlElement e1 = doc.CreateElement("foo"); + XmlElement e2 = doc.CreateElement("foo"); + e1.SetAttribute("schemaLocation", + "http://www.w3.org/2001/XMLSchema-instance", + "somewhere"); + e2.SetAttribute("schemaLocation", + "http://www.w3.org/2001/XMLSchema-instance", + "somewhere else"); + + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.SCHEMA_LOCATION); + d.DifferenceListener += ex.ComparisonPerformed; + d.DifferenceEvaluator = delegate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.Type == ComparisonType.SCHEMA_LOCATION) { + Assert.AreEqual(ComparisonResult.DIFFERENT, outcome); + return ComparisonResult.CRITICAL; + } + Assert.AreEqual(ComparisonResult.EQUAL, outcome); + return ComparisonResult.EQUAL; + }; + Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(1, ex.invoked); + + e1 = doc.CreateElement("foo"); + e2 = doc.CreateElement("foo"); + e1.SetAttribute("noNamespaceSchemaLocation", + "http://www.w3.org/2001/XMLSchema-instance", + "somewhere"); + e2.SetAttribute("noNamespaceSchemaLocation", + "http://www.w3.org/2001/XMLSchema-instance", + "somewhere else"); + d = new DOMDifferenceEngine(); + ex = new DiffExpecter(ComparisonType.NO_NAMESPACE_SCHEMA_LOCATION); + d.DifferenceListener += ex.ComparisonPerformed; + d.DifferenceEvaluator = delegate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.Type == ComparisonType.NO_NAMESPACE_SCHEMA_LOCATION) { + Assert.AreEqual(ComparisonResult.DIFFERENT, outcome); + return ComparisonResult.CRITICAL; + } + Assert.AreEqual(ComparisonResult.EQUAL, outcome); + return ComparisonResult.EQUAL; + }; + Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(1, ex.invoked); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-19 14:04:23
|
Revision: 429 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=429&view=rev Author: bodewig Date: 2010-08-19 14:04:16 +0000 (Thu, 19 Aug 2010) Log Message: ----------- treat XML NS Declarations and XML Schema Instance Namespaces differently 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/net-core/diff/DOMDifferenceEngineTest.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-08-18 14:45:50 UTC (rev 428) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-19 14:04:16 UTC (rev 429) @@ -17,9 +17,12 @@ 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.Set"/> <import reference="java.util.TreeSet"/> + <import reference="javax.xml.XMLConstants"/> <import reference="javax.xml.transform.Source"/> <import reference="net.sf.xmlunit.util.Convert"/> <import reference="net.sf.xmlunit.util.IterableNodeList"/> @@ -180,51 +183,41 @@ <lastResultDef/> <compare type="ELEMENT_TAG_NAME" property="getTagName()"/> <literal><![CDATA[ - NamedNodeMap controlAttributes = control.getAttributes(); - NamedNodeMap testAttributes = test.getAttributes(); - final int controlAttrLen = controlAttributes.getLength(); - final int testAttrLen = testAttributes.getLength(); + Attributes controlAttributes = splitAttributes(control.getAttributes()); + Attributes testAttributes = splitAttributes(test.getAttributes()); + Set<Attr> foundTestAttributes = new HashSet<Attr>(); ]]></literal> <compareExpr type="ELEMENT_NUM_ATTRIBUTES" - controlExpr="controlAttrLen" - testExpr="testAttrLen"/> + controlExpr="controlAttributes.remainingAttributes.size()" + testExpr="testAttributes.remainingAttributes.size()"/> <literal><![CDATA[ - for (int i = 0; i < controlAttrLen; i++) { - final Attr controlAttr = (Attr) controlAttributes.item(i); - final Attr testAttr = findMatchingAttr(testAttributes, controlAttr); + for (Attr controlAttr : controlAttributes.remainingAttributes) { + final Attr testAttr = + findMatchingAttr(testAttributes.remainingAttributes, + controlAttr); ]]></literal> <compareExpr type="ATTR_NAME_LOOKUP" controlExpr="Boolean.TRUE" testExpr="Boolean.valueOf(testAttr != null)"/> <literal><![CDATA[ - } -]]></literal> - <literal><![CDATA[ - for (int i = 0; i < testAttrLen; i++) { - final Attr testAttr = (Attr) testAttributes.item(i); - final Attr controlAttr = findMatchingAttr(controlAttributes, - testAttr); -]]></literal> - <compareExpr type="ATTR_NAME_LOOKUP" - controlExpr="Boolean.valueOf(controlAttr != null)" - testExpr="Boolean.TRUE"/> - <literal><![CDATA[ - } -]]></literal> - <literal><![CDATA[ - for (int i = 0; i < controlAttrLen; i++) { - final Attr controlAttr = (Attr) controlAttributes.item(i); - final Attr testAttr = findMatchingAttr(testAttributes, controlAttr); if (testAttr != null) { ]]></literal> <compareMethodExpr method="compareNodes" controlExpr="controlAttr" testExpr="testAttr"/> <literal><![CDATA[ + foundTestAttributes.add(testAttr); } } ]]></literal> <literal><![CDATA[ + for (Attr testAttr : testAttributes.remainingAttributes) { +]]></literal> + <compareExpr type="ATTR_NAME_LOOKUP" + controlExpr="Boolean.valueOf(foundTestAttributes.contains(testAttr))" + testExpr="Boolean.TRUE"/> + <literal><![CDATA[ + } return lastResult; } @@ -300,14 +293,58 @@ test, null, test.getValue())); } - private static Attr findMatchingAttr(final NamedNodeMap map, + 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) { - if (attrToMatch.getNamespaceURI() == null) { - return (Attr) map.getNamedItem(attrToMatch.getName()); - } else { - return (Attr) map.getNamedItemNS(attrToMatch.getNamespaceURI(), - attrToMatch.getLocalName()); + 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 Match findMatchingNode(final Node searchFor, Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-18 14:45:50 UTC (rev 428) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-19 14:04:16 UTC (rev 429) @@ -20,9 +20,12 @@ <import reference="System"/> <import reference="System.Collections.Generic"/> <import reference="System.Xml"/> + <import reference="System.Xml.Schema"/> <literal><![CDATA[ + private static readonly object DUMMY = new object(); + public override void Compare(ISource control, ISource test) { if (control == null) { throw new ArgumentNullException("control"); @@ -171,55 +174,46 @@ <lastResultDef/> <compare type="ELEMENT_TAG_NAME" property="Name"/> <literal><![CDATA[ - XmlAttributeCollection controlAttributes = control.Attributes; - XmlAttributeCollection testAttributes = test.Attributes; - int controlAttrLen = controlAttributes.Count; - int testAttrLen = testAttributes.Count; + Attributes controlAttributes = SplitAttributes(control.Attributes); + Attributes testAttributes = SplitAttributes(test.Attributes); + IDictionary<XmlAttribute, object> foundTestAttributes = + new Dictionary<XmlAttribute, object>(); ]]></literal> <compareExpr type="ELEMENT_NUM_ATTRIBUTES" - controlExpr="controlAttrLen" - testExpr="testAttrLen"/> + controlExpr="controlAttributes.RemainingAttributes.Count" + testExpr="testAttributes.RemainingAttributes.Count"/> <literal><![CDATA[ - for (int i = 0; i < controlAttrLen; i++) { - XmlAttribute controlAttr = controlAttributes[i]; - XmlAttribute testAttr = FindMatchingAttr(testAttributes, - controlAttr); + foreach (XmlAttribute controlAttr in controlAttributes.RemainingAttributes) { + XmlAttribute testAttr = + FindMatchingAttr(testAttributes.RemainingAttributes, + controlAttr); ]]></literal> <compareExpr type="ATTR_NAME_LOOKUP" controlExpr="true" testExpr="testAttr != null"/> <literal><![CDATA[ - } + if (testAttr != null) { ]]></literal> + <compareMethodExpr method="CompareNodes" + controlExpr="controlAttr" + testExpr="testAttr"/> <literal><![CDATA[ - for (int i = 0; i < testAttrLen; i++) { - XmlAttribute testAttr = testAttributes[i]; - XmlAttribute controlAttr = FindMatchingAttr(controlAttributes, - testAttr); + foundTestAttributes[testAttr] = DUMMY; + } + } ]]></literal> + <literal><![CDATA[ + foreach (XmlAttribute testAttr in testAttributes.RemainingAttributes) { +]]></literal> <compareExpr type="ATTR_NAME_LOOKUP" - controlExpr="controlAttr != null" + controlExpr="foundTestAttributes.ContainsKey(testAttr)" testExpr="true"/> <literal><![CDATA[ - } + } ]]></literal> <literal><![CDATA[ - for (int i = 0; i < controlAttrLen; i++) { - XmlAttribute controlAttr = controlAttributes[i]; - XmlAttribute testAttr = FindMatchingAttr(testAttributes, - controlAttr); - if (testAttr != null) { -]]></literal> - <compareMethodExpr method="CompareNodes" - controlExpr="controlAttr" - testExpr="testAttr"/> - <literal><![CDATA[ - } + return lastResult; } -]]></literal> - <literal><![CDATA[ - return lastResult; - } private ComparisonResult CompareProcessingInstructions(XmlProcessingInstruction control, @@ -233,8 +227,6 @@ test, null, test.Data)); } - private static readonly object DUMMY = new object(); - private ComparisonResult CompareNodeLists(XmlNodeList control, XmlNodeList test) { IList<XmlNode> controlList = @@ -299,15 +291,56 @@ test, null, test.Value)); } - private static XmlAttribute FindMatchingAttr(XmlAttributeCollection map, + private static Attributes SplitAttributes(XmlAttributeCollection map) { + XmlAttribute sLoc = map.GetNamedItem("schemaLocation", + XmlSchema.InstanceNamespace) + as XmlAttribute; + XmlAttribute nNsLoc = map.GetNamedItem("noNamespaceSchemaLocation", + XmlSchema.InstanceNamespace) + as XmlAttribute; + List<XmlAttribute> rest = new List<XmlAttribute>(); + foreach (XmlAttribute a in map) { + if (XmlSchema.InstanceNamespace != a.NamespaceURI + && + "http://www.w3.org/2000/xmlns/" != a.NamespaceURI) { + rest.Add(a); + } + } + return new Attributes(sLoc, nNsLoc, rest); + } + + internal class Attributes { + internal readonly XmlAttribute SchemaLocation; + internal readonly XmlAttribute NoNamespaceSchemaLocation; + internal readonly IList<XmlAttribute> RemainingAttributes; + internal Attributes(XmlAttribute schemaLocation, + XmlAttribute noNamespaceSchemaLocation, + IList<XmlAttribute> remainingAttributes) { + this.SchemaLocation = schemaLocation; + this.NoNamespaceSchemaLocation = noNamespaceSchemaLocation; + this.RemainingAttributes = remainingAttributes; + } + } + + private static XmlAttribute FindMatchingAttr(IList<XmlAttribute> attrs, XmlAttribute attrToMatch) { - if (attrToMatch.NamespaceURI == null) { - return map.GetNamedItem(attrToMatch.Name) as XmlAttribute; - } else { - return map.GetNamedItem(attrToMatch.LocalName, - attrToMatch.NamespaceURI) - as XmlAttribute; + bool hasNs = !string.IsNullOrEmpty(attrToMatch.NamespaceURI); + string nsToMatch = attrToMatch.NamespaceURI; + string nameToMatch = hasNs ? attrToMatch.LocalName + : attrToMatch.Name; + foreach (XmlAttribute a in attrs) { + if (((!hasNs && string.IsNullOrEmpty(a.NamespaceURI)) + || + (hasNs && nsToMatch == a.NamespaceURI)) + && + ((hasNs && nameToMatch == a.LocalName) + || + (!hasNs && nameToMatch == a.Name)) + ) { + return a; + } } + return null; } private Match FindMatchingNode(XmlNode searchFor, Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-18 14:45:50 UTC (rev 428) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-19 14:04:16 UTC (rev 429) @@ -423,7 +423,8 @@ + " with outcome " + r + " and values '" + comp.ControlDetails.Value + "' and '" - + comp.TestDetails.Value + "'"); + + comp.TestDetails.Value + "'" + + " on '" + comp.ControlDetails.Target + "'"); }; d.DifferenceEvaluator = DifferenceEvaluators.DefaultStopWhenDifferent; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-18 14:45:56
|
Revision: 428 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=428&view=rev Author: bodewig Date: 2010-08-18 14:45:50 +0000 (Wed, 18 Aug 2010) Log Message: ----------- use element selector during recursion 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-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-18 14:27:27 UTC (rev 427) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-18 14:45:50 UTC (rev 428) @@ -328,6 +328,10 @@ } 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 = compare(new Comparison(ComparisonType.NODE_TYPE, n1, null, n1.getNodeType(), Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-18 14:27:27 UTC (rev 427) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-18 14:45:50 UTC (rev 428) @@ -328,6 +328,9 @@ } private bool NodesMatch(XmlNode n1, XmlNode n2) { + if (n1 is XmlElement && n2 is XmlElement) { + return ElementSelector(n1 as XmlElement, n2 as XmlElement); + } ComparisonResult r = Compare(new Comparison(ComparisonType.NODE_TYPE, n1, null, n1.NodeType, 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-08-18 14:27:27 UTC (rev 427) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-18 14:45:50 UTC (rev 428) @@ -520,4 +520,27 @@ assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); assertEquals(ComparisonResult.EQUAL, d.compareNodes(e2, e1)); } + + @Test public void recursionUsesElementSelector() { + Element e1 = doc.createElement("foo"); + Element e2 = doc.createElement("foo"); + Element e3 = doc.createElement("bar"); + e1.appendChild(e3); + Element e4 = doc.createElement("baz"); + e2.appendChild(e4); + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.ELEMENT_TAG_NAME); + d.addDifferenceListener(ex); + d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); + assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(1, ex.invoked); + + d = new DOMDifferenceEngine(); + d.setElementSelector(ElementSelectors.byName); + ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.addDifferenceListener(ex); + d.setDifferenceEvaluator(DifferenceEvaluators.DefaultStopWhenDifferent); + assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(1, ex.invoked); + } } Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-18 14:27:27 UTC (rev 427) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-18 14:45:50 UTC (rev 428) @@ -502,7 +502,7 @@ } [Test] - public void textAndCDataMatchRecursively() { + public void TextAndCDataMatchRecursively() { XmlElement e1 = doc.CreateElement("foo"); XmlElement e2 = doc.CreateElement("foo"); XmlText fooText = doc.CreateTextNode("foo"); @@ -513,5 +513,31 @@ Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e1, e2)); Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e2, e1)); } + + [Test] + public void RecursionUsesElementSelector() { + XmlElement e1 = doc.CreateElement("foo"); + XmlElement e2 = doc.CreateElement("foo"); + XmlElement e3 = doc.CreateElement("bar"); + e1.AppendChild(e3); + XmlElement e4 = doc.CreateElement("baz"); + e2.AppendChild(e4); + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.ELEMENT_TAG_NAME); + d.DifferenceListener += ex.ComparisonPerformed; + d.DifferenceEvaluator = + DifferenceEvaluators.DefaultStopWhenDifferent; + Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(1, ex.invoked); + + d = new DOMDifferenceEngine(); + d.ElementSelector = ElementSelectors.ByName; + ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.DifferenceListener += ex.ComparisonPerformed; + d.DifferenceEvaluator = + DifferenceEvaluators.DefaultStopWhenDifferent; + Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(1, ex.invoked); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-18 14:27:34
|
Revision: 427 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=427&view=rev Author: bodewig Date: 2010-08-18 14:27:27 +0000 (Wed, 18 Aug 2010) Log Message: ----------- allow CData to match Text nodes in recursion 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-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-18 14:06:06 UTC (rev 426) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-18 14:27:27 UTC (rev 427) @@ -332,7 +332,7 @@ compare(new Comparison(ComparisonType.NODE_TYPE, n1, null, n1.getNodeType(), n2, null, n2.getNodeType())); - return r == ComparisonResult.EQUAL; + return r != ComparisonResult.CRITICAL; } private class Match { Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-18 14:06:06 UTC (rev 426) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-18 14:27:27 UTC (rev 427) @@ -332,7 +332,7 @@ Compare(new Comparison(ComparisonType.NODE_TYPE, n1, null, n1.NodeType, n2, null, n2.NodeType)); - return r == ComparisonResult.EQUAL; + return r != ComparisonResult.CRITICAL; } internal class Match { 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-08-18 14:06:06 UTC (rev 426) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-18 14:27:27 UTC (rev 427) @@ -505,6 +505,19 @@ d.addDifferenceListener(ex); d.setDifferenceEvaluator(ev); assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.EQUAL, d.compareNodes(e2, e1)); assertEquals(0, ex.invoked); } + + @Test public void textAndCDataMatchRecursively() { + Element e1 = doc.createElement("foo"); + Element e2 = doc.createElement("foo"); + Text fooText = doc.createTextNode("foo"); + e1.appendChild(fooText); + CDATASection fooCDATASection = doc.createCDATASection("foo"); + e2.appendChild(fooCDATASection); + DOMDifferenceEngine d = new DOMDifferenceEngine(); + assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); + assertEquals(ComparisonResult.EQUAL, d.compareNodes(e2, e1)); + } } Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-18 14:06:06 UTC (rev 426) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-18 14:27:27 UTC (rev 427) @@ -497,8 +497,21 @@ d.DifferenceListener += ex.ComparisonPerformed; d.DifferenceEvaluator = ev; Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e2, e1)); Assert.AreEqual(0, ex.invoked); } + [Test] + public void textAndCDataMatchRecursively() { + XmlElement e1 = doc.CreateElement("foo"); + XmlElement e2 = doc.CreateElement("foo"); + XmlText fooText = doc.CreateTextNode("foo"); + e1.AppendChild(fooText); + XmlCDataSection fooCDATASection = doc.CreateCDataSection("foo"); + e2.AppendChild(fooCDATASection); + DOMDifferenceEngine d = new DOMDifferenceEngine(); + Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e2, e1)); + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-18 14:06:12
|
Revision: 426 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=426&view=rev Author: bodewig Date: 2010-08-18 14:06:06 +0000 (Wed, 18 Aug 2010) Log Message: ----------- make NodeList comparison symmetric 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-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-13 13:10:16 UTC (rev 425) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-18 14:06:06 UTC (rev 426) @@ -18,6 +18,8 @@ extends="AbstractDifferenceEngine"> <import reference="java.util.List"/> + <import reference="java.util.Set"/> + <import reference="java.util.TreeSet"/> <import reference="javax.xml.transform.Source"/> <import reference="net.sf.xmlunit.util.Convert"/> <import reference="net.sf.xmlunit.util.IterableNodeList"/> @@ -241,13 +243,19 @@ private ComparisonResult compareNodeLists(NodeList control, NodeList test) { List<Node> controlList = IterableNodeList.asList(control); List<Node> testList = IterableNodeList.asList(test); - Match lastMatch = new Match(null, -1); + 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; - <literal><![CDATA[ - for (int i = 0; i < controlList.size(); i++) { + final int controlSize = controlList.size(); + Match lastMatch = new Match(null, -1); + for (int i = 0; i < controlSize; i++) { Match testMatch = findMatchingNode(controlList.get(i), testList, lastMatch.index); if (testMatch != null) { @@ -256,6 +264,7 @@ controlExpr="controlList.get(i)" testExpr="testMatch.node"/> <literal><![CDATA[ + unmatchedTestIndexes.remove(Integer.valueOf(testMatch.index)); lastMatch = testMatch; } else { lastResult = @@ -268,6 +277,16 @@ <literal><![CDATA[ } } + for (Integer I : unmatchedTestIndexes) { + int i = I.intValue(); + lastResult = + compare(new Comparison(ComparisonType.CHILD_LOOKUP, + null, null, null, + testList.get(i), null, testList.get(i))); +]]></literal> + <if-return-boilerplate/> + <literal><![CDATA[ + } return lastResult; } Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-13 13:10:16 UTC (rev 425) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-18 14:06:06 UTC (rev 426) @@ -233,29 +233,37 @@ test, null, test.Data)); } + private static readonly object DUMMY = new object(); + private ComparisonResult CompareNodeLists(XmlNodeList control, XmlNodeList test) { - List<XmlNode> controlList = + IList<XmlNode> controlList = new List<XmlNode>(net.sf.xmlunit.util.Convert .Cast<XmlNode>(control)); - List<XmlNode> testList = + IList<XmlNode> testList = new List<XmlNode>(net.sf.xmlunit.util.Convert .Cast<XmlNode>(test)); - Match lastMatch = new Match(null, -1); + 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; - <literal><![CDATA[ + Match lastMatch = new Match(null, -1); for (int i = 0; i < controlList.Count; i++) { Match testMatch = FindMatchingNode(controlList[i], testList, - lastMatch.index); + lastMatch.Index); if (testMatch != null) { ]]></literal> <compareMethodExpr method="CompareNodes" controlExpr="controlList[i]" - testExpr="testMatch.node"/> + testExpr="testMatch.Node"/> <literal><![CDATA[ + unmatchedTestIndexes.Remove(testMatch.Index); lastMatch = testMatch; } else { lastResult = @@ -268,6 +276,15 @@ <literal><![CDATA[ } } + foreach (int i in unmatchedTestIndexes.Keys) { + lastResult = + Compare(new Comparison(ComparisonType.CHILD_LOOKUP, + null, null, null, + testList[i], null, testList[i])); +]]></literal> + <if-return-boilerplate/> + <literal><![CDATA[ + } return lastResult; } @@ -319,11 +336,11 @@ } internal class Match { - internal readonly XmlNode node; - internal readonly int index; + internal readonly XmlNode Node; + internal readonly int Index; internal Match(XmlNode match, int index) { - this.node = match; - this.index = index; + Node = match; + Index = index; } } ]]></literal> 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-08-13 13:10:16 UTC (rev 425) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-18 14:06:06 UTC (rev 426) @@ -490,6 +490,14 @@ assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); assertEquals(1, ex.invoked); + // symmetric? + d = new DOMDifferenceEngine(); + ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.addDifferenceListener(ex); + d.setDifferenceEvaluator(ev); + assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e2, e1)); + assertEquals(1, ex.invoked); + Element c2 = doc.createElement("bar"); e2.appendChild(c2); d = new DOMDifferenceEngine(); Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-13 13:10:16 UTC (rev 425) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-18 14:06:06 UTC (rev 426) @@ -482,6 +482,14 @@ Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); Assert.AreEqual(1, ex.invoked); + // symmetric? + d = new DOMDifferenceEngine(); + ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.DifferenceListener += ex.ComparisonPerformed; + d.DifferenceEvaluator = ev; + Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e2, e1)); + Assert.AreEqual(1, ex.invoked); + XmlElement c2 = doc.CreateElement("bar"); e2.AppendChild(c2); 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-08-13 13:10:22
|
Revision: 425 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=425&view=rev Author: bodewig Date: 2010-08-13 13:10:16 +0000 (Fri, 13 Aug 2010) Log Message: ----------- start recursion support Modified Paths: -------------- trunk/xmlunit/src/buildtools/codegen.xslt trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml trunk/xmlunit/src/main/net-core/util/Convert.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs Modified: trunk/xmlunit/src/buildtools/codegen.xslt =================================================================== --- trunk/xmlunit/src/buildtools/codegen.xslt 2010-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/buildtools/codegen.xslt 2010-08-13 13:10:16 UTC (rev 425) @@ -122,6 +122,10 @@ <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; 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-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DOMDifferenceEngine.java.xml 2010-08-13 13:10:16 UTC (rev 425) @@ -17,8 +17,10 @@ summary="Difference engine based on DOM." extends="AbstractDifferenceEngine"> + <import reference="java.util.List"/> <import reference="javax.xml.transform.Source"/> <import reference="net.sf.xmlunit.util.Convert"/> + <import reference="net.sf.xmlunit.util.IterableNodeList"/> <import reference="org.w3c.dom.Attr"/> <import reference="org.w3c.dom.CharacterData"/> <import reference="org.w3c.dom.Document"/> @@ -237,7 +239,36 @@ } private ComparisonResult compareNodeLists(NodeList control, NodeList test) { - return ComparisonResult.EQUAL; + List<Node> controlList = IterableNodeList.asList(control); + List<Node> testList = IterableNodeList.asList(test); + Match lastMatch = new Match(null, -1); +]]></literal> + <lastResultDef/> + // if there are no children on either Node, the result is equal + lastResult = ComparisonResult.EQUAL; + <literal><![CDATA[ + for (int i = 0; i < controlList.size(); i++) { + Match testMatch = findMatchingNode(controlList.get(i), testList, + lastMatch.index); + if (testMatch != null) { +]]></literal> + <compareMethodExpr method="compareNodes" + controlExpr="controlList.get(i)" + testExpr="testMatch.node"/> + <literal><![CDATA[ + lastMatch = testMatch; + } else { + lastResult = + compare(new Comparison(ComparisonType.CHILD_LOOKUP, + controlList.get(i), null, + controlList.get(i), + null, null, null)); +]]></literal> + <if-return-boilerplate/> + <literal><![CDATA[ + } + } + return lastResult; } private ComparisonResult compareAttributes(Attr control, Attr test) { @@ -250,7 +281,8 @@ test, null, test.getValue())); } - private static Attr findMatchingAttr(NamedNodeMap map, Attr attrToMatch) { + private static Attr findMatchingAttr(final NamedNodeMap map, + final Attr attrToMatch) { if (attrToMatch.getNamespaceURI() == null) { return (Attr) map.getNamedItem(attrToMatch.getName()); } else { @@ -259,5 +291,39 @@ } } + private Match findMatchingNode(final Node searchFor, + final List<Node> searchIn, + final int indexOfLastMatch) { + final int searchSize = searchIn.size(); + for (int i = indexOfLastMatch + 1; i < searchSize; i++) { + if (nodesMatch(searchFor, searchIn.get(i))) { + return new Match(searchIn.get(i), i); + } + } + for (int i = 0; i < indexOfLastMatch; i++) { + if (nodesMatch(searchFor, searchIn.get(i))) { + return new Match(searchIn.get(i), i); + } + } + return null; + } + + private boolean nodesMatch(final Node n1, final Node n2) { + ComparisonResult r = + compare(new Comparison(ComparisonType.NODE_TYPE, + n1, null, n1.getNodeType(), + n2, null, n2.getNodeType())); + return r == ComparisonResult.EQUAL; + } + + private class Match { + private final Node node; + private final int index; + private Match(Node match, int index) { + this.node = match; + this.index = index; + } + } + ]]></literal> </class> \ No newline at end of file Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java 2010-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/IterableNodeList.java 2010-08-13 13:10:16 UTC (rev 425) @@ -13,7 +13,9 @@ */ package net.sf.xmlunit.util; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -46,4 +48,22 @@ return current < length; } } + + /** + * Turns the iterable into a list. + */ + public static List<Node> asList(IterableNodeList l) { + ArrayList<Node> a = new ArrayList<Node>(l.length); + for (Node n : l) { + a.add(n); + } + return a; + } + + /** + * Turns the NodeList into a list. + */ + public static List<Node> asList(NodeList l) { + return asList(new IterableNodeList(l)); + } } Modified: trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/main/net-core/diff/DOMDifferenceEngine.xml 2010-08-13 13:10:16 UTC (rev 425) @@ -18,6 +18,7 @@ extends="AbstractDifferenceEngine"> <import reference="System"/> + <import reference="System.Collections.Generic"/> <import reference="System.Xml"/> <literal><![CDATA[ @@ -234,7 +235,40 @@ private ComparisonResult CompareNodeLists(XmlNodeList control, XmlNodeList test) { - return ComparisonResult.EQUAL; + List<XmlNode> controlList = + new List<XmlNode>(net.sf.xmlunit.util.Convert + .Cast<XmlNode>(control)); + List<XmlNode> testList = + new List<XmlNode>(net.sf.xmlunit.util.Convert + .Cast<XmlNode>(test)); + Match lastMatch = new Match(null, -1); +]]></literal> + <lastResultDef/> + // if there are no children on either Node, the result is equal + lastResult = ComparisonResult.EQUAL; + <literal><![CDATA[ + for (int i = 0; i < controlList.Count; i++) { + Match testMatch = FindMatchingNode(controlList[i], testList, + lastMatch.index); + if (testMatch != null) { +]]></literal> + <compareMethodExpr method="CompareNodes" + controlExpr="controlList[i]" + testExpr="testMatch.node"/> + <literal><![CDATA[ + lastMatch = testMatch; + } else { + lastResult = + Compare(new Comparison(ComparisonType.CHILD_LOOKUP, + controlList[i], null, + controlList[i], + null, null, null)); +]]></literal> + <if-return-boilerplate/> + <literal><![CDATA[ + } + } + return lastResult; } private ComparisonResult CompareAttributes(XmlAttribute control, @@ -258,5 +292,39 @@ as XmlAttribute; } } + + private Match FindMatchingNode(XmlNode searchFor, + IList<XmlNode> searchIn, + int indexOfLastMatch) { + int searchSize = searchIn.Count; + for (int i = indexOfLastMatch + 1; i < searchSize; i++) { + if (NodesMatch(searchFor, searchIn[i])) { + return new Match(searchIn[i], i); + } + } + for (int i = 0; i < indexOfLastMatch; i++) { + if (NodesMatch(searchFor, searchIn[i])) { + return new Match(searchIn[i], i); + } + } + return null; + } + + private bool NodesMatch(XmlNode n1, XmlNode n2) { + ComparisonResult r = + Compare(new Comparison(ComparisonType.NODE_TYPE, + n1, null, n1.NodeType, + n2, null, n2.NodeType)); + return r == ComparisonResult.EQUAL; + } + + internal class Match { + internal readonly XmlNode node; + internal readonly int index; + internal Match(XmlNode match, int index) { + this.node = match; + this.index = index; + } + } ]]></literal> </class> \ No newline at end of file Modified: trunk/xmlunit/src/main/net-core/util/Convert.cs =================================================================== --- trunk/xmlunit/src/main/net-core/util/Convert.cs 2010-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/main/net-core/util/Convert.cs 2010-08-13 13:10:16 UTC (rev 425) @@ -12,6 +12,7 @@ limitations under the License. */ +using System.Collections; using System.Collections.Generic; using System.Xml; using net.sf.xmlunit.input; @@ -72,5 +73,11 @@ } return man; } + + public static IEnumerable<T> Cast<T>(IEnumerable i) { + foreach (T t in i) { + yield return t; + } + } } } 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-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-13 13:10:16 UTC (rev 425) @@ -185,7 +185,7 @@ d.compareNodes(fooCDATASection, fooCDATASection)); assertEquals(ComparisonResult.CRITICAL, d.compareNodes(fooCDATASection, barCDATASection)); - + assertEquals(ComparisonResult.EQUAL, d.compareNodes(fooComment, fooText)); assertEquals(ComparisonResult.CRITICAL, @@ -467,4 +467,36 @@ assertEquals(ComparisonResult.CRITICAL, d.compareNodes(a1, a3)); assertEquals(1, ex.invoked); } + + @Test public void naiveRecursion() { + Element e1 = doc.createElement("foo"); + Element e2 = doc.createElement("foo"); + Element c1 = doc.createElement("bar"); + e1.appendChild(c1); + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.addDifferenceListener(ex); + DifferenceEvaluator ev = new DifferenceEvaluator() { + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.getType() == ComparisonType.CHILD_NODELIST_LENGTH) { + return ComparisonResult.EQUAL; + } + return DifferenceEvaluators.DefaultStopWhenDifferent + .evaluate(comparison, outcome); + } + }; + d.setDifferenceEvaluator(ev); + assertEquals(ComparisonResult.CRITICAL, d.compareNodes(e1, e2)); + assertEquals(1, ex.invoked); + + Element c2 = doc.createElement("bar"); + e2.appendChild(c2); + d = new DOMDifferenceEngine(); + ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.addDifferenceListener(ex); + d.setDifferenceEvaluator(ev); + assertEquals(ComparisonResult.EQUAL, d.compareNodes(e1, e2)); + assertEquals(0, ex.invoked); + } } Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-13 11:54:14 UTC (rev 424) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-13 13:10:16 UTC (rev 425) @@ -172,7 +172,7 @@ d.CompareNodes(fooCDataSection, fooCDataSection)); Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(fooCDataSection, barCDataSection)); - + Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(fooComment, fooText)); Assert.AreEqual(ComparisonResult.CRITICAL, @@ -460,5 +460,37 @@ Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(a1, a3)); Assert.AreEqual(1, ex.invoked); } + + [Test] + public void NaiveRecursion() { + XmlElement e1 = doc.CreateElement("foo"); + XmlElement e2 = doc.CreateElement("foo"); + XmlElement c1 = doc.CreateElement("bar"); + e1.AppendChild(c1); + DOMDifferenceEngine d = new DOMDifferenceEngine(); + DiffExpecter ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.DifferenceListener += ex.ComparisonPerformed; + DifferenceEvaluator ev = delegate(Comparison comparison, + ComparisonResult outcome) { + if (comparison.Type == ComparisonType.CHILD_NODELIST_LENGTH) { + return ComparisonResult.EQUAL; + } + return DifferenceEvaluators.DefaultStopWhenDifferent(comparison, + outcome); + }; + d.DifferenceEvaluator = ev; + Assert.AreEqual(ComparisonResult.CRITICAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(1, ex.invoked); + + XmlElement c2 = doc.CreateElement("bar"); + e2.AppendChild(c2); + d = new DOMDifferenceEngine(); + ex = new DiffExpecter(ComparisonType.CHILD_LOOKUP); + d.DifferenceListener += ex.ComparisonPerformed; + d.DifferenceEvaluator = ev; + Assert.AreEqual(ComparisonResult.EQUAL, d.CompareNodes(e1, e2)); + Assert.AreEqual(0, ex.invoked); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-13 11:54:20
|
Revision: 424 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=424&view=rev Author: bodewig Date: 2010-08-13 11:54:14 +0000 (Fri, 13 Aug 2010) Log Message: ----------- don't tie the DifferenceEngine's interface to DOM Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/Comparison.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs trunk/xmlunit/src/main/net-core/diff/Comparison.cs trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.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-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/AbstractDifferenceEngine.java 2010-08-13 11:54:14 UTC (rev 424) @@ -74,8 +74,8 @@ * listeners and returns the outcome. */ protected final ComparisonResult compare(Comparison comp) { - Object controlValue = comp.getControlNodeDetails().getValue(); - Object testValue = comp.getTestNodeDetails().getValue(); + Object controlValue = comp.getControlDetails().getValue(); + Object testValue = comp.getTestDetails().getValue(); boolean equal = controlValue == null ? testValue == null : controlValue.equals(testValue); ComparisonResult initial = Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/Comparison.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/Comparison.java 2010-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/Comparison.java 2010-08-13 11:54:14 UTC (rev 424) @@ -13,37 +13,36 @@ */ package net.sf.xmlunit.diff; -import org.w3c.dom.Node; - /** * Details of a single comparison XMLUnit has performed. */ public class Comparison { /** - * The details of a Node that took part in the comparision. + * The details of a target (usually some representation of an XML + * Node) that took part in the comparison. */ public static class Detail { - private final Node node; + private final Object target; private final String xpath; private final Object value; - private Detail(Node n, String x, Object v) { - node = n; + private Detail(Object n, String x, Object v) { + target = n; xpath = x; value = v; } /** - * The actual Node. + * The actual target. */ - public Node getNode() { return node; } + public Object getTarget() { return target; } /** - * XPath leading to the Node. + * XPath leading to the target. */ public String getXPath() { return xpath; } /** - * The value for comparision found at the current node. + * The value for comparison found at the current target. */ public Object getValue() { return value; } } @@ -51,32 +50,32 @@ private final Detail control, test; private final ComparisonType type; - public Comparison(ComparisonType t, Node controlNode, + public Comparison(ComparisonType t, Object controlTarget, String controlXPath, Object controlValue, - Node testNode, String testXPath, Object testValue) { + Object testTarget, String testXPath, Object testValue) { type = t; - control = new Detail(controlNode, controlXPath, controlValue); - test = new Detail(testNode, testXPath, testValue); + control = new Detail(controlTarget, controlXPath, controlValue); + test = new Detail(testTarget, testXPath, testValue); } /** - * The kind of comparision performed. + * The kind of comparison performed. */ public ComparisonType getType() { return type; } /** - * Details of the control node. + * Details of the control target. */ - public Detail getControlNodeDetails() { + public Detail getControlDetails() { return control; } /** - * Details of the test node. + * Details of the test target. */ - public Detail getTestNodeDetails() { + public Detail getTestDetails() { return test; } Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java 2010-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/diff/DifferenceEvaluators.java 2010-08-13 11:54:14 UTC (rev 424) @@ -48,9 +48,9 @@ switch (comparison.getType()) { case NODE_TYPE: Short control = (Short) comparison - .getControlNodeDetails().getValue(); + .getControlDetails().getValue(); Short test = (Short) comparison - .getTestNodeDetails().getValue(); + .getTestDetails().getValue(); if ((control.equals(TEXT) && test.equals(CDATA)) || (control.equals(CDATA) && test.equals(TEXT))) { Modified: trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/main/net-core/diff/AbstractDifferenceEngine.cs 2010-08-13 11:54:14 UTC (rev 424) @@ -59,8 +59,8 @@ /// listeners and returns the outcome. /// </summary> protected internal ComparisonResult Compare(Comparison comp) { - object controlValue = comp.ControlNodeDetails.Value; - object testValue = comp.TestNodeDetails.Value; + object controlValue = comp.ControlDetails.Value; + object testValue = comp.TestDetails.Value; bool equal = controlValue == null ? testValue == null : controlValue.Equals(testValue); ComparisonResult initial = Modified: trunk/xmlunit/src/main/net-core/diff/Comparison.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/Comparison.cs 2010-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/main/net-core/diff/Comparison.cs 2010-08-13 11:54:14 UTC (rev 424) @@ -12,8 +12,6 @@ limitations under the License. */ -using System.Xml; - namespace net.sf.xmlunit.diff { /// <summary> @@ -22,29 +20,30 @@ public class Comparison { /// <summary> - /// The details of a Node that took part in the comparision. + /// The details of a target (usually a representation of an + /// XML node) that took part in the comparison. /// </summary> public sealed class Detail { - private readonly XmlNode node; + private readonly object target; private readonly string xpath; private readonly object value; - internal Detail(XmlNode n, string x, object v) { - node = n; + internal Detail(object t, string x, object v) { + target = t; xpath = x; value = v; } /// <summary> - /// The actual Node. + /// The actual target. /// </summary> - public XmlNode Node { get { return node; } } + public object Target { get { return target; } } /// <summary> - /// XPath leading to the Node. + /// XPath leading to the target. /// </summary> public string XPath { get { return xpath; } } /// <summary> - /// The value for comparision found at the current node. + /// The value for comparison found at the current target. /// </summary> public object Value { get { return value; } } } @@ -52,17 +51,17 @@ private readonly Detail control, test; private readonly ComparisonType type; - public Comparison(ComparisonType t, XmlNode controlNode, + public Comparison(ComparisonType t, object controlTarget, string controlXPath, object controlValue, - XmlNode testNode, string testXPath, + object testTarget, string testXPath, object testValue) { type = t; - control = new Detail(controlNode, controlXPath, controlValue); - test = new Detail(testNode, testXPath, testValue); + control = new Detail(controlTarget, controlXPath, controlValue); + test = new Detail(testTarget, testXPath, testValue); } /// <summary> - /// The kind of comparision performed. + /// The kind of comparison performed. /// </summary> public ComparisonType Type { get { @@ -71,18 +70,18 @@ } /// <summary> - /// Details of the control node. + /// Details of the control target. /// </summary> - public Detail ControlNodeDetails { + public Detail ControlDetails { get { return control; } } /// <summary> - /// Details of the test node. + /// Details of the test target. /// </summary> - public Detail TestNodeDetails { + public Detail TestDetails { get { return test; } Modified: trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs =================================================================== --- trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs 2010-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/main/net-core/diff/DifferenceEvaluators.cs 2010-08-13 11:54:14 UTC (rev 424) @@ -41,9 +41,9 @@ switch (comparison.Type) { case ComparisonType.NODE_TYPE: XmlNodeType control = - (XmlNodeType) comparison.ControlNodeDetails.Value; + (XmlNodeType) comparison.ControlDetails.Value; XmlNodeType test = - (XmlNodeType) comparison.TestNodeDetails.Value; + (XmlNodeType) comparison.TestDetails.Value; if ((control == XmlNodeType.Text && test == XmlNodeType.CDATA) || (control == XmlNodeType.CDATA && test == XmlNodeType.Text) 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-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/tests/java-core/net/sf/xmlunit/diff/DOMDifferenceEngineTest.java 2010-08-13 11:54:14 UTC (rev 424) @@ -152,11 +152,11 @@ if (comparison.getType() == ComparisonType.NODE_TYPE) { if (outcome == ComparisonResult.EQUAL || ( - comparison.getControlNodeDetails() - .getNode() instanceof CharacterData + comparison.getControlDetails() + .getTarget() instanceof CharacterData && - comparison.getTestNodeDetails() - .getNode() instanceof CharacterData + comparison.getTestDetails() + .getTarget() instanceof CharacterData )) { return ComparisonResult.EQUAL; } @@ -429,9 +429,9 @@ ComparisonResult outcome) { fail("unexpected Comparison of type " + comparison.getType() + " with outcome " + outcome + " and values '" - + comparison.getControlNodeDetails().getValue() + + comparison.getControlDetails().getValue() + "' and '" - + comparison.getTestNodeDetails().getValue() + "'"); + + comparison.getTestDetails().getValue() + "'"); } }); e1.setAttributeNS("urn:xmlunit:test", "attr1", "value1"); Modified: trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-10 16:12:49 UTC (rev 423) +++ trunk/xmlunit/src/tests/net-core/diff/DOMDifferenceEngineTest.cs 2010-08-13 11:54:14 UTC (rev 424) @@ -143,11 +143,9 @@ if (comparison.Type == ComparisonType.NODE_TYPE) { if (outcome == ComparisonResult.EQUAL || ( - comparison.ControlNodeDetails.Node - is XmlCharacterData + comparison.ControlDetails.Target is XmlCharacterData && - comparison.TestNodeDetails.Node is XmlCharacterData - )) { + comparison.TestDetails.Target is XmlCharacterData)) { return ComparisonResult.EQUAL; } } @@ -423,9 +421,9 @@ ComparisonResult r) { Assert.Fail("unexpected Comparison of type " + comp.Type + " with outcome " + r + " and values '" - + comp.ControlNodeDetails.Value + + comp.ControlDetails.Value + "' and '" - + comp.TestNodeDetails.Value + "'"); + + comp.TestDetails.Value + "'"); }; d.DifferenceEvaluator = DifferenceEvaluators.DefaultStopWhenDifferent; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-10 16:12:55
|
Revision: 423 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=423&view=rev Author: bodewig Date: 2010-08-10 16:12:49 +0000 (Tue, 10 Aug 2010) Log Message: ----------- remove test report generation since it requires VisualBasic on Mono (don't know why) Modified Paths: -------------- trunk/xmlunit/xmlunit.nant.build Modified: trunk/xmlunit/xmlunit.nant.build =================================================================== --- trunk/xmlunit/xmlunit.nant.build 2010-08-10 16:06:43 UTC (rev 422) +++ trunk/xmlunit/xmlunit.nant.build 2010-08-10 16:12:49 UTC (rev 423) @@ -123,9 +123,6 @@ <formatter type="Xml" usefile="true" outputdir="${test.report.dir}"/> <test assemblyname="${bin.dir}/${project::get-name()}-core.tests.dll"/> </nunit2> - <style style="lib/NUnitSummary.xsl" - in="${test.report.dir}/${project::get-name()}-core.tests.dll-results" - out="${test.report.dir}/html/index.html"/> </target> <target name="deploy" description="zip all code for deployment" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-10 16:06:49
|
Revision: 422 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=422&view=rev Author: bodewig Date: 2010-08-10 16:06:43 +0000 (Tue, 10 Aug 2010) Log Message: ----------- use XML file without schema location Modified Paths: -------------- trunk/xmlunit/src/tests/net-core/validation/ValidatorTest.cs Modified: trunk/xmlunit/src/tests/net-core/validation/ValidatorTest.cs =================================================================== --- trunk/xmlunit/src/tests/net-core/validation/ValidatorTest.cs 2010-08-10 16:03:53 UTC (rev 421) +++ trunk/xmlunit/src/tests/net-core/validation/ValidatorTest.cs 2010-08-10 16:06:43 UTC (rev 422) @@ -33,7 +33,7 @@ public void ShouldSuccessfullyValidateInstance() { Validator v = Validator.ForLanguage(Languages.W3C_XML_SCHEMA_NS_URI); v.SchemaSource = new StreamSource(TestResources.TESTS_DIR + "Book.xsd"); - ValidationResult r = v.ValidateInstance(new StreamSource(TestResources.TESTS_DIR + "BookXsdGenerated.xml")); + ValidationResult r = v.ValidateInstance(new StreamSource(TestResources.TESTS_DIR + "BookXsdGeneratedNoSchema.xml")); IEnumerator<ValidationProblem> problems = r.Problems.GetEnumerator(); bool haveErrors = problems.MoveNext(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2010-08-10 16:03:59
|
Revision: 421 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=421&view=rev Author: bodewig Date: 2010-08-10 16:03:53 +0000 (Tue, 10 Aug 2010) Log Message: ----------- revert experiment, neither resolver is consulted on Mono Modified Paths: -------------- trunk/xmlunit/src/main/net-core/validation/Validator.cs Modified: trunk/xmlunit/src/main/net-core/validation/Validator.cs =================================================================== --- trunk/xmlunit/src/main/net-core/validation/Validator.cs 2010-08-10 16:00:40 UTC (rev 420) +++ trunk/xmlunit/src/main/net-core/validation/Validator.cs 2010-08-10 16:03:53 UTC (rev 421) @@ -101,7 +101,6 @@ try { XmlSchema s = XmlSchema.Read(loc.Reader, ThrowOnError); settings.Schemas.Add(s); - settings.Schemas.XmlResolver = new ThrowingResolver(); } catch (IOException ex) { throw new XMLUnitException("Schema is not readable", ex); @@ -117,17 +116,6 @@ return new ValidationResult(problems.Count == 0, problems); } - private class ThrowingResolver : XmlResolver { - public override object GetEntity(Uri uri, string role, Type type) { - throw new Exception(string.Format("GetEntity invoked with ({0}, {1}, {2}", - uri, role, type)); - } - - public override System.Net.ICredentials Credentials { - set {} - } - } - private static readonly IDictionary<string, ValidationType> types; static Validator() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |