1755
|
1 |
"
|
|
2 |
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
|
|
3 |
SWING Research Group, Czech Technical University
|
|
4 |
in Prague
|
|
5 |
|
|
6 |
Permission is hereby granted, free of charge, to any person
|
|
7 |
obtaining a copy of this software and associated documentation
|
|
8 |
files (the 'Software'), to deal in the Software without
|
|
9 |
restriction, including without limitation the rights to use,
|
|
10 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11 |
copies of the Software, and to permit persons to whom the
|
|
12 |
Software is furnished to do so, subject to the following
|
|
13 |
conditions:
|
|
14 |
|
|
15 |
The above copyright notice and this permission notice shall be
|
|
16 |
included in all copies or substantial portions of the Software.
|
|
17 |
|
|
18 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
19 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
20 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
22 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
23 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
24 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
25 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
26 |
"
|
|
27 |
"{ Package: 'stx:libjava' }"
|
|
28 |
|
|
29 |
TestCase subclass:#JavaLookupTests
|
|
30 |
instanceVariableNames:''
|
|
31 |
classVariableNames:''
|
|
32 |
poolDictionaries:''
|
|
33 |
category:'Languages-Java-Tests-Interop'
|
|
34 |
!
|
|
35 |
|
|
36 |
!JavaLookupTests class methodsFor:'documentation'!
|
|
37 |
|
|
38 |
copyright
|
|
39 |
"
|
|
40 |
Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
|
|
41 |
SWING Research Group, Czech Technical University
|
|
42 |
in Prague
|
|
43 |
|
|
44 |
Permission is hereby granted, free of charge, to any person
|
|
45 |
obtaining a copy of this software and associated documentation
|
|
46 |
files (the 'Software'), to deal in the Software without
|
|
47 |
restriction, including without limitation the rights to use,
|
|
48 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
49 |
copies of the Software, and to permit persons to whom the
|
|
50 |
Software is furnished to do so, subject to the following
|
|
51 |
conditions:
|
|
52 |
|
|
53 |
The above copyright notice and this permission notice shall be
|
|
54 |
included in all copies or substantial portions of the Software.
|
|
55 |
|
|
56 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
57 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
58 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
59 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
60 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
61 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
62 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
63 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
64 |
|
|
65 |
"
|
|
66 |
!
|
|
67 |
|
|
68 |
documentation
|
|
69 |
"
|
|
70 |
This testcase tests the java-smalltalk interop lookup
|
|
71 |
(JavaLookup)
|
|
72 |
|
|
73 |
[author:]
|
|
74 |
Jan Vrany <jan.vrany@fit.cvut.cz>
|
|
75 |
|
|
76 |
[instance variables:]
|
|
77 |
|
|
78 |
[class variables:]
|
|
79 |
|
|
80 |
[see also:]
|
|
81 |
|
|
82 |
"
|
|
83 |
! !
|
|
84 |
|
|
85 |
!JavaLookupTests class methodsFor:'resources'!
|
|
86 |
|
|
87 |
resources
|
|
88 |
^ Array with: JavaLookupTestsResource.
|
|
89 |
|
|
90 |
"Created: / 11-04-2011 / 19:38:11 / kursjan <kursjan@fit.cvut.cz>"
|
|
91 |
"Modified: / 29-08-2011 / 23:35:06 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
92 |
"Modified: / 29-10-2012 / 07:47:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
93 |
! !
|
|
94 |
|
|
95 |
!JavaLookupTests methodsFor:'support'!
|
|
96 |
|
|
97 |
javaTestClass
|
1845
|
98 |
^ JAVA cz cvut fit swing methodLookup Object.
|
1755
|
99 |
|
|
100 |
"Created: / 05-09-2011 / 20:13:48 / Jan Kurs <kursjan@fit.cvut.cz>"
|
1845
|
101 |
"Modified: / 30-11-2012 / 22:16:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
1755
|
102 |
!
|
|
103 |
|
|
104 |
personManipulatorClass
|
|
105 |
"Person Manipulator can interact with Person class defined in Java"
|
1845
|
106 |
|
|
107 |
^ JAVA cz cvut fit swing methodLookup PersonManipulator.
|
1755
|
108 |
|
|
109 |
"Created: / 06-09-2011 / 21:48:16 / Jan Kurs <kursjan@fit.cvut.cz>"
|
1845
|
110 |
"Modified: / 30-11-2012 / 22:16:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
1755
|
111 |
!
|
|
112 |
|
|
113 |
setManipulatorClass
|
|
114 |
"Person Manipulator can interact with Person class defined in Java"
|
1845
|
115 |
|
|
116 |
^ JAVA cz cvut fit swing methodLookup SetManipulator.
|
1755
|
117 |
|
|
118 |
"Created: / 25-09-2011 / 16:41:02 / Jan Kurs <kursjan@fit.cvut.cz>"
|
1845
|
119 |
"Modified: / 30-11-2012 / 22:13:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
1755
|
120 |
! !
|
|
121 |
|
|
122 |
!JavaLookupTests methodsFor:'tests - java lookup'!
|
|
123 |
|
|
124 |
test3
|
|
125 |
"I am not sure with this test :)"
|
|
126 |
self shouldnt: [(Java classForName: 'cz.cvut.fit.swing.methodLookup.Object') new isNumber] raise: Exception.
|
|
127 |
self assert: (Java classForName: 'cz.cvut.fit.swing.methodLookup.Object') new isNumber = false.
|
|
128 |
|
|
129 |
"Created: / 11-04-2011 / 19:43:37 / kursjan <kursjan@fit.cvut.cz>"
|
|
130 |
!
|
|
131 |
|
|
132 |
testBasic
|
|
133 |
self
|
|
134 |
shouldnt:[ (Java classForName:'java.lang.Object') new hash ]
|
|
135 |
raise:Exception.
|
|
136 |
self
|
|
137 |
shouldnt:[ (Java classForName:'java.lang.Object') new toString ]
|
|
138 |
raise:Exception.
|
|
139 |
|
|
140 |
"Created: / 11-04-2011 / 19:22:07 / kursjan <kursjan@fit.cvut.cz>"
|
|
141 |
!
|
|
142 |
|
|
143 |
testBoolean
|
|
144 |
self assert: (self javaTestClass new getTrue) = true.
|
|
145 |
|
|
146 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
147 |
"Created: / 05-09-2011 / 21:06:13 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
148 |
!
|
|
149 |
|
|
150 |
testBoolean2
|
|
151 |
self assert: (self javaTestClass new getFalse) = false.
|
|
152 |
|
|
153 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
154 |
"Created: / 05-09-2011 / 21:06:25 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
155 |
!
|
|
156 |
|
|
157 |
testBoolean3
|
|
158 |
self assert: (self javaTestClass new getTruePrim) = true.
|
|
159 |
|
|
160 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
161 |
"Created: / 05-09-2011 / 21:07:29 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
162 |
!
|
|
163 |
|
|
164 |
testBoolean4
|
|
165 |
self assert: (self javaTestClass new getFalsePrim) = false.
|
|
166 |
|
|
167 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
168 |
"Created: / 05-09-2011 / 21:07:38 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
169 |
!
|
|
170 |
|
|
171 |
testBoolean5
|
|
172 |
self assert: (self javaTestClass new getFalseWithConversion) = false.
|
|
173 |
|
|
174 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
175 |
"Created: / 25-09-2011 / 19:23:36 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
176 |
!
|
|
177 |
|
|
178 |
testBoolean6
|
|
179 |
self assert: (self javaTestClass new getFalseFromBooleanValueOf) = false.
|
|
180 |
|
|
181 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
182 |
"Created: / 25-09-2011 / 19:40:22 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
183 |
!
|
|
184 |
|
|
185 |
testClass
|
|
186 |
self assert: ((Java classForName: 'java.lang.Object') isKindOf: JavaClass).
|
|
187 |
self assert: ((Java classForName: 'java.lang.Object') new isKindOf: JavaObject)
|
|
188 |
|
|
189 |
|
|
190 |
"Created: / 11-04-2011 / 19:22:07 / kursjan <kursjan@fit.cvut.cz>"
|
|
191 |
!
|
|
192 |
|
|
193 |
testDoesNotUnderstand
|
|
194 |
self
|
|
195 |
should:[ (Java classForName:'java.lang.Object') new bafickyBaf ]
|
|
196 |
raise:MessageNotUnderstood.
|
|
197 |
|
|
198 |
"Created: / 11-04-2011 / 19:22:07 / kursjan <kursjan@fit.cvut.cz>"
|
|
199 |
"Created: / 30-08-2011 / 22:06:16 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
200 |
!
|
|
201 |
|
|
202 |
testMultipleParameters
|
|
203 |
"test multiple parameters"
|
|
204 |
|
|
205 |
self
|
|
206 |
assert: (self javaTestClass new foo) = 0
|
|
207 |
|
|
208 |
"Created: / 11-04-2011 / 19:48:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
209 |
"Modified: / 05-09-2011 / 20:18:03 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
210 |
!
|
|
211 |
|
|
212 |
testMultipleParameters1
|
|
213 |
"test multiple parameters"
|
|
214 |
|
|
215 |
self
|
|
216 |
assert: (self javaTestClass new foo: 1) = 1
|
|
217 |
|
|
218 |
"Created: / 11-04-2011 / 19:48:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
219 |
"Created: / 05-09-2011 / 20:18:14 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
220 |
!
|
|
221 |
|
|
222 |
testMultipleParameters2
|
|
223 |
"test multiple parameters"
|
|
224 |
|
|
225 |
self
|
|
226 |
assert: (self javaTestClass new foo: 1 and: 2) = 2
|
|
227 |
|
|
228 |
"Created: / 11-04-2011 / 19:48:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
229 |
"Created: / 05-09-2011 / 20:18:30 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
230 |
!
|
|
231 |
|
|
232 |
testSayHello
|
|
233 |
self assert: (self javaTestClass new sayHello = 'hello').
|
|
234 |
|
|
235 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
236 |
"Modified: / 05-09-2011 / 21:05:40 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
237 |
!
|
|
238 |
|
|
239 |
testSayHelloStatic
|
|
240 |
self assert: self javaTestClass staticSayHello = 'static hello'.
|
|
241 |
|
|
242 |
"Created: / 11-04-2011 / 19:32:51 / kursjan <kursjan@fit.cvut.cz>"
|
|
243 |
"Created: / 05-09-2011 / 20:26:44 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
244 |
!
|
|
245 |
|
|
246 |
testTypeOverloading
|
|
247 |
"test type overloading"
|
|
248 |
|
|
249 |
self
|
|
250 |
assert:(self javaTestClass new overloadedMethod: 1) = 4
|
|
251 |
|
|
252 |
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
253 |
"Modified: / 05-09-2011 / 21:37:53 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
254 |
!
|
|
255 |
|
|
256 |
testTypeOverloading2
|
|
257 |
"test type overloading"
|
|
258 |
|
|
259 |
self
|
|
260 |
assert:(self javaTestClass new overloadedMethod: 'Hi') = 3.
|
|
261 |
|
|
262 |
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
263 |
"Created: / 05-09-2011 / 21:37:57 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
264 |
! !
|
|
265 |
|
|
266 |
!JavaLookupTests methodsFor:'tests - obsolete'!
|
|
267 |
|
|
268 |
_testSetManipulator_add
|
|
269 |
"test interaction of smalltalk Set and java.util.Set"
|
|
270 |
| aSet anObject |
|
|
271 |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
|
|
272 |
aSet := SetSample new.
|
|
273 |
anObject := Object new.
|
|
274 |
|
|
275 |
self setManipulatorClass new addElement: aSet and: anObject.
|
|
276 |
self assert: aSet size = 1.
|
|
277 |
self assert:(self setManipulatorClass new getSize: aSet) = 1.
|
|
278 |
self assert:(aSet contains: [:e | e = anObject ]).
|
|
279 |
|
|
280 |
"Created: / 29-10-2012 / 07:17:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
281 |
!
|
|
282 |
|
|
283 |
_testSetManipulator_contains
|
|
284 |
"test interaction of smalltalk Set and java.util.Set"
|
|
285 |
| aSet anObject |
|
|
286 |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
|
|
287 |
aSet := SetSample new.
|
|
288 |
anObject := Object new.
|
|
289 |
|
|
290 |
self assert: (self setManipulatorClass new contains: aSet and: anObject) = false.
|
|
291 |
aSet add: anObject.
|
|
292 |
self assert: (self setManipulatorClass new contains: aSet and: anObject) = true.
|
|
293 |
|
|
294 |
"Created: / 29-10-2012 / 07:18:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
295 |
!
|
|
296 |
|
|
297 |
_testSetManipulator_getSize
|
|
298 |
"test interaction of smalltalk Set and java.util.Set"
|
|
299 |
| aSet |
|
|
300 |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
|
|
301 |
aSet := SetSample new.
|
|
302 |
|
|
303 |
self assert:(self setManipulatorClass new getSize: aSet) = 0.
|
|
304 |
aSet add: Object new.
|
|
305 |
self assert:(self setManipulatorClass new getSize: aSet) = 1.
|
|
306 |
|
|
307 |
"Created: / 29-10-2012 / 07:17:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
308 |
!
|
|
309 |
|
|
310 |
_testSetManipulator_isEmpty
|
|
311 |
"test interaction of smalltalk Set and java.util.Set"
|
|
312 |
| aSet |
|
|
313 |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
|
|
314 |
aSet := SetSample new.
|
|
315 |
|
|
316 |
self assert: (self setManipulatorClass new isEmpty:aSet).
|
|
317 |
aSet add: Object new.
|
|
318 |
self assert: (self setManipulatorClass new isEmpty:aSet) not.
|
|
319 |
|
|
320 |
"Created: / 29-10-2012 / 07:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
321 |
!
|
|
322 |
|
|
323 |
_testSetManipulator_remove
|
|
324 |
"test interaction of smalltalk Set and java.util.Set"
|
|
325 |
| aSet anObject |
|
|
326 |
self breakPoint: #jk info: 'using SetSample, because it contains DNU hook - this is workaround'.
|
|
327 |
aSet := SetSample new.
|
|
328 |
anObject := Object new.
|
|
329 |
|
|
330 |
|
|
331 |
aSet add: anObject.
|
|
332 |
self setManipulatorClass new remove: aSet and: anObject.
|
|
333 |
self assert: aSet size = 0.
|
|
334 |
self assert:(self setManipulatorClass new getSize: aSet) = 0.
|
|
335 |
self assert:(aSet contains: [:e | e = anObject ]) not.
|
|
336 |
|
|
337 |
"Created: / 29-10-2012 / 07:17:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
338 |
! !
|
|
339 |
|
|
340 |
!JavaLookupTests methodsFor:'tests - smalltalk lookup'!
|
|
341 |
|
|
342 |
testPersonManipulator_getAge
|
|
343 |
"test interaction of Smalltallk objects with Java code"
|
|
344 |
| person |
|
|
345 |
person := PersonSample new.
|
|
346 |
|
|
347 |
person name: 'Anne'.
|
|
348 |
person age: 18.
|
|
349 |
|
|
350 |
self
|
|
351 |
assert:(self personManipulatorClass new getPersonAge: person) = 18.
|
|
352 |
|
|
353 |
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
354 |
"Created: / 25-09-2011 / 17:27:45 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
355 |
!
|
|
356 |
|
|
357 |
testPersonManipulator_getName
|
|
358 |
"test interaction of Smalltallk objects with Java code"
|
|
359 |
| person |
|
|
360 |
person := PersonSample new.
|
|
361 |
|
|
362 |
person name: 'Anne'.
|
|
363 |
person age: 18.
|
|
364 |
|
|
365 |
self
|
|
366 |
assert:(self personManipulatorClass new getPersonName: person) = 'Anne'.
|
|
367 |
|
|
368 |
"Created: / 11-04-2011 / 20:02:54 / kursjan <kursjan@fit.cvut.cz>"
|
|
369 |
"Created: / 25-09-2011 / 17:27:34 / Jan Kurs <kursjan@fit.cvut.cz>"
|
|
370 |
! !
|
|
371 |
|
|
372 |
!JavaLookupTests class methodsFor:'documentation'!
|
|
373 |
|
|
374 |
version_SVN
|
|
375 |
^ '$Id$'
|
|
376 |
! !
|