Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferguson2008-04-03 17:11:08 +0000
committerAndrew Ferguson2008-04-03 17:11:08 +0000
commit24213569982835981f227a128669bc7589b68125 (patch)
treed0255fb263bdf79351173f7086e520227c47a40b
parentd1d37fc9c8ac0a52efca45f1220692ca620737ad (diff)
downloadorg.eclipse.cdt-24213569982835981f227a128669bc7589b68125.tar.gz
org.eclipse.cdt-24213569982835981f227a128669bc7589b68125.tar.xz
org.eclipse.cdt-24213569982835981f227a128669bc7589b68125.zip
224364: add unit tests
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java30
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java64
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java14
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java33
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPTemplateResolutionTest.java39
5 files changed, 160 insertions, 20 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
index 7f23ad5101e..eb319d23a70 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPTests.java
@@ -4701,24 +4701,20 @@ public class AST2CPPTests extends AST2BaseTest {
assertSame(strcmp, col.getName(4).resolveBinding());
}
+ // class Other;
+ // class Base {
+ // public: Base( Other * );
+ // };
+ // class Sub : public Base {
+ // public: Sub( Other * );
+ // };
+ // Sub::Sub( Other * b ) : Base(b) {}
public void testBug95673() throws Exception {
- StringBuffer buffer = new StringBuffer();
- buffer.append("class Other; \n"); //$NON-NLS-1$
- buffer.append("class Base { \n"); //$NON-NLS-1$
- buffer.append(" public: Base( Other * ); \n"); //$NON-NLS-1$
- buffer.append("}; \n"); //$NON-NLS-1$
- buffer.append("class Sub : public Base { \n"); //$NON-NLS-1$
- buffer.append(" public: Sub( Other * ); \n"); //$NON-NLS-1$
- buffer.append("}; \n"); //$NON-NLS-1$
- buffer.append("Sub::Sub( Other * b ) : Base(b) {} \n"); //$NON-NLS-1$
-
- IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.CPP);
- CPPNameCollector col = new CPPNameCollector();
- tu.accept(col);
-
- ICPPConstructor ctor = (ICPPConstructor) col.getName(2)
- .resolveBinding();
- assertSame(ctor, col.getName(15).resolveBinding());
+ BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
+
+ ICPPConstructor ctor= ba.assertNonProblem("Base( Other", 4, ICPPConstructor.class);
+ ICPPConstructor ctor2= ba.assertNonProblem("Base(b)", 4, ICPPConstructor.class);
+ assertSame(ctor, ctor2);
}
public void testBug95768() throws Exception {
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
index 4c1be0d2ed1..e71a891fc9b 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java
@@ -2274,4 +2274,68 @@ public class AST2TemplateTests extends AST2BaseTest {
assertInstance(f1.getParameters()[0].getType(), ICPPClassType.class);
assertInstance(f1.getParameters()[0].getType(), ICPPTemplateInstance.class);
}
+
+ // class A {};
+ // class B {};
+ // template<typename T>
+ // class C {
+ // public:
+ // T t;
+ // operator B() {B b; return b;}
+ // };
+ // template<typename T>
+ // class D : public C<T> {};
+ // void foo(B b) {}
+ //
+ // void refs() {
+ // D<A> d;
+ // foo(d);
+ // }
+ public void _testUserDefinedConversions_224364() throws Exception {
+ BindingAssertionHelper bh= new BindingAssertionHelper(getContents(1)[0].toString(), true);
+ ICPPFunction fn= bh.assertNonProblem("foo(d)", 3, ICPPFunction.class);
+ }
+
+ // class B {};
+ // template<typename T>
+ // class C {
+ // public:
+ // T t;
+ // operator T() {return t;}
+ // };
+ // template<typename T>
+ // class D : public C<T> {};
+ // void foo(B b) {}
+ //
+ // void refs() {
+ // D<B> d;
+ // foo(d);
+ // }
+ public void _testUserDefinedConversions_224364_2() throws Exception {
+ BindingAssertionHelper bh= new BindingAssertionHelper(getContents(1)[0].toString(), true);
+ ICPPFunction fn= bh.assertNonProblem("foo(d)", 3, ICPPFunction.class);
+ }
+
+ // class Z {};
+ // template<typename TA>
+ // class A {
+ // public:
+ // TA ta;
+ // operator TA() {return ta;}
+ // };
+ // template<typename TB>
+ // class B : public A<TB> {};
+ // template<typename TC>
+ // class C : public B<TC> {};
+ // template<typename TD>
+ // class D : public C<TD> {};
+ // template<typename TE>
+ // class E : public D<TE> {};
+ // Z foo(Z z) {return z;}
+ //
+ // Z z= foo(*new E<Z>());
+ public void _testUserDefinedConversions_224364_3() throws Exception {
+ BindingAssertionHelper bh= new BindingAssertionHelper(getContents(1)[0].toString(), true);
+ ICPPFunction fn= bh.assertNonProblem("foo(*new", 3, ICPPFunction.class);
+ }
}
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 39bee0e29fc..1e039b1b039 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
@@ -90,13 +90,15 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
* <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 clazz an expected class type or interface that the binding should extend/implement
* @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.
* @return the associated name's binding
*/
- protected IBinding getBindingFromASTName(String section, int len) {
+ protected <T> T getBindingFromASTName(Class<T> clazz, String section, int len) {
IASTName name= findName(section, len);
assertNotNull("name not found for \""+section+"\"", name);
assertEquals(section.substring(0, len), name.getRawSignature());
@@ -104,7 +106,15 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
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()));
- return name.resolveBinding();
+ assertInstance(binding, clazz);
+ return clazz.cast(binding);
+ }
+
+ /*
+ * @see IndexBindingResolutionTestBase#getBindingFromASTName(Class, String, int)
+ */
+ protected IBinding getBindingFromASTName(String section, int len) {
+ return getBindingFromASTName(IBinding.class, section, len);
}
/**
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 04e62edd2ce..8e46c95e9a7 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
@@ -1271,7 +1271,38 @@ public abstract class IndexCPPBindingResolutionTest extends IndexBindingResoluti
// }
public void testLegalConflictWithUsingDeclaration() throws Exception {
getBindingFromASTName("a(1)", 1);
- }
+ }
+
+ // class A {};
+ // class B {};
+ // class C {
+ // public:
+ // operator B() {B b; return b;}
+ // };
+ // class D : public C {};
+ // void foo(B b) {}
+
+ // class E : public C {};
+ // void refs() {
+ // C c;
+ // foo(c);
+ // D d;
+ // foo(d);
+ // E e;
+ // foo(e);
+ // }
+ public void _testUserDefinedConversionOperator_224364() throws Exception {
+ IBinding ca= getBindingFromASTName("C c;", 1);
+ assertInstance(ca, ICPPClassType.class);
+
+ IBinding foo1= getBindingFromASTName("foo(c)", 3);
+
+ IBinding da= getBindingFromASTName("D d", 1);
+ assertInstance(da, ICPPClassType.class);
+
+ IBinding foo2= getBindingFromASTName("foo(d)", 3);
+ IBinding foo3= getBindingFromASTName("foo(e)", 3);
+ }
/* CPP assertion helpers */
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 57e17c8f555..e1c72b73d0d 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
@@ -921,4 +921,43 @@ public class IndexCPPTemplateResolutionTest extends IndexBindingResolutionTestBa
assertInstance(type, ICPPClassType.class);
assertEquals("A", ((ICPPClassType) type).getName());
}
+
+ // class A {};
+ // class B {};
+ // template<typename T>
+ // class C {
+ // public:
+ // T t;
+ // operator B() {B b; return b;}
+ // };
+ // template<typename T>
+ // class D : public C<T> {};
+ // class E : public C<A> {};
+ // void foo(B b) {}
+
+ // class F : public C<A> {};
+ // void refs() {
+ // C<A> c;
+ // foo(c);
+ // D<A> d;
+ // foo(d);
+ // E e;
+ // foo(e);
+ // F f;
+ // foo(f);
+ // }
+ public void _testUserDefinedConversionOperator_224364() throws Exception {
+ IBinding ca= getBindingFromASTName("C<A>", 4);
+ assertInstance(ca, ICPPClassType.class);
+ assertInstance(ca, ICPPTemplateInstance.class);
+
+ IBinding foo1= getBindingFromASTName("foo(c)", 3);
+
+ IBinding da= getBindingFromASTName("D<A>", 4);
+ assertInstance(da, ICPPClassType.class);
+ assertInstance(da, ICPPTemplateInstance.class);
+
+ IBinding foo2= getBindingFromASTName("foo(d)", 3);
+ IBinding foo3= getBindingFromASTName("foo(e)", 3);
+ }
}

Back to the top