use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class FlowOptimizer_ExecutionEntryTest method testNoNullCall.
@Test
public void testNoNullCall() {
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);
State s2 = _createState("s2", r);
{
_createEntryAssignment(v1, s2, 3);
Region r2 = _createRegion("r2", s2);
{
Entry e = _createEntry(EntryKind.INITIAL, null, r2);
Entry history = _createEntry(EntryKind.SHALLOW_HISTORY, "history", r2);
State s3 = _createState("s3", r2);
{
_createEntryAssignment(v1, s3, 4);
}
State s4 = _createState("s4", r2);
{
Region r4 = _createRegion("r4", s4);
{
Entry e4 = _createEntry(EntryKind.INITIAL, null, r2);
State s5 = _createState("s5", r4);
_createTransition(e4, s5);
_createTransition(s5, s1);
}
}
_createTransition(e, s3);
_createTransition(history, s3);
_createTransition(s3, s4);
_createTransition(s1, history);
}
}
_createTransition(r_entry, s1);
_createTransition(s1, s2);
}
}
ExecutionFlow flow = sequencer.transform(sc);
optimizer.inlineChoices(true);
optimizer.inlineEnterSequences(true);
optimizer.inlineEntryActions(true);
optimizer.inlineExitActions(true);
optimizer.inlineExitRegion(true);
optimizer.inlineExitSequences(true);
optimizer.inlineReactions(true);
optimizer.inlineEntries(true);
optimizer.transform(flow);
TreeIterator<EObject> iter = flow.eAllContents();
while (iter.hasNext()) {
EObject child = iter.next();
if (child instanceof Call) {
Call childCall = (Call) child;
if (childCall.getStep() == null) {
if (childCall.eContainer() instanceof Sequence) {
Sequence sequence = (Sequence) childCall.eContainer();
fail(sequence.getName() + ": " + sequence.getComment());
} else {
fail("Call of null-Step in " + childCall.eContainer());
}
}
}
}
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerHistoryTest method testFlowName.
@SuppressWarnings("unused")
@Test
public void testFlowName() {
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);
State s2 = _createState("s2", r);
{
Region r2 = _createRegion("r2", s2);
{
Entry r2_entry1 = _createEntry(EntryKind.SHALLOW_HISTORY, null, r2);
Entry r2_entry2 = _createEntry(EntryKind.INITIAL, "Unused_Backup", r2);
State s3 = _createState("s3", r2);
State s4 = _createState("s4", r2);
_createTransition(r2_entry1, s3);
_createTransition(r2_entry2, s4);
_createTransition(s1, r2_entry1);
}
}
_createTransition(s1, s2);
Transition _t = _createTransition(s1, s2);
_createTransition(r_entry, s1);
}
}
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.s2", _s2.getName());
ExecutionState _s3 = flow.getStates().get(2);
assertEquals("sc.r.s2.r2.s3", _s3.getName());
ExecutionState _s4 = flow.getStates().get(3);
assertEquals("sc.r.s2.r2.s4", _s4.getName());
ExecutionNode r2_history_entry = flow.getNodes().get(1);
EList<Reaction> _t1 = _s1.getReactions();
Sequence reactSequence_history = flow.getNodes().get(1).getReactSequence();
HistoryEntry historyStep = (HistoryEntry) reactSequence_history.getSteps().get(0);
assertFalse(historyStep.isDeep());
assertCall(firstStep(firstStep(historyStep.getInitialStep())), _s3.getEnterSequences().get(0));
Reaction reaction_history = _t1.get(0);
assertCall(assertedSequence(reaction_history.getEffect()), 1, reactSequence_history);
Sequence reactSequence_initial = flow.getNodes().get(2).getReactSequence();
assertCall(((Sequence) firstStep(firstStep(reactSequence_initial))), 0, _s4.getEnterSequences().get(0));
Reaction reaction = _t1.get(1);
assertCall(assertedSequence(reaction.getEffect()), 1, _s2.getEnterSequences().get(0));
assertCall(_s3.getSuperScope().getEnterSequences().get(0), 0, r2_history_entry.getReactSequence());
Step saveStep = _s3.getEnterSequences().get(0).getSteps().get(1);
assertTrue(saveStep.eClass().toString(), saveStep instanceof SaveHistory);
saveStep = _s4.getEnterSequences().get(0).getSteps().get(1);
assertTrue(saveStep.eClass().toString(), saveStep instanceof SaveHistory);
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerStateTest method testLeafStateExitSequence.
/**
* A leaf state must have a exit sequence. This exit sequence consists of an
* exit action call and a state exit step.
*/
@Test
public void testLeafStateExitSequence() {
Statechart sc = _createStatechart("cs");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("r", sc);
State s1 = _createState("s1", r);
LocalReaction entryAction = _createExitAction(s1);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) entryAction.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
assertEquals(s1.getName(), _s1.getSimpleName());
assertNotNull(_s1.getExitAction());
assertNotNull(_s1.getExitSequence());
assertEquals(2, _s1.getExitSequence().getSteps().size());
assertClass(ExitState.class, _s1.getExitSequence().getSteps().get(0));
assertCall(_s1.getExitSequence(), 1, _s1.getExitAction());
}
use of org.yakindu.sct.model.stext.test.util.StextTestFactory._createInterfaceScope 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._createInterfaceScope in project statecharts by Yakindu.
the class ModelSequencerStateTest method testLeafStateEnterSequence.
/**
* A leaf state must have a enter sequence. This enter sequence consists of
* an entry action call and a state enter step.
*/
@SuppressWarnings("unused")
@Test
public void testLeafStateEnterSequence() {
Statechart sc = _createStatechart("cs");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("r", sc);
State s1 = _createState("s1", r);
LocalReaction entryAction = _createEntryAction(s1);
_createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) entryAction.getEffect());
Entry e = _createEntry(EntryKind.INITIAL, null, r);
Transition t = _createTransition(e, s1);
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s1 = flow.getStates().get(0);
assertEquals(s1.getName(), _s1.getSimpleName());
assertNotNull(_s1.getEntryAction());
assertNotNull(_s1.getEnterSequences().get(0));
assertEquals(2, _s1.getEnterSequences().get(0).getSteps().size());
assertCall(_s1.getEnterSequences().get(0), 0, _s1.getEntryAction());
assertClass(EnterState.class, _s1.getEnterSequences().get(0).getSteps().get(1));
}
Aggregations