mirror of
https://github.com/revanced/smali.git
synced 2025-05-05 09:04:25 +02:00
Minor refactoring of simple unit tests, using the same test implementation for all branch target instructions.
This commit is contained in:
parent
e05e01eee0
commit
8309057de3
@ -100,6 +100,10 @@ public class JumboStringConversionTest {
|
|||||||
ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference);
|
ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference);
|
||||||
instructions.add(stringInstr);
|
instructions.add(stringInstr);
|
||||||
|
|
||||||
|
reference = new ImmutableStringReference(mJumboStrings.get(1));
|
||||||
|
stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference);
|
||||||
|
instructions.add(stringInstr);
|
||||||
|
|
||||||
ImmutableInstruction10x nopInstr = new ImmutableInstruction10x(Opcode.NOP);
|
ImmutableInstruction10x nopInstr = new ImmutableInstruction10x(Opcode.NOP);
|
||||||
instructions.add(nopInstr);
|
instructions.add(nopInstr);
|
||||||
|
|
||||||
@ -111,13 +115,18 @@ public class JumboStringConversionTest {
|
|||||||
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
||||||
|
|
||||||
ImmutableInstruction10t gotoInstr = new ImmutableInstruction10t(Opcode.GOTO, 3);
|
ImmutableInstruction10t gotoInstr = new ImmutableInstruction10t(Opcode.GOTO, 3);
|
||||||
instructions.add(0, gotoInstr);
|
instructions.add(1, gotoInstr);
|
||||||
|
|
||||||
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
||||||
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
||||||
|
|
||||||
Instruction10t instruction = (Instruction10t) writeUtil.getInstructions().iterator().next();
|
for (Instruction instr: writeUtil.getInstructions()) {
|
||||||
|
if (instr instanceof Instruction10t) {
|
||||||
|
Instruction10t instruction = (Instruction10t) instr;
|
||||||
Assert.assertEquals("goto (Format10t) target was not modified properly", instruction.getCodeOffset(), 4);
|
Assert.assertEquals("goto (Format10t) target was not modified properly", instruction.getCodeOffset(), 4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -125,13 +134,18 @@ public class JumboStringConversionTest {
|
|||||||
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
||||||
|
|
||||||
ImmutableInstruction20t gotoInstr = new ImmutableInstruction20t(Opcode.GOTO_16, 4);
|
ImmutableInstruction20t gotoInstr = new ImmutableInstruction20t(Opcode.GOTO_16, 4);
|
||||||
instructions.add(0, gotoInstr);
|
instructions.add(1, gotoInstr);
|
||||||
|
|
||||||
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
||||||
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
||||||
|
|
||||||
Instruction20t instruction = (Instruction20t) writeUtil.getInstructions().iterator().next();
|
for (Instruction instr: writeUtil.getInstructions()) {
|
||||||
|
if (instr instanceof Instruction20t) {
|
||||||
|
Instruction20t instruction = (Instruction20t) instr;
|
||||||
Assert.assertEquals("goto/16 (Format20t) target was not modified properly", instruction.getCodeOffset(), 5);
|
Assert.assertEquals("goto/16 (Format20t) target was not modified properly", instruction.getCodeOffset(), 5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -139,13 +153,18 @@ public class JumboStringConversionTest {
|
|||||||
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
||||||
|
|
||||||
ImmutableInstruction30t gotoInstr = new ImmutableInstruction30t(Opcode.GOTO_32, 5);
|
ImmutableInstruction30t gotoInstr = new ImmutableInstruction30t(Opcode.GOTO_32, 5);
|
||||||
instructions.add(0, gotoInstr);
|
instructions.add(1, gotoInstr);
|
||||||
|
|
||||||
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
||||||
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
||||||
|
|
||||||
Instruction30t instruction = (Instruction30t) writeUtil.getInstructions().iterator().next();
|
for (Instruction instr: writeUtil.getInstructions()) {
|
||||||
|
if (instr instanceof Instruction30t) {
|
||||||
|
Instruction30t instruction = (Instruction30t) instr;
|
||||||
Assert.assertEquals("goto/32 (Format30t) target was not modified properly", instruction.getCodeOffset(), 6);
|
Assert.assertEquals("goto/32 (Format30t) target was not modified properly", instruction.getCodeOffset(), 6);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -153,12 +172,7 @@ public class JumboStringConversionTest {
|
|||||||
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
||||||
|
|
||||||
ImmutableInstruction21t branchInstr = new ImmutableInstruction21t(Opcode.IF_EQZ, 0, 4);
|
ImmutableInstruction21t branchInstr = new ImmutableInstruction21t(Opcode.IF_EQZ, 0, 4);
|
||||||
instructions.add(0, branchInstr);
|
instructions.add(1, branchInstr);
|
||||||
|
|
||||||
// jam a jumbo string before the branch target instruction, to make sure that relative offset is modified
|
|
||||||
ImmutableStringReference reference = new ImmutableStringReference(mJumboStrings.get(1));
|
|
||||||
ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference);
|
|
||||||
instructions.add(0, stringInstr);
|
|
||||||
|
|
||||||
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
||||||
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
||||||
@ -177,12 +191,7 @@ public class JumboStringConversionTest {
|
|||||||
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
||||||
|
|
||||||
ImmutableInstruction22t branchInstr = new ImmutableInstruction22t(Opcode.IF_EQ, 0, 1, 4);
|
ImmutableInstruction22t branchInstr = new ImmutableInstruction22t(Opcode.IF_EQ, 0, 1, 4);
|
||||||
instructions.add(0, branchInstr);
|
instructions.add(1, branchInstr);
|
||||||
|
|
||||||
// jam a jumbo string before the branch target instruction, to make sure that relative offset is modified
|
|
||||||
ImmutableStringReference reference = new ImmutableStringReference(mJumboStrings.get(1));
|
|
||||||
ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference);
|
|
||||||
instructions.add(0, stringInstr);
|
|
||||||
|
|
||||||
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
||||||
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
||||||
@ -201,12 +210,7 @@ public class JumboStringConversionTest {
|
|||||||
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
ArrayList<ImmutableInstruction> instructions = createSimpleInstructionList();
|
||||||
|
|
||||||
ImmutableInstruction31t branchInstr = new ImmutableInstruction31t(Opcode.PACKED_SWITCH, 0, 5);
|
ImmutableInstruction31t branchInstr = new ImmutableInstruction31t(Opcode.PACKED_SWITCH, 0, 5);
|
||||||
instructions.add(0, branchInstr);
|
instructions.add(1, branchInstr);
|
||||||
|
|
||||||
// jam a jumbo string before the branch target instruction, to make sure that relative offset is modified
|
|
||||||
ImmutableStringReference reference = new ImmutableStringReference(mJumboStrings.get(1));
|
|
||||||
ImmutableInstruction21c stringInstr = new ImmutableInstruction21c(Opcode.CONST_STRING, 0, reference);
|
|
||||||
instructions.add(0, stringInstr);
|
|
||||||
|
|
||||||
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
ImmutableMethodImplementation methodImplementation = new ImmutableMethodImplementation(1, instructions, null, null);
|
||||||
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
InstructionWriteUtil writeUtil = new InstructionWriteUtil(methodImplementation, mStringPool);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user