use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_ldc.
@Test
public void test_ldc() throws Exception {
ProgramState programState = execute(new Instruction.LdcInsn("a"));
assertStack(programState, ObjectConstraint.NOT_NULL);
SymbolicValue sv = programState.peekValue();
assertThat(isDoubleOrLong(programState, sv)).isFalse();
programState = execute(new Instruction.LdcInsn(1L));
sv = programState.peekValue();
assertThat(isDoubleOrLong(programState, sv)).isTrue();
programState = execute(new Instruction.LdcInsn(1D));
sv = programState.peekValue();
assertThat(isDoubleOrLong(programState, sv)).isTrue();
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup2_x2.
@Test
public void test_dup2_x2() throws Exception {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
SymbolicValue sv3 = new SymbolicValue();
SymbolicValue sv4 = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.DUP2_X2), ProgramState.EMPTY_STATE.stackValue(sv4).stackValue(sv3).stackValue(sv2).stackValue(sv1));
ProgramState.Pop pop = programState.unstackValue(6);
assertThat(pop.values).containsExactly(sv1, sv2, sv3, sv4, sv1, sv2);
assertThat(pop.state).isEqualTo(ProgramState.EMPTY_STATE);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.DUP2_X2), ProgramState.EMPTY_STATE.stackValue(sv1).stackValue(sv2).stackValue(sv3))).hasMessage("DUP2_X2 needs 4 values on stack");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_xReturn.
@Test
public void test_xReturn() throws Exception {
SymbolicValue returnValue = new SymbolicValue();
int[] opcodes = { Opcodes.IRETURN, Opcodes.LRETURN, Opcodes.FRETURN, Opcodes.DRETURN, Opcodes.ARETURN };
for (int opcode : opcodes) {
ProgramState programState = execute(new Instruction(opcode), ProgramState.EMPTY_STATE.stackValue(returnValue));
assertThat(programState.peekValue()).isNull();
assertThat(programState.exitValue()).isEqualTo(returnValue);
}
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup2_x2_form2.
// see https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.dup2_x2
@Test
public void test_dup2_x2_form2() throws Exception {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
SymbolicValue sv3 = new SymbolicValue();
SymbolicValue sv4 = new SymbolicValue();
ProgramState startingState = ProgramState.EMPTY_STATE.stackValue(sv4).stackValue(sv3).stackValue(sv2).stackValue(sv1);
startingState = setDoubleOrLong(startingState, sv1, true);
ProgramState programState = execute(new Instruction(Opcodes.DUP2_X2), startingState);
ProgramState.Pop pop = programState.unstackValue(6);
assertThat(pop.values).containsExactly(sv1, sv2, sv3, sv1, sv4);
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup2.
@Test
public void test_dup2() throws Exception {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.DUP2), ProgramState.EMPTY_STATE.stackValue(sv2).stackValue(sv1));
ProgramState.Pop pop = programState.unstackValue(4);
assertThat(pop.values).containsExactly(sv1, sv2, sv1, sv2);
assertThat(pop.state).isEqualTo(ProgramState.EMPTY_STATE);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.DUP2))).hasMessage("DUP2 needs at least 1 value on stack");
}
Aggregations