diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java index bab311e9d34..72fa12acb7e 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/BaseUITestCase.java @@ -20,6 +20,11 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.index.IIndex; @@ -108,4 +113,23 @@ public class BaseUITestCase extends BaseTestCase { item.getParent().notifyListeners(SWT.Expand, event); runEventQueue(0); } + + protected void closeEditor(IEditorPart editor) { + IWorkbenchPartSite site; + IWorkbenchPage page; + if (editor != null && (site= editor.getSite()) != null && (page= site.getPage()) != null) { + page.closeEditor(editor, false); + } + } + + protected void closeAllEditors() { + IWorkbenchWindow[] windows= PlatformUI.getWorkbench().getWorkbenchWindows(); + for (int i= 0; i < windows.length; i++) { + IWorkbenchPage[] pages= windows[i].getPages(); + for (int j= 0; j < pages.length; j++) { + IWorkbenchPage page= pages[j]; + page.closeAllEditors(false); + } + } + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java index 2d96d7de8f7..b49f105c325 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/callhierarchy/CallHierarchyBaseTest.java @@ -55,6 +55,7 @@ public class CallHierarchyBaseTest extends BaseUITestCase { } protected void tearDown() throws Exception { + closeAllEditors(); if (fCProject != null) { CProjectHelper.delete(fCProject); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/EditorTestHelper.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/EditorTestHelper.java index cef9059faa5..fbf8a24aa3e 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/EditorTestHelper.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/EditorTestHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -53,7 +53,6 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorReference; import org.eclipse.ui.IViewReference; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; @@ -162,9 +161,7 @@ public class EditorTestHelper { for (int i= 0; i < windows.length; i++) { IWorkbenchPage[] pages= windows[i].getPages(); for (int j= 0; j < pages.length; j++) { - IEditorReference[] editorReferences= pages[j].getEditorReferences(); - for (int k= 0; k < editorReferences.length; k++) - closeEditor(editorReferences[k].getEditor(false)); + pages[j].closeAllEditors(false); } } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java index 03d2cb965cc..e9733251d02 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java @@ -108,6 +108,7 @@ public class ContentAssistTests extends BaseUITestCase { } public void cleanupProject() throws Exception { + closeAllEditors(); try{ project.delete( true, false, monitor ); project = null; @@ -120,6 +121,8 @@ public class ContentAssistTests extends BaseUITestCase { if( project == null || !project.exists() ) return; + closeAllEditors(); + IResource [] members = project.members(); for( int i = 0; i < members.length; i++ ){ if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cdtproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java index 72ec36a6b36..2d37d844b27 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.java @@ -61,6 +61,7 @@ public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsInde } protected void tearDown() throws Exception { + closeAllEditors(); CProjectHelper.delete(fCProject); super.tearDown(); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java index 7e8e2a32fe5..1b23c6128ae 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsNoIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -50,7 +50,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.cdt.ui.tests.BaseUITestCase; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.parser.ParserException; @@ -64,7 +64,7 @@ import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; * * @author dsteffle */ -public class CPPSelectionTestsNoIndexer extends BaseTestCase { +public class CPPSelectionTestsNoIndexer extends BaseUITestCase { private static final String INDEX_FILE_ID = "2946365241"; //$NON-NLS-1$ static NullProgressMonitor monitor; @@ -116,6 +116,7 @@ public class CPPSelectionTestsNoIndexer extends BaseTestCase { } public void cleanupProject() throws Exception { + closeAllEditors(); try{ project.delete( true, false, monitor ); project = null; @@ -128,6 +129,8 @@ public class CPPSelectionTestsNoIndexer extends BaseTestCase { if( project == null || !project.exists() ) return; + closeAllEditors(); + IResource [] members = project.members(); for( int i = 0; i < members.length; i++ ){ if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cdtproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java index 16901694553..58817f0c3c5 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsAnyIndexer.java @@ -57,6 +57,7 @@ public abstract class CSelectionTestsAnyIndexer extends BaseSelectionTestsIndexe } protected void tearDown() throws Exception { + closeAllEditors(); CProjectHelper.delete(fCProject); super.tearDown(); } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java index 3de409cda0d..f49fbd7b43e 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CSelectionTestsNoIndexer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,7 +16,6 @@ import java.io.File; import java.io.InputStream; import junit.framework.Test; -import junit.framework.TestCase; import junit.framework.TestSuite; import org.eclipse.core.resources.IFile; @@ -48,6 +47,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; +import org.eclipse.cdt.ui.tests.BaseUITestCase; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; import org.eclipse.cdt.internal.core.parser.ParserException; @@ -61,7 +61,7 @@ import org.eclipse.cdt.internal.ui.search.actions.OpenDeclarationsAction; * * @author dsteffle */ -public class CSelectionTestsNoIndexer extends TestCase { +public class CSelectionTestsNoIndexer extends BaseUITestCase { private static final String INDEX_FILE_ID = "2324852323"; //$NON-NLS-1$ static NullProgressMonitor monitor; @@ -107,6 +107,7 @@ public class CSelectionTestsNoIndexer extends TestCase { } public void cleanupProject() throws Exception { + closeAllEditors(); CProjectHelper.delete(cPrj); project= null; } @@ -114,7 +115,9 @@ public class CSelectionTestsNoIndexer extends TestCase { protected void tearDown() throws Exception { if( project == null || !project.exists() ) return; - + + closeAllEditors(); + IResource [] members = project.members(); for( int i = 0; i < members.length; i++ ){ if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cdtproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java index dfddab6d731..05ff4333bee 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java @@ -60,6 +60,7 @@ public class TypeHierarchyBaseTest extends BaseUITestCase { } protected void tearDown() throws Exception { + closeAllEditors(); if (fCProject != null) { CProjectHelper.delete(fCProject); }