view paraspace/tests/dexfile_test.py @ 23:fff40aabefab

Move collect_dependencies() to dex_deptracker.py
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 02 Jun 2011 16:53:12 +0800
parents 265f39947b36
children 670167ed06bb
line wrap: on
line source

from paraspace import dexfile
import os

def block_sizes_test():
    srcdir = os.path.dirname(__file__)
    srcroot = os.path.join(srcdir, '..', '..')
    testdatapath = os.path.join(srcroot, 'data', 'testdata1.dex')
    dex = dexfile.DEXFile.open(testdatapath)
    assert dex.stringIds.data_size == 5384
    assert dex.typeIds.data_size == 704
    assert dex.protoIds.data_size == 1776
    assert dex.fieldIds.data_size == 1944
    assert dex.methodIds.data_size == 3552
    assert dex.classDefs.data_size == 1600
    assert dex.classDatas.data_size == 2052
    assert dex.typeLists.data_size == 838
    assert dex.codeItems.data_size == 30688
    assert dex.annotationSetItems.data_size == 412
    assert dex.annotationsDirectoryItems.data_size == 792
    assert dex.annotationItems.data_size == 642
    assert dex.encodedArrayItems.data_size == 139
    assert dex.debugInfoItems.data_size == 6353
    assert dex.stringDataItems.data_size == 23492
    pass


def dependencies_test():
    import dex_deptracker
    
    deps = dex_deptracker.collect_dependencies()
    assert deps['_DEX_AnnotationItem.typeIdx'][0] == dexfile.depend_idx
    assert deps['_DEX_AnnotationItem.typeIdx'][1] == 'DEXFile.typeIds'
    assert deps['_DEX_FieldId.typeIdx'][0] == dexfile.depend_idx
    assert deps['_DEX_FieldId.typeIdx'][1] == 'DEXFile.typeIds'
    assert deps['_DEX_ClassDef.staticValuesOff'][0] == dexfile.depend_off
    assert deps['_DEX_ClassDef.staticValuesOff'][1] == '_DEX_EncodedArrayItem'
    assert deps['_DEX_Try.handlerOff'][0] == dexfile.depend_off_rel
    assert deps['_DEX_Try.handlerOff'][1] == '_DEX_Catch'
    assert deps['_DEX_Try.handlerOff'][2] == None
    pass