From: <bo...@us...> - 2010-09-02 10:59:49
|
Revision: 452 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=452&view=rev Author: bodewig Date: 2010-09-02 10:59:43 +0000 (Thu, 02 Sep 2010) Log Message: ----------- handle CDATA/Text comparisons inside NewDifferenceEngine like it is done in legacy's DifferenceEngine - i.e. hide the difference from listeners completely Modified Paths: -------------- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-08-31 16:32:41 UTC (rev 451) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/NewDifferenceEngine.java 2010-09-02 10:59:43 UTC (rev 452) @@ -42,6 +42,7 @@ import net.sf.xmlunit.diff.Comparison; import net.sf.xmlunit.diff.ComparisonListener; import net.sf.xmlunit.diff.ComparisonResult; +import net.sf.xmlunit.diff.ComparisonType; import net.sf.xmlunit.diff.DOMDifferenceEngine; import net.sf.xmlunit.diff.DifferenceEvaluator; import net.sf.xmlunit.diff.DifferenceEvaluators; @@ -292,6 +293,31 @@ } } + private static final Short TEXT_TYPE = Short.valueOf(Node.TEXT_NODE); + private static final Short CDATA_TYPE = + Short.valueOf(Node.CDATA_SECTION_NODE); + + private static boolean swallowComparison(Comparison comparison, + ComparisonResult outcome) { + if (outcome == ComparisonResult.EQUAL) { + return true; + } + if (XMLUnit.getIgnoreDiffBetweenTextAndCDATA() + && comparison.getType() == ComparisonType.NODE_TYPE) { + return ( + TEXT_TYPE.equals(comparison.getControlDetails().getValue()) + || + CDATA_TYPE.equals(comparison.getControlDetails().getValue()) + ) + && ( + TEXT_TYPE.equals(comparison.getTestDetails().getValue()) + || + CDATA_TYPE.equals(comparison.getTestDetails().getValue()) + ); + } + return false; + } + public static class ComparisonController2DifferenceEvaluator implements DifferenceEvaluator { private final ComparisonController cc; @@ -301,13 +327,14 @@ public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - if (outcome != ComparisonResult.EQUAL) { + if (!swallowComparison(comparison, outcome)) { Difference diff = toDifference(comparison); if (diff != null && cc.haltComparison(diff)) { return ComparisonResult.CRITICAL; } + return outcome; } - return outcome; + return ComparisonResult.EQUAL; } } @@ -336,7 +363,7 @@ public ComparisonResult evaluate(Comparison comparison, ComparisonResult outcome) { - if (outcome != ComparisonResult.EQUAL) { + if (!swallowComparison(comparison, outcome)) { Difference diff = toDifference(comparison); if (diff != null) { switch (dl.differenceFound(diff)) { @@ -351,8 +378,9 @@ return ComparisonResult.DIFFERENT; } } + return outcome; } - return outcome; + return ComparisonResult.EQUAL; } } } Modified: trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java 2010-08-31 16:32:41 UTC (rev 451) +++ trunk/xmlunit/src/main/java-legacy/org/custommonkey/xmlunit/XMLUnit.java 2010-09-02 10:59:43 UTC (rev 452) @@ -75,7 +75,7 @@ private static EntityResolver testEntityResolver = null; private static EntityResolver controlEntityResolver = null; private static NamespaceContext namespaceContext = null; - private static Boolean ignoreDiffBetweenTextAndCDATA = null; + private static boolean ignoreDiffBetweenTextAndCDATA = false; private static boolean ignoreComments = false; private static boolean normalize = false; private static boolean normalizeWhitespace = false; @@ -685,7 +685,7 @@ * document.</p> */ public static void setIgnoreDiffBetweenTextAndCDATA(boolean b) { - ignoreDiffBetweenTextAndCDATA = Boolean.valueOf(b); + ignoreDiffBetweenTextAndCDATA = b; getControlDocumentBuilderFactory().setCoalescing(b); getTestDocumentBuilderFactory().setCoalescing(b); } @@ -696,21 +696,10 @@ * @return false by default */ public static boolean getIgnoreDiffBetweenTextAndCDATA() { - return ignoreDiffBetweenTextAndCDATA == null ? false - : ignoreDiffBetweenTextAndCDATA.booleanValue(); + return ignoreDiffBetweenTextAndCDATA; } /** - * Whether CDATA sections and Text nodes should be considered the same. - * - * @return true by default - */ - public static boolean getExplicitIgnoreDiffBetweenTextAndCDATA() { - return ignoreDiffBetweenTextAndCDATA == null ? true - : ignoreDiffBetweenTextAndCDATA.booleanValue(); - } - - /** * Whether comments should be ignored. * * <p>The default value is false</p> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |