1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-03 14:25:37 +02:00
Fixed Bug36799  STL Testing: Parser fails on Variable Definition 

TESTS
	Moved fixed tests from FailedTests to DOMTests. 
	Added DOMTests::testBug36799().
	Cleaned up tests to reduce amount of code necessary to maintain these things. 

JohnC
This commit is contained in:
John Camelon 2003-04-24 21:01:25 +00:00
parent a294752676
commit fcd010f569
16 changed files with 448 additions and 515 deletions

View file

@ -1,3 +1,6 @@
2003-04-24 John Camelon
Fixed Bug36799 STL Testing: Parser fails on Variable Definition
2003-04-24 John Camelon
Fixed bug36693 - Problem parsing Loki's Reference SmallObj.cpp Impl
Fixed bug36696 - Problem parsing Loki's Reference SmartPtr.h Impl

View file

@ -881,39 +881,42 @@ c, quick);
case Token.t_class:
case Token.t_struct:
case Token.t_union:
try
if( !parm )
{
classSpecifier(decl);
return;
try
{
classSpecifier(decl);
return;
}
catch( Backtrack bt )
{
elaboratedTypeSpecifier(decl);
return;
}
}
catch( Backtrack bt )
else
{
// this is an elaborated class specifier
Object elab = null;
try{ elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );} catch( Exception e ) {}
name();
try{
callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab );
} catch( Exception e ) {}
elaboratedTypeSpecifier(decl);
return;
}
case Token.t_enum:
try
if( !parm )
{
enumSpecifier(decl);
return;
try
{
enumSpecifier(decl);
return;
}
catch( Backtrack bt )
{
// this is an elaborated class specifier
elaboratedTypeSpecifier(decl);
return;
}
}
catch( Backtrack bt )
else
{
// this is an elaborated class specifier
Object elab = null;
try{ elab = callback.elaboratedTypeSpecifierBegin( decl, consume() ); } catch( Exception e ) {}
name();
try{
callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab );
} catch( Exception e ) {}
elaboratedTypeSpecifier(decl);
return;
}
default:
@ -922,6 +925,17 @@ c, quick);
}
}
private void elaboratedTypeSpecifier(Object decl) throws Backtrack {
// this is an elaborated class specifier
Object elab = null;
try{ elab = callback.elaboratedTypeSpecifierBegin( decl, consume() );} catch( Exception e ) {}
name();
try{
callback.elaboratedTypeSpecifierName( elab );
callback.elaboratedTypeSpecifierEnd( elab );
} catch( Exception e ) {}
}
protected void identifier() throws Backtrack {
Token first = consume(Token.tIDENTIFIER); // throws backtrack if its not that
@ -2236,6 +2250,29 @@ c, quick);
consume();
// TO DO: this
break;
// simple-type-specifier ( assignment-expression , .. )
case Token.t_char:
case Token.t_wchar_t:
case Token.t_bool:
case Token.t_short:
case Token.t_int:
case Token.t_long:
case Token.t_signed:
case Token.t_unsigned:
case Token.t_float:
case Token.t_double:
consume();
consume( Token.tLPAREN );
while( true )
{
assignmentExpression( expression );
if( LT(1) == Token.tRPAREN ) break;
consume( Token.tCOMMA );
}
consume( Token.tRPAREN );
break;
case Token.t_dynamic_cast:
case Token.t_static_cast:
case Token.t_reinterpret_cast:

View file

@ -1,3 +1,8 @@
2003-04-24 John Camelon
Moved fixed tests from FailedTests to DOMTests.
Added DOMTests::testBug36799().
Cleaned up tests to reduce amount of code necessary to maintain these things.
2003-04-24 John Camelon
Moved fixed tests from FailedTests to DOMTests.
Added LokiFailures.java to failed tests directory.

View file

@ -13,12 +13,7 @@ package org.eclipse.cdt.core.parser.failedTests;
import java.io.StringWriter;
import java.io.Writer;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.DOMTests;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
/**
@ -27,7 +22,7 @@ import org.eclipse.cdt.internal.core.parser.ParserException;
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class ACEFailedTest extends DOMTests {
public class ACEFailedTest extends BaseDOMTest {
/**
* @param arg
@ -35,44 +30,19 @@ public class ACEFailedTest extends DOMTests {
public ACEFailedTest(String arg) {
super(arg);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new ACEFailedTest("testBug36769"));
suite.addTest(new ACEFailedTest("testBug36771"));
return suite;
public void testBug36771() throws Exception {
Writer code = new StringWriter();
code.write("#include /**/ \"foo.h\"\n");
failTest( code.toString());
}
public void testBug36771(){
boolean testPassed = false;
try{
Writer code = new StringWriter();
code.write("#include /**/ \"foo.h\"\n");
TranslationUnit tu = parse( code.toString());
testPassed = true;
} catch( Throwable e ){
if( ! (e instanceof ParserException))
fail( "Unexpected Error: " + e.getMessage() );
}
if( testPassed )
fail( "The expected error did not occur.");
}
public void testBug36769(){
boolean testPassed = false;
try{
Writer code = new StringWriter();
code.write("template <class A, B> cls<A, C>::operator op &() const {}\n");
code.write("template <class A, B> cls<A, C>::cls() {}\n");
code.write("template <class A, B> cls<A, C>::~cls() {}\n");
public void testBug36769() throws Exception {
Writer code = new StringWriter();
code.write("template <class A, B> cls<A, C>::operator op &() const {}\n");
code.write("template <class A, B> cls<A, C>::cls() {}\n");
code.write("template <class A, B> cls<A, C>::~cls() {}\n");
TranslationUnit tu = parse( code.toString());
testPassed = true;
} catch( Throwable e ){
if( ! (e instanceof ParserException))
fail( "Unexpected Error: " + e.getMessage() );
}
if( testPassed )
fail( "The expected error did not occur.");
failTest( code.toString());
}
}

View file

@ -13,157 +13,77 @@ package org.eclipse.cdt.core.parser.failedTests;
import java.io.StringWriter;
import java.io.Writer;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.DOMTests;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
/**
* @author jcamelon
*/
public class DOMFailedTest extends DOMTests {
public class DOMFailedTest extends BaseDOMTest {
public DOMFailedTest(String name) {
super(name);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new DOMFailedTest("testBug36691"));
suite.addTest(new DOMFailedTest("testBug36699"));
suite.addTest(new DOMFailedTest("testBug36704"));
suite.addTest(new DOMFailedTest("testBug36707"));
suite.addTest(new DOMFailedTest("testBug36708"));
suite.addTest(new DOMFailedTest("testBug36713"));
suite.addTest(new DOMFailedTest("testBug36714"));
suite.addTest(new DOMFailedTest("testBug36730"));
return suite;
public void testBug36704() throws Exception {
failTest("template <class T, class U> struct Length< Typelist<T, U> > { enum { value = 1 + Length<U>::value };};);");
}
public void testBug36691() {
boolean testPassed = false;
try {
Writer code = new StringWriter();
code.write("template <class T, class H>\n");
code.write(
"typename H::template Rebind<T>::Result& Field(H& obj)\n");
code.write("{ return obj; }\n");
TranslationUnit tu = parse(code.toString());
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
public void testBug36691() throws Exception {
Writer code = new StringWriter();
code.write("template <class T, class H>\n");
code.write(
"typename H::template Rebind<T>::Result& Field(H& obj)\n");
code.write("{ return obj; }\n");
failTest(code.toString());
}
public void testBug36699() {
boolean testPassed = false;
try {
Writer code = new StringWriter();
code.write(
"template < template <class> class ThreadingModel = DEFAULT_THREADING,\n");
code.write("std::size_t chunkSize = DEFAULT_CHUNK_SIZE,\n");
code.write(
"std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE >\n");
code.write("class SmallObject : public ThreadingModel<\n");
code.write(
"SmallObject<ThreadingModel, chunkSize, maxSmallObjectSize> >\n");
code.write("{};\n");
TranslationUnit tu = parse(code.toString());
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
public void testBug36699() throws Exception {
Writer code = new StringWriter();
code.write(
"template < template <class> class ThreadingModel = DEFAULT_THREADING,\n");
code.write("std::size_t chunkSize = DEFAULT_CHUNK_SIZE,\n");
code.write(
"std::size_t maxSmallObjectSize = MAX_SMALL_OBJECT_SIZE >\n");
code.write("class SmallObject : public ThreadingModel<\n");
code.write(
"SmallObject<ThreadingModel, chunkSize, maxSmallObjectSize> >\n");
code.write("{};\n");
failTest(code.toString());
}
public void testBug36704() {
boolean testPassed = false;
try {
TranslationUnit tu =
parse("template <class T, class U> struct Length< Typelist<T, U> > { enum { value = 1 + Length<U>::value };};);");
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
}
public void testBug36707() {
boolean testPassed = false;
try {
TranslationUnit tu =
parse("enum { exists = sizeof(typename H::Small) == sizeof((H::Test(H::MakeT()))) };");
testPassed = true;
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
}
public void testBug36708() {
boolean testPassed = false;
try {
TranslationUnit tu =
parse("enum { isPointer = PointerTraits<T>::result };");
testPassed = true;
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
}
public void testBug36714(){
boolean testPassed = false;
try{
Writer code = new StringWriter();
code.write("unsigned long a = 0UL;\n");
code.write("unsigned long a2 = 0L; \n");
public void testBug36714() throws Exception {
Writer code = new StringWriter();
code.write("unsigned long a = 0UL;\n");
code.write("unsigned long a2 = 0L; \n");
TranslationUnit tu = parse(code.toString());
testPassed = true;
} catch (Throwable e ) {
if( ! (e instanceof ParserException))
fail( "Unexpected Error: " + e.getMessage() );
}
if( testPassed )
fail( "The expected error did not occur.");
failTest(code.toString());
}
public void testBug36730(){
boolean testPassed = false;
try{
TranslationUnit tu = parse("FUNCTION_MACRO( 1, a );\n int i;");
failTest("FUNCTION_MACRO( 1, a );\n int i;");
}
public void testBug36702() throws Exception
{
Writer code = new StringWriter();
code.write( "void mad_decoder_init(struct mad_decoder *, void *,\n" );
code.write( " enum mad_flow (*)(void *, struct mad_stream *),\n" );
code.write( " enum mad_flow (*)(void *, struct mad_header const *),\n" );
code.write( " enum mad_flow (*)(void *,\n" );
code.write( " struct mad_stream const *,\n" );
code.write( " struct mad_frame *),\n" );
code.write( " enum mad_flow (*)(void *,\n" );
code.write( " struct mad_header const *,\n" );
code.write( " struct mad_pcm *),\n" );
code.write( " enum mad_flow (*)(void *,\n" );
code.write( " struct mad_stream *,\n" );
code.write( " struct mad_frame *),\n" );
code.write( " enum mad_flow (*)(void *, void *, unsigned int *)\n" );
code.write( ");\n" );
failTest( code.toString() );
testPassed = true;
} catch (Throwable e ) {
if( ! (e instanceof ParserException))
fail( "Unexpected Error: " + e.getMessage() );
}
if( testPassed )
fail( "The expected error did not occur.");
}
}

View file

@ -14,31 +14,17 @@ import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.DOMTests;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
/**
* @author jcamelon
*/
public class LokiFailures extends DOMTests {
public class LokiFailures extends BaseDOMTest {
public LokiFailures(String name) {
super(name);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new LokiFailures("testBugSingleton192"));
suite.addTest(new LokiFailures("testBugFunctor758"));
return suite;
}
public void testBugSingleton192() {
failTest("int Test::* pMember_;" );
}
@ -58,21 +44,5 @@ public class LokiFailures extends DOMTests {
} catch( IOException ioe ){}
failTest( code.toString() );
}
public void failTest( String code )
{
boolean testPassed = false;
try {
TranslationUnit tu = parse(code);
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
}
if (testPassed)
fail("The expected error did not occur.");
}
}
}

View file

@ -12,90 +12,41 @@ package org.eclipse.cdt.core.parser.failedTests;
import java.io.StringWriter;
import java.io.Writer;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.DOMTests;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.core.parser.tests.BaseDOMTest;
/**
* @author hamer
*/
public class STLFailedTests extends DOMTests {
public class STLFailedTests extends BaseDOMTest {
public STLFailedTests(String name) {
super(name);
}
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(new STLFailedTests("testBug36766A"));
suite.addTest(new STLFailedTests("testBug36766B"));
suite.addTest(new STLFailedTests("testBug36766C"));
return suite;
public void testBug36766A() throws Exception {
Writer code = new StringWriter();
code.write("template <class _CharT, class _Alloc>\n");
code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n");
code.write("const allocator_type& __a): _Base(__a)\n");
code.write("{}\n");
failTest(code.toString());
}
public void testBug36766A() {
boolean testPassed = false;
try {
Writer code = new StringWriter();
code.write("template <class _CharT, class _Alloc>\n");
code.write("rope<_CharT, _Alloc>::rope(size_t __n, _CharT __c,\n");
code.write("const allocator_type& __a): _Base(__a)\n");
code.write("{}\n");
TranslationUnit tu = parse(code.toString());
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
public void testBug36766B() throws Exception {
Writer code = new StringWriter();
code.write("template<class _CharT>\n");
code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n");
code.write("(const _CharT* __leaf, size_t __n)\n");
code.write("{}\n");
failTest(code.toString());
}
public void testBug36766B() {
boolean testPassed = false;
try {
Writer code = new StringWriter();
code.write("template<class _CharT>\n");
code.write("bool _Rope_insert_char_consumer<_CharT>::operator()\n");
code.write("(const _CharT* __leaf, size_t __n)\n");
code.write("{}\n");
TranslationUnit tu = parse(code.toString());
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
public void testBug36766C() throws Exception {
Writer code = new StringWriter();
code.write("template <class _CharT, class _Alloc>\n");
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n");
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n");
code.write("{}\n");
failTest(code.toString());
}
public void testBug36766C() {
boolean testPassed = false;
try {
Writer code = new StringWriter();
code.write("template <class _CharT, class _Alloc>\n");
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>&\n");
code.write("_Rope_char_ref_proxy<_CharT, _Alloc>::operator= (_CharT __c)\n");
code.write("{}\n");
TranslationUnit tu = parse(code.toString());
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
if (testPassed)
fail("The expected error did not occur.");
}
}
}

View file

@ -17,9 +17,7 @@ import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.parser.tests.ScannerTestCase;
import org.eclipse.cdt.internal.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Token;
import org.eclipse.cdt.core.parser.tests.BaseScannerTest;
/**
* @author aniefer
@ -27,7 +25,7 @@ import org.eclipse.cdt.internal.core.parser.Token;
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class ScannerFailedTest extends ScannerTestCase {
public class ScannerFailedTest extends BaseScannerTest {
public ScannerFailedTest(String name){
super(name);

View file

@ -20,13 +20,13 @@ import java.util.LinkedList;
import java.util.Properties;
import java.util.Set;
import org.eclipse.cdt.internal.core.parser.IParserCallback;
import org.eclipse.cdt.internal.core.parser.NullParserCallback;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.internal.core.parser.IParserCallback;
import org.eclipse.cdt.internal.core.parser.NullParserCallback;
/**
* @author aniefer
*

View file

@ -14,17 +14,15 @@ package org.eclipse.cdt.core.parser.tests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import org.eclipse.core.runtime.Path;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.cdt.internal.core.parser.IParser;
import org.eclipse.cdt.internal.core.parser.Parser;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.core.runtime.Path;

View file

@ -0,0 +1,62 @@
/*******************************************************************************
* Copyright (c) 2001 IBM Corporation 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 Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.core.parser.tests;
import junit.framework.TestCase;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.DOMFactory;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.parser.IParser;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
/**
* @author jcamelon
*
*/
public class BaseDOMTest extends TestCase {
public BaseDOMTest( String arg )
{
super( arg );
}
public TranslationUnit parse( String code ) throws Exception
{
return parse( code, false, true );
}
public TranslationUnit parse(String code, boolean quickParse, boolean throwOnError ) throws Exception {
DOMBuilder domBuilder = DOMFactory.createDOMBuilder(false);
IParser parser = new Parser(code, domBuilder, quickParse );
if( ! parser.parse() )
if( throwOnError ) throw new ParserException( "Parse failure" );
else domBuilder.getTranslationUnit().setParseSuccessful( false );
return domBuilder.getTranslationUnit();
}
public void failTest(String code) {
boolean testPassed = false;
try {
TranslationUnit tu = parse(code);
testPassed = true;
fail( "We should not reach this point");
} catch (Throwable e) {
if (!(e instanceof ParserException))
fail("Unexpected Error: " + e.getMessage());
}
if (testPassed)
fail("The expected error did not occur.");
}
}

View file

@ -0,0 +1,198 @@
/*******************************************************************************
* Copyright (c) 2001 IBM Corporation 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 Corp. - Rational Software - initial implementation
******************************************************************************/
package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import junit.framework.TestCase;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.Scanner;
import org.eclipse.cdt.internal.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Token;
/**
* @author jcamelon
*
*/
public class BaseScannerTest extends TestCase {
protected Scanner scanner;
public BaseScannerTest( String x )
{
super(x);
}
public void initializeScanner(String input)
{
scanner= new Scanner();
scanner.initialize( new StringReader(input),"TEXT");
}
public int fullyTokenize() throws Exception
{
try
{
Token t= scanner.nextToken();
while (t != null)
{
if (verbose)
System.out.println("Token t = " + t);
if ((t.type < 1) || (t.type > Token.tLAST))
System.out.println("Unknown type for token " + t);
t= scanner.nextToken();
}
}
catch (Parser.EndOfFile e)
{
}
catch (ScannerException se)
{
throw se;
}
return scanner.getCount();
}
public void validateIdentifier(String expectedImage) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == Token.tIDENTIFIER);
assertTrue(t.image.equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateInteger(String expectedImage) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == Token.tINTEGER);
assertTrue(t.image.equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateFloatingPointLiteral(String expectedImage) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == Token.tFLOATINGPT);
assertTrue(t.image.equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateChar( char expected )throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.getType() == Token.tCHAR );
Character c = new Character( expected );
assertEquals( t.getImage(), c.toString() );
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateChar( String expected ) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.getType() == Token.tCHAR );
assertEquals( t.getImage(), expected );
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateString( String expectedImage ) throws ScannerException
{
validateString( expectedImage, false );
}
public void validateString(String expectedImage, boolean lString ) throws ScannerException
{
try {
Token t= scanner.nextToken();
if( lString )
assertTrue(t.getType() == Token.tLSTRING);
else
assertTrue(t.getType() == Token.tSTRING);
assertTrue(t.getImage().equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateToken(int tokenType) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == tokenType);
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateBalance(int expected)
{
assertTrue(scanner.getDepth() == expected);
}
public void validateBalance()
{
assertTrue(scanner.getDepth() == 0);
}
public void validateEOF() throws ScannerException
{
try {
assertNull(scanner.nextToken());
} catch (Parser.EndOfFile e) {
}
}
public void validateDefinition(String name, String value)
{
String definition= null;
definition= (String) scanner.getDefinition(name);
assertNotNull(definition);
assertTrue(definition.trim().equals(value));
}
public void validateDefinition(String name, int value)
{
String definition= null;
definition= (String) scanner.getDefinition(name);
assertNotNull(definition);
int intValue= (Integer.valueOf((String) definition)).intValue();
assertEquals(value, intValue);
}
public void validateAsUndefined(String name)
{
assertNull(scanner.getDefinition(name));
}
public static final String EXCEPTION_THROWN = "Exception thrown ";
public static final String EXPECTED_FAILURE = "This statement should not be reached "
+ "as we sent in bad preprocessor input to the scanner";
public static final boolean verbose = false;
}

View file

@ -6,8 +6,6 @@ import java.io.Writer;
import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.cdt.internal.core.dom.ASMDefinition;
import org.eclipse.cdt.internal.core.dom.AccessSpecifier;
import org.eclipse.cdt.internal.core.dom.ArrayQualifier;
@ -17,8 +15,6 @@ import org.eclipse.cdt.internal.core.dom.ClassSpecifier;
import org.eclipse.cdt.internal.core.dom.ConstructorChain;
import org.eclipse.cdt.internal.core.dom.ConstructorChainElement;
import org.eclipse.cdt.internal.core.dom.ConstructorChainElementExpression;
import org.eclipse.cdt.internal.core.dom.DOMBuilder;
import org.eclipse.cdt.internal.core.dom.DOMFactory;
import org.eclipse.cdt.internal.core.dom.DeclSpecifier;
import org.eclipse.cdt.internal.core.dom.Declarator;
import org.eclipse.cdt.internal.core.dom.ElaboratedTypeSpecifier;
@ -42,33 +38,16 @@ import org.eclipse.cdt.internal.core.dom.TemplateParameterList;
import org.eclipse.cdt.internal.core.dom.TranslationUnit;
import org.eclipse.cdt.internal.core.dom.UsingDeclaration;
import org.eclipse.cdt.internal.core.dom.UsingDirective;
import org.eclipse.cdt.internal.core.parser.IParser;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.ParserException;
import org.eclipse.cdt.internal.core.parser.Token;
public class DOMTests extends TestCase {
public class DOMTests extends BaseDOMTest {
public DOMTests( String arg )
{
super( arg );
}
public TranslationUnit parse( String code ) throws Exception
{
return parse( code, false, true );
}
public TranslationUnit parse(String code, boolean quickParse, boolean throwOnError ) throws Exception {
DOMBuilder domBuilder = DOMFactory.createDOMBuilder(false);
IParser parser = new Parser(code, domBuilder, quickParse );
if( ! parser.parse() )
if( throwOnError ) throw new ParserException( "Parse failure" );
else domBuilder.getTranslationUnit().setParseSuccessful( false );
return domBuilder.getTranslationUnit();
}
public void testNamespaceDefinition() throws Exception
{
for( int i = 0; i < 2; ++i )
@ -1635,8 +1614,18 @@ public class DOMTests extends TestCase {
Writer code = new StringWriter();
code.write("A ( * const fPtr) (void *); \n");
code.write("A (* const fPtr2) ( A * ); \n");
code.write("A (*const fPtr3) ( A * ) = function\n");
TranslationUnit tu = parse(code.toString());
assertEquals( tu.getDeclarations().size(), 2 );
SimpleDeclaration simple = (SimpleDeclaration)tu.getDeclarations().get(0);
assertEquals( simple.getDeclarators().size(), 1) ;
Declarator top = (Declarator)simple.getDeclarators().get(0);
assertEquals( top.getPointerOperators().size(), 0 );
assertNotNull( top.getDeclarator() );
assertEquals( top.getDeclarator().getPointerOperators().size(), 1 );
PointerOperator po = (PointerOperator)top.getDeclarator().getPointerOperators().get(0);
assertTrue( po.isConst());
assertFalse( po.isVolatile());
assertEquals( po.getType(), PointerOperator.t_pointer);
}
public void testBug36794() throws Exception
@ -1659,6 +1648,11 @@ public class DOMTests extends TestCase {
assertNotNull( i.next() );
}
public void testBug36799() throws Exception
{
TranslationUnit tu = parse( "static const int __WORD_BIT = int(CHAR_BIT*sizeof(unsigned int));");
assertEquals( tu.getDeclarations().size(), 1 );
}
}

View file

@ -21,10 +21,9 @@ import java.util.StringTokenizer;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import org.eclipse.core.runtime.Path;
import org.eclipse.cdt.internal.core.parser.IParser;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.core.runtime.Path;
/**
* @author aniefer

View file

@ -10,12 +10,12 @@
***********************************************************************/
package org.eclipse.cdt.core.parser.tests;
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
/**
* @author jcamelon
*

View file

@ -1,17 +1,11 @@
package org.eclipse.cdt.core.parser.tests;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.cdt.internal.core.parser.IMacroDescriptor;
import org.eclipse.cdt.internal.core.parser.Parser;
import org.eclipse.cdt.internal.core.parser.Scanner;
import org.eclipse.cdt.internal.core.parser.ScannerException;
import org.eclipse.cdt.internal.core.parser.Token;
@ -23,7 +17,7 @@ import org.eclipse.cdt.internal.core.parser.Token;
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class ScannerTestCase extends TestCase
public class ScannerTestCase extends BaseScannerTest
{
public class TableRow
{
@ -152,52 +146,12 @@ public class ScannerTestCase extends TestCase
}
public final static String EXCEPTION_THROWN= "Exception thrown ";
public final static String EXPECTED_FAILURE=
"This statement should not be reached "
+ "as we sent in bad preprocessor input to the scanner";
public final static boolean verbose= false;
public final static boolean doIncludeStdio= false;
public final static boolean doIncludeWindowsH= false;
public final static boolean doIncludeWinUserH= false;
public final static int SIZEOF_TRUTHTABLE = 10;
public void initializeScanner(String input)
{
scanner= new Scanner();
scanner.initialize( new StringReader(input),"TEXT");
}
public static Test suite()
{
return new TestSuite(ScannerTestCase.class);
}
public int fullyTokenize() throws Exception
{
try
{
Token t= scanner.nextToken();
while (t != null)
{
if (verbose)
System.out.println("Token t = " + t);
if ((t.type < 1) || (t.type > Token.tLAST))
System.out.println("Unknown type for token " + t);
t= scanner.nextToken();
}
}
catch (Parser.EndOfFile e)
{
}
catch (ScannerException se)
{
throw se;
}
return scanner.getCount();
}
public void testWeirdStrings()
{
@ -238,8 +192,6 @@ public class ScannerTestCase extends TestCase
}
Scanner scanner;
/**
* Constructor for ScannerTestCase.
@ -1028,130 +980,6 @@ public class ScannerTestCase extends TestCase
}
public void validateIdentifier(String expectedImage) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == Token.tIDENTIFIER);
assertTrue(t.image.equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateInteger(String expectedImage) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == Token.tINTEGER);
assertTrue(t.image.equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateFloatingPointLiteral(String expectedImage) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == Token.tFLOATINGPT);
assertTrue(t.image.equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateChar( char expected )throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.getType() == Token.tCHAR );
Character c = new Character( expected );
assertEquals( t.getImage(), c.toString() );
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateChar( String expected ) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.getType() == Token.tCHAR );
assertEquals( t.getImage(), expected );
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateString( String expectedImage ) throws ScannerException
{
validateString( expectedImage, false );
}
public void validateString(String expectedImage, boolean lString ) throws ScannerException
{
try {
Token t= scanner.nextToken();
if( lString )
assertTrue(t.getType() == Token.tLSTRING);
else
assertTrue(t.getType() == Token.tSTRING);
assertTrue(t.getImage().equals(expectedImage));
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateToken(int tokenType) throws ScannerException
{
try {
Token t= scanner.nextToken();
assertTrue(t.type == tokenType);
} catch (Parser.EndOfFile e) {
assertTrue(false);
}
}
public void validateBalance(int expected)
{
assertTrue(scanner.getDepth() == expected);
}
public void validateBalance()
{
assertTrue(scanner.getDepth() == 0);
}
public void validateEOF() throws ScannerException
{
try {
assertNull(scanner.nextToken());
} catch (Parser.EndOfFile e) {
}
}
public void validateDefinition(String name, String value)
{
String definition= null;
definition= (String) scanner.getDefinition(name);
assertNotNull(definition);
assertTrue(definition.trim().equals(value));
}
public void validateDefinition(String name, int value)
{
String definition= null;
definition= (String) scanner.getDefinition(name);
assertNotNull(definition);
int intValue= (Integer.valueOf((String) definition)).intValue();
assertEquals(value, intValue);
}
public void validateAsUndefined(String name)
{
assertNull(scanner.getDefinition(name));
}
public void validateAllDefinitions(TableRow row)
{
int winner= row.selectWinner();