in java/src/org/apache/qetest/xsl/XHTFileCheckService.java [94:219]
public int check(Logger logger, Object actual, Object reference,
String msg, String id)
{
// Create our 'extended info' stuff now, so it will
// always reflect the most recent call to this method
sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
if (((null == actual) || (null == reference )))
{
pw.println("XHTFileCheckService actual or reference was null!");
pw.flush();
logFileCheckElem(logger, "null", "null", msg, id, sw.toString());
logger.checkErr(msg, id);
return logger.ERRR_RESULT;
}
if (!((actual instanceof File) & (reference instanceof File)))
{
// Must have File objects to continue
pw.println("XHTFileCheckService only takes File objects!");
pw.flush();
logFileCheckElem(logger, actual.toString(), reference.toString(), msg, id, sw.toString());
logger.checkErr(msg, id);
return logger.ERRR_RESULT;
}
File actualFile = (File) actual;
File referenceFile = (File) reference;
// Fail if Actual file doesn't exist or is 0 len
if ((!actualFile.exists()) || (actualFile.length() == 0))
{
pw.println("actual(" + actualFile.toString() + ") did not exist or was 0 len");
pw.flush();
logFileCheckElem(logger, actualFile.toString(), referenceFile.toString(), msg, id, sw.toString());
logger.checkFail(msg, id);
return logger.FAIL_RESULT;
}
// Ambiguous if gold file doesn't exist or is 0 len
if ((!referenceFile.exists()) || (referenceFile.length() == 0))
{
pw.println("reference(" + referenceFile.toString() + ") did not exist or was 0 len");
pw.flush();
logFileCheckElem(logger, actualFile.toString(), referenceFile.toString(), msg, id, sw.toString());
logger.checkAmbiguous(msg, id);
return Logger.AMBG_RESULT;
}
boolean warning[] = new boolean[1];
warning[0] = false;
boolean isEqual = false;
// Inefficient code to get around very rare spurious exception:
// java.io.IOException: The process cannot access the file because it is being used by another process
// at java.io.Win32FileSystem.canonicalize(Native Method)
// at java.io.File.getCanonicalPath(File.java:442)
// at org.apache.qetest.xsl.XHTFileCheckService.check(XHTFileCheckService.java:181)
// So get filenames first separately, then call comparator
String referenceFileName = referenceFile.getAbsolutePath();
String actualFileName = actualFile.getAbsolutePath();
try
{
referenceFileName = referenceFile.getCanonicalPath();
// Occasional spurious exception happens here, perhaps
// because sometimes the previous transform or whatever
// hasn't quite closed the actualFile yet
actualFileName = actualFile.getCanonicalPath();
}
catch (Exception e) { /* no-op, ignore */ }
try
{
// Note calling order (gold, act) is different than checkFiles()
isEqual = comparator.compare(referenceFileName,
actualFileName, pw,
warning, attributes);
// Side effect: fills in pw/sw with info about the comparison
}
catch (Throwable t)
{
// Add any exception info to pw/sw; this will automatically
// get logged out later on via logFileCheckElem
pw.println("XHTFileCheckService threw: " + t.toString());
t.printStackTrace(pw);
isEqual = false;
}
// If not equal at all, fail
if (!isEqual)
{
pw.println("XHTFileCheckService files were not equal");
pw.flush();
logFileCheckElem(logger, actualFile.toString(), referenceFile.toString(), msg, id, sw.toString());
logger.checkFail(msg, id);
return Logger.FAIL_RESULT;
}
// If whitespace-only diffs, then pass/fail based on allowWhitespaceDiff
else if (warning[0])
{
pw.println("XHTFileCheckService whitespace diff warning!");
pw.flush();
if (allowWhitespaceDiff)
{
logger.logMsg(Logger.STATUSMSG, "XHTFileCheckService whitespace diff warning, passing!");
logger.checkPass(msg, id);
return Logger.PASS_RESULT;
}
else
{
logFileCheckElem(logger, actualFile.toString(), referenceFile.toString(), msg, id,
"XHTFileCheckService whitespace diff warning, failing!\n" + sw.toString());
logger.checkFail(msg, id);
return Logger.FAIL_RESULT;
}
}
// Otherwise we were completely equal, so pass
else
{
pw.println("XHTFileCheckService files were equal");
pw.flush();
// For pass case, we *dont* call logFileCheckElem
logger.checkPass(msg, id);
return Logger.PASS_RESULT;
}
}