diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java new file mode 100644 index 00000000000..6342cd16a3f --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/FilesOnReindexTests.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 Symbian Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Symbian - Initial implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.pdom.tests; + +import java.util.regex.Pattern; + +import junit.framework.Test; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IIndexFile; +import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; + +/** + * See bugzilla + */ +public class FilesOnReindexTests extends PDOMTestBase { + + protected ICProject project; + protected IIndex pdom; + + public static Test suite() { + return suite(FilesOnReindexTests.class); + } + + protected void setUp() throws Exception { + if (pdom == null) { + project = createProject("filesOnReindex"); + pdom = CCorePlugin.getIndexManager().getIndex(project); + } + pdom.acquireReadLock(); + } + + protected void tearDown() throws Exception { + pdom.releaseReadLock(); + } + + public void testFilesOnReindex() throws CoreException, InterruptedException { + IFile file = project.getProject().getFile("simple.cpp"); + performAssertions(file); + pdom.releaseReadLock(); + CCorePlugin.getPDOMManager().getIndexer(project).reindex(); + + // wait until the indexer is done + assertTrue(CCorePlugin.getIndexManager().joinIndexer(360000, new NullProgressMonitor())); + pdom.acquireReadLock(); + performAssertions(file); + } + + void performAssertions(IFile file) throws CoreException { + IIndex index = CCorePlugin.getIndexManager().getIndex(project); + assertNotNull(index.getFile(file.getLocation())); + + IBinding[] bs = index.findBindings(Pattern.compile("C"), true, new IndexFilter(), new NullProgressMonitor()); + assertEquals(1, bs.length); + + PDOMBinding binding = (PDOMBinding) bs[0]; + IIndexFile file2 = binding.getFirstDefinition().getFile(); + assertEquals(file.getLocation().toOSString(), file2.getLocation()); + } +} diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java index 98db04fe6a0..95e7abd62ad 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/pdom/tests/PDOMTests.java @@ -29,7 +29,7 @@ public class PDOMTests extends TestSuite { suite.addTestSuite(OverloadsWithinSingleTUTests.class); suite.addTest(OverloadsWithinCommonHeaderTests.suite()); suite.addTestSuite(BTreeTests.class); - + suite.addTest(FilesOnReindexTests.suite()); suite.addTest(CPPFieldTests.suite()); suite.addTest(CPPFunctionTests.suite()); diff --git a/core/org.eclipse.cdt.core.tests/resources/pdomtests/filesOnReindex/simple.cpp b/core/org.eclipse.cdt.core.tests/resources/pdomtests/filesOnReindex/simple.cpp new file mode 100644 index 00000000000..07868b486a5 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/resources/pdomtests/filesOnReindex/simple.cpp @@ -0,0 +1 @@ +class C {};