use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_getstatic.
@Test
public void test_getstatic() throws Exception {
ProgramState programState = execute(new Instruction(Opcodes.GETSTATIC, new Instruction.FieldOrMethod("", "", "D", false)));
assertThat(programState.peekValue()).isNotNull();
assertThat(isDoubleOrLong(programState, programState.peekValue())).isTrue();
programState = execute(new Instruction(Opcodes.GETSTATIC, new Instruction.FieldOrMethod("", "", "I", false)));
assertThat(programState.peekValue()).isNotNull();
assertThat(isDoubleOrLong(programState, programState.peekValue())).isFalse();
}
use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_return.
@Test
public void test_return() throws Exception {
ProgramState programState = execute(new Instruction(Opcodes.RETURN), ProgramState.EMPTY_STATE);
assertThat(programState.peekValue()).isNull();
assertThat(programState.exitValue()).isNull();
}
use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_compare_with_zero.
@Test
public void test_compare_with_zero() {
SymbolicValue sv = new SymbolicValue();
int[] opcodes = { Opcodes.IFEQ, Opcodes.IFNE, Opcodes.IFLT, Opcodes.IFGE };
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()).isNotSameAs(sv);
assertThat(programState.getConstraints(relSV.getRightOp()).hasConstraint(DivisionByZeroCheck.ZeroConstraint.ZERO)).isTrue();
}
// these opcodes inverse operator and swap operands
int[] swapOperandsOpcodes = { Opcodes.IFLE, Opcodes.IFGT };
for (int opcode : swapOperandsOpcodes) {
ProgramState programState = walker.branchingState(new Instruction(opcode), ProgramState.EMPTY_STATE.stackValue(sv));
RelationalSymbolicValue relSV = (RelationalSymbolicValue) programState.peekValue();
assertThat(relSV.getRightOp()).isSameAs(sv);
assertThat(relSV.getLeftOp()).isNotSameAs(sv);
assertThat(programState.getConstraints(relSV.getLeftOp()).hasConstraint(DivisionByZeroCheck.ZeroConstraint.ZERO)).isTrue();
}
}
use of org.sonar.java.bytecode.cfg.Instruction 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.bytecode.cfg.Instruction 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);
}
}
Aggregations