using Runnable to comply to the SWT threading model.
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / XMLReportHandler.java
index 84ead73..2f8b5aa 100644 (file)
@@ -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") {
+                       });                     
                        
                }