Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2012-05-16 15:05:18 +0000
committerHenrik Rentz-Reichert2012-05-16 15:05:18 +0000
commita5632a4ad02a1aa2fb5e1640d7ba3185f2857da3 (patch)
tree675fff9a0f49f8c3eac18b1df8e5e2075e5fd5c9 /tests/org.eclipse.etrice.ui.behavior.tests
parent167acfea5ff08b56822538bc2f835aab2f36d24e (diff)
downloadorg.eclipse.etrice-a5632a4ad02a1aa2fb5e1640d7ba3185f2857da3.tar.gz
org.eclipse.etrice-a5632a4ad02a1aa2fb5e1640d7ba3185f2857da3.tar.xz
org.eclipse.etrice-a5632a4ad02a1aa2fb5e1640d7ba3185f2857da3.zip
[ui.behavior.test] added test for state machine inheritance
Diffstat (limited to 'tests/org.eclipse.etrice.ui.behavior.tests')
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/models/InheritedStateMachine.room101
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java4
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestInheritedStateMachine.java148
3 files changed, 253 insertions, 0 deletions
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/models/InheritedStateMachine.room b/tests/org.eclipse.etrice.ui.behavior.tests/models/InheritedStateMachine.room
new file mode 100644
index 000000000..59fb2aa1e
--- /dev/null
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/models/InheritedStateMachine.room
@@ -0,0 +1,101 @@
+RoomModel InheritedStateMachine {
+
+ ActorClass Base {
+ Interface {
+ Port p0: PC
+ }
+ Structure {
+ external Port p0
+ }
+ Behavior {
+ StateMachine {
+ Transition init: initial -> b0 { }
+ Transition tr0: b0 -> cp cp0 {
+ triggers {
+ <x: p0>
+ }
+ }
+ Transition tr1: cp cp0 -> b2
+ Transition tr2: cp cp0 -> tp0 of b1 {
+ cond {
+ "true"
+ }
+ }
+ Transition tr3: tp1 of b1 -> b2
+ ChoicePoint cp0
+ TransitionPoint tp0
+ State b0
+ State b1 {
+ subgraph {
+ EntryPoint tp0
+ ExitPoint tp1
+ }
+ }
+ State b2
+ }
+ }
+ }
+
+ ActorClass Derived extends Base {
+ Structure { }
+ Behavior {
+ StateMachine {
+ RefinedState b1 {
+ subgraph {
+ Transition tr0: my tp0 -> d11
+ Transition tr1: d11 -> my tp1 {
+ triggers {
+ <x: p0>
+ }
+ }
+ State d11
+ }
+ }
+ RefinedState b2 {
+ subgraph {
+ State d21
+ }
+ }
+ }
+ }
+ }
+
+ ActorClass DoubleDerived extends Derived {
+ Structure { }
+ Behavior {
+ StateMachine {
+ RefinedState b1 {
+ subgraph {
+ RefinedState d11 {
+ subgraph {
+ State dd111
+ }
+ }
+ State dd12
+ State dd13
+ }
+ }
+ RefinedState b2 {
+ subgraph {
+ State xt2
+ RefinedState d21 {
+ subgraph {
+ State dd211
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ ProtocolClass PC {
+ incoming {
+ Message x()
+ }
+ outgoing {
+ Message x()
+ }
+ }
+
+} \ No newline at end of file
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java
index 767be6c9a..ac8bf0cde 100644
--- a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java
@@ -22,6 +22,7 @@ import org.eclipse.etrice.core.room.ChoicePoint;
import org.eclipse.etrice.core.room.EntryPoint;
import org.eclipse.etrice.core.room.ExitPoint;
import org.eclipse.etrice.core.room.InitialTransition;
+import org.eclipse.etrice.core.room.RefinedState;
import org.eclipse.etrice.core.room.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateGraphItem;
@@ -150,6 +151,9 @@ public abstract class AbstractStateMachineTest extends TestBase {
* @return true if state graph item is not owned by the given actor class
*/
private boolean isInherited(ActorClass ac, StateGraphItem item) {
+ if (item instanceof RefinedState)
+ return true;
+
EObject owner = item.eContainer();
while (owner!=null) {
if (owner instanceof ActorClass)
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestInheritedStateMachine.java b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestInheritedStateMachine.java
new file mode 100644
index 000000000..b095eaa45
--- /dev/null
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestInheritedStateMachine.java
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.ui.behavior.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.State;
+import org.eclipse.etrice.core.room.StateGraph;
+import org.eclipse.etrice.ui.behavior.DiagramAccess;
+import org.eclipse.graphiti.mm.pictograms.ContainerShape;
+import org.eclipse.graphiti.mm.pictograms.Diagram;
+import org.eclipse.graphiti.mm.pictograms.Shape;
+import org.eclipse.graphiti.services.Graphiti;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * unit test of a hierarchical state machine (defined by HierarchicalStateMachine.room)
+ *
+ * @author Henrik Rentz-Reichert initial contribution and API
+ *
+ */
+public class TestInheritedStateMachine extends AbstractStateMachineTest {
+
+ @Before
+ public void setUp() {
+ loadModelFile();
+ }
+
+ @After
+ public void tearDown() {
+ removeDiagramsDirectory();
+ }
+
+ @Override
+ protected String getModelFileName() {
+ return "InheritedStateMachine.room";
+ }
+
+ @Test
+ public void checkModel() {
+ assertEquals("models read", 1, getModels().size());
+ assertEquals("actor classes in our model", 3, getModels().get(0).getActorClasses().size());
+ }
+
+ @Test
+ public void testBaseClass() {
+ ActorClass ac = getActorClass("Base");
+ assertTrue("actor class Base present in model", ac!=null);
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+
+ // have to use the actor class from the diagram since this is another instance
+ ac = (ActorClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
+
+ testSGItems(ac.getStateMachine(), diagram);
+
+ // top and one sub state graph
+ assertEquals("diagram children", 2, diagram.getChildren().size());
+
+ for (Shape shape : diagram.getChildren()) {
+ assertTrue("top level shape is container shape", shape instanceof ContainerShape);
+
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
+ assertTrue("top level business object is StateGraph", bo instanceof StateGraph);
+ }
+ }
+
+ @Test
+ public void testDerivedClass() {
+ ActorClass ac = getActorClass("Derived");
+ assertTrue("actor class Derived present in model", ac!=null);
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+
+ // have to use the actor class from the diagram since this is another instance
+ ac = (ActorClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
+ assertTrue("is derived", ac.getBase()!=null);
+ assertTrue("extends Base", ac.getBase().getName().equals("Base"));
+
+ testSGItems(ac.getStateMachine(), diagram);
+
+ // top and two sub state graph
+ assertEquals("diagram children", 3, diagram.getChildren().size());
+
+ for (Shape shape : diagram.getChildren()) {
+ assertTrue("top level shape is container shape", shape instanceof ContainerShape);
+
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
+ assertTrue("top level business object is StateGraph", bo instanceof StateGraph);
+ }
+ }
+
+ @Test
+ public void testDoubleDerivedClass() {
+ ActorClass ac = getActorClass("DoubleDerived");
+ assertTrue("actor class DoubleDerived present in model", ac!=null);
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+
+ // have to use the actor class from the diagram since this is another instance
+ ac = (ActorClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
+ assertTrue("is derived", ac.getBase()!=null);
+ assertTrue("extends Base", ac.getBase().getName().equals("Derived"));
+
+ testSGItems(ac.getStateMachine(), diagram);
+
+ // top and four sub state graph
+ assertEquals("diagram children", 5, diagram.getChildren().size());
+
+ for (Shape shape : diagram.getChildren()) {
+ assertTrue("top level shape is container shape", shape instanceof ContainerShape);
+
+ EObject bo = Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
+ assertTrue("top level business object is StateGraph", bo instanceof StateGraph);
+ }
+ }
+
+ public void testSGItems(StateGraph sg, Diagram diagram) {
+
+ testStateGraph(diagram, sg);
+
+ for (State s : sg.getStates()) {
+ if (s.getSubgraph()!=null)
+ testSGItems(s.getSubgraph(), diagram);
+ }
+ }
+
+ private ActorClass getActorClass(String name) {
+ for (ActorClass ac : getModels().get(0).getActorClasses()) {
+ if (ac.getName().equals(name))
+ return ac;
+ }
+ return null;
+ }
+}

Back to the top