use of org.yakindu.sct.model.sexec.ExecutionState in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateReaction_WithTransitionAction.
/**
* The transition action must be part of the reaction effect sequence
*/
@Test
public void testStateReaction_WithTransitionAction() {
SimpleFlatTSC tsc = new SimpleFlatTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
ReactionEffect effect = _createReactionEffect(tsc.t1);
AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), effect);
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
ExecutionState s2 = flow.getStates().get(1);
assertEquals(tsc.s1.getName(), s1.getSimpleName());
assertEquals(tsc.s2.getName(), s2.getSimpleName());
assertEquals(1, s1.getReactions().size());
Reaction reaction = s1.getReactions().get(0);
assertNotNull(reaction.getCheck());
assertNotNull(reaction.getEffect());
Sequence seq = (Sequence) reaction.getEffect();
assertCall(seq, 0, s1.getExitSequence());
assertClass(Sequence.class, seq.getSteps().get(1));
Execution _exec = (Execution) ((Sequence) seq.getSteps().get(1)).getSteps().get(0);
AssignmentExpression _assign = (AssignmentExpression) _exec.getStatement();
assertNotSame(_assign, assign);
assertNotSame(_assign.getVarRef(), assign.getVarRef());
assertNotSame(_assign.getVarRef(), v1);
assertCall(seq, 2, s2.getEnterSequences().get(0));
}
use of org.yakindu.sct.model.sexec.ExecutionState in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_ExitActionExclusion.
/**
* Exit action behaviors are not directly part of the states cycle steps
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_ExitActionExclusion() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createExitAction(tsc.s1);
ReactionEffect lr_eff = _createReactionEffect(lr);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
// TRANSFORM
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(0, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
}
use of org.yakindu.sct.model.sexec.ExecutionState 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.sexec.ExecutionState in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger.
/**
* Local reactions that define regular and entry triggers side by side must
* also be part of the cycle steps.
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_LocalReactionWithMixedRegularAndEntryTrigger() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// add a simple entry action: "entry / x=42;"
LocalReaction lr = _createEntryAction(tsc.s1);
_createRegularEventSpec(tsc.e1, (ReactionTrigger) lr.getTrigger());
ReactionEffect lr_eff = _createReactionEffect(lr);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr_eff);
// TRANSFORM
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(1, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
assertEquals(1, s1.getReactSequence().getSteps().size());
Sequence _seq = (Sequence) s1.getReactSequence().getSteps().get(0);
If _lr1 = (If) assertedSequence(assertedSequence(assertedSequence(assertedSequence(_seq.getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
assertClass(ElementReferenceExpression.class, _lr1.getCheck().getCondition());
assertSame(s1.getReactions().get(0).getCheck().getCondition(), _lr1.getCheck().getCondition());
Call _lr1_eff_call = (Call) _lr1.getThenStep();
assertSame(s1.getReactions().get(0).getEffect(), _lr1_eff_call.getStep());
}
use of org.yakindu.sct.model.sexec.ExecutionState in project statecharts by Yakindu.
the class TreeNamingServiceTest method statechartNamingBaseTest.
@Test
public void statechartNamingBaseTest() {
Statechart toTest = getNamingServiceStatechart();
List<String> names = new ArrayList<>();
List<String> expectedNames = new ArrayList<>(Arrays.asList("main_region_StateA", "main_region_StateB", "second_region_StateA", "third_region_StateA", "second_region_StateA_AnotherRegion_StateA", "second_region_StateA_AnotherRegion_StateB", "third_region_StateA_AnotherRegion_StateA", "third_region_StateA_AnotherRegion_StateB"));
ExecutionFlow flow = optimizer.transform(sequencer.transform(toTest));
executionflowNamingService.setMaxLength(0);
executionflowNamingService.setSeparator('_');
executionflowNamingService.initializeNamingService(flow);
statechartNamingService.setMaxLength(0);
statechartNamingService.setSeparator('_');
statechartNamingService.initializeNamingService(toTest);
for (ExecutionState state : flow.getStates()) {
String name = executionflowNamingService.getShortName(state);
assertEquals(names.contains(name), false);
assertEquals(name, statechartNamingService.getShortName(state));
names.add(name);
}
stringListsEqual(expectedNames, names);
}
Aggregations