From: shleh Date: Fri, 17 Sep 2004 19:30:36 +0000 (+0000) Subject: First commit in a looooooong time. I had connectivity problems. X-Git-Url: http://secure.phpeclipse.com First commit in a looooooong time. I had connectivity problems. Using a testPool to show progress and test result info. Added icons... --- diff --git a/net.sourceforge.phpeclipse.phpunit/.classpath b/net.sourceforge.phpeclipse.phpunit/.classpath new file mode 100644 index 0000000..26a1867 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/.classpath @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse.phpunit/.project b/net.sourceforge.phpeclipse.phpunit/.project new file mode 100644 index 0000000..7c1262f --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/.project @@ -0,0 +1,39 @@ + + + net.sourceforge.phpeclipse.phpunit + + + org.eclipse.core.boot + org.eclipse.core.resources + org.eclipse.core.runtime + org.eclipse.ui + org.eclipse.ui.views + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + net.sourceforge.metrics.builder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + net.sourceforge.metrics.nature + + diff --git a/net.sourceforge.phpeclipse.phpunit/build.properties b/net.sourceforge.phpeclipse.phpunit/build.properties new file mode 100644 index 0000000..e07c485 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/build.properties @@ -0,0 +1,4 @@ +source.phpunit.jar = src/ +bin.includes = plugin.xml,\ + *.jar,\ + phpunit.jar diff --git a/net.sourceforge.phpeclipse.phpunit/icons/sample.gif b/net.sourceforge.phpeclipse.phpunit/icons/sample.gif new file mode 100644 index 0000000..34fb3c9 Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/sample.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/test.gif b/net.sourceforge.phpeclipse.phpunit/icons/test.gif new file mode 100644 index 0000000..8f73ccb Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/test.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/testerr.gif b/net.sourceforge.phpeclipse.phpunit/icons/testerr.gif new file mode 100644 index 0000000..f866a2e Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/testerr.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/testfail.gif b/net.sourceforge.phpeclipse.phpunit/icons/testfail.gif new file mode 100644 index 0000000..de59bac Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/testfail.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/testok.gif b/net.sourceforge.phpeclipse.phpunit/icons/testok.gif new file mode 100644 index 0000000..f824bd8 Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/testok.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/tsuite.gif b/net.sourceforge.phpeclipse.phpunit/icons/tsuite.gif new file mode 100644 index 0000000..5198579 Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/tsuite.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/tsuiteerror.gif b/net.sourceforge.phpeclipse.phpunit/icons/tsuiteerror.gif new file mode 100644 index 0000000..7cd107c Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/tsuiteerror.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/tsuitefail.gif b/net.sourceforge.phpeclipse.phpunit/icons/tsuitefail.gif new file mode 100644 index 0000000..d247a8f Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/tsuitefail.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/icons/tsuiteok.gif b/net.sourceforge.phpeclipse.phpunit/icons/tsuiteok.gif new file mode 100644 index 0000000..e3db1eb Binary files /dev/null and b/net.sourceforge.phpeclipse.phpunit/icons/tsuiteok.gif differ diff --git a/net.sourceforge.phpeclipse.phpunit/plugin.xml b/net.sourceforge.phpeclipse.phpunit/plugin.xml index 8cdf02d..a86b87c 100644 --- a/net.sourceforge.phpeclipse.phpunit/plugin.xml +++ b/net.sourceforge.phpeclipse.phpunit/plugin.xml @@ -4,7 +4,7 @@ name="net.sourceforge.phpeclipse.phpunit" version="1.0.0" provider-name="Ali Echihabi" - class=""> + class="net.sourceforge.phpeclipse.phpunit.PHPUnitPlugin"> @@ -20,7 +20,7 @@ + id="net.sourceforge.phpeclipse.phpunit.PHPUnitView"> testsuite1->testcase->test_function */ - private int numTests; // total number of tests - private int numTestsRun; // number of tests run so far - private int numFailures; // number of failures so far - private int numErrors; // number of errors so far - private int numPasses; // number of passes so far (they should add up) + private static PHPUnitView view = null; private XMLReportHandler handler; - - - + private TestPool testPool; private Button startButton; private ProgressInfoComposite progressInfoComposite; private ResultsInfoComposite resultsInfoComposite; - private Group settingsInfoComposite; //TODO: move somewhere else, launcher, wizard or preferences. + private SettingsInfoComposite settingsInfoComposite; //TODO: move somewhere else, launcher, wizard or preferences. public PHPUnitView() { - handler = new XMLReportHandler(); - testPool = new TestPool(); + if(view == null) + view = this; } + + public static PHPUnitView getDefault() { + + + return view; + } public void createPartControl(Composite parent) { - parent.setLayout(new FillLayout(SWT.VERTICAL)); + //parent.setLayout(new FillLayout(SWT.VERTICAL)); + + GridLayout gridLayout = new GridLayout(); + gridLayout.numColumns = 1; + + // set title and layout + parent.setLayout(gridLayout); + //Launch ToolBar: setActions(); - //Build the progress info Composite s + //Build the progress info Composites progressInfoComposite = new ProgressInfoComposite(parent); + progressInfoComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING)); - + + //Build the result info composite resultsInfoComposite = new ResultsInfoComposite(parent); + resultsInfoComposite.setLayoutData(new GridData(GridData.GRAB_VERTICAL | GridData.FILL_BOTH)); //build the settings composite - buildSettingsComposite(parent); + //buildSettingsComposite(parent); + + settingsInfoComposite = new SettingsInfoComposite(parent, SWT.NONE); + startButton = new Button(parent, SWT.CENTER); startButton.setText("Start Tests"); @@ -104,12 +129,20 @@ public class PHPUnitView extends ViewPart { public void mouseDown(MouseEvent arg0) { - startTests(); + } public void mouseUp(MouseEvent arg0) { + try { + String testFile = settingsInfoComposite.getTestSuite(); + startTests(testFile); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } }); // end add action listener. @@ -122,8 +155,8 @@ public class PHPUnitView extends ViewPart { private void buildSettingsComposite(Composite parent) { - settingsInfoComposite = new Group(parent, SWT.NONE); -// settingsInfoComposite.setText("Settings"); + //settingsInfoComposite = new Group(parent, SWT.NONE); + //settingsInfoComposite.setText("Settings"); // settingsInfoComposite.setLayout(new GridLayout(2,false)); // // @@ -138,9 +171,7 @@ public class PHPUnitView extends ViewPart { // phpPathLabel.setText("php Path:"); // //testSuiteLabel.setLayoutData(new GridData()) // Text phpPathText = new Text(settingsInfoComposite, SWT.NONE); - - } private void setActions() { @@ -180,41 +211,41 @@ public class PHPUnitView extends ViewPart { * * @param testID */ - public void markTestPassed(String testID) { + private void markTestPassed(String testID) { // testid, use it in hashmap to retrieve tree item of test and // change icon color, increment pass counter, etc... - testPool.getTest(testID).setVerdict(Test.PASS); + testPool.getTest(testID).setVerdict(TestCase.PASS); } - public void markTestStarted(String testID) { + private void markTestStarted(String testID) { } - public void createNewTest(String testName, String testID) { + private void createNewTest(String testName, String testID) { - testPool.addTest(new Test(testName, testID)); + testPool.addTest(new TestCase(testName, testID)); } - public void markTestFail(String testID) { - numFailures++; - testPool.getTest(testID).setVerdict(Test.FAIL); + private void markTestFail(String testID) { + + testPool.getTest(testID).setVerdict(TestCase.FAIL); } - public void markTestingStarted(int numTestsToBeRun) { + private void markTestingStarted(int numTestsToBeRun) { + - this.numTests = numTestsToBeRun; //reportArea.append("Tests started expecting: " + numTests + " \n"); } - public void markTestingFinished() { + private void markTestingFinished() { //reportArea.append("end all tests \n"); @@ -222,25 +253,107 @@ public class PHPUnitView extends ViewPart { } // action to start tests: - private void startTests() { + public void startTests() throws IOException { + +// // 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. +// +// testPool = new TestPool("RUN MONDAY 11:15 PM"); +// listenForReports(); +// +// try { +// Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\""); +// } catch (Exception e) { +// +// e.printStackTrace(); +// } + + startTests("C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php"); + + } + + public void startTests(String testSuite) throws IOException { + + //testSuite: the name of the file containing the suite we want to run. + // we will put that test suite inside a contained that uses our SocketResult. + + + //reset from previous run + reset(); + + //where the plugin's temp files should go + String tempFolder = "C:\\tmp"; + String tempFileName = "temTest.php"; + + //create the file. + File testFile = new File(tempFolder + "/" + tempFileName); + BufferedWriter out = new BufferedWriter(new FileWriter(testFile)); + + out.write("addTest(new TestSuite(\"" + testSuiteName + "\"));" + "\n"); + + + + //out.write("$suite->addTest(new TestSuite(\"MoreTesterTests\"));" + "\n"); + + //out.write("$suite->addTest(new TestSuite(\"ManyFailingTests\"));" + "\n"); + //out.write("$suite->addTest(new TestSuite(\"AssertEqualsTests\"));" + "\n"); + + out.write("$result = new SocketTestResult();" + "\n"); + out.write("$suite->run($result);" + "\n"); + out.write("$result->report(); " + "\n"); + out.write("" + "\n"); + out.write("" + "\n"); + + out.write("?>" + "\n"); + + out.flush(); + out.close(); listenForReports(); try { - Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\""); - } catch (IOException e) { - // TODO Auto-generated catch block + Runtime.getRuntime().exec("php.exe " + tempFolder + "/" + tempFileName); + } catch (Exception e) { + e.printStackTrace(); } + + //testFile.delete(); + + } + /** + * + */ + private void reset() { + + handler = new XMLReportHandler(); + testPool = new TestPool("Ali Baba"); + + progressInfoComposite.resetInfo(); + resultsInfoComposite.resetInfo(); + } /** @@ -281,9 +394,14 @@ public class PHPUnitView extends ViewPart { markTestingStarted(new Integer(testCount).intValue()); - }else if (command.equals("testStarted")) { + } else if (command.equals("testSuiteStarted")) { + + createNewTestSuite("TestSuiteName: " + testID, testID, new Integer(testCount).intValue()); + markTestSuiteStarted(testID); + + } else if (command.equals("testStarted")) { - createNewTest("testName", testID); + createNewTest("TestName: " + testID, testID); markTestStarted(testID); } else if (command.equals("testFINISHED")) { @@ -295,10 +413,42 @@ public class PHPUnitView extends ViewPart { markTestingFinished(); } + + update(); + - progressInfoComposite.updateInfo(numTests, numTestsRun, numFailures, numErrors); + + } + + /** + * + */ + private void update() { + + //progressInfoComposite.updateInfo(numTests, testPool.getNumTestsRun(), numFailures, numErrors); + progressInfoComposite.updateInfo(testPool); resultsInfoComposite.updateInfo(testPool); + + } + + /** + * @param testID + */ + private void markTestSuiteStarted(String testID) { + // TODO Auto-generated method stub + + } + /** + * @param string + * @param testID + * @param testCount + */ + private void createNewTestSuite(String name, String testID, int testCount) { + + TestSuite suite = new TestSuite(name, testID, testCount); + testPool.addTestSuite(suite); + } /** @@ -306,7 +456,6 @@ public class PHPUnitView extends ViewPart { */ private void markTestFinished() { - numTestsRun++; } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ProgressInfoComposite.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ProgressInfoComposite.java index 7d779e4..3781fde 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ProgressInfoComposite.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ProgressInfoComposite.java @@ -6,6 +6,8 @@ */ package net.sourceforge.phpeclipse.phpunit; +import net.sourceforge.phpeclipse.phpunit.testpool.TestPool; + import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -74,13 +76,21 @@ public class ProgressInfoComposite extends Composite { labelErrorsVal.setText("0"); } + public void resetInfo() { + + labelErrorsVal.setText("0"); + labelFailuresVal.setText("0"); + labelRunsVal.setText("0 / 0"); + progressBar.setSelection(0); + + } + public void updateInfo(int numTests, int numTestsRun, int numFailures, int numErrors) { //update progress bar progressBar.setMaximum(numTests); progressBar.setSelection(numTestsRun); - - System.out.println("numTestsRun: " + numTestsRun); + //update labels labelRunsVal.setText(numTestsRun + " / " + numTests); @@ -93,4 +103,26 @@ public class ProgressInfoComposite extends Composite { } + + public void updateInfo(TestPool testPool) { + + int numTestsOverall = testPool.getNumTestsOverall(); + int numTestsRun = testPool.getNumTestsRun(); + + //update progress bar + progressBar.setMaximum(numTestsOverall); + progressBar.setSelection(numTestsRun); + + + //update labels + labelRunsVal.setText(numTestsRun + " / " + numTestsOverall); + labelFailuresVal.setText("" + testPool.getNumFailures()); + labelErrorsVal.setText("" + testPool.getNumErrors()); + + //TODO: change Failures label to red if some exist. + + + + } + } 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 bb4686d..a26ec25 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 @@ -30,9 +30,9 @@ public class ReportListener extends Thread { while ( (report = in.readLine()) != null && (report != "end_all_tests") ) { - System.out.println("received something..."); + //System.out.println("received something..."); view.handleReport(report); - System.out.println(report); + //System.out.println(report); } //reportArea.append("Finished!"); diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ResultsInfoComposite.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ResultsInfoComposite.java index 8f50171..627da42 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ResultsInfoComposite.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/ResultsInfoComposite.java @@ -6,10 +6,13 @@ */ package net.sourceforge.phpeclipse.phpunit; +import net.sourceforge.phpeclipse.phpunit.testpool.TestPool; + +import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Text; /** * @author Ali Echihabi @@ -20,7 +23,8 @@ import org.eclipse.swt.widgets.Text; public class ResultsInfoComposite extends Composite { - private Text reportArea; // TODO: replace with Tree display like JUnit + + private TreeViewer treeViewer; /** * @param arg0 @@ -28,32 +32,38 @@ public class ResultsInfoComposite extends Composite { */ public ResultsInfoComposite(Composite parent) { - super(parent, SWT.NONE); + super(parent, SWT.BORDER); - setLayout(new FillLayout(SWT.VERTICAL)); + GridLayout layout = new GridLayout(); + layout.numColumns = 1; + + setLayout(layout); + + treeViewer = new TreeViewer(this, SWT.BORDER | SWT.SHADOW_ETCHED_IN); - reportArea = - new Text( - this, - SWT.MULTI - | SWT.BORDER - | SWT.WRAP - | SWT.V_SCROLL - | SWT.READ_ONLY); + treeViewer.getControl().setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_BOTH | GridData.GRAB_VERTICAL)); + + TestPoolLabelProvider labelProvider = new TestPoolLabelProvider(); + TestPoolContentProvider contentProvider= new TestPoolContentProvider(); + + treeViewer.setContentProvider(contentProvider); + treeViewer.setLabelProvider(labelProvider); + } + public void resetInfo() { + + treeViewer.setInput(null); + } public void updateInfo(TestPool testPool) { // take care of the TreeView and its content and label providers. + + treeViewer.setInput(testPool.getRoot()); } - - - - - } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/SettingsInfoComposite.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/SettingsInfoComposite.java new file mode 100644 index 0000000..1babb56 --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/SettingsInfoComposite.java @@ -0,0 +1,75 @@ +/* + * Created on Sep 11, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package net.sourceforge.phpeclipse.phpunit; + +import org.eclipse.swt.SWT; +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.FileDialog; + +/** + * @author Ali Echihabi + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class SettingsInfoComposite extends Composite { + + FileDialog dialog; + Button button; + + String testSuitePath; + + /** + * @param arg0 + * @param arg1 + */ + public SettingsInfoComposite(Composite parent, int style) { + + super(parent, style); + + dialog = new FileDialog(parent.getShell()); + + button = new Button(parent, SWT.NONE); + button.setText("Browser for test..."); + + button.addMouseListener(new MouseListener() { + public void mouseDoubleClick(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + public void mouseDown(MouseEvent arg0) { + + testSuitePath = dialog.open(); + System.out.println("file: " + testSuitePath); + + } + + public void mouseUp(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + }); + + + + + + } + + + public String getTestSuite() { + + return testSuitePath; + } + + + +} diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPool.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPool.java deleted file mode 100644 index a4ba019..0000000 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPool.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Created on Jul 31, 2004 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package net.sourceforge.phpeclipse.phpunit; - -import java.util.HashMap; - -/** - * @author Ali Echihabi - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class TestPool { - - private HashMap tests; - - public TestPool() { - - tests = new HashMap(); - } - - public void addTest(TestCase test) { - - tests.put(test.getTestID(), test); - - } - - public TestCase getTest(String testID) { - - return (TestCase) tests.get(testID); - } - -} diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPoolContentProvider.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPoolContentProvider.java new file mode 100644 index 0000000..96489da --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPoolContentProvider.java @@ -0,0 +1,91 @@ +/* + * Created on Aug 8, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package net.sourceforge.phpeclipse.phpunit; + +import java.util.Vector; + +import net.sourceforge.phpeclipse.phpunit.testpool.*; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * @author Ali Echihabi + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class TestPoolContentProvider implements ITreeContentProvider { + + + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) + */ + public Object[] getChildren(Object parentElement) { + + if(parentElement instanceof TestSuite) { + + Vector allChildren = new Vector(); + allChildren.addAll(((TestSuite)parentElement).getTestCases()); + allChildren.addAll(((TestSuite)parentElement).getTestSuites()); + + return allChildren.toArray(); + + } else { + return new Object[0]; + } + + + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object) + */ + public Object getParent(Object element) { + + if(element instanceof TestSuite) + return ((TestSuite)element).getParent(); + else if (element instanceof TestCase) + return ((TestCase)element).getParentSuite(); + else + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) + */ + public boolean hasChildren(Object element) { + + return getChildren(element).length > 0; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) + */ + public Object[] getElements(Object inputElement) { + + return getChildren(inputElement); + + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#dispose() + */ + public void dispose() { + + } + + /* (non-Javadoc) + * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // TODO Auto-generated method stub + + } + +} diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPoolLabelProvider.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPoolLabelProvider.java new file mode 100644 index 0000000..6977a6d --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestPoolLabelProvider.java @@ -0,0 +1,89 @@ +/* + * Created on Aug 8, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package net.sourceforge.phpeclipse.phpunit; + +import java.net.MalformedURLException; +import java.net.URL; + +import net.sourceforge.phpeclipse.phpunit.testpool.TestCase; +import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + +/** + * @author Ali Echihabi + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class TestPoolLabelProvider extends LabelProvider { + + //TODO: replace with installDir + path + private static String iconsPath = "C:\\Documents and Settings\\Ali Echihabi\\My Documents\\workspace.eclipse2.1\\net.sourceforge.phpeclipse.phpunit\\icons"; + + public String getText(Object element) { + + if(element instanceof TestSuite) + return ((TestSuite)element).getName(); + else if(element instanceof TestCase) + return ((TestCase)element).getTestName(); + else + return "UNKNOWN ELEMENT TYPE"; + + + + } + + public Image getImage(Object element) { + + Image image = null; + + try { + + String icon = ""; + if(element instanceof TestSuite) { + + TestSuite suite = (TestSuite)element; + + //TODO check if there has been an error, a failure... + + icon = "tsuite.gif"; + + } else if(element instanceof TestCase) { + + TestCase test = (TestCase)element; + + if(test.isError()) + icon = "testerr.gif"; + else if(test.isFailure()) + icon = "testfail.gif"; + else if(test.isPass()) + icon = "testok.gif"; + + } + + + ImageDescriptor descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon)); + image = descriptor.createImage(); + + } catch (MalformedURLException e) { + + e.printStackTrace(); + image = ImageDescriptor.getMissingImageDescriptor().createImage(); + } + + + + + + return image; + + } + +} diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestSuite.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestSuite.java deleted file mode 100644 index faced9d..0000000 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestSuite.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Created on Jul 31, 2004 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package net.sourceforge.phpeclipse.phpunit; - -import java.util.Vector; - -/** - * @author Ali Echihabi - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class TestSuite { - - private Vector testCases; - private String name; - private String id; - - public void addTestCase(TestCase test) { - - } - - public void removeTestCase(TestCase test) {} - - public boolean contains(TestCase test) { - return false; - } - - - -} diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/actions/RunTestsAction.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/actions/RunTestsAction.java index bfb6799..2e1c39c 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/actions/RunTestsAction.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/actions/RunTestsAction.java @@ -6,10 +6,17 @@ */ package net.sourceforge.phpeclipse.phpunit.actions; +import java.io.IOException; + +import net.sourceforge.phpeclipse.phpunit.PHPUnitView; + +import org.eclipse.core.resources.IFile; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Item; import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.navigator.ResourceNavigator; /** * @author Ali Echihabi @@ -19,19 +26,60 @@ import org.eclipse.ui.IWorkbenchPart; */ public class RunTestsAction implements IObjectActionDelegate { + + + /* (non-Javadoc) * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) */ public void setActivePart(IAction action, IWorkbenchPart targetPart) { // TODO Auto-generated method stub + System.out.println(targetPart.getTitle()); + ResourceNavigator nav = (ResourceNavigator)targetPart; + + Item selectedItem = nav.getViewer().getTree().getSelection()[0]; + + Object d = selectedItem.getData(); +// +// try { +// +// IFile data = (IFile) selectedItem.getData(); +// +// } +// catch(Exception e) { +// +// e.printStackTrace(); +// +// } +// + + + +// Shell shell = PHPUnitPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(); +// +// if(shell instanceof IStructuredSelection) { +// +// Object testObj = ((IStructuredSelection) ) +// } +// + + + } /* (non-Javadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { - // TODO Auto-generated method stub + + try { + PHPUnitView.getDefault().startTests(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestCase.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestCase.java similarity index 59% rename from net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestCase.java rename to net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestCase.java index beac173..7812b67 100644 --- a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/TestCase.java +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestCase.java @@ -4,7 +4,8 @@ * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ -package net.sourceforge.phpeclipse.phpunit; +package net.sourceforge.phpeclipse.phpunit.testpool; + /** * @author Ali Echihabi @@ -14,6 +15,15 @@ package net.sourceforge.phpeclipse.phpunit; */ public class TestCase { + public static final String PASS = "PASS"; + public static final String FAIL = "FAIL"; + public static final String ERROR = "ERROR"; + + + private TestSuite parentSuite; + + + /** * @param testName * @param testID @@ -24,9 +34,6 @@ public class TestCase { this.testID = testID; } - static final String PASS = "PASS"; - static final String FAIL = "PASS"; - static final String ERROR = "PASS"; String testName; String testID; @@ -72,6 +79,53 @@ public class TestCase { */ public void setVerdict(String string) { verdict = string; + + + + + + } + + /** + * @param suite + */ + public void setParentSuite(TestSuite suite) { + this.parentSuite = suite; + + } + + /** + * @return + */ + public Object getParentSuite() { + + return parentSuite; + } + + /** + * @return + */ + public boolean isError() { + + return getVerdict().equals(TestCase.ERROR); + } + + /** + * @return + */ + public boolean isFailure() { + + return getVerdict().equals(TestCase.FAIL); + + } + + /** + * @return + */ + public boolean isPass() { + + return getVerdict().equals(TestCase.PASS); + } } diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestPool.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestPool.java new file mode 100644 index 0000000..008cb3d --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestPool.java @@ -0,0 +1,180 @@ +/* + * Created on Jul 31, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package net.sourceforge.phpeclipse.phpunit.testpool; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Vector; + + +/** + * @author Ali Echihabi + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class TestPool { + + //private TestSuite currentParentTestSuite; + private HashMap tests; + private TestSuite root; + private TestSuite currentTestSuite; + + + /** + * + */ + public TestPool(String rootTitle) { + + tests = new HashMap(); + root = new TestSuite(rootTitle, "-1", 0); + + currentTestSuite = root; + + } + + /** + * @param test + */ + public void addTest(TestCase test) { + + tests.put(test.getTestID(), test); + + currentTestSuite.addTestCase(test); + + + //if we run all tests. then this is the end of this test suite. + if( currentTestSuite != root && currentTestSuite.isFinished()) { + + currentTestSuite = currentTestSuite.getParent(); + + } + + } + + /** + * @param suite + * @param numTestsRunSinceStartOfTestSuite + */ + public void addTestSuite(TestSuite suite) { + + //add as sibling + currentTestSuite.addTestSuite(suite); + suite.setParent(currentTestSuite); + + currentTestSuite = suite; + } + + /** + * @return + */ + public TestSuite getRoot() { + + return root; + } + + /** + * @param r + */ + public void setRoot(TestSuite r) { + this.root = r; + } + + + + /** + * @param testID + * @return + */ + public TestCase getTest(String testID) { + + return (TestCase) tests.get(testID); + } + + public String toString() { + + String string = ""; + + TestSuite node = root; + + string = root.toString(); + + return string; + + } + + private int countSuiteExpectedTests(TestSuite suite) { + + int total = 0; + + total += suite.getNumTestCasesExpected(); + + for(int i = 0; i < suite.getTestSuites().size(); i++) + total += countSuiteExpectedTests((TestSuite) suite.getTestSuites().elementAt(i)); + + return total; + + } + + public int getNumTestsOverall() { + + return countSuiteExpectedTests(root); + + } + + public int getNumTestsRun() { + + return tests.size(); + + + } + + public int getNumFailures() { + + int total = 0; + + Iterator i = tests.keySet().iterator(); + String key = ""; + while (i.hasNext()) { + + + key = (String) i.next(); + TestCase element = (TestCase) tests.get(key); + + + if(element.isFailure()) + total++; + + } + + return total; + } + + public int getNumErrors() { + + int total = 0; + +// Iterator i = tests.keySet().iterator(); +// String key = ""; +// while (i.hasNext()) { +// +// +// key = (String) i.next(); +// TestCase element = (TestCase) tests.get(key); +// +// if(element.isError()) +// total++; +// +// } + + return total; + + } + + + +} diff --git a/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestSuite.java b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestSuite.java new file mode 100644 index 0000000..9d565da --- /dev/null +++ b/net.sourceforge.phpeclipse.phpunit/src/net/sourceforge/phpeclipse/phpunit/testpool/TestSuite.java @@ -0,0 +1,206 @@ +/* + * Created on Jul 31, 2004 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package net.sourceforge.phpeclipse.phpunit.testpool; + +import java.util.Vector; + +/** + * @author Ali Echihabi + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class TestSuite { + + + + private Vector testCases; // current or actual. + private Vector testSuites; // current or actual. + private String name; + private String id; + private int numTestCasesExpected; //expected + private int numTestCasesRunSoFar; + TestSuite parent; + + /** + * @param name + * @param testID + * @param testCount + */ + public TestSuite(String name, String testID, int testCount) { + + this.parent = null; + this.id = testID; + this.name = name; + this.numTestCasesExpected = testCount; + + testCases = new Vector(); + testSuites = new Vector(); + + } + + /** + * @param name + * @param testID + * @param testCount + */ + public TestSuite(TestSuite parent, String name, String testID, int testCount) { + + this.parent = parent; + this.id = testID; + this.name = name; + this.numTestCasesExpected = testCount; + + testCases = new Vector(); + testSuites = new Vector(); + } + + public void addTestCase(TestCase test) { + testCases.addElement(test); + test.setParentSuite(this); + numTestCasesRunSoFar++; + } + + public void removeTestCase(TestCase test) {} + + public boolean contains(TestCase test) { + + return false; + + } + + public String toString() { + + String string = ""; + + //print test cases. + TestCase tc = null; + for(int i = 0; i < testCases.size(); i++) { + + tc = (TestCase) testCases.elementAt(i); + string += " - " + tc.getTestID() + ", " + tc.getTestName() + "\n"; + + + } + + for(int i = 0; i < testSuites.size(); i++) + string += ((TestSuite) testSuites.elementAt(i)).toString(); + + //print its own test suites. + return string; + } + + /** + * @return + */ + public String getId() { + return id; + } + + /** + * @return + */ + public String getName() { + return name; + } + + /** + * @return + */ + public int getNumTestCasesExpected() { + return numTestCasesExpected; + } + + /** + * @param string + */ + public void setId(String string) { + id = string; + } + + /** + * @param string + */ + public void setName(String string) { + name = string; + } + + /** + * @param i + */ + public void setNumTestCasesExpected(int i) { + numTestCasesExpected = i; + } + + /** + * @param suite + */ + public void addTestSuite(TestSuite suite) { + testSuites.addElement(suite); + + } + + /** + * @return + */ + public boolean isFinished() { + + return numTestCasesRunSoFar >= numTestCasesExpected; + + } + + /** + * @return + */ + public TestSuite getParent() { + return parent; + } + + /** + * @param suite + */ + public void setParent(TestSuite suite) { + parent = suite; + } + + /** + * @return + */ + public int getNumTestCases() { + + return testCases.size(); + } + + /** + * @return + */ + public Vector getTestCases() { + return testCases; + } + + /** + * @return + */ + public Vector getTestSuites() { + return testSuites; + } + + /** + * @param vector + */ + public void setTestCases(Vector vector) { + testCases = vector; + } + + /** + * @param vector + */ + public void setTestSuites(Vector vector) { + testSuites = vector; + } + +}