mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-09 01:55:24 +02:00
update framework to allow foreground and background running of tests
This commit is contained in:
parent
f52d6e1157
commit
f58f805e4a
5 changed files with 141 additions and 46 deletions
|
@ -62,6 +62,24 @@
|
|||
id="org.eclipse.rse.tests.framework.RunHolder"/>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
|
||||
<extension point="org.eclipse.ui.viewActions">
|
||||
<viewContribution
|
||||
id="org.eclipse.rse.tests.framework.HolderViewActions"
|
||||
targetID="org.eclipse.rse.tests.framework.HolderView">
|
||||
<action
|
||||
class="org.eclipse.rse.tests.framework.actions.ToggleRunInBackgroundDelegate"
|
||||
icon="icons/GreenDot.gif"
|
||||
id="org.eclipse.rse.tests.framework.runInBackgroundToggle"
|
||||
label="Run In Background"
|
||||
state="true"
|
||||
style="toggle"
|
||||
toolbarPath="RunGroup"
|
||||
tooltip="Run In Background"/>
|
||||
</viewContribution>
|
||||
|
||||
</extension>
|
||||
|
||||
<extension point="org.eclipse.help.toc">
|
||||
<toc primary="true" file="toc.xml"/>
|
||||
</extension>
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
* *******************************************************************************/
|
||||
package org.eclipse.rse.tests.framework;
|
||||
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
|
@ -18,6 +20,8 @@ import org.osgi.framework.BundleContext;
|
|||
*/
|
||||
public class TestFrameworkPlugin extends AbstractUIPlugin {
|
||||
|
||||
public static final String PREF_RUN_IN_BACKGROUND = "org.eclipse.rse.tests.runInBackground";
|
||||
|
||||
private static TestFrameworkPlugin plugin;
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -26,6 +30,8 @@ public class TestFrameworkPlugin extends AbstractUIPlugin {
|
|||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
IPreferenceStore store = getPreferenceStore();
|
||||
store.setDefault(PREF_RUN_IN_BACKGROUND, true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -50,7 +56,7 @@ public class TestFrameworkPlugin extends AbstractUIPlugin {
|
|||
public void logUnexpectedException(Exception e) {
|
||||
e.printStackTrace();
|
||||
String id = getBundle().getSymbolicName();
|
||||
Status status = new Status(Status.ERROR, id, 0, "Unexpected Exception", e);
|
||||
Status status = new Status(IStatus.ERROR, id, 0, "Unexpected Exception", e);
|
||||
getLog().log(status);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
* *******************************************************************************/
|
||||
package org.eclipse.rse.tests.framework.actions;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Iterator;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -16,9 +17,13 @@ import org.eclipse.core.runtime.Status;
|
|||
import org.eclipse.core.runtime.SubProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.operation.IRunnableContext;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.rse.tests.framework.AbstractTestSuiteHolder;
|
||||
import org.eclipse.rse.tests.framework.TestFrameworkPlugin;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchPartSite;
|
||||
|
@ -61,26 +66,19 @@ public class RunHolderDelegate implements IObjectActionDelegate {
|
|||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
final ISelection selection = this.selection;
|
||||
Job job = new Job("Running JUnit Tests Suites") {
|
||||
IStatus result = Status.OK_STATUS;
|
||||
IPreferenceStore store = TestFrameworkPlugin.getDefault().getPreferenceStore();
|
||||
boolean runInBackground = store.getBoolean(TestFrameworkPlugin.PREF_RUN_IN_BACKGROUND);
|
||||
if (runInBackground) {
|
||||
runInBackground();
|
||||
} else {
|
||||
runInUI();
|
||||
}
|
||||
}
|
||||
|
||||
private void runInBackground() {
|
||||
Job job = new Job("Running JUnit Tests Suites") {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection ss = (IStructuredSelection) selection;
|
||||
monitor.beginTask("", ss.size());
|
||||
for (Iterator z = ss.iterator(); z.hasNext();) {
|
||||
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) z.next();
|
||||
monitor.subTask(holder.getName());
|
||||
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
|
||||
holder.run(subMonitor);
|
||||
if (monitor.isCanceled()) {
|
||||
result = Status.CANCEL_STATUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
IStatus result = runTests(monitor);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
@ -90,4 +88,40 @@ public class RunHolderDelegate implements IObjectActionDelegate {
|
|||
IWorkbenchSiteProgressService siteService = (IWorkbenchSiteProgressService) site.getAdapter(IWorkbenchSiteProgressService.class);
|
||||
siteService.schedule(job, 0, true);
|
||||
}
|
||||
|
||||
private void runInUI() {
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) {
|
||||
runTests(monitor);
|
||||
}
|
||||
};
|
||||
IWorkbenchPartSite site = part.getSite();
|
||||
IWorkbenchSiteProgressService siteService = (IWorkbenchSiteProgressService) site.getAdapter(IWorkbenchSiteProgressService.class);
|
||||
try {
|
||||
siteService.runInUI(siteService, runnable, null);
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private IStatus runTests(IProgressMonitor monitor) {
|
||||
IStatus result = Status.OK_STATUS;
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
IStructuredSelection ss = (IStructuredSelection) selection;
|
||||
monitor.beginTask("", ss.size());
|
||||
for (Iterator z = ss.iterator(); z.hasNext();) {
|
||||
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) z.next();
|
||||
monitor.subTask(holder.getName());
|
||||
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
|
||||
holder.run(subMonitor);
|
||||
if (monitor.isCanceled()) {
|
||||
result = Status.CANCEL_STATUS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
monitor.done();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.eclipse.rse.tests.framework.actions;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.rse.tests.framework.TestFrameworkPlugin;
|
||||
import org.eclipse.ui.IViewActionDelegate;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
|
||||
public class ToggleRunInBackgroundDelegate extends Object implements IViewActionDelegate {
|
||||
|
||||
public void init(IViewPart view) {
|
||||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
boolean runInBackground = action.isChecked();
|
||||
setPreference(runInBackground);
|
||||
}
|
||||
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
}
|
||||
|
||||
private void setPreference(boolean runInBackground) {
|
||||
IPreferenceStore store = TestFrameworkPlugin.getDefault().getPreferenceStore();
|
||||
store.setValue(TestFrameworkPlugin.PREF_RUN_IN_BACKGROUND, runInBackground);
|
||||
}
|
||||
|
||||
}
|
|
@ -57,14 +57,13 @@ import org.osgi.framework.Bundle;
|
|||
* Provides a view of the test suites installed in this workbench.
|
||||
*/
|
||||
public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderListener, ISelectionChangedListener {
|
||||
|
||||
private class MyLabelProvider implements ITableLabelProvider {
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) element;
|
||||
Image columnImage = null;
|
||||
switch (columnIndex) {
|
||||
case 1: // name column
|
||||
break;
|
||||
case 0: { // graphic column
|
||||
String columnId = getColumnId(columnIndex);
|
||||
if (columnId.equals("graphic")) {
|
||||
TestResult result = holder.getTestResult();
|
||||
if (result != null) {
|
||||
if (result.wasSuccessful()) {
|
||||
|
@ -75,14 +74,6 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
} else {
|
||||
columnImage = graphicUnknown;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: // status column
|
||||
break;
|
||||
case 3: // date column
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return columnImage;
|
||||
}
|
||||
|
@ -90,14 +81,12 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
public String getColumnText(Object element, int columnIndex) {
|
||||
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) element;
|
||||
String columnText = null;
|
||||
switch (columnIndex) {
|
||||
case 1: // name column
|
||||
String columnId = getColumnId(columnIndex);
|
||||
if (columnId.equals("name")) {
|
||||
columnText = holder.getName();
|
||||
break;
|
||||
case 0: // graphic column
|
||||
} else if (columnId.equals("graphic")) {
|
||||
columnText = "";
|
||||
break;
|
||||
case 2: // status column
|
||||
} else if (columnId.equals("status")) {
|
||||
TestResult result = holder.getTestResult();
|
||||
if (result != null) {
|
||||
Object[] values = { new Integer(result.runCount()), new Integer(result.failureCount()), new Integer(result.errorCount()) };
|
||||
|
@ -106,8 +95,7 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
} else {
|
||||
columnText = "";
|
||||
}
|
||||
break;
|
||||
case 3: // run date/time column
|
||||
} else if (columnId.equals("stamp")) {
|
||||
Calendar stamp = holder.getLastRunTime();
|
||||
if (stamp != null) {
|
||||
DateFormat formatter = DateFormat.getDateTimeInstance();
|
||||
|
@ -115,12 +103,9 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
} else {
|
||||
columnText = "";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return columnText;
|
||||
};
|
||||
}
|
||||
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
}
|
||||
|
@ -219,6 +204,7 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
private String[] columnTitles = {"", "Test Suite", "Summary", "Time Run"};
|
||||
private SelectionListener[] columnListeners = {graphicListener, nameListener, statusListener, stampListener};
|
||||
private boolean[] columnResizable = {false, true, true, true};
|
||||
private boolean[] columnMoveable = {false, true, true, true};
|
||||
private Image graphicFailed = null;
|
||||
private Image graphicPassed = null;
|
||||
private Image graphicUnknown = null;
|
||||
|
@ -241,9 +227,11 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
int n = columnIds.length;
|
||||
for (int i = 0; i < n; i++) {
|
||||
TableColumn column = new TableColumn(table, SWT.NONE);
|
||||
column.setData("id", columnIds[i]);
|
||||
column.setText(columnTitles[i]);
|
||||
column.setWidth(columnWidths[i]);
|
||||
column.setResizable(columnResizable[i]);
|
||||
column.setMoveable(columnMoveable[i]);
|
||||
column.addSelectionListener(columnListeners[i]);
|
||||
}
|
||||
holderViewer = new TableViewer(table);
|
||||
|
@ -349,7 +337,28 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
|||
*/
|
||||
public void testHolderReset(ITestSuiteHolder holder) {
|
||||
updateHolderInView(holder);
|
||||
updateResultString(holder);;
|
||||
updateResultString(holder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns in this table may be reordered. Given a column index retrieve its id.
|
||||
* @param columnIndex the index of the column
|
||||
* @return The string id of the column. Will be null if no id has been assigned or columnIndex is out
|
||||
* of range.
|
||||
*/
|
||||
private String getColumnId(int columnIndex) {
|
||||
String columnId = null;
|
||||
if (holderViewer != null) {
|
||||
Table table = holderViewer.getTable();
|
||||
int n = table.getColumnCount();
|
||||
if (0 <= columnIndex && columnIndex < n) {
|
||||
TableColumn column = table.getColumn(columnIndex);
|
||||
if (column != null) {
|
||||
columnId = (String) column.getData("id");
|
||||
}
|
||||
}
|
||||
}
|
||||
return columnId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue