1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

Failing test case for bug 253080.

This commit is contained in:
Sergey Prigogin 2008-11-08 19:28:02 +00:00
parent f7adcb4979
commit a28d15d9cc
2 changed files with 85 additions and 16 deletions

View file

@ -144,12 +144,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
protected static void assertQNEquals(String expectedQN, IBinding b) {
try {
assertInstance(b, IBinding.class);
if(b instanceof ICPPBinding) {
if (b instanceof ICPPBinding) {
assertEquals(expectedQN, CPPVisitor.renderQualifiedName(((ICPPBinding)b).getQualifiedName()));
} else {
assertEquals(expectedQN, b.getName());
}
} catch(DOMException de) {
} catch (DOMException de) {
fail(de.getMessage());
}
}
@ -183,7 +183,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) {
assertNotNull("Expected "+clazz.getName()+" but got null", o);
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o));
for(Class c : cs) {
for (Class c : cs) {
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
}
return clazz.cast(o);
@ -213,12 +213,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IVariable variable = (IVariable) b;
assertQNEquals(qn, variable);
assertInstance(variable.getType(), expType);
if(expTypeQN!=null) {
if (expTypeQN != null) {
IType type= variable.getType();
assertInstance(type, IBinding.class);
assertQNEquals(expTypeQN, (IBinding) type);
}
} catch(DOMException de) {
} catch (DOMException de) {
fail(de.getMessage());
}
}
@ -229,11 +229,11 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
assertInstance(conType, containerType);
IType containedType= ((ITypeContainer)conType).getType();
assertInstance(containedType, expContainedType);
if(expContainedTypeQN!=null) {
if (expContainedTypeQN != null) {
assertInstance(containedType, IBinding.class);
assertQNEquals(expContainedTypeQN, (IBinding) containedType);
}
} catch(DOMException de) {
} catch (DOMException de) {
fail(de.getMessage());
}
}
@ -274,7 +274,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
IFile cppfile= TestSourceReader.createFile(cproject.getProject(), new Path("references.c" + (cpp ? "pp" : "")), testData[1].toString());
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if(DEBUG) {
if (DEBUG) {
System.out.println("Project PDOM: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
}
@ -286,7 +286,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
public void tearDown() throws Exception {
if(index != null) {
if (index != null) {
index.releaseReadLock();
}
if (cproject != null) {
@ -319,7 +319,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
}
public void tearDown() throws Exception {
if(index != null) {
if (index != null) {
index.releaseReadLock();
}
if (cproject != null) {
@ -350,7 +350,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
CCorePlugin.getIndexManager().reindex(cproject);
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if(DEBUG) {
if (DEBUG) {
System.out.println("Online: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
}
@ -372,7 +372,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
if(DEBUG) {
if (DEBUG) {
System.out.println("Referenced: "+getName());
((PDOM)CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter());
}
@ -404,7 +404,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
* quite rare.
*/
protected void fakeFailForSingle() {
if(getName().startsWith("_") && strategy instanceof SinglePDOMTestStrategy) {
if (getName().startsWith("_") && strategy instanceof SinglePDOMTestStrategy) {
fail("Artificially failing - see IndexBindingResolutionTestBase.fakeFailForSingle()");
}
}
@ -416,7 +416,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
* quite rare.
*/
protected void fakeFailForMultiProject() {
if(getName().startsWith("_") && strategy instanceof ReferencedProject) {
if (getName().startsWith("_") && strategy instanceof ReferencedProject) {
fail("Artificially failing - see IndexBindingResolutionTestBase.fakeFailForReferenced()");
}
}

View file

@ -37,10 +37,12 @@ import org.eclipse.cdt.core.dom.ast.IEnumeration;
import org.eclipse.cdt.core.dom.ast.IEnumerator;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
@ -141,6 +143,46 @@ public class IndexBugsTests extends BaseTestCase {
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, time);
}
/**
* Attempts to get an IBinding from the initial specified number of characters
* from the specified code fragment. Fails the test if
* <ul>
* <li> There is not a unique name with the specified criteria
* <li> The binding associated with the name is null or a problem binding
* <li> The binding is not an instance of the specified class
* </ul>
* @param ast the AST to test.
* @param source the source code corresponding to the AST.
* @param section the code fragment to search for in the AST. The first occurrence of
* an identical section is used.
* @param len the length of the specified section to use as a name. This can also be useful
* for distinguishing between template names, and template ids.
* @param clazz an expected class type or interface that the binding should extend/implement
* @return the associated name's binding
*/
protected <T> T getBindingFromASTName(IASTTranslationUnit ast, String source, String section, int len,
Class<T> clazz, Class ... cs) {
IASTName name= ast.getNodeSelector(null).findName(source.indexOf(section), len);
assertNotNull("name not found for \""+section+"\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
IBinding binding = name.resolveBinding();
assertNotNull("No binding for "+name.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name "+name.getRawSignature(),
IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
assertInstance(binding, clazz, cs);
return clazz.cast(binding);
}
protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) {
assertNotNull("Expected "+clazz.getName()+" but got null", o);
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o));
for (Class c : cs) {
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
}
return clazz.cast(o);
}
// class A {
// public:
// void one() {}
@ -555,6 +597,34 @@ public class IndexBugsTests extends BaseTestCase {
}
}
// // header.h
// template <class T> class Test {};
// #include "header.h"
// struct A {};
// Test<A> a;
// template <class U> class Test;
public void _test253080() throws Exception {
waitForIndexer();
String[] testData = getContentsForTest(3);
IFile header= TestSourceReader.createFile(fCProject.getProject(), "header.h", testData[0]);
IFile test= TestSourceReader.createFile(fCProject.getProject(), "test.cpp", testData[1]);
IFile unrelated= TestSourceReader.createFile(fCProject.getProject(), "unrelated.cpp", testData[2]);
final IIndexManager indexManager = CCorePlugin.getIndexManager();
indexManager.reindex(fCProject);
waitForIndexer();
IIndex index= indexManager.getIndex(fCProject);
index.acquireReadLock();
try {
IASTTranslationUnit ast = TestSourceReader.createIndexBasedAST(index, fCProject, test);
ICPPTemplateInstance b0= getBindingFromASTName(ast, testData[1], "Test<A>", 7, ICPPTemplateInstance.class);
} finally {
index.releaseReadLock();
}
}
// typedef struct S20070201 {
// int a;
// } S20070201;
@ -1238,8 +1308,7 @@ public class IndexBugsTests extends BaseTestCase {
waitForIndexer();
fIndex.acquireReadLock();
try {
IIndexBinding[] bindings = fIndex
.findBindings("ok".toCharArray(), IndexFilter.ALL, NPM);
IIndexBinding[] bindings = fIndex.findBindings("ok".toCharArray(), IndexFilter.ALL, NPM);
assertEquals(1, bindings.length);
} finally {
fIndex.releaseReadLock();