From 02470347410c6a0244ac4ce1d7cd0af0894254f6 Mon Sep 17 00:00:00 2001 From: Andrew Ferguson Date: Thu, 1 May 2008 12:44:27 +0000 Subject: [PATCH] move to new-style framework --- .../tests/ast2/AST2CPPSpecFailingTest.java | 819 +- .../parser/tests/ast2/AST2CPPSpecTest.java | 16970 +++++----------- .../parser/tests/ast2/AST2SpecBaseTest.java | 4 +- 3 files changed, 5451 insertions(+), 12342 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java index 493e557918a..ecc5c7fb991 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPSpecFailingTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2007 IBM Corporation and others. + * Copyright (c) 2005, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.cdt.core.parser.tests.ast2; +import junit.framework.TestSuite; + import org.eclipse.cdt.core.parser.ParserLanguage; /** @@ -21,8 +23,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage; */ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { - - public AST2CPPSpecFailingTest() { } @@ -30,583 +30,252 @@ public class AST2CPPSpecFailingTest extends AST2SpecBaseTest { super(name); } - /** - [--Start Example(CPP 6.4-3): - int foo() { - if (int x = f()) { - int x; // illformed,redeclaration of x - } - else { - int x; // illformed,redeclaration of x - } - } - --End Example] - */ - public void test6_4s3() { // TODO raised bug 90618 - StringBuffer buffer = new StringBuffer(); - buffer.append("int foo() {\n"); //$NON-NLS-1$ - buffer.append("if (int x = f()) {\n"); //$NON-NLS-1$ - buffer.append("int x; // illformed,redeclaration of x\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - buffer.append("else {\n"); //$NON-NLS-1$ - buffer.append("int x; // illformed,redeclaration of x\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); //Andrew, there should be problem bindings here - 2 - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 6.8-2): - class T { - // ... - public: - T(); - T(int); - T(int, int); - }; - T(a); //declaration - T(*b)(); //declaration - T(c)=7; //declaration - T(d),e,f=3; //declaration - extern int h; - T(g)(h,2); //declaration - --End Example] - */ - public void test6_8s2() { // TODO raised bug 90622 - StringBuffer buffer = new StringBuffer(); - buffer.append("class T {\n"); //$NON-NLS-1$ - buffer.append("// ...\n"); //$NON-NLS-1$ - buffer.append("public:\n"); //$NON-NLS-1$ - buffer.append("T();\n"); //$NON-NLS-1$ - buffer.append("T(int);\n"); //$NON-NLS-1$ - buffer.append("T(int, int);\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("T(a); //declaration\n"); //$NON-NLS-1$ - buffer.append("T(*b)(); //declaration\n"); //$NON-NLS-1$ - buffer.append("T(c)=7; //declaration\n"); //$NON-NLS-1$ - buffer.append("T(d),e,f=3; //declaration\n"); //$NON-NLS-1$ - buffer.append("extern int h;\n"); //$NON-NLS-1$ - buffer.append("T(g)(h,2); //declaration\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - - - /** - [--Start Example(CPP 7.3.3-12): - struct B { - virtual void f(int); - virtual void f(char); - void g(int); - void h(int); - }; - struct D : B { - using B::f; - void f(int); // OK: D::f(int) overrides B::f(int); - using B::g; - void g(char); // OK - using B::h; - void h(int); // OK: D::h(int) hides B::h(int) - }; - void k(D* p) - { - p->f(1); //calls D::f(int) - p->f('a'); //calls B::f(char) - p->g(1); //calls B::g(int) - p->g('a'); //calls D::g(char) - } - --End Example] - */ - // raised bug 161562 for that - public void test7_3_3s12() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("struct B {\n"); //$NON-NLS-1$ - buffer.append("virtual void f(int);\n"); //$NON-NLS-1$ - buffer.append("virtual void f(char);\n"); //$NON-NLS-1$ - buffer.append("void g(int);\n"); //$NON-NLS-1$ - buffer.append("void h(int);\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("struct D : B {\n"); //$NON-NLS-1$ - buffer.append("using B::f;\n"); //$NON-NLS-1$ - buffer.append("void f(int); // OK: D::f(int) overrides B::f(int);\n"); //$NON-NLS-1$ - buffer.append("using B::g;\n"); //$NON-NLS-1$ - buffer.append("void g(char); // OK\n"); //$NON-NLS-1$ - buffer.append("using B::h;\n"); //$NON-NLS-1$ - buffer.append("void h(int); // OK: D::h(int) hides B::h(int)\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("void k(D* p)\n"); //$NON-NLS-1$ - buffer.append("{\n"); //$NON-NLS-1$ - buffer.append("p->f(1); //calls D::f(int)\n"); //$NON-NLS-1$ - buffer.append("p->f('a'); //calls B::f(char)\n"); //$NON-NLS-1$ - buffer.append("p->g(1); //calls B::g(int)\n"); //$NON-NLS-1$ - buffer.append("p->g('a'); //calls D::g(char)\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 8.2-7a): - class C { }; - void f(int(C)) { } // void f(int (*fp)(C c)) { } - // not: void f(int C); - int g(C); - void foo() { - f(1); //error: cannot convert 1 to function pointer - f(g); //OK - } - --End Example] - */ - public void test8_2s7a() { // TODO raised bug 90633 - StringBuffer buffer = new StringBuffer(); - buffer.append("class C { };\n"); //$NON-NLS-1$ - buffer.append("void f(int(C)) { } // void f(int (*fp)(C c)) { }\n"); //$NON-NLS-1$ - buffer.append("// not: void f(int C);\n"); //$NON-NLS-1$ - buffer.append("int g(C);\n"); //$NON-NLS-1$ - buffer.append("void foo() {\n"); //$NON-NLS-1$ - buffer.append("f(1); //error: cannot convert 1 to function pointer\n"); //$NON-NLS-1$ - buffer.append("f(g); //OK\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 8.5.2-1): - char msg[] = "Syntax error on line %s\n"; - --End Example] - */ - public void test8_5_2s1() { // TODO raised bug 90647 - StringBuffer buffer = new StringBuffer(); - buffer.append("char msg[] = \"Syntax error on line %s\n\";\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.5.3-1): - template class task; - template task* preempt(task*); - template class task { - // ... - friend void next_time(); - friend void process(task*); - friend task* preempt(task*); - template friend int func(C); - friend class task; - template friend class frd; - // ... - }; - --End Example] - */ - public void test14_5_3s1() { // TODO raised bug 90678 - StringBuffer buffer = new StringBuffer(); - buffer.append("template class task;\n"); //$NON-NLS-1$ - buffer.append("template task* preempt(task*);\n"); //$NON-NLS-1$ - buffer.append("template class task {\n"); //$NON-NLS-1$ - buffer.append("// ...\n"); //$NON-NLS-1$ - buffer.append("friend void next_time();\n"); //$NON-NLS-1$ - buffer.append("friend void process(task*);\n"); //$NON-NLS-1$ - buffer.append("friend task* preempt(task*);\n"); //$NON-NLS-1$ - buffer.append("template friend int func(C);\n"); //$NON-NLS-1$ - buffer.append("friend class task;\n"); //$NON-NLS-1$ - buffer.append("template friend class frd;\n"); //$NON-NLS-1$ - buffer.append("// ...\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.5.4.2-2): - template class X { }; - template class X { }; // #1 - template class X { }; // #2 - template void f(X); // #A - template void f(X); // #B - --End Example] - */ - public void test14_5_4_2s2() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("template class X { };\n"); //$NON-NLS-1$ - buffer.append("template class X { }; // #1\n"); //$NON-NLS-1$ - buffer.append("template class X { }; // #2\n"); //$NON-NLS-1$ - buffer.append("template void f(X); // #A\n"); //$NON-NLS-1$ - buffer.append("template void f(X); // #B\n"); //$NON-NLS-1$ - parse(buffer.toString(), ParserLanguage.CPP, true, 2); - } - - /** - [--Start Example(CPP 14.5.5.1-5): - template A f(A, A); // #1 - template A f(A, A); // same as #1 - template A f(A, A); // different from #1 - --End Example] - */ - public void test14_5_5_1s5() { // TODO raised bug 90683 - StringBuffer buffer = new StringBuffer(); - buffer.append("template A f(A, A); // #1\n"); //$NON-NLS-1$ - buffer.append("template A f(A, A); // same as #1\n"); //$NON-NLS-1$ - buffer.append("template A f(A, A); // different from #1\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.5.5.1-6): - template void f(A); // #1 - template void f(A); // same as #1 - --End Example] - */ - public void test14_5_5_1s6() { // TODO raised bug 90683 - StringBuffer buffer = new StringBuffer(); - buffer.append("template void f(A); // #1\n"); //$NON-NLS-1$ - buffer.append("template void f(A); // same as #1\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.6.2-3): - typedef double A; - template B { - typedef int A; - }; - template struct X : B { - A a; // a has type double - }; - --End Example] - */ - public void test14_6_2s3() { // TODO this doesn't compile via g++ ? - StringBuffer buffer = new StringBuffer(); - buffer.append("typedef double A;\n"); //$NON-NLS-1$ - buffer.append("template B {\n"); //$NON-NLS-1$ - buffer.append("typedef int A;\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("template struct X : B {\n"); //$NON-NLS-1$ - buffer.append("A a; // a has type double\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.8.2-2b): - template int f(typename T::B*); - int i = f(0); - --End Example] - */ - public void test14_8_2s2b() { - StringBuffer buffer = new StringBuffer(); - buffer.append("template int f(typename T::B*);\n"); //$NON-NLS-1$ - buffer.append("int i = f(0);\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 1); - assertTrue(false); - } catch (Exception e) { - } + public static TestSuite suite() { + return suite(AST2CPPSpecFailingTest.class); } - /** - [--Start Example(CPP 14.8.2-2c): - template int f(typename T::B*); - struct A {}; - struct C { int B; }; - int i = f(0); - int j = f(0); - --End Example] - */ - public void test14_8_2s2c() { - StringBuffer buffer = new StringBuffer(); - buffer.append("template int f(typename T::B*);\n"); //$NON-NLS-1$ - buffer.append("struct A {};\n"); //$NON-NLS-1$ - buffer.append("struct C { int B; };\n"); //$NON-NLS-1$ - buffer.append("int i = f(0);\n"); //$NON-NLS-1$ - buffer.append("int j = f(0);\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 2); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.8.2-3): - template void f(T t); - template void g(const X x); - template void h(Z, Z*); - int main() - { - // #1: function type is f(int), t is nonconst - f(1); - // #2: function type is f(int), t is const - f(1); - // #3: function type is g(int), x is const - g(1); - // #4: function type is g(int), x is const - g(1); - // #5: function type is h(int, const int*) - h(1,0); - } - --End Example] - */ - public void test14_8_2s3() { - StringBuffer buffer = new StringBuffer(); - buffer.append("template void f(T t);\n"); //$NON-NLS-1$ - buffer.append("template void g(const X x);\n"); //$NON-NLS-1$ - buffer.append("template void h(Z, Z*);\n"); //$NON-NLS-1$ - buffer.append("int main()\n"); //$NON-NLS-1$ - buffer.append("{\n"); //$NON-NLS-1$ - buffer.append("// #1: function type is f(int), t is nonconst\n"); //$NON-NLS-1$ - buffer.append("f(1);\n"); //$NON-NLS-1$ - buffer.append("// #2: function type is f(int), t is const\n"); //$NON-NLS-1$ - buffer.append("f(1);\n"); //$NON-NLS-1$ - buffer.append("// #3: function type is g(int), x is const\n"); //$NON-NLS-1$ - buffer.append("g(1);\n"); //$NON-NLS-1$ - buffer.append("// #4: function type is g(int), x is const\n"); //$NON-NLS-1$ - buffer.append("g(1);\n"); //$NON-NLS-1$ - buffer.append("// #5: function type is h(int, const int*)\n"); //$NON-NLS-1$ - buffer.append("h(1,0);\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.8.2.4-7): - template void f(const T*) {} - int *p; - void s() - { - f(p); // f(const int *) - } - --End Example] - */ - public void test14_8_2_4s7() { - StringBuffer buffer = new StringBuffer(); - buffer.append("template void f(const T*) {}\n"); //$NON-NLS-1$ - buffer.append("int *p;\n"); //$NON-NLS-1$ - buffer.append("void s()\n"); //$NON-NLS-1$ - buffer.append("{\n"); //$NON-NLS-1$ - buffer.append("f(p); // f(const int *)\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.8.2.4-8): - template struct B { }; - template struct D : public B {}; - struct D2 : public B {}; - template void f(B&){} - void t() - { - D d; - D2 d2; - f(d); //calls f(B&) - f(d2); //calls f(B&) - } - --End Example] - */ - public void test14_8_2_4s8() { - StringBuffer buffer = new StringBuffer(); - buffer.append("template struct B { };\n"); //$NON-NLS-1$ - buffer.append("template struct D : public B {};\n"); //$NON-NLS-1$ - buffer.append("struct D2 : public B {};\n"); //$NON-NLS-1$ - buffer.append("template void f(B&){}\n"); //$NON-NLS-1$ - buffer.append("void t()\n"); //$NON-NLS-1$ - buffer.append("{\n"); //$NON-NLS-1$ - buffer.append("D d;\n"); //$NON-NLS-1$ - buffer.append("D2 d2;\n"); //$NON-NLS-1$ - buffer.append("f(d); //calls f(B&)\n"); //$NON-NLS-1$ - buffer.append("f(d2); //calls f(B&)\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.CPP, true, 0); - assertTrue(false); - } catch (Exception e) { - } - } - - /** - [--Start Example(CPP 14.8.2.4-18): - template