From 3840ecf1563d7b969c9d2bd75219f0309495c77c Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Thu, 31 May 2007 10:36:15 +0000 Subject: [PATCH] 188274: add a testcase for the reported CCE, plus a testcase for a related failure --- .../tests/IndexBindingResolutionTestBase.java | 12 +++++ .../tests/IndexCPPBindingResolutionBugs.java | 50 ++++++++++++++++--- .../tests/IndexCPPTemplateResolutionTest.java | 48 ++++++++++++++++++ 3 files changed, 102 insertions(+), 8 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 a6b3e2d91cc..dff1780f5b2 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 @@ -397,4 +397,16 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase { return true; } } + + /** + * When a test is failing only for the strategy where the test data is split over + * multiple index fragements, we artificially fail the single fragment strategy also. + * This is not ideal, but as both strategies behaviour are typically the same, is + * quite rare. + */ + protected void fakeFailForSingle() { + if(getName().startsWith("_") && strategy instanceof SinglePDOMTestStrategy) { + fail("Artificially failing - see IndexBindingResolutionTestBase.fakeFailForSingle()"); + } + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java index 1ed3c830606..7bb41cf2398 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionBugs.java @@ -18,6 +18,8 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IFunction; import org.eclipse.cdt.core.dom.ast.IScope; +import org.eclipse.cdt.core.dom.ast.IType; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; 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; @@ -28,6 +30,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition; import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateParameter; import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable; import org.eclipse.cdt.core.parser.util.ObjectMap; +import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalTemplateInstantiator; /** * For testing PDOM binding resolution @@ -37,6 +40,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas public static class SingleProject extends IndexCPPBindingResolutionBugs { public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));} } + public static class ProjectWithDepProj extends IndexCPPBindingResolutionBugs { public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));} } @@ -54,11 +58,41 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas setStrategy(new SinglePDOMTestStrategy(true)); } + // template + // class A {}; + // + // template + // class B : public A {}; + // + // class C {}; + // + // B b; + + // void foo() {C c; B b;} + public void _testBug188274() throws Exception { + IBinding b0= getBindingFromASTName("C", 1); + IBinding b1= getBindingFromASTName("B", 1); + assertInstance(b0, ICPPClassType.class); + assertInstance(b1, ICPPClassType.class); + assertInstance(b1, ICPPClassTemplate.class); + assertInstance(b1, ICPPInternalTemplateInstantiator.class); + + ICPPInternalTemplateInstantiator ct= (ICPPInternalTemplateInstantiator) b1; + ICPPSpecialization inst= ct.getInstance(new IType[]{(IType)b0}); + assertInstance(inst, ICPPClassType.class); + ICPPClassType c2t= (ICPPClassType) inst; + ICPPBase[] bases= c2t.getBases(); + assertEquals(1, bases.length); + assertInstance(bases[0].getBaseClass(), ICPPClassType.class); + + fakeFailForSingle(); + } + // namespace ns {class A{};} // ns::A a; // class B {}; - public void test188324() throws Exception { + public void testBug188324() throws Exception { IASTName name= findNames("B", 1)[0]; IBinding b0= getBindingFromASTName("ns::A", 2); assertInstance(b0, ICPPNamespace.class); @@ -72,7 +106,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // void foo() { // C::unresolvable(); // }; - public void test185828() throws Exception { + public void testBug185828() throws Exception { // Bug 185828 reports a StackOverflowException is thrown before we get here. // That the SOE is thrown is detected in BaseTestCase via an Error IStatus @@ -101,10 +135,10 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // }; // int main() { - // MyClass* cls; + // MyClass* cls= new MyClass(); // } - public void test184216() throws Exception { - IBinding b0= getBindingFromASTName("MyClass", 7); + public void testBug184216() throws Exception { + IBinding b0= getBindingFromASTName("MyClass*", 7); assertInstance(b0, ICPPClassType.class); ICPPClassType ct= (ICPPClassType) b0; ICPPMethod[] ms= ct.getDeclaredMethods(); // 184216 reports CCE thrown @@ -155,7 +189,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // b.fooovr(1); // b.fooovr('a'); // } - public void test168020() { + public void testBug168020() { getBindingFromASTName("foo(int i)", 3); getBindingFromASTName("fooint()", 6); getBindingFromASTName("fooovr()", 6); @@ -185,7 +219,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // void Base::foo(int i) { // i=2; // } - // void Base::foo2(int j) { + // int Base::foo2(int j) { // j=2; // } // void func(int k) { @@ -194,7 +228,7 @@ public class IndexCPPBindingResolutionBugs extends IndexBindingResolutionTestBas // void func2(int l) { // l=2; // } - public void test168054() { + public void testBug168054() { getBindingFromASTName("i=2", 1); getBindingFromASTName("j=2", 1); getBindingFromASTName("k=2", 1); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java index 0fa3d360b82..3849e5aff85 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IParameter; import org.eclipse.cdt.core.dom.ast.IType; import org.eclipse.cdt.core.dom.ast.ITypedef; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase; import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate; import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; @@ -258,6 +259,53 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa assertEquals(3, ct.getPartialSpecializations().length); } + // template + // class A {}; + // + // template + // class B : public A { + // public: + // static void foo() {} + // }; + // + // B bb; // make sure the instance is in the pdom + + // template + // class X : public B {}; + // + // void qux() { + // B::foo(); + // B::foo(); // instance not in the referenced pdom + // X x; + // } + public void _testClassImplicitInstantiations_188274() throws Exception { + IBinding b2= getBindingFromASTName("X", 6, true); + assertInstance(b2, ICPPClassType.class); + assertInstance(b2, ICPPTemplateInstance.class); + ICPPClassType ct2= (ICPPClassType) b2; + ICPPBase[] bss2= ct2.getBases(); + assertEquals(1, bss2.length); + assertInstance(bss2[0].getBaseClass(), ICPPClassType.class); + ICPPClassType ct2b= (ICPPClassType) bss2[0].getBaseClass(); + assertInstance(ct2b, ICPPTemplateInstance.class); + + IBinding b0= getBindingFromASTName("B", 6, true); + assertInstance(b0, ICPPClassType.class); + ICPPClassType ct= (ICPPClassType) b0; + ICPPBase[] bss= ct.getBases(); + assertEquals(1, bss.length); + assertInstance(bss[0].getBaseClass(), ICPPClassType.class); + + IBinding b1= getBindingFromASTName("B", 7, true); + assertInstance(b1, ICPPClassType.class); + ICPPClassType ct1= (ICPPClassType) b1; + ICPPBase[] bss1= ct1.getBases(); + assertEquals(1, bss1.length); + assertInstance(bss1[0].getBaseClass(), ICPPClassType.class); + + fakeFailForSingle(); + } + // class B {}; // // template