From 72312ab02a508feb53d016c9c518c17c03cabeeb Mon Sep 17 00:00:00 2001 From: Mike Kucera Date: Tue, 6 May 2008 14:47:33 +0000 Subject: [PATCH] Added several core parser tests to the LR parser test suite --- .../core/parser/tests/ast2/AST2CSpecTest.java | 2 +- .../parser/tests/ast2/SemanticsTests.java | 4 + .../lrparser/tests/LRCPPSpecFailingTest.java | 55 ++++++ .../core/lrparser/tests/LRCPPSpecTest.java | 10 ++ .../cdt/core/lrparser/tests/LRCPPTests.java | 10 ++ .../lrparser/tests/LRCSpecFailingTest.java | 54 ++++++ .../cdt/core/lrparser/tests/LRCSpecTests.java | 161 ++---------------- .../lrparser/tests/LRImageLocationTests.java | 48 ++++++ .../cdt/core/lrparser/tests/LRKnRTests.java | 64 +++---- .../lrparser/tests/LRNodeSelectorTest.java | 48 ++++++ .../lrparser/tests/LRParserTestSuite.java | 44 ++--- .../lrparser/tests/LRQuickParser2Tests.java | 39 +++++ .../lrparser/tests/LRSelectionParseTest.java | 150 ++++++++-------- .../core/lrparser/tests/LRSemanticsTests.java | 47 +++++ .../core/lrparser/tests/LRTemplateTests.java | 10 ++ .../cdt/core/lrparser/tests/ParseHelper.java | 4 +- 16 files changed, 473 insertions(+), 277 deletions(-) create mode 100644 lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecFailingTest.java create mode 100644 lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecFailingTest.java create mode 100644 lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java create mode 100644 lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java create mode 100644 lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java create mode 100644 lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java index f6c2e0a0d00..ac821642b31 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CSpecTest.java @@ -33,7 +33,7 @@ public class AST2CSpecTest extends AST2SpecBaseTest { */ public void test4s6() throws Exception { StringBuffer buffer = new StringBuffer(); - buffer.append("#ifdef _ _STDC_IEC_559_ _ /* FE_UPWARD defined */\n"); //$NON-NLS-1$ + buffer.append("#ifdef __STDC_IEC_559__ /* FE_UPWARD defined */\n"); //$NON-NLS-1$ buffer.append("fesetround(FE_UPWARD);\n"); //$NON-NLS-1$ buffer.append("#endif\n"); //$NON-NLS-1$ parseCandCPP(buffer.toString(), false, 0); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java index 6aa53cc19c7..e1a07d8dcd8 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/SemanticsTests.java @@ -22,6 +22,10 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.SemanticUtil; */ public class SemanticsTests extends AST2BaseTest { + public SemanticsTests() {} + public SemanticsTests(String name) { super(name); } + + // class A {}; // class B {}; // diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecFailingTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecFailingTest.java new file mode 100644 index 00000000000..b9a17971b2a --- /dev/null +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecFailingTest.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.lrparser.tests; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage; +import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; +import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.tests.ast2.AST2CPPSpecFailingTest; +import org.eclipse.cdt.internal.core.parser.ParserException; + +@SuppressWarnings("restriction") +public class LRCPPSpecFailingTest extends AST2CPPSpecFailingTest { + + public static TestSuite suite() { + return suite(LRCPPSpecFailingTest.class); + } + + public LRCPPSpecFailingTest() { } + public LRCPPSpecFailingTest(String name) { super(name); } + + + @Override + protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException { + parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings); + parse(code, ParserLanguage.CPP, checkBindings, expectedProblemBindings); + } + + @Override + protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException { + ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage(); + return ParseHelper.parse(code, language, true, checkBindings, expectedProblemBindings ); + } + + protected BaseExtensibleLanguage getCLanguage() { + return C99Language.getDefault(); + } + + protected BaseExtensibleLanguage getCPPLanguage() { + return ISOCPPLanguage.getDefault(); + } + +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java index acba2dfc514..7aebd9bf17c 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPSpecTest.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2006, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.core.lrparser.tests; import junit.framework.TestSuite; diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java index 3ce8e297144..f73a11fb6f9 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCPPTests.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2006, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.core.lrparser.tests; import junit.framework.AssertionFailedError; diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecFailingTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecFailingTest.java new file mode 100644 index 00000000000..316f66a0cae --- /dev/null +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecFailingTest.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2006, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.lrparser.tests; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.lrparser.BaseExtensibleLanguage; +import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; +import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.tests.ast2.AST2CSpecFailingTest; +import org.eclipse.cdt.internal.core.parser.ParserException; + +@SuppressWarnings("restriction") +public class LRCSpecFailingTest extends AST2CSpecFailingTest { + + public static TestSuite suite() { + return suite(LRCSpecFailingTest.class); + } + + public LRCSpecFailingTest() { } + public LRCSpecFailingTest(String name) { super(name); } + + + @Override + protected void parseCandCPP( String code, boolean checkBindings, int expectedProblemBindings ) throws ParserException { + parse(code, ParserLanguage.C, checkBindings, expectedProblemBindings); + parse(code, ParserLanguage.CPP, checkBindings, expectedProblemBindings); + } + + @Override + protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean checkBindings, int expectedProblemBindings ) throws ParserException { + ILanguage language = lang.isCPP() ? getCPPLanguage() : getCLanguage(); + return ParseHelper.parse(code, language, true, checkBindings, expectedProblemBindings ); + } + + protected BaseExtensibleLanguage getCLanguage() { + return C99Language.getDefault(); + } + + protected BaseExtensibleLanguage getCPPLanguage() { + return ISOCPPLanguage.getDefault(); + } +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java index aafb44c05d3..5788342de39 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRCSpecTests.java @@ -21,7 +21,7 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.tests.ast2.AST2CSpecTest; import org.eclipse.cdt.internal.core.parser.ParserException; -@SuppressWarnings("restriction") +@SuppressWarnings({"restriction", "nls"}) public class LRCSpecTests extends AST2CSpecTest { public static TestSuite suite() { @@ -52,157 +52,22 @@ public class LRCSpecTests extends AST2CSpecTest { return ISOCPPLanguage.getDefault(); } - //Assignment statements cannot exists outside of a function body - @Override + + @Override // example code needs to be nested in a function body public void test5_1_2_3s15() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("//#include \n"); //$NON-NLS-1$ - buffer.append("int foo() { \n"); //$NON-NLS-1$ - buffer.append("int sum;\n"); //$NON-NLS-1$ - buffer.append("char *p;\n"); //$NON-NLS-1$ - buffer.append("sum = sum * 10 - '0' + (*p++ = getchar());\n"); //$NON-NLS-1$ - buffer.append("sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));\n"); //$NON-NLS-1$ - buffer.append("} \n"); //$NON-NLS-1$ - parseCandCPP(buffer.toString(), false, 0); + String code = + "//#include \n" + + "int foo() { \n" + + "int sum;\n" + + "char *p;\n" + + "sum = sum * 10 - '0' + (*p++ = getchar());\n" + + "sum = (((sum * 10) - '0') + ((*(p++)) = (getchar())));\n" + + "} \n"; + + parseCandCPP(code, false, 0); } - - - // Tests from AST2CSpecFailingTests - - /** - * TODO: This one fails, it can't resolve one of the bindings (const t) I think - * - [--Start Example(C 6.7.7-6): - typedef signed int t; - typedef int plain; - struct tag { - unsigned t:4; - const t:5; - plain r:5; - }; - t f(t (t)); - long t; - --End Example] - */ - public void test6_7_7s6() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("typedef signed int t;\n"); //$NON-NLS-1$ - buffer.append("typedef int plain;\n"); //$NON-NLS-1$ - buffer.append("struct tag {\n"); //$NON-NLS-1$ - buffer.append("unsigned t:4;\n"); //$NON-NLS-1$ - buffer.append("const t:5;\n"); //$NON-NLS-1$ - buffer.append("plain r:5;\n"); //$NON-NLS-1$ - buffer.append("};\n"); //$NON-NLS-1$ - buffer.append("t f(t (t));\n"); //$NON-NLS-1$ - buffer.append("long t;\n"); //$NON-NLS-1$ - try { - parse(buffer.toString(), ParserLanguage.C, true, 0); - } catch(AssertionFailedError _) { - // there should be an error - } - } - - - - /** - [--Start Example(C 6.10.3.5-5): - #define x 3 - #define f(a) f(x * (a)) - #undef x - #define x 2 - #define g f - #define z z[0] - #define h g(~ - #define m(a) a(w) - #define w 0,1 - #define t(a) a - #define p() int - #define q(x) x - #define r(x,y) x ## y - #define str(x) # x - int foo() { - p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) }; - char c[2][6] = { str(hello), str() }; - } - --End Example] - */ - @Override - public void test6_10_3_5s5() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define x 3\n"); //$NON-NLS-1$ - buffer.append("#define f(a) f(x * (a))\n"); //$NON-NLS-1$ - buffer.append("#undef x\n"); //$NON-NLS-1$ - buffer.append("#define x 2\n"); //$NON-NLS-1$ - buffer.append("#define g f\n"); //$NON-NLS-1$ - buffer.append("#define z z[0]\n"); //$NON-NLS-1$ - buffer.append("#define h g(~\n"); //$NON-NLS-1$ - buffer.append("#define m(a) a(w)\n"); //$NON-NLS-1$ - buffer.append("#define w 0,1\n"); //$NON-NLS-1$ - buffer.append("#define t(a) a\n"); //$NON-NLS-1$ - buffer.append("#define p() int\n"); //$NON-NLS-1$ - buffer.append("#define q(x) x\n"); //$NON-NLS-1$ - buffer.append("#define r(x,y) x ## y\n"); //$NON-NLS-1$ - buffer.append("#define str(x) # x\n"); //$NON-NLS-1$ - buffer.append("int foo() {\n"); //$NON-NLS-1$ - buffer.append("p() i[q()] = { q(1), r(2,3), r(4,), r(,5), r(,) };\n"); //$NON-NLS-1$ - buffer.append("char c[2][6] = { str(hello), str() };\n"); //$NON-NLS-1$ - buffer.append("}\n"); //$NON-NLS-1$ - - //parseCandCPP(buffer.toString(), true, 0); - // TODO: this only works on the C99 parser for now - parse(buffer.toString(), ParserLanguage.C, true, 0); - } - - - /** - [--Start Example(C 6.10.3.5-7): - #define t(x,y,z) x ## y ## z - int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), - t(10,,), t(,11,), t(,,12), t(,,) }; - --End Example] - */ - @Override - public void test6_10_3_5s7() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#define t(x,y,z) x ## y ## z\n"); //$NON-NLS-1$ - buffer.append("int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),\n"); //$NON-NLS-1$ - buffer.append("t(10,,), t(,11,), t(,,12), t(,,) };\n"); //$NON-NLS-1$ - - // TODO: this only works on the C99 parser for now - parse(buffer.toString(), ParserLanguage.C, true, 0); - } - - /** - * This test seems to be incorrect in AST2SpecTests - */ - @Override - public void test4s6() throws Exception { - StringBuffer buffer = new StringBuffer(); - buffer.append("#ifdef __STDC_IEC_559__ /* FE_UPWARD defined */\n"); //$NON-NLS-1$ - buffer.append("fesetround(FE_UPWARD);\n"); //$NON-NLS-1$ - buffer.append("#endif\n"); //$NON-NLS-1$ - parseCandCPP(buffer.toString(), false, 0); - } - - -// @Override -// public void test6_7_8s24() throws Exception { // complex isn't declared as a typedef -// try { -// super.test6_7_8s24(); -// fail(); -// } catch(AssertionFailedError _) { } -// } -// -// -// @Override -// public void test6_7_8s34() throws Exception { // div_t isn't declared as a typedef -// try { -// super.test6_7_8s34(); -// fail(); -// } catch(AssertionFailedError _) { } -// } @Override public void test6_7_2_1s17() throws Exception { // what the heck is offsetof diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java new file mode 100644 index 00000000000..2bca1e7c61a --- /dev/null +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRImageLocationTests.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 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 http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.core.lrparser.tests; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; +import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.tests.ast2.ImageLocationTests; +import org.eclipse.cdt.internal.core.parser.ParserException; + +@SuppressWarnings("restriction") +public class LRImageLocationTests extends ImageLocationTests { + + public static TestSuite suite() { + return suite(LRImageLocationTests.class); + } + + public LRImageLocationTests() { } + public LRImageLocationTests(String name) { super(name); } + + + @Override + @SuppressWarnings("unused") + protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, + boolean expectNoProblems, boolean parseComments) throws ParserException { + ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language(); + return ParseHelper.parse(code, language, expectNoProblems); + } + + protected ILanguage getC99Language() { + return C99Language.getDefault(); + } + + protected ILanguage getCPPLanguage() { + return ISOCPPLanguage.getDefault(); + } + +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java index b2e56b5f934..8ade3de5790 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRKnRTests.java @@ -47,37 +47,37 @@ public class LRKnRTests extends AST2KnRTests { } // TODO: Failing tests, will get around to fixing these bugs - - @Override - public void testKRCProblem3() throws Exception { - try { - super.testKRCProblem3(); - fail(); - } catch(Throwable _) { } - } - - @Override - public void testKRCProblem4() throws Exception { - try { - super.testKRCProblem4(); - fail(); - } catch(Throwable _) { } - } - - @Override - public void testKRCProblem5() throws Exception { - try { - super.testKRCProblem5(); - fail(); - } catch(Throwable _) { } - } - - @Override - public void testKRCProblem2() throws Exception { - try { - super.testKRCProblem2(); - fail(); - } catch(Throwable _) { } - } +// +// @Override +// public void testKRCProblem3() throws Exception { +// try { +// super.testKRCProblem3(); +// fail(); +// } catch(Throwable _) { } +// } +// +// @Override +// public void testKRCProblem4() throws Exception { +// try { +// super.testKRCProblem4(); +// fail(); +// } catch(Throwable _) { } +// } +// +// @Override +// public void testKRCProblem5() throws Exception { +// try { +// super.testKRCProblem5(); +// fail(); +// } catch(Throwable _) { } +// } +// +// @Override +// public void testKRCProblem2() throws Exception { +// try { +// super.testKRCProblem2(); +// fail(); +// } catch(Throwable _) { } +// } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java new file mode 100644 index 00000000000..001c04f6faf --- /dev/null +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRNodeSelectorTest.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2006, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.core.lrparser.tests; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; +import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.tests.ast2.ASTNodeSelectorTest; +import org.eclipse.cdt.internal.core.parser.ParserException; + +@SuppressWarnings("restriction") +public class LRNodeSelectorTest extends ASTNodeSelectorTest { + + public static TestSuite suite() { + return suite(LRNodeSelectorTest.class); + } + + public LRNodeSelectorTest() {} + public LRNodeSelectorTest(String name) { super(name); } + + + @Override + protected IASTTranslationUnit parse( String code, ParserLanguage lang, @SuppressWarnings("unused") boolean useGNUExtensions, boolean expectNoProblems, @SuppressWarnings("unused") boolean parseComments) throws ParserException { + ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language(); + return ParseHelper.parse(code, language, expectNoProblems); + } + + protected ILanguage getC99Language() { + return C99Language.getDefault(); + } + + protected ILanguage getCPPLanguage() { + return ISOCPPLanguage.getDefault(); + } + +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java index 6d03837e98c..19b4c5efb86 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRParserTestSuite.java @@ -29,33 +29,33 @@ public class LRParserTestSuite extends TestSuite { public static Test suite() { return new TestSuite() {{ - addTestSuite(LRTests.class); // has some tests that do fail - - addTestSuite(LRCSpecTests.class); // a couple of failures - addTestSuite(LRKnRTests.class); // mostly fail due to ambiguities - - // The majority of the content assist test are in the ui tests plugin + addTestSuite(LRCommentTests.class); + addTestSuite(LRCompleteParser2Tests.class); addTestSuite(LRCompletionBasicTest.class); addTestSuite(LRCompletionParseTest.class); - // this one still has a lot of failing tests though - addTestSuite(LRSelectionParseTest.class); - - addTestSuite(LRDOMLocationInclusionTests.class); - addTestSuite(LRDOMLocationTests.class); - addTestSuite(LRDOMLocationMacroTests.class); - addTestSuite(LRDOMPreprocessorInformationTest.class); - addTestSuite(LRCommentTests.class); - addTestSuite(LRDigraphTrigraphTests.class); - addTestSuite(LRGCCTests.class); - addTestSuite(LRUtilOldTests.class); - addTestSuite(LRUtilTests.class); - addTestSuite(LRCompleteParser2Tests.class); - addTestSuite(LRTaskParserTest.class); - + addTestSuite(LRCPPSpecFailingTest.class); addTestSuite(LRCPPSpecTest.class); addTestSuite(LRCPPTests.class); + addTestSuite(LRCSpecFailingTest.class); + addTestSuite(LRCSpecTests.class); // a couple of failures + addTestSuite(LRDigraphTrigraphTests.class); + addTestSuite(LRDOMLocationInclusionTests.class); + addTestSuite(LRDOMLocationMacroTests.class); + addTestSuite(LRDOMLocationTests.class); + addTestSuite(LRDOMPreprocessorInformationTest.class); + addTestSuite(LRGCCTests.class); + addTestSuite(LRImageLocationTests.class); + addTestSuite(LRKnRTests.class); // mostly fail due to ambiguities + addTestSuite(LRNodeSelectorTest.class); + addTestSuite(LRQuickParser2Tests.class); + addTestSuite(LRSelectionParseTest.class); // this one still has a lot of failing tests though + addTestSuite(LRSemanticsTests.class); + addTestSuite(LRTaskParserTest.class); addTestSuite(LRTemplateTests.class); - + addTestSuite(LRTests.class); // has some tests that do fail + addTestSuite(LRUtilOldTests.class); + addTestSuite(LRUtilTests.class); + }}; } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java new file mode 100644 index 00000000000..2d4997c74d0 --- /dev/null +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRQuickParser2Tests.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 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 http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.core.lrparser.tests; + +import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; +import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.tests.ast2.QuickParser2Tests; + +public class LRQuickParser2Tests extends QuickParser2Tests { + + public LRQuickParser2Tests() {} + public LRQuickParser2Tests(String name) { super(name); } + + + @Override + protected void parse(String code, boolean expectedToPass, + ParserLanguage lang, @SuppressWarnings("unused") boolean gcc) throws Exception { + ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language(); + ParseHelper.parse(code, language, expectedToPass); + } + + + protected ILanguage getC99Language() { + return C99Language.getDefault(); + } + + protected ILanguage getCPPLanguage() { + return ISOCPPLanguage.getDefault(); + } + +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java index 06e99027ab3..efe349389a7 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSelectionParseTest.java @@ -10,15 +10,20 @@ *******************************************************************************/ package org.eclipse.cdt.core.lrparser.tests; +import java.util.Collections; + import junit.framework.TestSuite; import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.parser.CodeReader; +import org.eclipse.cdt.core.parser.ExtendedScannerInfo; import org.eclipse.cdt.core.parser.IScannerInfo; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ScannerInfo; @@ -26,6 +31,7 @@ import org.eclipse.cdt.core.parser.tests.ast2.AST2SelectionParseTest; import org.eclipse.cdt.internal.core.dom.SavedCodeReaderFactory; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; @SuppressWarnings("restriction") public class LRSelectionParseTest extends AST2SelectionParseTest { @@ -86,77 +92,77 @@ public class LRSelectionParseTest extends AST2SelectionParseTest { } -// public void testBug193185_IncludeNext() throws Exception -// { -// String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$ -// String i1Next = "int one; \n#include_next "; //$NON-NLS-1$ -// String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$ -// String i3Next = "int three; \n"; //$NON-NLS-1$ -// -// -// IFile base = importFile( "base.c", baseFile ); //$NON-NLS-1$ -// importFile( "foo.h", i1Next ); //$NON-NLS-1$ -// IFolder twof = importFolder("two"); //$NON-NLS-1$ -// IFolder threef = importFolder("three"); //$NON-NLS-1$ -// importFile( "two/foo.h", i2Next ); //$NON-NLS-1$ -// importFile( "three/foo.h", i3Next ); //$NON-NLS-1$ -// -// String[] path = new String[] { -// twof.getRawLocation().toOSString(), -// threef.getRawLocation().toOSString() -// }; -// -// IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[0], path ); -// -// IASTTranslationUnit tu = parse(base, ParserLanguage.C, scannerInfo, false, true); -// -// IASTDeclaration[] decls = tu.getDeclarations(); -// assertEquals(4, decls.length); -// -// IASTSimpleDeclaration declaration = (IASTSimpleDeclaration)decls[0]; -// assertEquals("zero", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ -// -// declaration = (IASTSimpleDeclaration)decls[1]; -// assertEquals("one", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ -// -// declaration = (IASTSimpleDeclaration)decls[2]; -// assertEquals("two", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ -// -// declaration = (IASTSimpleDeclaration)decls[3]; -// assertEquals("three", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ -// } -// -// -// public void testBug193366() throws Exception -// { -// String baseFile = -// "#define FOOH \n" + //$NON-NLS-1$ -// "#define bar blahblahblah \n" + //$NON-NLS-1$ -// "#include FOOH \n" + //$NON-NLS-1$ -// "#include \n"; //$NON-NLS-1$ -// -// String fooFile = "int x; \n"; //$NON-NLS-1$ -// String barFile = "int y; \n"; //$NON-NLS-1$ -// -// -// IFile base = importFile( "base.c", baseFile ); //$NON-NLS-1$ -// IFolder include = importFolder("inc"); //$NON-NLS-1$ -// importFile( "inc/foo.h", fooFile ); //$NON-NLS-1$ -// importFile( "inc/bar.h", barFile ); //$NON-NLS-1$ -// -// String[] path = new String[] { include.getRawLocation().toOSString() }; -// IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[0], path ); -// -// IASTTranslationUnit tu = parse(base, ParserLanguage.C, scannerInfo, false, true); -// -// IASTDeclaration[] decls = tu.getDeclarations(); -// assertEquals(2, decls.length); -// -// IASTSimpleDeclaration declaration = (IASTSimpleDeclaration)decls[0]; -// assertEquals("x", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ -// -// declaration = (IASTSimpleDeclaration)decls[1]; -// assertEquals("y", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ -// } + public void testBug193185_IncludeNext() throws Exception + { + String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$ + String i1Next = "int one; \n#include_next "; //$NON-NLS-1$ + String i2Next = "int two; \n#include_next \"foo.h\""; //$NON-NLS-1$ + String i3Next = "int three; \n"; //$NON-NLS-1$ + + + IFile base = importFile( "base.c", baseFile ); //$NON-NLS-1$ + importFile( "foo.h", i1Next ); //$NON-NLS-1$ + IFolder twof = importFolder("two"); //$NON-NLS-1$ + IFolder threef = importFolder("three"); //$NON-NLS-1$ + importFile( "two/foo.h", i2Next ); //$NON-NLS-1$ + importFile( "three/foo.h", i3Next ); //$NON-NLS-1$ + + String[] path = new String[] { + twof.getRawLocation().toOSString(), + threef.getRawLocation().toOSString() + }; + + IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[0], path ); + + IASTTranslationUnit tu = parse(base, ParserLanguage.C, scannerInfo, false, true); + + IASTDeclaration[] decls = tu.getDeclarations(); + assertEquals(4, decls.length); + + IASTSimpleDeclaration declaration = (IASTSimpleDeclaration)decls[0]; + assertEquals("zero", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ + + declaration = (IASTSimpleDeclaration)decls[1]; + assertEquals("one", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ + + declaration = (IASTSimpleDeclaration)decls[2]; + assertEquals("two", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ + + declaration = (IASTSimpleDeclaration)decls[3]; + assertEquals("three", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ + } + + + public void testBug193366() throws Exception + { + String baseFile = + "#define FOOH \n" + //$NON-NLS-1$ + "#define bar blahblahblah \n" + //$NON-NLS-1$ + "#include FOOH \n" + //$NON-NLS-1$ + "#include \n"; //$NON-NLS-1$ + + String fooFile = "int x; \n"; //$NON-NLS-1$ + String barFile = "int y; \n"; //$NON-NLS-1$ + + + IFile base = importFile( "base.c", baseFile ); //$NON-NLS-1$ + IFolder include = importFolder("inc"); //$NON-NLS-1$ + importFile( "inc/foo.h", fooFile ); //$NON-NLS-1$ + importFile( "inc/bar.h", barFile ); //$NON-NLS-1$ + + String[] path = new String[] { include.getRawLocation().toOSString() }; + IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, new String[0], path ); + + IASTTranslationUnit tu = parse(base, ParserLanguage.C, scannerInfo, false, true); + + IASTDeclaration[] decls = tu.getDeclarations(); + assertEquals(2, decls.length); + + IASTSimpleDeclaration declaration = (IASTSimpleDeclaration)decls[0]; + assertEquals("x", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ + + declaration = (IASTSimpleDeclaration)decls[1]; + assertEquals("y", declaration.getDeclarators()[0].getName().toString()); //$NON-NLS-1$ + } } diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java new file mode 100644 index 00000000000..c5ffa32c1cd --- /dev/null +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRSemanticsTests.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 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 http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.cdt.core.lrparser.tests; + +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.lrparser.c99.C99Language; +import org.eclipse.cdt.core.dom.lrparser.cpp.ISOCPPLanguage; +import org.eclipse.cdt.core.model.ILanguage; +import org.eclipse.cdt.core.parser.ParserLanguage; +import org.eclipse.cdt.core.parser.tests.ast2.SemanticsTests; +import org.eclipse.cdt.internal.core.parser.ParserException; + +@SuppressWarnings("restriction") +public class LRSemanticsTests extends SemanticsTests { + + public static TestSuite suite() { + return suite(LRSemanticsTests.class); + } + + public LRSemanticsTests() { } + public LRSemanticsTests(String name) { super(name); } + + + @SuppressWarnings("unused") + @Override + protected IASTTranslationUnit parse( String code, ParserLanguage lang, boolean useGNUExtensions, + boolean expectNoProblems, boolean parseComments) throws ParserException { + ILanguage language = lang.isCPP() ? getCPPLanguage() : getC99Language(); + return ParseHelper.parse(code, language, expectNoProblems); + } + + protected ILanguage getC99Language() { + return C99Language.getDefault(); + } + + protected ILanguage getCPPLanguage() { + return ISOCPPLanguage.getDefault(); + } +} diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java index b83019ccc17..4ccf6596ea0 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/LRTemplateTests.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2006, 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package org.eclipse.cdt.core.lrparser.tests; import junit.framework.TestSuite; diff --git a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java index d45b267a721..f3c18ea5f84 100644 --- a/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java +++ b/lrparser/org.eclipse.cdt.core.lrparser.tests/src/org/eclipse/cdt/core/lrparser/tests/ParseHelper.java @@ -13,12 +13,12 @@ package org.eclipse.cdt.core.lrparser.tests; import junit.framework.AssertionFailedError; import org.eclipse.cdt.core.dom.ICodeReaderFactory; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.IProblemBinding; -import org.eclipse.cdt.core.dom.ast.cpp.CPPASTVisitor; import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.parser.CodeReader; import org.eclipse.cdt.core.parser.IScannerInfo; @@ -37,7 +37,7 @@ public class ParseHelper { static int testsRun = 0; - private static class NameResolver extends CPPASTVisitor { + private static class NameResolver extends ASTVisitor { { shouldVisitNames = true; }