changeset 90:fe7b3f111d57

Testcase for code injection
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 24 Jul 2011 22:28:21 +0800
parents 7a059ab408f0
children a33dfe2dae9d
files paraspace/dex_deptracker.py paraspace/tests/injection_test.py
diffstat 2 files changed, 37 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/paraspace/dex_deptracker.py	Sun Jul 24 20:54:54 2011 +0800
+++ b/paraspace/dex_deptracker.py	Sun Jul 24 22:28:21 2011 +0800
@@ -885,7 +885,7 @@
 ## \brief Prepare and return dependency declares.
 def prepare_dep_decls():
     decls = collect_all_dep_decls()
-    _install_idx_marker(decls)
+    _install_markers(decls)
     _patch_dex_type_markers(decls)
     return decls
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/paraspace/tests/injection_test.py	Sun Jul 24 22:28:21 2011 +0800
@@ -0,0 +1,36 @@
+from paraspace import dexfile
+import os
+
+def _install_dexfile_4_deptracker():
+    global dexfile
+    import imp
+    from paraspace import dex_deptracker
+    
+    try:
+        new_dexfile = imp.load_compiled('dexfile', dexfile.__file__)
+    except ImportError:
+        new_dexfile = imp.load_source('dexfile', dexfile.__file__)
+        pass
+    dex_deptracker.dexfile = new_dexfile
+    dexfile = new_dexfile
+    dex_deptracker._nest_types = (dexfile.array, dexfile.cond, dexfile.switch)
+    pass
+
+
+def inject_fakefile_to_helloworld_test():
+    from paraspace.dex_deptracker import prepare_dep_decls
+    
+    _install_dexfile_4_deptracker()
+    
+    all_dep_decls = prepare_dep_decls()
+    
+    srcdir = os.path.dirname(__file__)
+    srcroot = os.path.join(srcdir, '..', '..')
+    
+    helloworld_fn = os.path.join(srcroot, 'data', 'helloworld.dex')
+    helloworld_dex = dexfile.DEXFile.open(helloworld_fn)
+
+    fakefile_fn = os.path.join(srcroot, 'data', 'fakefile.dex')
+    fakefile_dex = dexfile.DEXFile.open(fakefile_fn)
+    pass
+