use of org.yakindu.base.expressions.expressions.PrimitiveValueExpression in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testAlwaysTriggerCondition.
/**
* The 'always' trigger event will be converted to a simple 'true'
* condition.
*/
@Test
public void testAlwaysTriggerCondition() {
ReactionTrigger tr1 = _createReactionTrigger(null);
_createAlwaysEventSpec(tr1);
Expression s = behaviorMapping.buildCondition(tr1);
assertNotNull(s);
assertTrue(s instanceof PrimitiveValueExpression);
assertBoolLiteral(true, ((PrimitiveValueExpression) s).getValue());
}
use of org.yakindu.base.expressions.expressions.PrimitiveValueExpression in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testAlwaysLocalReaction.
/**
* Local reactions must be created for behavior with 'always' trigger
*/
@SuppressWarnings("unused")
@Test
public void testAlwaysLocalReaction() {
Statechart sc = _createStatechart("test");
Scope scope = _createInterfaceScope("interface", sc);
VariableDefinition v1 = _createVariableDefinition("v1", TYPE_INTEGER, scope);
Region r = _createRegion("main", sc);
State s = _createState("s", r);
LocalReaction timeTriggeredReaction = _createLocalReaction(s, StextFactory.eINSTANCE.createAlwaysEvent());
AssignmentExpression assign = _createVariableAssignment(v1, AssignmentOperator.ASSIGN, _createValue(42), (ReactionEffect) timeTriggeredReaction.getEffect());
ExecutionFlow flow = sequencer.transform(sc);
ExecutionState _s = flow.getStates().get(0);
// assert that a local reaction is created
Reaction reaction = _s.getReactions().get(0);
PrimitiveValueExpression pve = (PrimitiveValueExpression) reaction.getCheck().getCondition();
assertBoolLiteral(true, pve.getValue());
}
use of org.yakindu.base.expressions.expressions.PrimitiveValueExpression 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.base.expressions.expressions.PrimitiveValueExpression in project statecharts by Yakindu.
the class ModelSequencerStateReactionTest method testTransitionCheckSequenceWithoutTrigger.
@Test
public void testTransitionCheckSequenceWithoutTrigger() {
ReactionTrigger tr1 = _createReactionTrigger(null);
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.
PrimitiveValueExpression guard = (PrimitiveValueExpression) reaction.getCheck().getCondition();
assertBoolLiteral(false, guard.getValue());
}
use of org.yakindu.base.expressions.expressions.PrimitiveValueExpression in project statecharts by Yakindu.
the class StextTestFactory method _createValue.
public static PrimitiveValueExpression _createValue(boolean b) {
PrimitiveValueExpression pve = ExpressionsFactory.eINSTANCE.createPrimitiveValueExpression();
BoolLiteral boolLit = ExpressionsFactory.eINSTANCE.createBoolLiteral();
boolLit.setValue(b);
pve.setValue(boolLit);
return pve;
}
Aggregations