Mercurial > paraspace
diff paraspace/tests/dalvik_opcodes_test.py @ 69:d07fd67e2b08
Add dalvik_opcode.py
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 01 Jul 2011 16:19:42 +0800 |
parents | |
children | 16a5a8eb1831 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/paraspace/tests/dalvik_opcodes_test.py Fri Jul 01 16:19:42 2011 +0800 @@ -0,0 +1,39 @@ +from paraspace.dalvik_opcodes import decode_inst, encode_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' + 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