mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
CORE
Fix Bug 38380 "Include" class public methods fails JUnit tests Updated CModel, DOM, Scanner and current Parser callback to set the information appropriately. TESTS Moved testBug23478A() & testBug23478B() from failed tests to TranslationUnitTests.java. Removed TranslationUnitFailedTests.java as it was empty. I also had to apply Alain's partial fix to the Parser_SymbolTable branch to get this working.
This commit is contained in:
parent
8efde68c59
commit
f5f345cdff
15 changed files with 83 additions and 220 deletions
|
@ -161,8 +161,13 @@ public class DOMBuilder implements IParserCallback
|
|||
/**
|
||||
* @see org.eclipse.cdt.internal.core.newparser.IParserCallback#inclusionBegin(java.lang.String)
|
||||
*/
|
||||
public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) {
|
||||
Inclusion inclusion = new Inclusion( includeFile, offset, inclusionBeginOffset, offset - inclusionBeginOffset + includeFile.length() + 1 );
|
||||
public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) {
|
||||
Inclusion inclusion = new Inclusion(
|
||||
includeFile,
|
||||
offset,
|
||||
inclusionBeginOffset,
|
||||
offset - inclusionBeginOffset + includeFile.length() + 1,
|
||||
local );
|
||||
translationUnit.addInclusion( inclusion );
|
||||
return inclusion;
|
||||
}
|
||||
|
|
|
@ -18,8 +18,18 @@ package org.eclipse.cdt.internal.core.dom;
|
|||
*/
|
||||
public class Inclusion extends PreprocessorStatement {
|
||||
|
||||
public Inclusion( String name, int nameOffset, int startingOffset, int totalLength )
|
||||
private final boolean local;
|
||||
|
||||
public Inclusion( String name, int nameOffset, int startingOffset, int totalLength, boolean local )
|
||||
{
|
||||
super( name, nameOffset, startingOffset, totalLength );
|
||||
this.local = local;
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,8 +91,8 @@ public class LineNumberedDOMBuilder extends DOMBuilder {
|
|||
public Object inclusionBegin(
|
||||
String includeFile,
|
||||
int offset,
|
||||
int inclusionBeginOffset) {
|
||||
Object inclusion = super.inclusionBegin(includeFile, offset, inclusionBeginOffset);
|
||||
int inclusionBeginOffset, boolean local) {
|
||||
Object inclusion = super.inclusionBegin(includeFile, offset, inclusionBeginOffset, local);
|
||||
setLineNumber( (IOffsetable)inclusion, inclusionBeginOffset, true );
|
||||
setLineNumber( (IOffsetable)inclusion, offset + includeFile.length() + 1, false );
|
||||
return inclusion;
|
||||
|
|
|
@ -10,8 +10,11 @@ import org.eclipse.cdt.core.model.IInclude;
|
|||
|
||||
public class Include extends SourceManipulation implements IInclude {
|
||||
|
||||
public Include(ICElement parent, String name) {
|
||||
private final boolean standard;
|
||||
|
||||
public Include(ICElement parent, String name, boolean isStandard) {
|
||||
super(parent, name, CElement.C_INCLUDE);
|
||||
standard = isStandard;
|
||||
}
|
||||
|
||||
public String getIncludeName() {
|
||||
|
@ -19,7 +22,7 @@ public class Include extends SourceManipulation implements IInclude {
|
|||
}
|
||||
|
||||
public boolean isStandard() {
|
||||
return true;
|
||||
return standard;
|
||||
}
|
||||
|
||||
protected CElementInfo createElementInfo () {
|
||||
|
|
|
@ -28,7 +28,7 @@ public class ModelBuilder implements IStructurizerCallback {
|
|||
}
|
||||
|
||||
public void includeDecl(String name, int startPos, int endPos, int startLine, int endLine) {
|
||||
Include elem= new Include(fCurrFile, name);
|
||||
Include elem= new Include(fCurrFile, name, true ); // assume standard inclusion
|
||||
elem.setPos(startPos, fixLength(startPos, endPos));
|
||||
elem.setIdPos(startPos, fixLength(startPos, endPos));
|
||||
elem.setLines(startLine, endLine);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
2003-06-05 John Camelon
|
||||
Fix Bug 38380 "Include" class public methods fails JUnit tests
|
||||
|
||||
2003-05-05 John Camelon/Andrew Niefer
|
||||
Added Symboltable infrastructure into main parser.
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ public class CModelBuilder {
|
|||
}
|
||||
protected Include createInclusion(Parent parent, Inclusion inclusion){
|
||||
// create element
|
||||
Include element = new Include((CElement)parent, inclusion.getName());
|
||||
Include element = new Include((CElement)parent, inclusion.getName(), !inclusion.isLocal());
|
||||
// add to parent
|
||||
parent.addChild((CElement) element);
|
||||
// set position
|
||||
|
|
|
@ -125,7 +125,7 @@ public class ExpressionEvaluator implements IParserCallback {
|
|||
/**
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#inclusionBegin(java.lang.String, int)
|
||||
*/
|
||||
public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) {
|
||||
public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface IParserCallback {
|
|||
public Object translationUnitBegin();
|
||||
public void translationUnitEnd(Object unit);
|
||||
|
||||
public Object inclusionBegin(String includeFile, int nameBeginOffset, int inclusionBeginOffset);
|
||||
public Object inclusionBegin(String includeFile, int nameBeginOffset, int inclusionBeginOffset, boolean local);
|
||||
public void inclusionEnd(Object inclusion);
|
||||
public Object macro(String macroName, int macroNameOffset, int macroBeginOffset, int macroEndOffset);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public class NullParserCallback implements IParserCallback {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.internal.core.parser.IParserCallback#inclusionBegin(java.lang.String, int)
|
||||
*/
|
||||
public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset) {
|
||||
public Object inclusionBegin(String includeFile, int offset, int inclusionBeginOffset, boolean local) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1664,7 +1664,7 @@ public class Scanner implements IScanner {
|
|||
if( callback != null )
|
||||
{
|
||||
offset = contextStack.getCurrentContext().getOffset() - f.length() - 1; // -1 for the end quote
|
||||
callback.inclusionEnd(callback.inclusionBegin( f, offset, beginningOffset ));
|
||||
callback.inclusionEnd(callback.inclusionBegin( f, offset, beginningOffset, !useIncludePath ));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-06-05 John Camelon
|
||||
Moved testBug23478A() & testBug23478B() from failed tests to TranslationUnitTests.java.
|
||||
Removed TranslationUnitFailedTests.java as it was empty.
|
||||
|
||||
2003-05-05 John Camelon/Andrew Niefer
|
||||
Added CrossReferenceTests to ParserTestSuite to test symbol-table/DOM interworking.
|
||||
|
||||
|
|
|
@ -1,206 +0,0 @@
|
|||
package org.eclipse.cdt.core.model.failedTests;
|
||||
|
||||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003 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:
|
||||
* Rational Software - Initial API and implementation
|
||||
***********************************************************************/
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IInclude;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.testplugin.util.ExpectedStrings;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceDescription;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This file contains a set of generic tests for the core C model's TranslationUnit
|
||||
* class. There is nothing exotic here, mostly just sanity type tests
|
||||
*
|
||||
*/
|
||||
public class TranslationUnitFailedTests extends TestCase {
|
||||
IWorkspace workspace;
|
||||
IWorkspaceRoot root;
|
||||
ICProject testProject;
|
||||
IFile cfile, exefile, libfile, archfile, objfile;
|
||||
Path cpath, exepath, libpath, archpath, objpath;
|
||||
NullProgressMonitor monitor;
|
||||
|
||||
/* This is a list of elements in the test .c file. It will be used
|
||||
* in a number of places in the tests
|
||||
*/
|
||||
String[] expectedStringList= {"stdio.h", "unistd.h", "func2p",
|
||||
"globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype",
|
||||
"func1", "func2", "main", "func3"};
|
||||
int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65};
|
||||
/* This is a list of that the types of the above list of elements is
|
||||
* expected to be.
|
||||
*/
|
||||
int[] expectedTypes= { ICElement.C_INCLUDE, ICElement.C_INCLUDE,
|
||||
ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE,
|
||||
ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF,
|
||||
ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION,
|
||||
ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION};
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for TranslationUnitTests
|
||||
* @param name
|
||||
*/
|
||||
public TranslationUnitFailedTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() throws CoreException,FileNotFoundException {
|
||||
/***
|
||||
* The rest of the tests assume that they have a working workspace
|
||||
* and workspace root object to use to create projects/files in,
|
||||
* so we need to get them setup first.
|
||||
*/
|
||||
IWorkspaceDescription desc;
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
|
||||
workspace= ResourcesPlugin.getWorkspace();
|
||||
root= workspace.getRoot();
|
||||
monitor = new NullProgressMonitor();
|
||||
if (workspace==null)
|
||||
fail("Workspace was not setup");
|
||||
if (root==null)
|
||||
fail("Workspace root was not setup");
|
||||
|
||||
desc=workspace.getDescription();
|
||||
desc.setAutoBuilding(false);
|
||||
workspace.setDescription(desc);
|
||||
|
||||
/***
|
||||
* Setup the various files, paths and projects that are needed by the
|
||||
* tests
|
||||
*/
|
||||
|
||||
testProject=CProjectHelper.createCProject("filetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
|
||||
cfile = testProject.getProject().getFile("exetest.c");
|
||||
if (!cfile.exists()) {
|
||||
cfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/cfiles/TranslationUnits.c"),false, monitor);
|
||||
|
||||
}
|
||||
cpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.c");
|
||||
|
||||
objfile = testProject.getProject().getFile("exetest.o");
|
||||
if (!objfile.exists()) {
|
||||
objfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor);
|
||||
|
||||
}
|
||||
objpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.o");
|
||||
|
||||
exefile = testProject.getProject().getFile("test_g");
|
||||
if (!exefile.exists()) {
|
||||
exefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor);
|
||||
|
||||
}
|
||||
exepath=new Path(workspace.getRoot().getLocation()+"/filetest/exe_g");
|
||||
|
||||
archfile = testProject.getProject().getFile("libtestlib_g.a");
|
||||
if (!archfile.exists()) {
|
||||
archfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor);
|
||||
|
||||
}
|
||||
libpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.so");
|
||||
|
||||
libfile = testProject.getProject().getFile("libtestlib_g.so");
|
||||
if (!libfile.exists()) {
|
||||
libfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor);
|
||||
|
||||
}
|
||||
archpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.a");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() throws CoreException {
|
||||
// release resources here and clean-up
|
||||
testProject.getProject().delete(true,true,monitor);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Simple sanity tests for the getInclude call
|
||||
*/
|
||||
public void testBug23478A() {
|
||||
IInclude myInclude;
|
||||
int x;
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
for (x=0; x < includes.length; x++) {
|
||||
myInclude=myTranslationUnit.getInclude(includes[x]);
|
||||
if (myInclude==null)
|
||||
fail("Unable to get include: " + includes[x]);
|
||||
else {
|
||||
// Failed test: Include.getIncludeName() always returns "";
|
||||
// assertTrue
|
||||
assertFalse("PR:23478 Expected:"+ new String("") +" Got:"+ myInclude.getIncludeName(), includes[x].equals(myInclude.getIncludeName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/***
|
||||
* Simple sanity tests for the getIncludes call
|
||||
*/
|
||||
public void testBug23478B() throws CModelException {
|
||||
IInclude myIncludes[];
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
ExpectedStrings myExp= new ExpectedStrings(includes);
|
||||
int x;
|
||||
ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
myIncludes=myTranslationUnit.getIncludes();
|
||||
for (x=0; x < myIncludes.length; x++) {
|
||||
myExp.foundString(myIncludes[x].getIncludeName());
|
||||
}
|
||||
// Failed test: Include.getIncludeName() always returns "";
|
||||
// assertTrue
|
||||
assertFalse(myExp.getMissingString(), myExp.gotAll());
|
||||
assertFalse(myExp.getExtraString(), !myExp.gotExtra());
|
||||
}
|
||||
|
||||
}
|
|
@ -232,6 +232,51 @@ public class TranslationUnitTests extends TestCase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple sanity tests for the getInclude call
|
||||
*/
|
||||
public void testBug23478A() {
|
||||
IInclude myInclude;
|
||||
int x;
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
for (x=0; x < includes.length; x++) {
|
||||
myInclude=myTranslationUnit.getInclude(includes[x]);
|
||||
if (myInclude==null)
|
||||
fail("Unable to get include: " + includes[x]);
|
||||
else {
|
||||
// Failed test: Include.getIncludeName() always returns "";
|
||||
// assertTrue
|
||||
assertTrue("PR:23478 Expected:"+ new String("") +" Got:"+ myInclude.getIncludeName(), includes[x].equals(myInclude.getIncludeName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/***
|
||||
* Simple sanity tests for the getIncludes call
|
||||
*/
|
||||
public void testBug23478B() throws CModelException {
|
||||
IInclude myIncludes[];
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
ExpectedStrings myExp= new ExpectedStrings(includes);
|
||||
int x;
|
||||
ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
myIncludes=myTranslationUnit.getIncludes();
|
||||
for (x=0; x < myIncludes.length; x++) {
|
||||
myExp.foundString(myIncludes[x].getIncludeName());
|
||||
}
|
||||
// Failed test: Include.getIncludeName() always returns "";
|
||||
// assertTrue
|
||||
assertTrue(myExp.getMissingString(), myExp.gotAll());
|
||||
assertTrue(myExp.getExtraString(), !myExp.gotExtra());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Simple sanity tests for the getElementAtLine() call
|
||||
*/
|
||||
|
|
|
@ -83,7 +83,6 @@ public class AutomatedIntegrationSuite extends TestSuite implements TestListener
|
|||
suite.addTestSuite(ScannerFailedTest.class);
|
||||
suite.addTestSuite(STLFailedTests.class);
|
||||
suite.addTestSuite(CModelElementsFailedTests.class);
|
||||
suite.addTestSuite(TranslationUnitFailedTests.class);
|
||||
|
||||
// Last test to trigger report generation
|
||||
suite.addTest(suite.new GenerateReport("testGenerateReport"));
|
||||
|
|
Loading…
Add table
Reference in a new issue