Mercurial > paraspace
annotate 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 |
rev | line source |
---|---|
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
1 from paraspace.dalvik_opcodes import decode_inst, encode_inst, format_inst |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
2 |
69 | 3 |
4 def encode_inst_test(): | |
5 opv = (0x90, (00, 02, 03)) | |
6 insn = encode_inst(opv) | |
7 assert len(insn) == 4 | |
8 assert insn == '\x90\00\02\03' | |
9 | |
10 opv = (0x59, (0, 2, 0x0002)) | |
11 insn = encode_inst(opv) | |
12 assert insn == '\x59\x20\x02\x00' | |
13 | |
14 opv = (0x6f, (0, 1, 0xa601, 1, 0, 0, 0)) | |
15 insn = encode_inst(opv) | |
16 assert insn == '\x6f\x10\x01\xa6\x01\x00' | |
73
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
17 |
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
18 opv = (0, ()) |
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
19 insn = encode_inst(opv) |
6d56483b56cd
Round size of encoded Dalvik instructions to 2 times.
Thinker K.F. Li <thinker@codemud.net>
parents:
72
diff
changeset
|
20 assert insn == '\x00\x00' |
69 | 21 pass |
22 | |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
23 |
69 | 24 def decode_inst_test(): |
25 insn = '\x90\00\02\03' | |
26 opv = decode_inst(insn) | |
27 opcode, args = opv | |
28 assert opcode == 0x90 | |
29 assert len(args) == 3 | |
30 assert args == (0, 2, 3) | |
31 | |
32 insn = '\x59\x20\x02\x00' | |
33 opv = decode_inst(insn) | |
34 opcode, args = opv | |
35 assert opcode == 0x59 | |
36 assert len(args) == 3 | |
37 assert args == (0, 2, 0x0002) | |
38 | |
39 insn = '\x6f\x10\x01\xa6\x01\x00' | |
40 opv = decode_inst(insn) | |
41 opcode, args = opv | |
42 assert opcode == 0x6f | |
43 assert len(args) == 7 | |
44 assert args == (0, 1, 0xa601, 1, 0, 0, 0) | |
45 pass | |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
46 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
47 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
48 def format_inst_test(): |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
49 opv = (0x90, (0, 2, 3)) |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
50 line = format_inst(opv) |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
51 assert line == 'OP_ADD_INT v0, v2, v3' |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
52 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
53 opv = (0x59, (0, 2, 0x0002)) |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
54 line = format_inst(opv) |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
55 assert line == 'OP_IPUT v0, v2, thing@0002' |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
56 |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
57 opv = (0x6f, (0, 1, 0xa601, 1, 0, 0, 0)) |
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
58 line = format_inst(opv) |
71 | 59 assert line == 'OP_INVOKE_SUPER {v1, v0, v0, v0, v0},' \ |
91
a33dfe2dae9d
Fix testcase to match changes of format strings
Thinker K.F. Li <thinker@codemud.net>
parents:
73
diff
changeset
|
60 ' meth@a601 (1: count, A: vG)' |
72
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
71
diff
changeset
|
61 |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
71
diff
changeset
|
62 opv = (0, ()) |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
71
diff
changeset
|
63 line = format_inst(opv) |
6c2efdeffa7b
Strip instruction string for opcode with no any argument.
Thinker K.F. Li <thinker@codemud.net>
parents:
71
diff
changeset
|
64 assert line == 'OP_NOP' |
70
16a5a8eb1831
Add format_inst() in dalvik_opcodes.py
Thinker K.F. Li <thinker@codemud.net>
parents:
69
diff
changeset
|
65 pass |