Search in sources :

Example 1 with BinarySymbolicValue

use of org.sonar.java.se.symbolicvalues.BinarySymbolicValue in project sonar-java by SonarSource.

the class BytecodeEGWalkerExecuteTest method assertBinarySymbolicValue.

private void assertBinarySymbolicValue(int[] opcodes, Class<? extends BinarySymbolicValue> binarySvClass) {
    SymbolicValue sv1 = new SymbolicValue();
    SymbolicValue sv2 = new SymbolicValue();
    ProgramState initState = ProgramState.EMPTY_STATE.stackValue(sv2).stackValue(sv1);
    for (int opcode : opcodes) {
        ProgramState programState = execute(new Instruction(opcode), initState);
        ProgramState.Pop pop = programState.unstackValue(1);
        assertStack(programState, new Constraint[][] { { ObjectConstraint.NOT_NULL } });
        SymbolicValue result = pop.values.get(0);
        assertThat(result).isNotEqualTo(sv1);
        assertThat(result).isNotEqualTo(sv2);
        assertThat(result).isInstanceOf(binarySvClass);
        assertThat(isDoubleOrLong(programState, result)).isEqualTo(LONG_OPCODE.contains(opcode));
        BinarySymbolicValue andSv = (BinarySymbolicValue) result;
        assertThat(andSv.getRightOp()).isEqualTo(sv1);
        assertThat(andSv.getLeftOp()).isEqualTo(sv2);
    }
}
Also used : ProgramState(org.sonar.java.se.ProgramState) Instruction(org.sonar.java.bytecode.cfg.Instruction) BinarySymbolicValue(org.sonar.java.se.symbolicvalues.BinarySymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) BooleanConstraint(org.sonar.java.se.constraint.BooleanConstraint) TypedConstraint(org.sonar.java.se.constraint.TypedConstraint) Constraint(org.sonar.java.se.constraint.Constraint) ObjectConstraint(org.sonar.java.se.constraint.ObjectConstraint) ProgramPoint(org.sonar.java.se.ProgramPoint) BinarySymbolicValue(org.sonar.java.se.symbolicvalues.BinarySymbolicValue)

Aggregations

Instruction (org.sonar.java.bytecode.cfg.Instruction)1 ProgramPoint (org.sonar.java.se.ProgramPoint)1 ProgramState (org.sonar.java.se.ProgramState)1 BooleanConstraint (org.sonar.java.se.constraint.BooleanConstraint)1 Constraint (org.sonar.java.se.constraint.Constraint)1 ObjectConstraint (org.sonar.java.se.constraint.ObjectConstraint)1 TypedConstraint (org.sonar.java.se.constraint.TypedConstraint)1 BinarySymbolicValue (org.sonar.java.se.symbolicvalues.BinarySymbolicValue)1 RelationalSymbolicValue (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)1 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)1