use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup_x2_long_double.
@Test
public void test_dup_x2_long_double() throws Exception {
SymbolicValue normalSv = new SymbolicValue();
SymbolicValue longSv = new SymbolicValue();
SymbolicValue another = new SymbolicValue();
ProgramState startingState = ProgramState.EMPTY_STATE.stackValue(another).stackValue(longSv).stackValue(normalSv);
startingState = setDoubleOrLong(startingState, longSv, true);
ProgramState programState = execute(new Instruction(Opcodes.DUP_X2), startingState);
ProgramState.Pop pop = programState.unstackValue(4);
assertThat(pop.values).containsExactly(normalSv, longSv, normalSv, another);
}
use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_newarray.
@Test
public void test_newarray() throws Exception {
SymbolicValue size = new SymbolicValue();
int[] opcodes = { Opcodes.NEWARRAY, Opcodes.ANEWARRAY };
for (int opcode : opcodes) {
ProgramState programState = execute(new Instruction(opcode), ProgramState.EMPTY_STATE.stackValue(size));
assertThat(programState.peekValue()).isNotEqualTo(size);
assertStack(programState, ObjectConstraint.NOT_NULL);
assertThatThrownBy(() -> execute(new Instruction(opcode), ProgramState.EMPTY_STATE)).hasMessage(Printer.OPCODES[opcode] + " needs 1 values on stack");
}
}
use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_dup2_x2_form4.
@Test
public void test_dup2_x2_form4() 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);
startingState = setDoubleOrLong(startingState, sv2, true);
ProgramState programState = execute(new Instruction(Opcodes.DUP2_X2), startingState);
ProgramState.Pop pop = programState.unstackValue(6);
assertThat(pop.values).containsExactly(sv1, sv2, sv1, sv3, sv4);
}
use of org.sonar.java.bytecode.cfg.Instruction in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method test_sipush.
@Test
public void test_sipush() throws Exception {
ProgramState programState = execute(new Instruction(Opcodes.SIPUSH, 42));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL } });
programState = execute(new Instruction(Opcodes.SIPUSH, 1));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.NON_ZERO, ObjectConstraint.NOT_NULL, BooleanConstraint.TRUE } });
programState = execute(new Instruction(Opcodes.SIPUSH, 0));
assertStack(programState, new Constraint[][] { { DivisionByZeroCheck.ZeroConstraint.ZERO, ObjectConstraint.NOT_NULL, BooleanConstraint.FALSE } });
}
use of org.sonar.java.bytecode.cfg.Instruction 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);
}
Aggregations