use of org.yakindu.sct.model.sexec.StateSwitch in project statecharts by Yakindu.
the class LocalReactionTest method testSCLocalReaction.
/**
* The transition sequence must contain all exit actions for parent states
* that will be left by a transition.
*/
@Test
public void testSCLocalReaction() {
Statechart sc = _createStatechart("sc");
{
LocalReaction lr0 = _createLocalReaction(sc, _createAlwaysEventSpec(null));
VariableDefinition v = _createVariableDefinition("v", TYPE_INTEGER, getOrCreateInternalScope(sc));
_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN, _createValue(1), (ReactionEffect) lr0.getEffect());
Region r = _createRegion("r", sc);
{
State s1 = _createState("s1", r);
{
LocalReaction lr1 = _createLocalReaction(s1, _createAlwaysEventSpec(null));
_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN, _createValue(2), (ReactionEffect) lr1.getEffect());
_createEntryAssignment(v, s1, 1);
Region r_s1 = _createRegion("r", s1);
{
_createState("s3", r_s1);
}
}
State s2 = _createState("s2", r);
{
_createEntryAssignment(v, s2, 1);
Region r_s2 = _createRegion("r", s2);
{
_createState("s6", r_s2);
}
}
}
}
Transition t = _createTransition(findState(sc, "s3"), findState(sc, "s6"));
ReactionTrigger tr = _createReactionTrigger(t);
tr.setGuard(createGuardExpression(_createValue(true)));
ExecutionFlow flow = sequencer.transform(sc);
assertEquals(1, flow.getReactions().size());
ExecutionState _s1 = flow.getStates().get(0);
assertEquals("sc.r.s1", _s1.getName());
// assertEquals(1, _s1.getReactions().size());
ExecutionState _s3 = flow.getStates().get(1);
assertEquals("sc.r.s1.r.s3", _s3.getName());
ExecutionState _s2 = flow.getStates().get(2);
assertEquals("sc.r.s2", _s2.getName());
// assertEquals(1, _s2.getReactions().size());
ExecutionState _s6 = flow.getStates().get(3);
assertEquals("sc.r.s2.r.s6", _s6.getName());
Reaction _t = _s3.getReactions().get(0);
assertTrue(_t.isTransition());
// Check Stateswitch in flow
StateSwitch sSwitch = assertedSwitch(flow.getReactSequence().getSteps().get(0));
assertStateSwitch(sSwitch, _s3, _s6);
assertCall(assertedStateCase(sSwitch, _s3).getStep(), _s3.getReactSequence());
// Check reactSequence of leaf state
Sequence _effect = (Sequence) _t.getEffect();
assertCall(_effect, 0, _s1.getExitSequence());
assertCall(_effect, 1, _s2.getEntryAction());
assertCall(_effect, 2, _s6.getEnterSequences().get(0));
assertEquals(3, _effect.getSteps().size());
List<Step> steps = flattenSequenceStepsAsList(_s3.getReactSequence());
If _if = assertClass(If.class, steps.get(0));
assertEquals(flow.getReactions().get(0).getCheck(), assertClass(CheckRef.class, _if.getCheck()).getCheck());
_if = assertClass(If.class, steps.get(1));
assertEquals(_s1.getReactions().get(0).getCheck(), assertClass(CheckRef.class, _if.getCheck()).getCheck());
_if = assertClass(If.class, steps.get(2));
assertNotNull(assertClass(CheckRef.class, _if.getCheck()).getCheck());
assertCall(_if.getThenStep(), _effect);
}
use of org.yakindu.sct.model.sexec.StateSwitch in project statecharts by Yakindu.
the class Assert method findNext.
protected static Iterable<Step> findNext(Step step, Collection<? extends ExecutionState> currentStates, List<? extends AbstractStep> requiredSteps) {
if (step instanceof Sequence) {
return ((Sequence) step).getSteps();
} else if (step instanceof Call) {
return Collections.singleton(((Call) step).getStep());
} else if (step instanceof StateSwitch) {
StateCase stateCase = null;
StringBuilder sb = new StringBuilder();
for (StateCase caze : ((StateSwitch) step).getCases()) {
sb.append(", " + caze.getState().getName());
if (stateCase == null && currentStates.contains(caze.getState())) {
stateCase = caze;
}
}
assertNotNull("No state case found for " + currentStates + " in " + sb.toString(), stateCase);
return Collections.singleton(stateCase.getStep());
}
return null;
}
use of org.yakindu.sct.model.sexec.StateSwitch in project statecharts by Yakindu.
the class ModelSequencerOrthogonalityTest method testBottomUpExitSequence_TwoLevels.
/**
* When exiting an orthogonal state exits must be performed in a well
* defined order bottom up with highest priority/order states first.
*/
@Test
public void testBottomUpExitSequence_TwoLevels() {
Statechart sc = _createStatechart("sc");
{
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, s_scope);
Region r = _createRegion("r", sc);
{
State s = _createState("s", r);
{
_createExitAssignment(v1, s, 42);
Region r2 = _createRegion("r2", s);
{
State s2 = _createState("s2", r2);
{
_createExitAssignment(v1, s2, 42);
Region r2a = _createRegion("r2a", s2);
{
_createState("s2a1", r2a);
_createState("s2a2", r2a);
}
Region r2b = _createRegion("r2b", s2);
{
_createState("s2b1", r2b);
_createState("s2b2", r2b);
}
Region r2c = _createRegion("r2c", s2);
{
_createState("s2c1", r2c);
_createState("s2c2", r2c);
}
}
}
Region r3 = _createRegion("r3", s);
{
State s3 = _createState("s3", r3);
{
_createExitAssignment(v1, s3, 42);
Region r3a = _createRegion("r3a", s3);
{
_createState("s3a1", r3a);
_createState("s3a2", r3a);
}
Region r3b = _createRegion("r3b", s3);
{
_createState("s3b1", r3b);
_createState("s3b2", r3b);
}
}
}
Region r4 = _createRegion("r4", s);
{
State s4 = _createState("s4", r4);
{
_createExitAssignment(v1, s4, 42);
Region r4a = _createRegion("r4a", s4);
{
_createState("s4a1", r4a);
_createState("s4a2", r4a);
}
Region r4b = _createRegion("r4b", s4);
{
_createState("s4b1", r4b);
_createState("s4b2", r4b);
}
}
}
}
}
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s = assertedState(flow, 0, "sc.r.s");
ExecutionState _s2 = assertedState(flow, 1, "sc.r.s.r2.s2");
ExecutionState _s2a1 = assertedState(flow, 2, "sc.r.s.r2.s2.r2a.s2a1");
ExecutionState _s2a2 = assertedState(flow, 3, "sc.r.s.r2.s2.r2a.s2a2");
ExecutionState _s2b1 = assertedState(flow, 4, "sc.r.s.r2.s2.r2b.s2b1");
ExecutionState _s2b2 = assertedState(flow, 5, "sc.r.s.r2.s2.r2b.s2b2");
ExecutionState _s2c1 = assertedState(flow, 6, "sc.r.s.r2.s2.r2c.s2c1");
ExecutionState _s2c2 = assertedState(flow, 7, "sc.r.s.r2.s2.r2c.s2c2");
ExecutionState _s3 = assertedState(flow, 8, "sc.r.s.r3.s3");
ExecutionState _s3a1 = assertedState(flow, 9, "sc.r.s.r3.s3.r3a.s3a1");
ExecutionState _s3a2 = assertedState(flow, 10, "sc.r.s.r3.s3.r3a.s3a2");
ExecutionState _s3b1 = assertedState(flow, 11, "sc.r.s.r3.s3.r3b.s3b1");
ExecutionState _s3b2 = assertedState(flow, 12, "sc.r.s.r3.s3.r3b.s3b2");
ExecutionState _s4 = assertedState(flow, 13, "sc.r.s.r4.s4");
ExecutionState _s4a1 = assertedState(flow, 14, "sc.r.s.r4.s4.r4a.s4a1");
ExecutionState _s4a2 = assertedState(flow, 15, "sc.r.s.r4.s4.r4a.s4a2");
ExecutionState _s4b1 = assertedState(flow, 16, "sc.r.s.r4.s4.r4b.s4b1");
ExecutionState _s4b2 = assertedState(flow, 17, "sc.r.s.r4.s4.r4b.s4b2");
// check the exit sequence of _s
Sequence _exit = _s.getExitSequence();
assertEquals("wrong steps: " + stepListAsString(_exit), 4, _exit.getSteps().size());
assertCall(_exit, 0, _s2.getSuperScope().getExitSequence());
assertCall(_exit, 1, _s3.getSuperScope().getExitSequence());
assertCall(_exit, 2, _s4.getSuperScope().getExitSequence());
StateSwitch _switch0 = assertedSwitch(_s2.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch0, _s2a1, _s2a2);
assertSequenceSize(1, assertedStateCase(_switch0, _s2a1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch0, _s2a1).getStep()), 0, _s2a1.getExitSequence());
assertSequenceSize(1, assertedStateCase(_switch0, _s2a2).getStep());
assertCall(assertedSequence(assertedStateCase(_switch0, _s2a2).getStep()), 0, _s2a2.getExitSequence());
StateSwitch _switch1 = assertedSwitch(_s2b1.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch1, _s2b1, _s2b2);
assertSequenceSize(1, assertedStateCase(_switch1, _s2b1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch1, _s2b1).getStep()), 0, _s2b1.getExitSequence());
assertSequenceSize(1, assertedStateCase(_switch1, _s2b2).getStep());
assertCall(assertedSequence(assertedStateCase(_switch1, _s2b2).getStep()), 0, _s2b2.getExitSequence());
StateSwitch _switch2 = assertedSwitch(_s2c1.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch2, _s2c1, _s2c2);
assertSequenceSize(1, assertedStateCase(_switch2, _s2c1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch2, _s2c1).getStep()), 0, _s2c1.getExitSequence());
assertSequenceSize(4, _s2.getExitSequence());
assertCall(_s2.getExitSequence(), 3, _s2.getExitAction());
assertSequenceSize(1, assertedStateCase(_switch2, _s2c2).getStep());
assertCall(assertedSequence(assertedStateCase(_switch2, _s2c2).getStep()), 0, _s2c2.getExitSequence());
StateSwitch _switch3 = assertedSwitch(_s3a1.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch3, _s3a1, _s3a2);
assertSequenceSize(1, assertedStateCase(_switch3, _s3a1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch3, _s3a1).getStep()), 0, _s3a1.getExitSequence());
assertSequenceSize(1, assertedStateCase(_switch3, _s3a2).getStep());
assertCall(assertedSequence(assertedStateCase(_switch3, _s3a2).getStep()), 0, _s3a2.getExitSequence());
StateSwitch _switch4 = assertedSwitch(_s3b1.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch4, _s3b1, _s3b2);
assertSequenceSize(1, assertedStateCase(_switch4, _s3b1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch4, _s3b1).getStep()), 0, _s3b1.getExitSequence());
assertCall(assertedSequence(assertedStateCase(_s3.getSuperScope().getExitSequence().getSteps().get(1), _s3b1).getStep()), 1, _s3.getExitAction());
assertSequenceSize(1, assertedStateCase(_switch4, _s3b2).getStep());
assertCall(assertedSequence(assertedStateCase(_switch4, _s3b2).getStep()), 0, _s3b2.getExitSequence());
assertCall(assertedSequence(assertedStateCase(_s3.getSuperScope().getExitSequence().getSteps().get(1), _s3b2).getStep()), 1, _s3.getExitAction());
StateSwitch _switch5 = assertedSwitch(_s4a1.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch5, _s4a1, _s4a2);
assertSequenceSize(1, assertedStateCase(_switch5, _s4a1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch5, _s4a1).getStep()), 0, _s4a1.getExitSequence());
assertSequenceSize(1, assertedStateCase(_switch5, _s4a2).getStep());
assertCall(assertedSequence(assertedStateCase(_switch5, _s4a2).getStep()), 0, _s4a2.getExitSequence());
StateSwitch _switch6 = assertedSwitch(_s4b1.getSuperScope().getExitSequence().getSteps().get(0));
assertStateSwitch(_switch6, _s4b1, _s4b2);
assertSequenceSize(1, assertedStateCase(_switch6, _s4b1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch6, _s4b1).getStep()), 0, _s4b1.getExitSequence());
assertCall(assertedSequence(assertedStateCase(_s4.getSuperScope().getExitSequence().getSteps().get(1), _s4b1).getStep()), 1, _s4.getExitAction());
assertSequenceSize(1, assertedStateCase(_switch6, _s4b1).getStep());
assertCall(assertedSequence(assertedStateCase(_switch6, _s4b2).getStep()), 0, _s4b2.getExitSequence());
assertCall(_s4.getExitSequence(), 2, _s4.getExitAction());
assertCall(_exit, 3, _s.getExitAction());
}
use of org.yakindu.sct.model.sexec.StateSwitch in project statecharts by Yakindu.
the class ModelSequencerHierarchyTest method testParentExitDeep.
/**
* The transition sequence must contain all exit actions for parent states
* that will be left by a transition.
*/
@SuppressWarnings("unused")
@Test
public void testParentExitDeep() {
Statechart sc = _createStatechart("sc");
{
InterfaceScope s_scope = _createInterfaceScope("Interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, 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);
State s5 = _createState("s5", r_s3);
}
}
}
}
State s2 = _createState("s2", r);
{
Region r_s1 = _createRegion("r", s2);
{
_createState("s6", r_s1);
}
}
}
}
_createTransition(findState(sc, "s4"), findState(sc, "s6"));
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
assertEquals("sc.r.s1", _s1.getName());
assertNotNull(_s1.getExitAction());
ExecutionState _s3 = flow.getStates().get(1);
assertEquals("sc.r.s1.r.s3", _s3.getName());
assertNotNull(_s3.getExitAction());
ExecutionState _s4 = flow.getStates().get(2);
assertEquals("sc.r.s1.r.s3.r.s4", _s4.getName());
assertNotNull(_s4.getExitAction());
ExecutionState _s6 = flow.getStates().get(5);
assertEquals("sc.r.s2.r.s6", _s6.getName());
Reaction _t = _s4.getReactions().get(0);
assertTrue(_t.isTransition());
Sequence _effect = (Sequence) _t.getEffect();
assertEquals(2, _effect.getSteps().size());
assertCall(_effect, 0, _s1.getExitSequence());
assertCall(_effect, 1, _s6.getEnterSequences().get(0));
assertCall(_s1.getExitSequence(), 0, _s1.getSubScopes().get(0).getExitSequence());
StateSwitch _switch = (StateSwitch) _s1.getSubScopes().get(0).getExitSequence().getSteps().get(0);
StateCase _s4_case = assertedStateCase(_switch, _s4);
assertCall(assertedSequence(_s4_case.getStep()), 0, _s4.getExitSequence());
assertCall(assertedSequence(_s4_case.getStep()), 1, _s3.getExitAction());
assertCall(_s1.getExitSequence(), 1, _s1.getExitAction());
}
use of org.yakindu.sct.model.sexec.StateSwitch in project statecharts by Yakindu.
the class Assert method assertedStateCase.
public static StateCase assertedStateCase(Step step, ExecutionState state) {
assertNotNull("Step is null", step);
assertNotNull("No state specified", state);
assertTrue("Step is no StateSwitch (was " + step.getClass().getName() + ")", step instanceof StateSwitch);
for (StateCase sCase : ((StateSwitch) step).getCases()) {
if (sCase.getState() == state)
return sCase;
}
fail("No case for state '" + state.getSimpleName() + "' exists.");
return null;
}
Aggregations