1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Bug 479138 - Allow index tests to specify that recursion resolving

bindings are allowed

Change-Id: I3a55cbb1062e8edf4b84920738c9d1cca02b65d6
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-11-26 21:29:11 -05:00 committed by Sergey Prigogin
parent c531b2d5e6
commit 9bcb71b26a

View file

@ -46,6 +46,7 @@ import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader; import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.CCoreInternals; import org.eclipse.cdt.internal.core.CCoreInternals;
import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer; import org.eclipse.cdt.internal.core.dom.parser.ITypeContainer;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTNameBase;
import org.eclipse.cdt.internal.core.pdom.PDOM; import org.eclipse.cdt.internal.core.pdom.PDOM;
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences; import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.cdt.internal.pdom.tests.PDOMPrettyPrinter; import org.eclipse.cdt.internal.pdom.tests.PDOMPrettyPrinter;
@ -379,7 +380,22 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
public boolean isCompositeIndex(); public boolean isCompositeIndex();
} }
class SinglePDOMTestFirstASTStrategy implements ITestStrategy { private abstract class BaseTestStrategy implements ITestStrategy {
// This method allows tests to specify test-specific flags by including special strings
// in the test source (presumably in a comment).
// Note that it would be insufficient for the tests to do the corresponding actions
// in the test body, because they may need to be done before the indexer runs.
protected void setTestSpecificFlags(String sourceContents) {
// Allow tests to specify that the code contained in the test is allowed to produce
// recursion resolving bidings.
if (sourceContents.contains("special:allowRecursionBindings")) {
System.out.println("setting sAllowRecursionBindings = true");
CPPASTNameBase.sAllowRecursionBindings = true;
}
}
}
class SinglePDOMTestFirstASTStrategy extends BaseTestStrategy {
private IIndex index; private IIndex index;
private ICProject cproject; private ICProject cproject;
private StringBuilder[] testData; private StringBuilder[] testData;
@ -431,7 +447,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
fail("Insufficient test data"); fail("Insufficient test data");
testData[1].insert(0, "#include \"header.h\" " + END_OF_ADDED_CODE_MARKER + "\n"); testData[1].insert(0, "#include \"header.h\" " + END_OF_ADDED_CODE_MARKER + "\n");
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), testData[0].toString()); String headerContents = testData[0].toString();
String sourceContents = testData[1].toString();
setTestSpecificFlags(sourceContents);
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), headerContents);
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
waitForIndexer(cproject); waitForIndexer(cproject);
@ -443,7 +464,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
index= CCorePlugin.getIndexManager().getIndex(cproject); index= CCorePlugin.getIndexManager().getIndex(cproject);
index.acquireReadLock(); index.acquireReadLock();
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString()); IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), sourceContents);
ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile); ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile);
} }
@ -468,7 +489,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
} }
} }
class SinglePDOMTestStrategy implements ITestStrategy { class SinglePDOMTestStrategy extends BaseTestStrategy {
private IIndex index; private IIndex index;
private ICProject cproject; private ICProject cproject;
private StringBuilder[] testData; private StringBuilder[] testData;
@ -520,11 +541,16 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
fail("Insufficient test data"); fail("Insufficient test data");
testData[1].insert(0, "#include \"header.h\" " + END_OF_ADDED_CODE_MARKER + "\n"); testData[1].insert(0, "#include \"header.h\" " + END_OF_ADDED_CODE_MARKER + "\n");
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), testData[0].toString()); String headerContents = testData[0].toString();
String sourceContents = testData[1].toString();
setTestSpecificFlags(sourceContents);
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), headerContents);
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
waitForIndexer(cproject); waitForIndexer(cproject);
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString()); IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), sourceContents);
waitForIndexer(cproject); waitForIndexer(cproject);
if (DEBUG) { if (DEBUG) {
@ -689,7 +715,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
} }
} }
class ReferencedProject implements ITestStrategy { class ReferencedProject extends BaseTestStrategy {
private IIndex index; private IIndex index;
private ICProject cproject, referenced; private ICProject cproject, referenced;
private StringBuilder[] testData; private StringBuilder[] testData;
@ -729,10 +755,14 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
fail("Insufficient test data"); fail("Insufficient test data");
testData[1].insert(0, "#include \"header.h\" " + END_OF_ADDED_CODE_MARKER + "\n"); testData[1].insert(0, "#include \"header.h\" " + END_OF_ADDED_CODE_MARKER + "\n");
String sourceContents = testData[1].toString();
setTestSpecificFlags(sourceContents);
referenced = createReferencedContent(); referenced = createReferencedContent();
TestScannerProvider.sIncludes= new String[] {referenced.getProject().getLocation().toOSString()}; TestScannerProvider.sIncludes= new String[] {referenced.getProject().getLocation().toOSString()};
IFile references= TestSourceReader.createFile(cproject.getProject(), new Path("refs.c" + (cpp ? "pp" : "")), testData[1].toString()); IFile references= TestSourceReader.createFile(cproject.getProject(), new Path("refs.c" + (cpp ? "pp" : "")), sourceContents);
IProject[] refs = new IProject[] {referenced.getProject()}; IProject[] refs = new IProject[] {referenced.getProject()};
IProjectDescription pd = cproject.getProject().getDescription(); IProjectDescription pd = cproject.getProject().getDescription();