use of org.sonar.java.se.xproc.HappyPathYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_int_comparator.
@Test
public void test_int_comparator() throws Exception {
MethodBehavior methodBehavior = getMethodBehavior("int_comparison(II)Ljava/lang/Object;");
assertThat(methodBehavior.yields()).hasSize(1);
HappyPathYield methodYield = ((HappyPathYield) methodBehavior.yields().get(0));
assertThat(methodYield.resultConstraint().get(ObjectConstraint.class)).isSameAs(ObjectConstraint.NULL);
}
use of org.sonar.java.se.xproc.HappyPathYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method test_enqueueing_of_exit_block4.
@Test
public void test_enqueueing_of_exit_block4() {
MethodBehavior mb = getMethodBehavior(ExceptionEnqueue.class, "enqueueExitBlock4()Z");
List<HappyPathYield> happyPathYields = mb.happyPathYields().collect(Collectors.toList());
assertThat(happyPathYields.get(0).resultConstraint().hasConstraint(BooleanConstraint.TRUE)).isTrue();
assertThat(mb.exceptionalPathYields().findFirst().isPresent()).isFalse();
}
use of org.sonar.java.se.xproc.HappyPathYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerTest method verify_behavior_of_fun2_method.
@Test
public void verify_behavior_of_fun2_method() throws Exception {
MethodBehavior methodBehavior = getMethodBehavior("fun2(Z)Ljava/lang/Object;");
assertThat(methodBehavior.yields()).hasSize(2);
SymbolicValue svFirstArg = new SymbolicValue();
SymbolicValue svResult = new SymbolicValue();
List<SymbolicValue> invocationArguments = Lists.newArrayList(svFirstArg);
List<HappyPathYield> oneYield = methodBehavior.happyPathYields().filter(my -> ObjectConstraint.NULL.equals(my.resultConstraint().get(ObjectConstraint.class))).collect(Collectors.toList());
assertThat(oneYield).hasSize(1);
HappyPathYield yield = oneYield.get(0);
Collection<ProgramState> pss = yield.statesAfterInvocation(invocationArguments, Lists.newArrayList(), ProgramState.EMPTY_STATE, () -> svResult).collect(Collectors.toList());
assertThat(pss).hasSize(1);
ProgramState ps = pss.iterator().next();
assertThat(ps.getConstraint(svFirstArg, ObjectConstraint.class)).isNull();
assertThat(ps.getConstraint(svFirstArg, BooleanConstraint.class)).isSameAs(BooleanConstraint.TRUE);
assertThat(ps.getConstraint(svFirstArg, DivisionByZeroCheck.ZeroConstraint.class)).isNull();
oneYield = methodBehavior.happyPathYields().filter(my -> ObjectConstraint.NOT_NULL.equals(my.resultConstraint().get(ObjectConstraint.class))).collect(Collectors.toList());
assertThat(oneYield).hasSize(1);
yield = oneYield.get(0);
pss = yield.statesAfterInvocation(invocationArguments, Lists.newArrayList(), ProgramState.EMPTY_STATE, () -> svResult).collect(Collectors.toList());
assertThat(pss).hasSize(1);
ps = pss.iterator().next();
assertThat(ps.getConstraint(svFirstArg, ObjectConstraint.class)).isNull();
assertThat(ps.getConstraint(svFirstArg, BooleanConstraint.class)).isSameAs(BooleanConstraint.FALSE);
assertThat(ps.getConstraint(svFirstArg, DivisionByZeroCheck.ZeroConstraint.class)).isNull();
}
use of org.sonar.java.se.xproc.HappyPathYield in project sonar-java by SonarSource.
the class BytecodeEGWalkerExecuteTest method exceptional_paths_should_be_enqueued.
@Test
public void exceptional_paths_should_be_enqueued() {
MethodBehavior mb = walker.getMethodBehavior(BytecodeEGWalkerExecuteTest.class.getCanonicalName() + "#enqueue_exceptional_paths(Lorg/sonar/java/bytecode/se/BytecodeEGWalkerExecuteTest;)Ljava/lang/Object;", squidClassLoader);
assertThat(mb.yields()).hasSize(2);
List<Constraint> resultConstraints = mb.yields().stream().map(y -> ((HappyPathYield) y).resultConstraint()).map(c -> c.get(ObjectConstraint.class)).collect(Collectors.toList());
assertThat(resultConstraints).contains(ObjectConstraint.NOT_NULL, ObjectConstraint.NULL);
}
Aggregations