From: <bo...@us...> - 2010-09-03 08:42:00
|
Revision: 456 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=456&view=rev Author: bodewig Date: 2010-09-03 08:41:54 +0000 (Fri, 03 Sep 2010) Log Message: ----------- match tracker tests for NewDifferenceEngine Modified Paths: -------------- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-02 14:01:57 UTC (rev 455) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_DetailedDiff.java 2010-09-03 08:41:54 UTC (rev 456) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001-2008, Jeff Martin, Tim Bacon +Copyright (c) 2001-2008,2010 Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -128,9 +128,6 @@ assertEquals(1402 + unmatchedNodes, differencesWithWhitespace.getAllDifferences().size()); - } finally { - XMLUnit.clearCompareUnmatched(); - } try { XMLUnit.setIgnoreWhitespace(true); @@ -138,7 +135,7 @@ new Diff(new FileReader(control), new FileReader(test)); DetailedDiff detailedDiff = new DetailedDiff(prototype); List differences = detailedDiff.getAllDifferences(); - int unmatchedNodes = 0; + unmatchedNodes = 0; for (Iterator iter = differences.iterator(); iter.hasNext();) { Difference d = (Difference) iter.next(); if (d.getId() == DifferenceConstants.CHILD_NODE_NOT_FOUND_ID) { @@ -190,6 +187,9 @@ } finally { XMLUnit.setIgnoreWhitespace(false); } + } finally { + XMLUnit.clearCompareUnmatched(); + } } @@ -317,7 +317,7 @@ } protected Diff buildDiff(String control, String test, - DifferenceEngine engine) throws Exception { + DifferenceEngineContract engine) throws Exception { return new DetailedDiff(super.buildDiff(control, test, engine)); } Modified: trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java =================================================================== --- trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-02 14:01:57 UTC (rev 455) +++ trunk/xmlunit/src/tests/java-legacy/org/custommonkey/xmlunit/test_Diff.java 2010-09-03 08:41:54 UTC (rev 456) @@ -488,7 +488,7 @@ } protected Diff buildDiff(String control, String test, - DifferenceEngine engine) throws Exception { + DifferenceEngineContract engine) throws Exception { return new Diff(XMLUnit.buildControlDocument(control), XMLUnit.buildTestDocument(test), engine); } @@ -792,7 +792,7 @@ public void testMatchTrackerSetViaEngine() throws Exception { final int[] count = new int[1]; - DifferenceEngine engine = + DifferenceEngineContract engine = new DifferenceEngine(new ComparisonController() { public boolean haltComparison(Difference afterDifference) { fail("haltComparison invoked"); @@ -817,7 +817,7 @@ } public void testMatchTrackerSetViaOverrideOnEngine() throws Exception { - DifferenceEngine engine = + DifferenceEngineContract engine = new DifferenceEngine(new ComparisonController() { public boolean haltComparison(Difference afterDifference) { fail("haltComparison invoked"); @@ -843,6 +843,61 @@ assertEquals(12, count[0]); } + public void testMatchTrackerSetViaNewEngine() throws Exception { + final int[] count = new int[1]; + DifferenceEngineContract engine = + new NewDifferenceEngine(new ComparisonController() { + public boolean haltComparison(Difference afterDifference) { + fail("haltComparison invoked"); + // NOTREACHED + return false; + } + }, new MatchTracker() { + public void matchFound(Difference d) { + count[0]++; + } + }); + Diff diff = buildDiff("<foo/>", "<foo/>", engine); + assertTrue(diff.identical()); + // NODE_TYPE(Document), NAMESPACE_URI(none), + // NAMESPACE_PREFIX(none), NUMBER_OF_CHILDREN(1) + // HAS_DOCTYPE_DECLARATION(no), CHILD_NODE_SEQUENCE(0) + // + // NODE_TYPE(Element), NAMESPACE_URI(none), + // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), + // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) + assertEquals(14, count[0]); + } + + public void testMatchTrackerSetViaOverrideOnNewEngine() throws Exception { + DifferenceEngineContract engine = + new NewDifferenceEngine(new ComparisonController() { + public boolean haltComparison(Difference afterDifference) { + fail("haltComparison invoked"); + // NOTREACHED + return false; + } + }); + Diff diff = buildDiff("<foo/>", "<foo/>", engine); + final int[] count = new int[1]; + diff.overrideMatchTracker(new MatchTracker() { + public void matchFound(Difference d) { + count[0]++; + } + }); + assertTrue(diff.identical()); + // NODE_TYPE(Document), NAMESPACE_URI(none), + // NAMESPACE_PREFIX(none), NUMBER_OF_CHILDREN(1) + // HAS_DOCTYPE_DECLARATION(no), CHILD_NODE_SEQUENCE(0) + // + // NODE_TYPE(Element), NAMESPACE_URI(none), + // NAMESPACE_PREFIX(none), HAS_CHILD_NODES(false), + // ELEMENT_TAG_NAME(foo), ELEMENT_NUM_ATTRIBUTE(none), + // SCHEMA_LOCATION(none), NO_NAMESPACE_SCHEMA_LOCATION(none) + assertEquals(14, count[0]); + } + public void testCDATAAndIgnoreWhitespace() throws Exception { String control = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Data><Person><Name><![CDATA[JOE]]></Name></Person></Data>"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |