1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-09-10 12:03:16 +02:00

Testcase and fix for 164360, NPE while adding include to PDOM.

This commit is contained in:
Markus Schorn 2006-11-14 09:59:53 +00:00
parent 3eaab306ed
commit e3c77133d7
6 changed files with 96 additions and 10 deletions

View file

@ -24,12 +24,15 @@ import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IIndexBinding;
import org.eclipse.cdt.core.index.IIndexFile;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexName;
import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.core.testplugin.CTestPlugin;
import org.eclipse.cdt.core.testplugin.TestScannerProvider;
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.CCoreInternals;
@ -78,6 +81,10 @@ public class IndexBugsTests extends BaseTestCase {
return TestSourceReader.createFile(container, new Path(fileName), contents);
}
private void waitForIndexer() {
assertTrue(CCorePlugin.getIndexManager().joinIndexer(10000, NPM));
}
protected Pattern[] getPattern(String qname) {
String[] parts= qname.split("::");
Pattern[] result= new Pattern[parts.length];
@ -179,4 +186,64 @@ public class IndexBugsTests extends BaseTestCase {
}
}
public void test164360_1() throws Exception {
waitForIndexer();
try {
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
TestScannerProvider.sIncludeFiles= new String[]{include.getLocation().toOSString()};
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(1, includes.length);
IIndexInclude i= includes[0];
assertEquals(file.getLocation().toOSString(), i.getIncludedByLocation());
assertEquals(include.getLocation().toOSString(), i.getIncludesLocation());
assertEquals(true, i.isSystemInclude());
assertEquals(0, i.getNameOffset());
assertEquals(0, i.getNameLength());
}
finally {
fIndex.releaseReadLock();
}
}
finally {
TestScannerProvider.sIncludeFiles= null;
}
}
public void test164360_2() throws Exception {
waitForIndexer();
try {
IFile include= TestSourceReader.createFile(fCProject.getProject(), "test164360.h", "");
TestScannerProvider.sMacroFiles= new String[]{include.getLocation().toOSString()};
IFile file= TestSourceReader.createFile(fCProject.getProject(), "test164360.cpp", "");
TestSourceReader.waitUntilFileIsIndexed(fIndex, file, 4000);
fIndex.acquireReadLock();
try {
IIndexFile ifile= fIndex.getFile(file.getLocation());
assertNotNull(ifile);
IIndexInclude[] includes= ifile.getIncludes();
assertEquals(1, includes.length);
IIndexInclude i= includes[0];
assertEquals(file.getLocation().toOSString(), i.getIncludedByLocation());
assertEquals(include.getLocation().toOSString(), i.getIncludesLocation());
assertEquals(true, i.isSystemInclude());
assertEquals(0, i.getNameOffset());
assertEquals(0, i.getNameLength());
}
finally {
fIndex.releaseReadLock();
}
}
finally {
TestScannerProvider.sMacroFiles= null;
}
}
}

View file

@ -77,7 +77,7 @@ public class IndexListenerTest extends BaseTestCase {
try {
IFile file= TestSourceReader.createFile(fProject1.getProject(), "test.cpp", "int a;");
synchronized (mutex) {
mutex.wait(1000);
mutex.wait(8000);
if (state[0]+state[1] < 2) {
mutex.wait(1000);
}

View file

@ -14,20 +14,34 @@ package org.eclipse.cdt.core.testplugin;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IExtendedScannerInfo;
public class TestScannerInfo implements IScannerInfo {
private Map emptyMap = new HashMap(0);
public class TestScannerInfo implements IExtendedScannerInfo {
private static final String[] EMPTY = new String[0];
private static final Map EMPTY_MAP = new HashMap(0);
private String[] fIncludes;
private String[] fIncludeFiles;
private String[] fMacroFiles;
public TestScannerInfo(String[] includes) {
public TestScannerInfo(String[] includes, String[] includeFiles, String[] macroFiles) {
fIncludes= includes;
fIncludeFiles= includeFiles;
fMacroFiles= macroFiles;
}
public Map getDefinedSymbols() {
return emptyMap;
return EMPTY_MAP;
}
public String[] getIncludePaths() {
return fIncludes == null ? new String[0] : fIncludes;
return fIncludes == null ? EMPTY : fIncludes;
}
public String[] getIncludeFiles() {
return fIncludeFiles == null ? EMPTY: fIncludeFiles;
}
public String[] getLocalIncludePath() {
return null;
}
public String[] getMacroFiles() {
return fMacroFiles == null ? EMPTY: fMacroFiles;
}
}

View file

@ -20,10 +20,12 @@ import org.eclipse.core.resources.IResource;
public class TestScannerProvider extends AbstractCExtension implements IScannerInfoProvider {
public static String[] sIncludes= null;
public static String[] sIncludeFiles= null;
public static String[] sMacroFiles= null;
public final static String SCANNER_ID = CTestPlugin.PLUGIN_ID + ".TestScanner";
public IScannerInfo getScannerInformation(IResource resource) {
return new TestScannerInfo(sIncludes);
return new TestScannerInfo(sIncludes, sIncludeFiles, sMacroFiles);
}
public void subscribe(IResource resource, IScannerInfoChangeListener listener) {

View file

@ -234,7 +234,7 @@ public class DOMScanner extends BaseScanner {
{
int resolved = getGlobalOffset(0, 0);
CodeReader codeReader = (CodeReader) data;
locationMap.startInclusion( codeReader, resolved, resolved, resolved, resolved, CharArrayUtils.EMPTY, false);
locationMap.startInclusion( codeReader, resolved, resolved, resolved, resolved, CharArrayUtils.EMPTY, true);
}
super.pushContext(buffer, data);

View file

@ -54,7 +54,10 @@ public class PDOMInclude implements IIndexFragmentInclude {
this.record = pdom.getDB().malloc(RECORD_SIZE);
IASTName name= include.getName();
IASTFileLocation loc= name.getFileLocation();
setNameOffsetAndLength(loc.getNodeOffset(), (short) loc.getNodeLength());
// includes generated by -include or -macro don't have a location
if (loc != null) {
setNameOffsetAndLength(loc.getNodeOffset(), (short) loc.getNodeLength());
}
setFlag(encodeFlags(include));
}