mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 12:03:16 +02:00
Corrections and extensions to test cases.
This commit is contained in:
parent
56a40e0e70
commit
84567f7497
4 changed files with 139 additions and 90 deletions
|
@ -459,7 +459,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
return binding;
|
||||
}
|
||||
|
||||
public IBinding assertNonProblem(String section, int len) {
|
||||
public <T extends IBinding> T assertNonProblem(String section, int len) {
|
||||
IBinding binding= binding(section, len);
|
||||
if (binding instanceof IProblemBinding) {
|
||||
IProblemBinding problem= (IProblemBinding) binding;
|
||||
|
@ -468,7 +468,7 @@ public class AST2BaseTest extends BaseTestCase {
|
|||
if (binding == null) {
|
||||
fail("Null binding resolved for name: " + section.substring(0, len));
|
||||
}
|
||||
return binding;
|
||||
return (T) binding;
|
||||
}
|
||||
|
||||
private String renderProblemID(int i) {
|
||||
|
|
|
@ -6,20 +6,20 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Devin Steffler (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
|
||||
/**
|
||||
*
|
||||
* NOTE: Once these tests pass (are fixed) then fix the test to work so that they
|
||||
* are tested for a pass instead of a failure and move them to AST2CPPSpecTest.java.
|
||||
*
|
||||
* @author dsteffle
|
||||
*/
|
||||
public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
||||
|
||||
|
@ -36,18 +36,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
|
||||
public void testDummy() {} // avoids JUnit "no tests" warning
|
||||
|
||||
// int foo() {
|
||||
// if (int x = f()) {
|
||||
// int x; // illformed,redeclaration of x
|
||||
// }
|
||||
// else {
|
||||
// int x; // illformed,redeclaration of x
|
||||
// }
|
||||
// }
|
||||
public void _test6_4s3() throws Exception { // TODO raised bug 90618
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 2);
|
||||
}
|
||||
|
||||
// struct B {
|
||||
// virtual void f(int);
|
||||
// virtual void f(char);
|
||||
|
@ -73,12 +61,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// char msg[] = "Syntax error on line %s
|
||||
// ";
|
||||
public void _test8_5_2s1() throws Exception { // TODO raised bug 90647
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template<class T> class task;
|
||||
// template<class T> task<T>* preempt(task<T>*);
|
||||
// template<class T> class task {
|
||||
|
@ -95,45 +77,21 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template <int I, int J> A<I+J> f(A<I>, A<J>); // #1
|
||||
// template <int K, int L> A<K+L> f(A<K>, A<L>); // same as #1
|
||||
// template <int I, int J> A<I-J> f(A<I>, A<J>); // different from #1
|
||||
public void _test14_5_5_1s5() throws Exception { // TODO raised bug 90683
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
// template <int I> class A;
|
||||
// template <int I, int J> A<I+J> f/*1*/(A<I>, A<J>); // #1
|
||||
// template <int K, int L> A<K+L> f/*2*/(A<K>, A<L>); // same as #1
|
||||
// template <int I, int J> A<I-J> f/*3*/(A<I>, A<J>); // different from #1
|
||||
public void _test14_5_5_1s5() throws Exception {
|
||||
final String content= getAboveComment();
|
||||
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
|
||||
ICPPFunctionTemplate f1= bh.assertNonProblem("f/*1*/", 1);
|
||||
ICPPFunctionTemplate f2= bh.assertNonProblem("f/*2*/", 1);
|
||||
ICPPFunctionTemplate f3= bh.assertNonProblem("f/*3*/", 1);
|
||||
assertSame(f1, f2);
|
||||
assertNotSame(f1, f3);
|
||||
}
|
||||
|
||||
// template <int I, int J> void f(A<I+J>); // #1
|
||||
// template <int K, int L> void f(A<K+L>); // same as #1
|
||||
public void _test14_5_5_1s6() throws Exception { // TODO raised bug 90683
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// typedef double A;
|
||||
// template<class T> B {
|
||||
// typedef int A;
|
||||
// };
|
||||
// template<class T> struct X : B<T> {
|
||||
// A a; // a has type double
|
||||
// };
|
||||
public void _test14_6_2s3() throws Exception { // TODO this doesn't compile via g++ ?
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template <class T> int f(typename T::B*);
|
||||
// int i = f<int>(0);
|
||||
public void _test14_8_2s2b() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 1);
|
||||
}
|
||||
|
||||
// template <class T> int f(typename T::B*);
|
||||
// struct A {};
|
||||
// struct C { int B; };
|
||||
// int i = f<A>(0);
|
||||
// int j = f<C>(0);
|
||||
public void _test14_8_2s2c() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 2);
|
||||
}
|
||||
|
||||
|
||||
// template <class T> void f(T t);
|
||||
// template <class X> void g(const X x);
|
||||
// template <class Z> void h(Z, Z*);
|
||||
|
@ -151,6 +109,7 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
// h<const int>(1,0);
|
||||
// }
|
||||
public void _test14_8_2s3() throws Exception {
|
||||
// mstodo this one must pass
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
|
@ -169,27 +128,6 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template <template X<class T> > struct A { };
|
||||
// template <template X<class T> > void f(A<X>) { }
|
||||
// template<class T> struct B { };
|
||||
// int foo() {
|
||||
// A<B> ab;
|
||||
// f(ab); //calls f(A<B>)
|
||||
// }
|
||||
public void _test14_8_2_4s18() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// // Guaranteed to be the same
|
||||
// template <int I> void f(A<I>, A<I+10>);
|
||||
// template <int I> void f(A<I>, A<I+10>);
|
||||
// // Guaranteed to be different
|
||||
// template <int I> void f(A<I>, A<I+10>);
|
||||
// template <int I> void f(A<I>, A<I+11>);
|
||||
public void _test14_5_5_1s8a() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template<class T> void f(T);
|
||||
// class Complex {
|
||||
// // ...
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Devin Steffler (IBM Corporation) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||
|
@ -22,16 +22,21 @@ import org.eclipse.cdt.core.dom.ast.IASTName;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTProblemDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTypeId;
|
||||
import org.eclipse.cdt.core.dom.ast.IBasicType;
|
||||
import org.eclipse.cdt.core.dom.ast.IFunction;
|
||||
import org.eclipse.cdt.core.dom.ast.IProblemBinding;
|
||||
import org.eclipse.cdt.core.dom.ast.IType;
|
||||
import org.eclipse.cdt.core.dom.ast.ITypedef;
|
||||
import org.eclipse.cdt.core.dom.ast.IVariable;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTNewExpression;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTemplateId;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
|
||||
|
||||
/**
|
||||
* @author dsteffle
|
||||
* Examples taken from the c++-specification.
|
||||
*/
|
||||
public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
||||
|
||||
|
@ -916,6 +921,20 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// int foo() {
|
||||
// if (int x = 1) {
|
||||
// int x; // illformed,redeclaration of x
|
||||
// }
|
||||
// else {
|
||||
// int x; // illformed,redeclaration of x
|
||||
// }
|
||||
// }
|
||||
public void test6_4s3() throws Exception {
|
||||
// raised bug 90618
|
||||
// gcc does not report an error, either, so leave it as it is.
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// int foo() {
|
||||
// int x=5;
|
||||
// while (--x >= 0)
|
||||
|
@ -2260,8 +2279,15 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// char msg[] = "Syntax error on line %s";
|
||||
public void test8_5_2s1() throws Exception {
|
||||
// raised bug 90647
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// char cv[4] = "asdf"; // error
|
||||
public void test8_5_2s2() throws Exception {
|
||||
// we do not check the size of an array, which is ok.
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
|
@ -4744,6 +4770,23 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// // Guaranteed to be the same
|
||||
// template <int T> class A;
|
||||
// template <int I> void f/*1*/(A<I>, A<I+10>);
|
||||
// template <int I> void f/*2*/(A<I>, A<I+10>);
|
||||
// // Guaranteed to be different
|
||||
// template <int I> void f/*3*/(A<I>, A<I+11>);
|
||||
public void test14_5_5_1s8a() throws Exception {
|
||||
final String content= getAboveComment();
|
||||
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
|
||||
ICPPFunctionTemplate f1= bh.assertNonProblem("f/*1*/", 1);
|
||||
ICPPFunctionTemplate f2= bh.assertNonProblem("f/*2*/", 1);
|
||||
ICPPFunctionTemplate f3= bh.assertNonProblem("f/*3*/", 1);
|
||||
assertSame(f1, f2);
|
||||
assertNotSame(f1, f3);
|
||||
}
|
||||
|
||||
// // Illformed, no diagnostic required
|
||||
// template <int I> void f(A<I>, A<I+10>);
|
||||
// template <int I> void f(A<I>, A<I+1+2+3+4>);
|
||||
|
@ -4984,6 +5027,25 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, false, 0);
|
||||
}
|
||||
|
||||
// typedef double A;
|
||||
// template<class T> class B {
|
||||
// typedef int A;
|
||||
// };
|
||||
// template<class T> struct X : B<T> {
|
||||
// A a; // a has type double
|
||||
// };
|
||||
public void test14_6_2s3() throws Exception { // TODO this doesn't compile via g++ ?
|
||||
final String content= getAboveComment();
|
||||
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
|
||||
IVariable v= bh.assertNonProblem("a;", 1);
|
||||
IType t= v.getType();
|
||||
assertInstance(t, ITypedef.class);
|
||||
t= ((ITypedef) t).getType();
|
||||
assertInstance(t, IBasicType.class);
|
||||
assertEquals(IBasicType.t_double, ((IBasicType) t).getType());
|
||||
}
|
||||
|
||||
// struct A {
|
||||
// struct B { };
|
||||
// int a;
|
||||
|
@ -5446,6 +5508,31 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, false, 0);
|
||||
}
|
||||
|
||||
// template <class T> int f(typename T::B*);
|
||||
// int i = f<int>(0);
|
||||
public void test14_8_2s2b() throws Exception {
|
||||
final String content= getAboveComment();
|
||||
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 2);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
|
||||
bh.assertProblem("f<", 1);
|
||||
bh.assertProblem("f<int>", 6);
|
||||
}
|
||||
|
||||
// template <class T> int f(typename T::B*);
|
||||
// struct A {};
|
||||
// struct C { int B; };
|
||||
// int i = f<A>(0);
|
||||
// int j = f<C>(0);
|
||||
public void test14_8_2s2c() throws Exception {
|
||||
final String content= getAboveComment();
|
||||
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 4);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
|
||||
bh.assertProblem("f<A", 1);
|
||||
bh.assertProblem("f<A>", 4);
|
||||
bh.assertProblem("f<C", 1);
|
||||
bh.assertProblem("f<C>", 4);
|
||||
}
|
||||
|
||||
// template <class T> int f(int T::*);
|
||||
// int i = f<int>(0);
|
||||
public void test14_8_2s2d() throws Exception {
|
||||
|
@ -5573,6 +5660,17 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
public void test14_8_2_4s17() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, false, 0);
|
||||
}
|
||||
|
||||
// template <template <class T> class X> struct A { };
|
||||
// template <template <class T> class X> void f(A<X>) { }
|
||||
// template<class T> struct B { };
|
||||
// int foo() {
|
||||
// A<B> ab;
|
||||
// f(ab); //calls f(A<B>)
|
||||
// }
|
||||
public void test14_8_2_4s18() throws Exception {
|
||||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template<class T> T max(T a, T b) { return a>b?a:b; }
|
||||
// void f(int a, int b, char c, char d)
|
||||
|
@ -6111,6 +6209,18 @@ public class AST2CPPSpecTest extends AST2SpecBaseTest {
|
|||
parse(getAboveComment(), ParserLanguage.CPP, true, 0);
|
||||
}
|
||||
|
||||
// template <int I> class A;
|
||||
// template <int I, int J> void f/*1*/(A<I+J>); // #1
|
||||
// template <int K, int L> void f/*2*/(A<K+L>); // same as #1
|
||||
public void test14_5_5_1s6() throws Exception {
|
||||
final String content= getAboveComment();
|
||||
IASTTranslationUnit tu= parse(content, ParserLanguage.CPP, true, 0);
|
||||
BindingAssertionHelper bh= new BindingAssertionHelper(content, true);
|
||||
ICPPFunctionTemplate f1= bh.assertNonProblem("f/*1*/", 1);
|
||||
ICPPFunctionTemplate f2= bh.assertNonProblem("f/*2*/", 1);
|
||||
assertSame(f1, f2);
|
||||
}
|
||||
|
||||
// template <class T> int f(T); // #1
|
||||
// int f(int); // #2
|
||||
// int k = f(1); // uses #2
|
||||
|
|
|
@ -60,6 +60,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPParameter;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPReferenceType;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPSpecialization;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateArgument;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateInstance;
|
||||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateNonTypeParameter;
|
||||
|
@ -70,6 +71,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPTemplateTypeParameter;
|
|||
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.util.ObjectMap;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.Value;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPDeferredClassInstance;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPInternalUnknownScope;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.ICPPUnknownBinding;
|
||||
|
@ -2902,13 +2904,12 @@ public class AST2TemplateTests extends AST2BaseTest {
|
|||
// public:
|
||||
// C<y> go();
|
||||
// };
|
||||
public void _testDeferredNonTypeArgument() throws Exception {
|
||||
public void testDeferredNonTypeArgument() throws Exception {
|
||||
BindingAssertionHelper ba= new BindingAssertionHelper(getAboveComment(), true);
|
||||
ICPPDeferredClassInstance ci= ba.assertNonProblem("C<y>", 4, ICPPDeferredClassInstance.class);
|
||||
ObjectMap args= ci.getArgumentMap();
|
||||
assertEquals(1, args.size());
|
||||
assertInstance(args.keyAt(0), ICPPTemplateNonTypeParameter.class);
|
||||
assertInstance(args.getAt(0), ICPPTemplateNonTypeParameter.class);
|
||||
ICPPTemplateArgument[] args= ci.getTemplateArguments();
|
||||
assertEquals(1, args.length);
|
||||
assertEquals(0, Value.isTemplateParameter(args[0].getNonTypeValue()));
|
||||
}
|
||||
|
||||
// template<int x>
|
||||
|
|
Loading…
Add table
Reference in a new issue