use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.
the class ModelSequencerStateTest method testFinalState.
/**
* A final state must be transformed into a execution state with name
* '_final_'. and must include parent reactions.
*/
@SuppressWarnings("unused")
@Test
public void testFinalState() {
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);
FinalState fs = _createFinalState(r_s3);
Transition t_s4_fs = _createTransition(findState(sc, "s4"), fs);
_createReactionTrigger(t_s4_fs);
_createRegularEventSpec(e1, (ReactionTrigger) t_s4_fs.getTrigger());
}
}
}
}
State s2 = _createState("s2", r);
{
Region r_s1 = _createRegion("r", s2);
{
_createState("s6", r_s1);
}
}
}
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 _fs = flow.getStates().get(3);
assertEquals("sc.r.s1.r.s3.r._final_", _fs.getName());
ExecutionState _s6 = flow.getStates().get(5);
assertEquals("sc.r.s2.r.s6", _s6.getName());
assertNull(_fs.getEntryAction());
assertNull(_fs.getExitAction());
Sequence cycle = _fs.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());
assertNotNull(_if.getElseStep());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition 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.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.
the class ModelSequencerStateTest method testCompositeStateExitSequence_Deep.
/**
* A composite state must have a exit sequence. This exit sequence consists
* of an exit action call and a state switch for all leaf states.
*/
@SuppressWarnings("unused")
@Test
public void testCompositeStateExitSequence_Deep() {
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);
{
_createExitAssignment(v1, s1, 1);
Region r_s1 = _createRegion("r", s1);
{
State s3 = _createState("s3", r_s1);
{
_createExitAssignment(v1, s3, 2);
Region r_s3 = _createRegion("r", s3);
{
State s4 = _createState("s4", r_s3);
_createExitAssignment(v1, s4, 3);
FinalState fs = _createFinalState(r_s3);
}
}
}
}
State s2 = _createState("s2", r);
{
Region r_s1 = _createRegion("r", s2);
{
_createState("s6", r_s1);
}
}
}
}
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 _fs = flow.getStates().get(3);
assertEquals("sc.r.s1.r.s3.r._final_", _fs.getName());
ExecutionState _s6 = flow.getStates().get(5);
assertEquals("sc.r.s2.r.s6", _s6.getName());
assertNull(_fs.getEntryAction());
assertNull(_fs.getExitAction());
assertNotNull(_fs.getExitSequence());
assertEquals(2, _s1.getExitSequence().getSteps().size());
ExecutionScope _r_s1 = _s1.getSubScopes().get(0);
assertCall(_s1.getExitSequence(), 0, _r_s1.getExitSequence());
Step _switch = _r_s1.getExitSequence().getSteps().get(0);
assertStateSwitch(_switch, _s4, _fs);
assertCall(assertedSequence(assertedStateCase(_switch, _s4).getStep()), 0, _s4.getExitSequence());
assertCall(assertedSequence(assertedStateCase(_switch, _s4).getStep()), 1, _s3.getExitAction());
assertCall(assertedSequence(assertedStateCase(_switch, _fs).getStep()), 0, _fs.getExitSequence());
assertCall(assertedSequence(assertedStateCase(_switch, _fs).getStep()), 1, _s3.getExitAction());
assertCall(_s1.getExitSequence(), 1, _s1.getExitAction());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testMultipleRegularEventTriggerCondition.
/**
* Multiple trigger events of a ReactionTrigger will be converted to a
* condition that consists of a ElementReferenceExpressions connected by
* LogicalOrExpressions.
*
* e1, e1 -> e1 || e2
*/
@Test
public void testMultipleRegularEventTriggerCondition() {
EventDefinition e1 = _createEventDefinition("e1", null);
EventDefinition e2 = _createEventDefinition("e2", null);
ReactionTrigger tr1 = _createReactionTrigger(null);
_createRegularEventSpec(e1, tr1);
_createRegularEventSpec(e2, tr1);
Expression s = behaviorMapping.buildCondition(tr1);
assertTrue(s instanceof LogicalOrExpression);
assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) s).getLeftOperand());
assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) s).getRightOperand());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createEventDefinition in project statecharts by Yakindu.
the class ModelSequencertDeclarationsTest method testTriggerEventDeclarationIntegrity.
/**
* The event refs used in the trigger condition must refer to the event
* declarations in the flow model and not the sc source model.
*/
@Test
public void testTriggerEventDeclarationIntegrity() {
Statechart sc = _createStatechart("test");
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
EventDefinition e1 = _createEventDefinition("e1", s_scope);
Region r = _createRegion("main", sc);
State s1 = _createState("S1", r);
State s2 = _createState("S2", r);
Transition t = _createTransition(s1, s2);
ReactionTrigger tr1 = _createReactionTrigger(t);
_createRegularEventSpec(e1, tr1);
ExecutionFlow flow = sequencer.transform(sc);
EventDefinition _e1 = (EventDefinition) flow.getScopes().get(0).getDeclarations().get(0);
assertNotSame(e1, _e1);
assertEquals(e1.getName(), _e1.getName());
assertEquals(2, flow.getStates().size());
assertEquals(s1.getName(), flow.getStates().get(0).getSimpleName());
Step step = flow.getStates().get(0).getReactSequence().getSteps().get(0);
If _if = (If) assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
ElementReferenceExpression _ere = (ElementReferenceExpression) _if.getCheck().getCondition();
assertSame(_e1, _ere.getReference());
}
Aggregations