1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 00:45:28 +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,16 +24,15 @@ 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, String binFolderName) throws CoreException { public static ICProject createCProject(String projectName,
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()) {
@ -43,49 +40,39 @@ public class CProjectHelper {
} 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)) { if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
String projectId = CCorePlugin.PLUGIN_ID + ".make"; String projectId = CTestPlugin.PLUGIN_ID + ".TestProject";
CCorePlugin.getDefault().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(
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project); project);
return cproject; return cproject;
} }
/** /**
* Removes a ICProject. * Removes a ICProject.
*/ */
public static void delete(ICProject cproject) throws CoreException { 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. * Adds a source container to a ICProject.
*/ */
public static ICContainer addSourceContainer(ICProject cproject, String containerName) throws CoreException { public static ICContainer addSourceContainer(ICProject cproject,
String containerName) throws CoreException {
IProject project = cproject.getProject(); IProject project = cproject.getProject();
ICContainer container = null; ICContainer container = null;
if (containerName == null || containerName.length() == 0) { if (containerName == null || containerName.length() == 0) {
@ -97,30 +84,27 @@ public class CProjectHelper {
} }
container = CModelManager.getDefault().create(folder); 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, String containerName, ZipFile zipFile) throws InvocationTargetException, CoreException { public static ICContainer addSourceContainerWithImport(ICProject cproject,
String containerName, ZipFile zipFile)
throws InvocationTargetException, CoreException {
ICContainer root = addSourceContainer(cproject, containerName); ICContainer root = addSourceContainer(cproject, containerName);
importFilesFromZip(zipFile, root.getPath(), null); importFilesFromZip(zipFile, root.getPath(), null);
return root; 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,
String containerName) throws CoreException {
IFolder folder = cproject.getProject().getFolder(containerName); IFolder folder = cproject.getProject().getFolder(containerName);
folder.delete(true, null); 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
*/ */
@ -128,21 +112,19 @@ public class CProjectHelper {
int x; int x;
IArchive[] myArchives; IArchive[] myArchives;
IArchiveContainer archCont; IArchiveContainer archCont;
/*** /***********************************************************************
* Since ArchiveContainer.getArchives does not wait until * Since ArchiveContainer.getArchives does not wait until all the
* all the archives in the project have been parsed before * archives in the project have been parsed before returning the list,
* returning the list, we have to do a sync ArchiveContainer.getChildren * we have to do a sync ArchiveContainer.getChildren first to make sure
* first to make sure we find all the archives. * we find all the archives.
*/ */
archCont = testProject.getArchiveContainer(); archCont = testProject.getArchiveContainer();
myArchives = archCont.getArchives(); myArchives = archCont.getArchives();
if (myArchives.length < 1) if (myArchives.length < 1)
return (null); return (null);
for (x = 0; x < myArchives.length; x++) { for (x = 0; x < myArchives.length; x++) {
if (myArchives[x].getElementName().equals(name)) if (myArchives[x].getElementName().equals(name))
return (myArchives[x]); return (myArchives[x]);
} }
return (null); return (null);
} }
@ -154,19 +136,15 @@ public class CProjectHelper {
int x; int x;
IBinary[] myBinaries; IBinary[] myBinaries;
binCont = testProject.getBinaryContainer(); binCont = testProject.getBinaryContainer();
myBinaries = binCont.getBinaries(); myBinaries = binCont.getBinaries();
if (myBinaries.length < 1) if (myBinaries.length < 1)
return (null); return (null);
for (x = 0; x < myBinaries.length; x++) { for (x = 0; x < myBinaries.length; x++) {
if (myBinaries[x].getElementName().equals(name)) if (myBinaries[x].getElementName().equals(name))
return (myBinaries[x]); return (myBinaries[x]);
} }
return (null); return (null);
} }
/** /**
* Attempts to find an object with the given name in the workspace * Attempts to find an object with the given name in the workspace
*/ */
@ -178,18 +156,17 @@ public class CProjectHelper {
return (null); return (null);
for (x = 0; x < myElements.length; x++) { for (x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) {
if (myElements[x] instanceof IBinary) { if (myElements[x] instanceof IBinary) {
return ((IBinary) myElements[x]); return ((IBinary) myElements[x]);
} }
} }
}
return (null); return (null);
} }
/** /**
* Attempts to find a TranslationUnit with the given name in the workspace * Attempts to find a TranslationUnit with the given name in the workspace
*/ */
public static ITranslationUnit findTranslationUnit(ICProject testProject,String name) { public static ITranslationUnit findTranslationUnit(ICProject testProject,
String name) {
int x; int x;
ICElement[] myElements; ICElement[] myElements;
myElements = testProject.getChildren(); myElements = testProject.getChildren();
@ -197,17 +174,12 @@ public class CProjectHelper {
return (null); return (null);
for (x = 0; x < myElements.length; x++) { for (x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) {
if (myElements[x] instanceof ITranslationUnit) { if (myElements[x] instanceof ITranslationUnit) {
return ((ITranslationUnit) myElements[x]); return ((ITranslationUnit) myElements[x]);
} }
} }
}
return (null); return (null);
} }
/** /**
* Attempts to find an element with the given name in the workspace * Attempts to find an element with the given name in the workspace
*/ */
@ -219,16 +191,12 @@ public class CProjectHelper {
return (null); return (null);
for (x = 0; x < myElements.length; x++) { for (x = 0; x < myElements.length; x++) {
if (myElements[x].getElementName().equals(name)) if (myElements[x].getElementName().equals(name))
if (myElements[x] instanceof ICElement) { return myElements[x];
return((ICElement) myElements[x]);
}
} }
return (null); return (null);
} }
private static void addNatureToProject(IProject proj, String natureId,
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { IProgressMonitor monitor) throws CoreException {
IProjectDescription description = proj.getDescription(); IProjectDescription description = proj.getDescription();
String[] prevNatures = description.getNatureIds(); String[] prevNatures = description.getNatureIds();
String[] newNatures = new String[prevNatures.length + 1]; String[] newNatures = new String[prevNatures.length + 1];
@ -237,23 +205,22 @@ public class CProjectHelper {
description.setNatureIds(newNatures); description.setNatureIds(newNatures);
proj.setDescription(description, monitor); proj.setDescription(description, monitor);
} }
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath,
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException { IProgressMonitor monitor) throws InvocationTargetException {
ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile); ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
srcZipFile);
try { try {
ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery()); ImportOperation op = new ImportOperation(destPath,
structureProvider.getRoot(), structureProvider,
new ImportOverwriteQuery());
op.run(monitor); op.run(monitor);
} catch (InterruptedException e) { } catch (InterruptedException e) {
// should not happen // should not happen
} }
} }
private static class ImportOverwriteQuery implements IOverwriteQuery { private static class ImportOverwriteQuery implements IOverwriteQuery {
public String queryOverwrite(String file) { public String queryOverwrite(String file) {
return ALL; 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 {
}
}