in java/src/org/apache/qetest/xsl/XHTComparator.java [228:408]
boolean diff(Node gold, Node test, PrintWriter reporter,
boolean[] warning)
{
String name1 = gold.getNodeName();
String name2 = test.getNodeName();
// If both there but not equal, fail
if ((null != name1) && (null != name2) &&!name1.equals(name2))
{
reporter.println(MISMATCH_NODE + nodeTypeString(gold) + SEPARATOR
+ nodeTypeString(test) + SEPARATOR
+ "name does not equal test node");
return false;
}
else if ((null != name1) && (null == name2))
{
reporter.println(MISSING_TEST_NODE + nodeTypeString(gold)
+ SEPARATOR + nodeTypeString(test) + SEPARATOR
+ "name missing on test");
return false;
}
else if ((null == name1) && (null != name2))
{
reporter.println(MISSING_GOLD_NODE + nodeTypeString(gold)
+ SEPARATOR + nodeTypeString(test) + SEPARATOR
+ "name missing on gold");
return false;
}
String value1 = gold.getNodeValue();
String value2 = test.getNodeValue();
if ((null != value1) && (null != value2) &&!value1.equals(value2))
{
reporter.println(MISMATCH_VALUE + nodeTypeString(gold) + "len="
+ value1.length() + SEPARATOR
+ nodeTypeString(test) + "len=" + value2.length()
+ SEPARATOR + "values do not match");
printNodeDiff(gold, test, reporter);
return false;
}
else if ((null != value1) && (null == value2))
{
reporter.println(MISSING_TEST_VALUE + nodeTypeString(gold) + "-"
+ value1 + SEPARATOR + nodeTypeString(test)
+ SEPARATOR + "test no value");
return false;
}
else if ((null == value1) && (null != value2))
{
reporter.println(MISSING_GOLD_VALUE + nodeTypeString(gold)
+ SEPARATOR + nodeTypeString(test) + "-" + value2
+ SEPARATOR + "gold no value");
return false;
}
switch (gold.getNodeType())
{
case Node.DOCUMENT_NODE :
{
// Why don't we do anything here? -sc
}
break;
case Node.ELEMENT_NODE :
{
// Explicitly ignore attribute ordering
// TODO do we need to make this settable for testing purposes? -sc
NamedNodeMap goldAttrs = gold.getAttributes();
NamedNodeMap testAttrs = test.getAttributes();
if ((null != goldAttrs) && (null == testAttrs))
{
reporter.println(MISMATCH_ATTRIBUTE + nodeTypeString(gold)
+ SEPARATOR + nodeTypeString(test) + SEPARATOR
+ "test no attrs");
return false;
}
else if ((null == goldAttrs) && (null != testAttrs))
{
reporter.println(MISMATCH_ATTRIBUTE + nodeTypeString(gold)
+ SEPARATOR + nodeTypeString(test) + SEPARATOR
+ "gold no attrs");
return false;
}
int gn = goldAttrs.getLength();
int tn = testAttrs.getLength();
if (gn != tn)
{
reporter.println(MISMATCH_ATTRIBUTE + nodeTypeString(gold)
+ "-" + gn + SEPARATOR + nodeTypeString(test)
+ "-" + tn + SEPARATOR
+ "attribte count mismatch");
// TODO: add output of each set of attrs for comparisons
return false;
}
// TODO verify this checks the full list of attributes both ways,
// from gold->test and from test->gold -sc
for (int i = 0; i < gn; i++)
{
Attr goldAttr = (Attr) goldAttrs.item(i);
String goldAttrName = goldAttr.getName();
Node testAttr = testAttrs.getNamedItem(goldAttrName);
if (null == testAttr)
{
reporter.println(MISMATCH_ATTRIBUTE + nodeTypeString(gold)
+ "-" + goldAttrName + SEPARATOR
+ nodeTypeString(test) + SEPARATOR
+ "missing attribute on test");
return false;
}
if (!diff(goldAttr, testAttr, reporter, warning))
{
return false;
}
}
}
break;
case Node.CDATA_SECTION_NODE :{}
break;
case Node.ENTITY_REFERENCE_NODE :{}
break;
case Node.ATTRIBUTE_NODE :{}
break;
case Node.COMMENT_NODE :{}
break;
case Node.ENTITY_NODE :{}
break;
case Node.NOTATION_NODE :{}
break;
case Node.PROCESSING_INSTRUCTION_NODE :{}
break;
case Node.TEXT_NODE :{}
break;
default :{}
}
Node try2[] = new Node[2];
Node goldChild = gold.getFirstChild();
Node testChild = test.getFirstChild();
if (!basicChildCompare(goldChild, testChild, reporter, warning, try2))
return false;
goldChild = try2[0];
testChild = try2[1];
while (null != goldChild)
{
if (!diff(goldChild, testChild, reporter, warning))
return false;
goldChild = goldChild.getNextSibling();
testChild = testChild.getNextSibling();
if (!basicChildCompare(goldChild, testChild, reporter, warning,
try2))
return false;
goldChild = try2[0];
testChild = try2[1];
}
return true;
} // end of diff()