1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Restructured the Parser tests so that the GCC Extension specific ones are separate.

Created a GCCExtensions Suite which currently is not included in ParserTestSuite.
This commit is contained in:
John Camelon 2004-08-06 01:57:11 +00:00
parent df2be63243
commit 6544ff498d
8 changed files with 242 additions and 98 deletions

View file

@ -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 testBug39698B() 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
{

View file

@ -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$
}
public void testBug39698B() 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$
}
}

View file

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

View file

@ -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$
}
public void testBug39698B() throws Exception
{
parse("int c = a >? b;"); //$NON-NLS-1$
}
}

View file

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

View file

@ -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 testBug39698B() throws Exception
{
parse("int c = a >? b;"); //$NON-NLS-1$
}
public void testBug59179() throws Exception
{

View file

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

View file

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