Skip to content

Commit 941845d

Browse files
committed
More tests
1 parent cbdbe98 commit 941845d

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

tests/org.eclipse.rcptt.core.tests/src/org/eclipse/rcptt/core/tests/model/WorkingCopyTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.rcptt.core.tests.NoErrorsInLog;
2929
import org.eclipse.rcptt.core.workspace.RcpttCore;
3030
import org.junit.After;
31+
import org.junit.Assert;
3132
import org.junit.Before;
3233
import org.junit.Rule;
3334
import org.junit.Test;
@@ -37,6 +38,7 @@ public class WorkingCopyTest {
3738
private static final IWorkspace WORKSPACE = ResourcesPlugin.getWorkspace();
3839
private static final IProject PROJECT = WORKSPACE.getRoot().getProject(PRJ_NAME);
3940
private IQ7Project q7project;
41+
private static final int LEAK_SIZE = 100;
4042

4143

4244
@Rule
@@ -77,7 +79,40 @@ public void testNewTestcaseAppear() throws ModelException {
7779
copy.commitWorkingCopy(true, new NullProgressMonitor());
7880
assertEquals("new test case name", testcase.getElementName());
7981
}
82+
83+
84+
@Test
85+
public void queryDeletedResource() throws CoreException, InterruptedException {
86+
IQ7Project prj = q7project;
87+
for (int i = 0; i < LEAK_SIZE; i++) {
88+
ITestCase testcase = prj.getRootFolder().createTestCase("mytestcase"+i,true, new NullProgressMonitor());
89+
PROJECT.getFile(testcase.getName()).delete(true, null);
90+
try {
91+
testcase.getContexts(); // may cause leaks
92+
Assert.fail();
93+
} catch(ModelException e) {
94+
// expected, as resource is deleted
95+
}
96+
System.gc();
97+
NO_ERRORS.assertNoErrors();
98+
}
99+
}
80100

101+
@Test
102+
public void deleteWorkingCopyResource() throws CoreException {
103+
for (int i = 0; i < LEAK_SIZE; i++) {
104+
ITestCase testcase = q7project.getRootFolder().createTestCase("mytestcase" + i, true, new NullProgressMonitor());
105+
106+
ITestCase copy = (ITestCase) testcase
107+
.getWorkingCopy(new NullProgressMonitor());
108+
assertTrue(testcase.exists());
109+
assertFalse(copy.hasUnsavedChanges());
110+
PROJECT.getFile(testcase.getName()).delete(true, null);
111+
System.gc();
112+
NO_ERRORS.assertNoErrors();
113+
}
114+
}
115+
81116
@Test
82117
public void deleteEditedResource() throws CoreException, InterruptedException {
83118
IQ7Project prj = q7project;
@@ -92,12 +127,13 @@ public void deleteEditedResource() throws CoreException, InterruptedException {
92127
};
93128
RcpttCore.addElementChangedListener(listener);
94129
try {
95-
for (int i = 0; i < 1000; i++) {
130+
for (int i = 0; i < LEAK_SIZE; i++) {
96131
ITestCase testcase = prj.getRootFolder().createTestCase("mytestcase"+i,true, new NullProgressMonitor());
97132

98133
ITestCase copy = (ITestCase) testcase
99134
.getWorkingCopy(new NullProgressMonitor());
100135
assertTrue(testcase.exists());
136+
assertFalse(copy.hasUnsavedChanges());
101137
PROJECT.getFile(testcase.getName()).delete(true, null);
102138
try {
103139
testcase.getElementName();

0 commit comments

Comments
 (0)