From c6c327fe7deb74cb87c9e5f3e4e6f48b8e72e0b2 Mon Sep 17 00:00:00 2001 From: shleh Date: Sun, 25 Jul 2004 06:07:10 +0000 Subject: [PATCH 1/1] using Runnable to comply to the SWT threading model. --- .../phpeclipse/phpunit/ConnectionListener.java | 12 +++- .../phpeclipse/phpunit/PHPUnitView.java | 66 ++++++++++++++++---- .../phpeclipse/phpunit/ReportListener.java | 7 +- .../phpeclipse/phpunit/XMLReportHandler.java | 64 ++++++++++++------- 4 files changed, 108 insertions(+), 41 deletions(-) diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ConnectionListener.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ConnectionListener.java index e947753..30a711d 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ConnectionListener.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ConnectionListener.java @@ -19,6 +19,14 @@ public class ConnectionListener extends Thread { private ServerSocket sSocket = null; private Socket serviceSocket = null; + private PHPUnitView view; + + + public void start(PHPUnitView view) { + + this.view = view; + super.start(); + } public void run() { @@ -31,7 +39,7 @@ public class ConnectionListener extends Thread { // accept connection from test reporter. serviceSocket = sSocket.accept(); - (new ReportListener(serviceSocket)).start(); + (new ReportListener(serviceSocket, this.view)).start(); sSocket.close(); @@ -45,7 +53,7 @@ public class ConnectionListener extends Thread { public static void main(String[] args) { - (new ConnectionListener()).start(); + (new ConnectionListener()).start(new PHPUnitView()); } } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java index 341c218..bc1dd6a 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/PHPUnitView.java @@ -134,22 +134,22 @@ public class PHPUnitView extends ViewPart { //for now: - reportArea.append("test passed \n"); + reportArea.append("test : " + testID + " passed \n"); } public void markTestStarted(String testID) { - reportArea.append("test started \n"); + reportArea.append("test started: " + testID + " \n"); } public void createNewTest(String testName, String testID) { - reportArea.append("new test: " + testName + " - testID \n"); + reportArea.append("new test: " + testName + " - testID " + testID + " \n"); } public void markTestFail(String testID) { - reportArea.append("test failed \n"); + reportArea.append("test " + testID + " failed \n"); } public void markTestingFinished() { @@ -175,12 +175,15 @@ public class PHPUnitView extends ViewPart { } + /** + * + */ private void listenForReports() { ConnectionListener conListener = new ConnectionListener(); - conListener.start(); + conListener.start(this); } //end of method @@ -188,22 +191,61 @@ public class PHPUnitView extends ViewPart { * handle this report: test passed, faile, end of all. * @param report */ - private void handleReport(String report) { - - reportArea.append("msg: " + report + "\n"); - - String event = report.substring(0, report.indexOf(" ")); - - System.out.println(event); + public void handleReport(String report) { + //delegate to the XML report handler. + //reportArea.append("msg: " + report + "\n"); handler.handle(report, this); } + /** + * @param command + * @param testCount + * @param testID + */ public void handleCommand(String command, String testCount, String testID) { + + if (command.equals("testStarted")) { + + createNewTest("testName", testID); + markTestStarted(testID); + + } else if (command.equals("testFinished")) { + + + // do nothing wait for verdict + } else if (command.equals("endAll")) { + + markTestingFinished(); + } + + + } + + /** + * @param currentTestID + * @param verdict + */ + public void setTestVerdict(String currentTestID, String verdict) { + + if( verdict.equals("passed")) + markTestPassed(currentTestID); + else + markTestFail(currentTestID); + + + } + + /** + * @param currentTestID + * @param exception + */ + public void addTestException(String currentTestID, String exception) { + reportArea.append(" test " + currentTestID + " exception: " + exception + "\n"); } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ReportListener.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ReportListener.java index 035f48f..bb4686d 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ReportListener.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ReportListener.java @@ -8,9 +8,10 @@ import java.net.Socket; public class ReportListener extends Thread { Socket serviceSocket; + PHPUnitView view; - public ReportListener(Socket serviceSocket) { - + public ReportListener(Socket serviceSocket, PHPUnitView view) { + this.view = view; this.serviceSocket = serviceSocket; } @@ -30,7 +31,7 @@ public class ReportListener extends Thread { (report != "end_all_tests") ) { System.out.println("received something..."); - //handleReport(report); + view.handleReport(report); System.out.println(report); } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/XMLReportHandler.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/XMLReportHandler.java index 84ead73..2f8b5aa 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/XMLReportHandler.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/XMLReportHandler.java @@ -17,12 +17,17 @@ import org.xml.sax.helpers.DefaultHandler; public class XMLReportHandler extends DefaultHandler { - private PHPUnitView view; - + private String currentVerdict; + private PHPUnitView view; private String currentCommand; private String currentTestCount; private String currentTestID; + private void doAsyncRunnable(Runnable runnable) { + + view.getSite().getShell().getDisplay().asyncExec(runnable); + } + public void handle(String report, PHPUnitView view) { //TODO : how to parse directly a string? @@ -34,7 +39,7 @@ public class XMLReportHandler extends DefaultHandler { try { - File file = new File("tmp2.xml"); + File file = new File("tmp3.xml"); FileOutputStream out = null; FileInputStream in = null; out = new FileOutputStream(file); @@ -92,40 +97,51 @@ public class XMLReportHandler extends DefaultHandler { System.out.println(arg0 + " - " + arg1 + " - " + elementName); - if(elementName == "report") { + if(elementName.equals("report")) { currentCommand = attributes.getValue("command"); currentTestCount = attributes.getValue("testCount"); currentTestID = attributes.getValue("testID"); - //view.handleCommand(currentCommand, currentTestCount, currentTestID); - - if (currentCommand == "testStarted") { - - //view.createNewTest("testName", currentTestID); - //view.markTestStarted(currentTestID); - - } else if (currentCommand == "testFinished") { + doAsyncRunnable(new Runnable() { - // do nothing wait for verdict - } else if (currentCommand == "endAll") { + public void run() { + + view.handleCommand(currentCommand, currentTestCount, currentTestID); + } + + }); + + } else if (elementName.equals("verdict")) { + + currentVerdict = attributes.getValue("desc"); + //view.setTestVerdict(currentTestID, currentVerdict); + + doAsyncRunnable(new Runnable() { - //view.markTestingFinished(); - } + public void run() { + + view.setTestVerdict(currentTestID, currentVerdict); + } - } else if (elementName == "verdict") { + }); + + } else if (elementName.equals("exceptions")) { - String verdict = attributes.getValue("desc"); + //do nothing -// if( verdict == "passed") -// view.markTestPassed(currentTestID); -// else -// view.markTestFail(currentTestID); + } else if (elementName.equals("exception")) { - } else if (elementName == "exceptions") { + final String exception = attributes.getValue("desc"); + doAsyncRunnable(new Runnable() { + + public void run() { + + view.addTestException(currentTestID, exception); + } - } else if (elementName == "exception") { + }); } -- 1.7.1