use of org.yakindu.sct.model.sexec.Reaction in project statecharts by Yakindu.
the class ModelSequencerOrthogonalityTest method testSiblingRegionExitFromSourceState.
/*
* --------------------------------------------------------------------------
* ----------------- Exit behavior tests
* ------------------------------------
* -------------------------------------------------------
*/
/**
* The transition from a leaf state with orthogonal siblings must invoke the
* exit sequence of the orthogonal sibling regions.
*/
@SuppressWarnings("unused")
@Test
public void testSiblingRegionExitFromSourceState() {
Statechart sc = _createStatechart("sc");
{
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
Region r = _createRegion("r", sc);
{
Entry r_entry = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
{
Region r2 = _createRegion("r2", s1);
{
Entry r2_entry = _createEntry(EntryKind.INITIAL, null, r2);
State s2 = _createState("s2", r2);
_createTransition(r2_entry, s2);
State s2b = _createState("s2b", r2);
}
Region r3 = _createRegion("r3", s1);
{
Entry r3_entry = _createEntry(EntryKind.INITIAL, null, r3);
State s3 = _createState("s3", r3);
_createTransition(r3_entry, s3);
}
Region r4 = _createRegion("r4", s1);
{
Entry r4_entry = _createEntry(EntryKind.INITIAL, null, r4);
State s4 = _createState("s4", r4);
_createTransition(r4_entry, s4);
State s4b = _createState("s4b", r4);
}
}
_createTransition(r_entry, s1);
State s5 = _createState("s5", r);
_createTransition(findState(sc, "s3"), s5);
}
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
assertEquals("sc.r.s1", _s1.getName());
ExecutionState _s2 = flow.getStates().get(1);
assertEquals("sc.r.s1.r2.s2", _s2.getName());
ExecutionState _s2b = flow.getStates().get(2);
assertEquals("sc.r.s1.r2.s2b", _s2b.getName());
ExecutionState _s3 = flow.getStates().get(3);
assertEquals("sc.r.s1.r3.s3", _s3.getName());
ExecutionState _s4 = flow.getStates().get(4);
assertEquals("sc.r.s1.r4.s4", _s4.getName());
ExecutionState _s4b = flow.getStates().get(5);
assertEquals("sc.r.s1.r4.s4b", _s4b.getName());
ExecutionState _s5 = flow.getStates().get(6);
assertEquals("sc.r.s5", _s5.getName());
Reaction _t = _s3.getReactions().get(0);
assertTrue(_t.isTransition());
Sequence _effect = (Sequence) _t.getEffect();
assertEquals(2, _effect.getSteps().size());
assertedOrder(_effect, Lists.newArrayList(_s2b, _s3, _s4b), Lists.newArrayList(new StepLeaf(_s2b.getExitSequence()), new StepLeaf(_s3.getExitSequence()), new StepLeaf(_s4b.getExitSequence())));
assertCall(_effect, 1, _s5.getEnterSequences().get(0));
}
use of org.yakindu.sct.model.sexec.Reaction in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testAlwaysLocalReaction.
/**
* Local reactions must be created for behavior with 'always' trigger
*/
@SuppressWarnings("unused")
@Test
public void testAlwaysLocalReaction() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
State s = _createState("s", r);
LocalReaction timeTriggeredReaction = _createLocalReaction(s, StextFactory.eINSTANCE.createAlwaysEvent());
AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) timeTriggeredReaction.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s = flow.getStates().get(0);
// assert that a local reaction is created
Reaction reaction = _s.getReactions().get(0);
PrimitiveValueExpression pve = (PrimitiveValueExpression) reaction.getCheck().getCondition();
assertBoolLiteral(true, pve.getValue());
}
use of org.yakindu.sct.model.sexec.Reaction in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithGuard.
@Test
public void testTransitionCheckSequenceWithGuard() {
EventDefinition e1 = _createEventDefinition("e1", null);
EventDefinition e2 = _createEventDefinition("e2", null);
ReactionTrigger tr1 = _createReactionTrigger(null);
_createRegularEventSpec(e1, tr1);
_createRegularEventSpec(e2, tr1);
PrimitiveValueExpression exp = _createValue(false);
tr1.setGuard(createGuardExpression(exp));
Transition t = SGraphFactory.eINSTANCE.createTransition();
t.setTrigger(tr1);
Statechart sc = _createStatechart("test");
Region region = _createRegion("r1", sc);
t.setSource(_createState("A", region));
t.setTarget(_createState("B", region));
Reaction reaction = behaviorMapping.mapTransition(t);
// now check the expression structure ...
// the root is an and condition with the trigger check as the first
// (left) part and the guard as the right (second) part.
LogicalAndExpression and = (LogicalAndExpression) reaction.getCheck().getCondition();
ParenthesizedExpression parenthesis = (ParenthesizedExpression) and.getLeftOperand();
LogicalOrExpression triggerCheck = (LogicalOrExpression) parenthesis.getExpression();
PrimitiveValueExpression guardCheck = (PrimitiveValueExpression) ((ParenthesizedExpression) and.getRightOperand()).getExpression();
assertClass(ElementReferenceExpression.class, triggerCheck.getLeftOperand());
assertClass(ElementReferenceExpression.class, triggerCheck.getRightOperand());
assertEquals(e1.getName(), ((NamedElement) ((ElementReferenceExpression) triggerCheck.getLeftOperand()).getReference()).getName());
assertEquals(e2.getName(), ((NamedElement) ((ElementReferenceExpression) triggerCheck.getRightOperand()).getReference()).getName());
assertBoolLiteral(false, guardCheck.getValue());
}
use of org.yakindu.sct.model.sexec.Reaction in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithoutGuard.
@Test
public void testTransitionCheckSequenceWithoutGuard() {
EventDefinition e1 = _createEventDefinition("e1", null);
EventDefinition e2 = _createEventDefinition("e2", null);
ReactionTrigger tr1 = _createReactionTrigger(null);
_createRegularEventSpec(e1, tr1);
_createRegularEventSpec(e2, tr1);
Transition t = SGraphFactory.eINSTANCE.createTransition();
t.setTrigger(tr1);
Statechart sc = _createStatechart("test");
Region region = _createRegion("r1", sc);
t.setSource(_createState("A", region));
t.setTarget(_createState("B", region));
Reaction reaction = behaviorMapping.mapTransition(t);
assertTrue(reaction.getCheck().getCondition() instanceof LogicalOrExpression);
assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand());
assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand());
assertEquals(e1.getName(), ((NamedElement) ((ElementReferenceExpression) ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand()).getReference()).getName());
assertEquals(e2.getName(), ((NamedElement) ((ElementReferenceExpression) ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand()).getReference()).getName());
}
use of org.yakindu.sct.model.sexec.Reaction in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithoutTrigger.
@Test
public void testTransitionCheckSequenceWithoutTrigger() {
ReactionTrigger tr1 = _createReactionTrigger(null);
PrimitiveValueExpression exp = _createValue(false);
tr1.setGuard(createGuardExpression(exp));
Transition t = SGraphFactory.eINSTANCE.createTransition();
t.setTrigger(tr1);
Statechart sc = _createStatechart("test");
Region region = _createRegion("r1", sc);
t.setSource(_createState("A", region));
t.setTarget(_createState("B", region));
Reaction reaction = behaviorMapping.mapTransition(t);
// now check the expression structure ...
// the root is an and condition with the trigger check as the first
// (left) part and the guard as the right (second) part.
PrimitiveValueExpression guard = (PrimitiveValueExpression) reaction.getCheck().getCondition();
assertBoolLiteral(false, guard.getValue());
}
Aggregations