Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2011-02-11 07:57:07 -0500
committerHenrik Rentz-Reichert2011-02-11 07:57:07 -0500
commit6df8754cce5b2ae19e38878bfb9eeac984ef056e (patch)
tree93cd2d30b28b7a149c519a3b472dc2ad96a4e679 /tests
parent8cb0f8c60e5f0572af4183f8dd91f7c05a8c4110 (diff)
downloadorg.eclipse.etrice-6df8754cce5b2ae19e38878bfb9eeac984ef056e.tar.gz
org.eclipse.etrice-6df8754cce5b2ae19e38878bfb9eeac984ef056e.tar.xz
org.eclipse.etrice-6df8754cce5b2ae19e38878bfb9eeac984ef056e.zip
ui.behavior.test: unit test for hierarchical state machine
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java (renamed from tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestStateMachineBase.java)24
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFlatStateMachine.java14
-rw-r--r--tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestHierarchicalStateMachine.java91
3 files changed, 114 insertions, 15 deletions
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestStateMachineBase.java b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java
index 88e473fb5..767be6c9a 100644
--- a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestStateMachineBase.java
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/AbstractStateMachineTest.java
@@ -13,18 +13,23 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.net.URL;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
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.State;
import org.eclipse.etrice.core.room.StateGraph;
import org.eclipse.etrice.core.room.StateGraphItem;
import org.eclipse.etrice.core.room.TrPoint;
import org.eclipse.etrice.core.room.Transition;
+import org.eclipse.etrice.core.room.TransitionPoint;
import org.eclipse.etrice.tests.base.TestBase;
+import org.eclipse.etrice.ui.behavior.BehaviorTestActivator;
import org.eclipse.etrice.ui.behavior.support.StateSupport;
import org.eclipse.etrice.ui.behavior.support.TrPointSupport;
import org.eclipse.graphiti.mm.algorithms.Ellipse;
@@ -41,7 +46,7 @@ import org.eclipse.graphiti.services.Graphiti;
*
* @author Henrik Rentz-Reichert - API and initial contribution
*/
-public abstract class TestStateMachineBase extends TestBase {
+public abstract class AbstractStateMachineTest extends TestBase {
/**
* test general conditions for state graphs
@@ -79,7 +84,7 @@ public abstract class TestStateMachineBase extends TestBase {
for (TrPoint tp : sg.getTrPoints()) {
elements = Graphiti.getLinkService().getPictogramElements(diagram, tp);
- assertEquals("PEs for our tp", 1, elements.size());
+ assertEquals("PEs for our tp", (tp instanceof TransitionPoint)? 1:2, elements.size());
assertTrue("PE is shape", elements.get(0) instanceof Shape);
checkTrpGAs(ac, tp, (Shape) elements.get(0));
}
@@ -123,7 +128,12 @@ public abstract class TestStateMachineBase extends TestBase {
assertTrue("ga is ellipse", shape.getGraphicsAlgorithm() instanceof Rectangle);
assertFalse("ga is invisible", shape.getGraphicsAlgorithm().getFilled());
assertFalse("ga is invisible", shape.getGraphicsAlgorithm().getLineVisible());
- assertEquals("border rect", 1, shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().size());
+ int nga = 1;
+ if (tp instanceof EntryPoint)
+ nga = 3;
+ else if (tp instanceof ExitPoint)
+ nga = 2;
+ assertEquals("border rect", nga, shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().size());
GraphicsAlgorithm borderRect = shape.getGraphicsAlgorithm().getGraphicsAlgorithmChildren().get(0);
assertTrue("border rect is rounded rectangle", borderRect instanceof Ellipse);
if (isInherited(ac,tp))
@@ -148,4 +158,12 @@ public abstract class TestStateMachineBase extends TestBase {
}
return ac!=owner;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.etrice.tests.base.TestBase#getModelsDirectoy()
+ */
+ @Override
+ protected URL getModelsDirectoy() {
+ return BehaviorTestActivator.getDefault().getBundle().getEntry("models");
+ }
}
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFlatStateMachine.java b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFlatStateMachine.java
index 0c4f2a66b..a4512821d 100644
--- a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFlatStateMachine.java
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestFlatStateMachine.java
@@ -15,12 +15,10 @@ package org.eclipse.etrice.ui.behavior.commands;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import java.net.URL;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.etrice.core.room.ActorClass;
import org.eclipse.etrice.core.room.StateGraph;
-import org.eclipse.etrice.ui.behavior.BehaviorTestActivator;
import org.eclipse.etrice.ui.behavior.DiagramAccess;
import org.eclipse.graphiti.mm.pictograms.ContainerShape;
import org.eclipse.graphiti.mm.pictograms.Diagram;
@@ -31,12 +29,12 @@ import org.junit.Before;
import org.junit.Test;
/**
- * test of a flat state machine (defined by FlatStateMachine.room)
+ * unit test of a flat state machine (defined by FlatStateMachine.room)
*
* @author Henrik Rentz-Reichert initial contribution and API
*
*/
-public class TestFlatStateMachine extends TestStateMachineBase {
+public class TestFlatStateMachine extends AbstractStateMachineTest {
@Before
public void setUp() {
@@ -82,12 +80,4 @@ public class TestFlatStateMachine extends TestStateMachineBase {
StateGraph sg = (StateGraph) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(shape);
testStateGraph(diagram, sg);
}
-
- /* (non-Javadoc)
- * @see org.eclipse.etrice.tests.base.TestBase#getModelsDirectoy()
- */
- @Override
- protected URL getModelsDirectoy() {
- return BehaviorTestActivator.getDefault().getBundle().getEntry("models");
- }
}
diff --git a/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestHierarchicalStateMachine.java b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestHierarchicalStateMachine.java
new file mode 100644
index 000000000..b37ca30ca
--- /dev/null
+++ b/tests/org.eclipse.etrice.ui.behavior.tests/src/org/eclipse/etrice/ui/behavior/commands/TestHierarchicalStateMachine.java
@@ -0,0 +1,91 @@
+/*******************************************************************************
+ * 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 TestHierarchicalStateMachine extends AbstractStateMachineTest {
+
+ @Before
+ public void setUp() {
+ loadModelFile();
+ }
+
+ @After
+ public void tearDown() {
+ removeDiagramsDirectory();
+ }
+
+ @Override
+ protected String getModelFileName() {
+ return "HierarchicalStateMachine.room";
+ }
+
+ @Test
+ public void checkModel() {
+ assertEquals("models read", 1, getModels().size());
+ assertEquals("actor classes in our model", 1, getModels().get(0).getActorClasses().size());
+ }
+
+ @Test
+ public void testActorClass() {
+ ActorClass ac = getModels().get(0).getActorClasses().get(0);
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+
+ // 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 testSGItems() {
+ ActorClass ac = getModels().get(0).getActorClasses().get(0);
+ Diagram diagram = new DiagramAccess().getDiagram(ac);
+
+ ac = (ActorClass) Graphiti.getLinkService().getBusinessObjectForLinkedPictogramElement(diagram);
+ StateGraph sg = ac.getStateMachine();
+ testStateGraph(diagram, sg);
+
+ for (State s : sg.getStates()) {
+ if (s.getSubgraph()!=null)
+ testStateGraph(diagram, s.getSubgraph());
+ }
+ }
+}

Back to the top