Search in sources :

Example 1 with Pop

use of org.sonar.java.se.ProgramState.Pop in project sonar-java by SonarSource.

the class ProgramStateTest method test_symbols_on_stack.

@Test
public void test_symbols_on_stack() {
    ProgramState ps = ProgramState.EMPTY_STATE;
    SymbolicValue sv = new SymbolicValue();
    JavaSymbol.VariableJavaSymbol symbol = variable("a");
    ps = ps.stackValue(sv, symbol);
    Pop pop = ps.unstackValue(1);
    assertThat(ps.peekValue()).isEqualTo(sv);
    assertThat(ps.peekValueSymbol().symbol()).isEqualTo(symbol);
    assertThat(pop.valuesAndSymbols.get(0).symbol()).isEqualTo(symbol);
    assertThat(pop.valuesAndSymbols.get(0).symbolicValue()).isEqualTo(sv);
}
Also used : Pop(org.sonar.java.se.ProgramState.Pop) JavaSymbol(org.sonar.java.resolve.JavaSymbol) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Example 2 with Pop

use of org.sonar.java.se.ProgramState.Pop 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);
}
Also used : Pop(org.sonar.java.se.ProgramState.Pop) RelationalSymbolicValue(org.sonar.java.se.symbolicvalues.RelationalSymbolicValue) SymbolicValue(org.sonar.java.se.symbolicvalues.SymbolicValue) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Pop (org.sonar.java.se.ProgramState.Pop)2 RelationalSymbolicValue (org.sonar.java.se.symbolicvalues.RelationalSymbolicValue)2 SymbolicValue (org.sonar.java.se.symbolicvalues.SymbolicValue)2 JavaSymbol (org.sonar.java.resolve.JavaSymbol)1