diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java index b7ead3f3f28..947a4262516 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixTestCase.java @@ -12,15 +12,21 @@ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; import java.io.IOException; +import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.cdt.codan.core.test.CheckerTestCase; import org.eclipse.cdt.codan.core.test.TestUtils; +import org.eclipse.cdt.codan.internal.ui.CodanUIActivator; import org.eclipse.cdt.codan.ui.AbstractCodanCMarkerResolution; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; @@ -29,11 +35,63 @@ import org.eclipse.ui.PlatformUI; */ public abstract class QuickFixTestCase extends CheckerTestCase { AbstractCodanCMarkerResolution quickFix; + Display display; + /** + * Dispatch ui events for at least msec - milliseconds + * + * @param msec - + * milliseconds delay + * @param display - + * display that dispatches events + */ + public void dispatch(int msec) { + long cur = System.currentTimeMillis(); + long pass = 0; + while (pass < msec) { + if (!display.readAndDispatch()) + display.sleep(); + pass = System.currentTimeMillis() - cur; + } + } + + public static void closeWelcome() { + try { + IWorkbenchWindow window = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow(); + IWorkbenchPage activePage = window.getActivePage(); + IWorkbenchPart activePart = activePage.getActivePart(); + if (activePart.getTitle().equals("Welcome")) { + //activePage.close(); + activePart.dispose(); + } + } catch (Exception e) { + // ignore + } + } + + @SuppressWarnings("restriction") @Override public void setUp() throws Exception { super.setUp(); quickFix = createQuickFix(); + display = PlatformUI.getWorkbench().getDisplay(); + closeWelcome(); + IPreferenceStore store = CodanUIActivator.getDefault() + .getPreferenceStore(cproject.getProject()); + // turn off editor reconsiler + store.setValue(PreferenceConstants.P_RUN_IN_EDITOR, false); + } + + @Override + public void tearDown() throws CoreException { + IWorkbenchPage[] pages = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getPages(); + for (IWorkbenchPage page : pages) { + page.closeAllEditors(false); + dispatch(200); + } + super.tearDown(); } /** @@ -60,9 +118,9 @@ public abstract class QuickFixTestCase extends CheckerTestCase { public String runQuickFixOneFile() { // need to load before running codan because otherwise marker is lost when doing quick fix 8[] try { - EditorUtility.openInEditor(currentIFile); runCodan(); doRunQuickFix(); + dispatch(500); String result = TestUtils.loadFile(currentIFile.getContents()); return result; } catch (Exception e) { @@ -79,6 +137,7 @@ public abstract class QuickFixTestCase extends CheckerTestCase { for (int i = 0; i < markers.length; i++) { IMarker marker = markers[i]; quickFix.run(marker); + dispatch(200); } PlatformUI.getWorkbench().saveAllEditors(false); }