1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-01 06:05:24 +02:00

fixed junit test to work without the deprecated CDT stuff

This commit is contained in:
David Inglis 2004-01-14 22:05:56 +00:00
parent db794992cb
commit d70a6ac41a
6 changed files with 261 additions and 260 deletions

View file

@ -32,6 +32,7 @@ import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -59,7 +60,6 @@ import org.eclipse.core.runtime.Path;
public class ManagedBuildTests extends TestCase {
private static final boolean boolVal = true;
private static final String PROJECT_ID = CCorePlugin.PLUGIN_ID + ".make";
private static final String testConfigId = "test.config.override";
private static final String testConfigName = "Tester";
private static final String enumVal = "Another Enum";
@ -896,7 +896,7 @@ public class ManagedBuildTests extends TestCase {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
//description.setLocation(root.getLocation());
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), PROJECT_ID);
project = CCorePlugin.getDefault().createCProject(description, newProjectHandle, new NullProgressMonitor(), MakeCorePlugin.MAKE_PROJECT_ID);
} else {
newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
project = newProjectHandle;

View file

@ -124,7 +124,11 @@ public class CModelTests extends TestCase {
CCProjectNature.removeCNature(testProject.getProject(), monitor);
assertTrue("hasCNature works without cnature", !CoreModel.getDefault().hasCNature(testProject.getProject()));
assertTrue("hasCCNature works without ccnature or cnature", !(CoreModel.getDefault().hasCCNature(testProject.getProject())));
try{
testProject.getProject().delete(true,true,monitor);
}
catch (ResourceException e) {}
catch (CoreException e) {}
}
/***

View file

@ -39,17 +39,17 @@
defaultExtension="toor"
isAbstract="false"
makeCommand="make"
makeFlags="-k"
binaryParser="org.eclipse.cdt.core.PE"
makeFlags="-k"
osList="win32">
<tool
natureFilter="cnature"
name="Root Tool"
sources="foo,bar"
name="Root Tool"
headerExtensions="baz"
outputFlag="-r"
command="doIt"
outputs="toor"
command="doIt"
id="root.tool">
<optionCategory
owner="root.tool"
@ -59,39 +59,39 @@
<option
name="List Option in Top"
command="-L"
id="list.option"
valueType="stringList">
valueType="stringList"
id="list.option">
<listOptionValue
value="a">
</listOptionValue>
<listOptionValue
builtIn="false"
value="b">
value="b"
builtIn="false">
</listOptionValue>
<listOptionValue
builtIn="true"
value="c">
value="c"
builtIn="true">
</listOptionValue>
</option>
<option
defaultValue="false"
name="Boolean Option in Top"
command="-b"
id="boolean.option"
valueType="boolean">
valueType="boolean"
id="boolean.option">
</option>
<option
defaultValue="x"
name="String Option in Category"
category="category"
id="string.option"
valueType="string">
valueType="string"
id="string.option">
</option>
<option
name="Enumerated Option in Category"
category="category"
id="enumerated.option"
valueType="enumerated">
valueType="enumerated"
id="enumerated.option">
<enumeratedOptionValue
name="Default Enum"
isDefault="true"
@ -164,17 +164,17 @@
</configuration>
<tool
natureFilter="both"
name="Sub Tool"
sources="yarf"
name="Sub Tool"
headerExtensions="arf,barf"
outputPrefix="lib"
outputs="bus"
outputPrefix="lib"
id="tool.sub">
<option
name="Include Paths"
command="-I"
id="sub.tool.opt.inc.paths"
valueType="includePath">
valueType="includePath"
id="sub.tool.opt.inc.paths">
<listOptionValue
value="/usr/include">
</listOptionValue>
@ -182,45 +182,45 @@
value="/opt/gnome/include">
</listOptionValue>
<listOptionValue
builtIn="true"
value="/usr/gnu/include">
value="/usr/gnu/include"
builtIn="true">
</listOptionValue>
</option>
<option
name="Defined Symbols"
command="-D"
id="sub.tool.opt.def.symbols"
valueType="definedSymbols">
valueType="definedSymbols"
id="sub.tool.opt.def.symbols">
<listOptionValue
builtIn="true"
value="BUILTIN">
value="BUILTIN"
builtIn="true">
</listOptionValue>
</option>
<option
name="More Includes"
command="-I"
id="sub.tool.opts.inc.paths.more"
valueType="includePath">
valueType="includePath"
id="sub.tool.opts.inc.paths.more">
<listOptionValue
builtIn="false"
value="C:\home\tester/include">
value="C:\home\tester/include"
builtIn="false">
</listOptionValue>
<listOptionValue
builtIn="false"
value="&quot;../includes&quot;">
value="&quot;../includes&quot;"
builtIn="false">
</listOptionValue>
</option>
<option
name="User Objects"
id="sub.tool.opt.objs"
valueType="userObjs">
valueType="userObjs"
id="sub.tool.opt.objs">
<listOptionValue
builtIn="false"
value="obj1.o">
value="obj1.o"
builtIn="false">
</listOptionValue>
<listOptionValue
builtIn="false"
value="obj2.o">
value="obj2.o"
builtIn="false">
</listOptionValue>
</option>
</tool>
@ -228,8 +228,8 @@
<target
isTest="true"
name="Test Sub Sub"
binaryParser="org.eclipse.cdt.core.ELF"
parent="test.sub"
binaryParser="org.eclipse.cdt.core.ELF"
defaultExtension="tss"
makeCommand="nmake"
id="test.sub.sub">
@ -244,5 +244,12 @@
</run>
</application>
</extension>
<extension
id="TestProject"
name="%TestProject.name"
point="org.eclipse.cdt.core.CProject">
<cproject
class="org.eclipse.cdt.testplugin.TestProject">
</cproject>
</extension>
</plugin>

View file

@ -1,8 +1,6 @@
package org.eclipse.cdt.testplugin;
import java.lang.reflect.InvocationTargetException;
import java.util.zip.ZipFile;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
import org.eclipse.cdt.core.model.IArchive;
@ -26,234 +24,203 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.dialogs.IOverwriteQuery;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
/**
* Helper methods to set up a ICProject.
*/
public class CProjectHelper {
/**
* Creates a ICProject.
*/
public static ICProject createCProject(String projectName, String binFolderName) 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);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = CCorePlugin.PLUGIN_ID + ".make";
CCorePlugin.getDefault().mapCProjectOwner(project, projectId, false);
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
}
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
return cproject;
}
/**
* Removes a ICProject.
*/
public static void delete(ICProject cproject) throws CoreException {
/**
* Creates a ICProject.
*/
public static ICProject createCProject(String projectName,
String binFolderName) 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);
}
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = CTestPlugin.PLUGIN_ID + ".TestProject";
CCorePlugin.getDefault()
.mapCProjectOwner(project, projectId, false);
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
}
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(
project);
return cproject;
}
/**
* Removes a ICProject.
*/
public static void delete(ICProject cproject) throws CoreException {
try {
cproject.getProject().delete(true, true, null);
} catch (CoreException e) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
}
finally{
} finally {
cproject.getProject().delete(true, true, null);
}
}
}
/**
* Adds a source container to a ICProject.
*/
public static ICContainer addSourceContainer(ICProject cproject, String containerName) throws CoreException {
IProject project= cproject.getProject();
ICContainer container= null;
if (containerName == null || containerName.length() == 0) {
container= CModelManager.getDefault().create(project);
} else {
IFolder folder= project.getFolder(containerName);
if (!folder.exists()) {
folder.create(false, true, null);
}
container= CModelManager.getDefault().create(folder);
}
}
/**
* Adds a source container to a ICProject.
*/
public static ICContainer addSourceContainer(ICProject cproject,
String containerName) throws CoreException {
IProject project = cproject.getProject();
ICContainer container = null;
if (containerName == null || containerName.length() == 0) {
container = CModelManager.getDefault().create(project);
} else {
IFolder folder = project.getFolder(containerName);
if (!folder.exists()) {
folder.create(false, true, null);
}
container = CModelManager.getDefault().create(folder);
}
return container;
}
/**
* Adds a source container to a ICProject and imports all files contained
* in the given Zip file.
*/
public static ICContainer addSourceContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) throws InvocationTargetException, CoreException {
ICContainer root= addSourceContainer(cproject, containerName);
importFilesFromZip(zipFile, root.getPath(), null);
return root;
}
/**
* Removes a source folder from a ICProject.
*/
public static void removeSourceContainer(ICProject cproject, String containerName) throws CoreException {
IFolder folder= cproject.getProject().getFolder(containerName);
folder.delete(true, null);
}
/**
* Attempts to find an archive with the given name in the workspace
*/
public static IArchive findArchive(ICProject testProject,String name) {
int x;
IArchive[] myArchives;
IArchiveContainer archCont;
/***
* Since ArchiveContainer.getArchives does not wait until
* all the archives in the project have been parsed before
* returning the list, we have to do a sync ArchiveContainer.getChildren
* first to make sure we find all the archives.
*/
archCont=testProject.getArchiveContainer();
myArchives=archCont.getArchives();
if (myArchives.length<1)
return(null);
for (x=0;x<myArchives.length;x++) {
if (myArchives[x].getElementName().equals(name))
return(myArchives[x]);
}
return(null);
}
/**
* Attempts to find a binary with the given name in the workspace
*/
public static IBinary findBinary(ICProject testProject,String name) {
IBinaryContainer binCont;
int x;
IBinary[] myBinaries;
binCont=testProject.getBinaryContainer();
myBinaries=binCont.getBinaries();
if (myBinaries.length<1)
return(null);
for (x=0;x<myBinaries.length;x++) {
if (myBinaries[x].getElementName().equals(name))
return(myBinaries[x]);
}
return(null);
}
/**
* Attempts to find an object with the given name in the workspace
*/
public static IBinary findObject(ICProject testProject,String name) {
int x;
ICElement[] myElements;
myElements=testProject.getChildren();
if (myElements.length<1)
return(null);
for (x=0;x<myElements.length;x++) {
if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) {
if (myElements[x] instanceof IBinary) {
return((IBinary) myElements[x]);
}
}
}
return(null);
}
/**
* Attempts to find a TranslationUnit with the given name in the workspace
*/
public static ITranslationUnit findTranslationUnit(ICProject testProject,String name) {
int x;
ICElement[] myElements;
myElements=testProject.getChildren();
if (myElements.length<1)
return(null);
for (x=0;x<myElements.length;x++) {
if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) {
if (myElements[x] instanceof ITranslationUnit) {
return((ITranslationUnit) myElements[x]);
}
}
}
return(null);
}
/**
* Attempts to find an element with the given name in the workspace
*/
public static ICElement findElement(ICProject testProject,String name) {
int x;
ICElement[] myElements;
myElements=testProject.getChildren();
if (myElements.length<1)
return(null);
for (x=0;x<myElements.length;x++) {
if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) {
return((ICElement) myElements[x]);
}
}
return(null);
}
private static 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);
}
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException {
ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile);
try {
ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery());
op.run(monitor);
} catch (InterruptedException e) {
// should not happen
}
}
private static class ImportOverwriteQuery implements IOverwriteQuery {
public String queryOverwrite(String file) {
return ALL;
}
}
}
/**
* Adds a source container to a ICProject and imports all files contained
* in the given Zip file.
*/
public static ICContainer addSourceContainerWithImport(ICProject cproject,
String containerName, ZipFile zipFile)
throws InvocationTargetException, CoreException {
ICContainer root = addSourceContainer(cproject, containerName);
importFilesFromZip(zipFile, root.getPath(), null);
return root;
}
/**
* Removes a source folder from a ICProject.
*/
public static void removeSourceContainer(ICProject cproject,
String containerName) throws CoreException {
IFolder folder = cproject.getProject().getFolder(containerName);
folder.delete(true, null);
}
/**
* Attempts to find an archive with the given name in the workspace
*/
public static IArchive findArchive(ICProject testProject, String name) {
int x;
IArchive[] myArchives;
IArchiveContainer archCont;
/***********************************************************************
* Since ArchiveContainer.getArchives does not wait until all the
* archives in the project have been parsed before returning the list,
* we have to do a sync ArchiveContainer.getChildren first to make sure
* we find all the archives.
*/
archCont = testProject.getArchiveContainer();
myArchives = archCont.getArchives();
if (myArchives.length < 1)
return (null);
for (x = 0; x < myArchives.length; x++) {
if (myArchives[x].getElementName().equals(name))
return (myArchives[x]);
}
return (null);
}
/**
* Attempts to find a binary with the given name in the workspace
*/
public static IBinary findBinary(ICProject testProject, String name) {
IBinaryContainer binCont;
int x;
IBinary[] myBinaries;
binCont = testProject.getBinaryContainer();
myBinaries = binCont.getBinaries();
if (myBinaries.length < 1)
return (null);
for (x = 0; x < myBinaries.length; x++) {
if (myBinaries[x].getElementName().equals(name))
return (myBinaries[x]);
}
return (null);
}
/**
* Attempts to find an object with the given name in the workspace
*/
public static IBinary findObject(ICProject testProject, String name) {
int x;
ICElement[] myElements;
myElements = testProject.getChildren();
if (myElements.length < 1)
return (null);
for (x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof IBinary) {
return ((IBinary) myElements[x]);
}
}
return (null);
}
/**
* Attempts to find a TranslationUnit with the given name in the workspace
*/
public static ITranslationUnit findTranslationUnit(ICProject testProject,
String name) {
int x;
ICElement[] myElements;
myElements = testProject.getChildren();
if (myElements.length < 1)
return (null);
for (x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ITranslationUnit) {
return ((ITranslationUnit) myElements[x]);
}
}
return (null);
}
/**
* Attempts to find an element with the given name in the workspace
*/
public static ICElement findElement(ICProject testProject, String name) {
int x;
ICElement[] myElements;
myElements = testProject.getChildren();
if (myElements.length < 1)
return (null);
for (x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name))
return myElements[x];
}
return (null);
}
private static 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);
}
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath,
IProgressMonitor monitor) throws InvocationTargetException {
ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
srcZipFile);
try {
ImportOperation op = new ImportOperation(destPath,
structureProvider.getRoot(), structureProvider,
new ImportOverwriteQuery());
op.run(monitor);
} catch (InterruptedException e) {
// should not happen
}
}
private static class ImportOverwriteQuery implements IOverwriteQuery {
public String queryOverwrite(String file) {
return ALL;
}
}
}

View file

@ -20,6 +20,7 @@ import org.eclipse.core.runtime.Plugin;
public class CTestPlugin extends Plugin {
public static final String PLUGIN_ID = "org.eclipse.cdt.core.tests";
private static CTestPlugin fgDefault;
public CTestPlugin(IPluginDescriptor descriptor) {

View file

@ -0,0 +1,22 @@
/*
* Created on Jan 14, 2004
*
* Copyright (c) 2002,2003 QNX Software Systems Ltd.
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.testplugin;
import org.eclipse.cdt.core.ICDescriptor;
import org.eclipse.cdt.core.ICOwner;
import org.eclipse.core.runtime.CoreException;
public class TestProject implements ICOwner {
public void configure(ICDescriptor cproject) throws CoreException {
}
public void update(ICDescriptor cproject, String extensionID) throws CoreException {
}
}