use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_WithParent.
/**
* The state cycle must contain all reactions of parent states.
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_WithParent() {
Statechart sc = _createStatechart("sc");
{
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
EventDefinition e1 = _createEventDefinition("e1", s_scope);
Region r = _createRegion("r", sc);
{
State s1 = _createState("s1", r);
{
// a local reaction: "e1 / x=42;"
LocalReaction lr1 = _createLocalReaction(s1, null);
_createRegularEventSpec(e1, (ReactionTrigger) lr1.getTrigger());
ReactionEffect lr1_eff = _createReactionEffect(lr1);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr1_eff);
Region r_s1 = _createRegion("r", s1);
{
State s3 = _createState("s3", r_s1);
{
_createEntryAssignment(v1, s3, 2);
Region r_s3 = _createRegion("r", s3);
{
State s4 = _createState("s4", r_s3);
_createEntryAssignment(v1, s4, 3);
State s5 = _createState("s5", r_s3);
}
}
}
}
State s2 = _createState("s2", r);
{
Region r_s1 = _createRegion("r", s2);
{
_createState("s6", r_s1);
}
}
}
Transition t_s4_s5 = _createTransition(findState(sc, "s4"), findState(sc, "s5"));
_createReactionTrigger(t_s4_s5);
_createRegularEventSpec(e1, (ReactionTrigger) t_s4_s5.getTrigger());
Transition t_s3_s6 = _createTransition(findState(sc, "s3"), findState(sc, "s6"));
_createReactionTrigger(t_s3_s6);
_createRegularEventSpec(e1, (ReactionTrigger) t_s3_s6.getTrigger());
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
assertEquals("sc.r.s1", _s1.getName());
ExecutionState _s3 = flow.getStates().get(1);
assertEquals("sc.r.s1.r.s3", _s3.getName());
ExecutionState _s4 = flow.getStates().get(2);
assertEquals("sc.r.s1.r.s3.r.s4", _s4.getName());
ExecutionState _s6 = flow.getStates().get(5);
assertEquals("sc.r.s2.r.s6", _s6.getName());
Sequence cycle = _s4.getReactSequence();
Sequence _seq = (Sequence) cycle.getSteps().get(0);
// first entry is the s1 local reaction
List<Step> steps = SCTTestUtil.flattenSequenceStepsAsList(_seq);
If _if = (If) steps.get(0);
assertCall(_if.getThenStep(), _s1.getReactions().get(0).getEffect());
// second entry is the s3 cycle with the transition reaction
_if = (If) steps.get(1);
assertCall(_if.getThenStep(), _s3.getReactions().get(0).getEffect());
assertTrue(_s3.getReactions().get(0).isTransition());
// third is the s4 cycle with the transition reaction
_seq = (Sequence) _if.getElseStep();
cycle = (Sequence) _seq.getSteps().get(0);
_if = (If) assertedSequence(cycle.getSteps().get(0)).getSteps().get(0);
assertCall(_if.getThenStep(), _s4.getReactions().get(0).getEffect());
assertTrue(_s4.getReactions().get(0).isTransition());
assertTrue(assertedSequence(assertedSequence(_if.getElseStep()).getSteps().get(0)).getSteps().isEmpty());
assertEquals(1, cycle.getSteps().size());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testSubStateEntryActionExclusion.
/**
* entry actions of a substate must not be included in a states entry action
* list
*/
@Test
public void testSubStateEntryActionExclusion() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
// Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s2 = _createState("s2", r);
Region s2_r = _createRegion("sub", s2);
State s2_1 = _createState("s2_1", s2_r);
LocalReaction entryAction = _createEntryAction(s2_1);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) entryAction.getEffect());
LocalReaction exitAction = _createExitAction(s2_1);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(43), (ReactionEffect) exitAction.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s2 = flow.getStates().get(0);
ExecutionState _s2_1 = flow.getStates().get(1);
assertEquals(s2.getName(), _s2.getSimpleName());
assertEquals(s2_1.getName(), _s2_1.getSimpleName());
assertNull(_s2.getEntryAction());
assertNotNull(_s2_1.getEntryAction());
assertNull(_s2.getExitAction());
assertNotNull(_s2_1.getExitAction());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_ExitActionExclusion.
/**
* Exit action behaviors are not directly part of the states cycle steps
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_ExitActionExclusion() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createExitAction(tsc.s1);
ReactionEffect lr_eff = _createReactionEffect(lr);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
// TRANSFORM
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(0, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger.
/**
* Local reactions that define regular and entry triggers side by side must
* also be part of the cycle steps.
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createEntryAction(tsc.s1);
_createRegularEventSpec(tsc.e1, (ReactionTrigger) lr.getTrigger());
ReactionEffect lr_eff = _createReactionEffect(lr);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
// TRANSFORM
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(1, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
Sequence _seq = (Sequence) s1.getReactSequence().getSteps().get(0);
If _lr1 = (If) assertedSequence(assertedSequence(assertedSequence(assertedSequence(_seq.getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
assertClass(ElementReferenceExpression.class, _lr1.getCheck().getCondition());
assertSame(s1.getReactions().get(0).getCheck().getCondition(), _lr1.getCheck().getCondition());
Call _lr1_eff_call = (Call) _lr1.getThenStep();
assertSame(s1.getReactions().get(0).getEffect(), _lr1_eff_call.getStep());
}
use of org.yakindu.sct.model.stext.stext.LocalReaction in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testExitActionWithoutGuard.
/**
* If a entry trigger is combined with a guard condition then the entry
* action is executed conditionally with this trigger.
*/
@Test
public void testExitActionWithoutGuard() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
Entry e = _createEntry(EntryKind.INITIAL, null, r);
State s1 = _createState("s1", r);
State s2 = _createState("s2", r);
_createTransition(e, s1);
_createTransition(s1, s2);
LocalReaction exitAction = _createExitAction(s2);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) exitAction.getEffect());
// ((ReactionTrigger)entryAction.getTrigger()).setGuardExpression(_createValue(true));
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals(s1.getName(), _s1.getSimpleName());
assertEquals(s2.getName(), _s2.getSimpleName());
Sequence _exitSeq = (Sequence) _s2.getExitAction();
assertClass(Sequence.class, _exitSeq.getSteps().get(0));
assertAssignment(((Sequence) _exitSeq.getSteps().get(0)).getSteps().get(0), "v1", AssignmentOperator.ASSIGN, "42");
}
Aggregations