use of org.jf.dexlib2.iface.instruction.formats.PackedSwitchPayload in project smali by JesusFreke.
the class SmalideaMethodTest method testPackedSwitch.
public void testPackedSwitch() {
String text = ".class public LFormat31t;\n" + ".super Ljava/lang/Object;\n" + ".source \"Format31t.smali\"" + "\n" + ".method public test_packed-switch()V\n" + " .registers 1\n" + " .annotation runtime Lorg/junit/Test;\n" + " .end annotation\n" + "\n" + " const v0, 12\n" + "\n" + ":switch\n" + " packed-switch v0, :PackedSwitch\n" + "\n" + ":Label10\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":Label11\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":Label12\n" + " return-void\n" + "\n" + ":Label13\n" + " invoke-static {}, Lorg/junit/Assert;->fail()V\n" + " return-void\n" + "\n" + ":PackedSwitch\n" + " .packed-switch 10\n" + " :Label10\n" + " :Label11\n" + " :Label12\n" + " :Label13\n" + " .end packed-switch\n" + ".end method";
SmaliFile file = (SmaliFile) myFixture.addFileToProject("my/pkg/blah.smali", text);
SmaliClass smaliClass = file.getPsiClass();
SmaliMethod smaliMethod = smaliClass.getMethods()[0];
SmalideaMethod method = new SmalideaMethod(smaliMethod);
MethodImplementation impl = method.getImplementation();
Assert.assertNotNull(impl);
List<Instruction> instructions = Lists.newArrayList(impl.getInstructions());
PackedSwitchPayload packedSwitchPayload = (PackedSwitchPayload) instructions.get(9);
List<? extends SwitchElement> switchElements = packedSwitchPayload.getSwitchElements();
Assert.assertEquals(4, switchElements.size());
checkSwitchElement(switchElements.get(0), 10, 6);
checkSwitchElement(switchElements.get(1), 11, 14);
checkSwitchElement(switchElements.get(2), 12, 22);
checkSwitchElement(switchElements.get(3), 13, 24);
}
Aggregations