use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_pop2.
@Test
public void test_pop2() throws Exception {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
SymbolicValue sv3 = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.POP2), ProgramState.EMPTY_STATE.stackValue(sv1).stackValue(sv2).stackValue(sv3));
assertThat(programState.peekValue()).isEqualTo(sv1);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.POP2))).hasMessage("POP2 on empty stack");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_compare_with_null.
@Test
public void test_compare_with_null() {
SymbolicValue sv = new SymbolicValue();
int[] opcodes = { Opcodes.IFNULL, Opcodes.IFNONNULL };
for (int opcode : opcodes) {
ProgramState programState = walker.branchingState(new Instruction(opcode), ProgramState.EMPTY_STATE.stackValue(sv));
RelationalSymbolicValue relSV = (RelationalSymbolicValue) programState.peekValue();
assertThat(relSV.getLeftOp()).isSameAs(sv);
assertThat(relSV.getRightOp()).isSameAs(SymbolicValue.NULL_LITERAL);
}
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup.
@Test
public void test_dup() throws Exception {
SymbolicValue sv = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.DUP), ProgramState.EMPTY_STATE.stackValue(sv));
ProgramState.Pop pop = programState.unstackValue(2);
assertThat(pop.values).containsOnly(sv);
assertThat(pop.state).isEqualTo(ProgramState.EMPTY_STATE);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.DUP))).hasMessage("DUP on empty stack");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup2_x1.
@Test
public void test_dup2_x1() throws Exception {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
SymbolicValue sv3 = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.DUP2_X1), ProgramState.EMPTY_STATE.stackValue(sv3).stackValue(sv2).stackValue(sv1));
ProgramState.Pop pop = programState.unstackValue(5);
assertThat(pop.values).containsExactly(sv1, sv2, sv3, sv1, sv2);
assertThat(pop.state).isEqualTo(ProgramState.EMPTY_STATE);
assertThatThrownBy(() -> execute(new Instruction(Opcodes.DUP2_X1), ProgramState.EMPTY_STATE.stackValue(sv1))).hasMessage("DUP2_X1 needs 3 values on stack");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_putfield.
@Test
public void test_putfield() throws Exception {
SymbolicValue objectRef = new SymbolicValue();
SymbolicValue value = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.PUTFIELD), ProgramState.EMPTY_STATE.stackValue(objectRef).stackValue(value));
assertThat(programState.peekValue()).isNull();
assertThatThrownBy(() -> execute(new Instruction(Opcodes.PUTFIELD), ProgramState.EMPTY_STATE.stackValue(value))).hasMessage("PUTFIELD needs 2 values on stack");
}
Aggregations