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 |
AbstractJavaTestCase subclass:#JavaClassReader2Tests
|
|
45 |
instanceVariableNames:''
|
|
46 |
classVariableNames:''
|
|
47 |
poolDictionaries:''
|
|
48 |
category:'Languages-Java-Tests-RuntimeConstantPool'
|
|
49 |
!
|
|
50 |
|
|
51 |
!JavaClassReader2Tests 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 |
!JavaClassReader2Tests methodsFor:'tests'!
|
|
99 |
|
|
100 |
_testJavaInitializationWithNewReader
|
|
101 |
|
|
102 |
"Disabled by default, since it flushes
|
|
103 |
Java causing hudson test runner to fail
|
|
104 |
(proxy testcases are already loaded)"
|
|
105 |
|
|
106 |
|
|
107 |
self assert: false.
|
|
108 |
JavaClassReader useNewClassReader.
|
|
109 |
Java flushAllJavaResources.
|
|
110 |
Java initialize.
|
|
111 |
JavaVM initializeVM.
|
|
112 |
JavaClassReader useOldClassReader.
|
|
113 |
|
|
114 |
"Modified: / 12-05-2011 / 18:21:32 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
115 |
"Created: / 01-06-2011 / 21:48:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
116 |
!
|
|
117 |
|
|
118 |
_testJavaInitializationWithOldReader
|
|
119 |
|
|
120 |
"Disabled by default, since it flushes
|
|
121 |
Java causing hudson test runner to fail
|
|
122 |
(proxy testcases are already loaded)"
|
|
123 |
|
|
124 |
JavaClassReader useOldClassReader.
|
|
125 |
Java flushAllJavaResources.
|
|
126 |
Java initialize.
|
|
127 |
JavaVM initializeVM.
|
|
128 |
JavaClassReader useOldClassReader.
|
|
129 |
|
|
130 |
"Created: / 01-06-2011 / 21:47:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
131 |
!
|
|
132 |
|
|
133 |
testReadingClass
|
|
134 |
| reader constantPool result |
|
|
135 |
|
|
136 |
reader := JavaClassReader new.
|
|
137 |
constantPool := JavaConstantPool new: 1.
|
|
138 |
constantPool at: 1 put: 'Ljava/lang/Object;'.
|
|
139 |
reader constants: constantPool.
|
|
140 |
reader stream: (ReadStream on: #( 1 0 )).
|
|
141 |
result := reader readConstant_Class.
|
|
142 |
self assertTrue: (result notNil).
|
|
143 |
self assertTrue: (result isJavaRef).
|
|
144 |
self assertTrue: (result isNewJavaRef).
|
|
145 |
self assertTrue: (result name = 'Ljava/lang/Object;').
|
|
146 |
|
|
147 |
"Created: / 10-05-2011 / 13:52:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
148 |
"Modified: / 08-08-2011 / 17:25:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
149 |
!
|
|
150 |
|
|
151 |
testReadingField
|
|
152 |
| reader constantPool result |
|
|
153 |
|
|
154 |
reader := JavaClassReader new.
|
|
155 |
constantPool := JavaConstantPool new: 5.
|
|
156 |
constantPool at: 1 put: 'class'.
|
|
157 |
constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
|
|
158 |
constantPool at: 3
|
|
159 |
put: (self
|
|
160 |
getNameAndTypeIn: constantPool
|
|
161 |
withNameAt: 4
|
|
162 |
andTypeAt: 5).
|
|
163 |
constantPool at: 4 put: 'name'.
|
|
164 |
constantPool at: 5 put: 'type'.
|
|
165 |
constantPool owner: self javaLangObject.
|
|
166 |
reader constants: constantPool.
|
|
167 |
reader stream: (ReadStream on: #( 2 0 3 0 )).
|
|
168 |
result := reader readConstant_Fieldref.
|
|
169 |
self assertTrue: (result notNil).
|
|
170 |
self assertTrue: (result isJavaRef).
|
|
171 |
self assertTrue: (result isNewJavaRef).
|
|
172 |
self assertTrue: (result classRef isJavaRef).
|
|
173 |
self assertTrue: (result nameAndType isNewJavaNameAndType).
|
|
174 |
self assertTrue: (result nameAndType name = 'name').
|
|
175 |
self assertTrue: (result nameAndType descriptor = 'type').
|
|
176 |
self assertTrue: (result owner = self javaLangObject).
|
|
177 |
|
|
178 |
"Created: / 10-05-2011 / 14:12:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
179 |
"Modified: / 23-05-2011 / 18:00:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
180 |
"Modified: / 08-08-2011 / 17:25:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
181 |
!
|
|
182 |
|
|
183 |
testReadingInterfaceMethod
|
|
184 |
| reader constantPool result |
|
|
185 |
|
|
186 |
reader := JavaClassReader new.
|
|
187 |
constantPool := JavaConstantPool new: 5.
|
|
188 |
constantPool at: 1 put: 'class'.
|
|
189 |
constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
|
|
190 |
constantPool at: 3
|
|
191 |
put: (self
|
|
192 |
getNameAndTypeIn: constantPool
|
|
193 |
withNameAt: 4
|
|
194 |
andTypeAt: 5).
|
|
195 |
constantPool at: 4 put: 'name'.
|
|
196 |
constantPool at: 5 put: 'type'.
|
|
197 |
constantPool owner: self javaLangObject.
|
|
198 |
reader constants: constantPool.
|
|
199 |
reader stream: (ReadStream on: #( 2 0 3 0 )).
|
|
200 |
result := reader readConstant_InterfaceMethodref.
|
|
201 |
self assertTrue: (result notNil).
|
|
202 |
self assertTrue: (result isJavaRef).
|
|
203 |
self assertTrue: (result isNewJavaRef).
|
|
204 |
self assertTrue: (result classRef isNewJavaRef).
|
|
205 |
self assertTrue: (result classRef isNewJavaRef).
|
|
206 |
self assertTrue: (result nameAndType isNewJavaNameAndType).
|
|
207 |
self assertTrue: (result nameAndType name = 'name').
|
|
208 |
self assertTrue: (result nameAndType descriptor = 'type').
|
|
209 |
self assertTrue: (result owner = self javaLangObject).
|
|
210 |
self assertTrue: (result owner = self javaLangObject).
|
|
211 |
|
|
212 |
"Created: / 10-05-2011 / 14:12:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
213 |
"Modified: / 23-05-2011 / 18:00:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
214 |
"Modified: / 08-08-2011 / 17:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
215 |
!
|
|
216 |
|
|
217 |
testReadingMethod
|
|
218 |
| reader constantPool result |
|
|
219 |
|
|
220 |
reader := JavaClassReader new.
|
|
221 |
constantPool := JavaConstantPool new: 5.
|
|
222 |
constantPool at: 1 put: 'class'.
|
|
223 |
constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
|
|
224 |
constantPool at: 3
|
|
225 |
put: (self
|
|
226 |
getNameAndTypeIn: constantPool
|
|
227 |
withNameAt: 4
|
|
228 |
andTypeAt: 5).
|
|
229 |
constantPool at: 4 put: 'name'.
|
|
230 |
constantPool at: 5 put: 'type'.
|
|
231 |
constantPool owner: self javaLangObject.
|
|
232 |
reader constants: constantPool.
|
|
233 |
reader stream: (ReadStream on: #( 2 0 3 0 )).
|
|
234 |
result := reader readConstant_Methodref.
|
|
235 |
self assertTrue: (result notNil).
|
|
236 |
self assertTrue: (result isJavaRef).
|
|
237 |
self assertTrue: (result isNewJavaRef).
|
|
238 |
self assertTrue: (result classRef isNewJavaRef).
|
|
239 |
self assertTrue: (result classRef isNewJavaRef).
|
|
240 |
self assertTrue: (result nameAndType isNewJavaNameAndType).
|
|
241 |
self assertTrue: (result nameAndType name = 'name').
|
|
242 |
self assertTrue: (result nameAndType descriptor = 'type').
|
|
243 |
self assertTrue: (result owner = self javaLangObject).
|
|
244 |
|
|
245 |
"Created: / 10-05-2011 / 14:10:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
246 |
"Modified: / 23-05-2011 / 18:00:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
247 |
"Modified: / 08-08-2011 / 17:25:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
248 |
!
|
|
249 |
|
|
250 |
testReadingNameAndType
|
|
251 |
| reader constantPool result |
|
|
252 |
|
|
253 |
reader := JavaClassReader new.
|
|
254 |
constantPool := JavaConstantPool new: 2.
|
|
255 |
constantPool at: 1 put: 'foo'.
|
|
256 |
constantPool at: 2 put: 'bar'.
|
|
257 |
reader constants: constantPool.
|
|
258 |
reader stream: (ReadStream on: #( 1 0 2 0 )).
|
|
259 |
result := reader readConstant_NameAndType.
|
|
260 |
self assertTrue: (result notNil).
|
|
261 |
self assertTrue: (result isJavaNameAndType).
|
|
262 |
self assertTrue: (result isNewJavaNameAndType).
|
|
263 |
self assertTrue: (result name = 'foo').
|
|
264 |
self assertTrue: (result descriptor = 'bar').
|
|
265 |
|
|
266 |
"Created: / 10-05-2011 / 13:56:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
267 |
"Modified: / 08-08-2011 / 17:25:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
268 |
!
|
|
269 |
|
|
270 |
testReadingStream
|
|
271 |
|
|
272 |
|result|
|
|
273 |
result := JavaClassReader readStream: self getCrateClassReadStream.
|
|
274 |
self assertTrue: (result notNil).
|
|
275 |
|
|
276 |
"Created: / 10-05-2011 / 12:16:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
277 |
"Modified: / 08-08-2011 / 17:25:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
278 |
!
|
|
279 |
|
|
280 |
testWholeConstantPoolContainsFullyInitializedItems
|
|
281 |
| result |
|
|
282 |
|
|
283 |
result := JavaClassReader readStream: self getCrateClassReadStream.
|
|
284 |
result constantPool do:
|
|
285 |
[:each |
|
|
286 |
each isJavaRef
|
|
287 |
ifTrue: [ self assertTrue: each isNewJavaRef. self assertTrue: each owner notNil. self assertTrue: each constantPool notNil.]
|
|
288 |
ifFalse:
|
|
289 |
[ each isJavaNameAndType
|
|
290 |
ifTrue: [ self assertTrue: each isNewJavaNameAndType. self assertTrue: each owner notNil. self assertTrue: each constantPool notNil.] ] ].
|
|
291 |
|
|
292 |
"Created: / 10-05-2011 / 17:01:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
293 |
!
|
|
294 |
|
|
295 |
testWholeConstantPoolContainsOnlyNewRefs
|
|
296 |
| result |
|
|
297 |
|
|
298 |
result := JavaClassReader readStream: self getCrateClassReadStream.
|
|
299 |
result constantPool do:
|
|
300 |
[:each |
|
|
301 |
each isJavaRef
|
|
302 |
ifTrue: [ self assertTrue: each isNewJavaRef ]
|
|
303 |
ifFalse:
|
|
304 |
[ each isJavaNameAndType
|
|
305 |
ifTrue: [ self assertTrue: each isNewJavaNameAndType ] ] ].
|
|
306 |
|
|
307 |
"Created: / 10-05-2011 / 12:18:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
308 |
"Modified: / 10-05-2011 / 16:59:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
309 |
! !
|
|
310 |
|
|
311 |
!JavaClassReader2Tests class methodsFor:'documentation'!
|
|
312 |
|
|
313 |
version_SVN
|
2152
|
314 |
^ '$Id: JavaClassReader2Tests.st,v 1.1 2011-08-18 19:06:53 vrany Exp $'
|
|
315 |
! !
|