From 6544ff498df420b44d066fb169714ac74e57b199 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Fri, 6 Aug 2004 01:57:11 +0000 Subject: [PATCH] Restructured the Parser tests so that the GCC Extension specific ones are separate. Created a GCCExtensions Suite which currently is not included in ParserTestSuite. --- .../parser/tests/CompleteParseASTTest.java | 35 ------- .../tests/GCCCompleteExtensionsParseTest.java | 78 ++++++++++++++++ .../tests/GCCParserExtensionTestSuite.java | 33 +++++++ .../tests/GCCQuickParseExtensionsTest.java | 92 +++++++++++++++++++ .../core/parser/tests/ParserTestSuite.java | 1 + .../core/parser/tests/QuickParseASTTests.java | 58 +----------- .../scanner2/GCCScannerExtensionsTest.java | 36 ++++++++ .../parser/tests/scanner2/Scanner2Test.java | 7 -- 8 files changed, 242 insertions(+), 98 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteExtensionsParseTest.java create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java index 23fcd3b1dcf..432ad466cf3 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/CompleteParseASTTest.java @@ -18,7 +18,6 @@ import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; import org.eclipse.cdt.core.parser.ast.ASTPointerOperator; -import org.eclipse.cdt.core.parser.ast.ASTUtil; import org.eclipse.cdt.core.parser.ast.IASTASMDefinition; import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; import org.eclipse.cdt.core.parser.ast.IASTBaseSpecifier; @@ -28,7 +27,6 @@ import org.eclipse.cdt.core.parser.ast.IASTCodeScope; import org.eclipse.cdt.core.parser.ast.IASTElaboratedTypeSpecifier; import org.eclipse.cdt.core.parser.ast.IASTEnumerationSpecifier; import org.eclipse.cdt.core.parser.ast.IASTEnumerator; -import org.eclipse.cdt.core.parser.ast.IASTExpression; import org.eclipse.cdt.core.parser.ast.IASTField; import org.eclipse.cdt.core.parser.ast.IASTFunction; import org.eclipse.cdt.core.parser.ast.IASTLinkageSpecification; @@ -45,8 +43,6 @@ import org.eclipse.cdt.core.parser.ast.IASTUsingDeclaration; import org.eclipse.cdt.core.parser.ast.IASTUsingDirective; import org.eclipse.cdt.core.parser.ast.IASTVariable; import org.eclipse.cdt.core.parser.ast.IASTVariableReference; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; -import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; import org.eclipse.cdt.internal.core.parser.ParserException; @@ -1553,23 +1549,6 @@ public class CompleteParseASTTest extends CompleteParseBaseTest IASTClassSpecifier A = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); IASTClassSpecifier B = (IASTClassSpecifier) ((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier(); } - public void testBug39695() throws Exception - { - Iterator i = parse("int a = __alignof__ (int);").getDeclarations(); //$NON-NLS-1$ - IASTVariable a = (IASTVariable) i.next(); - assertFalse( i.hasNext() ); - IASTExpression exp = a.getInitializerClause().getAssigmentExpression(); - assertEquals( exp.getExpressionKind(), IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ); - assertEquals( exp.toString(), "__alignof__(int)"); //$NON-NLS-1$ - } - - public void testBug39684() throws Exception - { - IASTFunction bar = (IASTFunction) parse("typeof(foo(1)) bar () { return foo(1); }").getDeclarations().next(); //$NON-NLS-1$ - - IASTSimpleTypeSpecifier simpleTypeSpec = ((IASTSimpleTypeSpecifier)bar.getReturnType().getTypeSpecifier()); - assertEquals( simpleTypeSpec.getType(), IASTGCCSimpleTypeSpecifier.Type.TYPEOF ); - } public void testBug59302() throws Exception { @@ -1589,20 +1568,6 @@ public class CompleteParseASTTest extends CompleteParseBaseTest } - public void testBug39698A() throws Exception - { - Iterator i = parse("int c = a ? b;").getDeclarations(); //$NON-NLS-1$ - IASTVariable c = (IASTVariable) i.next(); - IASTExpression exp = c.getInitializerClause().getAssigmentExpression(); - assertEquals( ASTUtil.getExpressionString( exp ), "a >? b" ); //$NON-NLS-1$ - } public void testULong() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteExtensionsParseTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteExtensionsParseTest.java new file mode 100644 index 00000000000..f0525574914 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCCompleteExtensionsParseTest.java @@ -0,0 +1,78 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Canada Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.tests; + +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.ASTUtil; +import org.eclipse.cdt.core.parser.ast.IASTExpression; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTSimpleTypeSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTVariable; +import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCExpression; +import org.eclipse.cdt.core.parser.ast.gcc.IASTGCCSimpleTypeSpecifier; + +/** + * @author jcamelon + * + */ +public class GCCCompleteExtensionsParseTest extends CompleteParseBaseTest { + + /** + * + */ + public GCCCompleteExtensionsParseTest() { + super(); + // TODO Auto-generated constructor stub + } + + /** + * @param name + */ + public GCCCompleteExtensionsParseTest(String name) { + super(name); + // TODO Auto-generated constructor stub + } + + public void testBug39695() throws Exception + { + Iterator i = parse("int a = __alignof__ (int);").getDeclarations(); //$NON-NLS-1$ + IASTVariable a = (IASTVariable) i.next(); + assertFalse( i.hasNext() ); + IASTExpression exp = a.getInitializerClause().getAssigmentExpression(); + assertEquals( exp.getExpressionKind(), IASTGCCExpression.Kind.UNARY_ALIGNOF_TYPEID ); + assertEquals( exp.toString(), "__alignof__(int)"); //$NON-NLS-1$ + } + + public void testBug39684() throws Exception + { + IASTFunction bar = (IASTFunction) parse("typeof(foo(1)) bar () { return foo(1); }").getDeclarations().next(); //$NON-NLS-1$ + + IASTSimpleTypeSpecifier simpleTypeSpec = ((IASTSimpleTypeSpecifier)bar.getReturnType().getTypeSpecifier()); + assertEquals( simpleTypeSpec.getType(), IASTGCCSimpleTypeSpecifier.Type.TYPEOF ); + } + + public void testBug39698A() throws Exception + { + Iterator i = parse("int c = a ? b;").getDeclarations(); //$NON-NLS-1$ + IASTVariable c = (IASTVariable) i.next(); + IASTExpression exp = c.getInitializerClause().getAssigmentExpression(); + assertEquals( ASTUtil.getExpressionString( exp ), "a >? b" ); //$NON-NLS-1$ + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java new file mode 100644 index 00000000000..088e13518c1 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCParserExtensionTestSuite.java @@ -0,0 +1,33 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Canada Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.tests; + +import org.eclipse.cdt.core.parser.tests.scanner2.GCCScannerExtensionsTest; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * @author jcamelon + * + */ +public class GCCParserExtensionTestSuite extends TestCase { + + public static Test suite() { + TestSuite suite= new TestSuite(GCCParserExtensionTestSuite.class.getName()); + suite.addTestSuite( GCCScannerExtensionsTest.class ); + suite.addTestSuite( GCCQuickParseExtensionsTest.class ); + suite.addTestSuite( GCCCompleteExtensionsParseTest.class ); + return suite; + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java new file mode 100644 index 00000000000..85d5d6eef64 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/GCCQuickParseExtensionsTest.java @@ -0,0 +1,92 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Canada Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.tests; + +import java.io.StringWriter; +import java.io.Writer; +import java.util.Iterator; + +import org.eclipse.cdt.core.parser.ast.ASTClassKind; +import org.eclipse.cdt.core.parser.ast.IASTAbstractTypeSpecifierDeclaration; +import org.eclipse.cdt.core.parser.ast.IASTClassSpecifier; +import org.eclipse.cdt.core.parser.ast.IASTField; +import org.eclipse.cdt.core.parser.ast.IASTFunction; +import org.eclipse.cdt.core.parser.ast.IASTVariable; + +/** + * @author jcamelon + * + */ +public class GCCQuickParseExtensionsTest extends BaseASTTest { + + /** + * @param a + */ + public GCCQuickParseExtensionsTest(String a) { + super(a); + // TODO Auto-generated constructor stub + } + + public void testBug39694() throws Exception + { + IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next(); //$NON-NLS-1$ + assertEquals( variable.getName(), "ab$cd"); //$NON-NLS-1$ + } + + public void testBug39704A() throws Exception + { + IASTVariable foo = (IASTVariable) assertSoleDeclaration("__declspec (dllimport) int foo;"); //$NON-NLS-1$ + assertEquals( foo.getName(), "foo"); //$NON-NLS-1$ + } + public void testBug39704D() throws Exception + { + IASTFunction func1 = (IASTFunction) assertSoleDeclaration("__declspec(dllexport) int func1 (int a) {}"); //$NON-NLS-1$ + assertEquals( func1.getName(), "func1"); //$NON-NLS-1$ + } + + public void testBug39695() throws Exception + { + parse("int a = __alignof__ (int);"); //$NON-NLS-1$ + } + + public void testBug39684() throws Exception + { + parse("typeof(foo(1)) bar () { return foo(1); }"); //$NON-NLS-1$ + } + + public void testBug39703() throws Exception + { + Writer code = new StringWriter(); + code.write("/* __extension__ enables GNU C mode for the duration of the declaration. */\n"); //$NON-NLS-1$ + code.write("__extension__ struct G {\n"); //$NON-NLS-1$ + code.write(" struct { char z; };\n"); //$NON-NLS-1$ + code.write(" char g;\n"); //$NON-NLS-1$ + code.write("};\n"); //$NON-NLS-1$ + IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString()); + IASTClassSpecifier G = ((IASTClassSpecifier)abs.getTypeSpecifier()); + assertEquals( G.getName(), "G" ); //$NON-NLS-1$ + assertEquals( G.getClassKind(), ASTClassKind.STRUCT ); + Iterator i = G.getDeclarations(); + assertEquals( ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()).getName(), "" ); //$NON-NLS-1$ + assertEquals( ((IASTField)i.next()).getName(), "g" ); //$NON-NLS-1$ + assertFalse( i.hasNext() ); + } + + public void testBug39698A() throws Exception + { + parse("int c = a ? b;"); //$NON-NLS-1$ + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java index 4e4dc614619..b87b293c19b 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ParserTestSuite.java @@ -47,6 +47,7 @@ public class ParserTestSuite extends TestCase { suite.addTestSuite( CompleteParseASTTemplateTest.class ); suite.addTestSuite( StructuralParseTest.class ); suite.addTestSuite( ObjectMapTest.class ); +// suite.addTest( GCCParserExtensionTestSuite.suite() ); return suite; } } diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java index f92ac0b0555..3f918e822ce 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/QuickParseASTTests.java @@ -14,8 +14,6 @@ import java.io.StringWriter; import java.io.Writer; import java.util.Iterator; -import org.eclipse.cdt.core.parser.IMacroDescriptor; -import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTClassKind; @@ -2128,19 +2126,8 @@ public class QuickParseASTTests extends BaseASTTest { parse("#ident \"@(#)filename.c 1.3 90/02/12\""); //$NON-NLS-1$ } + - public void testBug39694() throws Exception - { - IASTVariable variable = (IASTVariable)parse("int ab$cd = 1;").getDeclarations().next(); //$NON-NLS-1$ - assertEquals( variable.getName(), "ab$cd"); //$NON-NLS-1$ - } - - - public void testBug39704A() throws Exception - { - IASTVariable foo = (IASTVariable) assertSoleDeclaration("__declspec (dllimport) int foo;"); //$NON-NLS-1$ - assertEquals( foo.getName(), "foo"); //$NON-NLS-1$ - } public void testBug39704B() throws Exception @@ -2154,11 +2141,7 @@ public class QuickParseASTTests extends BaseASTTest assertEquals( f.getName(), "func2"); //$NON-NLS-1$ } - public void testBug39704D() throws Exception - { - IASTFunction func1 = (IASTFunction) assertSoleDeclaration("__declspec(dllexport) int func1 (int a) {}"); //$NON-NLS-1$ - assertEquals( func1.getName(), "func1"); //$NON-NLS-1$ - } + public void testBug45235() throws Exception { @@ -2174,43 +2157,6 @@ public class QuickParseASTTests extends BaseASTTest assertTrue( forewardDecl.isFriendDeclaration() ); assertTrue( f.isFriend() ); } - - public void testBug39695() throws Exception - { - parse("int a = __alignof__ (int);"); //$NON-NLS-1$ - } - - public void testBug39684() throws Exception - { - parse("typeof(foo(1)) bar () { return foo(1); }"); //$NON-NLS-1$ - } - - public void testBug39703() throws Exception - { - Writer code = new StringWriter(); - code.write("/* __extension__ enables GNU C mode for the duration of the declaration. */\n"); //$NON-NLS-1$ - code.write("__extension__ struct G {\n"); //$NON-NLS-1$ - code.write(" struct { char z; };\n"); //$NON-NLS-1$ - code.write(" char g;\n"); //$NON-NLS-1$ - code.write("};\n"); //$NON-NLS-1$ - IASTAbstractTypeSpecifierDeclaration abs = (IASTAbstractTypeSpecifierDeclaration)assertSoleDeclaration(code.toString()); - IASTClassSpecifier G = ((IASTClassSpecifier)abs.getTypeSpecifier()); - assertEquals( G.getName(), "G" ); //$NON-NLS-1$ - assertEquals( G.getClassKind(), ASTClassKind.STRUCT ); - Iterator i = G.getDeclarations(); - assertEquals( ((IASTClassSpecifier)((IASTAbstractTypeSpecifierDeclaration)i.next()).getTypeSpecifier()).getName(), "" ); //$NON-NLS-1$ - assertEquals( ((IASTField)i.next()).getName(), "g" ); //$NON-NLS-1$ - assertFalse( i.hasNext() ); - } - - public void testBug39698A() throws Exception - { - parse("int c = a ? b;"); //$NON-NLS-1$ - } public void testBug59179() throws Exception { diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java new file mode 100644 index 00000000000..ab9c3a1ac01 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/GCCScannerExtensionsTest.java @@ -0,0 +1,36 @@ +/********************************************************************** + * Copyright (c) 2004 IBM Canada Ltd. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * IBM Rational Software - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.core.parser.tests.scanner2; + +import org.eclipse.cdt.core.parser.IGCCToken; + +/** + * @author jcamelon + * + */ +public class GCCScannerExtensionsTest extends BaseScanner2Test { + + /** + * @param x + */ + public GCCScannerExtensionsTest(String x) { + super(x); + } + + public void testBug39698() throws Exception + { + initializeScanner( "?"); //$NON-NLS-1$ + validateToken( IGCCToken.tMIN ); + validateToken( IGCCToken.tMAX ); + validateEOF(); + } + +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java index e73c36aaeec..26be54eef13 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/scanner2/Scanner2Test.java @@ -1526,13 +1526,6 @@ public class Scanner2Test extends BaseScanner2Test validateEOF(); } - public void testBug39698() throws Exception - { - initializeScanner( "?"); //$NON-NLS-1$ - validateToken( IGCCToken.tMIN ); - validateToken( IGCCToken.tMAX ); - validateEOF(); - } public void testBug59768() throws Exception {