annotate paraspace/tests/injection_test.py @ 92:1728795c29b7

Build dependencies for injection testcases
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 25 Jul 2011 10:01:14 +0800
parents fe7b3f111d57
children 2fa9b6f21344
rev   line source
90
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 from paraspace import dexfile
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2 import os
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 def _install_dexfile_4_deptracker():
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 global dexfile
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6 import imp
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7 from paraspace import dex_deptracker
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9 try:
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 new_dexfile = imp.load_compiled('dexfile', dexfile.__file__)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 except ImportError:
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12 new_dexfile = imp.load_source('dexfile', dexfile.__file__)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 pass
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 dex_deptracker.dexfile = new_dexfile
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 dexfile = new_dexfile
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 dex_deptracker._nest_types = (dexfile.array, dexfile.cond, dexfile.switch)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 pass
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 def inject_fakefile_to_helloworld_test():
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21 from paraspace.dex_deptracker import prepare_dep_decls
92
1728795c29b7 Build dependencies for injection testcases
Thinker K.F. Li <thinker@codemud.net>
parents: 90
diff changeset
22 from paraspace.dex_deptracker import build_dependencies
90
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24 _install_dexfile_4_deptracker()
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 all_dep_decls = prepare_dep_decls()
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 srcdir = os.path.dirname(__file__)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 srcroot = os.path.join(srcdir, '..', '..')
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex')
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
32 helloworld_dex = dexfile.DEXFile.open(helloworld_fn)
92
1728795c29b7 Build dependencies for injection testcases
Thinker K.F. Li <thinker@codemud.net>
parents: 90
diff changeset
33 build_dependencies(helloworld_dex, all_dep_decls)
90
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex')
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36 fakefile_dex = dexfile.DEXFile.open(fakefile_fn)
92
1728795c29b7 Build dependencies for injection testcases
Thinker K.F. Li <thinker@codemud.net>
parents: 90
diff changeset
37 build_dependencies(fakefile_dex, all_dep_decls)
90
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
38 pass
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39