use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerOrthogonalityTest method testSourceSiblingEnterExclusion.
/**
* A transition from a state with orthogonal siblings that dives into a non
* orthogonal sibling state must exclude the source state sibling entry
* behavior.
*/
@SuppressWarnings("unused")
@Test
public void testSourceSiblingEnterExclusion() {
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);
}
Region r3 = _createRegion("r3", s1);
{
Entry r3_entry = _createEntry(EntryKind.INITIAL, null, r3);
State s3 = _createState("s3", r3);
{
Region r3a = _createRegion("r3a", s3);
{
Entry r3a_entry = _createEntry(EntryKind.INITIAL, null, r3a);
State s3a = _createState("s3a", r3a);
_createTransition(r3a_entry, s3a);
}
Region r3b = _createRegion("r3b", s3);
{
Entry r3b_entry = _createEntry(EntryKind.INITIAL, null, r3b);
State s3b = _createState("s3b", r3b);
State s3b2 = _createState("s3b2", r3b);
_createTransition(r3b_entry, s3b);
}
Region r3c = _createRegion("r3c", s3);
{
Entry r3c_entry = _createEntry(EntryKind.INITIAL, null, r3c);
State s3c = _createState("s3c", r3c);
_createTransition(r3c_entry, s3c);
}
}
State s3z = _createState("s3z", r3);
_createEntryAssignment(v1, s3, 42);
_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);
}
}
_createTransition(r_entry, s1);
State s5 = _createState("s5", r);
_createTransition(findState(sc, "s3z"), findState(sc, "s3b2"));
}
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals("sc.r.s1.r2.s2", _s2.getName());
ExecutionState _s3 = flow.getStates().get(2);
assertEquals("sc.r.s1.r3.s3", _s3.getName());
ExecutionState _s3a = flow.getStates().get(3);
assertEquals("sc.r.s1.r3.s3.r3a.s3a", _s3a.getName());
ExecutionState _s3b = flow.getStates().get(4);
assertEquals("sc.r.s1.r3.s3.r3b.s3b", _s3b.getName());
ExecutionState _s3b2 = flow.getStates().get(5);
assertEquals("sc.r.s1.r3.s3.r3b.s3b2", _s3b2.getName());
ExecutionState _s3c = flow.getStates().get(6);
assertEquals("sc.r.s1.r3.s3.r3c.s3c", _s3c.getName());
ExecutionState _s3z = flow.getStates().get(7);
assertEquals("sc.r.s1.r3.s3z", _s3z.getName());
ExecutionState _s4 = flow.getStates().get(8);
assertEquals("sc.r.s1.r4.s4", _s4.getName());
ExecutionState _s5 = flow.getStates().get(9);
assertEquals("sc.r.s5", _s5.getName());
Reaction _t = _s3z.getReactions().get(0);
assertTrue(_t.isTransition());
Sequence _effect = (Sequence) _t.getEffect();
assertEquals("wrong sequence: " + stepListAsString(_effect), 5, _effect.getSteps().size());
assertCall(_effect, 0, _s3z.getExitSequence());
assertCall(_effect, 1, _s3.getEntryAction());
assertCall(_effect, 2, _s3a.getSuperScope().getEnterSequences().get(0));
Sequence r3a_entryReactSequence = flow.getNodes().get(3).getReactSequence();
assertCall(_s3a.getSuperScope().getEnterSequences().get(0), 0, r3a_entryReactSequence);
assertCall(((Sequence) firstStep(firstStep(r3a_entryReactSequence))), 0, _s3a.getEnterSequences().get(0));
assertCall(_effect, 3, _s3b2.getEnterSequences().get(0));
assertCall(_effect, 4, _s3c.getSuperScope().getEnterSequences().get(0));
Sequence r3c_entryReactSequence = flow.getNodes().get(5).getReactSequence();
assertCall(_s3c.getSuperScope().getEnterSequences().get(0), 0, r3c_entryReactSequence);
assertCall(((Sequence) firstStep(firstStep(r3c_entryReactSequence))), 0, _s3c.getEnterSequences().get(0));
assertTrue(_s3c.getEnterSequences().get(0).getSteps().get(0).getClass().getSimpleName(), _s3c.getEnterSequences().get(0).getSteps().get(0) instanceof EnterState);
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerOrthogonalityTest method testSiblingStateTransition.
/**
* Local transition within a region with orthogonal siblings does not have
* to invoke sibling region entries or exists.
*/
@SuppressWarnings("unused")
@Test
public void testSiblingStateTransition() {
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);
}
Region r3 = _createRegion("r3", s1);
{
Entry r3_entry = _createEntry(EntryKind.INITIAL, null, r3);
State s3 = _createState("s3", r3);
{
Region r3a = _createRegion("r3a", s3);
{
Entry r3a_entry = _createEntry(EntryKind.INITIAL, null, r3a);
State s3a = _createState("s3a", r3a);
_createTransition(r3a_entry, s3a);
}
Region r3b = _createRegion("r3b", s3);
{
Entry r3b_entry = _createEntry(EntryKind.INITIAL, null, r3b);
State s3b = _createState("s3b", r3b);
State s3b2 = _createState("s3b2", r3b);
_createTransition(r3b_entry, s3b);
}
Region r3c = _createRegion("r3c", s3);
{
Entry r3c_entry = _createEntry(EntryKind.INITIAL, null, r3c);
State s3c = _createState("s3c", r3c);
_createTransition(r3c_entry, s3c);
}
}
_createEntryAssignment(v1, s3, 42);
_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);
}
}
_createTransition(r_entry, s1);
State s5 = _createState("s5", r);
_createTransition(findState(sc, "s3b"), findState(sc, "s3b2"));
}
}
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s2 = flow.getStates().get(1);
assertEquals("sc.r.s1.r2.s2", _s2.getName());
ExecutionState _s3 = flow.getStates().get(2);
assertEquals("sc.r.s1.r3.s3", _s3.getName());
ExecutionState _s3a = flow.getStates().get(3);
assertEquals("sc.r.s1.r3.s3.r3a.s3a", _s3a.getName());
ExecutionState _s3b = flow.getStates().get(4);
assertEquals("sc.r.s1.r3.s3.r3b.s3b", _s3b.getName());
ExecutionState _s3b2 = flow.getStates().get(5);
assertEquals("sc.r.s1.r3.s3.r3b.s3b2", _s3b2.getName());
ExecutionState _s3c = flow.getStates().get(6);
assertEquals("sc.r.s1.r3.s3.r3c.s3c", _s3c.getName());
ExecutionState _s4 = flow.getStates().get(7);
assertEquals("sc.r.s1.r4.s4", _s4.getName());
ExecutionState _s5 = flow.getStates().get(8);
assertEquals("sc.r.s5", _s5.getName());
Reaction _t = _s3b.getReactions().get(0);
assertTrue(_t.isTransition());
Sequence _effect = (Sequence) _t.getEffect();
assertEquals(2, _effect.getSteps().size());
assertCall(_effect, 0, _s3b.getExitSequence());
assertCall(_effect, 1, _s3b2.getEnterSequences().get(0));
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerOrthogonalityTest method setUpDeepExitSC.
@SuppressWarnings("unused")
private Statechart setUpDeepExitSC() {
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 r1 = _createRegion("1", s);
{
State a = _createState("a", r1);
{
_createExitAssignment(v1, a, 42);
Region a1 = _createRegion("1", a);
{
State a1a = _createState("a", a1);
{
_createExitAssignment(v1, a1a, 42);
Region a11 = _createRegion("1", a1a);
{
_createState("a", a11);
}
Region a21 = _createRegion("2", a1a);
{
_createState("a", a21);
}
}
}
Region a2 = _createRegion("2", a);
{
State a2a = _createState("a", a2);
{
_createExitAssignment(v1, a2a, 42);
Region a11 = _createRegion("1", a2a);
{
_createState("a", a11);
}
Region a21 = _createRegion("2", a2a);
{
_createState("a", a21);
}
}
}
}
}
Region r2 = _createRegion("2", s);
{
State a = _createState("a", r2);
{
_createExitAssignment(v1, a, 42);
Region a1 = _createRegion("1", a);
{
State a1a = _createState("a", a1);
{
_createExitAssignment(v1, a1a, 42);
Region a11 = _createRegion("1", a1a);
{
_createState("a", a11);
}
Region a21 = _createRegion("2", a1a);
{
_createState("a", a21);
}
}
}
Region a2 = _createRegion("2", a);
{
State a2a = _createState("a", a2);
{
_createExitAssignment(v1, a2a, 42);
Region a11 = _createRegion("1", a2a);
{
_createState("a", a11);
}
Region a21 = _createRegion("2", a2a);
{
_createState("a", a21);
}
}
}
}
}
}
State b = _createState("b", r);
}
}
return sc;
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testSingleTransitionTimeTrigger.
/**
* If a time trigger is defined for a transition then an event must be
* introduced into the execution flow.
*/
@SuppressWarnings("unused")
@Test
public void testSingleTransitionTimeTrigger() {
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);
Transition t = _createTransition(s, s);
ReactionTrigger tr1 = _createReactionTrigger(t);
_createTimeEventSpec(TimeEventType.AFTER, _createValue(1), TimeUnit.SECOND, tr1);
AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) t.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
// assert definition of time event
Scope timerScope = flow.getScopes().get(1);
assertTrue(timerScope.getDeclarations().get(0) instanceof TimeEvent);
TimeEvent te = (TimeEvent) timerScope.getDeclarations().get(0);
// assert that the reaction check checks the time event
assertEquals(1, flow.getStates().size());
ExecutionState _s = flow.getStates().get(0);
assertEquals(s.getName(), _s.getSimpleName());
If _if = (If) SCTTestUtil.flattenSequenceStepsAsList(flow.getStates().get(0).getReactSequence()).get(0);
ElementReferenceExpression _ere = (ElementReferenceExpression) _if.getCheck().getCondition();
assertSame(te, _ere.getReference());
// assert the scheduling of the time event during state entry
assertNotNull(_s.getEntryAction());
Sequence entryAction = (Sequence) _s.getEntryAction();
ScheduleTimeEvent ste = (ScheduleTimeEvent) entryAction.getSteps().get(0);
assertSame(te, ste.getTimeEvent());
NumericalMultiplyDivideExpression multiply = (NumericalMultiplyDivideExpression) ste.getTimeValue();
assertIntLiteral(1, ((PrimitiveValueExpression) multiply.getLeftOperand()).getValue());
assertIntLiteral(1000, ((PrimitiveValueExpression) multiply.getRightOperand()).getValue());
assertEquals(MultiplicativeOperator.MUL, multiply.getOperator());
// assert the unscheduling of the time events during state exit
assertNotNull(_s.getExitAction());
Sequence exitAction = (Sequence) _s.getExitAction();
UnscheduleTimeEvent ute = (UnscheduleTimeEvent) exitAction.getSteps().get(0);
assertSame(te, ute.getTimeEvent());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope 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