mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 09:45:39 +02:00
Clean up usage of TestScannerProvider within the tests.
This commit is contained in:
parent
61c38d0f85
commit
f6b7c739ba
9 changed files with 105 additions and 110 deletions
|
@ -58,7 +58,6 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -75,18 +74,18 @@ public class IndexBugsTests extends BaseTestCase {
|
|||
return suite(IndexBugsTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws CoreException {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= CProjectHelper.createCCProject("__bugsTest__", "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||
CCorePlugin.getIndexManager().reindex(fCProject);
|
||||
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
|
||||
}
|
||||
|
||||
protected void tearDown() throws CoreException {
|
||||
TestScannerProvider.sIncludeFiles= TestScannerProvider.sIncludes=
|
||||
TestScannerProvider.sMacroFiles= null;
|
||||
protected void tearDown() throws Exception {
|
||||
if (fCProject != null) {
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected IProject getProject() {
|
||||
|
|
|
@ -68,7 +68,6 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
}
|
||||
|
||||
public void tearDown() throws Exception {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
@ -156,113 +155,93 @@ public class IndexIncludeTest extends IndexTestBase {
|
|||
public void testIncludeProperties() throws Exception {
|
||||
waitForIndexer();
|
||||
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
|
||||
try {
|
||||
String content= readTaggedComment("source20061107");
|
||||
TestSourceReader.createFile(fProject.getProject(), "user20061107.h", "");
|
||||
TestSourceReader.createFile(fProject.getProject(), "system20061107.h", "");
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", content);
|
||||
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
|
||||
String content= readTaggedComment("source20061107");
|
||||
TestSourceReader.createFile(fProject.getProject(), "user20061107.h", "");
|
||||
TestSourceReader.createFile(fProject.getProject(), "system20061107.h", "");
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", content);
|
||||
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(2, includes.length);
|
||||
|
||||
checkInclude(includes[0], content, "user20061107.h", false);
|
||||
checkInclude(includes[1], content, "system20061107.h", true);
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(2, includes.length);
|
||||
|
||||
checkInclude(includes[0], content, "user20061107.h", false);
|
||||
checkInclude(includes[1], content, "system20061107.h", true);
|
||||
}
|
||||
finally {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void testIncludeProperties_2() throws Exception {
|
||||
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
|
||||
try {
|
||||
TestSourceReader.createFile(fProject.getProject(), "header20061107.h", "");
|
||||
String content = "// comment \n#include \"header20061107.h\"\n";
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "intermed20061107.h", content);
|
||||
TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", "#include \"intermed20061107.h\"\n");
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
TestSourceReader.createFile(fProject.getProject(), "header20061107.h", "");
|
||||
String content = "// comment \n#include \"header20061107.h\"\n";
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "intermed20061107.h", content);
|
||||
TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", "#include \"intermed20061107.h\"\n");
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(1, includes.length);
|
||||
|
||||
checkInclude(includes[0], content, "header20061107.h", false);
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(1, includes.length);
|
||||
|
||||
checkInclude(includes[0], content, "header20061107.h", false);
|
||||
}
|
||||
finally {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void testInactiveInclude() throws Exception {
|
||||
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
|
||||
String content = "#if 0\n#include \"inactive20070213.h\"\n#endif\n";
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070213.cpp", content);
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
String content = "#if 0\n#include \"inactive20070213.h\"\n#endif\n";
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070213.cpp", content);
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(1, includes.length);
|
||||
|
||||
assertFalse(includes[0].isActive());
|
||||
checkInclude(includes[0], content, "inactive20070213.h", false);
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(1, includes.length);
|
||||
|
||||
assertFalse(includes[0].isActive());
|
||||
checkInclude(includes[0], content, "inactive20070213.h", false);
|
||||
}
|
||||
finally {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnresolvedInclude() throws Exception {
|
||||
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
|
||||
String content = "#include \"unresolved20070213.h\"\n";
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070214.cpp", content);
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
String content = "#include \"unresolved20070213.h\"\n";
|
||||
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070214.cpp", content);
|
||||
CCorePlugin.getIndexManager().reindex(fProject);
|
||||
waitForIndexer();
|
||||
|
||||
fIndex.acquireReadLock();
|
||||
try {
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(1, includes.length);
|
||||
|
||||
assertTrue(includes[0].isActive());
|
||||
assertFalse(includes[0].isResolved());
|
||||
checkInclude(includes[0], content, "unresolved20070213.h", false);
|
||||
}
|
||||
finally {
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
|
||||
assertNotNull(ifile);
|
||||
IIndexInclude[] includes= ifile.getIncludes();
|
||||
assertEquals(1, includes.length);
|
||||
|
||||
assertTrue(includes[0].isActive());
|
||||
assertFalse(includes[0].isResolved());
|
||||
checkInclude(includes[0], content, "unresolved20070213.h", false);
|
||||
}
|
||||
finally {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
fIndex.releaseReadLock();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.index.tests;
|
||||
|
||||
|
@ -40,6 +40,7 @@ public class TrilogyPerformanceTest extends IndexTestBase {
|
|||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Bundle b = CTestPlugin.getDefault().getBundle();
|
||||
if (cproject == null) {
|
||||
cproject= createProject(true, "resources/indexTests/trilogy");
|
||||
|
@ -48,6 +49,7 @@ public class TrilogyPerformanceTest extends IndexTestBase {
|
|||
|
||||
protected void tearDown() throws Exception {
|
||||
cproject.getProject().delete(true, new NullProgressMonitor());
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
// you must have the Windows SDK installed and the INETSDK env var setup
|
||||
|
@ -55,18 +57,14 @@ public class TrilogyPerformanceTest extends IndexTestBase {
|
|||
if(Platform.getOS().equals(Platform.OS_WIN32)) {
|
||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
||||
TestScannerProvider.sIncludes = new String[]{EnvironmentReader.getEnvVar("INETSDK")+"\\Include"};
|
||||
try {
|
||||
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true");
|
||||
long start = System.currentTimeMillis();
|
||||
CCorePlugin.getIndexManager().reindex(cproject);
|
||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
||||
System.out.println("Took: "+(System.currentTimeMillis() - start));
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject);
|
||||
IBinding[] binding = index.findBindings(Pattern.compile("IXMLElementCollection"), false, IndexFilter.ALL, new NullProgressMonitor());
|
||||
assertEquals(1, binding.length);
|
||||
} finally {
|
||||
TestScannerProvider.sIncludes = null;
|
||||
}
|
||||
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true");
|
||||
long start = System.currentTimeMillis();
|
||||
CCorePlugin.getIndexManager().reindex(cproject);
|
||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
|
||||
System.out.println("Took: "+(System.currentTimeMillis() - start));
|
||||
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject);
|
||||
IBinding[] binding = index.findBindings(Pattern.compile("IXMLElementCollection"), false, IndexFilter.ALL, new NullProgressMonitor());
|
||||
assertEquals(1, binding.length);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,6 +24,10 @@ public class TestScannerProvider extends AbstractCExtension implements IScannerI
|
|||
public static String[] sMacroFiles= null;
|
||||
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner";
|
||||
|
||||
public static void clear() {
|
||||
sIncludes= sIncludeFiles= sMacroFiles= null;
|
||||
}
|
||||
|
||||
public IScannerInfo getScannerInformation(IResource resource) {
|
||||
return new TestScannerInfo(sIncludes, sIncludeFiles, sMacroFiles);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ElementChangedEvent;
|
||||
import org.eclipse.cdt.core.model.IElementChangedListener;
|
||||
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.ILogListener;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
@ -52,6 +53,13 @@ public class BaseTestCase extends TestCase {
|
|||
public BaseTestCase(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
TestScannerProvider.clear();
|
||||
}
|
||||
|
||||
protected static TestSuite suite(Class clazz) {
|
||||
return suite(clazz, null);
|
||||
|
|
|
@ -53,7 +53,6 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
|
|||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
if (fCProject2 != null) {
|
||||
CProjectHelper.delete(fCProject2);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
package org.eclipse.cdt.ui.tests.includebrowser;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.swt.widgets.Tree;
|
||||
|
@ -44,7 +43,8 @@ public class IncludeBrowserBaseTest extends BaseUITestCase {
|
|||
super(name);
|
||||
}
|
||||
|
||||
protected void setUp() throws CoreException {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= CProjectHelper.createCCProject("__ibTest__", "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||
|
||||
// clear the index
|
||||
|
@ -52,10 +52,11 @@ public class IncludeBrowserBaseTest extends BaseUITestCase {
|
|||
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
|
||||
}
|
||||
|
||||
protected void tearDown() throws CoreException {
|
||||
protected void tearDown() throws Exception {
|
||||
if (fCProject != null) {
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected ICProject getProject() {
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.search;
|
||||
|
||||
|
@ -58,6 +59,7 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject = CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
|
||||
Bundle b = CTestPlugin.getDefault().getBundle();
|
||||
testData = TestSourceReader.getContentsForTest(b, "ui", this.getClass(), getName(), 2);
|
||||
|
@ -74,6 +76,7 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
if(fCProject != null) {
|
||||
fCProject.getProject().delete(true, NPM);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
// // empty
|
||||
|
@ -110,14 +113,19 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
ILabelProvider labpv= (ILabelProvider) viewer.getLabelProvider();
|
||||
IStructuredContentProvider scp= (IStructuredContentProvider) viewer.getContentProvider();
|
||||
|
||||
Object result0= result.getElements()[0];
|
||||
Object result1= result.getElements()[1];
|
||||
String label0= labpv.getText(scp.getElements(result)[0]);
|
||||
String label1= labpv.getText(scp.getElements(result)[1]);
|
||||
|
||||
// the content provider does not sort the result, so we have to do it:
|
||||
if (label0.compareTo(label1) < 0) {
|
||||
String h= label0; label0= label1; label1= h;
|
||||
}
|
||||
|
||||
// check the results are rendered
|
||||
String expected0= fCProject.getProject().getName();
|
||||
String expected1= new Path(externalFile.getAbsolutePath()).toString();
|
||||
assertEquals(expected0,labpv.getText(scp.getElements(result)[0]));
|
||||
assertEquals(expected1,labpv.getText(scp.getElements(result)[1]));
|
||||
assertEquals(expected0,label0);
|
||||
assertEquals(expected1,label1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,7 +58,6 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
|
|||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
TestScannerProvider.sIncludes= null;
|
||||
if (fCProject2 != null) {
|
||||
CProjectHelper.delete(fCProject2);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue