mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 08:55:25 +02:00
Patch from David Daoust. Added IncludeTest to ParserTestSuite.
This commit is contained in:
parent
a0c153442c
commit
f33bcba3fa
3 changed files with 131 additions and 0 deletions
|
@ -74,6 +74,7 @@ import org.eclipse.cdt.internal.core.parser.Parser;
|
|||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
|
@ -175,6 +176,15 @@ public class FileBasePluginTest extends TestCase {
|
|||
// return file;
|
||||
// }
|
||||
|
||||
protected IFolder importFolder(String folderName) throws Exception {
|
||||
IFolder folder = project.getProject().getFolder(folderName);
|
||||
|
||||
//Create file input stream
|
||||
if( !folder.exists() )
|
||||
folder.create( false, false, monitor );
|
||||
|
||||
return folder;
|
||||
}
|
||||
protected IFile importFile(String fileName, String contents ) throws Exception{
|
||||
//Obtain file handle
|
||||
IFile file = project.getProject().getFile(fileName);
|
||||
|
|
|
@ -17,6 +17,7 @@ import junit.framework.TestSuite;
|
|||
import org.eclipse.cdt.core.model.tests.CModelElementsTests;
|
||||
import org.eclipse.cdt.core.model.tests.StructuralCModelElementsTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ast2.DOMParserTestSuite;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.IncludeTest;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.ObjectMapTest;
|
||||
import org.eclipse.cdt.core.parser.tests.scanner2.Scanner2Test;
|
||||
|
||||
|
@ -50,6 +51,7 @@ public class ParserTestSuite extends TestCase {
|
|||
suite.addTestSuite( ObjectMapTest.class );
|
||||
suite.addTest( CompleteParsePluginTest.suite() );
|
||||
suite.addTest( IScannerInfoPluginTest.suite() );
|
||||
suite.addTestSuite( IncludeTest.class );
|
||||
suite.addTest( ScannerParserLoopTest.suite() );
|
||||
suite.addTest( GCCParserExtensionTestSuite.suite() );
|
||||
suite.addTest( DOMParserTestSuite.suite() );
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002-2004 Rational Software 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 Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.core.parser.tests.scanner2;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.parser.CodeReader;
|
||||
import org.eclipse.cdt.core.parser.ExtendedScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.IParser;
|
||||
import org.eclipse.cdt.core.parser.IScannerInfo;
|
||||
import org.eclipse.cdt.core.parser.NullLogService;
|
||||
import org.eclipse.cdt.core.parser.ParserFactory;
|
||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||
import org.eclipse.cdt.core.parser.ParserMode;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTScope;
|
||||
import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
||||
import org.eclipse.cdt.core.parser.tests.CompleteParseBaseTest;
|
||||
import org.eclipse.cdt.core.parser.tests.CompleteParsePluginTest;
|
||||
import org.eclipse.cdt.core.parser.tests.FileBasePluginTest;
|
||||
import org.eclipse.cdt.internal.core.parser.Parser;
|
||||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
|
||||
/**
|
||||
* @author jcamelon
|
||||
*
|
||||
*/
|
||||
public class IncludeTest extends FileBasePluginTest {
|
||||
|
||||
private static final String [] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public IncludeTest(String name) {
|
||||
super(name, IncludeTest.class);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite( IncludeTest.class );
|
||||
suite.addTest( new CompleteParsePluginTest("cleanupProject") ); //$NON-NLS-1$
|
||||
return suite;
|
||||
}
|
||||
CompleteParseBaseTest.FullParseCallback c;
|
||||
|
||||
protected IASTScope parse(IFile code, ParserLanguage language, IScannerInfo scannerInfo ) throws Exception
|
||||
{
|
||||
c = new CompleteParseBaseTest.FullParseCallback();
|
||||
InputStream stream = code.getContents();
|
||||
IParser parser = ParserFactory.createParser(
|
||||
ParserFactory.createScanner( new CodeReader( code.getLocation().toOSString(), stream ), scannerInfo, //$NON-NLS-1$
|
||||
ParserMode.COMPLETE_PARSE, language, c, new NullLogService(), null ), c, ParserMode.COMPLETE_PARSE, language, null
|
||||
);
|
||||
stream.close();
|
||||
boolean parseResult = parser.parse();
|
||||
// throw exception if there are generated IProblems
|
||||
if( !parseResult ) throw new ParserException( "FAILURE"); //$NON-NLS-1$
|
||||
assertTrue( ((Parser)parser).validateCaches());
|
||||
return c.getCompilationUnit();
|
||||
}
|
||||
|
||||
|
||||
public void testIncludeNext() throws Exception
|
||||
{
|
||||
String baseFile = "int zero; \n#include \"foo.h\""; //$NON-NLS-1$
|
||||
String i1Next = "int one; \n#include_next <foo.h>"; //$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.cpp", 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[2];
|
||||
path[0] = twof.getFullPath().toOSString();
|
||||
path[1] = threef.getFullPath().toOSString();
|
||||
|
||||
IScannerInfo scannerInfo = new ExtendedScannerInfo( Collections.EMPTY_MAP, path, EMPTY_STRING_ARRAY, path );
|
||||
Iterator i = parse( base, ParserLanguage.C, scannerInfo ).getDeclarations();
|
||||
IASTVariable v;
|
||||
|
||||
assertTrue( i.hasNext() );
|
||||
v = (IASTVariable) i.next();
|
||||
assertEquals( v.getName(), "zero" ); //$NON-NLS-1$
|
||||
|
||||
assertTrue( i.hasNext() );
|
||||
v = (IASTVariable) i.next();
|
||||
assertEquals( v.getName(), "one" ); //$NON-NLS-1$
|
||||
|
||||
assertTrue( i.hasNext() );
|
||||
v = (IASTVariable) i.next();
|
||||
assertEquals( v.getName(), "two" ); //$NON-NLS-1$
|
||||
|
||||
assertTrue( i.hasNext() );
|
||||
v = (IASTVariable) i.next();
|
||||
assertEquals( v.getName(), "three" ); //$NON-NLS-1$
|
||||
|
||||
assertFalse( i.hasNext() );
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue