28
28
import org .eclipse .rcptt .core .tests .NoErrorsInLog ;
29
29
import org .eclipse .rcptt .core .workspace .RcpttCore ;
30
30
import org .junit .After ;
31
+ import org .junit .Assert ;
31
32
import org .junit .Before ;
32
33
import org .junit .Rule ;
33
34
import org .junit .Test ;
@@ -37,6 +38,7 @@ public class WorkingCopyTest {
37
38
private static final IWorkspace WORKSPACE = ResourcesPlugin .getWorkspace ();
38
39
private static final IProject PROJECT = WORKSPACE .getRoot ().getProject (PRJ_NAME );
39
40
private IQ7Project q7project ;
41
+ private static final int LEAK_SIZE = 100 ;
40
42
41
43
42
44
@ Rule
@@ -77,7 +79,40 @@ public void testNewTestcaseAppear() throws ModelException {
77
79
copy .commitWorkingCopy (true , new NullProgressMonitor ());
78
80
assertEquals ("new test case name" , testcase .getElementName ());
79
81
}
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
+ }
80
100
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
+
81
116
@ Test
82
117
public void deleteEditedResource () throws CoreException , InterruptedException {
83
118
IQ7Project prj = q7project ;
@@ -92,12 +127,13 @@ public void deleteEditedResource() throws CoreException, InterruptedException {
92
127
};
93
128
RcpttCore .addElementChangedListener (listener );
94
129
try {
95
- for (int i = 0 ; i < 1000 ; i ++) {
130
+ for (int i = 0 ; i < LEAK_SIZE ; i ++) {
96
131
ITestCase testcase = prj .getRootFolder ().createTestCase ("mytestcase" +i ,true , new NullProgressMonitor ());
97
132
98
133
ITestCase copy = (ITestCase ) testcase
99
134
.getWorkingCopy (new NullProgressMonitor ());
100
135
assertTrue (testcase .exists ());
136
+ assertFalse (copy .hasUnsavedChanges ());
101
137
PROJECT .getFile (testcase .getName ()).delete (true , null );
102
138
try {
103
139
testcase .getElementName ();
0 commit comments