1 11 package org.eclipse.ui.internal.testing; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.OperationCanceledException; 15 import org.eclipse.core.runtime.Platform; 16 import org.eclipse.jface.dialogs.ErrorDialog; 17 import org.eclipse.jface.util.SafeRunnable; 18 import org.eclipse.swt.widgets.Display; 19 import org.eclipse.ui.IWorkbench; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.internal.Workbench; 22 import org.eclipse.ui.testing.TestableObject; 23 24 29 public class WorkbenchTestable extends TestableObject { 30 31 private Display display; 32 33 private IWorkbench workbench; 34 35 private boolean oldAutomatedMode; 36 37 private boolean oldIgnoreErrors; 38 39 42 public WorkbenchTestable() { 43 } 45 46 53 public void init(Display display, IWorkbench workbench) { 54 Assert.isNotNull(display); 55 Assert.isNotNull(workbench); 56 this.display = display; 57 this.workbench = workbench; 58 if (getTestHarness() != null) { 59 Runnable runnable = new Runnable () { 61 public void run() { 62 if (!"false".equalsIgnoreCase(System.getProperty(PlatformUI.PLUGIN_ID + ".testsWaitForEarlyStartup"))) { waitForEarlyStartup(); 67 } 68 getTestHarness().runTests(); 69 } 70 }; 71 new Thread (runnable, "WorkbenchTestable").start(); } 73 } 74 75 78 private void waitForEarlyStartup() { 79 try { 80 Platform.getJobManager().join(Workbench.EARLY_STARTUP_FAMILY, null); 81 } catch (OperationCanceledException e) { 82 } catch (InterruptedException e) { 84 } 86 } 87 88 93 public void testingStarting() { 94 Assert.isNotNull(workbench); 95 oldAutomatedMode = ErrorDialog.AUTOMATED_MODE; 96 ErrorDialog.AUTOMATED_MODE = true; 97 oldIgnoreErrors = SafeRunnable.getIgnoreErrors(); 98 SafeRunnable.setIgnoreErrors(true); 99 } 100 101 107 public void runTest(Runnable testRunnable) { 108 Assert.isNotNull(workbench); 109 display.syncExec(testRunnable); 110 } 111 112 117 public void testingFinished() { 118 display.syncExec(new Runnable () { 120 public void run() { 121 Assert.isTrue(workbench.close()); 122 } 123 }); 124 ErrorDialog.AUTOMATED_MODE = oldAutomatedMode; 125 SafeRunnable.setIgnoreErrors(oldIgnoreErrors); 126 } 127 } 128 | Popular Tags |