Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2012-05-09 20:05:51 -0400
committerSergey Prigogin2012-05-09 20:12:45 -0400
commitae606fe28bd730d640f6ec722da99628e813984d (patch)
tree2ceb0c5d500221d61fd20d897258e0a269878701 /core/org.eclipse.cdt.core.tests
parentfdbfec3f2bb2334d5818cc7bc3bed2cc75c151a8 (diff)
downloadorg.eclipse.cdt-ae606fe28bd730d640f6ec722da99628e813984d.tar.gz
org.eclipse.cdt-ae606fe28bd730d640f6ec722da99628e813984d.tar.xz
org.eclipse.cdt-ae606fe28bd730d640f6ec722da99628e813984d.zip
Bug 378317 - Index update mode for resolving unresolved includes and
reindexing files with I/O errors.
Diffstat (limited to 'core/org.eclipse.cdt.core.tests')
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java11
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java59
2 files changed, 69 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java
index 0c638a1740..d9809920da 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/EmptyIndexFragment.java
@@ -178,12 +178,23 @@ public class EmptyIndexFragment implements IIndexFragment {
public IIndexFragmentFileSet createFileSet() {
return null;
}
+
@Override
public IIndexFragmentFile[] getAllFiles() {
return IIndexFragmentFile.EMPTY_ARRAY;
}
@Override
+ public IIndexFragmentFile[] getDefectiveFiles() {
+ return IIndexFragmentFile.EMPTY_ARRAY;
+ }
+
+ @Override
+ public IIndexFragmentFile[] getFilesWithUnresolvedIncludes() {
+ return IIndexFragmentFile.EMPTY_ARRAY;
+ }
+
+ @Override
public Object getCachedResult(Object key) {
return null;
}
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
index 86963579ea..a0f0001426 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBugsTests.java
@@ -18,6 +18,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.HashSet;
+import java.util.Properties;
import java.util.Set;
import java.util.regex.Pattern;
@@ -62,6 +63,7 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
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.IIndexFileLocation;
import org.eclipse.cdt.core.index.IIndexFileSet;
import org.eclipse.cdt.core.index.IIndexInclude;
import org.eclipse.cdt.core.index.IIndexMacro;
@@ -85,6 +87,7 @@ import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
import org.eclipse.cdt.internal.core.pdom.CModelListener;
+import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
@@ -105,7 +108,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
public class IndexBugsTests extends BaseTestCase {
- private static final int INDEX_WAIT_TIME = 8000;
+ private static final int INDEX_WAIT_TIME = 800000; //XXX
private ICProject fCProject;
protected IIndex fIndex;
@@ -2470,4 +2473,58 @@ public class IndexBugsTests extends BaseTestCase {
fIndex.releaseReadLock();
}
}
+
+ // // test.cpp
+ // #include "a.h"
+ // using ns::INT;
+
+ // // a.h
+ // #include "b.h"
+
+ // // b.h
+ // namespace ns { typedef int INT; }
+ public void testUpdateUnresolvedIncludes_378317() throws Exception {
+ // Turn off indexing of unused headers.
+ IndexerPreferences.set(fCProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG, "false");
+ // Turn off automatic index update.
+ IndexerPreferences.setUpdatePolicy(fCProject.getProject(), IndexerPreferences.UPDATE_POLICY_MANUAL);
+
+ try {
+ String[] contents= getContentsForTest(3);
+ final IIndexManager indexManager = CCorePlugin.getIndexManager();
+ TestSourceReader.createFile(fCProject.getProject(), "test.c", contents[0]);
+ IFile ah= TestSourceReader.createFile(fCProject.getProject(), "a.h", contents[1]);
+ // b.h is not created yet, so #include "b.h" in a.h is unresolved.
+ indexManager.reindex(fCProject);
+ waitForIndexer();
+ fIndex.acquireReadLock();
+ try {
+ IIndexFile[] files = fIndex.getFilesWithUnresolvedIncludes();
+ assertEquals(1, files.length);
+ assertEquals(IndexLocationFactory.getWorkspaceIFL(ah), files[0].getLocation());
+ } finally {
+ fIndex.releaseReadLock();
+ }
+
+ IFile bh= TestSourceReader.createFile(fCProject.getProject(), "b.h", contents[2]);
+ indexManager.update(new ICElement[] { fCProject }, IIndexManager.UPDATE_UNRESOLVED_INCLUDES);
+ waitForIndexer();
+ fIndex.acquireReadLock();
+ try {
+ IIndexFile[] files = fIndex.getFilesWithUnresolvedIncludes();
+ assertEquals(0, files.length);
+ IIndexFileLocation location = IndexLocationFactory.getWorkspaceIFL(bh);
+ files = fIndex.getFiles(IndexLocationFactory.getWorkspaceIFL(bh));
+ assertEquals(1, files.length);
+ } finally {
+ fIndex.releaseReadLock();
+ }
+ } finally {
+ // Restore default indexer preferences.
+ Properties defaults = IndexerPreferences.getDefaultIndexerProperties();
+ IndexerPreferences.set(fCProject.getProject(), IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG,
+ defaults.getProperty(IndexerPreferences.KEY_INDEX_UNUSED_HEADERS_WITH_DEFAULT_LANG));
+ IndexerPreferences.setUpdatePolicy(fCProject.getProject(), IndexerPreferences.getDefaultUpdatePolicy());
+ }
+ }
}

Back to the top