From 0f1f113134a3afb9cf4277030075b9b4726af178 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Tue, 3 Apr 2007 15:39:37 +0000 Subject: [PATCH] 180738: add test case --- .../tests/IndexBindingResolutionTestBase.java | 34 +++++++++++- .../tests/IndexCPPBindingResolutionTest.java | 55 ++++++++++++++++++- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 8dee4edca2e..fc1c1fdf260 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.internal.index.tests; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.eclipse.cdt.core.CCorePlugin; 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); } + /** + * 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; i1 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) { IASTName[] names= findNames(section, len); 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())); } + 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 { 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())); // 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.acquireReadLock(); @@ -296,7 +326,7 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { //System.out.println("Referenced: "+getName()); 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; } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java index facc52ac44a..05d50cf73d8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java @@ -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.ICPPBinding; 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.ICPPField; 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.ICPPPointerToMemberType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.parser.util.ObjectMap; 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 * expected (type,name,etc..) */ -public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { +public class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase { public static class SingleProject extends IndexCPPBindingResolutionTest { public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} @@ -73,6 +76,56 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti IBinding b0 = getBindingFromASTName("sanity();", 6); IBinding b1 = getBindingFromASTName("left(a,b)", 4); } + + // //header file + // + // template + // class Foo {}; + // + // class B {}; + // + // template<> + // class Foo {}; + + // Foo b1; + // + // class A {}; + // + // template<> + // class Foo {}; + // + // Foo b2; + public void _testClassSpecializationInHeader() { + IBinding b1a = getBindingFromASTName("Foo b1;", 3); + IBinding b1b = getBindingFromASTNameWithRawSignature("Foo b1;", "Foo"); + + 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 b2;", 3); + IBinding b2b = getBindingFromASTNameWithRawSignature("Foo b2;", "Foo"); + + 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 // class Base {public: int field; void foo() {}};