mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Patch for Bogdan Gheorghe:
- support for class specifier search - a new C/C++ search menu item
This commit is contained in:
parent
bcf023a6c8
commit
5535e563a7
4 changed files with 179 additions and 16 deletions
|
@ -1,3 +1,6 @@
|
|||
2003-07-11 Bogdan Gheorghe
|
||||
Added ClassSpecifierSearchTest
|
||||
|
||||
2003-07-08 John Camelon
|
||||
Updated IScanner, clients & implementations to use IScannerInfo.
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ package org.eclipse.cdt.core.indexer.tests;
|
|||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.internal.core.index.IEntryResult;
|
||||
|
@ -33,14 +37,10 @@ import org.eclipse.core.runtime.NullProgressMonitor;
|
|||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
*/
|
||||
public class IndexManagerTest extends TestCase {
|
||||
public class IndexManagerTests extends TestCase {
|
||||
IFile file;
|
||||
IFileDocument fileDoc;
|
||||
IProject testProject;
|
||||
|
@ -50,7 +50,7 @@ public class IndexManagerTest extends TestCase {
|
|||
* Constructor for IndexManagerTest.
|
||||
* @param name
|
||||
*/
|
||||
public IndexManagerTest(String name) {
|
||||
public IndexManagerTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class IndexManagerTest extends TestCase {
|
|||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(IndexManagerTest.class);
|
||||
return new TestSuite(IndexManagerTests.class);
|
||||
}
|
||||
/*
|
||||
* Utils
|
||||
|
@ -97,9 +97,7 @@ public class IndexManagerTest extends TestCase {
|
|||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
|
||||
}
|
||||
|
||||
//Fill out a project description
|
||||
IPath defaultPath = Platform.getLocation();
|
||||
IPath newPath = project.getFullPath();
|
||||
|
@ -110,7 +108,7 @@ public class IndexManagerTest extends TestCase {
|
|||
description.setLocation(newPath);
|
||||
//Create the project
|
||||
IProject cproject = CCorePlugin.getDefault().createCProject(description,project,monitor,CCorePlugin.PLUGIN_ID + ".make"); //.getCoreModel().create(project);
|
||||
|
||||
|
||||
return cproject;
|
||||
}
|
||||
|
||||
|
@ -149,7 +147,7 @@ public class IndexManagerTest extends TestCase {
|
|||
IQueryResult[] qresults = ind.queryPrefix(prefix);
|
||||
IEntryResult[] eresults = ind.queryEntries(prefix);
|
||||
String [] queryResultModel = {"IndexedFile(1: /IndexerTestProject/mail.cpp)"};
|
||||
String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail/, refs={ 1 }", "EntryResult: word=typeDecl/C/Unknown/, refs={ 1 }", "EntryResult: word=typeDecl/C/container/, refs={ 1 }", "EntryResult: word=typeDecl/C/first_class/, refs={ 1 }", "EntryResult: word=typeDecl/C/postcard/, refs={ 1 }"};
|
||||
String [] entryResultModel ={"EntryResult: word=typeDecl/C/Mail, refs={ 1 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 1 }", "EntryResult: word=typeDecl/C/container, refs={ 1 }", "EntryResult: word=typeDecl/C/first_class, refs={ 1 }", "EntryResult: word=typeDecl/C/postcard, refs={ 1 }"};
|
||||
|
||||
if (qresults.length != queryResultModel.length)
|
||||
fail("Query Result length different from model");
|
||||
|
@ -183,8 +181,8 @@ public class IndexManagerTest extends TestCase {
|
|||
importFile("DocumentManager.h","resources/indexer/DocumentManager.h");
|
||||
Thread.sleep(10000);
|
||||
ind = indexManager.getIndex(testProjectPath,true,true);
|
||||
char[] prefix = "typeDecl/C/CDocumentManager/".toCharArray();
|
||||
String [] entryResultModel ={"EntryResult: word=typeDecl/C/CDocumentManager/, refs={ 1 }"};
|
||||
char[] prefix = "typeDecl/C/CDocumentManager".toCharArray();
|
||||
String [] entryResultModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }"};
|
||||
IEntryResult[] eresults =ind.queryEntries(prefix);
|
||||
|
||||
if (eresults.length != entryResultModel.length)
|
||||
|
@ -230,7 +228,7 @@ public class IndexManagerTest extends TestCase {
|
|||
ind = indexManager.getIndex(testProjectPath,true,true);
|
||||
char[] prefix = "typeDecl/".toCharArray();
|
||||
IEntryResult[] eresults = ind.queryEntries(prefix);
|
||||
String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager/, refs={ 1 }", "EntryResult: word=typeDecl/C/Mail/, refs={ 2 }", "EntryResult: word=typeDecl/C/Unknown/, refs={ 2 }", "EntryResult: word=typeDecl/C/container/, refs={ 2 }", "EntryResult: word=typeDecl/C/first_class/, refs={ 2 }", "EntryResult: word=typeDecl/C/postcard/, refs={ 2 }"};
|
||||
String [] entryResultBeforeModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }", "EntryResult: word=typeDecl/C/Mail, refs={ 2 }", "EntryResult: word=typeDecl/C/Unknown, refs={ 2 }", "EntryResult: word=typeDecl/C/container, refs={ 2 }", "EntryResult: word=typeDecl/C/first_class, refs={ 2 }", "EntryResult: word=typeDecl/C/postcard, refs={ 2 }"};
|
||||
if (eresults.length != entryResultBeforeModel.length)
|
||||
fail("Entry Result length different from model");
|
||||
|
||||
|
@ -245,7 +243,7 @@ public class IndexManagerTest extends TestCase {
|
|||
//See if the index is still there
|
||||
ind = indexManager.getIndex(testProjectPath,true,true);
|
||||
eresults = ind.queryEntries(prefix);
|
||||
String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager/, refs={ 1 }"};
|
||||
String [] entryResultAfterModel ={"EntryResult: word=typeDecl/C/CDocumentManager, refs={ 1 }"};
|
||||
if (eresults.length != entryResultAfterModel.length)
|
||||
fail("Entry Result length different from model");
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* Created on Jul 11, 2003
|
||||
*/
|
||||
package org.eclipse.cdt.core.search.tests;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.search.ICSearchConstants;
|
||||
import org.eclipse.cdt.core.search.ICSearchPattern;
|
||||
import org.eclipse.cdt.core.search.ICSearchResultCollector;
|
||||
import org.eclipse.cdt.core.search.SearchEngine;
|
||||
import org.eclipse.cdt.internal.core.index.impl.IFileDocument;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.search.PathCollector;
|
||||
import org.eclipse.cdt.internal.core.search.PatternSearchJob;
|
||||
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchResultCollector;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author bgheorgh
|
||||
*/
|
||||
public class ClassSpecifierSearchTests extends TestCase {
|
||||
IFile file;
|
||||
IFileDocument fileDoc;
|
||||
IProject testProject;
|
||||
NullProgressMonitor monitor;
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
public ClassSpecifierSearchTests(String name) {
|
||||
super(name);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new TestSuite(ClassSpecifierSearchTests.class);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
//Create temp project
|
||||
testProject = createProject("IndexerTestProject");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
//Add a file to the project
|
||||
importFile("mail.cpp","resources/indexer/mail.cpp");
|
||||
}
|
||||
/*
|
||||
* @see TestCase#tearDown()
|
||||
*/
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
//Delete project
|
||||
if (testProject.exists()){
|
||||
testProject.delete(true,monitor);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Utils
|
||||
*/
|
||||
private IProject createProject(String projectName) throws CoreException
|
||||
{
|
||||
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject project= root.getProject(projectName);
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
//Fill out a project description
|
||||
IPath defaultPath = Platform.getLocation();
|
||||
IPath newPath = project.getFullPath();
|
||||
if (defaultPath.equals(newPath))
|
||||
newPath = null;
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IProjectDescription description = workspace.newProjectDescription(project.getName());
|
||||
description.setLocation(newPath);
|
||||
//Create the project
|
||||
IProject cproject = CCorePlugin.getDefault().createCProject(description,project,monitor,CCorePlugin.PLUGIN_ID + ".make"); //.getCoreModel().create(project);
|
||||
|
||||
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
|
||||
}
|
||||
|
||||
return cproject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param project
|
||||
* @param string
|
||||
* @param object
|
||||
*/
|
||||
private void addNatureToProject(IProject project, String string, Object object) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private void importFile(String fileName, String resourceLocation)throws Exception{
|
||||
//Obtain file handle
|
||||
file = testProject.getProject().getFile(fileName);
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
|
||||
//Create file input stream
|
||||
monitor = new NullProgressMonitor();
|
||||
if (!file.exists()){
|
||||
file.create(new FileInputStream(pluginRoot + resourceLocation),false,monitor);
|
||||
}
|
||||
fileDoc = new IFileDocument(file);
|
||||
}
|
||||
|
||||
private void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
public void search(ICSearchPattern pattern, ICSearchResultCollector collector){
|
||||
|
||||
}
|
||||
/*
|
||||
* Start of tests
|
||||
*/
|
||||
public void testSearchSimpleName() throws Exception {
|
||||
//ICSearchPattern pattern = SearchEngine.createSearchPattern( "Mail", ICSearchConstants.TYPE, ICSearchConstants.DECLARATIONS , false );
|
||||
//Create a new result collector
|
||||
//CSearchResultCollector collector= new CSearchResultCollector();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ import org.eclipse.cdt.core.parser.failedTests.LokiFailures;
|
|||
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
|
||||
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
|
||||
import org.eclipse.cdt.core.search.tests.ClassDeclarationPatternTests;
|
||||
import org.eclipse.cdt.core.indexer.tests.IndexManagerTests;
|
||||
import org.eclipse.core.boot.IPlatformRunnable;
|
||||
|
||||
/**
|
||||
|
@ -80,6 +81,7 @@ public class AutomatedIntegrationSuite extends TestSuite
|
|||
suite.addTest(ElementDeltaTests.suite());
|
||||
suite.addTest(WorkingCopyTests.suite());
|
||||
suite.addTestSuite(ClassDeclarationPatternTests.class );
|
||||
suite.addTest(IndexManagerTests.suite());
|
||||
|
||||
// Last test to trigger report generation
|
||||
suite.addTest(suite.new GenerateReport("startFailedTests"));
|
||||
|
|
Loading…
Add table
Reference in a new issue