comparison paraspace/tests/injection_test.py @ 149:d4533a59c694

inject_classdefs() also inject relative _DEX_StringIds.
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 15 Aug 2011 21:51:39 +0800
parents c4324c3461e8
children 1eb1b2ca5de4
comparison
equal deleted inserted replaced
148:90e181f2a0c5 149:d4533a59c694
179 pass 179 pass
180 180
181 181
182 def collect_types_in_method_test(): 182 def collect_types_in_method_test():
183 from paraspace.dex_deptracker import prepare_dep_decls 183 from paraspace.dex_deptracker import prepare_dep_decls
184 from paraspace.injection import collect_typeidxs_in_method 184 from paraspace.injection import collect_typeidxs_stridxs_in_method
185 from paraspace.injection import collect_typeidxs_mentioned_by_class 185 from paraspace.injection import collect_typeidxs_stridxs_mentioned_by_class
186 from paraspace.dexfile import DEXFile_linked 186 from paraspace.dexfile import DEXFile_linked
187 187
188 _install_dexfile_4_deptracker() 188 _install_dexfile_4_deptracker()
189 189
190 all_dep_decls = prepare_dep_decls() 190 all_dep_decls = prepare_dep_decls()
201 fakefile_def = \ 201 fakefile_def = \
202 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;') 202 fakefile_linked.find_class_name('Lcom/codemud/fakefile/fakefile;')
203 203
204 init_method = fakefile_linked.find_method_name('<init>', fakefile_def) 204 init_method = fakefile_linked.find_method_name('<init>', fakefile_def)
205 205
206 typeidxs = collect_typeidxs_in_method(fakefile_linked, init_method) 206 typeidxs, stridxs = \
207 collect_typeidxs_stridxs_in_method(fakefile_linked, init_method)
207 assert len(typeidxs) == 1 208 assert len(typeidxs) == 1
208 209
209 typeid = fakefile_linked.find_typeid_idx(typeidxs[0]) 210 typeid = fakefile_linked.find_typeid_idx(typeidxs[0])
210 typeid_name = DEXFile_linked.get_typeid_name(typeid) 211 typeid_name = DEXFile_linked.get_typeid_name(typeid)
211 assert typeid_name == 'Ljava/io/File;' 212 assert typeid_name == 'Ljava/io/File;'
212 213
213 typeidxs = collect_typeidxs_mentioned_by_class(fakefile_linked, 214 typeidxs, stridxs = \
214 fakefile_def) 215 collect_typeidxs_stridxs_mentioned_by_class(fakefile_linked, \
216 fakefile_def)
215 assert len(typeidxs) == 1 217 assert len(typeidxs) == 1
216 218
217 typeid = fakefile_linked.find_typeid_idx(typeidxs[0]) 219 typeid = fakefile_linked.find_typeid_idx(typeidxs[0])
218 typeid_name = DEXFile_linked.get_typeid_name(typeid) 220 typeid_name = DEXFile_linked.get_typeid_name(typeid)
219 assert typeid_name == 'Ljava/io/File;' 221 assert typeid_name == 'Ljava/io/File;'
259 assert len(fakefile_data.virtualMethods.items) == 0 261 assert len(fakefile_data.virtualMethods.items) == 0
260 fakefile_dataheader = fakefile_data.header 262 fakefile_dataheader = fakefile_data.header
261 assert fakefile_dataheader.directMethodsSize == 1 263 assert fakefile_dataheader.directMethodsSize == 1
262 assert fakefile_dataheader.virtualMethodsSize == 0 264 assert fakefile_dataheader.virtualMethodsSize == 0
263 265
264 classdefs, typeids = dexfile_insert_classdefs_relative(helloworld_linked, 266 classdefs, typeids, strids = \
265 fakefile_linked, 267 dexfile_insert_classdefs_relative(helloworld_linked, \
266 [fakefile_def]) 268 fakefile_linked, \
269 [fakefile_def])
267 assert classdefs 270 assert classdefs
268 assert len(classdefs) == 1 271 assert len(classdefs) == 1
269 assert classdefs[0] != fakefile_def 272 assert classdefs[0] != fakefile_def
270 273
271 helloworld_unlinked = helloworld_linked.get_unlinked() 274 helloworld_unlinked = helloworld_linked.get_unlinked()