From: <bo...@us...> - 2009-06-19 09:26:22
|
Revision: 346 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=346&view=rev Author: bodewig Date: 2009-06-19 09:26:16 +0000 (Fri, 19 Jun 2009) Log Message: ----------- fix issue 2807167 Modified Paths: -------------- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java Modified: branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2009-06-09 11:45:58 UTC (rev 345) +++ branches/xmlunit-1.x/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2009-06-19 09:26:16 UTC (rev 346) @@ -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)); Modified: branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml =================================================================== --- branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml 2009-06-09 11:45:58 UTC (rev 345) +++ branches/xmlunit-1.x/src/user-guide/XMLUnit-Java.xml 2009-06-19 09:26:16 UTC (rev 346) @@ -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> Modified: branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java 2009-06-09 11:45:58 UTC (rev 345) +++ branches/xmlunit-1.x/tests/java/org/custommonkey/xmlunit/test_Diff.java 2009-06-19 09:26:16 UTC (rev 346) @@ -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()); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |