1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-04 06:45:43 +02:00

Adds testcase for bug 173997, typedef definitions in index.

This commit is contained in:
Markus Schorn 2007-02-13 13:13:37 +00:00
parent 88faee0afe
commit 4386f43881
2 changed files with 55 additions and 1 deletions

View file

@ -26,6 +26,7 @@ import org.eclipse.cdt.core.dom.IName;
import org.eclipse.cdt.core.dom.IPDOMManager; 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.IBasicType;
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.ICompositeType;
import org.eclipse.cdt.core.dom.ast.IEnumeration; import org.eclipse.cdt.core.dom.ast.IEnumeration;
@ -488,4 +489,53 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.releaseReadLock(); fIndex.releaseReadLock();
} }
} }
// typedef int T20070213;
public void _test173997() throws Exception {
waitForIndexer();
String content= getContentsForTest(1)[0].toString();
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
fIndex.acquireReadLock();
try {
IBinding[] bindings= fIndex.findBindings("T20070213".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM);
assertEquals(1, bindings.length);
assertTrue(bindings[0] instanceof ITypedef);
ITypedef td= (ITypedef) bindings[0];
IType type= td.getType();
assertTrue(type instanceof IBasicType);
IBasicType btype= (IBasicType) type;
assertEquals(IBasicType.t_int, btype.getType());
}
finally {
fIndex.releaseReadLock();
}
long timestamp= file.getLocalTimeStamp();
content= "int UPDATED20070213;\n" + content.replaceFirst("int", "float");
file= TestSourceReader.createFile(fCProject.getProject(), "test173997.cpp", content);
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, INDEX_WAIT_TIME);
fIndex.acquireReadLock();
try {
// double check if file was indexed
IBinding[] bindings= fIndex.findBindings("UPDATED20070213".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM);
assertEquals(1, bindings.length);
bindings= fIndex.findBindings("T20070213".toCharArray(), IndexFilter.getFilter(ILinkage.CPP_LINKAGE_ID), NPM);
assertEquals(1, bindings.length);
assertTrue(bindings[0] instanceof ITypedef);
ITypedef td= (ITypedef) bindings[0];
IType type= td.getType();
assertTrue(type instanceof IBasicType);
IBasicType btype= (IBasicType) type;
assertTrue(IBasicType.t_int != btype.getType());
assertEquals(IBasicType.t_float, btype.getType());
}
finally {
fIndex.releaseReadLock();
}
}
} }

View file

@ -220,7 +220,11 @@ public class TestSourceReader {
InputStream stream = new ByteArrayInputStream(contents.getBytes()); InputStream stream = new ByteArrayInputStream(contents.getBytes());
//Create file input stream //Create file input stream
if (file.exists()) { if (file.exists()) {
long timestamp= file.getLocalTimeStamp();
file.setContents(stream, false, false, new NullProgressMonitor()); file.setContents(stream, false, false, new NullProgressMonitor());
if (file.getLocalTimeStamp() == timestamp) {
file.setLocalTimeStamp(timestamp+1000);
}
} }
else { else {
file.create(stream, false, new NullProgressMonitor()); file.create(stream, false, new NullProgressMonitor());