Mercurial > paraspace
comparison paraspace/tests/injection_test.py @ 100:355986e5cfbd
Make surce methods of injected class are also being and bug fixed.
- dex_type_2_array_attr_map() misses marked array attributes.
- It is fixed by skiping marked array and use back type instead.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Tue, 26 Jul 2011 10:06:44 +0800 |
parents | 3898711adb2c |
children | f14c32108164 |
comparison
equal
deleted
inserted
replaced
99:3898711adb2c | 100:355986e5cfbd |
---|---|
41 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') | 41 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex') |
42 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) | 42 helloworld_dex = dexfile.DEXFile.open(helloworld_fn) |
43 | 43 |
44 classdef_map = _find_map(helloworld_dex, 0x0006) | 44 classdef_map = _find_map(helloworld_dex, 0x0006) |
45 saved_classdef_map_sz = classdef_map.size | 45 saved_classdef_map_sz = classdef_map.size |
46 saved_methodids_sz = len(helloworld_dex.methodIds.items) | |
47 | |
48 codeitems_map = _find_map(helloworld_dex, 0x2001) | |
49 saved_codeitems_sz = codeitems_map.size | |
46 | 50 |
47 helloworld_linked = \ | 51 helloworld_linked = \ |
48 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, | 52 dexfile.DEXFile_linked.build_dependencies(helloworld_dex, |
49 all_dep_decls) | 53 all_dep_decls) |
50 | 54 |
54 dexfile.DEXFile_linked. \ | 58 dexfile.DEXFile_linked. \ |
55 build_dependencies(fakefile_dex, all_dep_decls) | 59 build_dependencies(fakefile_dex, all_dep_decls) |
56 | 60 |
57 fakefile_def = fakefile_linked. \ | 61 fakefile_def = fakefile_linked. \ |
58 find_class_name('Lcom/codemud/fakefile/fakefile;') | 62 find_class_name('Lcom/codemud/fakefile/fakefile;') |
63 | |
64 fakefile_data = fakefile_def.classDataOffRef.value | |
65 assert len(fakefile_data.directMethods.items) == 1 | |
66 assert len(fakefile_data.virtualMethods.items) == 0 | |
67 fakefile_dataheader = fakefile_data.header | |
68 assert fakefile_dataheader.directMethodsSize == 1 | |
69 assert fakefile_dataheader.virtualMethodsSize == 0 | |
59 | 70 |
60 clone = dexfile_insert_class(helloworld_linked, fakefile_def) | 71 clone = dexfile_insert_class(helloworld_linked, fakefile_def) |
61 assert clone | 72 assert clone |
62 assert clone != fakefile_def | 73 assert clone != fakefile_def |
63 | 74 |
74 # Check strings | 85 # Check strings |
75 strdatas = helloworld_unlinked.stringDataItems.items | 86 strdatas = helloworld_unlinked.stringDataItems.items |
76 strs = sorted([strdata.data.data for strdata in strdatas]) | 87 strs = sorted([strdata.data.data for strdata in strdatas]) |
77 assert len(strs) == len(set(strs)) # uniquely | 88 assert len(strs) == len(set(strs)) # uniquely |
78 assert 'Lcom/codemud/fakefile/fakefile;' in strs | 89 assert 'Lcom/codemud/fakefile/fakefile;' in strs |
90 | |
91 # Check Method List | |
92 methodids_map = _find_map(helloworld_unlinked, 0x0005) # method ids | |
93 assert methodids_map.size == len(helloworld_unlinked.methodIds.items) | |
94 assert methodids_map.size == saved_methodids_sz + 1 | |
95 | |
96 # Check Code item List | |
97 codeitems_map = _find_map(helloworld_unlinked, 0x2001) | |
98 assert codeitems_map.size == saved_codeitems_sz + 1 | |
79 pass | 99 pass |
80 | 100 |