use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.
the class SCTResourceTest method testLinkingSuccess.
@Test
public void testLinkingSuccess() throws Exception {
Statechart statechart = createStatechart("internal: event Event1");
res.getContents().add(statechart);
Transition transition = createTransition("Event1 [true] / 3 * 3");
res.getContents().add(transition);
res.resolveLazyCrossReferences(CancelIndicator.NullImpl);
assertEquals("" + res.getLinkingDiagnostics(), 0, res.getLinkingDiagnostics().size());
ReactionTrigger trigger = (ReactionTrigger) transition.getTrigger();
RegularEventSpec eventSpec = (RegularEventSpec) trigger.getTriggers().get(0);
ElementReferenceExpression expression = (ElementReferenceExpression) eventSpec.getEvent();
EventDefinition reference = (EventDefinition) expression.getReference();
assertNotNull(reference);
assertEquals("Event1", reference.getName());
}
use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testSingleRegularEventTriggerCondition.
/**
* Single trigger events of a Reaction Trigger will be converted into a
* single condition that consists of a ElementReferenceExpression to the
* corresponding event definition.
*/
@Test
public void testSingleRegularEventTriggerCondition() {
EventDefinition e1 = _createEventDefinition("e1", null);
ReactionTrigger tr1 = _createReactionTrigger(null);
_createRegularEventSpec(e1, tr1);
Expression s = behaviorMapping.buildCondition(tr1);
assertClass(ElementReferenceExpression.class, s);
}
use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithGuard.
@Test
public void testTransitionCheckSequenceWithGuard() {
EventDefinition e1 = _createEventDefinition("e1", null);
EventDefinition e2 = _createEventDefinition("e2", null);
ReactionTrigger tr1 = _createReactionTrigger(null);
_createRegularEventSpec(e1, tr1);
_createRegularEventSpec(e2, tr1);
PrimitiveValueExpression exp = _createValue(false);
tr1.setGuard(createGuardExpression(exp));
Transition t = SGraphFactory.eINSTANCE.createTransition();
t.setTrigger(tr1);
Statechart sc = _createStatechart("test");
Region region = _createRegion("r1", sc);
t.setSource(_createState("A", region));
t.setTarget(_createState("B", region));
Reaction reaction = behaviorMapping.mapTransition(t);
// now check the expression structure ...
// the root is an and condition with the trigger check as the first
// (left) part and the guard as the right (second) part.
LogicalAndExpression and = (LogicalAndExpression) reaction.getCheck().getCondition();
ParenthesizedExpression parenthesis = (ParenthesizedExpression) and.getLeftOperand();
LogicalOrExpression triggerCheck = (LogicalOrExpression) parenthesis.getExpression();
PrimitiveValueExpression guardCheck = (PrimitiveValueExpression) ((ParenthesizedExpression) and.getRightOperand()).getExpression();
assertClass(ElementReferenceExpression.class, triggerCheck.getLeftOperand());
assertClass(ElementReferenceExpression.class, triggerCheck.getRightOperand());
assertEquals(e1.getName(), ((NamedElement) ((ElementReferenceExpression) triggerCheck.getLeftOperand()).getReference()).getName());
assertEquals(e2.getName(), ((NamedElement) ((ElementReferenceExpression) triggerCheck.getRightOperand()).getReference()).getName());
assertBoolLiteral(false, guardCheck.getValue());
}
use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithoutGuard.
@Test
public void testTransitionCheckSequenceWithoutGuard() {
EventDefinition e1 = _createEventDefinition("e1", null);
EventDefinition e2 = _createEventDefinition("e2", null);
ReactionTrigger tr1 = _createReactionTrigger(null);
_createRegularEventSpec(e1, tr1);
_createRegularEventSpec(e2, tr1);
Transition t = SGraphFactory.eINSTANCE.createTransition();
t.setTrigger(tr1);
Statechart sc = _createStatechart("test");
Region region = _createRegion("r1", sc);
t.setSource(_createState("A", region));
t.setTarget(_createState("B", region));
Reaction reaction = behaviorMapping.mapTransition(t);
assertTrue(reaction.getCheck().getCondition() instanceof LogicalOrExpression);
assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand());
assertClass(ElementReferenceExpression.class, ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand());
assertEquals(e1.getName(), ((NamedElement) ((ElementReferenceExpression) ((LogicalOrExpression) reaction.getCheck().getCondition()).getLeftOperand()).getReference()).getName());
assertEquals(e2.getName(), ((NamedElement) ((ElementReferenceExpression) ((LogicalOrExpression) reaction.getCheck().getCondition()).getRightOperand()).getReference()).getName());
}
use of org.yakindu.sct.model.stext.stext.EventDefinition in project statecharts by Yakindu.
the class ModelSequencertDeclarationsTest method testMapScope.
@SuppressWarnings("unused")
@Test
public void testMapScope() {
InterfaceScope scope = _createInterfaceScope(null, null);
EventDefinition e1 = _createEventDefinition("e1", scope);
EventDefinition e2 = _createEventDefinition("e2", scope);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Scope _scope = structureMapping.mapScope(scope);
assertTrue(_scope instanceof InterfaceScope);
assertEquals(3, _scope.getDeclarations().size());
for (int i = 0; i < _scope.getDeclarations().size(); i++) {
Declaration s_decl = scope.getDeclarations().get(i);
Declaration r_decl = _scope.getDeclarations().get(i);
assertNotSame(s_decl, r_decl);
assertEquals(s_decl.getName(), r_decl.getName());
assertEquals(s_decl.getClass(), r_decl.getClass());
}
}
Aggregations