ByteArrayOutputStream baos = new ByteArrayOutputStream();
//System.setOut(new PrintStream(baos, true));
// Run algorithm
project.getAlgo().runAlgorithm(0);
if (m_tester[0] instanceof RandomTester) {
RandomTester tester = (RandomTester) m_tester[0];
tester.setResetProbability(project.getResetProbability());
}
// Set up coverage matrix to check the test result
boolean[] bCoverage = project.getCoverageOption();
// Generate graph
if (bCoverage[0] || bCoverage[1] || bCoverage[2] || bCoverage[3])
m_tester[0].buildGraph();
CoverageMetric[] coverage = new CoverageMetric[COVERAGE_NUM];
if (bCoverage[0]) {
coverage[0] = new StateCoverage();
m_tester[0].addCoverageMetric(coverage[0]);
}
if (bCoverage[1]) {
coverage[1] = new TransitionCoverage();
m_tester[0].addCoverageMetric(coverage[1]);
}
if (bCoverage[2]) {
coverage[2] = new TransitionPairCoverage();
m_tester[0].addCoverageMetric(coverage[2]);
}
if (bCoverage[3]) {
coverage[3] = new ActionCoverage();
m_tester[0].addCoverageMetric(coverage[3]);
}
StringBuffer verbose = new StringBuffer();
StringWriter sw = new StringWriter();
if (project.getVerbosity()) {
VerboseListener vl = new VerboseListener();
m_tester[0].addListener(vl);
}
// We always want to see the tests drawn
m_tester[0].addListener(new VisualisationListener());
// Redirect model's output to string
Model md = m_tester[0].getModel();
Writer defWriter = md.getOutput();
md.setOutput(sw);
// This writer updates the test results panel.
// TODO: move this class into PanelResultViewer.
Writer newWriter = new Writer() {
@Override
public void close() throws IOException {
}
@Override
public void flush() throws IOException {
}
@Override
public void write(char[] cbuf, int off, int len) throws IOException {
StringBuffer str = new StringBuffer();
for (int i = off; i < off + len; i++) {
str.append(cbuf[i]);
}
gui.getResultViewer().updateRunTimeInformation(str.toString());
}
};
md.setOutput(newWriter);
for (int i = 0; i < COVERAGE_NUM; i++) {
if (bCoverage[i])
coverage[i].clear();
}
if (m_tester[0] instanceof QuickTester) {
QuickTester tester = (QuickTester) m_tester[0];
tester.clear();
}
// Generate tests
//System.err.println("Generating " + project.getWalkLength() + " tests with " + m_tester[0]);
m_tester[0].generate(project.getWalkLength());