1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-09 01:05:38 +02:00

bug 212596: JUnit failures in cdt.managedbuilder.test.suite

Java generics and other cleanup
This commit is contained in:
Andrew Gvozdev 2009-10-08 21:44:21 +00:00
parent 6700e5b1b3
commit bd20ae7286
2 changed files with 32 additions and 36 deletions

View file

@ -70,7 +70,6 @@ public class ManagedBuildTestHelper {
private static final String rcbsToolInputTypeName = new String("Resource Custom Build Step Input Type"); //$NON-NLS-1$ private static final String rcbsToolInputTypeName = new String("Resource Custom Build Step Input Type"); //$NON-NLS-1$
private static final String rcbsToolOutputTypeId = new String("org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype"); //$NON-NLS-1$ private static final String rcbsToolOutputTypeId = new String("org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype"); //$NON-NLS-1$
private static final String rcbsToolOutputTypeName = new String("Resource Custom Build Step Output Type"); //$NON-NLS-1$ private static final String rcbsToolOutputTypeName = new String("Resource Custom Build Step Output Type"); //$NON-NLS-1$
private static final String PATH_SEPERATOR = ";"; //$NON-NLS-1$
/* (non-Javadoc) /* (non-Javadoc)
@ -291,7 +290,6 @@ public class ManagedBuildTestHelper {
addManagedBuildNature(project); addManagedBuildNature(project);
// Find the base project type definition // Find the base project type definition
IProjectType[] projTypes = ManagedBuildManager.getDefinedProjectTypes();
IProjectType projType = ManagedBuildManager.getProjectType(projectTypeId); IProjectType projType = ManagedBuildManager.getProjectType(projectTypeId);
Assert.assertNotNull(projType); Assert.assertNotNull(projType);
@ -301,6 +299,7 @@ public class ManagedBuildTestHelper {
newProject = ManagedBuildManager.createManagedProject(project, projType); newProject = ManagedBuildManager.createManagedProject(project, projType);
} catch (Exception e) { } catch (Exception e) {
Assert.fail("Failed to create managed project for: " + project.getName()); Assert.fail("Failed to create managed project for: " + project.getName());
return;
} }
Assert.assertEquals(newProject.getName(), projType.getName()); Assert.assertEquals(newProject.getName(), projType.getName());
Assert.assertFalse(newProject.equals(projType)); Assert.assertFalse(newProject.equals(projType));
@ -344,6 +343,7 @@ public class ManagedBuildTestHelper {
static public void addManagedBuildNature (IProject project) { static public void addManagedBuildNature (IProject project) {
// Create the buildinformation object for the project // Create the buildinformation object for the project
IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project); IManagedBuildInfo info = ManagedBuildManager.createBuildInfo(project);
Assert.assertNotNull(info);
// info.setValid(true); // info.setValid(true);
// Add the managed build nature // Add the managed build nature
@ -362,6 +362,7 @@ public class ManagedBuildTestHelper {
desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY); desc.create(CCorePlugin.BUILD_SCANNER_INFO_UNIQ_ID, ManagedBuildManager.INTERFACE_IDENTITY);
} catch (CoreException e) { } catch (CoreException e) {
Assert.fail("Test failed on adding managed builder as scanner info provider: " + e.getLocalizedMessage()); Assert.fail("Test failed on adding managed builder as scanner info provider: " + e.getLocalizedMessage());
return;
} }
try { try {
desc.saveProjectData(); desc.saveProjectData();
@ -537,6 +538,7 @@ public class ManagedBuildTestHelper {
input = new FileReader(fullPath.toFile()); input = new FileReader(fullPath.toFile());
} catch (Exception e) { } catch (Exception e) {
Assert.fail("File " + fullPath.toString() + " could not be read: " + e.getLocalizedMessage()); Assert.fail("File " + fullPath.toString() + " could not be read: " + e.getLocalizedMessage());
return null;
} }
//InputStream input = file.getContents(true); // A different way to read the file... //InputStream input = file.getContents(true); // A different way to read the file...
int c; int c;
@ -582,6 +584,7 @@ public class ManagedBuildTestHelper {
srcReader = new FileReader(srcFile.toFile()); srcReader = new FileReader(srcFile.toFile());
} catch (Exception e) { } catch (Exception e) {
Assert.fail("File " + file.toString() + " could not be read."); Assert.fail("File " + file.toString() + " could not be read.");
return null;
} }
if (file.segmentCount() > 1) { if (file.segmentCount() > 1) {
IPath newDir = tmpSrcDir; IPath newDir = tmpSrcDir;
@ -598,6 +601,7 @@ public class ManagedBuildTestHelper {
writer = new FileWriter(destFile.toFile()); writer = new FileWriter(destFile.toFile());
} catch (Exception e) { } catch (Exception e) {
Assert.fail("File " + files[i].toString() + " could not be written."); Assert.fail("File " + files[i].toString() + " could not be written.");
return null;
} }
try { try {
int c; int c;
@ -631,14 +635,13 @@ public class ManagedBuildTestHelper {
if (!tmpSrcDirFile.exists()) { if (!tmpSrcDirFile.exists()) {
Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " does not exist."); Assert.fail("Temporary directory " + tmpSrcDirFile.toString() + " does not exist.");
} else { } else {
boolean succeed;
for (int i=0; i<files.length; i++) { for (int i=0; i<files.length; i++) {
// Delete the file // Delete the file
IPath thisFile = tmpSrcDir.append(files[i]); IPath thisFile = tmpSrcDir.append(files[i]);
succeed = thisFile.toFile().delete(); thisFile.toFile().delete();
} }
// Delete the dir // Delete the dir
succeed = tmpSrcDirFile.delete(); tmpSrcDirFile.delete();
} }
} }
} }
@ -683,16 +686,15 @@ public class ManagedBuildTestHelper {
} }
static private void deleteDirectory(File dir) { static private void deleteDirectory(File dir) {
boolean b;
File[] toDelete = dir.listFiles(); File[] toDelete = dir.listFiles();
for (int i=0; i<toDelete.length; i++) { for (int i=0; i<toDelete.length; i++) {
File fileToDelete = toDelete[i]; File fileToDelete = toDelete[i];
if (fileToDelete.isDirectory()) { if (fileToDelete.isDirectory()) {
deleteDirectory(fileToDelete); deleteDirectory(fileToDelete);
} }
b = fileToDelete.delete(); fileToDelete.delete();
} }
b = dir.delete(); dir.delete();
} }
public static ITool createRcbsTool(IConfiguration cfg, String file, String inputs, String outputs, String cmds){ public static ITool createRcbsTool(IConfiguration cfg, String file, String inputs, String outputs, String cmds){
@ -750,7 +752,7 @@ public class ManagedBuildTestHelper {
} }
public static ITool[] getRcbsTools(IResourceConfiguration rcConfig){ public static ITool[] getRcbsTools(IResourceConfiguration rcConfig){
List list = new ArrayList(); List<ITool> list = new ArrayList<ITool>();
ITool tools[] = rcConfig.getTools(); ITool tools[] = rcConfig.getTools();
for (int i = 0; i < tools.length; i++) { for (int i = 0; i < tools.length; i++) {
ITool tool = tools[i]; ITool tool = tools[i];
@ -759,7 +761,7 @@ public class ManagedBuildTestHelper {
} }
} }
if(list.size() != 0) if(list.size() != 0)
return (ITool[])list.toArray(new ITool[list.size()]); return list.toArray(new ITool[list.size()]);
return null; return null;
} }

View file

@ -18,27 +18,32 @@ package org.eclipse.cdt.managedbuilder.core.tests;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import junit.framework.Test; import junit.framework.Test;
import junit.framework.TestCase; import junit.framework.TestCase;
import junit.framework.TestSuite; import junit.framework.TestSuite;
import org.eclipse.cdt.managedbuilder.core.IAdditionalInput; import org.eclipse.cdt.managedbuilder.core.IAdditionalInput;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IInputType;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo; import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.IManagedProject; import org.eclipse.cdt.managedbuilder.core.IManagedProject;
import org.eclipse.cdt.managedbuilder.core.IOutputType; import org.eclipse.cdt.managedbuilder.core.IOutputType;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration; import org.eclipse.cdt.managedbuilder.core.IResourceConfiguration;
import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.internal.core.Tool; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.ToolChain; import org.eclipse.cdt.managedbuilder.internal.core.ToolChain;
import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager; import org.eclipse.cdt.managedbuilder.projectconverter.UpdateManagedProjectManager;
import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin; import org.eclipse.cdt.managedbuilder.testplugin.CTestPlugin;
import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper; import org.eclipse.cdt.managedbuilder.testplugin.ManagedBuildTestHelper;
import org.eclipse.core.resources.*; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IPathVariableManager;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
@ -68,7 +73,7 @@ public class ManagedProject30MakefileTests extends TestCase {
// TODO: testLinkedFolder fails intermittently saying that it cannot find // TODO: testLinkedFolder fails intermittently saying that it cannot find
// the makefiles to compare. This appears to be a test set issue, // the makefiles to compare. This appears to be a test set issue,
// rather than an MBS functionality issue // rather than an MBS functionality issue
//suite.addTest(new ManagedProject30MakefileTests("test30LinkedFolder")); suite.addTest(new ManagedProject30MakefileTests("test30LinkedFolder"));
suite.addTest(new ManagedProject30MakefileTests("test30CopyandDeploy")); suite.addTest(new ManagedProject30MakefileTests("test30CopyandDeploy"));
suite.addTest(new ManagedProject30MakefileTests("test30DeleteFile")); suite.addTest(new ManagedProject30MakefileTests("test30DeleteFile"));
suite.addTest(new ManagedProject30MakefileTests("test30NoFilesToBuild")); suite.addTest(new ManagedProject30MakefileTests("test30NoFilesToBuild"));
@ -92,7 +97,7 @@ public class ManagedProject30MakefileTests extends TestCase {
} }
private IProject[] createProject(String projName, IPath location, String projectTypeId, boolean containsZip){ private IProject[] createProject(String projName, IPath location, String projectTypeId, boolean containsZip){
ArrayList projectList = null; ArrayList<IProject> projectList = new ArrayList<IProject>();
if (containsZip) { if (containsZip) {
File testDir = CTestPlugin.getFileInPlugin(new Path("resources/test30Projects/" + projName)); File testDir = CTestPlugin.getFileInPlugin(new Path("resources/test30Projects/" + projName));
if(testDir == null) { if(testDir == null) {
@ -108,7 +113,7 @@ public class ManagedProject30MakefileTests extends TestCase {
} }
}); });
projectList = new ArrayList(projectZips.length); projectList = new ArrayList<IProject>(projectZips.length);
for(int i = 0; i < projectZips.length; i++){ for(int i = 0; i < projectZips.length; i++){
try{ try{
String projectName = projectZips[i].getName(); String projectName = projectZips[i].getName();
@ -133,12 +138,13 @@ public class ManagedProject30MakefileTests extends TestCase {
try{ try{
IProject project = ManagedBuildTestHelper.createProject(projName, null, location, projectTypeId); IProject project = ManagedBuildTestHelper.createProject(projName, null, location, projectTypeId);
if(project != null) if(project != null)
projectList = new ArrayList(1); projectList = new ArrayList<IProject>(1);
projectList.add(project); projectList.add(project);
} catch(Exception e){} } catch(Exception e){
}
} }
return (IProject[])projectList.toArray(new IProject[projectList.size()]); return projectList.toArray(new IProject[projectList.size()]);
} }
private IProject[] createProjects(String projName, IPath location, String projectTypeId, boolean containsZip) { private IProject[] createProjects(String projName, IPath location, String projectTypeId, boolean containsZip) {
@ -148,11 +154,6 @@ public class ManagedProject30MakefileTests extends TestCase {
public String queryOverwrite(String file) { public String queryOverwrite(String file) {
return ALL; return ALL;
}}; }};
IOverwriteQuery queryNOALL = new IOverwriteQuery(){
public String queryOverwrite(String file) {
return NO_ALL;
}};
UpdateManagedProjectManager.setBackupFileOverwriteQuery(queryALL); UpdateManagedProjectManager.setBackupFileOverwriteQuery(queryALL);
UpdateManagedProjectManager.setUpdateProjectQuery(queryALL); UpdateManagedProjectManager.setUpdateProjectQuery(queryALL);
@ -390,11 +391,11 @@ public class ManagedProject30MakefileTests extends TestCase {
IProject[] projects = createProjects("deleteFile", null, null, true); IProject[] projects = createProjects("deleteFile", null, null, true);
final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IWorkspace workspace = ResourcesPlugin.getWorkspace();
ArrayList resourceList = new ArrayList(1); ArrayList<IFile> resourceList = new ArrayList<IFile>(1);
IProject project = projects[0]; IProject project = projects[0];
IFile projfile = project.getFile("filetobedeleted.cxx"); IFile projfile = project.getFile("filetobedeleted.cxx");
resourceList.add(projfile); resourceList.add(projfile);
final IResource[] fileResource = (IResource[])resourceList.toArray(new IResource[resourceList.size()]); final IResource[] fileResource = resourceList.toArray(new IResource[resourceList.size()]);
IWorkspaceRunnable runnable = new IWorkspaceRunnable() { IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException { public void run(IProgressMonitor monitor) throws CoreException {
workspace.delete(fileResource, false, null); workspace.delete(fileResource, false, null);
@ -461,7 +462,6 @@ public class ManagedProject30MakefileTests extends TestCase {
IProject project = projects[0]; IProject project = projects[0];
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project); IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
IConfiguration config = info.getDefaultConfiguration(); IConfiguration config = info.getDefaultConfiguration();
IFile projfile = project.getFile("main.cxx");
config.setPreannouncebuildStep("Pre-announce Build Step"); config.setPreannouncebuildStep("Pre-announce Build Step");
config.setPrebuildStep("echo 'executing Pre-Build Step' "); config.setPrebuildStep("echo 'executing Pre-Build Step' ");
config.setPostannouncebuildStep("Post-announce Build Step"); config.setPostannouncebuildStep("Post-announce Build Step");
@ -552,13 +552,7 @@ public class ManagedProject30MakefileTests extends TestCase {
for (int i=0; i<configs.length; i++) { for (int i=0; i<configs.length; i++) {
IConfiguration config = configs[i]; IConfiguration config = configs[i];
ToolChain tc = (ToolChain)config.getToolChain(); ToolChain tc = (ToolChain)config.getToolChain();
Iterator iter = tc.getToolList().listIterator(); assertEquals(5, tc.getToolList().size());
int j = 0;
while (iter.hasNext()) {
Tool toolChild = (Tool) iter.next();
j++;
}
assertEquals(5, j);
} }
buildDegenerativeProjects(projects, null); buildDegenerativeProjects(projects, null);
} }