From c995fb5086a1a2989baf3680c1f4ba1c1f697dda Mon Sep 17 00:00:00 2001 From: Izzat Bahadirov Date: Mon, 25 Mar 2013 17:59:21 -0400 Subject: [PATCH] Unit tests for goto and goto/16 instructions embiggening. --- .../writer/JumboStringConversionTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/dexlib2/src/test/java/org/jf/dexlib2/writer/JumboStringConversionTest.java b/dexlib2/src/test/java/org/jf/dexlib2/writer/JumboStringConversionTest.java index 6244d96a..abef9af8 100644 --- a/dexlib2/src/test/java/org/jf/dexlib2/writer/JumboStringConversionTest.java +++ b/dexlib2/src/test/java/org/jf/dexlib2/writer/JumboStringConversionTest.java @@ -337,4 +337,51 @@ public class JumboStringConversionTest { codeOffset += instr.getCodeUnits(); } } + + @Test + public void testGotoToGoto16() { + ArrayList instructions = Lists.newArrayList(); + + ImmutableInstruction10t gotoInstr = new ImmutableInstruction10t(Opcode.GOTO, 127); + instructions.add(gotoInstr); + + ImmutableStringReference reference = new ImmutableStringReference(mJumboStrings.get(0)); + ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference); + instructions.add(stringInstr); + + for (int i=0;i<127;i++) { + ImmutableInstruction10x nopInstr = new ImmutableInstruction10x(Opcode.NOP); + instructions.add(nopInstr); + } + + ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null); + InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool); + + Instruction instr = writeUtil.getInstructions().iterator().next(); + Assert.assertEquals("goto was not converted to goto/16 properly", instr.getOpcode(), Opcode.GOTO_16); + } + + @Test + public void testGoto16ToGoto32() { + ArrayList instructions = Lists.newArrayList(); + + ImmutableInstruction20t gotoInstr = new ImmutableInstruction20t(Opcode.GOTO_16, Short.MAX_VALUE); + instructions.add(gotoInstr); + + ImmutableStringReference reference = new ImmutableStringReference(mJumboStrings.get(0)); + ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference); + instructions.add(stringInstr); + + for (int i=0;i