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

180738: add test case

This commit is contained in:
Andrew Ferguson 2007-04-03 15:39:37 +00:00
parent 39d2e909be
commit 0f1f113134
2 changed files with 86 additions and 3 deletions

View file

@ -12,6 +12,8 @@
package org.eclipse.cdt.internal.index.tests; package org.eclipse.cdt.internal.index.tests;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.IPDOMManager; import org.eclipse.cdt.core.dom.IPDOMManager;
@ -86,6 +88,29 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
return language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len); return language.getSelectedNames(ast, strategy.getTestData()[1].indexOf(section), len);
} }
/**
* Matching against a length of text can return several names, we use the RawSignature to
* disambiguate between them
* @param section
* @param rawSig
* @return
*/
protected IBinding getBindingFromASTNameWithRawSignature(String section, String rawSig) {
IASTName[] names= findNames(section, rawSig.length());
List matchSignature= new ArrayList();
for(int i=0; i<names.length; i++) {
if(rawSig.equals(names[i].getRawSignature())) {
matchSignature.add(names[i]);
}
}
assertTrue("<>1 names found for \""+section+"\" with signature "+rawSig, matchSignature.size()==1);
IASTName aname= (IASTName) matchSignature.get(0);
IBinding binding = aname.resolveBinding();
assertNotNull("No binding for "+aname.getRawSignature(), binding);
assertFalse("Binding is a ProblemBinding for name "+aname.getRawSignature(), IProblemBinding.class.isAssignableFrom(names[0].resolveBinding().getClass()));
return aname.resolveBinding();
}
protected IBinding getBindingFromASTName(String section, int len) { protected IBinding getBindingFromASTName(String section, int len) {
IASTName[] names= findNames(section, len); IASTName[] names= findNames(section, len);
assertEquals("<>1 name found for \""+section+"\"", 1, names.length); assertEquals("<>1 name found for \""+section+"\"", 1, names.length);
@ -151,6 +176,11 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
assertEquals(qn, CPPVisitor.renderQualifiedName(((ICPPClassType)ft.getParameterTypes()[index]).getQualifiedName())); assertEquals(qn, CPPVisitor.renderQualifiedName(((ICPPClassType)ft.getParameterTypes()[index]).getQualifiedName()));
} }
protected void assertInstance(Object o, Class c) {
assertNotNull(o);
assertTrue("Expected "+c.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
}
protected String readTaggedComment(final String tag) throws IOException { protected String readTaggedComment(final String tag) throws IOException {
return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag); return TestSourceReader.readTaggedComment(CTestPlugin.getDefault().getBundle(), "parser", getClass(), tag);
} }
@ -277,7 +307,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
// System.out.println("Online: "+getName()); // System.out.println("Online: "+getName());
// ((PDOM)CCorePlugin.getIndexManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter()); // ((PDOM)CCoreInternals.getPDOMManager().getPDOM(cproject)).accept(new PDOMPrettyPrinter());
index= CCorePlugin.getIndexManager().getIndex(cproject); index= CCorePlugin.getIndexManager().getIndex(cproject);
index.acquireReadLock(); index.acquireReadLock();
@ -296,7 +326,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
//System.out.println("Referenced: "+getName()); //System.out.println("Referenced: "+getName());
assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor()));
//((PDOM)CCorePlugin.getIndexManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter()); // ((PDOM)CCoreInternals.getPDOMManager().getPDOM(referenced)).accept(new PDOMPrettyPrinter());
return referenced; return referenced;
} }

View file

@ -27,13 +27,16 @@ import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
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.ICPPField; import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope; import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
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;
import org.eclipse.cdt.core.parser.util.ObjectMap;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
/** /**
@ -44,7 +47,7 @@ import org.eclipse.core.runtime.CoreException;
* additionally check that the binding obtained has characteristics as * additionally check that the binding obtained has characteristics as
* expected (type,name,etc..) * expected (type,name,etc..)
*/ */
public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase {
public static class SingleProject extends IndexCPPBindingResolutionTest { public static class SingleProject extends IndexCPPBindingResolutionTest {
public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));}
@ -73,6 +76,56 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
IBinding b0 = getBindingFromASTName("sanity();", 6); IBinding b0 = getBindingFromASTName("sanity();", 6);
IBinding b1 = getBindingFromASTName("left(a,b)", 4); IBinding b1 = getBindingFromASTName("left(a,b)", 4);
} }
// //header file
//
// template<typename T>
// class Foo {};
//
// class B {};
//
// template<>
// class Foo<B> {};
// Foo<B> b1;
//
// class A {};
//
// template<>
// class Foo<A> {};
//
// Foo<B> b2;
public void _testClassSpecializationInHeader() {
IBinding b1a = getBindingFromASTName("Foo<B> b1;", 3);
IBinding b1b = getBindingFromASTNameWithRawSignature("Foo<B> b1;", "Foo<B>");
assertInstance(b1a, ICPPClassType.class);
assertInstance(b1a, ICPPClassTemplate.class);
assertInstance(b1b, ICPPClassType.class);
assertInstance(b1b, ICPPSpecialization.class);
ICPPSpecialization b1spc= (ICPPSpecialization) b1b;
ObjectMap b1om= b1spc.getArgumentMap();
assertEquals(1, b1om.keyArray().length);
assertInstance(b1om.getAt(0), ICPPClassType.class);
ICPPClassType b1pct= (ICPPClassType) b1om.getAt(0);
assertEquals("B", b1pct.getName());
IBinding b2a = getBindingFromASTName("Foo<B> b2;", 3);
IBinding b2b = getBindingFromASTNameWithRawSignature("Foo<B> b2;", "Foo<B>");
assertInstance(b2a, ICPPClassType.class);
assertInstance(b2a, ICPPClassTemplate.class);
assertInstance(b2b, ICPPClassType.class);
assertInstance(b2b, ICPPSpecialization.class);
ICPPSpecialization b2spc= (ICPPSpecialization) b2b;
ObjectMap b2om= b2spc.getArgumentMap();
assertEquals(1, b2om.keyArray().length);
assertInstance(b2om.getAt(0), ICPPClassType.class);
ICPPClassType b2pct= (ICPPClassType) b2om.getAt(0);
assertEquals("B", b2pct.getName());
}
// // header file // // header file
// class Base {public: int field; void foo() {}}; // class Base {public: int field; void foo() {}};