use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method test_adding_constraint_transitively.
@Test
public void test_adding_constraint_transitively() throws Exception {
ProgramState ps = ProgramState.EMPTY_STATE;
SymbolicValue sv1 = new SymbolicValue();
SymbolicValue sv2 = new SymbolicValue();
RelationalSymbolicValue relSV = new RelationalSymbolicValue(RelationalSymbolicValue.Kind.EQUAL);
SymbolicValueTestUtil.computedFrom(relSV, sv1, sv2);
ps = ps.addConstraint(relSV, BooleanConstraint.TRUE);
UnclosedResourcesCheck.ResourceConstraint constraint = UnclosedResourcesCheck.ResourceConstraint.OPEN;
ps = ps.addConstraintTransitively(sv1, constraint);
assertThat(ps.getConstraint(sv2, constraint.getClass())).isEqualTo(constraint);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method test_peek_nth_value.
@Test
public void test_peek_nth_value() {
ProgramState state = ProgramState.EMPTY_STATE;
ProgramState finalState = state;
assertThatThrownBy(() -> finalState.peekValue(0)).isInstanceOf(IllegalStateException.class);
SymbolicValue sv1 = new SymbolicValue();
state = state.stackValue(sv1);
assertThat(state.peekValue(0)).isEqualTo(sv1);
SymbolicValue sv2 = new SymbolicValue();
state = state.stackValue(sv2);
assertThat(state.peekValue(1)).isEqualTo(sv1);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method test_symbol_should_not_change_equals.
@Test
public void test_symbol_should_not_change_equals() throws Exception {
ProgramState ps1 = ProgramState.EMPTY_STATE;
ProgramState ps2 = ProgramState.EMPTY_STATE;
SymbolicValue sv = new SymbolicValue();
JavaSymbol.VariableJavaSymbol symbol = variable("a");
ps1 = ps1.stackValue(sv);
ps2 = ps2.stackValue(sv, symbol);
assertThat(ps1).isEqualTo(ps2);
assertThat(ImmutableSet.of(ps1, ps2)).hasSize(1);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class ProgramStateTest method testStackUnstack.
@Test
public void testStackUnstack() {
SymbolicValue sv1 = new SymbolicValue();
ProgramState state = ProgramState.EMPTY_STATE.stackValue(sv1);
assertThat(state.peekValue()).isSameAs(sv1);
SymbolicValue sv2 = new SymbolicValue();
state = state.stackValue(sv2);
List<SymbolicValue> values = state.peekValues(2);
assertThat(values).hasSize(2).containsSequence(sv2, sv1);
try {
state.peekValues(3);
Assert.fail("Able to retrieve more values than there are actually on the stack!");
} catch (IllegalStateException e) {
// Expected behavior
}
Pop unstack = state.unstackValue(1);
state = unstack.state;
values = unstack.values;
assertThat(values).hasSize(1);
assertThat(values.get(0)).isSameAs(sv2);
assertThat(state.peekValue()).isSameAs(sv1);
}
use of org.sonar.java.se.symbolicvalues.SymbolicValue in project sonar-java by SonarSource.
the class DivisionByZeroCheckTest method test_zero_constraint_copy.
@Test
public void test_zero_constraint_copy() throws Exception {
SymbolicValue a = new SymbolicValue();
SymbolicValue b = new SymbolicValue();
DivisionByZeroCheck.ZeroConstraint bConstraint = copyConstraint(a, b, EQUAL, ZERO);
assertThat(bConstraint).isEqualTo(ZERO);
bConstraint = copyConstraint(a, b, NOT_EQUAL, NON_ZERO);
assertThat(bConstraint).isEqualTo(NON_ZERO);
bConstraint = copyConstraint(a, b, LESS_THAN, NON_ZERO);
assertThat(bConstraint).isEqualTo(NON_ZERO);
bConstraint = copyConstraint(a, b, GREATER_THAN_OR_EQUAL, null);
assertThat(bConstraint).isNull();
}
Aggregations