mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
Bug 579669: Remove testProject in finally block
These tests were not cleaning up properly if they failed. Change-Id: Ic649335dd439a1cc29dd2784b203158e49d4bb1c
This commit is contained in:
parent
af2b4aba4b
commit
e954ff6fe1
1 changed files with 163 additions and 155 deletions
|
@ -309,169 +309,177 @@ public class CModelTests extends TestCase {
|
|||
|
||||
// bug 275609
|
||||
public void testSourceExclusionFilters_275609() throws Exception {
|
||||
ICProject testProject;
|
||||
testProject = CProjectHelper.createCProject("bug257609", "none", IPDOMManager.ID_NO_INDEXER);
|
||||
if (testProject == null)
|
||||
fail("Unable to create project");
|
||||
|
||||
IFolder testFolder = testProject.getProject().getFolder("test");
|
||||
testFolder.create(true, true, monitor);
|
||||
IFolder subFolder1 = testFolder.getFolder("1");
|
||||
subFolder1.create(true, true, monitor);
|
||||
IFolder subFolder2 = testFolder.getFolder("2");
|
||||
subFolder2.create(true, true, monitor);
|
||||
IFile file0 = testFolder.getFile("test0.c");
|
||||
file0.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
IFile file1 = subFolder1.getFile("test1.c");
|
||||
file1.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
IFile file2 = subFolder2.getFile("test2.c");
|
||||
file2.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
|
||||
List<ICElement> cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
ISourceRoot sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
List<ICElement> cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals("test", cContainers.get(0).getElementName());
|
||||
|
||||
ICContainer testContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
List<ICElement> subContainers = testContainer.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(2, subContainers.size());
|
||||
assertEquals("1", subContainers.get(0).getElementName());
|
||||
assertEquals("2", subContainers.get(1).getElementName());
|
||||
Object[] nonCResources = testContainer.getNonCResources();
|
||||
assertEquals(0, nonCResources.length);
|
||||
|
||||
List<ICElement> tUnits = testContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(1, tUnits.size());
|
||||
assertEquals("test0.c", tUnits.get(0).getElementName());
|
||||
|
||||
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(testProject.getProject(), true);
|
||||
ICConfigurationDescription activeCfg = prjDesc.getActiveConfiguration();
|
||||
assertNotNull(activeCfg);
|
||||
|
||||
// add filter to source entry
|
||||
ICSourceEntry[] entries = activeCfg.getSourceEntries();
|
||||
final String sourceEntryName = entries[0].getName();
|
||||
final IPath[] exclusionPatterns = new IPath[] { new Path("test/*") };
|
||||
|
||||
ICSourceEntry entry = new CSourceEntry(sourceEntryName, exclusionPatterns, entries[0].getFlags());
|
||||
activeCfg.setSourceEntries(new ICSourceEntry[] { entry });
|
||||
|
||||
// store the changed configuration
|
||||
CoreModel.getDefault().setProjectDescription(testProject.getProject(), prjDesc);
|
||||
|
||||
cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals("test", cContainers.get(0).getElementName());
|
||||
|
||||
testContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
tUnits = testContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(0, tUnits.size());
|
||||
|
||||
subContainers = testContainer.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(0, subContainers.size());
|
||||
nonCResources = testContainer.getNonCResources();
|
||||
assertEquals(3, nonCResources.length);
|
||||
assertEquals(subFolder1, nonCResources[0]);
|
||||
assertEquals(subFolder2, nonCResources[1]);
|
||||
assertEquals(file0, nonCResources[2]);
|
||||
|
||||
ICProject testProject = null;
|
||||
try {
|
||||
testProject.getProject().delete(true, true, monitor);
|
||||
} catch (CoreException e) {
|
||||
testProject = CProjectHelper.createCProject("bug257609", "none", IPDOMManager.ID_NO_INDEXER);
|
||||
if (testProject == null)
|
||||
fail("Unable to create project");
|
||||
|
||||
IFolder testFolder = testProject.getProject().getFolder("test");
|
||||
testFolder.create(true, true, monitor);
|
||||
IFolder subFolder1 = testFolder.getFolder("1");
|
||||
subFolder1.create(true, true, monitor);
|
||||
IFolder subFolder2 = testFolder.getFolder("2");
|
||||
subFolder2.create(true, true, monitor);
|
||||
IFile file0 = testFolder.getFile("test0.c");
|
||||
file0.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
IFile file1 = subFolder1.getFile("test1.c");
|
||||
file1.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
IFile file2 = subFolder2.getFile("test2.c");
|
||||
file2.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
|
||||
List<ICElement> cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
ISourceRoot sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
List<ICElement> cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals("test", cContainers.get(0).getElementName());
|
||||
|
||||
ICContainer testContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
List<ICElement> subContainers = testContainer.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(2, subContainers.size());
|
||||
assertEquals("1", subContainers.get(0).getElementName());
|
||||
assertEquals("2", subContainers.get(1).getElementName());
|
||||
Object[] nonCResources = testContainer.getNonCResources();
|
||||
assertEquals(0, nonCResources.length);
|
||||
|
||||
List<ICElement> tUnits = testContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(1, tUnits.size());
|
||||
assertEquals("test0.c", tUnits.get(0).getElementName());
|
||||
|
||||
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(testProject.getProject(), true);
|
||||
ICConfigurationDescription activeCfg = prjDesc.getActiveConfiguration();
|
||||
assertNotNull(activeCfg);
|
||||
|
||||
// add filter to source entry
|
||||
ICSourceEntry[] entries = activeCfg.getSourceEntries();
|
||||
final String sourceEntryName = entries[0].getName();
|
||||
final IPath[] exclusionPatterns = new IPath[] { new Path("test/*") };
|
||||
|
||||
ICSourceEntry entry = new CSourceEntry(sourceEntryName, exclusionPatterns, entries[0].getFlags());
|
||||
activeCfg.setSourceEntries(new ICSourceEntry[] { entry });
|
||||
|
||||
// store the changed configuration
|
||||
CoreModel.getDefault().setProjectDescription(testProject.getProject(), prjDesc);
|
||||
|
||||
cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals("test", cContainers.get(0).getElementName());
|
||||
|
||||
testContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
tUnits = testContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(0, tUnits.size());
|
||||
|
||||
subContainers = testContainer.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(0, subContainers.size());
|
||||
nonCResources = testContainer.getNonCResources();
|
||||
assertEquals(3, nonCResources.length);
|
||||
assertEquals(subFolder1, nonCResources[0]);
|
||||
assertEquals(subFolder2, nonCResources[1]);
|
||||
assertEquals(file0, nonCResources[2]);
|
||||
} finally {
|
||||
try {
|
||||
if (testProject != null) {
|
||||
testProject.getProject().delete(true, true, monitor);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// bug 179474
|
||||
public void testSourceExclusionFilters_179474() throws Exception {
|
||||
ICProject testProject;
|
||||
testProject = CProjectHelper.createCProject("bug179474", "none", IPDOMManager.ID_NO_INDEXER);
|
||||
if (testProject == null)
|
||||
fail("Unable to create project");
|
||||
|
||||
IFolder subFolder = testProject.getProject().getFolder("sub");
|
||||
subFolder.create(true, true, monitor);
|
||||
IFile fileA = testProject.getProject().getFile("a.cpp");
|
||||
fileA.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
IFile fileB = subFolder.getFile("b.cpp");
|
||||
fileB.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
|
||||
List<ICElement> cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
ISourceRoot sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
List<ICElement> cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals(subFolder.getName(), cContainers.get(0).getElementName());
|
||||
|
||||
ICContainer subContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
List<ICElement> tUnits = subContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(1, tUnits.size());
|
||||
assertEquals(fileB.getName(), tUnits.get(0).getElementName());
|
||||
|
||||
tUnits = sourceRoot.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(1, tUnits.size());
|
||||
assertEquals(fileA.getName(), tUnits.get(0).getElementName());
|
||||
|
||||
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(testProject.getProject(), true);
|
||||
ICConfigurationDescription activeCfg = prjDesc.getActiveConfiguration();
|
||||
assertNotNull(activeCfg);
|
||||
|
||||
// add filter to source entry
|
||||
ICSourceEntry[] entries = activeCfg.getSourceEntries();
|
||||
final String sourceEntryName = entries[0].getName();
|
||||
final IPath[] exclusionPatterns = new IPath[] { new Path("**/*.cpp") };
|
||||
|
||||
ICSourceEntry entry = new CSourceEntry(sourceEntryName, exclusionPatterns, entries[0].getFlags());
|
||||
activeCfg.setSourceEntries(new ICSourceEntry[] { entry });
|
||||
|
||||
// store the changed configuration
|
||||
CoreModel.getDefault().setProjectDescription(testProject.getProject(), prjDesc);
|
||||
|
||||
cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals(subFolder.getName(), cContainers.get(0).getElementName());
|
||||
|
||||
subContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
tUnits = subContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(0, tUnits.size());
|
||||
|
||||
tUnits = sourceRoot.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(0, tUnits.size());
|
||||
|
||||
Object[] nonCResources = subContainer.getNonCResources();
|
||||
assertEquals(1, nonCResources.length);
|
||||
assertEquals(fileB, nonCResources[0]);
|
||||
|
||||
nonCResources = sourceRoot.getNonCResources();
|
||||
assertTrue(Arrays.asList(nonCResources).contains(fileA));
|
||||
|
||||
ICProject testProject = null;
|
||||
try {
|
||||
testProject.getProject().delete(true, true, monitor);
|
||||
} catch (CoreException e) {
|
||||
testProject = CProjectHelper.createCProject("bug179474", "none", IPDOMManager.ID_NO_INDEXER);
|
||||
if (testProject == null)
|
||||
fail("Unable to create project");
|
||||
|
||||
IFolder subFolder = testProject.getProject().getFolder("sub");
|
||||
subFolder.create(true, true, monitor);
|
||||
IFile fileA = testProject.getProject().getFile("a.cpp");
|
||||
fileA.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
IFile fileB = subFolder.getFile("b.cpp");
|
||||
fileB.create(new ByteArrayInputStream(new byte[0]), true, monitor);
|
||||
|
||||
List<ICElement> cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
ISourceRoot sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
List<ICElement> cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals(subFolder.getName(), cContainers.get(0).getElementName());
|
||||
|
||||
ICContainer subContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
List<ICElement> tUnits = subContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(1, tUnits.size());
|
||||
assertEquals(fileB.getName(), tUnits.get(0).getElementName());
|
||||
|
||||
tUnits = sourceRoot.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(1, tUnits.size());
|
||||
assertEquals(fileA.getName(), tUnits.get(0).getElementName());
|
||||
|
||||
ICProjectDescription prjDesc = CoreModel.getDefault().getProjectDescription(testProject.getProject(), true);
|
||||
ICConfigurationDescription activeCfg = prjDesc.getActiveConfiguration();
|
||||
assertNotNull(activeCfg);
|
||||
|
||||
// add filter to source entry
|
||||
ICSourceEntry[] entries = activeCfg.getSourceEntries();
|
||||
final String sourceEntryName = entries[0].getName();
|
||||
final IPath[] exclusionPatterns = new IPath[] { new Path("**/*.cpp") };
|
||||
|
||||
ICSourceEntry entry = new CSourceEntry(sourceEntryName, exclusionPatterns, entries[0].getFlags());
|
||||
activeCfg.setSourceEntries(new ICSourceEntry[] { entry });
|
||||
|
||||
// store the changed configuration
|
||||
CoreModel.getDefault().setProjectDescription(testProject.getProject(), prjDesc);
|
||||
|
||||
cSourceRoots = testProject.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cSourceRoots.size());
|
||||
assertEquals(testProject.getElementName(), cSourceRoots.get(0).getElementName());
|
||||
|
||||
sourceRoot = (ISourceRoot) cSourceRoots.get(0);
|
||||
|
||||
cContainers = sourceRoot.getChildrenOfType(ICElement.C_CCONTAINER);
|
||||
assertEquals(1, cContainers.size());
|
||||
assertEquals(subFolder.getName(), cContainers.get(0).getElementName());
|
||||
|
||||
subContainer = (ICContainer) cContainers.get(0);
|
||||
|
||||
tUnits = subContainer.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(0, tUnits.size());
|
||||
|
||||
tUnits = sourceRoot.getChildrenOfType(ICElement.C_UNIT);
|
||||
assertEquals(0, tUnits.size());
|
||||
|
||||
Object[] nonCResources = subContainer.getNonCResources();
|
||||
assertEquals(1, nonCResources.length);
|
||||
assertEquals(fileB, nonCResources[0]);
|
||||
|
||||
nonCResources = sourceRoot.getNonCResources();
|
||||
assertTrue(Arrays.asList(nonCResources).contains(fileA));
|
||||
} finally {
|
||||
try {
|
||||
if (testProject != null) {
|
||||
testProject.getProject().delete(true, true, monitor);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue