1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 19:25:38 +02:00

Clean up usage of TestScannerProvider within the tests.

This commit is contained in:
Markus Schorn 2007-07-20 10:02:03 +00:00
parent 61c38d0f85
commit f6b7c739ba
9 changed files with 105 additions and 110 deletions

View file

@ -58,7 +58,6 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -75,18 +74,18 @@ public class IndexBugsTests extends BaseTestCase {
return suite(IndexBugsTests.class); 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); fCProject= CProjectHelper.createCCProject("__bugsTest__", "bin", IPDOMManager.ID_FAST_INDEXER);
CCorePlugin.getIndexManager().reindex(fCProject); CCorePlugin.getIndexManager().reindex(fCProject);
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject); fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
} }
protected void tearDown() throws CoreException { protected void tearDown() throws Exception {
TestScannerProvider.sIncludeFiles= TestScannerProvider.sIncludes=
TestScannerProvider.sMacroFiles= null;
if (fCProject != null) { if (fCProject != null) {
CProjectHelper.delete(fCProject); CProjectHelper.delete(fCProject);
} }
super.tearDown();
} }
protected IProject getProject() { protected IProject getProject() {

View file

@ -68,7 +68,6 @@ public class IndexIncludeTest extends IndexTestBase {
} }
public void tearDown() throws Exception { public void tearDown() throws Exception {
TestScannerProvider.sIncludes= null;
super.tearDown(); super.tearDown();
} }
@ -156,113 +155,93 @@ public class IndexIncludeTest extends IndexTestBase {
public void testIncludeProperties() throws Exception { public void testIncludeProperties() throws Exception {
waitForIndexer(); waitForIndexer();
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
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 { try {
String content= readTaggedComment("source20061107"); IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
TestSourceReader.createFile(fProject.getProject(), "user20061107.h", ""); assertNotNull(ifile);
TestSourceReader.createFile(fProject.getProject(), "system20061107.h", ""); IIndexInclude[] includes= ifile.getIncludes();
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", content); assertEquals(2, includes.length);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
fIndex.acquireReadLock(); checkInclude(includes[0], content, "user20061107.h", false);
try { checkInclude(includes[1], content, "system20061107.h", true);
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();
}
} }
finally { finally {
TestScannerProvider.sIncludes= null; fIndex.releaseReadLock();
} }
} }
public void testIncludeProperties_2() throws Exception { public void testIncludeProperties_2() throws Exception {
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()};
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 { try {
TestSourceReader.createFile(fProject.getProject(), "header20061107.h", ""); IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
String content = "// comment \n#include \"header20061107.h\"\n"; assertNotNull(ifile);
IFile file= TestSourceReader.createFile(fProject.getProject(), "intermed20061107.h", content); IIndexInclude[] includes= ifile.getIncludes();
TestSourceReader.createFile(fProject.getProject(), "source20061107.cpp", "#include \"intermed20061107.h\"\n"); assertEquals(1, includes.length);
CCorePlugin.getIndexManager().reindex(fProject);
waitForIndexer();
checkInclude(includes[0], content, "header20061107.h", false);
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();
}
} }
finally { finally {
TestScannerProvider.sIncludes= null; fIndex.releaseReadLock();
} }
} }
public void testInactiveInclude() throws Exception { public void testInactiveInclude() throws Exception {
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; 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 { try {
String content = "#if 0\n#include \"inactive20070213.h\"\n#endif\n"; IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070213.cpp", content); assertNotNull(ifile);
CCorePlugin.getIndexManager().reindex(fProject); IIndexInclude[] includes= ifile.getIncludes();
waitForIndexer(); assertEquals(1, includes.length);
fIndex.acquireReadLock(); assertFalse(includes[0].isActive());
try { checkInclude(includes[0], content, "inactive20070213.h", false);
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();
}
} }
finally { finally {
TestScannerProvider.sIncludes= null; fIndex.releaseReadLock();
} }
} }
public void testUnresolvedInclude() throws Exception { public void testUnresolvedInclude() throws Exception {
TestScannerProvider.sIncludes= new String[]{fProject.getProject().getLocation().toOSString()}; 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 { try {
String content = "#include \"unresolved20070213.h\"\n"; IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file));
IFile file= TestSourceReader.createFile(fProject.getProject(), "source20070214.cpp", content); assertNotNull(ifile);
CCorePlugin.getIndexManager().reindex(fProject); IIndexInclude[] includes= ifile.getIncludes();
waitForIndexer(); assertEquals(1, includes.length);
fIndex.acquireReadLock(); assertTrue(includes[0].isActive());
try { assertFalse(includes[0].isResolved());
IIndexFile ifile= fIndex.getFile(IndexLocationFactory.getWorkspaceIFL(file)); checkInclude(includes[0], content, "unresolved20070213.h", false);
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();
}
} }
finally { finally {
TestScannerProvider.sIncludes= null; fIndex.releaseReadLock();
} }
} }

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
@ -40,6 +40,7 @@ public class TrilogyPerformanceTest extends IndexTestBase {
} }
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp();
Bundle b = CTestPlugin.getDefault().getBundle(); Bundle b = CTestPlugin.getDefault().getBundle();
if (cproject == null) { if (cproject == null) {
cproject= createProject(true, "resources/indexTests/trilogy"); cproject= createProject(true, "resources/indexTests/trilogy");
@ -48,6 +49,7 @@ public class TrilogyPerformanceTest extends IndexTestBase {
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
cproject.getProject().delete(true, new NullProgressMonitor()); cproject.getProject().delete(true, new NullProgressMonitor());
super.tearDown();
} }
// you must have the Windows SDK installed and the INETSDK env var setup // 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)) { if(Platform.getOS().equals(Platform.OS_WIN32)) {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
TestScannerProvider.sIncludes = new String[]{EnvironmentReader.getEnvVar("INETSDK")+"\\Include"}; TestScannerProvider.sIncludes = new String[]{EnvironmentReader.getEnvVar("INETSDK")+"\\Include"};
try { IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true");
IndexerPreferences.set(cproject.getProject(), IndexerPreferences.KEY_INDEX_ALL_FILES, "true"); long start = System.currentTimeMillis();
long start = System.currentTimeMillis(); CCorePlugin.getIndexManager().reindex(cproject);
CCorePlugin.getIndexManager().reindex(cproject); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); System.out.println("Took: "+(System.currentTimeMillis() - start));
System.out.println("Took: "+(System.currentTimeMillis() - start)); IIndex index= CCorePlugin.getIndexManager().getIndex(cproject);
IIndex index= CCorePlugin.getIndexManager().getIndex(cproject); IBinding[] binding = index.findBindings(Pattern.compile("IXMLElementCollection"), false, IndexFilter.ALL, new NullProgressMonitor());
IBinding[] binding = index.findBindings(Pattern.compile("IXMLElementCollection"), false, IndexFilter.ALL, new NullProgressMonitor()); assertEquals(1, binding.length);
assertEquals(1, binding.length);
} finally {
TestScannerProvider.sIncludes = null;
}
} }
} }
} }

View file

@ -24,6 +24,10 @@ public class TestScannerProvider extends AbstractCExtension implements IScannerI
public static String[] sMacroFiles= null; public static String[] sMacroFiles= null;
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner"; public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner";
public static void clear() {
sIncludes= sIncludeFiles= sMacroFiles= null;
}
public IScannerInfo getScannerInformation(IResource resource) { public IScannerInfo getScannerInformation(IResource resource) {
return new TestScannerInfo(sIncludes, sIncludeFiles, sMacroFiles); return new TestScannerInfo(sIncludes, sIncludeFiles, sMacroFiles);
} }

View file

@ -32,6 +32,7 @@ import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent; import org.eclipse.cdt.core.model.ElementChangedEvent;
import org.eclipse.cdt.core.model.IElementChangedListener; 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.CoreException;
import org.eclipse.core.runtime.ILogListener; import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -53,6 +54,13 @@ public class BaseTestCase extends TestCase {
super(name); super(name);
} }
protected void setUp() throws Exception {
}
protected void tearDown() throws Exception {
TestScannerProvider.clear();
}
protected static TestSuite suite(Class clazz) { protected static TestSuite suite(Class clazz) {
return suite(clazz, null); return suite(clazz, null);
} }

View file

@ -53,7 +53,6 @@ public class CallHierarchyAcrossProjectsTest extends CallHierarchyBaseTest {
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
TestScannerProvider.sIncludes= null;
if (fCProject2 != null) { if (fCProject2 != null) {
CProjectHelper.delete(fCProject2); CProjectHelper.delete(fCProject2);
} }

View file

@ -12,7 +12,6 @@
package org.eclipse.cdt.ui.tests.includebrowser; package org.eclipse.cdt.ui.tests.includebrowser;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.Tree;
@ -44,7 +43,8 @@ public class IncludeBrowserBaseTest extends BaseUITestCase {
super(name); super(name);
} }
protected void setUp() throws CoreException { protected void setUp() throws Exception {
super.setUp();
fCProject= CProjectHelper.createCCProject("__ibTest__", "bin", IPDOMManager.ID_FAST_INDEXER); fCProject= CProjectHelper.createCCProject("__ibTest__", "bin", IPDOMManager.ID_FAST_INDEXER);
// clear the index // clear the index
@ -52,10 +52,11 @@ public class IncludeBrowserBaseTest extends BaseUITestCase {
fIndex= CCorePlugin.getIndexManager().getIndex(fCProject); fIndex= CCorePlugin.getIndexManager().getIndex(fCProject);
} }
protected void tearDown() throws CoreException { protected void tearDown() throws Exception {
if (fCProject != null) { if (fCProject != null) {
CProjectHelper.delete(fCProject); CProjectHelper.delete(fCProject);
} }
super.tearDown();
} }
protected ICProject getProject() { protected ICProject getProject() {

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Andrew Ferguson (Symbian) - Initial implementation * Andrew Ferguson (Symbian) - Initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.ui.tests.search; package org.eclipse.cdt.ui.tests.search;
@ -58,6 +59,7 @@ public class BasicSearchTest extends BaseUITestCase {
} }
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp();
fCProject = CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER); fCProject = CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
Bundle b = CTestPlugin.getDefault().getBundle(); Bundle b = CTestPlugin.getDefault().getBundle();
testData = TestSourceReader.getContentsForTest(b, "ui", this.getClass(), getName(), 2); testData = TestSourceReader.getContentsForTest(b, "ui", this.getClass(), getName(), 2);
@ -74,6 +76,7 @@ public class BasicSearchTest extends BaseUITestCase {
if(fCProject != null) { if(fCProject != null) {
fCProject.getProject().delete(true, NPM); fCProject.getProject().delete(true, NPM);
} }
super.tearDown();
} }
// // empty // // empty
@ -110,14 +113,19 @@ public class BasicSearchTest extends BaseUITestCase {
ILabelProvider labpv= (ILabelProvider) viewer.getLabelProvider(); ILabelProvider labpv= (ILabelProvider) viewer.getLabelProvider();
IStructuredContentProvider scp= (IStructuredContentProvider) viewer.getContentProvider(); IStructuredContentProvider scp= (IStructuredContentProvider) viewer.getContentProvider();
Object result0= result.getElements()[0]; String label0= labpv.getText(scp.getElements(result)[0]);
Object result1= result.getElements()[1]; 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 // check the results are rendered
String expected0= fCProject.getProject().getName(); String expected0= fCProject.getProject().getName();
String expected1= new Path(externalFile.getAbsolutePath()).toString(); String expected1= new Path(externalFile.getAbsolutePath()).toString();
assertEquals(expected0,labpv.getText(scp.getElements(result)[0])); assertEquals(expected0,label0);
assertEquals(expected1,labpv.getText(scp.getElements(result)[1])); assertEquals(expected1,label1);
} }
/** /**

View file

@ -58,7 +58,6 @@ public class TypeHierarchyAcrossProjectsTest extends TypeHierarchyBaseTest {
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
TestScannerProvider.sIncludes= null;
if (fCProject2 != null) { if (fCProject2 != null) {
CProjectHelper.delete(fCProject2); CProjectHelper.delete(fCProject2);
} }