877
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
1152
|
3 |
|
1155
|
4 |
New code and modifications done at SWING Research Group [1]:
|
1152
|
5 |
|
877
|
6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
7 |
SWING Research Group, Czech Technical University in Prague
|
|
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 |
|
1155
|
16 |
[1] Code written at SWING Research Group contains a signature
|
|
17 |
of one of the above copright owners. For exact set of such code,
|
|
18 |
see the differences between this version and version stx:libjava
|
1152
|
19 |
as of 1.9.2010
|
877
|
20 |
"
|
752
|
21 |
"{ Package: 'stx:libjava' }"
|
|
22 |
|
1515
|
23 |
JavaRefsAndConstantPoolTestCase subclass:#JavaClassReaderTests
|
752
|
24 |
instanceVariableNames:''
|
|
25 |
classVariableNames:''
|
|
26 |
poolDictionaries:''
|
1509
|
27 |
category:'Languages-Java-Tests-RuntimeConstantPool'
|
752
|
28 |
!
|
|
29 |
|
877
|
30 |
!JavaClassReaderTests class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
copyright
|
|
33 |
"
|
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger
|
1152
|
35 |
|
1155
|
36 |
New code and modifications done at SWING Research Group [1]:
|
1152
|
37 |
|
877
|
38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
|
|
39 |
SWING Research Group, Czech Technical University in Prague
|
|
40 |
|
|
41 |
This software is furnished under a license and may be used
|
|
42 |
only in accordance with the terms of that license and with the
|
|
43 |
inclusion of the above copyright notice. This software may not
|
|
44 |
be provided or otherwise made available to, or used by, any
|
|
45 |
other person. No title to or ownership of the software is
|
|
46 |
hereby transferred.
|
|
47 |
|
1155
|
48 |
[1] Code written at SWING Research Group contains a signature
|
|
49 |
of one of the above copright owners. For exact set of such code,
|
|
50 |
see the differences between this version and version stx:libjava
|
1152
|
51 |
as of 1.9.2010
|
877
|
52 |
|
|
53 |
"
|
|
54 |
! !
|
752
|
55 |
|
1509
|
56 |
!JavaClassReaderTests methodsFor:'tests'!
|
|
57 |
|
|
58 |
testReadingClass
|
|
59 |
| reader constantPool result |
|
752
|
60 |
|
1509
|
61 |
reader := JavaClassReader new.
|
|
62 |
constantPool := JavaConstantPool new: 1.
|
|
63 |
constantPool at: 1 put: 'Ljava/lang/Object;'.
|
|
64 |
reader constants: constantPool.
|
|
65 |
reader stream: (ReadStream on: #( 1 0 )).
|
|
66 |
result := reader readConstant_Class.
|
|
67 |
self assertTrue: (result notNil).
|
|
68 |
self assertTrue: (result isJavaRef).
|
|
69 |
self assertTrue: (result isNewJavaRef).
|
|
70 |
self assertTrue: (result name = 'Ljava/lang/Object;').
|
|
71 |
|
|
72 |
"Created: / 10-05-2011 / 13:52:35 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
73 |
"Modified: / 08-08-2011 / 17:25:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
74 |
!
|
|
75 |
|
|
76 |
testReadingField
|
|
77 |
| reader constantPool result |
|
752
|
78 |
|
1509
|
79 |
reader := JavaClassReader new.
|
|
80 |
constantPool := JavaConstantPool new: 5.
|
|
81 |
constantPool at: 1 put: 'class'.
|
|
82 |
constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
|
|
83 |
constantPool at: 3
|
|
84 |
put: (self
|
|
85 |
getNameAndTypeIn: constantPool
|
|
86 |
withNameAt: 4
|
|
87 |
andTypeAt: 5).
|
|
88 |
constantPool at: 4 put: 'name'.
|
|
89 |
constantPool at: 5 put: 'type'.
|
|
90 |
constantPool owner: self javaLangObject.
|
|
91 |
reader constants: constantPool.
|
|
92 |
reader stream: (ReadStream on: #( 2 0 3 0 )).
|
|
93 |
result := reader readConstant_Fieldref.
|
|
94 |
self assertTrue: (result notNil).
|
|
95 |
self assertTrue: (result isJavaRef).
|
|
96 |
self assertTrue: (result isNewJavaRef).
|
|
97 |
self assertTrue: (result classRef isJavaRef).
|
|
98 |
self assertTrue: (result nameAndType isNewJavaNameAndType).
|
|
99 |
self assertTrue: (result nameAndType name = 'name').
|
|
100 |
self assertTrue: (result nameAndType descriptor = 'type').
|
|
101 |
self assertTrue: (result owner = self javaLangObject).
|
|
102 |
|
|
103 |
"Created: / 10-05-2011 / 14:12:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
104 |
"Modified: / 23-05-2011 / 18:00:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
105 |
"Modified: / 08-08-2011 / 17:25:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
106 |
!
|
|
107 |
|
|
108 |
testReadingInterfaceMethod
|
|
109 |
| reader constantPool result |
|
752
|
110 |
|
1509
|
111 |
reader := JavaClassReader new.
|
|
112 |
constantPool := JavaConstantPool new: 5.
|
|
113 |
constantPool at: 1 put: 'class'.
|
|
114 |
constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
|
|
115 |
constantPool at: 3
|
|
116 |
put: (self
|
|
117 |
getNameAndTypeIn: constantPool
|
|
118 |
withNameAt: 4
|
|
119 |
andTypeAt: 5).
|
|
120 |
constantPool at: 4 put: 'name'.
|
|
121 |
constantPool at: 5 put: 'type'.
|
|
122 |
constantPool owner: self javaLangObject.
|
|
123 |
reader constants: constantPool.
|
|
124 |
reader stream: (ReadStream on: #( 2 0 3 0 )).
|
|
125 |
result := reader readConstant_InterfaceMethodref.
|
|
126 |
self assertTrue: (result notNil).
|
|
127 |
self assertTrue: (result isJavaRef).
|
|
128 |
self assertTrue: (result isNewJavaRef).
|
|
129 |
self assertTrue: (result classRef isNewJavaRef).
|
|
130 |
self assertTrue: (result classRef isNewJavaRef).
|
|
131 |
self assertTrue: (result nameAndType isNewJavaNameAndType).
|
|
132 |
self assertTrue: (result nameAndType name = 'name').
|
|
133 |
self assertTrue: (result nameAndType descriptor = 'type').
|
|
134 |
self assertTrue: (result owner = self javaLangObject).
|
|
135 |
self assertTrue: (result owner = self javaLangObject).
|
752
|
136 |
|
1509
|
137 |
"Created: / 10-05-2011 / 14:12:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
138 |
"Modified: / 23-05-2011 / 18:00:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
139 |
"Modified: / 08-08-2011 / 17:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
140 |
!
|
|
141 |
|
|
142 |
testReadingMethod
|
|
143 |
| reader constantPool result |
|
752
|
144 |
|
1509
|
145 |
reader := JavaClassReader new.
|
|
146 |
constantPool := JavaConstantPool new: 5.
|
|
147 |
constantPool at: 1 put: 'class'.
|
|
148 |
constantPool at: 2 put: (self getClassRefIn: constantPool withNameAt: 1).
|
|
149 |
constantPool at: 3
|
|
150 |
put: (self
|
|
151 |
getNameAndTypeIn: constantPool
|
|
152 |
withNameAt: 4
|
|
153 |
andTypeAt: 5).
|
|
154 |
constantPool at: 4 put: 'name'.
|
|
155 |
constantPool at: 5 put: 'type'.
|
|
156 |
constantPool owner: self javaLangObject.
|
|
157 |
reader constants: constantPool.
|
|
158 |
reader stream: (ReadStream on: #( 2 0 3 0 )).
|
|
159 |
result := reader readConstant_Methodref.
|
|
160 |
self assertTrue: (result notNil).
|
|
161 |
self assertTrue: (result isJavaRef).
|
|
162 |
self assertTrue: (result isNewJavaRef).
|
|
163 |
self assertTrue: (result classRef isNewJavaRef).
|
|
164 |
self assertTrue: (result classRef isNewJavaRef).
|
|
165 |
self assertTrue: (result nameAndType isNewJavaNameAndType).
|
|
166 |
self assertTrue: (result nameAndType name = 'name').
|
|
167 |
self assertTrue: (result nameAndType descriptor = 'type').
|
|
168 |
self assertTrue: (result owner = self javaLangObject).
|
752
|
169 |
|
1509
|
170 |
"Created: / 10-05-2011 / 14:10:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
171 |
"Modified: / 23-05-2011 / 18:00:41 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
172 |
"Modified: / 08-08-2011 / 17:25:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
173 |
!
|
752
|
174 |
|
1509
|
175 |
testReadingNameAndType
|
|
176 |
| reader constantPool result |
|
752
|
177 |
|
1509
|
178 |
reader := JavaClassReader new.
|
|
179 |
constantPool := JavaConstantPool new: 2.
|
|
180 |
constantPool at: 1 put: 'foo'.
|
|
181 |
constantPool at: 2 put: 'bar'.
|
|
182 |
reader constants: constantPool.
|
|
183 |
reader stream: (ReadStream on: #( 1 0 2 0 )).
|
|
184 |
result := reader readConstant_NameAndType.
|
|
185 |
self assertTrue: (result notNil).
|
|
186 |
self assertTrue: (result isJavaNameAndType).
|
|
187 |
self assertTrue: (result isNewJavaNameAndType).
|
|
188 |
self assertTrue: (result name = 'foo').
|
|
189 |
self assertTrue: (result descriptor = 'bar').
|
|
190 |
|
|
191 |
"Created: / 10-05-2011 / 13:56:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
192 |
"Modified: / 08-08-2011 / 17:25:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
193 |
!
|
|
194 |
|
|
195 |
testReadingStream
|
|
196 |
|
|
197 |
|result|
|
|
198 |
result := JavaClassReader readStream: self getCrateClassReadStream.
|
|
199 |
self assertTrue: (result notNil).
|
|
200 |
|
|
201 |
"Created: / 10-05-2011 / 12:16:43 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
202 |
"Modified: / 08-08-2011 / 17:25:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
203 |
!
|
752
|
204 |
|
1509
|
205 |
testWholeConstantPoolContainsFullyInitializedItems
|
|
206 |
| result |
|
|
207 |
|
|
208 |
result := JavaClassReader readStream: self getCrateClassReadStream.
|
|
209 |
result constantPool do:
|
|
210 |
[:each |
|
|
211 |
each isJavaRef
|
|
212 |
ifTrue: [ self assertTrue: each isNewJavaRef. self assertTrue: each owner notNil. self assertTrue: each constantPool notNil.]
|
|
213 |
ifFalse:
|
|
214 |
[ each isJavaNameAndType
|
|
215 |
ifTrue: [ self assertTrue: each isNewJavaNameAndType. self assertTrue: each owner notNil. self assertTrue: each constantPool notNil.] ] ].
|
|
216 |
|
|
217 |
"Created: / 10-05-2011 / 17:01:12 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
218 |
!
|
|
219 |
|
|
220 |
testWholeConstantPoolContainsOnlyNewRefs
|
|
221 |
| result |
|
|
222 |
|
|
223 |
result := JavaClassReader readStream: self getCrateClassReadStream.
|
|
224 |
result constantPool do:
|
|
225 |
[:each |
|
|
226 |
each isJavaRef
|
|
227 |
ifTrue: [ self assertTrue: each isNewJavaRef ]
|
|
228 |
ifFalse:
|
|
229 |
[ each isJavaNameAndType
|
|
230 |
ifTrue: [ self assertTrue: each isNewJavaNameAndType ] ] ].
|
|
231 |
|
|
232 |
"Created: / 10-05-2011 / 12:18:58 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
|
233 |
"Modified: / 10-05-2011 / 16:59:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
|
752
|
234 |
! !
|
|
235 |
|
|
236 |
!JavaClassReaderTests class methodsFor:'documentation'!
|
|
237 |
|
|
238 |
version_SVN
|
|
239 |
^ '$Id$'
|
|
240 |
! !
|