mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-09 10:05: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"/>
|
id="org.eclipse.rse.tests.framework.RunHolder"/>
|
||||||
</objectContribution>
|
</objectContribution>
|
||||||
</extension>
|
</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">
|
<extension point="org.eclipse.help.toc">
|
||||||
<toc primary="true" file="toc.xml"/>
|
<toc primary="true" file="toc.xml"/>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
|
@ -9,7 +9,9 @@
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
package org.eclipse.rse.tests.framework;
|
package org.eclipse.rse.tests.framework;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
|
@ -18,6 +20,8 @@ import org.osgi.framework.BundleContext;
|
||||||
*/
|
*/
|
||||||
public class TestFrameworkPlugin extends AbstractUIPlugin {
|
public class TestFrameworkPlugin extends AbstractUIPlugin {
|
||||||
|
|
||||||
|
public static final String PREF_RUN_IN_BACKGROUND = "org.eclipse.rse.tests.runInBackground";
|
||||||
|
|
||||||
private static TestFrameworkPlugin plugin;
|
private static TestFrameworkPlugin plugin;
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -26,6 +30,8 @@ public class TestFrameworkPlugin extends AbstractUIPlugin {
|
||||||
public void start(BundleContext context) throws Exception {
|
public void start(BundleContext context) throws Exception {
|
||||||
super.start(context);
|
super.start(context);
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
IPreferenceStore store = getPreferenceStore();
|
||||||
|
store.setDefault(PREF_RUN_IN_BACKGROUND, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -50,7 +56,7 @@ public class TestFrameworkPlugin extends AbstractUIPlugin {
|
||||||
public void logUnexpectedException(Exception e) {
|
public void logUnexpectedException(Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
String id = getBundle().getSymbolicName();
|
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);
|
getLog().log(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
* *******************************************************************************/
|
* *******************************************************************************/
|
||||||
package org.eclipse.rse.tests.framework.actions;
|
package org.eclipse.rse.tests.framework.actions;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
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.SubProgressMonitor;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.jface.action.IAction;
|
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.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.rse.tests.framework.AbstractTestSuiteHolder;
|
import org.eclipse.rse.tests.framework.AbstractTestSuiteHolder;
|
||||||
|
import org.eclipse.rse.tests.framework.TestFrameworkPlugin;
|
||||||
import org.eclipse.ui.IObjectActionDelegate;
|
import org.eclipse.ui.IObjectActionDelegate;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
import org.eclipse.ui.IWorkbenchPartSite;
|
import org.eclipse.ui.IWorkbenchPartSite;
|
||||||
|
@ -61,11 +66,46 @@ public class RunHolderDelegate implements IObjectActionDelegate {
|
||||||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||||
*/
|
*/
|
||||||
public void run(IAction action) {
|
public void run(IAction action) {
|
||||||
final ISelection selection = this.selection;
|
IPreferenceStore store = TestFrameworkPlugin.getDefault().getPreferenceStore();
|
||||||
Job job = new Job("Running JUnit Tests Suites") {
|
boolean runInBackground = store.getBoolean(TestFrameworkPlugin.PREF_RUN_IN_BACKGROUND);
|
||||||
IStatus result = Status.OK_STATUS;
|
if (runInBackground) {
|
||||||
|
runInBackground();
|
||||||
|
} else {
|
||||||
|
runInUI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void runInBackground() {
|
||||||
|
Job job = new Job("Running JUnit Tests Suites") {
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
IStatus result = runTests(monitor);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
job.setPriority(Job.LONG);
|
||||||
|
job.setUser(true);
|
||||||
|
IWorkbenchPartSite site = part.getSite();
|
||||||
|
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) {
|
if (selection instanceof IStructuredSelection) {
|
||||||
IStructuredSelection ss = (IStructuredSelection) selection;
|
IStructuredSelection ss = (IStructuredSelection) selection;
|
||||||
monitor.beginTask("", ss.size());
|
monitor.beginTask("", ss.size());
|
||||||
|
@ -83,11 +123,5 @@ public class RunHolderDelegate implements IObjectActionDelegate {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
job.setPriority(Job.LONG);
|
|
||||||
job.setUser(true);
|
|
||||||
IWorkbenchPartSite site = part.getSite();
|
|
||||||
IWorkbenchSiteProgressService siteService = (IWorkbenchSiteProgressService) site.getAdapter(IWorkbenchSiteProgressService.class);
|
|
||||||
siteService.schedule(job, 0, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -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.
|
* Provides a view of the test suites installed in this workbench.
|
||||||
*/
|
*/
|
||||||
public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderListener, ISelectionChangedListener {
|
public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderListener, ISelectionChangedListener {
|
||||||
|
|
||||||
private class MyLabelProvider implements ITableLabelProvider {
|
private class MyLabelProvider implements ITableLabelProvider {
|
||||||
public Image getColumnImage(Object element, int columnIndex) {
|
public Image getColumnImage(Object element, int columnIndex) {
|
||||||
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) element;
|
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) element;
|
||||||
Image columnImage = null;
|
Image columnImage = null;
|
||||||
switch (columnIndex) {
|
String columnId = getColumnId(columnIndex);
|
||||||
case 1: // name column
|
if (columnId.equals("graphic")) {
|
||||||
break;
|
|
||||||
case 0: { // graphic column
|
|
||||||
TestResult result = holder.getTestResult();
|
TestResult result = holder.getTestResult();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
if (result.wasSuccessful()) {
|
if (result.wasSuccessful()) {
|
||||||
|
@ -75,14 +74,6 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
||||||
} else {
|
} else {
|
||||||
columnImage = graphicUnknown;
|
columnImage = graphicUnknown;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 2: // status column
|
|
||||||
break;
|
|
||||||
case 3: // date column
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return columnImage;
|
return columnImage;
|
||||||
}
|
}
|
||||||
|
@ -90,14 +81,12 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
||||||
public String getColumnText(Object element, int columnIndex) {
|
public String getColumnText(Object element, int columnIndex) {
|
||||||
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) element;
|
AbstractTestSuiteHolder holder = (AbstractTestSuiteHolder) element;
|
||||||
String columnText = null;
|
String columnText = null;
|
||||||
switch (columnIndex) {
|
String columnId = getColumnId(columnIndex);
|
||||||
case 1: // name column
|
if (columnId.equals("name")) {
|
||||||
columnText = holder.getName();
|
columnText = holder.getName();
|
||||||
break;
|
} else if (columnId.equals("graphic")) {
|
||||||
case 0: // graphic column
|
|
||||||
columnText = "";
|
columnText = "";
|
||||||
break;
|
} else if (columnId.equals("status")) {
|
||||||
case 2: // status column
|
|
||||||
TestResult result = holder.getTestResult();
|
TestResult result = holder.getTestResult();
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
Object[] values = { new Integer(result.runCount()), new Integer(result.failureCount()), new Integer(result.errorCount()) };
|
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 {
|
} else {
|
||||||
columnText = "";
|
columnText = "";
|
||||||
}
|
}
|
||||||
break;
|
} else if (columnId.equals("stamp")) {
|
||||||
case 3: // run date/time column
|
|
||||||
Calendar stamp = holder.getLastRunTime();
|
Calendar stamp = holder.getLastRunTime();
|
||||||
if (stamp != null) {
|
if (stamp != null) {
|
||||||
DateFormat formatter = DateFormat.getDateTimeInstance();
|
DateFormat formatter = DateFormat.getDateTimeInstance();
|
||||||
|
@ -115,12 +103,9 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
||||||
} else {
|
} else {
|
||||||
columnText = "";
|
columnText = "";
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return columnText;
|
return columnText;
|
||||||
};
|
}
|
||||||
|
|
||||||
public void addListener(ILabelProviderListener listener) {
|
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 String[] columnTitles = {"", "Test Suite", "Summary", "Time Run"};
|
||||||
private SelectionListener[] columnListeners = {graphicListener, nameListener, statusListener, stampListener};
|
private SelectionListener[] columnListeners = {graphicListener, nameListener, statusListener, stampListener};
|
||||||
private boolean[] columnResizable = {false, true, true, true};
|
private boolean[] columnResizable = {false, true, true, true};
|
||||||
|
private boolean[] columnMoveable = {false, true, true, true};
|
||||||
private Image graphicFailed = null;
|
private Image graphicFailed = null;
|
||||||
private Image graphicPassed = null;
|
private Image graphicPassed = null;
|
||||||
private Image graphicUnknown = null;
|
private Image graphicUnknown = null;
|
||||||
|
@ -241,9 +227,11 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
||||||
int n = columnIds.length;
|
int n = columnIds.length;
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
TableColumn column = new TableColumn(table, SWT.NONE);
|
TableColumn column = new TableColumn(table, SWT.NONE);
|
||||||
|
column.setData("id", columnIds[i]);
|
||||||
column.setText(columnTitles[i]);
|
column.setText(columnTitles[i]);
|
||||||
column.setWidth(columnWidths[i]);
|
column.setWidth(columnWidths[i]);
|
||||||
column.setResizable(columnResizable[i]);
|
column.setResizable(columnResizable[i]);
|
||||||
|
column.setMoveable(columnMoveable[i]);
|
||||||
column.addSelectionListener(columnListeners[i]);
|
column.addSelectionListener(columnListeners[i]);
|
||||||
}
|
}
|
||||||
holderViewer = new TableViewer(table);
|
holderViewer = new TableViewer(table);
|
||||||
|
@ -349,7 +337,28 @@ public class TestSuiteHolderView extends ViewPart implements ITestSuiteHolderLis
|
||||||
*/
|
*/
|
||||||
public void testHolderReset(ITestSuiteHolder holder) {
|
public void testHolderReset(ITestSuiteHolder holder) {
|
||||||
updateHolderInView(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