diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java index d15a4d1915e..fda554ba2d3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexSearchTest.java @@ -17,7 +17,6 @@ import java.util.regex.Pattern; import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMNode; import org.eclipse.cdt.core.dom.IPDOMVisitor; import org.eclipse.cdt.core.dom.ast.IEnumeration; @@ -33,19 +32,14 @@ import org.eclipse.cdt.core.index.IIndexBinding; import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.cdt.core.testplugin.CTestPlugin; -import org.eclipse.cdt.core.testplugin.util.BaseTestCase; import org.eclipse.cdt.internal.core.index.CIndex; import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; -public class IndexSearchTest extends BaseTestCase { +public class IndexSearchTest extends IndexTestBase { private static final IndexFilter INDEX_FILTER = new IndexFilter(); private static final IProgressMonitor NPM= new NullProgressMonitor(); @@ -66,7 +60,7 @@ public class IndexSearchTest extends BaseTestCase { public void setUp() throws Exception { super.setUp(); if (fProject == null) { - createProject(); + fProject= createProject(true); } fIndex= CCorePlugin.getIndexManager().getIndex(fProject); } @@ -76,23 +70,6 @@ public class IndexSearchTest extends BaseTestCase { super.tearDown(); } - - private void createProject() throws CoreException { - // Create the project - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - workspace.run(new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException { - fProject= CProjectHelper.createCProject("IndexSearchTest_" + System.currentTimeMillis(), null); - - CCorePlugin.getPDOMManager().setIndexerId(fProject, IPDOMManager.ID_NO_INDEXER); - CProjectHelper.importSourcesFromPlugin(fProject, CTestPlugin.getDefault().getBundle(), "resources/indexTests/search"); - } - }, null); - CCorePlugin.getPDOMManager().setIndexerId(fProject, IPDOMManager.ID_FAST_INDEXER); - // wait until the indexer is done - assertTrue(CCorePlugin.getIndexManager().joinIndexer(5000, new NullProgressMonitor())); - } - public void deleteProject() { if (fProject != null) { CProjectHelper.delete(fProject); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTestBase.java new file mode 100644 index 00000000000..70fe1189646 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexTestBase.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 Wind River Systems, Inc. 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.index.tests; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.IPDOMManager; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.testplugin.CProjectHelper; +import org.eclipse.cdt.core.testplugin.CTestPlugin; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; + +public class IndexTestBase extends BaseTestCase { + + public IndexTestBase(String name) { + super(name); + } + + protected ICProject createProject(final boolean useCpp) throws CoreException { + // Create the project + final ICProject[] result= new ICProject[] {null}; + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.run(new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + String name= "IndexSearchTest_" + System.currentTimeMillis(); + if (useCpp) { + result[0]= CProjectHelper.createCCProject(name, null); + } + else { + result[0]= CProjectHelper.createCProject(name, null); + } + + CCorePlugin.getPDOMManager().setIndexerId(result[0], IPDOMManager.ID_NO_INDEXER); + CProjectHelper.importSourcesFromPlugin(result[0], CTestPlugin.getDefault().getBundle(), "resources/indexTests/search"); + } + }, null); + CCorePlugin.getPDOMManager().setIndexerId(result[0], IPDOMManager.ID_FAST_INDEXER); + // wait until the indexer is done + assertTrue(CCorePlugin.getIndexManager().joinIndexer(5000, new NullProgressMonitor())); + return result[0]; + } +}