1445
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
1226
|
13 |
"{ Package: 'stx:libbasic3' }"
|
|
14 |
|
|
15 |
"{ NameSpace: Packages }"
|
|
16 |
|
|
17 |
AbstractTestCases subclass:#PackageTestCases
|
1268
|
18 |
instanceVariableNames:'packageManager workingPackage'
|
1226
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
category:'Package'
|
|
22 |
!
|
|
23 |
|
|
24 |
!PackageTestCases class methodsFor:'documentation'!
|
|
25 |
|
1445
|
26 |
copyright
|
|
27 |
"
|
|
28 |
COPYRIGHT (c) 2003 by eXept Software AG
|
|
29 |
All Rights Reserved
|
|
30 |
|
|
31 |
This software is furnished under a license and may be used
|
|
32 |
only in accordance with the terms of that license and with the
|
|
33 |
inclusion of the above copyright notice. This software may not
|
|
34 |
be provided or otherwise made available to, or used by, any
|
|
35 |
other person. No title to or ownership of the software is
|
|
36 |
hereby transferred.
|
|
37 |
"
|
|
38 |
!
|
|
39 |
|
1226
|
40 |
documentation
|
|
41 |
"
|
|
42 |
documentation to be added.
|
|
43 |
|
|
44 |
[author:]
|
|
45 |
(james@miraculix)
|
|
46 |
|
|
47 |
[instance variables:]
|
|
48 |
|
|
49 |
[class variables:]
|
|
50 |
|
|
51 |
[see also:]
|
|
52 |
|
|
53 |
"
|
|
54 |
!
|
|
55 |
|
|
56 |
history
|
|
57 |
"Created: / 24.1.2003 / 16:15:21 / james"
|
|
58 |
! !
|
|
59 |
|
|
60 |
!PackageTestCases methodsFor:'initialize / release'!
|
|
61 |
|
1268
|
62 |
initialize
|
|
63 |
|
|
64 |
packageManager ifNil:[
|
|
65 |
packageManager := self packageManager.
|
|
66 |
].
|
|
67 |
|
|
68 |
workingPackage ifNil:[
|
|
69 |
workingPackage := packageManager workingPackage.
|
|
70 |
].
|
|
71 |
!
|
|
72 |
|
1226
|
73 |
setUp
|
|
74 |
"common setup - invoked before testing"
|
1273
|
75 |
super setUp.
|
1268
|
76 |
self setUpUsedClasses.
|
|
77 |
!
|
|
78 |
|
|
79 |
setUpAllForQWERTY
|
|
80 |
| class copyQWERTYDic|
|
|
81 |
|
|
82 |
(class := Smalltalk at:#QWERTY) ifNil:[
|
|
83 |
self createClassNamed:#QWERTY.
|
|
84 |
(class := Smalltalk at:#QWERTY).
|
|
85 |
].
|
|
86 |
(class compiledMethodAt:#aDummyMethod) ifNil:[
|
|
87 |
self createMethodFor:QWERTY source:'aDummyMethod 1 + 1.'.
|
|
88 |
].
|
|
89 |
(class compiledMethodAt:#aDummyMethod2) ifNil:[
|
|
90 |
self createMethodFor:QWERTY source:'aDummyMethod2 1 + 1.'.
|
|
91 |
].
|
|
92 |
(class compiledMethodAt:#aDummyMethod3) ifNil:[
|
|
93 |
self createMethodFor:QWERTY source:'aDummyMethod3 1 + 1.'.
|
|
94 |
].
|
1273
|
95 |
|
|
96 |
copyQWERTYDic := QWERTY methodDictionary copy.
|
|
97 |
copyQWERTYDic removeKey:#aDummyMethod.
|
|
98 |
copyQWERTYDic removeKey:#aDummyMethod2.
|
|
99 |
copyQWERTYDic removeKey:#aDummyMethod3.
|
|
100 |
copyQWERTYDic keysAndValuesDo:[:key :value |
|
|
101 |
QWERTY methodDictionary removeKey:key.
|
|
102 |
].
|
|
103 |
|
|
104 |
|
1268
|
105 |
packageManager moveClass:QWERTY toPackage:workingPackage.
|
|
106 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod) toPackage:workingPackage.
|
|
107 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod2) toPackage:workingPackage.
|
|
108 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod3) toPackage:workingPackage.
|
|
109 |
!
|
|
110 |
|
|
111 |
setUpAllForQWERTZ
|
|
112 |
| class copyQWERTZDic|
|
1226
|
113 |
(class := Smalltalk at:#QWERTZ) ifNil:[
|
|
114 |
self createClassNamed:#QWERTZ.
|
1268
|
115 |
(class := Smalltalk at:#QWERTZ)
|
|
116 |
].
|
|
117 |
|
|
118 |
|
|
119 |
(class compiledMethodAt:#aDummyMethod) ifNil:[
|
1226
|
120 |
self createMethodFor:QWERTZ source:'aDummyMethod 1 + 1.'.
|
1268
|
121 |
].
|
|
122 |
(class compiledMethodAt:#aDummyMethod2) ifNil:[
|
1226
|
123 |
self createMethodFor:QWERTZ source:'aDummyMethod2 1 + 1.'.
|
1268
|
124 |
].
|
|
125 |
(class compiledMethodAt:#aDummyMethod3) ifNil:[
|
1226
|
126 |
self createMethodFor:QWERTZ source:'aDummyMethod3 1 + 1.'.
|
|
127 |
].
|
|
128 |
|
1268
|
129 |
copyQWERTZDic := QWERTZ methodDictionary copy.
|
|
130 |
copyQWERTZDic removeKey:#aDummyMethod.
|
|
131 |
copyQWERTZDic removeKey:#aDummyMethod2.
|
|
132 |
copyQWERTZDic removeKey:#aDummyMethod3.
|
|
133 |
copyQWERTZDic keysAndValuesDo:[:key :value |
|
|
134 |
QWERTZ methodDictionary removeKey:key.
|
1226
|
135 |
].
|
1268
|
136 |
|
|
137 |
packageManager moveClass:QWERTZ toPackage:workingPackage.
|
|
138 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod) toPackage:workingPackage.
|
|
139 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod2) toPackage:workingPackage.
|
|
140 |
packageManager moveMethod:(class compiledMethodAt:#aDummyMethod3) toPackage:workingPackage.
|
|
141 |
!
|
|
142 |
|
|
143 |
setUpUsedClasses
|
|
144 |
"common setup - invoked before testing"
|
|
145 |
| |
|
|
146 |
self setUpAllForQWERTZ.
|
|
147 |
self setUpAllForQWERTY.
|
1226
|
148 |
!
|
|
149 |
|
|
150 |
tearDown
|
|
151 |
"common cleanup - invoked after testing"
|
|
152 |
|
1268
|
153 |
"move class package to where it was"
|
1226
|
154 |
super tearDown
|
|
155 |
! !
|
|
156 |
|
|
157 |
!PackageTestCases methodsFor:'test - accessing'!
|
|
158 |
|
|
159 |
test_classNames
|
1268
|
160 |
| packageTestCases |
|
1226
|
161 |
[
|
1268
|
162 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'.
|
|
163 |
packageManager moveClass:QWERTZ toPackage:packageTestCases.
|
|
164 |
packageManager moveClass:QWERTY toPackage:packageTestCases.
|
1226
|
165 |
|
1268
|
166 |
self assert:(packageTestCases classNames includesAll:#(#QWERTZ #QWERTY)).
|
|
167 |
self assert:(packageTestCases isDirty).
|
|
168 |
] ensure:
|
|
169 |
[
|
|
170 |
packageTestCases ifNotNil:[
|
|
171 |
packageManager removePackage:packageTestCases.
|
|
172 |
].
|
1226
|
173 |
]
|
|
174 |
!
|
|
175 |
|
|
176 |
test_isDirty
|
1268
|
177 |
| packageTestCases |
|
1226
|
178 |
[
|
1268
|
179 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'.
|
|
180 |
packageManager moveClass:QWERTZ toPackage:packageTestCases.
|
|
181 |
self assert:(packageTestCases isDirty).
|
|
182 |
] ensure:
|
|
183 |
[
|
|
184 |
packageTestCases ifNotNil:[
|
|
185 |
packageManager removePackage:packageTestCases.
|
|
186 |
].
|
1226
|
187 |
]
|
|
188 |
! !
|
|
189 |
|
|
190 |
!PackageTestCases methodsFor:'test - adding and removing'!
|
|
191 |
|
1268
|
192 |
test_addMethod
|
|
193 |
| packageTestCases |
|
|
194 |
|
1226
|
195 |
[
|
1268
|
196 |
"setting up the test"
|
|
197 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'.
|
1226
|
198 |
|
1268
|
199 |
packageManager moveClass:QWERTZ toPackage:packageTestCases.
|
|
200 |
packageTestCases isDirty:false. "i am telling it a fib here "
|
|
201 |
"prerequisites to test"
|
|
202 |
self assert:((packageTestCases blockedMethodsAtClassNamed:#QWERTZ) size == 0).
|
|
203 |
self shouldnt:(packageTestCases isDirty).
|
|
204 |
self assert:(packageTestCases isInstalled).
|
1226
|
205 |
|
1268
|
206 |
"add a method for QWERTZ and test that the package adds a blocked method, as
|
|
207 |
the method is from the workingPackage "
|
|
208 |
self createMethodFor:QWERTZ source:'aDummyMethodTest_test_addMethod2 1 + 1.'.
|
|
209 |
self assert:((packageTestCases blockedMethodsAtClassNamed:#QWERTZ) size == 1).
|
|
210 |
self assert:(packageTestCases isInstalled).
|
|
211 |
self shouldnt:(packageTestCases isDirty).
|
1226
|
212 |
|
1268
|
213 |
self assert:(QWERTZ compiledMethodAt:#aDummyMethodTest_test_addMethod2) package == workingPackage name.
|
1226
|
214 |
|
1268
|
215 |
] ensure:
|
|
216 |
[
|
|
217 |
packageTestCases ifNotNil:[
|
|
218 |
packageManager removePackage:packageTestCases.
|
|
219 |
].
|
|
220 |
|
|
221 |
QWERTZ methodDictionary removeKey:#aDummyMethodTest_test_addMethod2 ifAbsent:["do nothing"].
|
1226
|
222 |
]
|
|
223 |
!
|
|
224 |
|
|
225 |
test_addMethod2
|
1268
|
226 |
"
|
|
227 |
check that when a method is added to a new package and then added back to the old package
|
|
228 |
that
|
|
229 |
1) the oldPackage has got the method and has not got any overriddenMethods
|
|
230 |
2) the 'newPackage' has got the method registered as an overriddenMethod
|
|
231 |
"
|
|
232 |
| packageTestCases packageTestCases2 aMethodToOverride|
|
1226
|
233 |
|
|
234 |
[
|
1268
|
235 |
"setting up the test"
|
|
236 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'.
|
|
237 |
packageTestCases2 := packageManager newPackageNamed:#'packageTestCases2'.
|
1226
|
238 |
|
1268
|
239 |
packageManager moveClass:QWERTZ toPackage:packageTestCases.
|
|
240 |
packageTestCases isDirty:false. "i am telling it a fib here "
|
|
241 |
"prerequisites to test"
|
|
242 |
self shouldnt:(packageTestCases isDirty).
|
|
243 |
aMethodToOverride := QWERTZ methodDictionary values first.
|
|
244 |
"add a method for QWERTZ and test that the package adds a blocked method, as
|
|
245 |
the method is from the workingPackage "
|
1226
|
246 |
|
1268
|
247 |
packageManager addMethod:aMethodToOverride toPackage:packageTestCases2.
|
1226
|
248 |
|
1268
|
249 |
"Tests for packageTestCases"
|
|
250 |
self assert:(packageTestCases overriddenChangesIncludesMethodName:aMethodToOverride name forClassNamed:#QWERTZ).
|
|
251 |
self shouldnt:(packageTestCases isDirty). "it is overridden not dirty"
|
1226
|
252 |
|
1268
|
253 |
"Tests for packageTestCases2"
|
|
254 |
self assert:(packageTestCases2 definesSelector:aMethodToOverride name forClassNamed:#QWERTZ).
|
|
255 |
self assert:(packageTestCases2 isDirty). "was not there before so is dirty!!"
|
|
256 |
self shouldnt:(packageTestCases2 overriddenChangesIncludesMethodName:aMethodToOverride name forClassNamed:#QWERTZ).
|
1226
|
257 |
|
1268
|
258 |
packageManager addMethod:aMethodToOverride toPackage:packageTestCases.
|
1226
|
259 |
|
1268
|
260 |
"Tests for packageTestCases"
|
|
261 |
self assert:(packageTestCases isDirty). "a new version of the method is added!!"
|
|
262 |
self shouldnt:(packageTestCases overriddenChangesIncludesMethodName:aMethodToOverride name forClassNamed:#QWERTZ).
|
1226
|
263 |
|
1268
|
264 |
"Tests for packageTestCases2"
|
|
265 |
self assert:(packageTestCases2 overriddenChangesIncludesMethodName:aMethodToOverride name forClassNamed:#QWERTZ).
|
|
266 |
self assert:(packageTestCases2 isDirty).
|
1226
|
267 |
|
1268
|
268 |
] ensure:
|
1226
|
269 |
[
|
1268
|
270 |
packageTestCases ifNotNil:[
|
|
271 |
packageManager removePackage:packageTestCases.
|
|
272 |
].
|
|
273 |
packageTestCases ifNotNil:[
|
|
274 |
packageManager removePackage:packageTestCases2.
|
|
275 |
].
|
1226
|
276 |
|
1268
|
277 |
QWERTZ methodDictionary removeKey:#aDummyMethodTest_test_addMethod2 ifAbsent:["do nothing"].
|
1226
|
278 |
]
|
|
279 |
!
|
|
280 |
|
1268
|
281 |
test_moveMethod
|
|
282 |
| packageTestCases method1 method2|
|
|
283 |
"prerequisites to test"
|
1226
|
284 |
|
|
285 |
[
|
1268
|
286 |
packageTestCases := packageManager newPackageNamed:#'packageTestCases'.
|
|
287 |
method1 := (QWERTZ compiledMethodAt:#aDummyMethod).
|
|
288 |
method2 := (QWERTZ compiledMethodAt:#aDummyMethod2).
|
1226
|
289 |
|
1268
|
290 |
self shouldnt:(packageTestCases isDirty).
|
1226
|
291 |
|
1268
|
292 |
packageManager moveMethod:method1 toPackage:packageTestCases.
|
|
293 |
packageManager moveMethod:method2 toPackage:packageTestCases.
|
1226
|
294 |
|
1268
|
295 |
self assert:(packageTestCases isDirty).
|
|
296 |
self assert:(packageTestCases isInstalled).
|
|
297 |
self assert:(packageTestCases definesSelector:method1 name forClassNamed:method1 mclass name).
|
|
298 |
self assert:(packageTestCases definesSelector:method2 name forClassNamed:method2 mclass name).
|
1226
|
299 |
|
1268
|
300 |
] ensure:
|
1226
|
301 |
[
|
1268
|
302 |
packageTestCases ifNotNil:[
|
|
303 |
packageManager removePackage:packageTestCases.
|
1226
|
304 |
].
|
|
305 |
]
|
|
306 |
!
|
|
307 |
|
1268
|
308 |
test_packagedClass_isInSmalltalk
|
|
309 |
| package1 package2|
|
|
310 |
"prerequisites to test"
|
1226
|
311 |
|
1268
|
312 |
[
|
|
313 |
package1 := Package packageManager newPackageNamed:#'package1'.
|
|
314 |
package2 := Package packageManager newPackageNamed:#'package2'.
|
1226
|
315 |
|
1268
|
316 |
packageManager moveClassNamed:#QWERTZ fromPackage:workingPackage toPackage:package1.
|
|
317 |
self assert:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk.
|
|
318 |
|
|
319 |
packageManager addClass:QWERTZ toPackage:package2.
|
1226
|
320 |
|
1268
|
321 |
self assert:(package2 packagedClassNamed:#QWERTZ) isInSmalltalk.
|
|
322 |
self shouldnt:(package1 packagedClassNamed:#QWERTZ) isInSmalltalk.
|
|
323 |
|
|
324 |
(package2 packagedClassNamed:#QWERTZ) .
|
1226
|
325 |
|
1268
|
326 |
] ensure:
|
|
327 |
[
|
|
328 |
package1 ifNotNil:[
|
|
329 |
packageManager unloadPackageNamed:#'package1'.
|
1226
|
330 |
].
|
1268
|
331 |
package2 ifNotNil:[
|
|
332 |
packageManager unloadPackageNamed:#'package2'.
|
1226
|
333 |
].
|
|
334 |
]
|
|
335 |
! !
|
|
336 |
|
1268
|
337 |
!PackageTestCases methodsFor:'test - moving'!
|
1226
|
338 |
|
1268
|
339 |
obsolete_test_moveMethod1
|
|
340 |
"moving classes via change notification is now deprecated as i found it best to try and seperate
|
|
341 |
the functionality on Smalltalk and the functionality of package handling.
|
|
342 |
"
|
|
343 |
"Move QWERTZ class from package1 to package 2. Then move the class back."
|
|
344 |
| package1 package2 aName theMethod methodOwnedClass|
|
|
345 |
[
|
|
346 |
package1 := packageManager newPackageNamed:#'package1'.
|
|
347 |
package2 := packageManager newPackageNamed:#'package2'.
|
|
348 |
theMethod :=(QWERTZ compiledMethodAt:#'aDummyMethod').
|
|
349 |
methodOwnedClass := QWERTZ.
|
1226
|
350 |
|
1268
|
351 |
packageManager addMethod:theMethod toPackage:package1.
|
1226
|
352 |
|
1268
|
353 |
self assert:(package1 definesSelector:#'aDummyMethod' forClassNamed:#QWERTZ).
|
|
354 |
self shouldnt:(package2 definesSelector:#'aDummyMethod' forClassNamed:#QWERTZ).
|
1226
|
355 |
|
1268
|
356 |
self assert:(package1 isDirty).
|
|
357 |
self shouldnt:(package2 isDirty).
|
1226
|
358 |
|
1268
|
359 |
"<simulatedChangeInBrowser>"
|
|
360 |
"This change always moves the method away from the classes current owner"
|
|
361 |
self assert:(aName := theMethod package) == package1 name.
|
|
362 |
theMethod setPackage:package2 name.
|
|
363 |
ChangeFaker methodMovePackageChangeWithMethod:theMethod class:methodOwnedClass oldPackageName:aName.
|
|
364 |
"</simulatedChangeInBrowser>"
|
|
365 |
self assert:(package1 definesSelector:#'aDummyMethod' forClassNamed:#QWERTZ).
|
|
366 |
self assert:(package2 definesSelector:#'aDummyMethod' forClassNamed:#QWERTZ).
|
1226
|
367 |
|
1268
|
368 |
self assert:(package2 packagedMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ) isInSmalltalk.
|
|
369 |
self shouldnt:(package1 packagedMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ) isInSmalltalk.
|
1226
|
370 |
|
1268
|
371 |
self assert:(package2 isDependentOnMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ).
|
|
372 |
self shouldnt:(package1 isDependentOnMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ).
|
|
373 |
|
|
374 |
self assert:(package2 isDirty).
|
|
375 |
self assert:(package1 isDirty).
|
1226
|
376 |
|
1268
|
377 |
"<simulatedChangeInBrowser>"
|
|
378 |
"This change always moves the method away from the classes current owner"
|
|
379 |
self assert:(aName := theMethod package) == package2 name.
|
|
380 |
theMethod setPackage:package1 name.
|
|
381 |
ChangeFaker methodMovePackageChangeWithMethod:theMethod class:methodOwnedClass oldPackageName:aName.
|
|
382 |
"</simulatedChangeInBrowser>"
|
|
383 |
self assert:(package1 isDependentOnMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ).
|
|
384 |
self shouldnt:(package2 isDependentOnMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ).
|
1226
|
385 |
|
1268
|
386 |
self shouldnt:(package2 packagedMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ) isInSmalltalk.
|
|
387 |
self assert:(package1 packagedMethodNamed:#'aDummyMethod' forClassNamed:#QWERTZ) isInSmalltalk.
|
1226
|
388 |
|
1268
|
389 |
self assert:(package2 isDirty).
|
|
390 |
self assert:(package1 isDirty).
|
1226
|
391 |
|
1268
|
392 |
packageManager addClass:QWERTZ toPackage:defaultPackage.
|
1226
|
393 |
] ensure:[
|
1268
|
394 |
packageManager unloadPackageNamed:#'package1'.
|
|
395 |
packageManager unloadPackageNamed:#'package2'.
|
|
396 |
].
|
1226
|
397 |
! !
|
|
398 |
|
|
399 |
!PackageTestCases class methodsFor:'documentation'!
|
|
400 |
|
|
401 |
version
|
1445
|
402 |
^ '$Header: /cvs/stx/stx/libbasic3/packages/PackageTestCases.st,v 1.5 2006-01-10 09:31:48 cg Exp $'
|
1226
|
403 |
! !
|