Search in sources :

Example 6 with SGraphTestFactory._createTransition

use of org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition 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));
}
Also used : ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) EnterState(org.yakindu.sct.model.sexec.EnterState) SCTTestUtil.findState(org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState) State(org.yakindu.sct.model.sgraph.State) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Sequence(org.yakindu.sct.model.sexec.Sequence) Reaction(org.yakindu.sct.model.sexec.Reaction) Test(org.junit.Test)

Example 7 with SGraphTestFactory._createTransition

use of org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testEntryActionWithGuard.

/**
 * If a entry trigger is combined with a guard condition then the entry
 * action is executed conditionally with this trigger.
 */
@Test
public void testEntryActionWithGuard() {
    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 entryAction = _createEntryAction(s2);
    _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) entryAction.getEffect());
    ((ReactionTrigger) entryAction.getTrigger()).setGuard(createGuardExpression(_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 _entrySeq = (Sequence) _s2.getEntryAction();
    assertClass(If.class, _entrySeq.getSteps().get(0));
    assertClass(PrimitiveValueExpression.class, ((If) _entrySeq.getSteps().get(0)).getCheck().getCondition());
    assertAssignment(((Sequence) ((If) _entrySeq.getSteps().get(0)).getThenStep()).getSteps().get(0), "v1", AssignmentOperator.ASSIGN, "42");
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Sequence(org.yakindu.sct.model.sexec.Sequence) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Example 8 with SGraphTestFactory._createTransition

use of org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testEntryActionWithoutGuard.

/**
 * If a entry trigger is combined with a guard condition then the entry
 * action is executed conditionally with this trigger.
 */
@Test
public void testEntryActionWithoutGuard() {
    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 entryAction = _createEntryAction(s2);
    _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) entryAction.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 _entrySeq = (Sequence) _s2.getEntryAction();
    assertClass(Sequence.class, _entrySeq.getSteps().get(0));
    assertAssignment(((Sequence) _entrySeq.getSteps().get(0)).getSteps().get(0), "v1", AssignmentOperator.ASSIGN, "42");
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Sequence(org.yakindu.sct.model.sexec.Sequence) Test(org.junit.Test)

Example 9 with SGraphTestFactory._createTransition

use of org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition in project statecharts by Yakindu.

the class ModelSequencerStateReactionTest method testExitActionWithGuard.

/**
 * If a entry trigger is combined with a guard condition then the entry
 * action is executed conditionally with this trigger.
 */
@Test
public void testExitActionWithGuard() {
    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) exitAction.getTrigger()).setGuard(createGuardExpression(_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(If.class, _exitSeq.getSteps().get(0));
    assertClass(PrimitiveValueExpression.class, ((If) _exitSeq.getSteps().get(0)).getCheck().getCondition());
    assertAssignment(((Sequence) ((If) _exitSeq.getSteps().get(0)).getThenStep()).getSteps().get(0), "v1", AssignmentOperator.ASSIGN, "42");
}
Also used : LocalReaction(org.yakindu.sct.model.stext.stext.LocalReaction) StextTestFactory._createLocalReaction(org.yakindu.sct.model.stext.test.util.StextTestFactory._createLocalReaction) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) Scope(org.yakindu.sct.model.sgraph.Scope) StextTestFactory._createInterfaceScope(org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope) StextTestFactory._createVariableDefinition(org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition) VariableDefinition(org.yakindu.sct.model.stext.stext.VariableDefinition) StextTestFactory._createReactionTrigger(org.yakindu.sct.model.stext.test.util.StextTestFactory._createReactionTrigger) ReactionTrigger(org.yakindu.sct.model.stext.stext.ReactionTrigger) SGraphTestFactory._createState(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState) ExecutionState(org.yakindu.sct.model.sexec.ExecutionState) State(org.yakindu.sct.model.sgraph.State) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Sequence(org.yakindu.sct.model.sexec.Sequence) If(org.yakindu.sct.model.sexec.If) Test(org.junit.Test)

Example 10 with SGraphTestFactory._createTransition

use of org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createTransition in project statecharts by Yakindu.

the class ModelSequencerStateVectorTest method testSCStateVectorPseudoStates.

/**
 * The state vector descriptor of the ExecutionFlow must have an offset of 0
 * and a size that is the maximum orthogonality of the statechart.
 */
@Test
public void testSCStateVectorPseudoStates() {
    Statechart sc = _createStatechart("test");
    {
        // first top region
        Region r = _createRegion("sc_r1", sc);
        Entry e = _createEntry(EntryKind.INITIAL, null, r);
        Entry s = _createEntry(null, "s", r);
        _createTransition(e, s);
    }
    ExecutionFlow flow = sequencer.transform(sc);
    assertNotNull(flow.getStateVector());
    assertEquals(0, flow.getStateVector().getSize());
    assertEquals(0, flow.getStateVector().getOffset());
}
Also used : Entry(org.yakindu.sct.model.sgraph.Entry) SGraphTestFactory._createEntry(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry) ExecutionFlow(org.yakindu.sct.model.sexec.ExecutionFlow) Statechart(org.yakindu.sct.model.sgraph.Statechart) SGraphTestFactory._createStatechart(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart) Region(org.yakindu.sct.model.sgraph.Region) SGraphTestFactory._createRegion(org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)46 ExecutionFlow (org.yakindu.sct.model.sexec.ExecutionFlow)46 Statechart (org.yakindu.sct.model.sgraph.Statechart)46 SGraphTestFactory._createStatechart (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createStatechart)46 Region (org.yakindu.sct.model.sgraph.Region)43 SGraphTestFactory._createRegion (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createRegion)43 State (org.yakindu.sct.model.sgraph.State)42 SGraphTestFactory._createState (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createState)42 ExecutionState (org.yakindu.sct.model.sexec.ExecutionState)40 VariableDefinition (org.yakindu.sct.model.stext.stext.VariableDefinition)39 StextTestFactory._createInterfaceScope (org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope)39 StextTestFactory._createVariableDefinition (org.yakindu.sct.model.stext.test.util.StextTestFactory._createVariableDefinition)39 Sequence (org.yakindu.sct.model.sexec.Sequence)37 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)34 Entry (org.yakindu.sct.model.sgraph.Entry)29 SGraphTestFactory._createEntry (org.yakindu.sct.model.sgraph.test.util.SGraphTestFactory._createEntry)29 SCTTestUtil.findState (org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState)24 Reaction (org.yakindu.sct.model.sexec.Reaction)21 EnterState (org.yakindu.sct.model.sexec.EnterState)16 Step (org.yakindu.sct.model.sexec.Step)11