/**
* This method will only throw exceptions if some aspect
* of the test's internal operation fails.
*/
public TestReport runImpl() throws Exception {
DefaultTestReport report
= new DefaultTestReport(this);
InputStream inIS;
try {
inIS = in.openStream();
} catch(Exception e) {
StringWriter trace = new StringWriter();
e.printStackTrace(new PrintWriter(trace));
report.setErrorCode(ERROR_CANNOT_READ_IN_URL);
report.setDescription(new TestReport.Entry[] {
new TestReport.Entry
(TestMessages.formatMessage
(ENTRY_KEY_ERROR_DESCRIPTION, null),
TestMessages.formatMessage
(ERROR_CANNOT_READ_IN_URL,
new String[]{in.toString(), trace.toString()}))
});
report.setPassed(false);
return report;
}
if (action.equals("ROUND"))
this.ref = in;
else if (!action.equals("ENCODE") &&
!action.equals("DECODE")) {
report.setErrorCode(ERROR_BAD_ACTION_STRING);
report.setDescription(new TestReport.Entry[] {
new TestReport.Entry
(TestMessages.formatMessage
(ENTRY_KEY_ERROR_DESCRIPTION, null),
TestMessages.formatMessage(ERROR_BAD_ACTION_STRING,
new String[]{action}))
});
report.setPassed(false);
return report;
}
InputStream refIS;
try {
refIS = ref.openStream();
} catch(Exception e) {
StringWriter trace = new StringWriter();
e.printStackTrace(new PrintWriter(trace));
report.setErrorCode(ERROR_CANNOT_READ_REF_URL);
report.setDescription(new TestReport.Entry[] {
new TestReport.Entry
(TestMessages.formatMessage
(ENTRY_KEY_ERROR_DESCRIPTION, null),
TestMessages.formatMessage
(ERROR_CANNOT_READ_REF_URL,
new String[]{ref.toString(), trace.toString()}))
});
report.setPassed(false);
return report;
}
if (action.equals("ENCODE") ||
action.equals("ROUND")) {
// We need to encode the incomming data
PipedOutputStream pos = new PipedOutputStream();
OutputStream os = new Base64EncoderStream(pos);
// Copy the input to the Base64 Encoder (in a seperate thread).
Thread t = new StreamCopier(inIS, os);
// Read that from the piped output stream.
inIS = new PipedInputStream(pos);
t.start();
}
if (action.equals("DECODE")||
action.equals("ROUND")) {
inIS = new Base64DecodeStream(inIS);
}
int mismatch = compareStreams(inIS, refIS, action.equals("ENCODE"));
if (mismatch == -1) {
report.setPassed(true);
return report;
}
report.setErrorCode(ERROR_WRONG_RESULT);
report.setDescription(new TestReport.Entry[] {
new TestReport.Entry
(TestMessages.formatMessage(ENTRY_KEY_ERROR_DESCRIPTION, null),
TestMessages.formatMessage(ERROR_WRONG_RESULT,
new String[]{""+mismatch}))
});
report.setPassed(false);
return report;
}