3.x RC1 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse.phpunit / src / net / sourceforge / phpeclipse / phpunit / PHPUnitView.java
index 5d8e181..6510e34 100644 (file)
@@ -1,11 +1,28 @@
 package net.sourceforge.phpeclipse.phpunit;
 
 
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.ServerSocket;
+import java.net.Socket;
+
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ControlEvent;
+import org.eclipse.swt.events.ControlListener;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.part.ViewPart;
 
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
 /*
  * Created on May 22, 2004
  *
@@ -45,6 +62,9 @@ public class PHPUnitView extends ViewPart {
        Label labelErrors, labelErrorsVal;
        Label labelFailures, labelFailuresVal;
        
+       Text reportArea; // TODO: replace with Tree display like JUnit
+
+       Button startButton;
 
        public PHPUnitView() {
                
@@ -68,21 +88,128 @@ public class PHPUnitView extends ViewPart {
                labelErrorsVal = new Label(parent, SWT.WRAP);
                labelErrorsVal.setText("0");
 
+               reportArea = new Text(parent, SWT.MULTI | SWT.BORDER |
+               SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
+               
+               startButton = new Button(parent, SWT.CENTER);
+               startButton.setText("Start Tests");
+               startButton.addMouseListener( new MouseListener() {
+
+                       public void mouseDoubleClick(MouseEvent arg0) {
+                               // TODO Auto-generated method stub
+                               
+                       }
+
+                       public void mouseDown(MouseEvent arg0) {
+                               // TODO Auto-generated method stub
+                               startTests();
+                       }
+
+                       public void mouseUp(MouseEvent arg0) {
+                               // TODO Auto-generated method stub
+                               
+                       }
+
+
+                       
+                       
+                       }); // end add action listener.
+               
+               // TODO layout!
        }
 
        /* (non-Javadoc)
         * @see org.eclipse.ui.IWorkbenchPart#setFocus()
         */
        public void setFocus() {
-               
+               //markTestPass("hello");
        }
 
-
+       /**
+        * mark the given test as passed in the GUI.
+        * 
+        * @param testID
+        */
+       private void markTestPass(String testID) {
+               
+               // testid, use it in hashmap to retrieve tree item of test and
+               // change icon color, increment pass counter, etc...
+               
+               
+               //for now:
+               reportArea.append("test passed");
+       }
 
        
        
        
+       // action to start tests:
+       private void startTests() {
+               
+               // preparation:
+               // take the full test suite (could containt other test suites).
+               // create temp php file that starts that suite and uses socketTestReport 
+               // as a test result reporter.
+               // add listener: localhost , port 13579
+               // start listening at port.
+               
+               reportArea.append("Tests started \n");
+               listenForReports();
+               
+               
+               
+       }
        
+       private void listenForReports() {
+               
+               ServerSocket sSocket = null;
+               Socket serviceSocket = null;    
+               
+               try {
+                       
+                       reportArea.append("listening at port 12345");
+                       
+                       sSocket = new ServerSocket(12345);
+                       
+                       // accept connection from test reporter.
+                       serviceSocket = sSocket.accept();
+       
+               
+                       InputStreamReader reader = new InputStreamReader(serviceSocket.getInputStream());                       
+                       BufferedReader in = new BufferedReader(reader);
+                       String report = null;
+                       
+                       // keep listening until the 
+                       while ( (report = in.readLine()) != null && (report != "end_all_tests") ) {                     
+                               
+                               handleReport(report);                   
+                       }                       
+                       
+                       reportArea.append("Finished!");
+                       
+                       sSocket.close();
+                       serviceSocket.close();          
+                       
+               } catch (Exception e) {
+                       
+                       e.printStackTrace();
+                       
+               } 
+               
+               
+                               
+               
+       }
+       
+       /**
+        * handle this report: test passed, faile, end of all.
+        * @param report
+        */
+       private void handleReport(String report) {
+               
+               reportArea.append("msg: " + report + "\n");
+               
+       }
        
 
 }