1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-21 16:05:25 +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.ParserFactory;
import org.eclipse.cdt.core.parser.ParserLanguage; import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode; 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.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -59,7 +60,6 @@ import org.eclipse.core.runtime.Path;
public class ManagedBuildTests extends TestCase { public class ManagedBuildTests extends TestCase {
private static final boolean boolVal = true; 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 testConfigId = "test.config.override";
private static final String testConfigName = "Tester"; private static final String testConfigName = "Tester";
private static final String enumVal = "Another Enum"; private static final String enumVal = "Another Enum";
@ -896,7 +896,7 @@ public class ManagedBuildTests extends TestCase {
IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName()); IProjectDescription description = workspace.newProjectDescription(newProjectHandle.getName());
//description.setLocation(root.getLocation()); //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 { } else {
newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, null); newProjectHandle.refreshLocal(IResource.DEPTH_INFINITE, null);
project = newProjectHandle; project = newProjectHandle;

View file

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

View file

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