use of org.jf.dexlib2.iface.ExceptionHandler in project smali by JesusFreke.
the class TryListBuilderTest method testHandlerMerge_Same.
@Test
public void testHandlerMerge_Same() {
TryListBuilder tlb = new TryListBuilder();
tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5));
tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException1;", 5));
List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks();
List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(0, 15, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5))));
Assert.assertEquals(expected, tryBlocks);
}
use of org.jf.dexlib2.iface.ExceptionHandler in project smali by JesusFreke.
the class TryListBuilderTest method testOverlap_Before_After.
@Test
public void testOverlap_Before_After() {
TryListBuilder tlb = new TryListBuilder();
tlb.addHandler(5, 10, new ImmutableExceptionHandler("LException1;", 5));
tlb.addHandler(0, 15, new ImmutableExceptionHandler("LException2;", 6));
List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks();
List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(0, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(10, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))));
Assert.assertEquals(expected, tryBlocks);
}
use of org.jf.dexlib2.iface.ExceptionHandler in project smali by JesusFreke.
the class TryListBuilderTest method testOverlap_Middle_After.
@Test
public void testOverlap_Middle_After() {
TryListBuilder tlb = new TryListBuilder();
tlb.addHandler(0, 10, new ImmutableExceptionHandler("LException1;", 5));
tlb.addHandler(5, 15, new ImmutableExceptionHandler("LException2;", 6));
List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks();
List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(0, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5))), new ImmutableTryBlock(5, 5, ImmutableList.of(new ImmutableExceptionHandler("LException1;", 5), new ImmutableExceptionHandler("LException2;", 6))), new ImmutableTryBlock(10, 5, ImmutableList.of(new ImmutableExceptionHandler("LException2;", 6))));
Assert.assertEquals(expected, tryBlocks);
}
use of org.jf.dexlib2.iface.ExceptionHandler in project smali by JesusFreke.
the class TryListBuilderTest method testHandlerMerge_Catchall_Catchall.
@Test
public void testHandlerMerge_Catchall_Catchall() {
TryListBuilder tlb = new TryListBuilder();
tlb.addHandler(5, 10, new ImmutableExceptionHandler(null, 5));
tlb.addHandler(0, 15, new ImmutableExceptionHandler(null, 5));
List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = tlb.getTryBlocks();
List<? extends TryBlock> expected = ImmutableList.of(new ImmutableTryBlock(0, 15, ImmutableList.of(new ImmutableExceptionHandler(null, 5))));
Assert.assertEquals(expected, tryBlocks);
}
use of org.jf.dexlib2.iface.ExceptionHandler in project smali by JesusFreke.
the class FixOffsetsTest method testFixOffsets.
@Test
public void testFixOffsets() {
MethodImplementationBuilder builder = new MethodImplementationBuilder(1);
Label firstGotoTarget = builder.getLabel("firstGotoTarget");
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, firstGotoTarget));
builder.addLineNumber(1);
for (int i = 0; i < 250; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLabel("tryStart");
builder.addLineNumber(2);
for (int i = 0; i < 250; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLineNumber(3);
Label secondGotoTarget = builder.getLabel("secondGotoTarget");
builder.addInstruction(new BuilderInstruction10t(Opcode.GOTO, secondGotoTarget));
builder.addLineNumber(4);
builder.addLabel("handler");
for (int i = 0; i < 500; i++) {
builder.addInstruction(new BuilderInstruction10x(Opcode.NOP));
}
builder.addLineNumber(5);
builder.addLabel("tryEnd");
builder.addLabel("firstGotoTarget");
builder.addLabel("secondGotoTarget");
builder.addInstruction(new BuilderInstruction10x(Opcode.RETURN_VOID));
Label tryStart = builder.getLabel("tryStart");
Label tryEnd = builder.getLabel("tryEnd");
Label handler = builder.getLabel("handler");
builder.addCatch(tryStart, tryEnd, handler);
MethodImplementation impl = builder.getMethodImplementation();
List<? extends Instruction> instructions = Lists.newArrayList(impl.getInstructions());
Assert.assertEquals(1003, instructions.size());
Assert.assertEquals(Opcode.GOTO_16, instructions.get(0).getOpcode());
Assert.assertEquals(1004, ((OffsetInstruction) instructions.get(0)).getCodeOffset());
Assert.assertEquals(Opcode.GOTO_16, instructions.get(501).getOpcode());
Assert.assertEquals(502, ((OffsetInstruction) instructions.get(501)).getCodeOffset());
List<? extends TryBlock<? extends ExceptionHandler>> exceptionHandlers = impl.getTryBlocks();
Assert.assertEquals(1, exceptionHandlers.size());
Assert.assertEquals(252, exceptionHandlers.get(0).getStartCodeAddress());
Assert.assertEquals(752, exceptionHandlers.get(0).getCodeUnitCount());
Assert.assertEquals(1, exceptionHandlers.get(0).getExceptionHandlers().size());
ExceptionHandler exceptionHandler = exceptionHandlers.get(0).getExceptionHandlers().get(0);
Assert.assertEquals(504, exceptionHandler.getHandlerCodeAddress());
List<DebugItem> debugItems = Lists.newArrayList(impl.getDebugItems());
Assert.assertEquals(5, debugItems.size());
Assert.assertEquals(1, ((LineNumber) debugItems.get(0)).getLineNumber());
Assert.assertEquals(2, debugItems.get(0).getCodeAddress());
Assert.assertEquals(2, ((LineNumber) debugItems.get(1)).getLineNumber());
Assert.assertEquals(252, debugItems.get(1).getCodeAddress());
Assert.assertEquals(3, ((LineNumber) debugItems.get(2)).getLineNumber());
Assert.assertEquals(502, debugItems.get(2).getCodeAddress());
Assert.assertEquals(4, ((LineNumber) debugItems.get(3)).getLineNumber());
Assert.assertEquals(504, debugItems.get(3).getCodeAddress());
Assert.assertEquals(5, ((LineNumber) debugItems.get(4)).getLineNumber());
Assert.assertEquals(1004, debugItems.get(4).getCodeAddress());
}
Aggregations