annotate paraspace/tests/injection_test.py @ 90:fe7b3f111d57

Testcase for code injection
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 24 Jul 2011 22:28:21 +0800
parents
children 1728795c29b7
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
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 _install_dexfile_4_deptracker()
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25 all_dep_decls = prepare_dep_decls()
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 srcdir = os.path.dirname(__file__)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 srcroot = os.path.join(srcdir, '..', '..')
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30 helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex')
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31 helloworld_dex = dexfile.DEXFile.open(helloworld_fn)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
32
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
33 fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex')
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 fakefile_dex = dexfile.DEXFile.open(fakefile_fn)
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35 pass
fe7b3f111d57 Testcase for code injection
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36