use of org.jf.dexlib2.base.reference.BaseStringReference in project smali by JesusFreke.
the class InstructionMethodItemTest method testInvalidReference.
@Test
public void testInvalidReference() throws IOException {
Instruction21c instruction = new Instruction21c() {
@Override
public int getRegisterA() {
return 0;
}
@Nonnull
@Override
public Reference getReference() {
return new BaseStringReference() {
@Override
public void validateReference() throws InvalidReferenceException {
throw new InvalidReferenceException("blahblahblah");
}
@Nonnull
@Override
public String getString() {
throw new RuntimeException("invalid reference");
}
};
}
@Override
public int getReferenceType() {
return ReferenceType.STRING;
}
@Override
public Opcode getOpcode() {
return Opcode.CONST_STRING;
}
@Override
public int getCodeUnits() {
return Format.Format21c.size / 2;
}
};
MethodImplementation methodImplementation = new MethodImplementation() {
@Override
public int getRegisterCount() {
return 1;
}
@Nonnull
@Override
public Iterable<? extends Instruction> getInstructions() {
return ImmutableList.of(instruction);
}
@Nonnull
@Override
public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks() {
return ImmutableList.of();
}
@Nonnull
@Override
public Iterable<? extends DebugItem> getDebugItems() {
return ImmutableList.of();
}
};
Method method = new TestMethod(methodImplementation);
ClassDefinition classDefinition = new ClassDefinition(new BaksmaliOptions(), new TestClassDef());
MethodDefinition methodDefinition = new MethodDefinition(classDefinition, method, methodImplementation);
methodDefinition.registerFormatter = new RegisterFormatter(new BaksmaliOptions(), 1, 0);
InstructionMethodItem methodItem = new InstructionMethodItem<Instruction21c>(methodDefinition, 0, instruction);
StringWriter stringWriter = new StringWriter();
BaksmaliWriter writer = new BaksmaliWriter(stringWriter);
methodItem.writeTo(writer);
Assert.assertEquals("#Invalid reference\n#const-string v0, blahblahblah\nnop", stringWriter.toString());
}
Aggregations