view paraspace/tests/dalvik_opcodes_test.py @ 143:c56c7cf32b88

Remove useless code
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 15 Aug 2011 10:08:43 +0800
parents a33dfe2dae9d
children
line wrap: on
line source

from paraspace.dalvik_opcodes import decode_inst, encode_inst, format_inst


def encode_inst_test():
    opv = (0x90, (00, 02, 03))
    insn = encode_inst(opv)
    assert len(insn) == 4
    assert insn == '\x90\00\02\03'

    opv = (0x59, (0, 2, 0x0002))
    insn = encode_inst(opv)
    assert insn == '\x59\x20\x02\x00'

    opv = (0x6f, (0, 1, 0xa601, 1, 0, 0, 0))
    insn = encode_inst(opv)
    assert insn == '\x6f\x10\x01\xa6\x01\x00'
    
    opv = (0, ())
    insn = encode_inst(opv)
    assert insn == '\x00\x00'
    pass


def decode_inst_test():
    insn = '\x90\00\02\03'
    opv = decode_inst(insn)
    opcode, args = opv
    assert opcode == 0x90
    assert len(args) == 3
    assert args == (0, 2, 3)

    insn = '\x59\x20\x02\x00'
    opv = decode_inst(insn)
    opcode, args = opv
    assert opcode == 0x59
    assert len(args) == 3
    assert args == (0, 2, 0x0002)
    
    insn = '\x6f\x10\x01\xa6\x01\x00'
    opv = decode_inst(insn)
    opcode, args = opv
    assert opcode == 0x6f
    assert len(args) == 7
    assert args == (0, 1, 0xa601, 1, 0, 0, 0)
    pass


def format_inst_test():
    opv = (0x90, (0, 2, 3))
    line = format_inst(opv)
    assert line == 'OP_ADD_INT v0, v2, v3'

    opv = (0x59, (0, 2, 0x0002))
    line = format_inst(opv)
    assert line == 'OP_IPUT v0, v2, thing@0002'

    opv = (0x6f, (0, 1, 0xa601, 1, 0, 0, 0))
    line = format_inst(opv)
    assert line == 'OP_INVOKE_SUPER {v1, v0, v0, v0, v0},' \
        ' meth@a601 (1: count, A: vG)'

    opv = (0, ())
    line = format_inst(opv)
    assert line == 'OP_NOP'
    pass