Переглянути джерело

Added test for statechart entry action

benjamin.schwertfeger@gmail.com 13 роки тому
батько
коміт
a140c2dc2b

+ 79 - 0
test-plugins/org.yakindu.sct.model.sexec.test/src/org/yakindu/sct/model/sexec/transformation/test/StatechartEnterExistActionTest.java

@@ -0,0 +1,79 @@
+package org.yakindu.sct.model.sexec.transformation.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.TYPE_INTEGER;
+import static org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.findState;
+import static org.yakindu.sct.model.sexec.transformation.test.SCTTestUtil.flattenSequenceStepsAsList;
+import static org.yakindu.sct.model.sgraph.test.util.SgraphTestFactory.*;
+import static org.yakindu.sct.model.stext.test.util.StextTestFactory.*;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.yakindu.sct.model.sexec.CheckRef;
+import org.yakindu.sct.model.sexec.ExecutionFlow;
+import org.yakindu.sct.model.sexec.ExecutionRegion;
+import org.yakindu.sct.model.sexec.ExecutionState;
+import org.yakindu.sct.model.sexec.If;
+import org.yakindu.sct.model.sexec.Reaction;
+import org.yakindu.sct.model.sexec.Sequence;
+import org.yakindu.sct.model.sexec.StateSwitch;
+import org.yakindu.sct.model.sexec.Step;
+import org.yakindu.sct.model.sexec.transformation.test.Assert.StepLeaf;
+import org.yakindu.sct.model.sgraph.Region;
+import org.yakindu.sct.model.sgraph.State;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.model.stext.stext.AssignmentOperator;
+import org.yakindu.sct.model.stext.stext.LocalReaction;
+import org.yakindu.sct.model.stext.stext.ReactionEffect;
+import org.yakindu.sct.model.stext.stext.VariableDefinition;
+
+import com.google.common.collect.Lists;
+
+public class StatechartEnterExistActionTest extends ModelSequencerTest {
+
+	/**
+	 * The transition sequence must contain all exit actions for parent states
+	 * that will be left by a transition.
+	 */
+	@Test
+	public void testSCLocalReaction() {
+
+		Statechart sc = _createStatechart("sc");
+		{
+			VariableDefinition v = _createVariableDefinition("v", TYPE_INTEGER,
+					getOrCreateInternalScope(sc));
+			LocalReaction entryAction = _createEntryAction(sc);
+			ReactionEffect effect = _createReactionEffect(entryAction);
+			_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN,
+					_createValue(1), effect);
+			LocalReaction exitAction = _createExitAction(sc);
+			effect = _createReactionEffect(exitAction);
+			_createVariableAssignment(v, AssignmentOperator.ADD_ASSIGN,
+					_createValue(1), effect);
+
+			Region r = _createRegion("r", sc);
+			{
+				_createState("s1", r);
+			}
+		}
+
+		ExecutionFlow flow = sequencer.transform(sc);
+
+		ExecutionRegion region = flow.getRegions().get(0);
+
+		assertEquals(0, flow.getReactions().size());
+
+		assertedOrder(flow.getEnterSequence(), null, Lists.newArrayList(
+				new StepLeaf(flow.getEntryAction()),
+				new StepLeaf(region.getEnterSequence())));
+
+		assertedOrder(flow.getExitSequence(), null, Lists.newArrayList(
+				new StepLeaf(region.getExitSequence()),
+				new StepLeaf(flow.getExitAction())));
+
+	}
+
+}

+ 10 - 0
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/util/StextTestFactory.java

@@ -162,11 +162,21 @@ public class StextTestFactory extends StextFactoryImpl {
 				StextFactory.eINSTANCE.createEntryEvent());
 	}
 
+	public static LocalReaction _createEntryAction(Statechart parent) {
+		return _createLocalReaction(parent,
+				StextFactory.eINSTANCE.createEntryEvent());
+	}
+
 	public static LocalReaction _createExitAction(State parent) {
 		return _createLocalReaction(parent,
 				StextFactory.eINSTANCE.createExitEvent());
 	}
 
+	public static LocalReaction _createExitAction(Statechart parent) {
+		return _createLocalReaction(parent,
+				StextFactory.eINSTANCE.createExitEvent());
+	}
+
 	public static LocalReaction _createTimeTriggeredReaction(State parent,
 			TimeEventType type, int value, TimeUnit unit) {
 		// TimeEventSpec timeTrigger =