--- /dev/null
+package net.sourceforge.phpeclipse.phpunit;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.swt.graphics.Image;
+
+public class PHPUnitImages {
+
+ protected static final String NAME_PREFIX =
+ "net.sourceforge.phpeclipse.phpunit";
+ protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
+
+ protected static URL iconBaseURL;
+
+ static {
+ String pathSuffix = "icons/";
+ try {
+ iconBaseURL =
+ new URL(
+ PHPUnitPlugin.getDefault().getDescriptor().getInstallURL(),
+ pathSuffix);
+ } catch (MalformedURLException e) {
+ //PHPUnitPlugin.log(e);
+ e.printStackTrace();
+ }
+ }
+
+ protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
+
+ /*
+ * Available cached Images in the Java plugin image registry.
+ */
+
+ public static final String IMG_SELECT_TEST_SUITE =
+ NAME_PREFIX + "tsuite.gif";
+ public static final String IMG_RUN_TEST_SUITE = NAME_PREFIX + "start.gif";
+ public static final String IMG_TEST_ERROR = NAME_PREFIX + "testerr.gif";
+ public static final String IMG_TEST_FAILURE = NAME_PREFIX + "testfail.gif";
+ public static final String IMG_TEST_PASS = NAME_PREFIX + "testok.gif";
+ public static final String IMG_TEST_SUITE_ERROR = NAME_PREFIX + "tsuiteerror.gif";
+ public static final String IMG_TEST_SUITE_PASS = NAME_PREFIX + "tsuiteok.gif";
+ public static final String IMG_TEST_SUITE_FAILURE = NAME_PREFIX + "tsuitefail.gif";
+
+
+
+
+ public static final ImageDescriptor DESC_SELECT_TEST_SUITE = createManaged(IMG_SELECT_TEST_SUITE);
+ public static final ImageDescriptor DESC_RUN_TEST_SUITE =createManaged(IMG_RUN_TEST_SUITE);
+ public static final ImageDescriptor DESC_TEST_ERROR = createManaged(IMG_TEST_ERROR);
+ public static final ImageDescriptor DESC_TEST_FAILURE = createManaged(IMG_TEST_FAILURE);
+ public static final ImageDescriptor DESC_TEST_PASS = createManaged(IMG_TEST_PASS);
+ public static final ImageDescriptor DESC_TEST_SUITE_ERROR = createManaged(IMG_TEST_SUITE_ERROR);
+ public static final ImageDescriptor DESC_TEST_SUITE_PASS = createManaged(IMG_TEST_SUITE_PASS);
+ public static final ImageDescriptor DESC_TEST_SUITE_FAILURE = createManaged(IMG_TEST_SUITE_FAILURE);
+
+ /**
+ * Returns the image managed under the given key in this registry.
+ *
+ * @param key the image's key
+ * @return the image managed under the given key
+ */
+ public static Image get(String key) {
+ return IMAGE_REGISTRY.get(key);
+ }
+
+ public static ImageRegistry getImageRegistry() {
+ return IMAGE_REGISTRY;
+ }
+
+ //---- Helper methods to access icons on the file system --------------------------------------
+
+ protected static ImageDescriptor createManaged(String name) {
+ try {
+ ImageDescriptor result =
+ ImageDescriptor.createFromURL(
+ makeIconFileURL(name.substring(NAME_PREFIX_LENGTH)));
+ IMAGE_REGISTRY.put(name, result);
+ return result;
+ } catch (MalformedURLException e) {
+ return ImageDescriptor.getMissingImageDescriptor();
+ }
+ }
+
+ protected static URL makeIconFileURL(String name)
+ throws MalformedURLException {
+ if (iconBaseURL == null)
+ throw new MalformedURLException();
+
+ return new URL(iconBaseURL, name);
+ }
+}
\ No newline at end of file
*/
package net.sourceforge.phpeclipse.phpunit;
-import java.net.MalformedURLException;
-import java.net.URL;
import java.util.ResourceBundle;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.plugin.AbstractUIPlugin;
private static PHPUnitPlugin plugin;
private ResourceBundle resourceBundle;
-
+ public static final String PLUGIN_ID= "net.sourceforge.phpeclipse.phpunit"; //$NON-NLS-1$
/**
* @param descriptor
*/
public PHPUnitPlugin(IPluginDescriptor descriptor) {
+
super(descriptor);
- plugin = this;
-
+ System.out.println("desc: " + descriptor.getInstallURL());
+
+
+ plugin= this;
+
+
+ String pathSuffix= "icons/"; //$NON-NLS-1$
+
+ System.out.println("" + Platform.getLocation());
+
+ System.out.println("" + Platform.getPluginStateLocation(plugin));
+
+ System.out.println("" + Platform.getLogFileLocation());
+
+
+
}
+ public String getPath() {
+ return plugin.getDescriptor().getInstallURL().getFile();
+ }
+
+
+
public static PHPUnitPlugin getDefault() {
return plugin;
}
super.startup();
}
- /**
- * @param string
- */
- public static ImageDescriptor getImageDescriptor(String name) {
-
- String iconPath = "icons/";
- try {
- URL installURL = getDefault().getDescriptor().getInstallURL();
- URL url = new URL(installURL, iconPath + name);
-
- System.out.println("url:" + url.toExternalForm());
-
- return ImageDescriptor.createFromURL(url);
- } catch (MalformedURLException e) {
- // should not happen
- return ImageDescriptor.getMissingImageDescriptor();
- }
-
-
- }
+
}
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
import net.sourceforge.phpeclipse.phpunit.testpool.TestCase;
import net.sourceforge.phpeclipse.phpunit.testpool.TestPool;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
final IActionBars actionBars = getViewSite().getActionBars();
IToolBarManager toolBarManager = actionBars.getToolBarManager();
- String iconsPath = "C:\\Documents and Settings\\Ali Echihabi\\My Documents\\workspace.eclipse2.1\\net.sourceforge.phpeclipse.phpunit\\icons";
-
- ImageDescriptor descriptor = null;
- String icon = "";
-
Action selectTestAction = new Action() {
public void run() {
testSuiteToRun = dialog.open();
}
};
+
selectTestAction.setText("Select Test Suite");
- selectTestAction.setToolTipText("Select Test Suite");
- try {
- icon = "tsuite.gif";
- descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon));
- selectTestAction.setImageDescriptor(descriptor);
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ selectTestAction.setToolTipText("Select Test Suite");
+ selectTestAction.setImageDescriptor(PHPUnitImages.DESC_SELECT_TEST_SUITE);
toolBarManager.add(selectTestAction);
}
};
+
startTestAction.setText("Start Test");
startTestAction.setToolTipText("Start Test Suite");
-
- try {
- icon = "start.gif";
- descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon));
- startTestAction.setImageDescriptor(descriptor);
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+ startTestAction.setImageDescriptor(PHPUnitImages.DESC_RUN_TEST_SUITE);
+
toolBarManager.add(startTestAction);
}
}
- // action to start tests:
- 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 {
out.write("<?php" + "\n");
out.write("ob_start();" + "\n");
+
+ //TODO: use install dir for path to phpunit. include it with plugin.
out.write("$path = \"C:/Documents and Settings/Ali Echihabi/My Documents/workspace.eclipse2.1/PHPUnit/phpunit\";" + "\n");
+
out.write("include_once($path . \"/phpunit_test.php\");" + "\n");
out.write("include_once $path . \"/socketTestResult.php\";" + "\n");
String testCount = args[1];
//createNewTestSuite("TestSuiteName: " + testID, testID, new Integer(testCount).intValue());
- TestSuite suite = new TestSuite("TestSuiteName: " + testID, testID, new Integer(testCount).intValue());
+ TestSuite suite = new TestSuite(null, "TestSuiteName: " + testID, testID, new Integer(testCount).intValue());
testPool.addTestSuite(suite);
} else if (command.equals("testStarted")) {
}
+
+
} //end of class
*/
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;
*/
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) {
String text = "";
public Image getImage(Object element) {
Image image = null;
-
- try {
+ ImageDescriptor descriptor = null;
- 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";
-
- }
+ if(element instanceof TestSuite) {
+ TestSuite suite = (TestSuite)element;
+ descriptor = PHPUnitImages.DESC_TEST_SUITE_PASS;
+
+
+ if(suite.hasError())
+ descriptor = PHPUnitImages.DESC_TEST_SUITE_ERROR;
+ else if(suite.hasFailure())
+ descriptor = PHPUnitImages.DESC_TEST_SUITE_FAILURE;
+ else if(suite.isAllPass())
+ descriptor = PHPUnitImages.DESC_TEST_SUITE_PASS;
+
+
+ } else if(element instanceof TestCase) {
- ImageDescriptor descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon));
- image = descriptor.createImage();
+ TestCase test = (TestCase)element;
- } catch (MalformedURLException e) {
+ descriptor = PHPUnitImages.DESC_TEST_PASS;
- e.printStackTrace();
- image = ImageDescriptor.getMissingImageDescriptor().createImage();
+ if(test.isError())
+ descriptor = PHPUnitImages.DESC_TEST_ERROR;
+ else if(test.isFailure())
+ descriptor = PHPUnitImages.DESC_TEST_FAILURE;
+ else if(test.isPass())
+ descriptor = PHPUnitImages.DESC_TEST_PASS;
+
}
-
-
-
+ image = descriptor.createImage();
+
return image;
public void setVerdict(String string) {
verdict = string;
+ if(isFailure())
+ parentSuite.setHasFailure();
+ if(isError())
+ parentSuite.setHasError();
+
}
/**
package net.sourceforge.phpeclipse.phpunit.testpool;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Vector;
/**
+ private boolean hasFailure;
+ private boolean isAllPass;
+ private boolean hasError;
private Vector testCases; // current or actual.
private Vector testSuites; // current or actual.
private String name;
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
testCases = new Vector();
testSuites = new Vector();
+
+ hasError = false;
+ isAllPass = true;
+ hasFailure = false;
}
public void addTestCase(TestCase test) {
testSuites = vector;
}
+ /**
+ * @return
+ */
+ public boolean hasError() {
+
+ return hasError;
+
+ }
+
+ public void setHasError() {
+
+ if(hasError)
+ return;
+
+ hasError = true;
+
+ if(parent != null)
+ parent.setHasError();
+ }
+
+
+ /**
+ * @return
+ */
+ public boolean hasFailure() {
+
+ return hasFailure;
+
+ }
+
+ public void setHasFailure() {
+
+ if(hasFailure)
+ return;
+
+ hasFailure = true;
+
+ if(parent != null)
+ parent.setHasFailure();
+ }
+
+
+ public boolean isAllPass() {
+
+ return !hasError() && !hasFailure();
+
+ }
}