From: <bo...@us...> - 2009-06-19 09:36:09
|
Revision: 347 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=347&view=rev Author: bodewig Date: 2009-06-19 09:36:07 +0000 (Fri, 19 Jun 2009) Log Message: ----------- merge fix for issue 2807167 from 1.x branch Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java trunk/xmlunit/src/user-guide/XMLUnit-Java.xml Property Changed: ---------------- trunk/xmlunit/src/main/java-legacy/ trunk/xmlunit/src/tests/java-legacy/ trunk/xmlunit/src/user-guide/ Property changes on: trunk/xmlunit/src/main/java-legacy ___________________________________________________________________ Modified: svn:mergeinfo - + /branches/xmlunit-1.x/src/java:346 Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java 2009-06-19 09:26:16 UTC (rev 346) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/DifferenceEngine.java 2009-06-19 09:36:07 UTC (rev 347) @@ -397,6 +397,30 @@ boolean matchFound = false; + /* + * XMLUnit 1.2 and earlier don't check whether the + * "matched" test node has already been matched to a + * different control node and will happily match the same + * test node to each and every control node, if necessary. + * + * I (Stefan) feel this is wrong but can't change it + * without breaking backwards compatibility + * (testXpathLocation12 in test_DifferenceEngine which + * predates XMLUnit 1.0 fails, so at one point it has been + * the expected and intended behaviour). + * + * As a side effect it may leave test nodes inside the + * unmatched list, see + * https://sourceforge.net/tracker/?func=detail&aid=2807167&group_id=23187&atid=377768 + * + * To overcome the later problem the code will now prefer + * test nodes that haven't already been matched to any + * other node and falls back to the first + * (multiply-)matched node if none could be found. Yes, + * this is strange. + */ + int fallbackMatch = -1; + while (!matchFound) { Node t = (Node) testChildren.get(j); if (findNodeType == t.getNodeType() @@ -407,6 +431,18 @@ .qualifyForComparison((Element) nextControl, (Element) t); } + if (matchFound && !unmatchedTestNodes.contains(t)) { + /* + * test node already matched to a different + * control node, try the other test nodes first + * but keep this as "fallback" (unless there + * already is a fallback) + */ + if (fallbackMatch < 0) { + fallbackMatch = j; + } + matchFound = false; + } if (!matchFound) { ++j; if (j > lastTestNode) { @@ -418,6 +454,10 @@ } } } + if (!matchFound && fallbackMatch >= 0) { + matchFound = true; + j = fallbackMatch; + } if (matchFound) { matchingNodes.put(nextControl, testChildren.get(j)); matchingNodeIndexes.put(nextControl, new Integer(j)); Property changes on: trunk/xmlunit/src/tests/java-legacy ___________________________________________________________________ Modified: svn:mergeinfo - /branches/xmlunit-1.x/tests/java:337 + /branches/xmlunit-1.x/tests:346 /branches/xmlunit-1.x/tests/java:337,346 Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2009-06-19 09:26:16 UTC (rev 346) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2009-06-19 09:36:07 UTC (rev 347) @@ -882,5 +882,31 @@ XMLUnit.setExpandEntityReferences(false); } } + + /** + * @see https://sourceforge.net/tracker/?func=detail&aid=2807167&group_id=23187&atid=377768 + */ + public void testIssue2807167() throws Exception { + String test = "<tag>" + + "<child amount=\"100\" />" + + "<child amount=\"100\" />" + + "<child amount=\"100\" />" + + "<child amount=\"250\" />" + + "<child amount=\"100\" />" + + "</tag>"; + + String control = "<tag>" + + "<child amount=\"100\" />" + + "<child amount=\"100\" />" + + "<child amount=\"250\" />" + + "<child amount=\"100\" />" + + "<child amount=\"100\" />" + + "</tag>"; + + Diff diff = new Diff(control, test); + diff.overrideElementQualifier(new + ElementNameAndAttributeQualifier()); + assertTrue(diff.toString(), diff.similar()); + } } Property changes on: trunk/xmlunit/src/user-guide ___________________________________________________________________ Added: svn:mergeinfo + /branches/xmlunit-1.x/src/user-guide:346 Modified: trunk/xmlunit/src/user-guide/XMLUnit-Java.xml =================================================================== --- trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2009-06-19 09:26:16 UTC (rev 346) +++ trunk/xmlunit/src/user-guide/XMLUnit-Java.xml 2009-06-19 09:36:07 UTC (rev 347) @@ -3542,8 +3542,15 @@ a <literal>ATTR_NAME_NOT_FOUND_ID</literal> kind of difference), the XPath expressions of the node details have been random. <ulink - url="https://sourceforge.net/tracker/index.php?func=detail&aid=2386807&group_id=23187&atid=377768">Issue 2386807</ulink>. + url="https://sourceforge.net/tracker/index.php?func=detail&aid=2386807&group_id=23187&atid=377768">Issue 2386807</ulink>. </listitem> + <listitem> + In some cases XMLUnit matched test nodes to multiple + control nodes and then created a "missing child" + difference for remaining test nodes even though they would + have been valid targets for control node matches as well. + <ulink url="https://sourceforge.net/tracker/?func=detail&aid=2807167&group_id=23187&atid=377768">Issue 2807167</ulink>. + </listitem> </itemizedlist> </section> </section> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |