749
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
3 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
4 |
SWING Research Group, Czech Technical University in Prague
|
|
5 |
|
|
6 |
Parts of the code written by Claus Gittinger are under following
|
|
7 |
license:
|
|
8 |
|
|
9 |
This software is furnished under a license and may be used
|
|
10 |
only in accordance with the terms of that license and with the
|
|
11 |
inclusion of the above copyright notice. This software may not
|
|
12 |
be provided or otherwise made available to, or used by, any
|
|
13 |
other person. No title to or ownership of the software is
|
|
14 |
hereby transferred.
|
|
15 |
|
|
16 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
17 |
|
|
18 |
Permission is hereby granted, free of charge, to any person
|
|
19 |
obtaining a copy of this software and associated documentation
|
|
20 |
files (the 'Software'), to deal in the Software without
|
|
21 |
restriction, including without limitation the rights to use,
|
|
22 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23 |
copies of the Software, and to permit persons to whom the
|
|
24 |
Software is furnished to do so, subject to the following
|
|
25 |
conditions:
|
|
26 |
|
|
27 |
The above copyright notice and this permission notice shall be
|
|
28 |
included in all copies or substantial portions of the Software.
|
|
29 |
|
|
30 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
31 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
32 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
33 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
34 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
35 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
36 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
37 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
38 |
|
|
39 |
[1] Code written at SWING Research Group contain a signature
|
|
40 |
of one of the above copright owners.
|
|
41 |
"
|
|
42 |
"{ Package: 'stx:libjava' }"
|
|
43 |
|
|
44 |
JavaByteCodeProcessorTests subclass:#JavaByteCodeInterpreterTests
|
|
45 |
instanceVariableNames:''
|
|
46 |
classVariableNames:''
|
|
47 |
poolDictionaries:''
|
|
48 |
category:'Languages-Java-Tests'
|
|
49 |
!
|
|
50 |
|
|
51 |
!JavaByteCodeInterpreterTests class methodsFor:'documentation'!
|
|
52 |
|
|
53 |
copyright
|
|
54 |
"
|
|
55 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
|
56 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
57 |
SWING Research Group, Czech Technical University in Prague
|
|
58 |
|
|
59 |
Parts of the code written by Claus Gittinger are under following
|
|
60 |
license:
|
|
61 |
|
|
62 |
This software is furnished under a license and may be used
|
|
63 |
only in accordance with the terms of that license and with the
|
|
64 |
inclusion of the above copyright notice. This software may not
|
|
65 |
be provided or otherwise made available to, or used by, any
|
|
66 |
other person. No title to or ownership of the software is
|
|
67 |
hereby transferred.
|
|
68 |
|
|
69 |
Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
|
|
70 |
|
|
71 |
Permission is hereby granted, free of charge, to any person
|
|
72 |
obtaining a copy of this software and associated documentation
|
|
73 |
files (the 'Software'), to deal in the Software without
|
|
74 |
restriction, including without limitation the rights to use,
|
|
75 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
76 |
copies of the Software, and to permit persons to whom the
|
|
77 |
Software is furnished to do so, subject to the following
|
|
78 |
conditions:
|
|
79 |
|
|
80 |
The above copyright notice and this permission notice shall be
|
|
81 |
included in all copies or substantial portions of the Software.
|
|
82 |
|
|
83 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
84 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
85 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
86 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
87 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
88 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
89 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
90 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
91 |
|
|
92 |
[1] Code written at SWING Research Group contain a signature
|
|
93 |
of one of the above copright owners.
|
|
94 |
|
|
95 |
"
|
|
96 |
! !
|
|
97 |
|
|
98 |
!JavaByteCodeInterpreterTests class methodsFor:'resources'!
|
|
99 |
|
|
100 |
resources
|
|
101 |
|
|
102 |
^ Array with: JavaInitializedResource with: JavaTestsResource.
|
|
103 |
|
|
104 |
"Created: / 15-03-2011 / 17:29:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
105 |
"Modified: / 16-03-2011 / 14:43:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
106 |
! !
|
|
107 |
|
|
108 |
!JavaByteCodeInterpreterTests methodsFor:'tests'!
|
|
109 |
|
|
110 |
testAnd
|
|
111 |
| result expResult |
|
|
112 |
|
|
113 |
expResult := 2r10010101.
|
|
114 |
result := self
|
|
115 |
invoke: #'and(II)I'
|
|
116 |
class: self loadSimpleMathJavaClass
|
|
117 |
args: #( 255 149 ).
|
|
118 |
self assertTrue: expResult = result.
|
|
119 |
|
|
120 |
"static method
|
|
121 |
|
|
122 |
0 iload_0
|
|
123 |
1 iload_1
|
|
124 |
2 iand
|
|
125 |
3 ireturn"
|
|
126 |
|
|
127 |
"Created: / 14-03-2011 / 17:02:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
128 |
"Modified: / 16-03-2011 / 21:49:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
129 |
!
|
|
130 |
|
|
131 |
testBitShiftLeft
|
|
132 |
| result expResult |
|
|
133 |
|
|
134 |
expResult := 2r101010000.
|
|
135 |
result := self
|
|
136 |
invoke: #'bitShiftLeft(II)I'
|
|
137 |
class: self loadSimpleMathJavaClass
|
|
138 |
args: #( 21 4 ).
|
|
139 |
self assertTrue: expResult = result.
|
|
140 |
|
|
141 |
"static method
|
|
142 |
|
|
143 |
0 iload_0
|
|
144 |
1 iload_1
|
|
145 |
2 ishl
|
|
146 |
3 ireturn"
|
|
147 |
|
|
148 |
"Created: / 14-03-2011 / 16:56:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
149 |
"Modified: / 16-03-2011 / 21:49:29 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
150 |
!
|
|
151 |
|
|
152 |
testBitShiftRight
|
|
153 |
| result expResult |
|
|
154 |
|
|
155 |
expResult := 2r11011.
|
|
156 |
result := self
|
|
157 |
invoke: #'bitShiftRight(II)I'
|
|
158 |
class: self loadSimpleMathJavaClass
|
|
159 |
args: #( 439 4 ).
|
|
160 |
self assertTrue: expResult = result.
|
|
161 |
|
|
162 |
"static method
|
|
163 |
|
|
164 |
0 iload_0
|
|
165 |
1 iload_1
|
|
166 |
2 ishr
|
|
167 |
3 ireturn"
|
|
168 |
|
|
169 |
"Created: / 14-03-2011 / 16:57:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
170 |
"Modified: / 16-03-2011 / 21:49:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
171 |
!
|
|
172 |
|
|
173 |
testDec2
|
|
174 |
| result expResult |
|
|
175 |
|
|
176 |
expResult := 1.
|
|
177 |
result := self
|
|
178 |
invoke: #'dec2(I)I'
|
|
179 |
class: self loadSimpleMathJavaClass
|
|
180 |
args: #( 3 ).
|
|
181 |
self assertTrue: expResult = result.
|
|
182 |
|
|
183 |
"static method
|
|
184 |
|
|
185 |
0 iinc 0 -1
|
|
186 |
3 iinc 0 -1
|
|
187 |
6 iload_0
|
|
188 |
7 ireturn"
|
|
189 |
|
|
190 |
"Created: / 14-03-2011 / 16:58:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
191 |
"Modified: / 16-03-2011 / 21:49:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
192 |
!
|
|
193 |
|
|
194 |
testDiv
|
|
195 |
| result expResult |
|
|
196 |
|
|
197 |
expResult := 1.
|
|
198 |
result := self
|
|
199 |
invoke: #'div(II)I'
|
|
200 |
class: self loadSimpleMathJavaClass
|
|
201 |
args: #( 101 10 ).
|
|
202 |
self assertTrue: expResult = result.
|
|
203 |
|
|
204 |
"static method
|
|
205 |
|
|
206 |
0 iload_0
|
|
207 |
1 iload_1
|
|
208 |
2 irem
|
|
209 |
3 ireturn"
|
|
210 |
|
|
211 |
"Created: / 14-03-2011 / 16:54:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
212 |
"Modified: / 16-03-2011 / 21:49:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
213 |
!
|
|
214 |
|
|
215 |
testDivision
|
|
216 |
| result expResult |
|
|
217 |
|
|
218 |
expResult := 10.
|
|
219 |
result := self
|
|
220 |
invoke: #'division(II)I'
|
|
221 |
class: self loadSimpleMathJavaClass
|
|
222 |
args: #( 101 10 ).
|
|
223 |
self assertTrue: expResult = result.
|
|
224 |
|
|
225 |
"static method
|
|
226 |
|
|
227 |
0 iload_0
|
|
228 |
1 iload_1
|
|
229 |
2 idiv
|
|
230 |
3 ireturn"
|
|
231 |
|
|
232 |
"Created: / 14-03-2011 / 16:57:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
233 |
"Modified: / 16-03-2011 / 21:48:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
234 |
!
|
|
235 |
|
|
236 |
testInc2
|
|
237 |
| result expResult |
|
|
238 |
|
|
239 |
expResult := 5.
|
|
240 |
result := self
|
|
241 |
invoke: #'inc2(I)I'
|
|
242 |
class: self loadSimpleMathJavaClass
|
|
243 |
args: #( 3 ).
|
|
244 |
self assertTrue: expResult = result.
|
|
245 |
|
|
246 |
"static method
|
|
247 |
|
|
248 |
0 iinc 0 1
|
|
249 |
3 iinc 0 1
|
|
250 |
6 iload_0
|
|
251 |
7 ireturn"
|
|
252 |
|
|
253 |
"Created: / 14-03-2011 / 16:58:00 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
254 |
"Modified: / 16-03-2011 / 21:48:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
255 |
!
|
|
256 |
|
|
257 |
testInheritedMethodCall
|
|
258 |
| result |
|
|
259 |
|
|
260 |
self shouldnt:
|
|
261 |
[ result := self
|
|
262 |
invoke: #'foo()Ljava/lang/String;'
|
|
263 |
class: self loadSimpleInheritingJavaClass
|
|
264 |
args: nil. ]
|
|
265 |
raise: Error.
|
|
266 |
self assertFalse: (result isNil).
|
|
267 |
"0 ldc1 2 ['foo']
|
|
268 |
2 areturn "
|
|
269 |
|
|
270 |
"Created: / 14-03-2011 / 16:21:04 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
271 |
"Modified: / 16-03-2011 / 21:47:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
272 |
!
|
|
273 |
|
|
274 |
testJustLoadConstants
|
|
275 |
"/self shouldnt:
|
|
276 |
|
|
277 |
|
|
278 |
[ self
|
|
279 |
invoke: #'justUseConstants()V'
|
|
280 |
class: self loadSimpleMathJavaClass
|
|
281 |
args: #(). ] value.
|
|
282 |
|
|
283 |
"static method
|
|
284 |
|
|
285 |
0 lconst_0
|
|
286 |
1 lstore_0
|
|
287 |
2 lconst_1
|
|
288 |
3 lstore_2
|
|
289 |
4 fconst_0
|
|
290 |
5 fstore 4
|
|
291 |
7 fconst_1
|
|
292 |
8 fstore 5
|
|
293 |
10 fconst_2
|
|
294 |
11 fstore 6
|
|
295 |
13 dconst_0
|
|
296 |
14 dstore 7
|
|
297 |
16 dconst_1
|
|
298 |
17 dstore 9
|
|
299 |
19 return"
|
|
300 |
|
|
301 |
"Created: / 14-03-2011 / 17:05:22 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
302 |
"Modified: / 16-03-2011 / 21:48:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
303 |
!
|
|
304 |
|
|
305 |
testMultipy
|
|
306 |
| result expResult |
|
|
307 |
|
|
308 |
expResult := 200.
|
|
309 |
result := self
|
|
310 |
invoke: #'multiply(II)I'
|
|
311 |
class: self loadSimpleMathJavaClass
|
|
312 |
args: (Array with: 20 with: 10).
|
|
313 |
self assertTrue: expResult = result.
|
|
314 |
"static method
|
|
315 |
|
|
316 |
0 iload_0
|
|
317 |
1 iload_1
|
|
318 |
2 imul
|
|
319 |
3 ireturn "
|
|
320 |
|
|
321 |
"Created: / 06-03-2011 / 14:17:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
322 |
"Modified: / 16-03-2011 / 21:50:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
323 |
!
|
|
324 |
|
|
325 |
testNegateInt
|
|
326 |
| result expResult |
|
|
327 |
|
|
328 |
expResult := -56.
|
|
329 |
result := self
|
|
330 |
invoke: #'negateInt(I)I'
|
|
331 |
class: self loadSimpleMathJavaClass
|
|
332 |
args: #( 55 ).
|
|
333 |
self assertTrue: expResult = result.
|
|
334 |
"0 iload_0
|
|
335 |
1 iconst_m1
|
|
336 |
2 ixor
|
|
337 |
3 ireturn "
|
|
338 |
|
|
339 |
"Created: / 14-03-2011 / 16:55:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
340 |
"Modified: / 16-03-2011 / 21:50:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
341 |
!
|
|
342 |
|
|
343 |
testOr
|
|
344 |
| result expResult |
|
|
345 |
|
|
346 |
expResult := 119.
|
|
347 |
result := self
|
|
348 |
invoke: #'or(II)I'
|
|
349 |
class: self loadSimpleMathJavaClass
|
|
350 |
args: #( 55 66 ).
|
|
351 |
self assertTrue: expResult = result.
|
|
352 |
"0 iload_0
|
|
353 |
1 iload_1
|
|
354 |
2 ior
|
|
355 |
3 ireturn "
|
|
356 |
|
|
357 |
"Created: / 14-03-2011 / 17:02:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
358 |
"Modified: / 16-03-2011 / 21:50:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
359 |
!
|
|
360 |
|
|
361 |
testOverridenMethodCall
|
|
362 |
| result |
|
|
363 |
|
|
364 |
self shouldnt:
|
|
365 |
[ result := self
|
|
366 |
invoke: #'bar()Ljava/lang/String;'
|
|
367 |
class: self loadSimpleInheritingJavaClass
|
|
368 |
args: nil. ]
|
|
369 |
raise: Error.
|
|
370 |
self assertFalse: (result isNil).
|
|
371 |
"0 ldc1 2 ['bar']
|
|
372 |
2 areturn "
|
|
373 |
|
|
374 |
"Modified: / 16-03-2011 / 21:51:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
375 |
!
|
|
376 |
|
|
377 |
testPower
|
|
378 |
| result expResult |
|
|
379 |
|
|
380 |
expResult := 1024.
|
|
381 |
result := self
|
|
382 |
invoke: #'power(II)I'
|
|
383 |
class: self loadSimpleMathJavaClass
|
|
384 |
args: (Array with: 2 with: 10).
|
|
385 |
self assertTrue: expResult = result.
|
|
386 |
"0 iload_0
|
|
387 |
1 iload_1
|
|
388 |
2 iconst_1
|
|
389 |
3 invokestatic 2 [JavaMethod(stx.libjava.tests.simpleClasses.SimpleMath::int powerAcc (int int int))]
|
|
390 |
6 ireturn "
|
|
391 |
|
|
392 |
"Created: / 06-03-2011 / 14:18:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
393 |
"Modified: / 16-03-2011 / 21:51:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
394 |
!
|
|
395 |
|
|
396 |
testReturnArrayOfLongs
|
|
397 |
| result |
|
|
398 |
|
|
399 |
self shouldnt:
|
|
400 |
[ result := self
|
|
401 |
invoke: #'giveMeArrayOfLongs()[J'
|
|
402 |
class: self loadSimpleMathJavaClass
|
|
403 |
args: #(). ]
|
|
404 |
raise: Error.
|
|
405 |
"0 bipush 100
|
|
406 |
2 newarray 11 [T_LONG]
|
|
407 |
4 areturn "
|
|
408 |
|
|
409 |
"Created: / 14-03-2011 / 17:08:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
410 |
"Modified: / 16-03-2011 / 21:52:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
411 |
!
|
|
412 |
|
|
413 |
testSetterAndGettersDouble
|
|
414 |
| result expResult crate |
|
|
415 |
|
|
416 |
crate := self loadCrateJavaClass new.
|
|
417 |
expResult := 1234.45.
|
|
418 |
self
|
|
419 |
invoke: #'setDoubleVar(D)V'
|
|
420 |
class: crate class
|
|
421 |
receiver: crate
|
|
422 |
args: (Array with: 1234.45).
|
|
423 |
result := self
|
|
424 |
invoke: #'getDoubleVar()D'
|
|
425 |
class: crate class
|
|
426 |
receiver: crate
|
|
427 |
args: nil.
|
|
428 |
self assert: (expResult = result).
|
|
429 |
|
|
430 |
"setDoubleVar:
|
|
431 |
0 aload_0
|
|
432 |
1 dload_1
|
|
433 |
2 putfield 3
|
|
434 |
5 return
|
|
435 |
|
|
436 |
getDoubleVar:
|
|
437 |
0 aload_0
|
|
438 |
1 getfield 3
|
|
439 |
4 dreturn"
|
|
440 |
|
|
441 |
"Created: / 13-03-2011 / 17:43:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
442 |
"Modified: / 16-03-2011 / 21:54:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
443 |
!
|
|
444 |
|
|
445 |
testSetterAndGettersDoubleMaxValue
|
|
446 |
| result expResult crate |
|
|
447 |
|
|
448 |
crate := self loadCrateJavaClass new.
|
|
449 |
expResult := 1.79769313486232E+308.
|
|
450 |
self
|
|
451 |
invoke: #'setDoubleVar(D)V'
|
|
452 |
class: crate class
|
|
453 |
receiver: crate
|
|
454 |
args: (Array with: 1.79769313486232E+308).
|
|
455 |
result := self
|
|
456 |
invoke: #'getDoubleVar()D'
|
|
457 |
class: crate class
|
|
458 |
receiver: crate
|
|
459 |
args: nil.
|
|
460 |
self assert: (expResult = result).
|
|
461 |
|
|
462 |
"setDoubleVar:
|
|
463 |
0 aload_0
|
|
464 |
1 dload_1
|
|
465 |
2 putfield 3
|
|
466 |
5 return
|
|
467 |
|
|
468 |
getDoubleVar:
|
|
469 |
0 aload_0
|
|
470 |
1 getfield 3
|
|
471 |
4 dreturn"
|
|
472 |
|
|
473 |
"Created: / 14-03-2011 / 14:06:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
474 |
"Modified: / 16-03-2011 / 21:53:59 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
475 |
!
|
|
476 |
|
|
477 |
testSetterAndGettersDoubleMinValue
|
|
478 |
| result expResult crate |
|
|
479 |
|
|
480 |
crate := self loadCrateJavaClass new.
|
|
481 |
expResult := 4.94065645841247E-324.
|
|
482 |
self
|
|
483 |
invoke: #'setDoubleVar(D)V'
|
|
484 |
class: crate class
|
|
485 |
receiver: crate
|
|
486 |
args: (Array with: 4.94065645841247E-324).
|
|
487 |
result := self
|
|
488 |
invoke: #'getDoubleVar()D'
|
|
489 |
class: crate class
|
|
490 |
receiver: crate
|
|
491 |
args: nil.
|
|
492 |
self assert: (expResult = result).
|
|
493 |
"setDoubleVar:
|
|
494 |
0 aload_0
|
|
495 |
1 dload_1
|
|
496 |
2 putfield 3
|
|
497 |
5 return
|
|
498 |
|
|
499 |
getDoubleVar:
|
|
500 |
0 aload_0
|
|
501 |
1 getfield 3
|
|
502 |
4 dreturn"
|
|
503 |
|
|
504 |
"Created: / 14-03-2011 / 14:06:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
505 |
"Modified: / 16-03-2011 / 21:54:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
506 |
!
|
|
507 |
|
|
508 |
testSetterAndGettersDoubleNan
|
|
509 |
| result crate |
|
|
510 |
|
|
511 |
crate := self loadCrateJavaClass new.
|
|
512 |
self
|
|
513 |
invoke: #'setDoubleVar(D)V'
|
|
514 |
class: crate class
|
|
515 |
receiver: crate
|
|
516 |
args: (Array with: Float nan).
|
|
517 |
result := self
|
|
518 |
invoke: #'getDoubleVar()D'
|
|
519 |
class: crate class
|
|
520 |
receiver: crate
|
|
521 |
args: nil.
|
|
522 |
self assert: (result isNaN).
|
|
523 |
"setDoubleVar:
|
|
524 |
0 aload_0
|
|
525 |
1 dload_1
|
|
526 |
2 putfield 3
|
|
527 |
5 return
|
|
528 |
|
|
529 |
getDoubleVar:
|
|
530 |
0 aload_0
|
|
531 |
1 getfield 3
|
|
532 |
4 dreturn"
|
|
533 |
|
|
534 |
"Created: / 14-03-2011 / 14:07:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
535 |
"Modified: / 16-03-2011 / 21:54:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
536 |
!
|
|
537 |
|
|
538 |
testSetterAndGettersDoubleWithInfinityArg
|
|
539 |
| result expResult crate |
|
|
540 |
|
|
541 |
crate := self loadCrateJavaClass new.
|
|
542 |
expResult := Float infinity.
|
|
543 |
self
|
|
544 |
invoke: #'setDoubleVar(D)V'
|
|
545 |
class: crate class
|
|
546 |
receiver: crate
|
|
547 |
args: (Array with: Float infinity).
|
|
548 |
result := self
|
|
549 |
invoke: #'getDoubleVar()D'
|
|
550 |
class: crate class
|
|
551 |
receiver: crate
|
|
552 |
args: nil.
|
|
553 |
self assert: (expResult = result).
|
|
554 |
"setDoubleVar:
|
|
555 |
0 aload_0
|
|
556 |
1 dload_1
|
|
557 |
2 putfield 3
|
|
558 |
5 return
|
|
559 |
|
|
560 |
getDoubleVar:
|
|
561 |
0 aload_0
|
|
562 |
1 getfield 3
|
|
563 |
4 dreturn"
|
|
564 |
|
|
565 |
"Created: / 14-03-2011 / 13:52:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
566 |
"Modified: / 16-03-2011 / 21:54:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
567 |
!
|
|
568 |
|
|
569 |
testSetterAndGettersDoubleWithNegativeInfinityArg
|
|
570 |
| result expResult crate |
|
|
571 |
|
|
572 |
crate := self loadCrateJavaClass new.
|
|
573 |
expResult := Float negativeInfinity.
|
|
574 |
self
|
|
575 |
invoke: #'setDoubleVar(D)V'
|
|
576 |
class: crate class
|
|
577 |
receiver: crate
|
|
578 |
args: (Array with: Float negativeInfinity).
|
|
579 |
result := self
|
|
580 |
invoke: #'getDoubleVar()D'
|
|
581 |
class: crate class
|
|
582 |
receiver: crate
|
|
583 |
args: nil.
|
|
584 |
self assert: (expResult = result).
|
|
585 |
"setDoubleVar:
|
|
586 |
0 aload_0
|
|
587 |
1 dload_1
|
|
588 |
2 putfield 3
|
|
589 |
5 return
|
|
590 |
|
|
591 |
getDoubleVar:
|
|
592 |
0 aload_0
|
|
593 |
1 getfield 3
|
|
594 |
4 dreturn"
|
|
595 |
|
|
596 |
"Created: / 14-03-2011 / 13:53:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
597 |
"Modified: / 16-03-2011 / 21:54:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
598 |
!
|
|
599 |
|
|
600 |
testSetterAndGettersInt
|
|
601 |
| result expResult crate |
|
|
602 |
|
|
603 |
crate := self loadCrateJavaClass new.
|
|
604 |
expResult := 1234.
|
|
605 |
self
|
|
606 |
invoke: #'setIntVar(I)V'
|
|
607 |
class: crate class
|
|
608 |
receiver: crate
|
|
609 |
args: (Array with: 1234).
|
|
610 |
result := self
|
|
611 |
invoke: #'getIntVar()I'
|
|
612 |
class: crate class
|
|
613 |
receiver: crate
|
|
614 |
args: nil.
|
|
615 |
self assert: (expResult = result).
|
|
616 |
"setIntVar:
|
|
617 |
0 aload_0
|
|
618 |
1 iload_1
|
|
619 |
2 putfield 2 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'intVar'I offs=1)]
|
|
620 |
5 return
|
|
621 |
|
|
622 |
getIntVar:
|
|
623 |
0 aload_0
|
|
624 |
1 getfield 2 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'intVar'I offs=1)]
|
|
625 |
4 ireturn"
|
|
626 |
|
|
627 |
"Created: / 13-03-2011 / 17:42:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
628 |
"Modified: / 16-03-2011 / 21:55:34 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
629 |
!
|
|
630 |
|
|
631 |
testSetterAndGettersIntMaxValue
|
|
632 |
| result expResult crate |
|
|
633 |
|
|
634 |
crate := self loadCrateJavaClass new.
|
|
635 |
expResult := 2147483647.
|
|
636 |
self
|
|
637 |
invoke: #'setIntVar(I)V'
|
|
638 |
class: crate class
|
|
639 |
receiver: crate
|
|
640 |
args: (Array with: 2147483647).
|
|
641 |
result := self
|
|
642 |
invoke: #'getIntVar()I'
|
|
643 |
class: crate class
|
|
644 |
receiver: crate
|
|
645 |
args: nil.
|
|
646 |
self assert: (expResult = result).
|
|
647 |
"setIntVar:
|
|
648 |
0 aload_0
|
|
649 |
1 iload_1
|
|
650 |
2 putfield 2 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'intVar'I offs=1)]
|
|
651 |
5 return
|
|
652 |
|
|
653 |
getIntVar:
|
|
654 |
0 aload_0
|
|
655 |
1 getfield 2 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'intVar'I offs=1)]
|
|
656 |
4 ireturn"
|
|
657 |
|
|
658 |
"Created: / 14-03-2011 / 14:02:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
659 |
"Modified: / 16-03-2011 / 21:55:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
660 |
!
|
|
661 |
|
|
662 |
testSetterAndGettersIntMinValue
|
|
663 |
| result expResult crate |
|
|
664 |
|
|
665 |
crate := self loadCrateJavaClass new.
|
|
666 |
expResult := -2147483648.
|
|
667 |
self
|
|
668 |
invoke: #'setIntVar(I)V'
|
|
669 |
class: crate class
|
|
670 |
receiver: crate
|
|
671 |
args: (Array with: -2147483648).
|
|
672 |
result := self
|
|
673 |
invoke: #'getIntVar()I'
|
|
674 |
class: crate class
|
|
675 |
receiver: crate
|
|
676 |
args: nil.
|
|
677 |
self assert: (expResult = result).
|
|
678 |
"setIntVar:
|
|
679 |
0 aload_0
|
|
680 |
1 iload_1
|
|
681 |
2 putfield 2 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'intVar'I offs=1)]
|
|
682 |
5 return
|
|
683 |
|
|
684 |
getIntVar:
|
|
685 |
0 aload_0
|
|
686 |
1 getfield 2 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'intVar'I offs=1)]
|
|
687 |
4 ireturn"
|
|
688 |
|
|
689 |
"Created: / 14-03-2011 / 14:01:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
690 |
"Modified: / 16-03-2011 / 21:55:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
691 |
!
|
|
692 |
|
|
693 |
testSetterAndGettersLong
|
|
694 |
| result expResult crate |
|
|
695 |
|
|
696 |
crate := self loadCrateJavaClass new.
|
|
697 |
expResult := 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.
|
|
698 |
self
|
|
699 |
invoke: #'setLongVar(J)V'
|
|
700 |
class: crate class
|
|
701 |
receiver: crate
|
|
702 |
args: (Array
|
|
703 |
with: 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890).
|
|
704 |
result := self
|
|
705 |
invoke: #'getLongVar()J'
|
|
706 |
class: crate class
|
|
707 |
receiver: crate
|
|
708 |
args: nil.
|
|
709 |
self assert: (expResult = result).
|
|
710 |
|
|
711 |
"setLongVar:
|
|
712 |
0 aload_0
|
|
713 |
1 lload_1
|
|
714 |
2 putfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
715 |
5 return
|
|
716 |
|
|
717 |
getLongVar:
|
|
718 |
0 aload_0
|
|
719 |
1 getfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
720 |
4 lreturn"
|
|
721 |
|
|
722 |
"Created: / 14-03-2011 / 13:36:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
723 |
"Modified: / 16-03-2011 / 21:56:38 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
724 |
!
|
|
725 |
|
|
726 |
testSetterAndGettersLongMaxValue
|
|
727 |
| result expResult crate |
|
|
728 |
|
|
729 |
crate := self loadCrateJavaClass new.
|
|
730 |
expResult := 9223372036854775807.
|
|
731 |
self
|
|
732 |
invoke: #'setLongVar(J)V'
|
|
733 |
class: crate class
|
|
734 |
receiver: crate
|
|
735 |
args: (Array with: 9223372036854775807).
|
|
736 |
result := self
|
|
737 |
invoke: #'getLongVar()J'
|
|
738 |
class: crate class
|
|
739 |
receiver: crate
|
|
740 |
args: nil.
|
|
741 |
self assert: (expResult = result).
|
|
742 |
"setLongVar:
|
|
743 |
0 aload_0
|
|
744 |
1 lload_1
|
|
745 |
2 putfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
746 |
5 return
|
|
747 |
|
|
748 |
getLongVar:
|
|
749 |
0 aload_0
|
|
750 |
1 getfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
751 |
4 lreturn"
|
|
752 |
|
|
753 |
"Created: / 14-03-2011 / 14:04:53 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
754 |
"Modified: / 16-03-2011 / 21:56:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
755 |
!
|
|
756 |
|
|
757 |
testSetterAndGettersLongMinValue
|
|
758 |
| result expResult crate |
|
|
759 |
|
|
760 |
crate := self loadCrateJavaClass new.
|
|
761 |
expResult := -9223372036854775808.
|
|
762 |
self
|
|
763 |
invoke: #'setLongVar(J)V'
|
|
764 |
class: crate class
|
|
765 |
receiver: crate
|
|
766 |
args: (Array with: -9223372036854775808).
|
|
767 |
result := self
|
|
768 |
invoke: #'getLongVar()J'
|
|
769 |
class: crate class
|
|
770 |
receiver: crate
|
|
771 |
args: nil.
|
|
772 |
self assert: (expResult = result).
|
|
773 |
"setLongVar:
|
|
774 |
0 aload_0
|
|
775 |
1 lload_1
|
|
776 |
2 putfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
777 |
5 return
|
|
778 |
|
|
779 |
getLongVar:
|
|
780 |
0 aload_0
|
|
781 |
1 getfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
782 |
4 lreturn"
|
|
783 |
|
|
784 |
"Created: / 14-03-2011 / 14:04:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
785 |
"Modified: / 16-03-2011 / 21:56:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
786 |
!
|
|
787 |
|
|
788 |
testSetterAndGettersLongWithIntArg
|
|
789 |
| result expResult crate |
|
|
790 |
|
|
791 |
crate := self loadCrateJavaClass new.
|
|
792 |
expResult := 12.
|
|
793 |
self
|
|
794 |
invoke: #'setLongVar(J)V'
|
|
795 |
class: crate class
|
|
796 |
receiver: crate
|
|
797 |
args: (Array with: 12).
|
|
798 |
result := self
|
|
799 |
invoke: #'getLongVar()J'
|
|
800 |
class: crate class
|
|
801 |
receiver: crate
|
|
802 |
args: nil.
|
|
803 |
self assert: (expResult = result).
|
|
804 |
"setLongVar:
|
|
805 |
0 aload_0
|
|
806 |
1 lload_1
|
|
807 |
2 putfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
808 |
5 return
|
|
809 |
|
|
810 |
getLongVar:
|
|
811 |
0 aload_0
|
|
812 |
1 getfield 4 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'longVar'J offs=3)]
|
|
813 |
4 lreturn"
|
|
814 |
|
|
815 |
"Created: / 14-03-2011 / 13:49:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
816 |
"Modified: / 16-03-2011 / 21:56:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
817 |
!
|
|
818 |
|
|
819 |
testSetterAndGettersString
|
|
820 |
| result expResult crate |
|
|
821 |
|
|
822 |
crate := self loadCrateJavaClass new.
|
|
823 |
expResult := 'hello world'.
|
|
824 |
self
|
|
825 |
invoke: #'setStringVar(Ljava/lang/String;)V'
|
|
826 |
class: crate class
|
|
827 |
receiver: crate
|
|
828 |
args: (Array with: 'hello world').
|
|
829 |
result := self
|
|
830 |
invoke: #'getStringVar()Ljava/lang/String;'
|
|
831 |
class: crate class
|
|
832 |
receiver: crate
|
|
833 |
args: nil.
|
|
834 |
self assert: (expResult = result).
|
|
835 |
"setString:
|
|
836 |
0 aload_0
|
|
837 |
1 aload_1
|
|
838 |
2 putfield 5 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'stringVar'Ljava/lang/String; offs=4)]
|
|
839 |
5 return
|
|
840 |
|
|
841 |
getString:
|
|
842 |
0 aload_0
|
|
843 |
1 getfield 5 [JavaFieldRef (stx.libjava.tests.simpleClasses.Crate 'stringVar'Ljava/lang/String; offs=4)]
|
|
844 |
4 areturn "
|
|
845 |
|
|
846 |
"Created: / 14-03-2011 / 13:45:57 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
847 |
"Modified: / 16-03-2011 / 21:57:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
848 |
!
|
|
849 |
|
|
850 |
testSimpleAdd
|
|
851 |
| result expResult |
|
|
852 |
|
|
853 |
expResult := 2002.
|
|
854 |
result := self
|
|
855 |
invoke: #'add2To2000Expect2002()I'
|
|
856 |
class: self loadSimpleMathJavaClass
|
|
857 |
args: nil.
|
|
858 |
self assertTrue: expResult = result.
|
|
859 |
|
|
860 |
"static method
|
|
861 |
|
|
862 |
0 iconst_2
|
|
863 |
1 istore_0
|
|
864 |
2 sipush 2000
|
|
865 |
5 istore_1
|
|
866 |
6 iload_0
|
|
867 |
7 iload_1
|
|
868 |
8 iadd
|
|
869 |
9 istore_2
|
|
870 |
10 iload_2
|
|
871 |
11 ireturn"
|
|
872 |
|
|
873 |
"Created: / 06-03-2011 / 14:18:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
874 |
"Modified: / 16-03-2011 / 21:57:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
875 |
!
|
|
876 |
|
|
877 |
testSimpleAdd2
|
|
878 |
| result expResult |
|
|
879 |
|
|
880 |
expResult := 5.
|
|
881 |
result := self
|
|
882 |
invoke: #'addMinus5ToArg(I)I'
|
|
883 |
class: self loadSimpleMathJavaClass
|
|
884 |
args: (Array with: 10).
|
|
885 |
self assertTrue: expResult = result.
|
|
886 |
|
|
887 |
"static method
|
|
888 |
|
|
889 |
0 iload_0
|
|
890 |
1 bipush -5
|
|
891 |
3 iadd
|
|
892 |
4 ireturn"
|
|
893 |
|
|
894 |
"Created: / 06-03-2011 / 14:18:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
895 |
"Modified: / 16-03-2011 / 21:59:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
896 |
!
|
|
897 |
|
|
898 |
testStackCreation
|
|
899 |
| result expResult |
|
|
900 |
|
|
901 |
expResult := 7.
|
|
902 |
result := self
|
|
903 |
invoke: #'isYourStackCreatedCorrectly()I'
|
|
904 |
class: self loadSimpleMathJavaClass
|
|
905 |
args: #().
|
|
906 |
self assertTrue: expResult = result.
|
|
907 |
|
|
908 |
"0 iconst_0
|
|
909 |
1 istore_0
|
|
910 |
2 iconst_1
|
|
911 |
3 istore_1
|
|
912 |
4 iconst_2
|
|
913 |
5 istore_0
|
|
914 |
6 iconst_3
|
|
915 |
7 istore_1
|
|
916 |
8 iconst_4
|
|
917 |
9 istore_0
|
|
918 |
10 iconst_5
|
|
919 |
11 istore_0
|
|
920 |
12 bipush 6
|
|
921 |
14 istore_1
|
|
922 |
15 bipush 7
|
|
923 |
17 istore_0
|
|
924 |
18 bipush 8
|
|
925 |
20 istore_1
|
|
926 |
21 bipush 9
|
|
927 |
23 istore_1
|
|
928 |
24 iload_0
|
|
929 |
25 ireturn"
|
|
930 |
|
|
931 |
"Created: / 14-03-2011 / 17:03:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
932 |
"Modified: / 16-03-2011 / 21:59:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
933 |
!
|
|
934 |
|
|
935 |
testSumArray
|
|
936 |
| result expResult |
|
|
937 |
|
|
938 |
expResult := 15.
|
|
939 |
result := self
|
|
940 |
invoke: #'sumArray([I)I'
|
|
941 |
class: self loadSimpleMathJavaClass
|
|
942 |
args: #( #(1 2 3 4 5) ).
|
|
943 |
self assertTrue: expResult = result.
|
|
944 |
|
|
945 |
"
|
|
946 |
Decompiled source:
|
|
947 |
Static method
|
|
948 |
0 iconst_0
|
|
949 |
1 istore_1
|
|
950 |
2 iconst_0
|
|
951 |
3 istore_2
|
|
952 |
4 iload_2
|
|
953 |
5 aload_0
|
|
954 |
6 arraylength
|
|
955 |
7 if_icmpge 15 [22]
|
|
956 |
10 iload_1
|
|
957 |
11 aload_0
|
|
958 |
12 iload_2
|
|
959 |
13 iaload
|
|
960 |
14 iadd
|
|
961 |
15 istore_1
|
|
962 |
16 iinc 2 1
|
|
963 |
19 goto -15 [4]
|
|
964 |
22 iload_1
|
|
965 |
23 ireturn"
|
|
966 |
|
|
967 |
"Created: / 14-03-2011 / 17:06:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
968 |
"Modified: / 16-03-2011 / 21:58:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
969 |
!
|
|
970 |
|
|
971 |
testSumArrayOfDoubles
|
|
972 |
| result expResult |
|
|
973 |
|
|
974 |
expResult := 16.5.
|
|
975 |
result := self
|
|
976 |
invoke: #'sumArrayOfDoubles([D)D'
|
|
977 |
class: self loadSimpleMathJavaClass
|
|
978 |
args: #( #(1.1 2.2 3.3 4.4 5.5) ).
|
|
979 |
self assertTrue: expResult = result.
|
|
980 |
"0 dconst_0
|
|
981 |
1 dstore_1
|
|
982 |
2 iconst_0
|
|
983 |
3 istore_3
|
|
984 |
4 iload_3
|
|
985 |
5 aload_0
|
|
986 |
6 arraylength
|
|
987 |
7 if_icmpge 15 [22]
|
|
988 |
10 dload_1
|
|
989 |
11 aload_0
|
|
990 |
12 iload_3
|
|
991 |
13 daload
|
|
992 |
14 dadd
|
|
993 |
15 dstore_1
|
|
994 |
16 iinc 3 1
|
|
995 |
19 goto -15 [4]
|
|
996 |
22 dload_1
|
|
997 |
23 dreturn "
|
|
998 |
|
|
999 |
"Created: / 14-03-2011 / 17:07:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1000 |
"Modified: / 16-03-2011 / 21:59:03 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1001 |
!
|
|
1002 |
|
|
1003 |
testUnsignedBitShiftLeft
|
|
1004 |
| result expResult |
|
|
1005 |
|
|
1006 |
expResult := 1234 bitShift: 5.
|
|
1007 |
result := self
|
|
1008 |
invoke: #'unsignedBitShiftRight(II)I'
|
|
1009 |
class: self loadSimpleMathJavaClass
|
|
1010 |
args: #( 1234 5 ).
|
|
1011 |
self assertTrue: expResult = result.
|
|
1012 |
"0 iload_0
|
|
1013 |
1 iload_1
|
|
1014 |
2 iushr
|
|
1015 |
3 ireturn"
|
|
1016 |
|
|
1017 |
"Created: / 14-03-2011 / 17:01:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1018 |
"Modified: / 16-03-2011 / 21:59:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1019 |
!
|
|
1020 |
|
|
1021 |
testXor
|
|
1022 |
| result expResult |
|
|
1023 |
|
|
1024 |
expResult := 1234 bitXor: 5.
|
|
1025 |
result := self
|
|
1026 |
invoke: #'xor(II)I'
|
|
1027 |
class: self loadSimpleMathJavaClass
|
|
1028 |
args: #( 1234 5 ).
|
|
1029 |
self assertTrue: expResult = result.
|
|
1030 |
"0 iload_0
|
|
1031 |
1 iload_1
|
|
1032 |
2 ixor
|
|
1033 |
3 ireturn "
|
|
1034 |
|
|
1035 |
"Modified: / 06-03-2011 / 15:11:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
1036 |
"Created: / 14-03-2011 / 17:02:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1037 |
"Modified: / 16-03-2011 / 21:59:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1038 |
! !
|
|
1039 |
|
|
1040 |
!JavaByteCodeInterpreterTests methodsFor:'tests-helpers'!
|
|
1041 |
|
|
1042 |
invoke: methodName class: aClass receiver: receiver args: args
|
|
1043 |
| method result |
|
|
1044 |
|
|
1045 |
method := aClass lookupMethodFor: methodName.
|
|
1046 |
result := JavaByteCodeInterpreter new
|
|
1047 |
interpret: method
|
|
1048 |
receiver: receiver
|
|
1049 |
arguments: args.
|
|
1050 |
^ result.
|
|
1051 |
|
|
1052 |
"Created: / 10-03-2011 / 23:30:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1053 |
"Modified: / 17-03-2011 / 17:32:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1054 |
! !
|
|
1055 |
|
|
1056 |
!JavaByteCodeInterpreterTests methodsFor:'tests2'!
|
|
1057 |
|
|
1058 |
testGetBoolean
|
|
1059 |
| result expResult inst |
|
|
1060 |
|
|
1061 |
inst := self loadSimpleClassWithManyReferences new.
|
|
1062 |
expResult := 1.
|
|
1063 |
result := self
|
|
1064 |
invoke: #'getBoolean()Z'
|
|
1065 |
class: inst class
|
|
1066 |
receiver: inst
|
|
1067 |
args: nil.
|
|
1068 |
self assertFalse: (result isNil).
|
|
1069 |
self assertTrue: (result = expResult).
|
|
1070 |
|
|
1071 |
"
|
|
1072 |
Deassembling getBoolean
|
|
1073 |
1: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences]
|
|
1074 |
2: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
|
|
1075 |
5: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
|
|
1076 |
7: AALOAD (50) ARGS: [] STACK: [arrayRef, index -> value]
|
|
1077 |
8: CHECKCAST (192) ARGS: [java.lang.Boolean] STACK: [objectRef -> objectRef]
|
|
1078 |
11: INVVIRT (182) ARGS: [JavaMethodRef (java.lang.Boolean 'booleanValue'()Z)] STACK: [objectRef, [arg1, arg2, ...] -> ..]
|
|
1079 |
14: IRETURN (172) ARGS: [] STACK: [value -> EMPTY]"
|
|
1080 |
|
|
1081 |
"Created: / 14-03-2011 / 21:36:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1082 |
"Modified: / 21-03-2011 / 17:45:18 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1083 |
!
|
|
1084 |
|
|
1085 |
testGetByte
|
|
1086 |
| result expResult |
|
|
1087 |
|
|
1088 |
expResult := 11.
|
|
1089 |
result := self
|
|
1090 |
invoke: #'getByte()B'
|
|
1091 |
class: self loadSimpleClassWithManyReferences
|
|
1092 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1093 |
args: nil.
|
|
1094 |
self assertFalse: (result isNil).
|
|
1095 |
self assertTrue: (result = expResult).
|
|
1096 |
"0 aload_0
|
|
1097 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1098 |
4 bipush 7
|
|
1099 |
6 aaload
|
|
1100 |
7 checkcast 17 [java.lang.Byte]
|
|
1101 |
10 invokevirtual 31 [JavaMethodRef (java.lang.Byte 'byteValue'()B)]
|
|
1102 |
13 ireturn "
|
|
1103 |
|
|
1104 |
"Created: / 14-03-2011 / 21:34:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1105 |
"Modified: / 16-03-2011 / 22:04:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1106 |
!
|
|
1107 |
|
|
1108 |
testGetChar
|
|
1109 |
| result expResult |
|
|
1110 |
|
|
1111 |
expResult := 97.
|
|
1112 |
result := self
|
|
1113 |
invoke: #'getChar()C'
|
|
1114 |
class: self loadSimpleClassWithManyReferences
|
|
1115 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1116 |
args: nil.
|
|
1117 |
self assertFalse: (result isNil).
|
|
1118 |
self assertTrue: (result = expResult).
|
|
1119 |
"0 aload_0
|
|
1120 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1121 |
4 iconst_3
|
|
1122 |
5 aaload
|
|
1123 |
6 checkcast 25 [java.lang.Character]
|
|
1124 |
9 invokevirtual 26 [JavaMethodRef (java.lang.Character 'charValue'()C)]
|
|
1125 |
12 ireturn "
|
|
1126 |
|
|
1127 |
"Created: / 14-03-2011 / 21:31:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1128 |
"Modified: / 21-03-2011 / 17:45:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1129 |
!
|
|
1130 |
|
|
1131 |
testGetDateArray
|
|
1132 |
| result expResult |
|
|
1133 |
|
|
1134 |
"again - you're comparing java array with st array - watch out"
|
|
1135 |
"/ expResult := #( nil nil nil ).
|
|
1136 |
result := self
|
|
1137 |
invoke: #'getDateArray()[Ljava/util/Date;'
|
|
1138 |
class: self loadSimpleClassWithManyReferences
|
|
1139 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1140 |
args: nil.
|
|
1141 |
self assertFalse: (result isNil).
|
|
1142 |
"/ self assertTrue: (result = expResult).
|
|
1143 |
"0 aload_0
|
|
1144 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1145 |
4 bipush 8
|
|
1146 |
6 aaload
|
|
1147 |
7 checkcast 32 [UnresolvedClass([Ljava.util.Date;)]
|
|
1148 |
10 checkcast 32 [UnresolvedClass([Ljava.util.Date;)]
|
|
1149 |
13 areturn "
|
|
1150 |
|
|
1151 |
"Created: / 14-03-2011 / 21:35:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1152 |
"Modified: / 21-03-2011 / 17:59:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1153 |
!
|
|
1154 |
|
|
1155 |
testGetDouble
|
|
1156 |
| result |
|
|
1157 |
|
|
1158 |
result := self
|
|
1159 |
invoke: #'getDouble()Ljava/lang/Double;'
|
|
1160 |
class: self loadSimpleClassWithManyReferences
|
|
1161 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1162 |
args: nil.
|
|
1163 |
self assertFalse: (result isNil).
|
|
1164 |
|
|
1165 |
"0 aload_0
|
|
1166 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1167 |
4 iconst_2
|
|
1168 |
5 aaload
|
|
1169 |
6 checkcast 24 [java.lang.Double]
|
|
1170 |
9 areturn"
|
|
1171 |
|
|
1172 |
"Created: / 14-03-2011 / 21:30:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1173 |
"Modified: / 22-03-2011 / 17:10:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1174 |
!
|
|
1175 |
|
|
1176 |
testGetInt
|
|
1177 |
| result expResult |
|
|
1178 |
|
|
1179 |
expResult := 1.
|
|
1180 |
result := self
|
|
1181 |
invoke: #'getInt()I'
|
|
1182 |
class: self loadSimpleClassWithManyReferences
|
|
1183 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1184 |
args: nil.
|
|
1185 |
self assertFalse: (result isNil).
|
|
1186 |
self assertTrue: (result = expResult).
|
|
1187 |
"0 aload_0
|
|
1188 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1189 |
4 iconst_1
|
|
1190 |
5 aaload
|
|
1191 |
6 checkcast 13 [java.lang.Integer]
|
|
1192 |
9 invokevirtual 23 [JavaMethodRef (java.lang.Integer 'intValue'()I)]
|
|
1193 |
12 ireturn"
|
|
1194 |
|
|
1195 |
"Created: / 14-03-2011 / 21:30:47 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1196 |
"Modified: / 16-03-2011 / 22:05:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1197 |
!
|
|
1198 |
|
|
1199 |
testGetIntArray
|
|
1200 |
| result expResult |
|
|
1201 |
|
|
1202 |
"again - you're comparing java array with st array - watch out"
|
|
1203 |
expResult := #( nil nil nil nil nil ).
|
|
1204 |
result := self
|
|
1205 |
invoke: #'getIntArray()[I'
|
|
1206 |
class: self loadSimpleClassWithManyReferences
|
|
1207 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1208 |
args: nil.
|
|
1209 |
self assertFalse: (result isNil).
|
|
1210 |
self
|
|
1211 |
invoke: #'setIntArray([I)V'
|
|
1212 |
class: self loadSimpleClassWithManyReferences
|
|
1213 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1214 |
args: result.
|
|
1215 |
|
|
1216 |
"/self assertTrue: (result = expResult).
|
|
1217 |
"0 aload_0
|
|
1218 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1219 |
4 iconst_5
|
|
1220 |
5 aaload
|
|
1221 |
6 checkcast 29 [JavaBuiltInClassPointerRef(class:IntegerArray ; name&type: '[I')]
|
|
1222 |
9 checkcast 29 [JavaBuiltInClassPointerRef(class:IntegerArray ; name&type: '[I')]
|
|
1223 |
12 areturn"
|
|
1224 |
|
|
1225 |
"Created: / 14-03-2011 / 21:33:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1226 |
"Modified: / 21-03-2011 / 18:53:06 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1227 |
!
|
|
1228 |
|
|
1229 |
testGetLong
|
|
1230 |
| result expResult |
|
|
1231 |
|
|
1232 |
expResult := 10.
|
|
1233 |
result := self
|
|
1234 |
invoke: #'getLong()J'
|
|
1235 |
class: self loadSimpleClassWithManyReferences
|
|
1236 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1237 |
args: nil.
|
|
1238 |
self assertFalse: (result isNil).
|
|
1239 |
self assertTrue: (result = expResult).
|
|
1240 |
|
|
1241 |
"0 aload_0
|
|
1242 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1243 |
4 iconst_4
|
|
1244 |
5 aaload
|
|
1245 |
6 checkcast 27 [java.lang.Long]
|
|
1246 |
9 invokevirtual 28 [JavaMethodRef (java.lang.Long 'longValue'()J)]
|
|
1247 |
12 lreturn"
|
|
1248 |
|
|
1249 |
"Created: / 14-03-2011 / 21:32:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1250 |
"Modified: / 16-03-2011 / 22:05:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1251 |
!
|
|
1252 |
|
|
1253 |
testGetShort
|
|
1254 |
| result expResult |
|
|
1255 |
|
|
1256 |
expResult := 1.
|
|
1257 |
result := self
|
|
1258 |
invoke: #'getShort()S'
|
|
1259 |
class: self loadSimpleClassWithManyReferences
|
|
1260 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1261 |
args: nil.
|
|
1262 |
self assertFalse: (result isNil).
|
|
1263 |
self assertTrue: (result = expResult).
|
|
1264 |
"0 aload_0
|
|
1265 |
1 getfield 3 [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)]
|
|
1266 |
4 bipush 6
|
|
1267 |
6 aaload
|
|
1268 |
7 checkcast 14 [java.lang.Short]
|
|
1269 |
10 invokevirtual 30 [JavaMethodRef (java.lang.Short 'shortValue'()S)]
|
|
1270 |
13 ireturn "
|
|
1271 |
|
|
1272 |
"Created: / 14-03-2011 / 21:33:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1273 |
"Modified: / 16-03-2011 / 22:06:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1274 |
!
|
|
1275 |
|
|
1276 |
testGetString
|
|
1277 |
|result|
|
|
1278 |
result := self
|
|
1279 |
invoke: #'getString()Ljava/lang/String;'
|
|
1280 |
class: self loadSimpleClassWithManyReferences
|
|
1281 |
receiver: self loadSimpleClassWithManyReferences new
|
|
1282 |
args: nil.
|
|
1283 |
self assertFalse: (result isNil).
|
|
1284 |
|
|
1285 |
"Modified: / 28-03-2011 / 22:40:16 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1286 |
!
|
|
1287 |
|
|
1288 |
testInitSimpleClassWithManyReferences
|
|
1289 |
|
|
1290 |
| c |
|
|
1291 |
self
|
|
1292 |
invoke: #'<init>()V'
|
|
1293 |
class: (c := self loadSimpleClassWithManyReferences)
|
|
1294 |
receiver: c new
|
|
1295 |
args: nil.
|
|
1296 |
|
|
1297 |
"Created: / 28-03-2011 / 22:39:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1298 |
"Modified: / 01-04-2011 / 14:54:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
1299 |
!
|
|
1300 |
|
|
1301 |
testLookupSwitch
|
|
1302 |
| result expResult |
|
|
1303 |
|
|
1304 |
expResult := -1.
|
|
1305 |
result := self
|
|
1306 |
invoke: #'switchInt(I)I'
|
|
1307 |
class: self loadSwitchExamplesClass
|
|
1308 |
receiver: self loadSwitchExamplesClass new
|
|
1309 |
args: #(-1000).
|
|
1310 |
self assertFalse: (result isNil).
|
|
1311 |
self assertTrue: (result = expResult).
|
|
1312 |
|
|
1313 |
"Created: / 21-03-2011 / 13:51:49 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1314 |
!
|
|
1315 |
|
|
1316 |
testSetBoolean
|
|
1317 |
| inst |
|
|
1318 |
|
|
1319 |
inst := self loadSimpleClassWithManyReferences new.
|
|
1320 |
self
|
|
1321 |
invoke: #'setBoolean(I)V'
|
|
1322 |
class: inst class
|
|
1323 |
receiver: inst
|
|
1324 |
args: #( 5 ).
|
|
1325 |
self
|
|
1326 |
invoke: #'setBoolean(I)V'
|
|
1327 |
class: inst class
|
|
1328 |
receiver: inst
|
|
1329 |
args: #( 4 ).
|
|
1330 |
|
|
1331 |
"
|
|
1332 |
1: ILOAD_1 (27) ARGS: [] STACK: [.. -> FIELD 1: 'Arg 1']
|
|
1333 |
2: ICONST_2 (5) ARGS: [] STACK: [.. -> 2]
|
|
1334 |
3: IREM (112) ARGS: [] STACK: [value, value -> result]
|
|
1335 |
4: IFNE (154) ARGS: [JMP to: 20] STACK: [value -> ..]
|
|
1336 |
7: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences]
|
|
1337 |
8: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
|
|
1338 |
11: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
|
|
1339 |
13: GETSTATIC (178) ARGS: [JavaFieldRef (java.lang.Boolean 'TRUE'Ljava/lang/Boolean; offs=29)] STACK: [.. -> objectRef]
|
|
1340 |
16: AASTORE (83) ARGS: [] STACK: [arrayRef, index, value -> ..]
|
|
1341 |
17: GOTO (167) ARGS: [JMP to: 31] STACK: [.. -> ..]
|
|
1342 |
20: ALOAD_0 (42) ARGS: [] STACK: [.. -> FIELD 0: stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences]
|
|
1343 |
21: GETFIELD (180) ARGS: [JavaFieldRef (stx.libjava.tests.simpleClasses.SimpleClassWithManyReferences 'values'[Ljava/lang/Object; offs=1)] STACK: [objectRef -> objectRef]
|
|
1344 |
24: BIPUSH (16) ARGS: [9] STACK: [.. -> value]
|
|
1345 |
26: ICONST_0 (3) ARGS: [] STACK: [.. -> 0]
|
|
1346 |
27: INVSTATIC (184) ARGS: [JavaMethodRef (java.lang.Boolean 'valueOf'(Z)Ljava/lang/Boolean;)] STACK: [[arg1, arg2, ...] -> ..]
|
|
1347 |
30: AASTORE (83) ARGS: [] STACK: [arrayRef, index, value -> ..]
|
|
1348 |
31: RETURN (177) ARGS: [] STACK: [.. -> EMPTY]"
|
|
1349 |
|
|
1350 |
"Created: / 21-03-2011 / 18:53:48 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1351 |
"Modified: / 22-03-2011 / 12:18:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1352 |
!
|
|
1353 |
|
|
1354 |
testTableSwitch
|
|
1355 |
| result expResult |
|
|
1356 |
|
|
1357 |
expResult := 1.
|
|
1358 |
result := self
|
|
1359 |
invoke: #'switchChar(C)I'
|
|
1360 |
class: self loadSwitchExamplesClass
|
|
1361 |
receiver: self loadSwitchExamplesClass new
|
|
1362 |
args: #($b).
|
|
1363 |
self assertFalse: (result isNil).
|
|
1364 |
self assertTrue: (result = expResult).
|
|
1365 |
|
|
1366 |
"Created: / 21-03-2011 / 13:51:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
1367 |
! !
|
|
1368 |
|
|
1369 |
!JavaByteCodeInterpreterTests class methodsFor:'documentation'!
|
|
1370 |
|
|
1371 |
version_SVN
|
2152
|
1372 |
^ '$Id: JavaByteCodeInterpreterTests.st,v 1.1 2011-08-18 19:06:53 vrany Exp $'
|
|
1373 |
! !
|