use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_nop.
@Test
public void test_nop() throws Exception {
ProgramState programState = execute(new Instruction(Opcodes.NOP));
assertThat(programState).isEqualTo(ProgramState.EMPTY_STATE);
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_arraylength.
@Test
public void test_arraylength() throws Exception {
SymbolicValue arrayRef = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.ARRAYLENGTH), ProgramState.EMPTY_STATE.stackValue(arrayRef));
SymbolicValue length = programState.peekValue();
assertStack(programState, new Constraint[] { null });
assertThat(length).isNotEqualTo(arrayRef);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.ARRAYLENGTH), ProgramState.EMPTY_STATE)).hasMessage("ARRAYLENGTH needs 1 values on stack");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_monitor_enter_exit.
@Test
public void test_monitor_enter_exit() throws Exception {
int[] opcodes = { Opcodes.MONITORENTER, Opcodes.MONITOREXIT };
for (int opcode : opcodes) {
ProgramState programState = execute(new Instruction(opcode), ProgramState.EMPTY_STATE.stackValue(new SymbolicValue()));
assertEmptyStack(programState);
assertThatThrownBy(() -> execute(new Instruction(opcode))).hasMessage(Printer.OPCODES[opcode] + " needs 1 values on stack");
}
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_checkcast.
@Test
public void test_checkcast() throws Exception {
SymbolicValue objectRef = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.CHECKCAST), ProgramState.EMPTY_STATE.stackValue(objectRef));
assertThat(programState.peekValue()).isEqualTo(objectRef);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.CHECKCAST), ProgramState.EMPTY_STATE)).hasMessage("CHECKCAST needs 1 value on stack");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_iconst.
@Test
public void test_iconst() throws Exception {
ProgramState programState = execute(new Instruction(Opcodes.ICONST_0));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.ZERO, BooleanConstraint.FALSE, ObjectConstraint.NOT_NULL } });
programState = execute(new Instruction(Opcodes.ICONST_1));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, BooleanConstraint.TRUE, ObjectConstraint.NOT_NULL } });
int[] opCodesConst = new int[] { Opcodes.ICONST_M1, Opcodes.ICONST_2, Opcodes.ICONST_3, Opcodes.ICONST_4, Opcodes.ICONST_5 };
for (int opcode : opCodesConst) {
programState = execute(new Instruction(opcode));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL } });
}
}
Aggregations