use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup2_long_double.
@Test
public void test_dup2_long_double() throws Exception {
SymbolicValue longSv = new SymbolicValue();
SymbolicValue another = new SymbolicValue();
ProgramState startingState = ProgramState.EMPTY_STATE.stackValue(another).stackValue(longSv);
startingState = setDoubleOrLong(startingState, longSv, true);
ProgramState programState = execute(new Instruction(Opcodes.DUP2), startingState);
ProgramState.Pop pop = programState.unstackValue(4);
assertThat(pop.values).containsExactly(longSv, longSv, another);
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_store.
@Test
public void test_store() throws Exception {
int[] storeOpcodes = new int[] { Opcodes.ISTORE, Opcodes.LSTORE, Opcodes.FSTORE, Opcodes.DSTORE, Opcodes.ASTORE };
SymbolicValue sv = new SymbolicValue();
ProgramState startState = ProgramState.EMPTY_STATE.stackValue(sv);
for (int opcode : storeOpcodes) {
ProgramState programState = execute(new Instruction(opcode, 67), startState);
assertThat(programState.getValue(67)).isEqualTo(sv);
}
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_fconst.
@Test
public void test_fconst() throws Exception {
ProgramState programState = execute(new Instruction(Opcodes.FCONST_0));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.ZERO, BooleanConstraint.FALSE, ObjectConstraint.NOT_NULL } });
programState = execute(new Instruction(Opcodes.FCONST_1));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, BooleanConstraint.TRUE, ObjectConstraint.NOT_NULL } });
programState = execute(new Instruction(Opcodes.FCONST_2));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL } });
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_invoke_dynamic.
@Test
public void test_invoke_dynamic() throws Exception {
SymbolicValue lambdaArg = new SymbolicValue();
ProgramState programState = execute(new Instruction.InvokeDynamicInsn("(I)Ljava/util/function/Supplier;"), ProgramState.EMPTY_STATE.stackValue(lambdaArg));
assertStack(programState, ObjectConstraint.NOT_NULL);
assertThat(programState.peekValue()).isNotEqualTo(lambdaArg);
programState = execute(new Instruction.InvokeDynamicInsn("()Ljava/util/function/Supplier;"), ProgramState.EMPTY_STATE);
assertStack(programState, ObjectConstraint.NOT_NULL);
assertThatThrownBy(() -> execute(new Instruction.InvokeDynamicInsn("()V"), ProgramState.EMPTY_STATE)).hasMessage("Lambda should always evaluate to target functional interface");
}
use of org.sonar.java.se.ProgramState in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_pop.
@Test
public void test_pop() throws Exception {
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
ProgramState programState = execute(new Instruction(Opcodes.POP), ProgramState.EMPTY_STATE.stackValue(sv1).stackValue(sv2));
assertThat(programState.peekValue()).isEqualTo(sv1);
programState = execute(new Instruction(Opcodes.POP));
assertEmptyStack(programState);
}
Aggregations