use of org.yakindu.sct.model.sexec.Call in project statecharts by Yakindu.
the class ModelSequencerSCTest 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);
TreeIterator<EObject> iter = flow.eAllContents();
while (iter.hasNext()) {
EObject child = iter.next();
if (child instanceof Call) {
Call childCall = (Call) child;
if (childCall.getStep() == null) {
Sequence sequence = assertedSequence((Step) childCall.eContainer());
fail(sequence.getName() + ": " + sequence.getComment());
}
}
}
}
use of org.yakindu.sct.model.sexec.Call in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle.
@Test
public void testStateCycle() {
OrthogonalFlatTSC tsc = new OrthogonalFlatTSC();
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());
assertNotNull(s1.getReactSequence());
Step step = s1.getReactSequence().getSteps().get(0);
If _if = (If) assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0);
assertNotNull(_if.getThenStep());
assertClass(Call.class, _if.getThenStep());
assert (assertedSequence(assertedSequence(_if.getElseStep()).getSteps().get(0)).getSteps().isEmpty());
Call seq = (Call) _if.getThenStep();
assertEquals(s1.getReactions().get(0).getEffect(), seq.getStep());
// assertTrue(seq.getSteps().get(0) instanceof ExitState);
// assertEquals(s1, ((ExitState)seq.getSteps().get(0)).getState());
// assertTrue(seq.getSteps().get(1) instanceof EnterState);
// assertEquals(s2, ((EnterState)seq.getSteps().get(1)).getState());
//
// test state with two outgoing transitions
ExecutionState s3 = flow.getStates().get(2);
assertEquals(tsc.s3.getName(), s3.getSimpleName());
assertNotNull(s3.getReactSequence());
step = s3.getReactSequence().getSteps().get(0);
_if = (If) step;
assertNotNull(_if.getThenStep());
assertClass(Call.class, _if.getThenStep());
assertNotNull(_if.getElseStep());
assertClass(If.class, _if.getElseStep());
}
use of org.yakindu.sct.model.sexec.Call 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.Call 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.sexec.Call in project statecharts by Yakindu.
the class ModelSequencerStateTest method testStateCycle_WithLocalReactionsOnly.
/**
* The cycle sequence of a state that only consists of local reactions
* includes sequential processing of the local reactions.
*/
@SuppressWarnings("unused")
@Test
public void testStateCycle_WithLocalReactionsOnly() {
MinimalTSC tsc = new MinimalTSC();
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, tsc.s_scope);
// the first local reaction conforms to "e1 / x=42;"
LocalReaction lr1 = _createLocalReaction(tsc.s1, null);
_createRegularEventSpec(tsc.e1, (ReactionTrigger) lr1.getTrigger());
ReactionEffect lr1_eff = _createReactionEffect(lr1);
AssignmentExpression assign1 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), lr1_eff);
// the secont local reaction conforms to "e1 [x==42] / x=0;"
LocalReaction lr2 = _createLocalReaction(tsc.s1, null);
_createRegularEventSpec(tsc.e1, (ReactionTrigger) lr2.getTrigger());
LogicalRelationExpression lr2_equals = ExpressionsFactory.eINSTANCE.createLogicalRelationExpression();
lr2_equals.setOperator(RelationalOperator.EQUALS);
ElementReferenceExpression lr2_varRef = ExpressionsFactory.eINSTANCE.createElementReferenceExpression();
lr2_varRef.setReference(v1);
PrimitiveValueExpression lr2_value = _createValue(42);
lr2_equals.setLeftOperand(lr2_varRef);
lr2_equals.setRightOperand(lr2_value);
((ReactionTrigger) lr2.getTrigger()).setGuard(createGuardExpression(lr2_equals));
ReactionEffect lr2_eff = _createReactionEffect(lr2);
AssignmentExpression assign2 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(0), lr2_eff);
// the third local reaction conforms to: "[x==0] / x=1;"
LocalReaction lr3 = _createLocalReaction(tsc.s1, null);
LogicalRelationExpression lr3_equals = ExpressionsFactory.eINSTANCE.createLogicalRelationExpression();
lr3_equals.setOperator(RelationalOperator.EQUALS);
ElementReferenceExpression lr3_varRef = ExpressionsFactory.eINSTANCE.createElementReferenceExpression();
lr3_varRef.setReference(v1);
PrimitiveValueExpression lr3_value = _createValue(0);
lr3_equals.setLeftOperand(lr3_varRef);
lr3_equals.setRightOperand(lr3_value);
((ReactionTrigger) lr3.getTrigger()).setGuard(createGuardExpression(lr3_equals));
ReactionEffect lr3_eff = _createReactionEffect(lr3);
AssignmentExpression assign3 = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(1), lr3_eff);
ExecutionFlow flow = sequencer.transform(tsc.sc);
// test state with one outgoing transition
ExecutionState s1 = flow.getStates().get(0);
assertEquals(tsc.s1.getName(), s1.getSimpleName());
assertEquals(3, s1.getReactions().size());
assertNotNull(s1.getReactSequence());
Step step = s1.getReactSequence().getSteps().get(0);
Sequence _seq = assertedSequence(assertedSequence(assertedSequence(assertedSequence(assertedSequence(step).getSteps().get(0)).getSteps().get(0)).getSteps().get(0)).getSteps().get(0));
assertEquals(3, _seq.getSteps().size());
// check first local reaction
If _lr1 = (If) _seq.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());
// check second local reaction
If _lr2 = (If) _seq.getSteps().get(1);
assertClass(LogicalAndExpression.class, _lr2.getCheck().getCondition());
assertSame(s1.getReactions().get(1).getCheck().getCondition(), _lr2.getCheck().getCondition());
Call _lr2_eff_call = (Call) _lr2.getThenStep();
assertSame(s1.getReactions().get(1).getEffect(), _lr2_eff_call.getStep());
// check the third local reaction
If _lr3 = (If) _seq.getSteps().get(2);
assertClass(LogicalRelationExpression.class, _lr3.getCheck().getCondition());
assertSame(s1.getReactions().get(2).getCheck().getCondition(), _lr3.getCheck().getCondition());
Call _lr3_eff_call = (Call) _lr3.getThenStep();
assertSame(s1.getReactions().get(2).getEffect(), _lr3_eff_call.getStep());
}
Aggregations