1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

224364: add unit tests

This commit is contained in:
Andrew Ferguson 2008-04-03 17:11:08 +00:00
parent d1d37fc9c8
commit 2421356998
5 changed files with 160 additions and 20 deletions

View file

@ -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 {

View file

@ -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);
}
}

View file

@ -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);
}
/**

View file

@ -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 */

View file

@ -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);
}
}