Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2017-02-27 08:45:28 -0500
committerHenrik Rentz-Reichert2017-02-27 08:45:28 -0500
commita22cc46d84a76e5d025205edce05ac7137704659 (patch)
tree7fc00109b53dce11127c209c87a8af2c762a8b77
parent69bcef330ef6508b6b42746a2f0515da60d1cbea (diff)
downloadorg.eclipse.etrice-a22cc46d84a76e5d025205edce05ac7137704659.tar.gz
org.eclipse.etrice-a22cc46d84a76e5d025205edce05ac7137704659.tar.xz
org.eclipse.etrice-a22cc46d84a76e5d025205edce05ac7137704659.zip
Bug 511330 - [core.genmodel.fsm] introduce simplified generator model for state machines
- more from the genmodel.tests (as far as state machines are concerned) - common data computation Change-Id: Id57666981218a5a8bad71641762b9303a7053ad4
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend2
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.xtend42
-rw-r--r--plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.java114
-rw-r--r--plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/CommonDataCalculator.xtend30
-rw-r--r--plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/room/util/CommonDataCalculator.java46
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/MultipleConnectedChoicepointExample.room119
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/StatesInheritanceExample.room234
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/Types.room13
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.xtend117
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.xtend117
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.xtend56
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.java272
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.java263
-rw-r--r--tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.java169
14 files changed, 1572 insertions, 22 deletions
diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend b/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend
index c78e60d91..f259ca69a 100644
--- a/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend
+++ b/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/ExtendedFsmGenBuilder.xtend
@@ -80,7 +80,7 @@ class ExtendedFsmGenBuilder extends BasicFsmGenBuilder {
}
private def void followChain(Link l, Link head) {
- // if we started at an initial or guarded transition no interface item can't be provided
+ // if we started at an initial or guarded transition no interface item can be provided
if (!(head.transition instanceof TriggeredTransition)) {
l.ifitemTriggered = false
}
diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.xtend b/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.xtend
index 11d9e5f0f..46b50f929 100644
--- a/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.xtend
+++ b/plugins/org.eclipse.etrice.core.genmodel.fsm2/src/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.xtend
@@ -25,6 +25,10 @@ import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
+import org.eclipse.etrice.core.fsm.fSM.EntryPoint
+import org.eclipse.etrice.core.fsm.fSM.ExitPoint
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition
+import org.eclipse.etrice.core.fsm.fSM.CPBranchTransition
class FsmGenExtensions {
@@ -60,6 +64,30 @@ class FsmGenExtensions {
g.allNodes.filter[stateGraphNode instanceof TrPoint]
}
+ public static def getTransitionPointNodes(Graph g) {
+ g.nodes.filter[stateGraphNode instanceof TransitionPoint]
+ }
+
+ public static def getAllTransitionPointNodes(Graph g) {
+ g.allNodes.filter[stateGraphNode instanceof TransitionPoint]
+ }
+
+ public static def getEntryPointNodes(Graph g) {
+ g.nodes.filter[stateGraphNode instanceof EntryPoint]
+ }
+
+ public static def getAllEntryPointNodes(Graph g) {
+ g.allNodes.filter[stateGraphNode instanceof EntryPoint]
+ }
+
+ public static def getExitPointNodes(Graph g) {
+ g.nodes.filter[stateGraphNode instanceof ExitPoint]
+ }
+
+ public static def getAllExitPointNodes(Graph g) {
+ g.allNodes.filter[stateGraphNode instanceof ExitPoint]
+ }
+
public static def getStates(Graph g) {
g.stateNodes.map[stateGraphNode].filter(typeof(State))
}
@@ -68,7 +96,7 @@ class FsmGenExtensions {
g.choicePointNodes.map[stateGraphNode].filter(typeof(ChoicePoint))
}
- public static def getTransitionPoints(Graph g) {
+ public static def getTrPoints(Graph g) {
g.trPointNodes.map[stateGraphNode].filter(typeof(TrPoint))
}
@@ -76,10 +104,22 @@ class FsmGenExtensions {
g.eAllContents.filter(typeof(Link))
}
+ public static def getAllInitialTranisitionLinks(Graph g) {
+ g.allLinks.filter[transition instanceof InitialTransition]
+ }
+
public static def getAllTriggeredTranisitionLinks(Graph g) {
g.allLinks.filter[transition instanceof TriggeredTransition]
}
+ public static def getAllContinuationTranisitionLinks(Graph g) {
+ g.allLinks.filter[transition instanceof ContinuationTransition]
+ }
+
+ public static def getAllCPBranchTranisitionLinks(Graph g) {
+ g.allLinks.filter[transition instanceof CPBranchTransition]
+ }
+
/**
* returns all links whose transitions are chain heads
*
diff --git a/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.java b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.java
index 0c22ca639..90e3464cc 100644
--- a/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.java
+++ b/plugins/org.eclipse.etrice.core.genmodel.fsm2/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/FsmGenExtensions.java
@@ -16,7 +16,11 @@ import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.fsm.fSM.CPBranchTransition;
import org.eclipse.etrice.core.fsm.fSM.ChoicePoint;
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition;
+import org.eclipse.etrice.core.fsm.fSM.EntryPoint;
+import org.eclipse.etrice.core.fsm.fSM.ExitPoint;
import org.eclipse.etrice.core.fsm.fSM.GuardedTransition;
import org.eclipse.etrice.core.fsm.fSM.InitialTransition;
import org.eclipse.etrice.core.fsm.fSM.RefinedTransition;
@@ -119,6 +123,78 @@ public class FsmGenExtensions {
return IteratorExtensions.<Node>filter(_allNodes, _function);
}
+ public static Iterable<Node> getTransitionPointNodes(final Graph g) {
+ EList<Node> _nodes = g.getNodes();
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof TransitionPoint));
+ }
+ };
+ return IterableExtensions.<Node>filter(_nodes, _function);
+ }
+
+ public static Iterator<Node> getAllTransitionPointNodes(final Graph g) {
+ Iterator<Node> _allNodes = FsmGenExtensions.getAllNodes(g);
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof TransitionPoint));
+ }
+ };
+ return IteratorExtensions.<Node>filter(_allNodes, _function);
+ }
+
+ public static Iterable<Node> getEntryPointNodes(final Graph g) {
+ EList<Node> _nodes = g.getNodes();
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof EntryPoint));
+ }
+ };
+ return IterableExtensions.<Node>filter(_nodes, _function);
+ }
+
+ public static Iterator<Node> getAllEntryPointNodes(final Graph g) {
+ Iterator<Node> _allNodes = FsmGenExtensions.getAllNodes(g);
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof EntryPoint));
+ }
+ };
+ return IteratorExtensions.<Node>filter(_allNodes, _function);
+ }
+
+ public static Iterable<Node> getExitPointNodes(final Graph g) {
+ EList<Node> _nodes = g.getNodes();
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof ExitPoint));
+ }
+ };
+ return IterableExtensions.<Node>filter(_nodes, _function);
+ }
+
+ public static Iterator<Node> getAllExitPointNodes(final Graph g) {
+ Iterator<Node> _allNodes = FsmGenExtensions.getAllNodes(g);
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof ExitPoint));
+ }
+ };
+ return IteratorExtensions.<Node>filter(_allNodes, _function);
+ }
+
public static Iterable<State> getStates(final Graph g) {
Iterable<Node> _stateNodes = FsmGenExtensions.getStateNodes(g);
final Function1<Node, StateGraphNode> _function = new Function1<Node, StateGraphNode>() {
@@ -143,7 +219,7 @@ public class FsmGenExtensions {
return Iterables.<ChoicePoint>filter(_map, ChoicePoint.class);
}
- public static Iterable<TrPoint> getTransitionPoints(final Graph g) {
+ public static Iterable<TrPoint> getTrPoints(final Graph g) {
Iterable<Node> _trPointNodes = FsmGenExtensions.getTrPointNodes(g);
final Function1<Node, StateGraphNode> _function = new Function1<Node, StateGraphNode>() {
@Override
@@ -160,6 +236,18 @@ public class FsmGenExtensions {
return Iterators.<Link>filter(_eAllContents, Link.class);
}
+ public static Iterator<Link> getAllInitialTranisitionLinks(final Graph g) {
+ Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(g);
+ final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ return Boolean.valueOf((_transition instanceof InitialTransition));
+ }
+ };
+ return IteratorExtensions.<Link>filter(_allLinks, _function);
+ }
+
public static Iterator<Link> getAllTriggeredTranisitionLinks(final Graph g) {
Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(g);
final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
@@ -172,6 +260,30 @@ public class FsmGenExtensions {
return IteratorExtensions.<Link>filter(_allLinks, _function);
}
+ public static Iterator<Link> getAllContinuationTranisitionLinks(final Graph g) {
+ Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(g);
+ final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ return Boolean.valueOf((_transition instanceof ContinuationTransition));
+ }
+ };
+ return IteratorExtensions.<Link>filter(_allLinks, _function);
+ }
+
+ public static Iterator<Link> getAllCPBranchTranisitionLinks(final Graph g) {
+ Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(g);
+ final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ return Boolean.valueOf((_transition instanceof CPBranchTransition));
+ }
+ };
+ return IteratorExtensions.<Link>filter(_allLinks, _function);
+ }
+
/**
* returns all links whose transitions are chain heads
*
diff --git a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/CommonDataCalculator.xtend b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/CommonDataCalculator.xtend
index 4e32cf435..082bb6797 100644
--- a/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/CommonDataCalculator.xtend
+++ b/plugins/org.eclipse.etrice.core.room/src/org/eclipse/etrice/core/room/util/CommonDataCalculator.xtend
@@ -12,16 +12,19 @@
package org.eclipse.etrice.core.room.util
-import org.eclipse.etrice.core.genmodel.fsm.ICommonDataCalculator
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
-import org.eclipse.etrice.core.fsm.fSM.RefinedTransition
import org.eclipse.emf.ecore.EObject
+import org.eclipse.etrice.core.fsm.fSM.RefinedTransition
+import org.eclipse.etrice.core.fsm.fSM.TransitionBase
import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition
+import org.eclipse.etrice.core.genmodel.fsm.ICommonDataCalculator
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link
import org.eclipse.etrice.core.room.Message
-import org.eclipse.etrice.core.fsm.fSM.TransitionBase
+import org.eclipse.etrice.core.room.RoomFactory
class CommonDataCalculator implements ICommonDataCalculator {
+ RoomHelpers roomHelpers = new RoomHelpers
+
override EObject calculateCommonData(Link l) {
if (!l.isIfitemTriggered) {
return null
@@ -34,14 +37,21 @@ class CommonDataCalculator implements ICommonDataCalculator {
val triggers = transitions.map[triggers].flatten
// and we have data which may be null
- val allData = triggers.map[msgFromIfPairs].flatten.map[(message as Message).data?.refType?.type].toSet
+ val varDeclarations = triggers.map[msgFromIfPairs].flatten.map[(message as Message).data]
+ val allData = varDeclarations.map[it?.refType?.type].toSet
if (allData.size==1) {
- return allData.head
+ return varDeclarations.head
+ }
+ else {
+ val types = varDeclarations.map[it?.refType].toList
+ val rt = roomHelpers.getLastCommonSuperType(types);
+ if (rt!=null) {
+ val vd = RoomFactory.eINSTANCE.createVarDecl
+ vd.name = "data"
+ vd.refType = rt
+ return vd
+ }
}
-
- // TODO: implement a logic that really computes the greatest common type.
- // This will stop if one or more data are null. Then we return null (no common data).
- // If the data have no common type we return the link itself indicating a general Object or void*
}
return null
diff --git a/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/room/util/CommonDataCalculator.java b/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/room/util/CommonDataCalculator.java
index 846d02797..976d28914 100644
--- a/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/room/util/CommonDataCalculator.java
+++ b/plugins/org.eclipse.etrice.core.room/xtend-gen/org/eclipse/etrice/core/room/util/CommonDataCalculator.java
@@ -10,6 +10,7 @@
*/
package org.eclipse.etrice.core.room.util;
+import com.google.common.base.Objects;
import com.google.common.collect.Iterables;
import java.util.List;
import java.util.Set;
@@ -26,13 +27,17 @@ import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
import org.eclipse.etrice.core.room.DataType;
import org.eclipse.etrice.core.room.Message;
import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomFactory;
import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
@SuppressWarnings("all")
public class CommonDataCalculator implements ICommonDataCalculator {
+ private RoomHelpers roomHelpers = new RoomHelpers();
+
@Override
public EObject calculateCommonData(final Link l) {
boolean _isIfitemTriggered = l.isIfitemTriggered();
@@ -66,14 +71,20 @@ public class CommonDataCalculator implements ICommonDataCalculator {
};
Iterable<EList<MessageFromIf>> _map_2 = IterableExtensions.<Trigger, EList<MessageFromIf>>map(triggers, _function_2);
Iterable<MessageFromIf> _flatten = Iterables.<MessageFromIf>concat(_map_2);
- final Function1<MessageFromIf, DataType> _function_3 = new Function1<MessageFromIf, DataType>() {
+ final Function1<MessageFromIf, VarDecl> _function_3 = new Function1<MessageFromIf, VarDecl>() {
@Override
- public DataType apply(final MessageFromIf it) {
+ public VarDecl apply(final MessageFromIf it) {
EObject _message = it.getMessage();
- VarDecl _data = ((Message) _message).getData();
+ return ((Message) _message).getData();
+ }
+ };
+ final Iterable<VarDecl> varDeclarations = IterableExtensions.<MessageFromIf, VarDecl>map(_flatten, _function_3);
+ final Function1<VarDecl, DataType> _function_4 = new Function1<VarDecl, DataType>() {
+ @Override
+ public DataType apply(final VarDecl it) {
RefableType _refType = null;
- if (_data!=null) {
- _refType=_data.getRefType();
+ if (it!=null) {
+ _refType=it.getRefType();
}
DataType _type = null;
if (_refType!=null) {
@@ -82,12 +93,33 @@ public class CommonDataCalculator implements ICommonDataCalculator {
return _type;
}
};
- Iterable<DataType> _map_3 = IterableExtensions.<MessageFromIf, DataType>map(_flatten, _function_3);
+ Iterable<DataType> _map_3 = IterableExtensions.<VarDecl, DataType>map(varDeclarations, _function_4);
final Set<DataType> allData = IterableExtensions.<DataType>toSet(_map_3);
int _size = allData.size();
boolean _equals = (_size == 1);
if (_equals) {
- return IterableExtensions.<DataType>head(allData);
+ return IterableExtensions.<VarDecl>head(varDeclarations);
+ } else {
+ final Function1<VarDecl, RefableType> _function_5 = new Function1<VarDecl, RefableType>() {
+ @Override
+ public RefableType apply(final VarDecl it) {
+ RefableType _refType = null;
+ if (it!=null) {
+ _refType=it.getRefType();
+ }
+ return _refType;
+ }
+ };
+ Iterable<RefableType> _map_4 = IterableExtensions.<VarDecl, RefableType>map(varDeclarations, _function_5);
+ final List<RefableType> types = IterableExtensions.<RefableType>toList(_map_4);
+ final RefableType rt = this.roomHelpers.getLastCommonSuperType(types);
+ boolean _notEquals = (!Objects.equal(rt, null));
+ if (_notEquals) {
+ final VarDecl vd = RoomFactory.eINSTANCE.createVarDecl();
+ vd.setName("data");
+ vd.setRefType(rt);
+ return vd;
+ }
}
}
return null;
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/MultipleConnectedChoicepointExample.room b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/MultipleConnectedChoicepointExample.room
new file mode 100644
index 000000000..ddaeabc48
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/MultipleConnectedChoicepointExample.room
@@ -0,0 +1,119 @@
+RoomModel TemplateModel {
+
+ import room.basic.types.* from "Types.room"
+
+ ActorClass TestActor {
+ Interface {
+ Port p0: PC
+ }
+ Structure {
+ external Port p0
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> state0 { }
+ Transition tr0: state0 -> cp cp0 {
+ triggers {
+ <m1: p0>
+ }
+ action {
+ "// left"
+ }
+ }
+ Transition tr1: state0 -> tp0 of state1 {
+ triggers {
+ <m2: p0>
+ }
+ }
+ Transition tr3: cp cp0 -> state2 {
+ action {
+ "// dflt branch"
+ }
+ }
+ Transition tr4: cp cp0 -> state3 {
+ cond {
+ "data.x>0"
+ }
+ action {
+ "// false branch"
+ }
+ }
+ Transition tr2: tp1 of state1 -> cp cp0 {
+ action {
+ "// right"
+ }
+ }
+ ChoicePoint cp0
+ State state0
+ State state1 {
+ subgraph {
+ Transition tr0: my tp0 -> state0
+ Transition tr1: state0 -> state1 {
+ triggers {
+ <m0: p0>
+ }
+ }
+ Transition tr2: state0 -> my tp1 {
+ triggers {
+ <m1: p0>
+ }
+ action {
+ "//state1/tr2"
+ }
+ }
+ Transition tr3: state1 -> my tp1 {
+ triggers {
+ <m3: p0>
+ }
+ action {
+ "//state1/tr3"
+ }
+ }
+ EntryPoint tp0
+ ExitPoint tp1
+ State state0
+ State state1
+ }
+ }
+ State state2
+ State state3
+ }
+ }
+ }
+
+ ProtocolClass PC {
+ incoming {
+ Message m0()
+ Message m1(data: DC2)
+ Message m2(data: DC3)
+ Message m3(data: DC4)
+ }
+ outgoing {
+ Message m1()
+ }
+ }
+
+ DataClass DC {
+ Attribute x: int32
+ }
+
+ DataClass DC1 {
+ Attribute a: int32
+ Attribute b: int32
+ Attribute c: int32
+ }
+
+ DataClass DC2 extends DC {
+ Attribute y: int32
+ Attribute r: DC1
+ }
+
+ DataClass DC3 extends DC {
+ Attribute z: int32
+ }
+
+ DataClass DC4 extends DC3 {
+ Attribute w: int32
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/StatesInheritanceExample.room b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/StatesInheritanceExample.room
new file mode 100644
index 000000000..354489aa8
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/StatesInheritanceExample.room
@@ -0,0 +1,234 @@
+RoomModel states_inheritance.t {
+
+ PrimitiveType int32: ptInteger -> int32 (Integer) default "0"
+
+ ProtocolClass PTimer {
+ incoming {
+ Message start (time_ms : int32)
+ Message kill ()
+ }
+ outgoing {
+ Message timerTick ()
+ }
+ }
+
+ ProtocolClass PTimeout {
+ incoming {
+ Message start (time_ms : int32)
+ Message kill ()
+ }
+ outgoing {
+ Message timeoutTick ()
+ }
+ }
+
+ ActorClass ATimingService {
+ Interface {
+ SPP timerSPP: PTimer
+ SPP timeoutSPP: PTimeout
+ }
+ Structure {
+ ServiceImplementation of timerSPP
+ ServiceImplementation of timeoutSPP
+ }
+ }
+
+ ProtocolClass PTest1 {
+ incoming {
+ Message a ()
+ Message b (x : int32)
+ Message c ()
+ }
+ outgoing {
+ Message x ()
+ }
+ }
+
+ ProtocolClass PTest2 {
+ incoming {
+ Message x ()
+ Message y ()
+ Message z ()
+ }
+ outgoing {
+ Message a ()
+ }
+ }
+
+ ProtocolClass PTest3 {
+ incoming {
+ Message a ()
+ }
+ outgoing {
+ Message b ()
+ }
+ }
+
+ ActorClass ABase {
+ Interface {
+ Port fct : PTest1
+ }
+ Structure {
+ external Port fct
+ Port subp : PTest2
+ SAP timer: PTimer
+ SAP timeout: PTimeout
+ }
+ Behavior {
+ StateMachine {
+ State State1 {}
+ State State2 {}
+ State State3 {
+ subgraph {
+ State State1 {}
+ State State2 {}
+ State State3 {}
+ EntryPoint tp1
+ TransitionPoint tp2
+ ExitPoint tp3
+ handler TransitionPoint tp5
+ Transition tr0: initial -> State1 {}
+ Transition tr1: my tp1 -> State3 {}
+ Transition tr2: State1 -> State2 {
+ triggers {
+ <b:fct>
+ }
+ }
+ Transition tr3: State2 -> State3 {
+ triggers {
+ <c:fct>
+ }
+ }
+ Transition tr4: State3 -> State1 {
+ triggers {
+ <a:fct>
+ }
+ }
+ Transition tr5: my tp2 -> State3 {
+ triggers {
+ <b:fct>
+ }
+ }
+ Transition tr6: State3 -> my tp3 {
+ triggers {
+ <c:fct>
+ }
+ }
+ Transition tr7: my tp5 -> my tp5 {
+ triggers {
+ <timeoutTick:timeout>
+ }
+ }
+ }
+ }
+ State State4 {}
+ TransitionPoint tp0
+ TransitionPoint tp1
+ ChoicePoint CP1
+ Transition tr0: initial -> State1 {}
+ Transition tr1: State1 -> State2 {
+ triggers {
+ <a:fct>
+ }
+ }
+ Transition tr2: State2 -> cp CP1 {
+ triggers {
+ <b:fct>
+ }
+ }
+ Transition tr3: cp CP1 -> State1 {}
+ Transition tr4: cp CP1 -> State3 {
+ cond {
+ "data==2"
+ }
+ }
+ Transition tr5: my tp0 -> tp1 of State3 {
+ triggers {
+ <a:fct>
+ }
+ }
+ Transition tr6: cp CP1 -> State4 {
+ cond {
+ "data==3"
+ }
+ }
+ Transition tr7: tp3 of State3 -> State2 {}
+ Transition tr8: State3 -> State2 {
+ triggers {
+ <c:fct>
+ }
+ }
+ Transition tr9: my tp1 -> State2 {
+ triggers {
+ <timerTick:timer>
+ }
+ }
+ }
+ }
+ }
+
+ ActorClass TestActor extends ABase {
+ Interface {
+ Port port : PTest3
+ }
+ Structure {
+ external Port port
+ }
+ Behavior {
+ StateMachine {
+ RefinedState State3 {
+ subgraph {
+ State State4 {}
+ EntryPoint tp6
+ TransitionPoint tp7
+ Transition tr8: my tp6 -> State2 {}
+ Transition tr9: my tp7 -> my tp7 {
+ triggers {
+ <z:subp>
+ }
+ }
+ Transition tr10a: State2 -> State4 {
+ triggers {
+ <y:subp>
+ }
+ }
+ Transition tr11a: State4 -> my tp3 {
+ triggers {
+ <z:subp>
+ }
+ }
+ }
+ }
+ RefinedState State4 {
+ subgraph {
+ State State1 {}
+ State State2 {}
+ Transition tr0: initial -> State1 {}
+ Transition tr1: State1 -> State2 {
+ triggers {
+ <a:port>
+ }
+ }
+ }
+ }
+ State State5 {}
+ Transition tr10: State1 -> State5 {
+ triggers {
+ <a:port>
+ }
+ }
+ Transition tr11: cp CP1 -> State5 {
+ cond {
+ "data==4"
+ }
+ }
+ Transition tr12: State5 -> tp6 of State3 {
+ triggers {
+ <a:port>
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/Types.room b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/Types.room
new file mode 100644
index 000000000..b27d100f4
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/models/Types.room
@@ -0,0 +1,13 @@
+RoomModel room.basic.types {
+
+ PrimitiveType boolean: ptBoolean -> 'boolean' (Boolean) default 'false'
+ PrimitiveType char: ptCharacter -> 'char' (Char) default ''
+ PrimitiveType int8: ptInteger -> 'byte' (Byte) default '0'
+ PrimitiveType int16: ptInteger -> 'short' (Short) default '0'
+ PrimitiveType int32: ptInteger -> 'int' (Integer) default '0'
+ PrimitiveType int64: ptInteger -> 'long' (Long) default '0'
+ PrimitiveType float32: ptReal -> 'float' (Float) default '0'
+ PrimitiveType float64: ptReal -> 'double' (Double) default '0'
+ PrimitiveType string: ptCharacter -> 'String' (String) default ''
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.xtend b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.xtend
new file mode 100644
index 000000000..4a991a136
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.xtend
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.genmodel.fsm.tests
+
+import org.eclipse.etrice.core.fsm.fSM.CPBranchTransition
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition
+import org.eclipse.etrice.core.fsm.fSM.Transition
+import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker
+import org.eclipse.etrice.core.genmodel.fsm.NullLogger
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.naming.RoomNameProvider
+import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.VarDecl
+import org.junit.Before
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+import static org.junit.Assert.assertFalse
+import static org.junit.Assert.assertNotNull
+import static org.junit.Assert.assertTrue
+
+import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.*
+
+class TestMultipleConnectedChoicepoint extends FsmGenTestBase {
+
+ GraphContainer gc
+
+ @Before
+ def void SetUp() {
+ gc = getGraphContainer("MultipleConnectedChoicepointExample.room", "TestActor")
+ assertNotNull("graph context was created", gc)
+
+ val logger = new NullLogger
+ FsmGenChecker.check(gc, logger)
+ assertFalse("logger has no errors", logger.hasErrors)
+
+ // enrich our generator model with all we have
+ gc.withTriggersInStates.withChainHeads.withCommonData
+
+ assertFalse("diagnostician has no errors", diagnostician.isFailed)
+ }
+
+ @Test
+ def void testObjectNumbers() {
+ assertEquals("Number of states", 6, gc.graph.allStateNodes.size)
+ assertEquals("Number of choice points", 1, gc.graph.allChoicePointNodes.size)
+ assertEquals("Number of transition points", 0, gc.graph.allTransitionPointNodes.size)
+ assertEquals("Number of entry points", 1, gc.graph.allEntryPointNodes.size)
+ assertEquals("Number of exit points", 1, gc.graph.allExitPointNodes.size)
+ assertEquals("Number of initial transitions", 1, gc.graph.allInitialTranisitionLinks.size)
+ assertEquals("Number of triggered transitions", 5, gc.graph.allTriggeredTranisitionLinks.size)
+ assertEquals("Number of continuation transitions", 3, gc.graph.allContinuationTranisitionLinks.size)
+ assertEquals("Number of cpbranch transitions", 1, gc.graph.allCPBranchTranisitionLinks.size)
+ }
+
+ @Test
+ def void testChainsAndTriggers() {
+ assertEquals("transition chains", 6, gc.graph.getAllChainHeads.size)
+ }
+
+ @Test
+ def void testData() {
+ var tr = gc.graph.links.filter[(transition as Transition).name.equals("tr0")].head
+ assertNotNull("transition found", tr)
+ assertTrue("transition is TriggeredTransition", tr.transition instanceof TriggeredTransition)
+ var data = tr.commonData as VarDecl
+ assertTrue("data is DataClass", data.refType.type instanceof DataClass)
+ assertEquals("data is of type", "DC2", data.refType.type.name)
+
+ val s = gc.graph.nodes.filter[stateGraphNode.name.equals("state1")].head
+ assertNotNull("state found", s)
+
+ tr = s.subgraph.links.filter[(transition as Transition).name.equals("tr2")].head
+ assertTrue("transition is TriggeredTransition", tr.transition instanceof TriggeredTransition)
+ data = tr.commonData as VarDecl
+ assertTrue("data is DataClass", data.refType.type instanceof DataClass)
+ assertEquals("data is of type", "DC2", data.refType.type.name)
+
+ tr = s.subgraph.links.filter[(transition as Transition).name.equals("tr3")].head
+ assertTrue("transition is TriggeredTransition", tr.transition instanceof TriggeredTransition)
+ data = tr.commonData as VarDecl
+ assertTrue("data is DataClass", data.refType.type instanceof DataClass)
+ assertEquals("data is of type", "DC4", data.refType.type.name)
+
+ tr = gc.graph.links.filter[(transition as Transition).name.equals("tr1")].head
+ assertNotNull("transition found", tr)
+ assertTrue("transition is TriggeredTransition", tr.transition instanceof TriggeredTransition)
+ data = tr.commonData as VarDecl
+ assertTrue("data is DataClass", data.refType.type instanceof DataClass)
+ assertEquals("data is of type", "DC3", data.refType.type.name)
+
+ tr = gc.graph.links.filter[(transition as Transition).name.equals("tr3")].head
+ assertNotNull("transition found", tr)
+ assertTrue("transition is ContinuationTransition", tr.transition instanceof ContinuationTransition)
+ data = tr.commonData as VarDecl
+ assertTrue("data is DataClass", data.refType.type instanceof DataClass)
+ assertEquals("data is of type", "DC", data.refType.type.name)
+
+ tr = gc.graph.links.filter[(transition as Transition).name.equals("tr4")].head
+ assertNotNull("transition found", tr)
+ assertTrue("transition is CPBranchTransition", tr.transition instanceof CPBranchTransition)
+ data = tr.commonData as VarDecl
+ assertTrue("data is DataClass", data.refType.type instanceof DataClass)
+ assertEquals("data is of type", "DC", data.refType.type.name)
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.xtend b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.xtend
new file mode 100644
index 000000000..08a01feb0
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.xtend
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.core.genmodel.fsm.tests
+
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker
+import org.eclipse.etrice.core.genmodel.fsm.NullLogger
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.naming.RoomNameProvider
+import org.junit.Before
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
+import static org.junit.Assert.assertFalse
+import static org.junit.Assert.assertNotNull
+
+import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.*
+import org.eclipse.etrice.core.fsm.fSM.Transition
+import org.eclipse.etrice.core.fsm.fSM.SimpleState
+
+class TestStatesInheritance extends FsmGenTestBase {
+
+ RoomNameProvider roomNameProvider = new RoomNameProvider
+
+ GraphContainer gc
+
+ @Before
+ def void SetUp() {
+ gc = getGraphContainer("StatesInheritanceExample.room", "TestActor")
+ assertNotNull("graph context was created", gc)
+
+ val logger = new NullLogger
+ FsmGenChecker.check(gc, logger)
+ assertFalse("logger has no errors", logger.hasErrors)
+
+ // enrich our generator model with all we have
+ gc.withTriggersInStates.withChainHeads.withCommonData
+
+ assertFalse("diagnostician has no errors", diagnostician.isFailed)
+ }
+
+ @Test
+ def void testNoTrigger() {
+ val s = gc.graph.allStateNodes.filter[name.equals("State3")].head
+ assertNotNull("state found", s)
+
+ assertEquals("non-leave state has no caught triggers", 0, s.caughtTriggers.size)
+ }
+
+ @Test
+ def void testObjectNumbers() {
+ assertEquals("Number of states", 11, gc.graph.allStateNodes.size)
+ assertEquals("Number of states", 9, gc.graph.allStateNodes.filter[stateGraphNode instanceof SimpleState].size)
+ assertEquals("Number of choice points", 1, gc.graph.allChoicePointNodes.size)
+ assertEquals("Number of transition points", 5, gc.graph.allTransitionPointNodes.size)
+ assertEquals("Number of entry points", 2, gc.graph.allEntryPointNodes.size)
+ assertEquals("Number of exit points", 1, gc.graph.allExitPointNodes.size)
+ assertEquals("Number of initial transitions", 3, gc.graph.allInitialTranisitionLinks.size)
+ assertEquals("Number of triggered transitions", 17, gc.graph.allTriggeredTranisitionLinks.size)
+ assertEquals("Number of continuation transitions", 4, gc.graph.allContinuationTranisitionLinks.size)
+ assertEquals("Number of cpbranch transitions", 3, gc.graph.allCPBranchTranisitionLinks.size)
+ }
+
+ @Test
+ def void testChainsAndTriggers() {
+ assertEquals("transition chains", 20, gc.graph.getAllChainHeads.size)
+ }
+
+ @Test
+ def void testGraph() {
+ var s = gc.graph.allStateNodes.filter[roomNameProvider.getFullPath(stateGraphNode).equals("State3_State3")].head
+ assertNotNull("state exists", s)
+ assertEquals("number of incoming transitions", 3, s.incoming.size)
+ assertEquals("number of outgoing transitions", 2, s.outgoing.size)
+ assertEquals("active triggers", 6, s.caughtTriggers.size)
+
+ s = gc.graph.allStateNodes.filter[roomNameProvider.getFullPath(stateGraphNode).equals("State2")].head
+ assertNotNull("state exists", s)
+ assertEquals("number of incoming transitions", 4, s.incoming.size)
+ assertEquals("number of outgoing transitions", 1, s.outgoing.size)
+ assertEquals("active triggers", 3, s.caughtTriggers.size)
+
+ val cp = gc.graph.allChoicePointNodes.filter[stateGraphNode.name.equals("CP1")].head
+ assertNotNull("cp exists", cp)
+ assertEquals("number of incoming transitions", 1, cp.incoming.size)
+ assertEquals("number of outgoing transitions", 4, cp.outgoing.size)
+
+ val cts = cp.outgoing.filter[transition instanceof ContinuationTransition]
+ assertEquals("Exactly one continuation (=default) transition", 1, cts.size)
+ }
+
+ @Test
+ def void testChains() {
+ var tr = gc.graph.allLinks.filter[roomNameProvider.getFullPath((transition as Transition)).equals("State3_TRANS_tr1_FROM_tp1_TO_State3")].head
+ assertNotNull("transition", tr)
+
+ assertEquals("one chain head", 1, tr.chainHeads.size)
+ assertEquals("chain name", "TRANS_tr5_FROM_tp0_TO_State3_tp1_BY_afct", roomNameProvider.getFullPath(tr.chainHeads.head.transition as Transition))
+
+ tr = gc.graph.allLinks.filter[roomNameProvider.getFullPath((transition as Transition)).equals("State3_TRANS_tr8_FROM_tp6_TO_State2")].head
+ assertNotNull("transition", tr)
+
+ assertEquals("one chain head", 1, tr.chainHeads.size)
+ assertEquals("chain name", "TRANS_tr12_FROM_State5_TO_State3_tp6_BY_aport", roomNameProvider.getFullPath(tr.chainHeads.head.transition as Transition))
+
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.xtend b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.xtend
index ba194f764..7a1c204be 100644
--- a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.xtend
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/src/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.xtend
@@ -12,10 +12,11 @@
package org.eclipse.etrice.core.genmodel.fsm.tests
-import org.eclipse.etrice.core.genmodel.fsm.ExtendedFsmGenBuilder
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition
import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker
import org.eclipse.etrice.core.genmodel.fsm.NullLogger
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.naming.RoomNameProvider
import org.junit.Before
import org.junit.Test
@@ -24,9 +25,12 @@ import static org.junit.Assert.assertFalse
import static org.junit.Assert.assertNotNull
import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.*
+import org.eclipse.etrice.core.fsm.fSM.Transition
class TestStatesTriggers extends FsmGenTestBase {
+ RoomNameProvider roomNameProvider = new RoomNameProvider
+
GraphContainer gc
@Before
@@ -52,5 +56,53 @@ class TestStatesTriggers extends FsmGenTestBase {
assertEquals("non-leave state has no caught triggers", 0, s.caughtTriggers.size)
}
- // TODO: implement test similar to org.eclipse.etrice.core.genmodel.TestStatesAndTriggers
+ @Test
+ def void testObjectNumbers() {
+ assertEquals("Number of states", 7, gc.graph.allStateNodes.size)
+ assertEquals("Number of choice points", 1, gc.graph.allChoicePointNodes.size)
+ assertEquals("Number of transition points", 4, gc.graph.allTransitionPointNodes.size)
+ assertEquals("Number of entry points", 1, gc.graph.allEntryPointNodes.size)
+ assertEquals("Number of exit points", 1, gc.graph.allExitPointNodes.size)
+ assertEquals("Number of initial transitions", 2, gc.graph.allInitialTranisitionLinks.size)
+ assertEquals("Number of triggered transitions", 11, gc.graph.allTriggeredTranisitionLinks.size)
+ assertEquals("Number of continuation transitions", 3, gc.graph.allContinuationTranisitionLinks.size)
+ assertEquals("Number of cpbranch transitions", 2, gc.graph.allCPBranchTranisitionLinks.size)
+ }
+
+ @Test
+ def void testChainsAndTriggers() {
+ assertEquals("transition chains", 13, gc.graph.getAllChainHeads.size)
+ }
+
+ @Test
+ def void testGraph() {
+ var s = gc.graph.nodes.filter[name.equals("State3")].head
+ s = s.subgraph.nodes.filter[name.equals("State3")].head
+ assertNotNull("state found", s)
+ assertEquals("number of incoming transitions", 3, s.incoming.size);
+ assertEquals("number of outgoing transitions", 2, s.outgoing.size);
+ assertEquals("active triggers", 6, s.caughtTriggers.size);
+
+ s = gc.graph.nodes.filter[name.equals("State2")].head
+ assertNotNull("state found", s)
+ assertEquals("number of incoming transitions", 4, s.incoming.size);
+ assertEquals("number of outgoing transitions", 1, s.outgoing.size);
+ assertEquals("active triggers", 3, s.caughtTriggers.size);
+
+ val cp = gc.graph.nodes.filter[name.equals("CP1")].head
+ assertNotNull("cp found", cp)
+ assertEquals("number of incoming transitions", 1, cp.incoming.size);
+ assertEquals("number of outgoing transitions", 3, cp.outgoing.size);
+
+ val cts = cp.outgoing.filter[transition instanceof ContinuationTransition]
+ assertEquals("Exactly one continuation (=default) transition", 1, cts.size)
+ }
+
+ @Test
+ def void testChains() {
+ val tr = gc.graph.allLinks.filter[roomNameProvider.getFullPath((transition as Transition)).equals("State3_TRANS_tr1_FROM_tp1_TO_State3")].head
+ assertNotNull("transition found", tr)
+ assertEquals("one chain head", 1, tr.chainHeads.size)
+ assertEquals("correct chain head", "TRANS_tr5_FROM_tp0_TO_State3_tp1_BY_afct", roomNameProvider.getFullPath((tr.chainHeads.head.transition as Transition)))
+ }
} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.java b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.java
new file mode 100644
index 000000000..3c6aa8681
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestMultipleConnectedChoicepoint.java
@@ -0,0 +1,272 @@
+/**
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.core.genmodel.fsm.tests;
+
+import java.util.Iterator;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.fsm.fSM.CPBranchTransition;
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.core.fsm.fSM.TransitionBase;
+import org.eclipse.etrice.core.fsm.fSM.TriggeredTransition;
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker;
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions;
+import org.eclipse.etrice.core.genmodel.fsm.NullLogger;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
+import org.eclipse.etrice.core.genmodel.fsm.tests.FsmGenTestBase;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.IteratorExtensions;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("all")
+public class TestMultipleConnectedChoicepoint extends FsmGenTestBase {
+ private GraphContainer gc;
+
+ @Before
+ public void SetUp() {
+ GraphContainer _graphContainer = this.getGraphContainer("MultipleConnectedChoicepointExample.room", "TestActor");
+ this.gc = _graphContainer;
+ Assert.assertNotNull("graph context was created", this.gc);
+ final NullLogger logger = new NullLogger();
+ FsmGenChecker.check(this.gc, logger);
+ boolean _hasErrors = logger.hasErrors();
+ Assert.assertFalse("logger has no errors", _hasErrors);
+ GraphContainer _withTriggersInStates = this.builder.withTriggersInStates(this.gc);
+ GraphContainer _withChainHeads = this.builder.withChainHeads(_withTriggersInStates);
+ this.builder.withCommonData(_withChainHeads);
+ boolean _isFailed = this.diagnostician.isFailed();
+ Assert.assertFalse("diagnostician has no errors", _isFailed);
+ }
+
+ @Test
+ public void testObjectNumbers() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Node> _allStateNodes = FsmGenExtensions.getAllStateNodes(_graph);
+ int _size = IteratorExtensions.size(_allStateNodes);
+ Assert.assertEquals("Number of states", 6, _size);
+ Graph _graph_1 = this.gc.getGraph();
+ Iterator<Node> _allChoicePointNodes = FsmGenExtensions.getAllChoicePointNodes(_graph_1);
+ int _size_1 = IteratorExtensions.size(_allChoicePointNodes);
+ Assert.assertEquals("Number of choice points", 1, _size_1);
+ Graph _graph_2 = this.gc.getGraph();
+ Iterator<Node> _allTransitionPointNodes = FsmGenExtensions.getAllTransitionPointNodes(_graph_2);
+ int _size_2 = IteratorExtensions.size(_allTransitionPointNodes);
+ Assert.assertEquals("Number of transition points", 0, _size_2);
+ Graph _graph_3 = this.gc.getGraph();
+ Iterator<Node> _allEntryPointNodes = FsmGenExtensions.getAllEntryPointNodes(_graph_3);
+ int _size_3 = IteratorExtensions.size(_allEntryPointNodes);
+ Assert.assertEquals("Number of entry points", 1, _size_3);
+ Graph _graph_4 = this.gc.getGraph();
+ Iterator<Node> _allExitPointNodes = FsmGenExtensions.getAllExitPointNodes(_graph_4);
+ int _size_4 = IteratorExtensions.size(_allExitPointNodes);
+ Assert.assertEquals("Number of exit points", 1, _size_4);
+ Graph _graph_5 = this.gc.getGraph();
+ Iterator<Link> _allInitialTranisitionLinks = FsmGenExtensions.getAllInitialTranisitionLinks(_graph_5);
+ int _size_5 = IteratorExtensions.size(_allInitialTranisitionLinks);
+ Assert.assertEquals("Number of initial transitions", 1, _size_5);
+ Graph _graph_6 = this.gc.getGraph();
+ Iterator<Link> _allTriggeredTranisitionLinks = FsmGenExtensions.getAllTriggeredTranisitionLinks(_graph_6);
+ int _size_6 = IteratorExtensions.size(_allTriggeredTranisitionLinks);
+ Assert.assertEquals("Number of triggered transitions", 5, _size_6);
+ Graph _graph_7 = this.gc.getGraph();
+ Iterator<Link> _allContinuationTranisitionLinks = FsmGenExtensions.getAllContinuationTranisitionLinks(_graph_7);
+ int _size_7 = IteratorExtensions.size(_allContinuationTranisitionLinks);
+ Assert.assertEquals("Number of continuation transitions", 3, _size_7);
+ Graph _graph_8 = this.gc.getGraph();
+ Iterator<Link> _allCPBranchTranisitionLinks = FsmGenExtensions.getAllCPBranchTranisitionLinks(_graph_8);
+ int _size_8 = IteratorExtensions.size(_allCPBranchTranisitionLinks);
+ Assert.assertEquals("Number of cpbranch transitions", 1, _size_8);
+ }
+
+ @Test
+ public void testChainsAndTriggers() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Link> _allChainHeads = FsmGenExtensions.getAllChainHeads(_graph);
+ int _size = IteratorExtensions.size(_allChainHeads);
+ Assert.assertEquals("transition chains", 6, _size);
+ }
+
+ @Test
+ public void testData() {
+ Graph _graph = this.gc.getGraph();
+ EList<Link> _links = _graph.getLinks();
+ final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _name = ((Transition) _transition).getName();
+ return Boolean.valueOf(_name.equals("tr0"));
+ }
+ };
+ Iterable<Link> _filter = IterableExtensions.<Link>filter(_links, _function);
+ Link tr = IterableExtensions.<Link>head(_filter);
+ Assert.assertNotNull("transition found", tr);
+ TransitionBase _transition = tr.getTransition();
+ Assert.assertTrue("transition is TriggeredTransition", (_transition instanceof TriggeredTransition));
+ EObject _commonData = tr.getCommonData();
+ VarDecl data = ((VarDecl) _commonData);
+ RefableType _refType = data.getRefType();
+ DataType _type = _refType.getType();
+ Assert.assertTrue("data is DataClass", (_type instanceof DataClass));
+ RefableType _refType_1 = data.getRefType();
+ DataType _type_1 = _refType_1.getType();
+ String _name = _type_1.getName();
+ Assert.assertEquals("data is of type", "DC2", _name);
+ Graph _graph_1 = this.gc.getGraph();
+ EList<Node> _nodes = _graph_1.getNodes();
+ final Function1<Node, Boolean> _function_1 = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ String _name = _stateGraphNode.getName();
+ return Boolean.valueOf(_name.equals("state1"));
+ }
+ };
+ Iterable<Node> _filter_1 = IterableExtensions.<Node>filter(_nodes, _function_1);
+ final Node s = IterableExtensions.<Node>head(_filter_1);
+ Assert.assertNotNull("state found", s);
+ Graph _subgraph = s.getSubgraph();
+ EList<Link> _links_1 = _subgraph.getLinks();
+ final Function1<Link, Boolean> _function_2 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _name = ((Transition) _transition).getName();
+ return Boolean.valueOf(_name.equals("tr2"));
+ }
+ };
+ Iterable<Link> _filter_2 = IterableExtensions.<Link>filter(_links_1, _function_2);
+ Link _head = IterableExtensions.<Link>head(_filter_2);
+ tr = _head;
+ TransitionBase _transition_1 = tr.getTransition();
+ Assert.assertTrue("transition is TriggeredTransition", (_transition_1 instanceof TriggeredTransition));
+ EObject _commonData_1 = tr.getCommonData();
+ data = ((VarDecl) _commonData_1);
+ RefableType _refType_2 = data.getRefType();
+ DataType _type_2 = _refType_2.getType();
+ Assert.assertTrue("data is DataClass", (_type_2 instanceof DataClass));
+ RefableType _refType_3 = data.getRefType();
+ DataType _type_3 = _refType_3.getType();
+ String _name_1 = _type_3.getName();
+ Assert.assertEquals("data is of type", "DC2", _name_1);
+ Graph _subgraph_1 = s.getSubgraph();
+ EList<Link> _links_2 = _subgraph_1.getLinks();
+ final Function1<Link, Boolean> _function_3 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _name = ((Transition) _transition).getName();
+ return Boolean.valueOf(_name.equals("tr3"));
+ }
+ };
+ Iterable<Link> _filter_3 = IterableExtensions.<Link>filter(_links_2, _function_3);
+ Link _head_1 = IterableExtensions.<Link>head(_filter_3);
+ tr = _head_1;
+ TransitionBase _transition_2 = tr.getTransition();
+ Assert.assertTrue("transition is TriggeredTransition", (_transition_2 instanceof TriggeredTransition));
+ EObject _commonData_2 = tr.getCommonData();
+ data = ((VarDecl) _commonData_2);
+ RefableType _refType_4 = data.getRefType();
+ DataType _type_4 = _refType_4.getType();
+ Assert.assertTrue("data is DataClass", (_type_4 instanceof DataClass));
+ RefableType _refType_5 = data.getRefType();
+ DataType _type_5 = _refType_5.getType();
+ String _name_2 = _type_5.getName();
+ Assert.assertEquals("data is of type", "DC4", _name_2);
+ Graph _graph_2 = this.gc.getGraph();
+ EList<Link> _links_3 = _graph_2.getLinks();
+ final Function1<Link, Boolean> _function_4 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _name = ((Transition) _transition).getName();
+ return Boolean.valueOf(_name.equals("tr1"));
+ }
+ };
+ Iterable<Link> _filter_4 = IterableExtensions.<Link>filter(_links_3, _function_4);
+ Link _head_2 = IterableExtensions.<Link>head(_filter_4);
+ tr = _head_2;
+ Assert.assertNotNull("transition found", tr);
+ TransitionBase _transition_3 = tr.getTransition();
+ Assert.assertTrue("transition is TriggeredTransition", (_transition_3 instanceof TriggeredTransition));
+ EObject _commonData_3 = tr.getCommonData();
+ data = ((VarDecl) _commonData_3);
+ RefableType _refType_6 = data.getRefType();
+ DataType _type_6 = _refType_6.getType();
+ Assert.assertTrue("data is DataClass", (_type_6 instanceof DataClass));
+ RefableType _refType_7 = data.getRefType();
+ DataType _type_7 = _refType_7.getType();
+ String _name_3 = _type_7.getName();
+ Assert.assertEquals("data is of type", "DC3", _name_3);
+ Graph _graph_3 = this.gc.getGraph();
+ EList<Link> _links_4 = _graph_3.getLinks();
+ final Function1<Link, Boolean> _function_5 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _name = ((Transition) _transition).getName();
+ return Boolean.valueOf(_name.equals("tr3"));
+ }
+ };
+ Iterable<Link> _filter_5 = IterableExtensions.<Link>filter(_links_4, _function_5);
+ Link _head_3 = IterableExtensions.<Link>head(_filter_5);
+ tr = _head_3;
+ Assert.assertNotNull("transition found", tr);
+ TransitionBase _transition_4 = tr.getTransition();
+ Assert.assertTrue("transition is ContinuationTransition", (_transition_4 instanceof ContinuationTransition));
+ EObject _commonData_4 = tr.getCommonData();
+ data = ((VarDecl) _commonData_4);
+ RefableType _refType_8 = data.getRefType();
+ DataType _type_8 = _refType_8.getType();
+ Assert.assertTrue("data is DataClass", (_type_8 instanceof DataClass));
+ RefableType _refType_9 = data.getRefType();
+ DataType _type_9 = _refType_9.getType();
+ String _name_4 = _type_9.getName();
+ Assert.assertEquals("data is of type", "DC", _name_4);
+ Graph _graph_4 = this.gc.getGraph();
+ EList<Link> _links_5 = _graph_4.getLinks();
+ final Function1<Link, Boolean> _function_6 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _name = ((Transition) _transition).getName();
+ return Boolean.valueOf(_name.equals("tr4"));
+ }
+ };
+ Iterable<Link> _filter_6 = IterableExtensions.<Link>filter(_links_5, _function_6);
+ Link _head_4 = IterableExtensions.<Link>head(_filter_6);
+ tr = _head_4;
+ Assert.assertNotNull("transition found", tr);
+ TransitionBase _transition_5 = tr.getTransition();
+ Assert.assertTrue("transition is CPBranchTransition", (_transition_5 instanceof CPBranchTransition));
+ EObject _commonData_5 = tr.getCommonData();
+ data = ((VarDecl) _commonData_5);
+ RefableType _refType_10 = data.getRefType();
+ DataType _type_10 = _refType_10.getType();
+ Assert.assertTrue("data is DataClass", (_type_10 instanceof DataClass));
+ RefableType _refType_11 = data.getRefType();
+ DataType _type_11 = _refType_11.getType();
+ String _name_5 = _type_11.getName();
+ Assert.assertEquals("data is of type", "DC", _name_5);
+ }
+}
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.java b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.java
new file mode 100644
index 000000000..e4b77f533
--- /dev/null
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesInheritance.java
@@ -0,0 +1,263 @@
+/**
+ * Copyright (c) 2017 protos software gmbh (http://www.protos.de).
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ */
+package org.eclipse.etrice.core.genmodel.fsm.tests;
+
+import java.util.Iterator;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition;
+import org.eclipse.etrice.core.fsm.fSM.SimpleState;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.core.fsm.fSM.TransitionBase;
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker;
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions;
+import org.eclipse.etrice.core.genmodel.fsm.NullLogger;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.CommonTrigger;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
+import org.eclipse.etrice.core.genmodel.fsm.tests.FsmGenTestBase;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.IteratorExtensions;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+@SuppressWarnings("all")
+public class TestStatesInheritance extends FsmGenTestBase {
+ private RoomNameProvider roomNameProvider = new RoomNameProvider();
+
+ private GraphContainer gc;
+
+ @Before
+ public void SetUp() {
+ GraphContainer _graphContainer = this.getGraphContainer("StatesInheritanceExample.room", "TestActor");
+ this.gc = _graphContainer;
+ Assert.assertNotNull("graph context was created", this.gc);
+ final NullLogger logger = new NullLogger();
+ FsmGenChecker.check(this.gc, logger);
+ boolean _hasErrors = logger.hasErrors();
+ Assert.assertFalse("logger has no errors", _hasErrors);
+ GraphContainer _withTriggersInStates = this.builder.withTriggersInStates(this.gc);
+ GraphContainer _withChainHeads = this.builder.withChainHeads(_withTriggersInStates);
+ this.builder.withCommonData(_withChainHeads);
+ boolean _isFailed = this.diagnostician.isFailed();
+ Assert.assertFalse("diagnostician has no errors", _isFailed);
+ }
+
+ @Test
+ public void testNoTrigger() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Node> _allStateNodes = FsmGenExtensions.getAllStateNodes(_graph);
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ String _name = FsmGenExtensions.getName(it);
+ return Boolean.valueOf(_name.equals("State3"));
+ }
+ };
+ Iterator<Node> _filter = IteratorExtensions.<Node>filter(_allStateNodes, _function);
+ final Node s = IteratorExtensions.<Node>head(_filter);
+ Assert.assertNotNull("state found", s);
+ EList<CommonTrigger> _caughtTriggers = s.getCaughtTriggers();
+ int _size = _caughtTriggers.size();
+ Assert.assertEquals("non-leave state has no caught triggers", 0, _size);
+ }
+
+ @Test
+ public void testObjectNumbers() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Node> _allStateNodes = FsmGenExtensions.getAllStateNodes(_graph);
+ int _size = IteratorExtensions.size(_allStateNodes);
+ Assert.assertEquals("Number of states", 11, _size);
+ Graph _graph_1 = this.gc.getGraph();
+ Iterator<Node> _allStateNodes_1 = FsmGenExtensions.getAllStateNodes(_graph_1);
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ return Boolean.valueOf((_stateGraphNode instanceof SimpleState));
+ }
+ };
+ Iterator<Node> _filter = IteratorExtensions.<Node>filter(_allStateNodes_1, _function);
+ int _size_1 = IteratorExtensions.size(_filter);
+ Assert.assertEquals("Number of states", 9, _size_1);
+ Graph _graph_2 = this.gc.getGraph();
+ Iterator<Node> _allChoicePointNodes = FsmGenExtensions.getAllChoicePointNodes(_graph_2);
+ int _size_2 = IteratorExtensions.size(_allChoicePointNodes);
+ Assert.assertEquals("Number of choice points", 1, _size_2);
+ Graph _graph_3 = this.gc.getGraph();
+ Iterator<Node> _allTransitionPointNodes = FsmGenExtensions.getAllTransitionPointNodes(_graph_3);
+ int _size_3 = IteratorExtensions.size(_allTransitionPointNodes);
+ Assert.assertEquals("Number of transition points", 5, _size_3);
+ Graph _graph_4 = this.gc.getGraph();
+ Iterator<Node> _allEntryPointNodes = FsmGenExtensions.getAllEntryPointNodes(_graph_4);
+ int _size_4 = IteratorExtensions.size(_allEntryPointNodes);
+ Assert.assertEquals("Number of entry points", 2, _size_4);
+ Graph _graph_5 = this.gc.getGraph();
+ Iterator<Node> _allExitPointNodes = FsmGenExtensions.getAllExitPointNodes(_graph_5);
+ int _size_5 = IteratorExtensions.size(_allExitPointNodes);
+ Assert.assertEquals("Number of exit points", 1, _size_5);
+ Graph _graph_6 = this.gc.getGraph();
+ Iterator<Link> _allInitialTranisitionLinks = FsmGenExtensions.getAllInitialTranisitionLinks(_graph_6);
+ int _size_6 = IteratorExtensions.size(_allInitialTranisitionLinks);
+ Assert.assertEquals("Number of initial transitions", 3, _size_6);
+ Graph _graph_7 = this.gc.getGraph();
+ Iterator<Link> _allTriggeredTranisitionLinks = FsmGenExtensions.getAllTriggeredTranisitionLinks(_graph_7);
+ int _size_7 = IteratorExtensions.size(_allTriggeredTranisitionLinks);
+ Assert.assertEquals("Number of triggered transitions", 17, _size_7);
+ Graph _graph_8 = this.gc.getGraph();
+ Iterator<Link> _allContinuationTranisitionLinks = FsmGenExtensions.getAllContinuationTranisitionLinks(_graph_8);
+ int _size_8 = IteratorExtensions.size(_allContinuationTranisitionLinks);
+ Assert.assertEquals("Number of continuation transitions", 4, _size_8);
+ Graph _graph_9 = this.gc.getGraph();
+ Iterator<Link> _allCPBranchTranisitionLinks = FsmGenExtensions.getAllCPBranchTranisitionLinks(_graph_9);
+ int _size_9 = IteratorExtensions.size(_allCPBranchTranisitionLinks);
+ Assert.assertEquals("Number of cpbranch transitions", 3, _size_9);
+ }
+
+ @Test
+ public void testChainsAndTriggers() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Link> _allChainHeads = FsmGenExtensions.getAllChainHeads(_graph);
+ int _size = IteratorExtensions.size(_allChainHeads);
+ Assert.assertEquals("transition chains", 20, _size);
+ }
+
+ @Test
+ public void testGraph() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Node> _allStateNodes = FsmGenExtensions.getAllStateNodes(_graph);
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ String _fullPath = TestStatesInheritance.this.roomNameProvider.getFullPath(_stateGraphNode);
+ return Boolean.valueOf(_fullPath.equals("State3_State3"));
+ }
+ };
+ Iterator<Node> _filter = IteratorExtensions.<Node>filter(_allStateNodes, _function);
+ Node s = IteratorExtensions.<Node>head(_filter);
+ Assert.assertNotNull("state exists", s);
+ EList<Link> _incoming = s.getIncoming();
+ int _size = _incoming.size();
+ Assert.assertEquals("number of incoming transitions", 3, _size);
+ EList<Link> _outgoing = s.getOutgoing();
+ int _size_1 = _outgoing.size();
+ Assert.assertEquals("number of outgoing transitions", 2, _size_1);
+ EList<CommonTrigger> _caughtTriggers = s.getCaughtTriggers();
+ int _size_2 = _caughtTriggers.size();
+ Assert.assertEquals("active triggers", 6, _size_2);
+ Graph _graph_1 = this.gc.getGraph();
+ Iterator<Node> _allStateNodes_1 = FsmGenExtensions.getAllStateNodes(_graph_1);
+ final Function1<Node, Boolean> _function_1 = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ String _fullPath = TestStatesInheritance.this.roomNameProvider.getFullPath(_stateGraphNode);
+ return Boolean.valueOf(_fullPath.equals("State2"));
+ }
+ };
+ Iterator<Node> _filter_1 = IteratorExtensions.<Node>filter(_allStateNodes_1, _function_1);
+ Node _head = IteratorExtensions.<Node>head(_filter_1);
+ s = _head;
+ Assert.assertNotNull("state exists", s);
+ EList<Link> _incoming_1 = s.getIncoming();
+ int _size_3 = _incoming_1.size();
+ Assert.assertEquals("number of incoming transitions", 4, _size_3);
+ EList<Link> _outgoing_1 = s.getOutgoing();
+ int _size_4 = _outgoing_1.size();
+ Assert.assertEquals("number of outgoing transitions", 1, _size_4);
+ EList<CommonTrigger> _caughtTriggers_1 = s.getCaughtTriggers();
+ int _size_5 = _caughtTriggers_1.size();
+ Assert.assertEquals("active triggers", 3, _size_5);
+ Graph _graph_2 = this.gc.getGraph();
+ Iterator<Node> _allChoicePointNodes = FsmGenExtensions.getAllChoicePointNodes(_graph_2);
+ final Function1<Node, Boolean> _function_2 = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ StateGraphNode _stateGraphNode = it.getStateGraphNode();
+ String _name = _stateGraphNode.getName();
+ return Boolean.valueOf(_name.equals("CP1"));
+ }
+ };
+ Iterator<Node> _filter_2 = IteratorExtensions.<Node>filter(_allChoicePointNodes, _function_2);
+ final Node cp = IteratorExtensions.<Node>head(_filter_2);
+ Assert.assertNotNull("cp exists", cp);
+ EList<Link> _incoming_2 = cp.getIncoming();
+ int _size_6 = _incoming_2.size();
+ Assert.assertEquals("number of incoming transitions", 1, _size_6);
+ EList<Link> _outgoing_2 = cp.getOutgoing();
+ int _size_7 = _outgoing_2.size();
+ Assert.assertEquals("number of outgoing transitions", 4, _size_7);
+ EList<Link> _outgoing_3 = cp.getOutgoing();
+ final Function1<Link, Boolean> _function_3 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ return Boolean.valueOf((_transition instanceof ContinuationTransition));
+ }
+ };
+ final Iterable<Link> cts = IterableExtensions.<Link>filter(_outgoing_3, _function_3);
+ int _size_8 = IterableExtensions.size(cts);
+ Assert.assertEquals("Exactly one continuation (=default) transition", 1, _size_8);
+ }
+
+ @Test
+ public void testChains() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(_graph);
+ final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _fullPath = TestStatesInheritance.this.roomNameProvider.getFullPath(((Transition) _transition));
+ return Boolean.valueOf(_fullPath.equals("State3_TRANS_tr1_FROM_tp1_TO_State3"));
+ }
+ };
+ Iterator<Link> _filter = IteratorExtensions.<Link>filter(_allLinks, _function);
+ Link tr = IteratorExtensions.<Link>head(_filter);
+ Assert.assertNotNull("transition", tr);
+ EList<Link> _chainHeads = tr.getChainHeads();
+ int _size = _chainHeads.size();
+ Assert.assertEquals("one chain head", 1, _size);
+ EList<Link> _chainHeads_1 = tr.getChainHeads();
+ Link _head = IterableExtensions.<Link>head(_chainHeads_1);
+ TransitionBase _transition = _head.getTransition();
+ String _fullPath = this.roomNameProvider.getFullPath(((Transition) _transition));
+ Assert.assertEquals("chain name", "TRANS_tr5_FROM_tp0_TO_State3_tp1_BY_afct", _fullPath);
+ Graph _graph_1 = this.gc.getGraph();
+ Iterator<Link> _allLinks_1 = FsmGenExtensions.getAllLinks(_graph_1);
+ final Function1<Link, Boolean> _function_1 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _fullPath = TestStatesInheritance.this.roomNameProvider.getFullPath(((Transition) _transition));
+ return Boolean.valueOf(_fullPath.equals("State3_TRANS_tr8_FROM_tp6_TO_State2"));
+ }
+ };
+ Iterator<Link> _filter_1 = IteratorExtensions.<Link>filter(_allLinks_1, _function_1);
+ Link _head_1 = IteratorExtensions.<Link>head(_filter_1);
+ tr = _head_1;
+ Assert.assertNotNull("transition", tr);
+ EList<Link> _chainHeads_2 = tr.getChainHeads();
+ int _size_1 = _chainHeads_2.size();
+ Assert.assertEquals("one chain head", 1, _size_1);
+ EList<Link> _chainHeads_3 = tr.getChainHeads();
+ Link _head_2 = IterableExtensions.<Link>head(_chainHeads_3);
+ TransitionBase _transition_1 = _head_2.getTransition();
+ String _fullPath_1 = this.roomNameProvider.getFullPath(((Transition) _transition_1));
+ Assert.assertEquals("chain name", "TRANS_tr12_FROM_State5_TO_State3_tp6_BY_aport", _fullPath_1);
+ }
+}
diff --git a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.java b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.java
index 9d30d7f2a..0b465b7dc 100644
--- a/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.java
+++ b/tests/org.eclipse.etrice.core.genmodel.fsm.tests/xtend-gen/org/eclipse/etrice/core/genmodel/fsm/tests/TestStatesTriggers.java
@@ -12,15 +12,21 @@ package org.eclipse.etrice.core.genmodel.fsm.tests;
import java.util.Iterator;
import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.fsm.fSM.ContinuationTransition;
+import org.eclipse.etrice.core.fsm.fSM.Transition;
+import org.eclipse.etrice.core.fsm.fSM.TransitionBase;
import org.eclipse.etrice.core.genmodel.fsm.FsmGenChecker;
import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions;
import org.eclipse.etrice.core.genmodel.fsm.NullLogger;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.CommonTrigger;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Graph;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Link;
import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
import org.eclipse.etrice.core.genmodel.fsm.tests.FsmGenTestBase;
+import org.eclipse.etrice.core.naming.RoomNameProvider;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.junit.Assert;
import org.junit.Before;
@@ -28,6 +34,8 @@ import org.junit.Test;
@SuppressWarnings("all")
public class TestStatesTriggers extends FsmGenTestBase {
+ private RoomNameProvider roomNameProvider = new RoomNameProvider();
+
private GraphContainer gc;
@Before
@@ -64,4 +72,165 @@ public class TestStatesTriggers extends FsmGenTestBase {
int _size = _caughtTriggers.size();
Assert.assertEquals("non-leave state has no caught triggers", 0, _size);
}
+
+ @Test
+ public void testObjectNumbers() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Node> _allStateNodes = FsmGenExtensions.getAllStateNodes(_graph);
+ int _size = IteratorExtensions.size(_allStateNodes);
+ Assert.assertEquals("Number of states", 7, _size);
+ Graph _graph_1 = this.gc.getGraph();
+ Iterator<Node> _allChoicePointNodes = FsmGenExtensions.getAllChoicePointNodes(_graph_1);
+ int _size_1 = IteratorExtensions.size(_allChoicePointNodes);
+ Assert.assertEquals("Number of choice points", 1, _size_1);
+ Graph _graph_2 = this.gc.getGraph();
+ Iterator<Node> _allTransitionPointNodes = FsmGenExtensions.getAllTransitionPointNodes(_graph_2);
+ int _size_2 = IteratorExtensions.size(_allTransitionPointNodes);
+ Assert.assertEquals("Number of transition points", 4, _size_2);
+ Graph _graph_3 = this.gc.getGraph();
+ Iterator<Node> _allEntryPointNodes = FsmGenExtensions.getAllEntryPointNodes(_graph_3);
+ int _size_3 = IteratorExtensions.size(_allEntryPointNodes);
+ Assert.assertEquals("Number of entry points", 1, _size_3);
+ Graph _graph_4 = this.gc.getGraph();
+ Iterator<Node> _allExitPointNodes = FsmGenExtensions.getAllExitPointNodes(_graph_4);
+ int _size_4 = IteratorExtensions.size(_allExitPointNodes);
+ Assert.assertEquals("Number of exit points", 1, _size_4);
+ Graph _graph_5 = this.gc.getGraph();
+ Iterator<Link> _allInitialTranisitionLinks = FsmGenExtensions.getAllInitialTranisitionLinks(_graph_5);
+ int _size_5 = IteratorExtensions.size(_allInitialTranisitionLinks);
+ Assert.assertEquals("Number of initial transitions", 2, _size_5);
+ Graph _graph_6 = this.gc.getGraph();
+ Iterator<Link> _allTriggeredTranisitionLinks = FsmGenExtensions.getAllTriggeredTranisitionLinks(_graph_6);
+ int _size_6 = IteratorExtensions.size(_allTriggeredTranisitionLinks);
+ Assert.assertEquals("Number of triggered transitions", 11, _size_6);
+ Graph _graph_7 = this.gc.getGraph();
+ Iterator<Link> _allContinuationTranisitionLinks = FsmGenExtensions.getAllContinuationTranisitionLinks(_graph_7);
+ int _size_7 = IteratorExtensions.size(_allContinuationTranisitionLinks);
+ Assert.assertEquals("Number of continuation transitions", 3, _size_7);
+ Graph _graph_8 = this.gc.getGraph();
+ Iterator<Link> _allCPBranchTranisitionLinks = FsmGenExtensions.getAllCPBranchTranisitionLinks(_graph_8);
+ int _size_8 = IteratorExtensions.size(_allCPBranchTranisitionLinks);
+ Assert.assertEquals("Number of cpbranch transitions", 2, _size_8);
+ }
+
+ @Test
+ public void testChainsAndTriggers() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Link> _allChainHeads = FsmGenExtensions.getAllChainHeads(_graph);
+ int _size = IteratorExtensions.size(_allChainHeads);
+ Assert.assertEquals("transition chains", 13, _size);
+ }
+
+ @Test
+ public void testGraph() {
+ Graph _graph = this.gc.getGraph();
+ EList<Node> _nodes = _graph.getNodes();
+ final Function1<Node, Boolean> _function = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ String _name = FsmGenExtensions.getName(it);
+ return Boolean.valueOf(_name.equals("State3"));
+ }
+ };
+ Iterable<Node> _filter = IterableExtensions.<Node>filter(_nodes, _function);
+ Node s = IterableExtensions.<Node>head(_filter);
+ Graph _subgraph = s.getSubgraph();
+ EList<Node> _nodes_1 = _subgraph.getNodes();
+ final Function1<Node, Boolean> _function_1 = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ String _name = FsmGenExtensions.getName(it);
+ return Boolean.valueOf(_name.equals("State3"));
+ }
+ };
+ Iterable<Node> _filter_1 = IterableExtensions.<Node>filter(_nodes_1, _function_1);
+ Node _head = IterableExtensions.<Node>head(_filter_1);
+ s = _head;
+ Assert.assertNotNull("state found", s);
+ EList<Link> _incoming = s.getIncoming();
+ int _size = _incoming.size();
+ Assert.assertEquals("number of incoming transitions", 3, _size);
+ EList<Link> _outgoing = s.getOutgoing();
+ int _size_1 = _outgoing.size();
+ Assert.assertEquals("number of outgoing transitions", 2, _size_1);
+ EList<CommonTrigger> _caughtTriggers = s.getCaughtTriggers();
+ int _size_2 = _caughtTriggers.size();
+ Assert.assertEquals("active triggers", 6, _size_2);
+ Graph _graph_1 = this.gc.getGraph();
+ EList<Node> _nodes_2 = _graph_1.getNodes();
+ final Function1<Node, Boolean> _function_2 = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ String _name = FsmGenExtensions.getName(it);
+ return Boolean.valueOf(_name.equals("State2"));
+ }
+ };
+ Iterable<Node> _filter_2 = IterableExtensions.<Node>filter(_nodes_2, _function_2);
+ Node _head_1 = IterableExtensions.<Node>head(_filter_2);
+ s = _head_1;
+ Assert.assertNotNull("state found", s);
+ EList<Link> _incoming_1 = s.getIncoming();
+ int _size_3 = _incoming_1.size();
+ Assert.assertEquals("number of incoming transitions", 4, _size_3);
+ EList<Link> _outgoing_1 = s.getOutgoing();
+ int _size_4 = _outgoing_1.size();
+ Assert.assertEquals("number of outgoing transitions", 1, _size_4);
+ EList<CommonTrigger> _caughtTriggers_1 = s.getCaughtTriggers();
+ int _size_5 = _caughtTriggers_1.size();
+ Assert.assertEquals("active triggers", 3, _size_5);
+ Graph _graph_2 = this.gc.getGraph();
+ EList<Node> _nodes_3 = _graph_2.getNodes();
+ final Function1<Node, Boolean> _function_3 = new Function1<Node, Boolean>() {
+ @Override
+ public Boolean apply(final Node it) {
+ String _name = FsmGenExtensions.getName(it);
+ return Boolean.valueOf(_name.equals("CP1"));
+ }
+ };
+ Iterable<Node> _filter_3 = IterableExtensions.<Node>filter(_nodes_3, _function_3);
+ final Node cp = IterableExtensions.<Node>head(_filter_3);
+ Assert.assertNotNull("cp found", cp);
+ EList<Link> _incoming_2 = cp.getIncoming();
+ int _size_6 = _incoming_2.size();
+ Assert.assertEquals("number of incoming transitions", 1, _size_6);
+ EList<Link> _outgoing_2 = cp.getOutgoing();
+ int _size_7 = _outgoing_2.size();
+ Assert.assertEquals("number of outgoing transitions", 3, _size_7);
+ EList<Link> _outgoing_3 = cp.getOutgoing();
+ final Function1<Link, Boolean> _function_4 = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ return Boolean.valueOf((_transition instanceof ContinuationTransition));
+ }
+ };
+ final Iterable<Link> cts = IterableExtensions.<Link>filter(_outgoing_3, _function_4);
+ int _size_8 = IterableExtensions.size(cts);
+ Assert.assertEquals("Exactly one continuation (=default) transition", 1, _size_8);
+ }
+
+ @Test
+ public void testChains() {
+ Graph _graph = this.gc.getGraph();
+ Iterator<Link> _allLinks = FsmGenExtensions.getAllLinks(_graph);
+ final Function1<Link, Boolean> _function = new Function1<Link, Boolean>() {
+ @Override
+ public Boolean apply(final Link it) {
+ TransitionBase _transition = it.getTransition();
+ String _fullPath = TestStatesTriggers.this.roomNameProvider.getFullPath(((Transition) _transition));
+ return Boolean.valueOf(_fullPath.equals("State3_TRANS_tr1_FROM_tp1_TO_State3"));
+ }
+ };
+ Iterator<Link> _filter = IteratorExtensions.<Link>filter(_allLinks, _function);
+ final Link tr = IteratorExtensions.<Link>head(_filter);
+ Assert.assertNotNull("transition found", tr);
+ EList<Link> _chainHeads = tr.getChainHeads();
+ int _size = _chainHeads.size();
+ Assert.assertEquals("one chain head", 1, _size);
+ EList<Link> _chainHeads_1 = tr.getChainHeads();
+ Link _head = IterableExtensions.<Link>head(_chainHeads_1);
+ TransitionBase _transition = _head.getTransition();
+ String _fullPath = this.roomNameProvider.getFullPath(((Transition) _transition));
+ Assert.assertEquals("correct chain head", "TRANS_tr5_FROM_tp0_TO_State3_tp1_BY_afct", _fullPath);
+ }
}

Back to the top