mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Testcases for bug 172454, indexing typedef struct X {...} X;
This commit is contained in:
parent
a2f3ea6701
commit
b782b390c5
3 changed files with 104 additions and 15 deletions
|
@ -26,8 +26,11 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
import org.eclipse.cdt.core.dom.ast.IEnumeration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IType;
|
import org.eclipse.cdt.core.dom.ast.IType;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.c.ICCompositeTypeScope;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||||
import org.eclipse.cdt.core.index.IIndex;
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
@ -46,6 +49,7 @@ import org.eclipse.cdt.core.testplugin.TestScannerProvider;
|
||||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
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.Linkage;
|
||||||
import org.eclipse.core.resources.IContainer;
|
import org.eclipse.core.resources.IContainer;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
@ -57,6 +61,7 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
|
|
||||||
public class IndexBugsTests extends BaseTestCase {
|
public class IndexBugsTests extends BaseTestCase {
|
||||||
|
private static final int INDEX_WAIT_TIME = 8000;
|
||||||
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
private static final IProgressMonitor NPM = new NullProgressMonitor();
|
||||||
private ICProject fCProject;
|
private ICProject fCProject;
|
||||||
protected IIndex fIndex;
|
protected IIndex fIndex;
|
||||||
|
@ -95,7 +100,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void waitForIndexer() {
|
private void waitForIndexer() {
|
||||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(10000, NPM));
|
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEX_WAIT_TIME, NPM));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Pattern[] getPattern(String qname) {
|
protected Pattern[] getPattern(String qname) {
|
||||||
|
@ -125,7 +130,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
int indexOfDecl = content.indexOf(funcName);
|
int indexOfDecl = content.indexOf(funcName);
|
||||||
int indexOfDef = content.indexOf(funcName, indexOfDecl+1);
|
int indexOfDef = content.indexOf(funcName, indexOfDecl+1);
|
||||||
IFile file= createFile(getProject(), fileName, content);
|
IFile file= createFile(getProject(), fileName, content);
|
||||||
waitUntilFileIsIndexed(file, 1000);
|
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
// make sure the ast is correct
|
// make sure the ast is correct
|
||||||
ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path(fileName));
|
ITranslationUnit tu= (ITranslationUnit) fCProject.findElement(new Path(fileName));
|
||||||
|
@ -174,10 +179,10 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
content.append("unsigned int arrayDataSize = sizeof(arrayData);\n");
|
content.append("unsigned int arrayDataSize = sizeof(arrayData);\n");
|
||||||
int indexOfDecl = content.indexOf(varName);
|
int indexOfDecl = content.indexOf(varName);
|
||||||
|
|
||||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(80000, NPM));
|
assertTrue(CCorePlugin.getIndexManager().joinIndexer(INDEX_WAIT_TIME, NPM));
|
||||||
IFile file= createFile(getProject(), fileName, content.toString());
|
IFile file= createFile(getProject(), fileName, content.toString());
|
||||||
// must be done in a reasonable amount of time
|
// must be done in a reasonable amount of time
|
||||||
waitUntilFileIsIndexed(file, 10000);
|
waitUntilFileIsIndexed(file, INDEX_WAIT_TIME);
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
IIndexBinding[] bindings= fIndex.findBindings(getPattern("arrayDataSize"), true, IndexFilter.ALL, NPM);
|
IIndexBinding[] bindings= fIndex.findBindings(getPattern("arrayDataSize"), true, IndexFilter.ALL, NPM);
|
||||||
|
@ -201,7 +206,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
|
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
|
||||||
TestScannerProvider.sIncludeFiles= new String[]{include.getLocation().toOSString()};
|
TestScannerProvider.sIncludeFiles= new String[]{include.getLocation().toOSString()};
|
||||||
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
|
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
|
||||||
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
|
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
|
@ -231,7 +236,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
|
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
|
||||||
TestScannerProvider.sMacroFiles= new String[]{include.getLocation().toOSString()};
|
TestScannerProvider.sMacroFiles= new String[]{include.getLocation().toOSString()};
|
||||||
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
|
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
|
||||||
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
|
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
|
@ -263,7 +268,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
String content= getContentsForTest(1)[0].toString();
|
String content= getContentsForTest(1)[0].toString();
|
||||||
|
|
||||||
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164500.cpp", content);
|
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164500.cpp", content);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
|
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
fIndex.acquireReadLock();
|
fIndex.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
|
@ -296,7 +301,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
|
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
|
||||||
String content= getContentsForTest(1)[0].toString();
|
String content= getContentsForTest(1)[0].toString();
|
||||||
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
|
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(index, file, 8000);
|
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME);
|
||||||
CProjectHelper.delete(cproject);
|
CProjectHelper.delete(cproject);
|
||||||
|
|
||||||
cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER);
|
cproject = CProjectHelper.createCCProject(pname, "bin", IPDOMManager.ID_FAST_INDEXER);
|
||||||
|
@ -323,7 +328,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
|
IIndex index = CCorePlugin.getIndexManager().getIndex(cproject);
|
||||||
String content= getContentsForTest(1)[0].toString();
|
String content= getContentsForTest(1)[0].toString();
|
||||||
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
|
IFile file= TestSourceReader.createFile(cproject.getProject(), "content.cpp", content);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(index, file, 8000);
|
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
// move the project to a random new location
|
// move the project to a random new location
|
||||||
File newLocation = CProjectHelper.freshDir();
|
File newLocation = CProjectHelper.freshDir();
|
||||||
|
@ -360,7 +365,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
StringBuffer[] testData = getContentsForTest(3);
|
StringBuffer[] testData = getContentsForTest(3);
|
||||||
IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0].toString());
|
IFile header= TestSourceReader.createFile(cproject.getProject(), "header.h", testData[0].toString());
|
||||||
IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1].toString());
|
IFile referer= TestSourceReader.createFile(cproject.getProject(), "content.cpp", testData[1].toString());
|
||||||
TestSourceReader.waitUntilFileIsIndexed(index, referer, 8000);
|
TestSourceReader.waitUntilFileIsIndexed(index, referer, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
index.acquireReadLock();
|
index.acquireReadLock();
|
||||||
try {
|
try {
|
||||||
|
@ -375,7 +380,7 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
|
|
||||||
InputStream in = new ByteArrayInputStream(testData[2].toString().getBytes());
|
InputStream in = new ByteArrayInputStream(testData[2].toString().getBytes());
|
||||||
header.setContents(in, IResource.FORCE, null);
|
header.setContents(in, IResource.FORCE, null);
|
||||||
TestSourceReader.waitUntilFileIsIndexed(index, header, 8000);
|
TestSourceReader.waitUntilFileIsIndexed(index, header, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IBinding[] bindings = index.findBindings(Pattern.compile("var"), true, IndexFilter.ALL, new NullProgressMonitor());
|
IBinding[] bindings = index.findBindings(Pattern.compile("var"), true, IndexFilter.ALL, new NullProgressMonitor());
|
||||||
|
@ -390,4 +395,74 @@ public class IndexBugsTests extends BaseTestCase {
|
||||||
CProjectHelper.delete(cproject);
|
CProjectHelper.delete(cproject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// typedef struct S20070201 {
|
||||||
|
// int a;
|
||||||
|
// } S20070201;
|
||||||
|
public void test172454_1() throws Exception {
|
||||||
|
waitForIndexer();
|
||||||
|
String content= getContentsForTest(1)[0].toString();
|
||||||
|
|
||||||
|
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.c", content);
|
||||||
|
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IBinding[] bindings= fIndex.findInGlobalScope(Linkage.C_LINKAGE, "S20070201".toCharArray());
|
||||||
|
assertEquals(2, bindings.length);
|
||||||
|
|
||||||
|
IBinding struct, typedef;
|
||||||
|
if (bindings[0] instanceof ICCompositeTypeScope) {
|
||||||
|
struct= bindings[0];
|
||||||
|
typedef= bindings[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
struct= bindings[1];
|
||||||
|
typedef= bindings[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(struct instanceof ICompositeType);
|
||||||
|
assertTrue(typedef instanceof ITypedef);
|
||||||
|
assertTrue(((ITypedef) typedef).getType() instanceof ICCompositeTypeScope);
|
||||||
|
assertTrue(((ITypedef) typedef).isSameType((ICompositeType) struct));
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// typedef struct S20070201 {
|
||||||
|
// int a;
|
||||||
|
// } S20070201;
|
||||||
|
public void test172454_2() throws Exception {
|
||||||
|
waitForIndexer();
|
||||||
|
String content= getContentsForTest(1)[0].toString();
|
||||||
|
|
||||||
|
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test172454.cpp", content);
|
||||||
|
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
|
||||||
|
|
||||||
|
fIndex.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IBinding[] bindings= fIndex.findInGlobalScope(Linkage.CPP_LINKAGE, "S20070201".toCharArray());
|
||||||
|
assertEquals(2, bindings.length);
|
||||||
|
|
||||||
|
IBinding struct, typedef;
|
||||||
|
if (bindings[0] instanceof ICCompositeTypeScope) {
|
||||||
|
struct= bindings[0];
|
||||||
|
typedef= bindings[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
struct= bindings[1];
|
||||||
|
typedef= bindings[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
assertTrue(struct instanceof ICompositeType);
|
||||||
|
assertTrue(typedef instanceof ITypedef);
|
||||||
|
assertTrue(((ITypedef) typedef).getType() instanceof ICCompositeTypeScope);
|
||||||
|
assertTrue(((ITypedef) typedef).isSameType((ICompositeType) struct));
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
fIndex.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ILinkage;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||||
import org.eclipse.cdt.core.dom.ast.IBinding;
|
import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
import org.eclipse.cdt.core.dom.ast.IPointerType;
|
||||||
|
@ -21,7 +22,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||||
import org.eclipse.cdt.internal.core.dom.Linkage;
|
|
||||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
|
@ -73,7 +73,7 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testOverloadedInCommonHeader_FileScope() throws CoreException {
|
public void testOverloadedInCommonHeader_FileScope() throws CoreException {
|
||||||
Pattern[] QuuxPath = makePatternArray(new String[] {"quux"});
|
Pattern[] QuuxPath = makePatternArray(new String[] {"quux"});
|
||||||
IBinding[] Quux = pdom.findBindings(QuuxPath, true, IndexFilter.getFilter(Linkage.CPP_LINKAGE), new NullProgressMonitor());
|
IBinding[] Quux = pdom.findBindings(QuuxPath, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor());
|
||||||
|
|
||||||
assertEquals(5,Quux.length);
|
assertEquals(5,Quux.length);
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testOverloadedInCommonHeader_NamespaceScope() throws CoreException {
|
public void testOverloadedInCommonHeader_NamespaceScope() throws CoreException {
|
||||||
Pattern[] GraultPath = makePatternArray(new String[] {"corge","grault"});
|
Pattern[] GraultPath = makePatternArray(new String[] {"corge","grault"});
|
||||||
IBinding[] Grault = pdom.findBindings(GraultPath, true, IndexFilter.getFilter(Linkage.CPP_LINKAGE), new NullProgressMonitor());
|
IBinding[] Grault = pdom.findBindings(GraultPath, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor());
|
||||||
assertEquals(5,Grault.length);
|
assertEquals(5,Grault.length);
|
||||||
|
|
||||||
// corge::grault()
|
// corge::grault()
|
||||||
|
@ -116,7 +116,7 @@ public class OverloadsWithinCommonHeaderTests extends PDOMTestBase {
|
||||||
|
|
||||||
public void testOverloadedInCommonHeader_NamespaceScope_Collides_With_Filescope() throws CoreException {
|
public void testOverloadedInCommonHeader_NamespaceScope_Collides_With_Filescope() throws CoreException {
|
||||||
Pattern[] ns2Path = makePatternArray(new String[] {"ns2","quux"});
|
Pattern[] ns2Path = makePatternArray(new String[] {"ns2","quux"});
|
||||||
IBinding[] ns2 = pdom.findBindings(ns2Path, true, IndexFilter.getFilter(Linkage.CPP_LINKAGE), new NullProgressMonitor());
|
IBinding[] ns2 = pdom.findBindings(ns2Path, true, IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), new NullProgressMonitor());
|
||||||
assertEquals(5,ns2.length);
|
assertEquals(5,ns2.length);
|
||||||
|
|
||||||
// ns2::quux()
|
// ns2::quux()
|
||||||
|
|
|
@ -30,6 +30,20 @@ import org.eclipse.cdt.core.dom.ast.IBinding;
|
||||||
public class IndexFilter {
|
public class IndexFilter {
|
||||||
public static final IndexFilter ALL = new IndexFilter();
|
public static final IndexFilter ALL = new IndexFilter();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an IndexFilter that filters out bindings from linkages other than that
|
||||||
|
* specified
|
||||||
|
* @param linkageID the id of the linkage whose bindings should be retained
|
||||||
|
* @return an IndexFilter instance
|
||||||
|
*/
|
||||||
|
public static IndexFilter getFilter(final String linkageID) {
|
||||||
|
return new IndexFilter() {
|
||||||
|
public boolean acceptLinkage(ILinkage linkage) {
|
||||||
|
return linkageID.equals(linkage.getID());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an IndexFilter that filters out bindings from linkages other than that
|
* Get an IndexFilter that filters out bindings from linkages other than that
|
||||||
* specified
|
* specified
|
||||||
|
|
Loading…
Add table
Reference in a new issue